@danielx/civet 0.6.87 → 0.6.89
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 +251 -48
- package/dist/civet +117 -10
- package/dist/esm.mjs +0 -11
- package/dist/main.js +251 -48
- package/dist/main.mjs +251 -48
- package/dist/types.d.ts +6 -1
- package/package.json +2 -2
- package/register.js +20 -4
package/dist/main.mjs
CHANGED
|
@@ -225,6 +225,9 @@ function hasAwait(exp) {
|
|
|
225
225
|
function hasYield(exp) {
|
|
226
226
|
return gatherRecursiveWithinFunction(exp, ({ type }) => type === "Yield").length > 0;
|
|
227
227
|
}
|
|
228
|
+
function hasImportDeclaration(exp) {
|
|
229
|
+
return gatherRecursiveWithinFunction(exp, ({ type }) => type === "ImportDeclaration").length > 0;
|
|
230
|
+
}
|
|
228
231
|
function deepCopy(node) {
|
|
229
232
|
if (node == null)
|
|
230
233
|
return node;
|
|
@@ -386,9 +389,10 @@ function parenthesizeType(type) {
|
|
|
386
389
|
}
|
|
387
390
|
return ["(", type, ")"];
|
|
388
391
|
}
|
|
389
|
-
function wrapIIFE(expressions,
|
|
392
|
+
function wrapIIFE(expressions, asyncFlag) {
|
|
390
393
|
let prefix;
|
|
391
|
-
|
|
394
|
+
let async;
|
|
395
|
+
if (asyncFlag) {
|
|
392
396
|
async = "async ";
|
|
393
397
|
} else if (hasAwait(expressions)) {
|
|
394
398
|
async = "async ";
|
|
@@ -576,16 +580,16 @@ function blockWithPrefix(prefixStatements, block) {
|
|
|
576
580
|
expressions,
|
|
577
581
|
children: block.children === block.expressions ? expressions : block.children.map((c) => c === block.expressions ? expressions : c)
|
|
578
582
|
};
|
|
579
|
-
|
|
580
|
-
block.children = [[" {"], ...block.children, "}"];
|
|
581
|
-
block.bare = false;
|
|
582
|
-
}
|
|
583
|
+
braceBlock(block);
|
|
583
584
|
updateParentPointers(block);
|
|
584
585
|
}
|
|
585
586
|
return block;
|
|
586
587
|
}
|
|
587
588
|
function braceBlock(block) {
|
|
588
589
|
if (block.bare) {
|
|
590
|
+
if (block.children === block.expressions) {
|
|
591
|
+
block.children = [block.expressions];
|
|
592
|
+
}
|
|
589
593
|
block.children.unshift(" {");
|
|
590
594
|
block.children.push("}");
|
|
591
595
|
return block.bare = false;
|
|
@@ -595,8 +599,13 @@ function braceBlock(block) {
|
|
|
595
599
|
}
|
|
596
600
|
function duplicateBlock(block) {
|
|
597
601
|
const expressions = [...block.expressions];
|
|
598
|
-
|
|
599
|
-
|
|
602
|
+
let children;
|
|
603
|
+
if (block.children === block.expressions) {
|
|
604
|
+
children = expressions;
|
|
605
|
+
} else {
|
|
606
|
+
children = [...block.children];
|
|
607
|
+
children.splice(children.indexOf(block.expressions), 1, expressions);
|
|
608
|
+
}
|
|
600
609
|
return {
|
|
601
610
|
...block,
|
|
602
611
|
expressions,
|
|
@@ -1702,7 +1711,11 @@ function patternAsValue(pattern) {
|
|
|
1702
1711
|
}
|
|
1703
1712
|
case "Identifier":
|
|
1704
1713
|
case "BindingProperty": {
|
|
1705
|
-
const children = [
|
|
1714
|
+
const children = [
|
|
1715
|
+
// { name: value } = ... declares value, not name
|
|
1716
|
+
pattern.value ?? pattern.name,
|
|
1717
|
+
pattern.delim
|
|
1718
|
+
];
|
|
1706
1719
|
if (isWhitespaceOrEmpty(pattern.children[0])) {
|
|
1707
1720
|
children.unshift(pattern.children[0]);
|
|
1708
1721
|
}
|
|
@@ -2009,8 +2022,7 @@ function expressionizeIteration(exp) {
|
|
|
2009
2022
|
throw new Error("Could not find iteration statement in iteration expression");
|
|
2010
2023
|
}
|
|
2011
2024
|
if (subtype === "DoStatement") {
|
|
2012
|
-
|
|
2013
|
-
children.splice(i, 1, ...wrapIIFE(["", statement, void 0], async));
|
|
2025
|
+
children.splice(i, 1, ...wrapIIFE([["", statement, void 0]], async));
|
|
2014
2026
|
updateParentPointers(exp);
|
|
2015
2027
|
return;
|
|
2016
2028
|
}
|
|
@@ -2310,6 +2322,111 @@ function processDeclarationConditionStatement(s, getRef) {
|
|
|
2310
2322
|
}
|
|
2311
2323
|
}
|
|
2312
2324
|
}
|
|
2325
|
+
function dynamizeFromClause(from) {
|
|
2326
|
+
from = from.slice(1);
|
|
2327
|
+
from = insertTrimmingSpace(from, "");
|
|
2328
|
+
if (from.at(-1)?.type === "ImportAssertion") {
|
|
2329
|
+
const assert2 = from.pop();
|
|
2330
|
+
from.push(", {", assert2.keyword, ":", assert2.object, "}");
|
|
2331
|
+
}
|
|
2332
|
+
return ["(", ...from, ")"];
|
|
2333
|
+
}
|
|
2334
|
+
function dynamizeImportDeclaration(decl) {
|
|
2335
|
+
const { imports } = decl;
|
|
2336
|
+
let { star, binding, specifiers } = imports;
|
|
2337
|
+
const justDefault = binding && !specifiers && !star;
|
|
2338
|
+
const pattern = (() => {
|
|
2339
|
+
{
|
|
2340
|
+
if (binding) {
|
|
2341
|
+
if (specifiers) {
|
|
2342
|
+
return makeRef();
|
|
2343
|
+
} else {
|
|
2344
|
+
return binding;
|
|
2345
|
+
}
|
|
2346
|
+
} else {
|
|
2347
|
+
return convertNamedImportsToObject(imports, true);
|
|
2348
|
+
}
|
|
2349
|
+
}
|
|
2350
|
+
})();
|
|
2351
|
+
const c = "const";
|
|
2352
|
+
const initializer = [
|
|
2353
|
+
" = ",
|
|
2354
|
+
justDefault ? "(" : void 0,
|
|
2355
|
+
{ type: "Await", children: ["await"] },
|
|
2356
|
+
" ",
|
|
2357
|
+
decl.children[0],
|
|
2358
|
+
// import
|
|
2359
|
+
dynamizeFromClause(decl.from),
|
|
2360
|
+
justDefault ? ").default" : void 0
|
|
2361
|
+
];
|
|
2362
|
+
const bindings = [{
|
|
2363
|
+
type: "Binding",
|
|
2364
|
+
names: pattern.names,
|
|
2365
|
+
pattern,
|
|
2366
|
+
initializer,
|
|
2367
|
+
children: [pattern, initializer]
|
|
2368
|
+
}];
|
|
2369
|
+
if (binding && specifiers) {
|
|
2370
|
+
const pattern2 = binding;
|
|
2371
|
+
const initializer2 = [
|
|
2372
|
+
" = ",
|
|
2373
|
+
pattern,
|
|
2374
|
+
".default"
|
|
2375
|
+
];
|
|
2376
|
+
bindings.push({
|
|
2377
|
+
type: "Binding",
|
|
2378
|
+
names: binding.names,
|
|
2379
|
+
pattern: pattern2,
|
|
2380
|
+
initializer: initializer2,
|
|
2381
|
+
children: [pattern2, initializer2]
|
|
2382
|
+
});
|
|
2383
|
+
const pattern3 = convertNamedImportsToObject(imports.children.at(-1), true);
|
|
2384
|
+
const initializer3 = [
|
|
2385
|
+
" = ",
|
|
2386
|
+
pattern
|
|
2387
|
+
];
|
|
2388
|
+
bindings.push({
|
|
2389
|
+
type: "Binding",
|
|
2390
|
+
names: specifiers.names,
|
|
2391
|
+
pattern: pattern3,
|
|
2392
|
+
initializer: initializer3,
|
|
2393
|
+
children: [pattern3, initializer3]
|
|
2394
|
+
});
|
|
2395
|
+
}
|
|
2396
|
+
return {
|
|
2397
|
+
type: "Declaration",
|
|
2398
|
+
names: imports.names,
|
|
2399
|
+
bindings,
|
|
2400
|
+
decl: c,
|
|
2401
|
+
children: [
|
|
2402
|
+
c,
|
|
2403
|
+
" ",
|
|
2404
|
+
bindings.flatMap((binding2, i) => i > 0 ? [", ", binding2] : [binding2])
|
|
2405
|
+
]
|
|
2406
|
+
};
|
|
2407
|
+
}
|
|
2408
|
+
function dynamizeImportDeclarationExpression($0) {
|
|
2409
|
+
const [imp, ws1, named, ws2, from] = $0;
|
|
2410
|
+
const object = convertNamedImportsToObject(named);
|
|
2411
|
+
const dot = ".";
|
|
2412
|
+
return processCallMemberExpression({
|
|
2413
|
+
type: "CallExpression",
|
|
2414
|
+
children: [
|
|
2415
|
+
{ type: "Await", children: "await" },
|
|
2416
|
+
" ",
|
|
2417
|
+
imp,
|
|
2418
|
+
insertTrimmingSpace(ws2, ""),
|
|
2419
|
+
dynamizeFromClause(from),
|
|
2420
|
+
{
|
|
2421
|
+
type: "PropertyGlob",
|
|
2422
|
+
dot,
|
|
2423
|
+
object,
|
|
2424
|
+
children: [ws1, dot, object],
|
|
2425
|
+
reversed: true
|
|
2426
|
+
}
|
|
2427
|
+
]
|
|
2428
|
+
});
|
|
2429
|
+
}
|
|
2313
2430
|
var init_declaration = __esm({
|
|
2314
2431
|
"source/parser/declaration.civet"() {
|
|
2315
2432
|
"use strict";
|
|
@@ -2319,6 +2436,7 @@ var init_declaration = __esm({
|
|
|
2319
2436
|
init_util();
|
|
2320
2437
|
init_function();
|
|
2321
2438
|
init_binding();
|
|
2439
|
+
init_lib();
|
|
2322
2440
|
}
|
|
2323
2441
|
});
|
|
2324
2442
|
|
|
@@ -3135,21 +3253,28 @@ __export(lib_exports, {
|
|
|
3135
3253
|
adjustIndexAccess: () => adjustIndexAccess,
|
|
3136
3254
|
attachPostfixStatementAsExpression: () => attachPostfixStatementAsExpression,
|
|
3137
3255
|
blockWithPrefix: () => blockWithPrefix,
|
|
3256
|
+
convertNamedImportsToObject: () => convertNamedImportsToObject,
|
|
3138
3257
|
convertObjectToJSXAttributes: () => convertObjectToJSXAttributes,
|
|
3139
3258
|
dedentBlockString: () => dedentBlockString,
|
|
3140
3259
|
dedentBlockSubstitutions: () => dedentBlockSubstitutions,
|
|
3141
3260
|
deepCopy: () => deepCopy,
|
|
3261
|
+
dynamizeImportDeclaration: () => dynamizeImportDeclaration,
|
|
3262
|
+
dynamizeImportDeclarationExpression: () => dynamizeImportDeclarationExpression,
|
|
3142
3263
|
expressionizeTypeIf: () => expressionizeTypeIf,
|
|
3143
3264
|
forRange: () => forRange,
|
|
3144
3265
|
gatherBindingCode: () => gatherBindingCode,
|
|
3145
3266
|
gatherRecursive: () => gatherRecursive,
|
|
3267
|
+
gatherRecursiveAll: () => gatherRecursiveAll,
|
|
3268
|
+
gatherRecursiveWithinFunction: () => gatherRecursiveWithinFunction,
|
|
3146
3269
|
getIndentLevel: () => getIndentLevel,
|
|
3147
3270
|
getPrecedence: () => getPrecedence,
|
|
3148
3271
|
getTrimmingSpace: () => getTrimmingSpace,
|
|
3149
3272
|
hasAwait: () => hasAwait,
|
|
3273
|
+
hasImportDeclaration: () => hasImportDeclaration,
|
|
3150
3274
|
hasYield: () => hasYield,
|
|
3151
3275
|
insertTrimmingSpace: () => insertTrimmingSpace,
|
|
3152
3276
|
isEmptyBareBlock: () => isEmptyBareBlock,
|
|
3277
|
+
isFunction: () => isFunction,
|
|
3153
3278
|
isWhitespaceOrEmpty: () => isWhitespaceOrEmpty,
|
|
3154
3279
|
lastAccessInCallExpression: () => lastAccessInCallExpression,
|
|
3155
3280
|
literalValue: () => literalValue,
|
|
@@ -3410,9 +3535,13 @@ function processCallMemberExpression(node) {
|
|
|
3410
3535
|
throw new Error(`Glob pattern must have call or member expression value, found ${JSON.stringify(part.value)}`);
|
|
3411
3536
|
}
|
|
3412
3537
|
let suppressPrefix = false;
|
|
3413
|
-
let
|
|
3538
|
+
let name = part.name;
|
|
3539
|
+
let value = part.value ?? name;
|
|
3414
3540
|
const wValue = getTrimmingSpace(part.value);
|
|
3415
3541
|
[value, suppressPrefix] = handleThisPrivateShorthands(value);
|
|
3542
|
+
if (glob.reversed) {
|
|
3543
|
+
[name, value] = [value, name];
|
|
3544
|
+
}
|
|
3416
3545
|
if (!suppressPrefix) {
|
|
3417
3546
|
value = prefix.concat(insertTrimmingSpace(value, ""));
|
|
3418
3547
|
}
|
|
@@ -3430,13 +3559,13 @@ function processCallMemberExpression(node) {
|
|
|
3430
3559
|
} else {
|
|
3431
3560
|
parts.push({
|
|
3432
3561
|
type: part.type === "Identifier" ? "Property" : part.type,
|
|
3433
|
-
name
|
|
3562
|
+
name,
|
|
3434
3563
|
value,
|
|
3435
3564
|
delim: part.delim,
|
|
3436
3565
|
names: part.names,
|
|
3437
3566
|
children: [
|
|
3438
3567
|
isWhitespaceOrEmpty(part.children[0]) && part.children[0],
|
|
3439
|
-
|
|
3568
|
+
name,
|
|
3440
3569
|
isWhitespaceOrEmpty(part.children[2]) && part.children[2],
|
|
3441
3570
|
part.children[3]?.token === ":" ? part.children[3] : ":",
|
|
3442
3571
|
value,
|
|
@@ -3581,6 +3710,35 @@ function convertMethodToFunction(method) {
|
|
|
3581
3710
|
block
|
|
3582
3711
|
};
|
|
3583
3712
|
}
|
|
3713
|
+
function convertNamedImportsToObject(node, pattern) {
|
|
3714
|
+
const properties = node.specifiers.map((specifier) => {
|
|
3715
|
+
if (specifier.ts) {
|
|
3716
|
+
return { type: "Error", message: "cannot use `type` in dynamic import" };
|
|
3717
|
+
} else {
|
|
3718
|
+
const { source, binding } = specifier;
|
|
3719
|
+
const delim = specifier.children.at(-1);
|
|
3720
|
+
return {
|
|
3721
|
+
type: pattern ? "BindingProperty" : "Property",
|
|
3722
|
+
name: source,
|
|
3723
|
+
value: !(source === binding) ? binding : void 0,
|
|
3724
|
+
delim,
|
|
3725
|
+
children: source === binding ? [source, delim] : [source, ":", binding, delim]
|
|
3726
|
+
};
|
|
3727
|
+
}
|
|
3728
|
+
});
|
|
3729
|
+
return {
|
|
3730
|
+
type: pattern ? "ObjectBindingPattern" : "ObjectExpression",
|
|
3731
|
+
names: node.names,
|
|
3732
|
+
properties,
|
|
3733
|
+
children: [
|
|
3734
|
+
node.children[0],
|
|
3735
|
+
// {
|
|
3736
|
+
properties,
|
|
3737
|
+
node.children.at(-1)
|
|
3738
|
+
// }
|
|
3739
|
+
]
|
|
3740
|
+
};
|
|
3741
|
+
}
|
|
3584
3742
|
function convertObjectToJSXAttributes(obj) {
|
|
3585
3743
|
const { properties } = obj;
|
|
3586
3744
|
const parts = [];
|
|
@@ -7056,14 +7214,17 @@ var require_parser = __commonJS({
|
|
|
7056
7214
|
children: [$1, ...$2, ...rest.flat()]
|
|
7057
7215
|
});
|
|
7058
7216
|
});
|
|
7059
|
-
var CallExpression$1 = $TS($S(
|
|
7217
|
+
var CallExpression$1 = $TS($S(Import, _, NamedImports, __, FromClause), function($skip, $loc, $0, $1, $2, $3, $4, $5) {
|
|
7218
|
+
return dynamizeImportDeclarationExpression($0);
|
|
7219
|
+
});
|
|
7220
|
+
var CallExpression$2 = $TS($S($EXPECT($L20, 'CallExpression "import"'), ArgumentsWithTrailingMemberExpressions, $Q(CallExpressionRest)), function($skip, $loc, $0, $1, $2, $3) {
|
|
7060
7221
|
var rest = $3;
|
|
7061
7222
|
return processCallMemberExpression({
|
|
7062
7223
|
type: "CallExpression",
|
|
7063
7224
|
children: [$1, ...$2, ...rest.flat()]
|
|
7064
7225
|
});
|
|
7065
7226
|
});
|
|
7066
|
-
var CallExpression$
|
|
7227
|
+
var CallExpression$3 = $TS($S(MemberExpression, AllowedTrailingMemberExpressions, $Q(CallExpressionRest)), function($skip, $loc, $0, $1, $2, $3) {
|
|
7067
7228
|
var member = $1;
|
|
7068
7229
|
var trailing = $2;
|
|
7069
7230
|
var rest = $3;
|
|
@@ -7076,7 +7237,7 @@ var require_parser = __commonJS({
|
|
|
7076
7237
|
}
|
|
7077
7238
|
return member;
|
|
7078
7239
|
});
|
|
7079
|
-
var CallExpression$$ = [CallExpression$0, CallExpression$1, CallExpression$2];
|
|
7240
|
+
var CallExpression$$ = [CallExpression$0, CallExpression$1, CallExpression$2, CallExpression$3];
|
|
7080
7241
|
function CallExpression(ctx, state) {
|
|
7081
7242
|
return $EVENT_C(ctx, state, "CallExpression", CallExpression$$);
|
|
7082
7243
|
}
|
|
@@ -8658,11 +8819,14 @@ var require_parser = __commonJS({
|
|
|
8658
8819
|
});
|
|
8659
8820
|
var NonSingleBracedBlock$1 = ImplicitNestedBlock;
|
|
8660
8821
|
var NonSingleBracedBlock$2 = $TS($S(InsertOpenBrace, NestedImplicitObjectLiteral, InsertCloseBrace), function($skip, $loc, $0, $1, $2, $3) {
|
|
8822
|
+
var o = $1;
|
|
8661
8823
|
var s = $2;
|
|
8824
|
+
var c = $3;
|
|
8825
|
+
const expressions = [s];
|
|
8662
8826
|
return {
|
|
8663
8827
|
type: "BlockStatement",
|
|
8664
|
-
expressions
|
|
8665
|
-
children:
|
|
8828
|
+
expressions,
|
|
8829
|
+
children: [o, expressions, c]
|
|
8666
8830
|
};
|
|
8667
8831
|
});
|
|
8668
8832
|
var NonSingleBracedBlock$$ = [NonSingleBracedBlock$0, NonSingleBracedBlock$1, NonSingleBracedBlock$2];
|
|
@@ -11340,28 +11504,31 @@ var require_parser = __commonJS({
|
|
|
11340
11504
|
};
|
|
11341
11505
|
});
|
|
11342
11506
|
var ImportDeclaration$1 = $T($S(Import, __, TypeKeyword, __, ImportClause, __, FromClause), function(value) {
|
|
11343
|
-
|
|
11507
|
+
var imports = value[4];
|
|
11508
|
+
var from = value[6];
|
|
11509
|
+
return { "type": "ImportDeclaration", "ts": true, "children": value, "imports": imports, "from": from };
|
|
11344
11510
|
});
|
|
11345
11511
|
var ImportDeclaration$2 = $T($S(Import, __, ImportClause, __, FromClause), function(value) {
|
|
11346
|
-
|
|
11512
|
+
var imports = value[2];
|
|
11513
|
+
var from = value[4];
|
|
11514
|
+
return { "type": "ImportDeclaration", "children": value, "imports": imports, "from": from };
|
|
11347
11515
|
});
|
|
11348
11516
|
var ImportDeclaration$3 = $T($S(Import, __, ModuleSpecifier), function(value) {
|
|
11349
|
-
|
|
11517
|
+
var module3 = value[2];
|
|
11518
|
+
return { "type": "ImportDeclaration", "children": value, "module": module3 };
|
|
11350
11519
|
});
|
|
11351
11520
|
var ImportDeclaration$4 = $TS($S(ImpliedImport, $E($S(TypeKeyword, __)), ImportClause, __, FromClause), function($skip, $loc, $0, $1, $2, $3, $4, $5) {
|
|
11352
11521
|
var i = $1;
|
|
11353
11522
|
var t = $2;
|
|
11354
|
-
var
|
|
11523
|
+
var imports = $3;
|
|
11355
11524
|
var w = $4;
|
|
11356
|
-
var
|
|
11525
|
+
var from = $5;
|
|
11357
11526
|
i.$loc = {
|
|
11358
|
-
pos:
|
|
11359
|
-
length:
|
|
11527
|
+
pos: from[0].$loc.pos - 1,
|
|
11528
|
+
length: from[0].$loc.length + 1
|
|
11360
11529
|
};
|
|
11361
|
-
const children = [i, t,
|
|
11362
|
-
|
|
11363
|
-
return children;
|
|
11364
|
-
return { type: "ImportDeclaration", ts: true, children };
|
|
11530
|
+
const children = [i, t, imports, w, from];
|
|
11531
|
+
return { type: "ImportDeclaration", ts: !!t, children, imports, from };
|
|
11365
11532
|
});
|
|
11366
11533
|
var ImportDeclaration$$ = [ImportDeclaration$0, ImportDeclaration$1, ImportDeclaration$2, ImportDeclaration$3, ImportDeclaration$4];
|
|
11367
11534
|
function ImportDeclaration(ctx, state) {
|
|
@@ -11379,14 +11546,17 @@ var require_parser = __commonJS({
|
|
|
11379
11546
|
if (rest) {
|
|
11380
11547
|
return {
|
|
11381
11548
|
type: "Declaration",
|
|
11382
|
-
children:
|
|
11383
|
-
names: [...binding.names, ...rest[3].names]
|
|
11549
|
+
children: [binding, ...rest],
|
|
11550
|
+
names: [...binding.names, ...rest[3].names],
|
|
11551
|
+
binding,
|
|
11552
|
+
specifiers: rest[3].specifiers
|
|
11384
11553
|
};
|
|
11385
11554
|
}
|
|
11386
11555
|
return {
|
|
11387
11556
|
type: "Declaration",
|
|
11388
|
-
children:
|
|
11389
|
-
names: binding.names
|
|
11557
|
+
children: [binding],
|
|
11558
|
+
names: binding.names,
|
|
11559
|
+
binding
|
|
11390
11560
|
};
|
|
11391
11561
|
});
|
|
11392
11562
|
var ImportClause$1 = NameSpaceImport;
|
|
@@ -11396,11 +11566,14 @@ var require_parser = __commonJS({
|
|
|
11396
11566
|
return $EVENT_C(ctx, state, "ImportClause", ImportClause$$);
|
|
11397
11567
|
}
|
|
11398
11568
|
var NameSpaceImport$0 = $TS($S(Star, ImportAsToken, __, ImportedBinding), function($skip, $loc, $0, $1, $2, $3, $4) {
|
|
11569
|
+
var star = $1;
|
|
11399
11570
|
var binding = $4;
|
|
11400
11571
|
return {
|
|
11401
11572
|
type: "Declaration",
|
|
11402
11573
|
children: $0,
|
|
11403
|
-
names: binding.names
|
|
11574
|
+
names: binding.names,
|
|
11575
|
+
binding,
|
|
11576
|
+
star
|
|
11404
11577
|
};
|
|
11405
11578
|
});
|
|
11406
11579
|
function NameSpaceImport(ctx, state) {
|
|
@@ -11412,17 +11585,32 @@ var require_parser = __commonJS({
|
|
|
11412
11585
|
return {
|
|
11413
11586
|
type: "Declaration",
|
|
11414
11587
|
children: $0,
|
|
11415
|
-
names
|
|
11588
|
+
names,
|
|
11589
|
+
specifiers
|
|
11416
11590
|
};
|
|
11417
11591
|
});
|
|
11418
11592
|
function NamedImports(ctx, state) {
|
|
11419
11593
|
return $EVENT(ctx, state, "NamedImports", NamedImports$0);
|
|
11420
11594
|
}
|
|
11421
|
-
var FromClause$0 = $S(From, __, ModuleSpecifier)
|
|
11595
|
+
var FromClause$0 = $TS($S(From, __, ModuleSpecifier), function($skip, $loc, $0, $1, $2, $3) {
|
|
11596
|
+
var module3 = $3;
|
|
11597
|
+
if (!Array.isArray(module3))
|
|
11598
|
+
return $0;
|
|
11599
|
+
return [$1, $2, ...module3];
|
|
11600
|
+
});
|
|
11422
11601
|
function FromClause(ctx, state) {
|
|
11423
11602
|
return $EVENT(ctx, state, "FromClause", FromClause$0);
|
|
11424
11603
|
}
|
|
11425
|
-
var ImportAssertion$0 = $S($E(_), $C($EXPECT($L117, 'ImportAssertion "with"'), $EXPECT($L118, 'ImportAssertion "assert"')), NonIdContinue, $E(_), ObjectLiteral)
|
|
11604
|
+
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) {
|
|
11605
|
+
var keyword = $2;
|
|
11606
|
+
var object = $5;
|
|
11607
|
+
return {
|
|
11608
|
+
type: "ImportAssertion",
|
|
11609
|
+
keyword,
|
|
11610
|
+
object,
|
|
11611
|
+
children: $0
|
|
11612
|
+
};
|
|
11613
|
+
});
|
|
11426
11614
|
function ImportAssertion(ctx, state) {
|
|
11427
11615
|
return $EVENT(ctx, state, "ImportAssertion", ImportAssertion$0);
|
|
11428
11616
|
}
|
|
@@ -11452,8 +11640,10 @@ var require_parser = __commonJS({
|
|
|
11452
11640
|
return $EVENT_C(ctx, state, "TypeAndImportSpecifier", TypeAndImportSpecifier$$);
|
|
11453
11641
|
}
|
|
11454
11642
|
var ImportSpecifier$0 = $TS($S(__, ModuleExportName, ImportAsToken, __, ImportedBinding, ObjectPropertyDelimiter), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6) {
|
|
11643
|
+
var source = $2;
|
|
11455
11644
|
var binding = $5;
|
|
11456
11645
|
return {
|
|
11646
|
+
source,
|
|
11457
11647
|
binding,
|
|
11458
11648
|
children: $0
|
|
11459
11649
|
};
|
|
@@ -11461,6 +11651,7 @@ var require_parser = __commonJS({
|
|
|
11461
11651
|
var ImportSpecifier$1 = $TS($S(__, ImportedBinding, ObjectPropertyDelimiter), function($skip, $loc, $0, $1, $2, $3) {
|
|
11462
11652
|
var binding = $2;
|
|
11463
11653
|
return {
|
|
11654
|
+
source: binding,
|
|
11464
11655
|
binding,
|
|
11465
11656
|
children: $0
|
|
11466
11657
|
};
|
|
@@ -11652,9 +11843,18 @@ var require_parser = __commonJS({
|
|
|
11652
11843
|
function ImplicitExportSpecifier(ctx, state) {
|
|
11653
11844
|
return $EVENT(ctx, state, "ImplicitExportSpecifier", ImplicitExportSpecifier$0);
|
|
11654
11845
|
}
|
|
11655
|
-
var Declaration$0 =
|
|
11656
|
-
|
|
11657
|
-
|
|
11846
|
+
var Declaration$0 = $TV(ImportDeclaration, function($skip, $loc, $0, $1) {
|
|
11847
|
+
var decl = $0;
|
|
11848
|
+
if (decl.ts || decl.module || !decl.imports || !decl.from)
|
|
11849
|
+
return $skip;
|
|
11850
|
+
const { imports } = decl;
|
|
11851
|
+
if (!imports.binding && !imports.specifiers)
|
|
11852
|
+
return $skip;
|
|
11853
|
+
return dynamizeImportDeclaration(decl);
|
|
11854
|
+
});
|
|
11855
|
+
var Declaration$1 = HoistableDeclaration;
|
|
11856
|
+
var Declaration$2 = ClassDeclaration;
|
|
11857
|
+
var Declaration$3 = $TV(LexicalDeclaration, function($skip, $loc, $0, $1) {
|
|
11658
11858
|
var d = $0;
|
|
11659
11859
|
if (d.thisAssignments?.length)
|
|
11660
11860
|
return {
|
|
@@ -11668,11 +11868,11 @@ var require_parser = __commonJS({
|
|
|
11668
11868
|
};
|
|
11669
11869
|
return d;
|
|
11670
11870
|
});
|
|
11671
|
-
var Declaration$
|
|
11672
|
-
var Declaration$
|
|
11673
|
-
var Declaration$
|
|
11674
|
-
var Declaration$
|
|
11675
|
-
var Declaration$$ = [Declaration$0, Declaration$1, Declaration$2, Declaration$3, Declaration$4, Declaration$5, Declaration$6];
|
|
11871
|
+
var Declaration$4 = TypeDeclaration;
|
|
11872
|
+
var Declaration$5 = EnumDeclaration;
|
|
11873
|
+
var Declaration$6 = OperatorDeclaration;
|
|
11874
|
+
var Declaration$7 = UsingDeclaration;
|
|
11875
|
+
var Declaration$$ = [Declaration$0, Declaration$1, Declaration$2, Declaration$3, Declaration$4, Declaration$5, Declaration$6, Declaration$7];
|
|
11676
11876
|
function Declaration(ctx, state) {
|
|
11677
11877
|
return $EVENT_C(ctx, state, "Declaration", Declaration$$);
|
|
11678
11878
|
}
|
|
@@ -16414,10 +16614,13 @@ function compile(src, options) {
|
|
|
16414
16614
|
let ast;
|
|
16415
16615
|
try {
|
|
16416
16616
|
import_parser.parse.config = options.parseOptions || {};
|
|
16417
|
-
ast =
|
|
16617
|
+
ast = (0, import_parser.parse)(src, {
|
|
16418
16618
|
filename,
|
|
16419
16619
|
events
|
|
16420
|
-
})
|
|
16620
|
+
});
|
|
16621
|
+
if (!(options.ast === "raw")) {
|
|
16622
|
+
ast = prune(ast);
|
|
16623
|
+
}
|
|
16421
16624
|
} finally {
|
|
16422
16625
|
if (hits || trace) {
|
|
16423
16626
|
import("fs").then(function({ writeFileSync }) {
|
package/dist/types.d.ts
CHANGED
|
@@ -32,8 +32,13 @@ declare module "@danielx/civet" {
|
|
|
32
32
|
}>
|
|
33
33
|
export type CompileOptions = {
|
|
34
34
|
filename?: string
|
|
35
|
-
js?: boolean
|
|
36
35
|
sourceMap?: boolean
|
|
36
|
+
inlineMap?: boolean
|
|
37
|
+
ast?: boolean | "raw"
|
|
38
|
+
js?: boolean
|
|
39
|
+
noCache?: boolean
|
|
40
|
+
hits?: string
|
|
41
|
+
trace?: string
|
|
37
42
|
parseOptions?: ParseOptions
|
|
38
43
|
}
|
|
39
44
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@danielx/civet",
|
|
3
3
|
"type": "commonjs",
|
|
4
|
-
"version": "0.6.
|
|
4
|
+
"version": "0.6.89",
|
|
5
5
|
"description": "CoffeeScript style syntax for TypeScript",
|
|
6
6
|
"main": "dist/main.js",
|
|
7
7
|
"module": "dist/main.mjs",
|
|
@@ -75,7 +75,7 @@
|
|
|
75
75
|
"@prettier/sync": "^0.3.0",
|
|
76
76
|
"@types/assert": "^1.5.6",
|
|
77
77
|
"@types/mocha": "^9.1.1",
|
|
78
|
-
"@types/node": "^20.
|
|
78
|
+
"@types/node": "^20.12.2",
|
|
79
79
|
"c8": "^7.12.0",
|
|
80
80
|
"esbuild": "0.20.0",
|
|
81
81
|
"marked": "^4.2.4",
|
package/register.js
CHANGED
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
|
-
@file Civet CJS registration
|
|
2
|
+
@file Civet CJS and ESM registration
|
|
3
3
|
|
|
4
|
-
`
|
|
5
|
-
|
|
4
|
+
`import`ing this file in Node 20.6.0+ will register the `.civet` extension
|
|
5
|
+
for both ESM `import`s and CJS `require`s.
|
|
6
|
+
|
|
7
|
+
@example
|
|
8
|
+
```bash
|
|
9
|
+
node --import @danielx/civet/register source.civet
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
On older Node, `require`ing this file will register the `.civet` extension
|
|
13
|
+
for CJS `require`s.
|
|
6
14
|
|
|
7
15
|
@example
|
|
8
16
|
```bash
|
|
@@ -10,17 +18,25 @@ node -r @danielx/civet/register source.civet
|
|
|
10
18
|
```
|
|
11
19
|
*/
|
|
12
20
|
|
|
21
|
+
try {
|
|
22
|
+
const { register } = require('node:module');
|
|
23
|
+
const { pathToFileURL } = require('node:url');
|
|
24
|
+
|
|
25
|
+
register('./dist/esm.mjs', pathToFileURL(__filename));
|
|
26
|
+
} catch (e) {}
|
|
27
|
+
|
|
28
|
+
// CJS registration
|
|
13
29
|
if (require.extensions) {
|
|
14
30
|
const fs = require("fs");
|
|
15
31
|
const { compile } = require("./");
|
|
16
32
|
|
|
17
33
|
require.extensions[".civet"] = function (module, filename) {
|
|
18
34
|
const js = compile(fs.readFileSync(filename, 'utf8'), {
|
|
35
|
+
filename,
|
|
19
36
|
js: true,
|
|
20
37
|
inlineMap: true,
|
|
21
38
|
});
|
|
22
39
|
module._compile(js, filename);
|
|
23
|
-
return;
|
|
24
40
|
};
|
|
25
41
|
|
|
26
42
|
try {
|