@danielx/civet 0.8.6 → 0.8.8

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/main.mjs CHANGED
@@ -518,6 +518,7 @@ __export(lib_exports, {
518
518
  hasImportDeclaration: () => hasImportDeclaration,
519
519
  hasYield: () => hasYield,
520
520
  insertTrimmingSpace: () => insertTrimmingSpace,
521
+ isComma: () => isComma,
521
522
  isEmptyBareBlock: () => isEmptyBareBlock,
522
523
  isFunction: () => isFunction,
523
524
  isWhitespaceOrEmpty: () => isWhitespaceOrEmpty,
@@ -2120,6 +2121,9 @@ function serialize(value, context) {
2120
2121
  throw new TypeError("cannot serialize native function");
2121
2122
  }
2122
2123
  if (/^class[\s{]/u.test(string)) {
2124
+ if (!Object.isExtensible(val)) {
2125
+ string = `Object.preventExtensions(${string})`;
2126
+ }
2123
2127
  return string;
2124
2128
  }
2125
2129
  if (stack.has(val)) {
@@ -2147,6 +2151,9 @@ function serialize(value, context) {
2147
2151
  }
2148
2152
  string = `Object.defineProperties(${string},${recurse(props)})`;
2149
2153
  }
2154
+ if (!Object.isExtensible(val)) {
2155
+ string = `Object.preventExtensions(${string})`;
2156
+ }
2150
2157
  stack.delete(val);
2151
2158
  return string;
2152
2159
  } else if (typeof val === "symbol") {
@@ -2300,11 +2307,21 @@ function serialize(value, context) {
2300
2307
  }
2301
2308
 
2302
2309
  // source/parser/function.civet
2310
+ function getTypeArguments(args) {
2311
+ while (typeof args === "object" && args != null && "args" in args) {
2312
+ args = args.args;
2313
+ }
2314
+ if (!Array.isArray(args)) {
2315
+ throw new Error("getTypeArguments could not find relevant array");
2316
+ }
2317
+ return args.filter((a) => typeof a === "object" && a != null && "type" in a && a.type === "TypeArgument");
2318
+ }
2303
2319
  function isVoidType(t) {
2304
- return t?.type === "TypeLiteral" && t.t.type === "VoidType";
2320
+ return typeof t === "object" && t != null && "type" in t && t.type === "TypeLiteral" && "t" in t && typeof t.t === "object" && t.t != null && "type" in t.t && t.t.type === "VoidType";
2305
2321
  }
2306
2322
  function isPromiseVoidType(t) {
2307
- return t?.type === "TypeIdentifier" && t.raw === "Promise" && t.args?.types?.length === 1 && isVoidType(t.args.types[0]);
2323
+ let args;
2324
+ return typeof t === "object" && t != null && "type" in t && t.type === "TypeIdentifier" && "raw" in t && t.raw === "Promise" && (args = getTypeArguments(t.args?.args)).length === 1 && isVoidType(args[0].t);
2308
2325
  }
2309
2326
  function implicitFunctionBlock(f) {
2310
2327
  if (f.abstract || f.block || f.signature?.optional)
@@ -2890,7 +2907,7 @@ function processParams(f) {
2890
2907
  if (isConstructor) {
2891
2908
  const { ancestor } = findAncestor(f, ($5) => $5.type === "ClassExpression");
2892
2909
  if (ancestor != null) {
2893
- const fields = new Set(gatherRecursiveWithinFunction(ancestor, ($6) => $6.type === "FieldDefinition").map(($7) => $7.id).filter((a) => typeof a === "object" && a != null && "type" in a && a.type === "Identifier").map(($8) => $8.name));
2910
+ const fields = new Set(gatherRecursiveWithinFunction(ancestor, ($6) => $6.type === "FieldDefinition").map(($7) => $7.id).filter((a1) => typeof a1 === "object" && a1 != null && "type" in a1 && a1.type === "Identifier").map(($8) => $8.name));
2894
2911
  const classExpressions = ancestor.body.expressions;
2895
2912
  let index = findChildIndex(classExpressions, f);
2896
2913
  assert.notEqual(index, -1, "Could not find constructor in class");
@@ -2942,10 +2959,10 @@ function processParams(f) {
2942
2959
  if (isConstructor) {
2943
2960
  const superCalls = gatherNodes(
2944
2961
  expressions,
2945
- (a1) => typeof a1 === "object" && a1 != null && "type" in a1 && a1.type === "CallExpression" && "children" in a1 && Array.isArray(a1.children) && a1.children.length >= 1 && typeof a1.children[0] === "object" && a1.children[0] != null && "token" in a1.children[0] && a1.children[0].token === "super"
2962
+ (a2) => typeof a2 === "object" && a2 != null && "type" in a2 && a2.type === "CallExpression" && "children" in a2 && Array.isArray(a2.children) && a2.children.length >= 1 && typeof a2.children[0] === "object" && a2.children[0] != null && "token" in a2.children[0] && a2.children[0].token === "super"
2946
2963
  );
2947
2964
  if (superCalls.length) {
2948
- const { child } = findAncestor(superCalls[0], (a2) => a2 === block);
2965
+ const { child } = findAncestor(superCalls[0], (a3) => a3 === block);
2949
2966
  const index = findChildIndex(expressions, child);
2950
2967
  if (index < 0) {
2951
2968
  throw new Error("Could not find super call within top-level expressions");
@@ -2955,6 +2972,7 @@ function processParams(f) {
2955
2972
  }
2956
2973
  }
2957
2974
  expressions.unshift(...prefix);
2975
+ braceBlock(block);
2958
2976
  }
2959
2977
  function processSignature(f) {
2960
2978
  const { block, signature } = f;
@@ -3077,11 +3095,11 @@ function processCoffeeDo(ws, expression) {
3077
3095
  parameter = {
3078
3096
  ...parameter,
3079
3097
  initializer: void 0,
3080
- children: parameter.children.filter((a3) => a3 !== initializer)
3098
+ children: parameter.children.filter((a4) => a4 !== initializer)
3081
3099
  };
3082
3100
  } else {
3083
3101
  args.push(parameter.children.filter(
3084
- (a4) => a4 !== parameter.typeSuffix
3102
+ (a5) => a5 !== parameter.typeSuffix
3085
3103
  ));
3086
3104
  }
3087
3105
  }
@@ -3154,7 +3172,7 @@ function makeAmpersandFunction(rhs) {
3154
3172
  }
3155
3173
  if (gatherRecursiveWithinFunction(
3156
3174
  block,
3157
- (a5) => a5 === ref
3175
+ (a6) => a6 === ref
3158
3176
  ).length > 1) {
3159
3177
  fn.ampersandBlock = false;
3160
3178
  }
@@ -7529,6 +7547,8 @@ var grammar = {
7529
7547
  BooleanLiteral,
7530
7548
  _BooleanLiteral,
7531
7549
  CoffeeScriptBooleanLiteral,
7550
+ SymbolLiteral,
7551
+ SymbolElement,
7532
7552
  Identifier,
7533
7553
  IdentifierName,
7534
7554
  IdentifierReference,
@@ -7629,6 +7649,7 @@ var grammar = {
7629
7649
  WhileClause,
7630
7650
  ForStatement,
7631
7651
  ForClause,
7652
+ ForStatementControlWithWhen,
7632
7653
  ForStatementControl,
7633
7654
  WhenCondition,
7634
7655
  CoffeeForStatementParameters,
@@ -8051,6 +8072,7 @@ var grammar = {
8051
8072
  NestedTypeArgumentList,
8052
8073
  NestedTypeArgument,
8053
8074
  SingleLineTypeArgumentList,
8075
+ WTypeArgument,
8054
8076
  TypeArgumentDelimited,
8055
8077
  TypeArgument,
8056
8078
  TypeArgumentDelimiter,
@@ -8912,10 +8934,10 @@ var RHS$$ = [RHS$0, RHS$1];
8912
8934
  function RHS(ctx, state2) {
8913
8935
  return (0, import_lib4.$EVENT_C)(ctx, state2, "RHS", RHS$$);
8914
8936
  }
8915
- var UnaryExpression$0 = (0, import_lib4.$TS)((0, import_lib4.$S)(IndentedApplicationAllowed, (0, import_lib4.$P)(UnaryOp), (0, import_lib4.$C)(ArrayLiteral, NestedArgumentList), (0, import_lib4.$E)(UnaryPostfix)), function($skip, $loc, $0, $1, $2, $3, $4) {
8937
+ var UnaryExpression$0 = (0, import_lib4.$TS)((0, import_lib4.$S)(IndentedApplicationAllowed, (0, import_lib4.$P)(UnaryOp), (0, import_lib4.$C)(ArrayLiteral, NestedArgumentList), (0, import_lib4.$N)(CallExpressionRest), (0, import_lib4.$E)(UnaryPostfix)), function($skip, $loc, $0, $1, $2, $3, $4, $5) {
8916
8938
  var pre = $2;
8917
8939
  var args = $3;
8918
- var post = $4;
8940
+ var post = $5;
8919
8941
  return processUnaryNestedExpression(pre, args, post) ?? $skip;
8920
8942
  });
8921
8943
  var UnaryExpression$1 = (0, import_lib4.$TS)((0, import_lib4.$S)((0, import_lib4.$Q)(UnaryOp), UnaryBody, (0, import_lib4.$E)(UnaryPostfix)), function($skip, $loc, $0, $1, $2, $3) {
@@ -9362,8 +9384,9 @@ var PrimaryExpression$7 = ClassExpression;
9362
9384
  var PrimaryExpression$8 = RegularExpressionLiteral;
9363
9385
  var PrimaryExpression$9 = ParenthesizedExpression;
9364
9386
  var PrimaryExpression$10 = Placeholder;
9365
- var PrimaryExpression$11 = JSXImplicitFragment;
9366
- var PrimaryExpression$$ = [PrimaryExpression$0, PrimaryExpression$1, PrimaryExpression$2, PrimaryExpression$3, PrimaryExpression$4, PrimaryExpression$5, PrimaryExpression$6, PrimaryExpression$7, PrimaryExpression$8, PrimaryExpression$9, PrimaryExpression$10, PrimaryExpression$11];
9387
+ var PrimaryExpression$11 = SymbolLiteral;
9388
+ var PrimaryExpression$12 = JSXImplicitFragment;
9389
+ var PrimaryExpression$$ = [PrimaryExpression$0, PrimaryExpression$1, PrimaryExpression$2, PrimaryExpression$3, PrimaryExpression$4, PrimaryExpression$5, PrimaryExpression$6, PrimaryExpression$7, PrimaryExpression$8, PrimaryExpression$9, PrimaryExpression$10, PrimaryExpression$11, PrimaryExpression$12];
9367
9390
  function PrimaryExpression(ctx, state2) {
9368
9391
  return (0, import_lib4.$EVENT_C)(ctx, state2, "PrimaryExpression", PrimaryExpression$$);
9369
9392
  }
@@ -10192,7 +10215,7 @@ var PropertyAccessModifier$$ = [PropertyAccessModifier$0, PropertyAccessModifier
10192
10215
  function PropertyAccessModifier(ctx, state2) {
10193
10216
  return (0, import_lib4.$EVENT_C)(ctx, state2, "PropertyAccessModifier", PropertyAccessModifier$$);
10194
10217
  }
10195
- var PropertyAccess$0 = (0, import_lib4.$TS)((0, import_lib4.$S)(AccessStart, (0, import_lib4.$C)(TemplateLiteral, StringLiteral, IntegerLiteral)), function($skip, $loc, $0, $1, $2) {
10218
+ var PropertyAccess$0 = (0, import_lib4.$TS)((0, import_lib4.$S)(AccessStart, (0, import_lib4.$C)(TemplateLiteral, StringLiteral, IntegerLiteral, SymbolLiteral)), function($skip, $loc, $0, $1, $2) {
10196
10219
  var dot = $1;
10197
10220
  var literal = $2;
10198
10221
  return {
@@ -11736,6 +11759,40 @@ var CoffeeScriptBooleanLiteral$$ = [CoffeeScriptBooleanLiteral$0, CoffeeScriptBo
11736
11759
  function CoffeeScriptBooleanLiteral(ctx, state2) {
11737
11760
  return (0, import_lib4.$EVENT_C)(ctx, state2, "CoffeeScriptBooleanLiteral", CoffeeScriptBooleanLiteral$$);
11738
11761
  }
11762
+ var SymbolLiteral$0 = (0, import_lib4.$TS)((0, import_lib4.$S)(Colon, IdentifierName), function($skip, $loc, $0, $1, $2) {
11763
+ var colon = $1;
11764
+ var id = $2;
11765
+ const { name, children: [token] } = id;
11766
+ if (config.symbols.includes(name)) {
11767
+ return {
11768
+ type: "SymbolLiteral",
11769
+ children: [
11770
+ { ...colon, token: "Symbol." },
11771
+ token
11772
+ ],
11773
+ name
11774
+ };
11775
+ } else {
11776
+ return {
11777
+ type: "SymbolLiteral",
11778
+ children: [
11779
+ { ...colon, token: 'Symbol.for("' },
11780
+ token,
11781
+ '")'
11782
+ ],
11783
+ name
11784
+ };
11785
+ }
11786
+ });
11787
+ function SymbolLiteral(ctx, state2) {
11788
+ return (0, import_lib4.$EVENT)(ctx, state2, "SymbolLiteral", SymbolLiteral$0);
11789
+ }
11790
+ var SymbolElement$0 = (0, import_lib4.$T)((0, import_lib4.$S)(SymbolLiteral), function(value) {
11791
+ return ["[", value[0], "]"];
11792
+ });
11793
+ function SymbolElement(ctx, state2) {
11794
+ return (0, import_lib4.$EVENT)(ctx, state2, "SymbolElement", SymbolElement$0);
11795
+ }
11739
11796
  var Identifier$0 = (0, import_lib4.$T)((0, import_lib4.$S)((0, import_lib4.$EXPECT)($R17, "Identifier /(?=\\p{ID_Start}|[_$])/"), (0, import_lib4.$N)(ReservedWord), IdentifierName), function(value) {
11740
11797
  var id = value[2];
11741
11798
  return id;
@@ -12483,7 +12540,8 @@ var PropertyName$3 = (0, import_lib4.$TV)((0, import_lib4.$TEXT)((0, import_lib4
12483
12540
  });
12484
12541
  var PropertyName$4 = IdentifierName;
12485
12542
  var PropertyName$5 = LengthShorthand;
12486
- var PropertyName$$ = [PropertyName$0, PropertyName$1, PropertyName$2, PropertyName$3, PropertyName$4, PropertyName$5];
12543
+ var PropertyName$6 = SymbolElement;
12544
+ var PropertyName$$ = [PropertyName$0, PropertyName$1, PropertyName$2, PropertyName$3, PropertyName$4, PropertyName$5, PropertyName$6];
12487
12545
  function PropertyName(ctx, state2) {
12488
12546
  return (0, import_lib4.$EVENT_C)(ctx, state2, "PropertyName", PropertyName$$);
12489
12547
  }
@@ -12745,7 +12803,8 @@ function MethodSignature(ctx, state2) {
12745
12803
  var ClassElementName$0 = PropertyName;
12746
12804
  var ClassElementName$1 = LengthShorthand;
12747
12805
  var ClassElementName$2 = PrivateIdentifier;
12748
- var ClassElementName$$ = [ClassElementName$0, ClassElementName$1, ClassElementName$2];
12806
+ var ClassElementName$3 = SymbolElement;
12807
+ var ClassElementName$$ = [ClassElementName$0, ClassElementName$1, ClassElementName$2, ClassElementName$3];
12749
12808
  function ClassElementName(ctx, state2) {
12750
12809
  return (0, import_lib4.$EVENT_C)(ctx, state2, "ClassElementName", ClassElementName$$);
12751
12810
  }
@@ -13702,7 +13761,7 @@ var ForStatement$0 = (0, import_lib4.$TS)((0, import_lib4.$S)(ForClause, BlockOr
13702
13761
  function ForStatement(ctx, state2) {
13703
13762
  return (0, import_lib4.$EVENT)(ctx, state2, "ForStatement", ForStatement$0);
13704
13763
  }
13705
- var ForClause$0 = (0, import_lib4.$TS)((0, import_lib4.$S)(For, (0, import_lib4.$E)((0, import_lib4.$S)((0, import_lib4.$E)(_), Star)), __, ForStatementControl), function($skip, $loc, $0, $1, $2, $3, $4) {
13764
+ var ForClause$0 = (0, import_lib4.$TS)((0, import_lib4.$S)(For, (0, import_lib4.$E)((0, import_lib4.$S)((0, import_lib4.$E)(_), Star)), __, ForStatementControlWithWhen), function($skip, $loc, $0, $1, $2, $3, $4) {
13706
13765
  var generator = $2;
13707
13766
  var c = $4;
13708
13767
  const { children, declaration } = c;
@@ -13719,26 +13778,41 @@ var ForClause$0 = (0, import_lib4.$TS)((0, import_lib4.$S)(For, (0, import_lib4.
13719
13778
  function ForClause(ctx, state2) {
13720
13779
  return (0, import_lib4.$EVENT)(ctx, state2, "ForClause", ForClause$0);
13721
13780
  }
13781
+ var ForStatementControlWithWhen$0 = (0, import_lib4.$TS)((0, import_lib4.$S)(ForStatementControl, (0, import_lib4.$E)(WhenCondition)), function($skip, $loc, $0, $1, $2) {
13782
+ var control = $1;
13783
+ var condition = $2;
13784
+ if (!condition)
13785
+ return control;
13786
+ const expressions = [["", {
13787
+ type: "ContinueStatement",
13788
+ children: ["continue"]
13789
+ }]];
13790
+ const block = {
13791
+ type: "BlockStatement",
13792
+ expressions,
13793
+ children: [expressions],
13794
+ bare: true
13795
+ };
13796
+ return {
13797
+ ...control,
13798
+ blockPrefix: [
13799
+ ...control.blockPrefix,
13800
+ ["", {
13801
+ type: "IfStatement",
13802
+ then: block,
13803
+ children: ["if (!", makeLeftHandSideExpression(trimFirstSpace(condition)), ") ", block]
13804
+ }, ";"]
13805
+ ]
13806
+ };
13807
+ });
13808
+ function ForStatementControlWithWhen(ctx, state2) {
13809
+ return (0, import_lib4.$EVENT)(ctx, state2, "ForStatementControlWithWhen", ForStatementControlWithWhen$0);
13810
+ }
13722
13811
  var ForStatementControl$0 = (0, import_lib4.$T)((0, import_lib4.$S)((0, import_lib4.$N)(CoffeeForLoopsEnabled), ForStatementParameters), function(value) {
13723
13812
  return value[1];
13724
13813
  });
13725
- var ForStatementControl$1 = (0, import_lib4.$TS)((0, import_lib4.$S)(CoffeeForLoopsEnabled, CoffeeForStatementParameters, (0, import_lib4.$E)(WhenCondition)), function($skip, $loc, $0, $1, $2, $3) {
13726
- var condition = $3;
13727
- if (condition) {
13728
- const block = "continue";
13729
- $2 = {
13730
- ...$2,
13731
- blockPrefix: [
13732
- ...$2.blockPrefix,
13733
- ["", {
13734
- type: "IfStatement",
13735
- then: block,
13736
- children: ["if (!(", trimFirstSpace(condition), ")) ", block]
13737
- }, ";"]
13738
- ]
13739
- };
13740
- }
13741
- return $2;
13814
+ var ForStatementControl$1 = (0, import_lib4.$T)((0, import_lib4.$S)(CoffeeForLoopsEnabled, CoffeeForStatementParameters), function(value) {
13815
+ return value[1];
13742
13816
  });
13743
13817
  var ForStatementControl$$ = [ForStatementControl$0, ForStatementControl$1];
13744
13818
  function ForStatementControl(ctx, state2) {
@@ -18318,11 +18392,12 @@ function TypeArrowFunction(ctx, state2) {
18318
18392
  }
18319
18393
  var TypeArguments$0 = (0, import_lib4.$TS)((0, import_lib4.$S)(OpenAngleBracket, (0, import_lib4.$P)((0, import_lib4.$S)(__, TypeArgumentDelimited)), __, CloseAngleBracket), function($skip, $loc, $0, $1, $2, $3, $4) {
18320
18394
  var args = $2;
18321
- args = args.map(([ws, arg]) => [ws, ...arg]);
18395
+ args = args.flatMap(([ws, [arg, delim]]) => [prepend(ws, arg), delim]);
18396
+ args.pop();
18322
18397
  return {
18323
18398
  type: "TypeArguments",
18324
18399
  ts: true,
18325
- types: args.map(([, t]) => t),
18400
+ args,
18326
18401
  children: $0
18327
18402
  };
18328
18403
  });
@@ -18334,10 +18409,15 @@ var ImplicitTypeArguments$0 = (0, import_lib4.$TS)((0, import_lib4.$S)(TypeAppli
18334
18409
  var ws = $3;
18335
18410
  var args = $4;
18336
18411
  var close = $5;
18337
- let last = args[args.length - 1];
18338
- if (last?.token === ",")
18412
+ const last = args[args.length - 1];
18413
+ if (isComma(last))
18339
18414
  args = args.slice(0, -1);
18340
- return [open, ws, args, close];
18415
+ return {
18416
+ type: "TypeArguments",
18417
+ ts: true,
18418
+ args,
18419
+ children: [open, ws, args, close]
18420
+ };
18341
18421
  });
18342
18422
  function ImplicitTypeArguments(ctx, state2) {
18343
18423
  return (0, import_lib4.$EVENT)(ctx, state2, "ImplicitTypeArguments", ImplicitTypeArguments$0);
@@ -18355,10 +18435,10 @@ var ForbiddenImplicitTypeCalls$$ = [ForbiddenImplicitTypeCalls$0, ForbiddenImpli
18355
18435
  function ForbiddenImplicitTypeCalls(ctx, state2) {
18356
18436
  return (0, import_lib4.$EVENT_C)(ctx, state2, "ForbiddenImplicitTypeCalls", ForbiddenImplicitTypeCalls$$);
18357
18437
  }
18358
- var TypeArgumentList$0 = (0, import_lib4.$TS)((0, import_lib4.$S)((0, import_lib4.$N)(EOS), TypeArgument, (0, import_lib4.$Q)((0, import_lib4.$S)(CommaDelimiter, (0, import_lib4.$N)(EOS), (0, import_lib4.$E)(_), TypeArgument)), (0, import_lib4.$P)((0, import_lib4.$S)(CommaDelimiter, (0, import_lib4.$C)(NestedTypeBulletedTuple, NestedInterfaceBlock, NestedTypeArgumentList)))), function($skip, $loc, $0, $1, $2, $3, $4) {
18438
+ var TypeArgumentList$0 = (0, import_lib4.$TS)((0, import_lib4.$S)((0, import_lib4.$N)(EOS), TypeArgument, (0, import_lib4.$Q)((0, import_lib4.$S)(CommaDelimiter, (0, import_lib4.$N)(EOS), WTypeArgument)), (0, import_lib4.$P)((0, import_lib4.$S)(CommaDelimiter, (0, import_lib4.$C)(NestedTypeBulletedTuple, NestedInterfaceBlock, NestedTypeArgumentList)))), function($skip, $loc, $0, $1, $2, $3, $4) {
18359
18439
  return [
18360
18440
  $2,
18361
- ...$3.flatMap(([comma, eos, ws, arg]) => [comma, prepend(ws, arg)]),
18441
+ ...$3.flatMap(([comma, eos, arg]) => [comma, arg]),
18362
18442
  ...$4.flatMap(
18363
18443
  ([comma, args]) => Array.isArray(args) ? [comma, ...args] : [comma, args]
18364
18444
  )
@@ -18373,10 +18453,10 @@ var TypeArgumentList$1 = (0, import_lib4.$TS)((0, import_lib4.$S)((0, import_lib
18373
18453
  ];
18374
18454
  });
18375
18455
  var TypeArgumentList$2 = NestedTypeArgumentList;
18376
- var TypeArgumentList$3 = (0, import_lib4.$TS)((0, import_lib4.$S)(TypeArgument, (0, import_lib4.$Q)((0, import_lib4.$S)(CommaDelimiter, (0, import_lib4.$E)(_), TypeArgument))), function($skip, $loc, $0, $1, $2) {
18456
+ var TypeArgumentList$3 = (0, import_lib4.$TS)((0, import_lib4.$S)(TypeArgument, (0, import_lib4.$Q)((0, import_lib4.$S)(CommaDelimiter, WTypeArgument))), function($skip, $loc, $0, $1, $2) {
18377
18457
  return [
18378
18458
  $1,
18379
- ...$2.flatMap(([comma, ws, arg]) => [comma, prepend(ws, arg)])
18459
+ ...$2.flatMap(([comma, arg]) => [comma, arg])
18380
18460
  ];
18381
18461
  });
18382
18462
  var TypeArgumentList$$ = [TypeArgumentList$0, TypeArgumentList$1, TypeArgumentList$2, TypeArgumentList$3];
@@ -18403,17 +18483,25 @@ var NestedTypeArgument$0 = (0, import_lib4.$TS)((0, import_lib4.$S)(Nested, Sing
18403
18483
  function NestedTypeArgument(ctx, state2) {
18404
18484
  return (0, import_lib4.$EVENT)(ctx, state2, "NestedTypeArgument", NestedTypeArgument$0);
18405
18485
  }
18406
- var SingleLineTypeArgumentList$0 = (0, import_lib4.$TS)((0, import_lib4.$S)((0, import_lib4.$S)((0, import_lib4.$E)(_), TypeArgument), (0, import_lib4.$Q)((0, import_lib4.$S)((0, import_lib4.$S)((0, import_lib4.$E)(_), Comma), (0, import_lib4.$S)((0, import_lib4.$E)(_), TypeArgument)))), function($skip, $loc, $0, $1, $2) {
18407
- return [$1, ...$2.flat()];
18486
+ var SingleLineTypeArgumentList$0 = (0, import_lib4.$TS)((0, import_lib4.$S)(WTypeArgument, (0, import_lib4.$Q)((0, import_lib4.$S)((0, import_lib4.$S)((0, import_lib4.$E)(_), Comma), WTypeArgument))), function($skip, $loc, $0, $1, $2) {
18487
+ return [$1, ...$2];
18408
18488
  });
18409
18489
  function SingleLineTypeArgumentList(ctx, state2) {
18410
18490
  return (0, import_lib4.$EVENT)(ctx, state2, "SingleLineTypeArgumentList", SingleLineTypeArgumentList$0);
18411
18491
  }
18492
+ var WTypeArgument$0 = (0, import_lib4.$TS)((0, import_lib4.$S)((0, import_lib4.$E)(_), TypeArgument), function($skip, $loc, $0, $1, $2) {
18493
+ return prepend($1, $2);
18494
+ });
18495
+ function WTypeArgument(ctx, state2) {
18496
+ return (0, import_lib4.$EVENT)(ctx, state2, "WTypeArgument", WTypeArgument$0);
18497
+ }
18412
18498
  var TypeArgumentDelimited$0 = (0, import_lib4.$S)(TypeArgument, TypeArgumentDelimiter);
18413
18499
  function TypeArgumentDelimited(ctx, state2) {
18414
18500
  return (0, import_lib4.$EVENT)(ctx, state2, "TypeArgumentDelimited", TypeArgumentDelimited$0);
18415
18501
  }
18416
- var TypeArgument$0 = Type;
18502
+ var TypeArgument$0 = (0, import_lib4.$T)(Type, function(value) {
18503
+ return { "type": "TypeArgument", "ts": true, "t": value, "children": [value] };
18504
+ });
18417
18505
  function TypeArgument(ctx, state2) {
18418
18506
  return (0, import_lib4.$EVENT)(ctx, state2, "TypeArgument", TypeArgument$0);
18419
18507
  }
@@ -18501,6 +18589,7 @@ var CivetOption$0 = (0, import_lib4.$TR)((0, import_lib4.$EXPECT)($R96, "CivetOp
18501
18589
  value = 0;
18502
18590
  break;
18503
18591
  case "globals":
18592
+ case "symbols":
18504
18593
  value = value.split(",").filter(Boolean);
18505
18594
  break;
18506
18595
  }
@@ -18876,6 +18965,7 @@ var Reset$0 = (0, import_lib4.$TV)((0, import_lib4.$EXPECT)($L0, 'Reset ""'), fu
18876
18965
  repl: false,
18877
18966
  rewriteTsImports: true,
18878
18967
  server: false,
18968
+ symbols: wellKnownSymbols,
18879
18969
  tab: void 0,
18880
18970
  // default behavior = same as space
18881
18971
  verbose: false
@@ -19172,6 +19262,21 @@ function parseProgram(input, options) {
19172
19262
  });
19173
19263
  }
19174
19264
  }
19265
+ var wellKnownSymbols = [
19266
+ "asyncIterator",
19267
+ "hasInstance",
19268
+ "isConcatSpreadable",
19269
+ "iterator",
19270
+ "match",
19271
+ "matchAll",
19272
+ "replace",
19273
+ "search",
19274
+ "species",
19275
+ "split",
19276
+ "toPrimitive",
19277
+ "toStringTag",
19278
+ "unscopables"
19279
+ ];
19175
19280
 
19176
19281
  // source/sourcemap.civet
19177
19282
  var sourcemap_exports = {};
package/dist/types.d.ts CHANGED
@@ -30,6 +30,7 @@ declare module "@danielx/civet" {
30
30
  rewriteCivetImports: string
31
31
  rewriteTsImports: boolean
32
32
  server: boolean
33
+ symbols: string[]
33
34
  tab: number
34
35
  verbose: boolean
35
36
  comptime: boolean
@@ -105,6 +105,7 @@ var rawPlugin = (options = {}, meta) => {
105
105
  const transformTS = options.emitDeclaration || options.typecheck;
106
106
  const outExt = options.outputExtension ?? (options.ts === "preserve" ? ".tsx" : ".jsx");
107
107
  const implicitExtension = options.implicitExtension ?? true;
108
+ let aliasResolver;
108
109
  let fsMap = /* @__PURE__ */ new Map();
109
110
  const sourceMaps = /* @__PURE__ */ new Map();
110
111
  let compilerOptions, compilerOptionsWithSourceMap;
@@ -121,7 +122,7 @@ var rawPlugin = (options = {}, meta) => {
121
122
  };
122
123
  };
123
124
  const cache = options.cache ? /* @__PURE__ */ new Map() : void 0;
124
- return {
125
+ const plugin = {
125
126
  name: "unplugin-civet",
126
127
  enforce: "pre",
127
128
  async buildStart() {
@@ -375,8 +376,14 @@ var rawPlugin = (options = {}, meta) => {
375
376
  }
376
377
  },
377
378
  resolveId(id, importer, options2) {
379
+ if (aliasResolver != null) {
380
+ id = aliasResolver(id);
381
+ }
378
382
  if (/\0/.test(id))
379
383
  return null;
384
+ if (plugin.__virtualModulePrefix && importer?.startsWith(plugin.__virtualModulePrefix)) {
385
+ importer = decodeURIComponent(importer.slice(plugin.__virtualModulePrefix.length));
386
+ }
380
387
  let postfix;
381
388
  ({ id, postfix } = cleanCivetId(id));
382
389
  let ref1;
@@ -519,35 +526,28 @@ var rawPlugin = (options = {}, meta) => {
519
526
  config.resolve.extensions ??= DEFAULT_EXTENSIONS;
520
527
  config.resolve.extensions.push(".civet");
521
528
  }
522
- ;
523
- return;
524
529
  },
525
530
  async transformIndexHtml(html) {
526
- return html.replace(
527
- /<!--[^]*?-->|<[^<>]*>/g,
528
- (tag) => {
529
- return tag.replace(
530
- /<\s*script\b[^<>]*>/gi,
531
- (script) => {
532
- return script.replace(
533
- /([:_\p{ID_Start}][:\p{ID_Continue}]*)(\s*=\s*("[^"]*"|'[^']*'|[^\s"'=<>`]*))?/gu,
534
- (attr, name, value) => {
535
- return name.toLowerCase() === "src" && value ? attr.replace(
536
- /(\.civet)(['"]?)$/,
537
- (_, extension, endQuote) => {
538
- return `${extension}${outExt}?transform${endQuote}`;
539
- }
540
- ) : attr;
531
+ return html.replace(/<!--[^]*?-->|<[^<>]*>/g, (tag) => {
532
+ return tag.replace(/<\s*script\b[^<>]*>/gi, (script) => {
533
+ return script.replace(
534
+ /([:_\p{ID_Start}][:\p{ID_Continue}]*)(\s*=\s*("[^"]*"|'[^']*'|[^\s"'=<>`]*))?/gu,
535
+ (attr, name, value) => {
536
+ return name.toLowerCase() === "src" && value ? attr.replace(
537
+ /(\.civet)(['"]?)$/,
538
+ (_, extension, endQuote) => {
539
+ return `${extension}${outExt}?transform${endQuote}`;
541
540
  }
542
- );
541
+ ) : attr;
543
542
  }
544
543
  );
545
- }
546
- );
544
+ });
545
+ });
547
546
  },
548
547
  handleHotUpdate({ file, server, modules }) {
549
- if (!file.endsWith(".civet"))
548
+ if (!file.endsWith(".civet")) {
550
549
  return;
550
+ }
551
551
  const resolvedId = slash(import_path.default.resolve(file) + outExt);
552
552
  const module2 = server.moduleGraph.getModuleById(resolvedId);
553
553
  if (module2) {
@@ -556,8 +556,33 @@ var rawPlugin = (options = {}, meta) => {
556
556
  }
557
557
  return modules;
558
558
  }
559
+ },
560
+ webpack(compiler) {
561
+ if (implicitExtension) {
562
+ compiler.options.resolve.extensions.unshift(".civet");
563
+ }
564
+ return aliasResolver = (id) => {
565
+ let ref2;
566
+ for (const key in ref2 = compiler.options.resolve.alias) {
567
+ const value = ref2[key];
568
+ if (key.endsWith("$")) {
569
+ if (id === key.slice(0, -1)) {
570
+ return typeof value === "string" ? value : "\0";
571
+ }
572
+ } else {
573
+ if (id === key || id.startsWith(key + "/")) {
574
+ if (!(typeof value === "string")) {
575
+ return "\0";
576
+ }
577
+ return value + id.slice(key.length);
578
+ }
579
+ }
580
+ }
581
+ return id;
582
+ };
559
583
  }
560
584
  };
585
+ return plugin;
561
586
  };
562
587
  var unplugin = (0, import_unplugin.createUnplugin)(rawPlugin);
563
588
  var unplugin_civet_default = unplugin;
@@ -73,6 +73,7 @@ var rawPlugin = (options = {}, meta) => {
73
73
  const transformTS = options.emitDeclaration || options.typecheck;
74
74
  const outExt = options.outputExtension ?? (options.ts === "preserve" ? ".tsx" : ".jsx");
75
75
  const implicitExtension = options.implicitExtension ?? true;
76
+ let aliasResolver;
76
77
  let fsMap = /* @__PURE__ */ new Map();
77
78
  const sourceMaps = /* @__PURE__ */ new Map();
78
79
  let compilerOptions, compilerOptionsWithSourceMap;
@@ -89,7 +90,7 @@ var rawPlugin = (options = {}, meta) => {
89
90
  };
90
91
  };
91
92
  const cache = options.cache ? /* @__PURE__ */ new Map() : void 0;
92
- return {
93
+ const plugin = {
93
94
  name: "unplugin-civet",
94
95
  enforce: "pre",
95
96
  async buildStart() {
@@ -343,8 +344,14 @@ var rawPlugin = (options = {}, meta) => {
343
344
  }
344
345
  },
345
346
  resolveId(id, importer, options2) {
347
+ if (aliasResolver != null) {
348
+ id = aliasResolver(id);
349
+ }
346
350
  if (/\0/.test(id))
347
351
  return null;
352
+ if (plugin.__virtualModulePrefix && importer?.startsWith(plugin.__virtualModulePrefix)) {
353
+ importer = decodeURIComponent(importer.slice(plugin.__virtualModulePrefix.length));
354
+ }
348
355
  let postfix;
349
356
  ({ id, postfix } = cleanCivetId(id));
350
357
  let ref1;
@@ -487,35 +494,28 @@ var rawPlugin = (options = {}, meta) => {
487
494
  config.resolve.extensions ??= DEFAULT_EXTENSIONS;
488
495
  config.resolve.extensions.push(".civet");
489
496
  }
490
- ;
491
- return;
492
497
  },
493
498
  async transformIndexHtml(html) {
494
- return html.replace(
495
- /<!--[^]*?-->|<[^<>]*>/g,
496
- (tag) => {
497
- return tag.replace(
498
- /<\s*script\b[^<>]*>/gi,
499
- (script) => {
500
- return script.replace(
501
- /([:_\p{ID_Start}][:\p{ID_Continue}]*)(\s*=\s*("[^"]*"|'[^']*'|[^\s"'=<>`]*))?/gu,
502
- (attr, name, value) => {
503
- return name.toLowerCase() === "src" && value ? attr.replace(
504
- /(\.civet)(['"]?)$/,
505
- (_, extension, endQuote) => {
506
- return `${extension}${outExt}?transform${endQuote}`;
507
- }
508
- ) : attr;
499
+ return html.replace(/<!--[^]*?-->|<[^<>]*>/g, (tag) => {
500
+ return tag.replace(/<\s*script\b[^<>]*>/gi, (script) => {
501
+ return script.replace(
502
+ /([:_\p{ID_Start}][:\p{ID_Continue}]*)(\s*=\s*("[^"]*"|'[^']*'|[^\s"'=<>`]*))?/gu,
503
+ (attr, name, value) => {
504
+ return name.toLowerCase() === "src" && value ? attr.replace(
505
+ /(\.civet)(['"]?)$/,
506
+ (_, extension, endQuote) => {
507
+ return `${extension}${outExt}?transform${endQuote}`;
509
508
  }
510
- );
509
+ ) : attr;
511
510
  }
512
511
  );
513
- }
514
- );
512
+ });
513
+ });
515
514
  },
516
515
  handleHotUpdate({ file, server, modules }) {
517
- if (!file.endsWith(".civet"))
516
+ if (!file.endsWith(".civet")) {
518
517
  return;
518
+ }
519
519
  const resolvedId = slash(path.resolve(file) + outExt);
520
520
  const module = server.moduleGraph.getModuleById(resolvedId);
521
521
  if (module) {
@@ -524,8 +524,33 @@ var rawPlugin = (options = {}, meta) => {
524
524
  }
525
525
  return modules;
526
526
  }
527
+ },
528
+ webpack(compiler) {
529
+ if (implicitExtension) {
530
+ compiler.options.resolve.extensions.unshift(".civet");
531
+ }
532
+ return aliasResolver = (id) => {
533
+ let ref2;
534
+ for (const key in ref2 = compiler.options.resolve.alias) {
535
+ const value = ref2[key];
536
+ if (key.endsWith("$")) {
537
+ if (id === key.slice(0, -1)) {
538
+ return typeof value === "string" ? value : "\0";
539
+ }
540
+ } else {
541
+ if (id === key || id.startsWith(key + "/")) {
542
+ if (!(typeof value === "string")) {
543
+ return "\0";
544
+ }
545
+ return value + id.slice(key.length);
546
+ }
547
+ }
548
+ }
549
+ return id;
550
+ };
527
551
  }
528
552
  };
553
+ return plugin;
529
554
  };
530
555
  var unplugin = createUnplugin(rawPlugin);
531
556
  var unplugin_civet_default = unplugin;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@danielx/civet",
3
3
  "type": "commonjs",
4
- "version": "0.8.6",
4
+ "version": "0.8.8",
5
5
  "description": "CoffeeScript style syntax for TypeScript",
6
6
  "main": "dist/main.js",
7
7
  "module": "dist/main.mjs",