@danielx/civet 0.10.4 → 0.10.6

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
@@ -496,6 +496,8 @@ __export(lib_civet_exports, {
496
496
  blockWithPrefix: () => blockWithPrefix,
497
497
  braceBlock: () => braceBlock,
498
498
  bracedBlock: () => bracedBlock,
499
+ convertArrowFunctionToMethod: () => convertArrowFunctionToMethod,
500
+ convertFunctionToMethod: () => convertFunctionToMethod,
499
501
  convertNamedImportsToObject: () => convertNamedImportsToObject,
500
502
  convertObjectToJSXAttributes: () => convertObjectToJSXAttributes,
501
503
  convertWithClause: () => convertWithClause,
@@ -6780,7 +6782,7 @@ function createVarDecs(block, scopes, pushVar) {
6780
6782
  findAssignments(assignmentStatements2.map((s) => s.children), decs2)
6781
6783
  );
6782
6784
  }
6783
- return assignmentStatements2;
6785
+ return assignmentStatements2.filter(($4) => !($4.parent?.type === "CoffeeClassPublic"));
6784
6786
  }
6785
6787
  pushVar ??= (name) => {
6786
6788
  varIds.push(name);
@@ -6791,7 +6793,7 @@ function createVarDecs(block, scopes, pushVar) {
6791
6793
  scopes.push(decs);
6792
6794
  const varIds = [];
6793
6795
  const assignmentStatements = findAssignments(statements, scopes);
6794
- const undeclaredIdentifiers = assignmentStatements.flatMap(($4) => $4?.names || []);
6796
+ const undeclaredIdentifiers = assignmentStatements.flatMap(($5) => $5?.names || []);
6795
6797
  undeclaredIdentifiers.filter((x, i, a) => {
6796
6798
  if (!hasDec(x)) return a.indexOf(x) === i;
6797
6799
  return;
@@ -7669,6 +7671,45 @@ function convertMethodToFunction(method) {
7669
7671
  block
7670
7672
  };
7671
7673
  }
7674
+ function convertFunctionToMethod(id, exp) {
7675
+ const fnTokenIndex = exp.children.findIndex(function(c) {
7676
+ return c?.token?.startsWith("function");
7677
+ });
7678
+ const children = exp.children.slice();
7679
+ if (exp.generator) {
7680
+ children.splice(fnTokenIndex, 2, children[fnTokenIndex + 1], id);
7681
+ } else {
7682
+ children.splice(fnTokenIndex, 1, id);
7683
+ }
7684
+ return {
7685
+ ...exp,
7686
+ type: "MethodDefinition",
7687
+ name: id.name,
7688
+ signature: { ...exp.signature, id, name: id.name },
7689
+ children
7690
+ };
7691
+ }
7692
+ function convertArrowFunctionToMethod(id, exp) {
7693
+ const block = { ...exp.block };
7694
+ const children = exp.children.filter(function(c) {
7695
+ return !(Array.isArray(c) && c[c.length - 1]?.token?.includes("=>"));
7696
+ }).map(function(c) {
7697
+ return c === exp.block ? block : c;
7698
+ });
7699
+ children.unshift(id);
7700
+ exp = {
7701
+ ...exp,
7702
+ type: "MethodDefinition",
7703
+ name: id.name,
7704
+ signature: { ...exp.signature, id, name: id.name },
7705
+ block,
7706
+ children,
7707
+ autoBind: true
7708
+ };
7709
+ block.parent = exp;
7710
+ braceBlock(block);
7711
+ return exp;
7712
+ }
7672
7713
  function convertNamedImportsToObject(node, pattern) {
7673
7714
  const properties = node.specifiers.map((specifier) => {
7674
7715
  if (specifier.ts) {
@@ -8453,7 +8494,17 @@ function processCoffeeClasses(statements) {
8453
8494
  })()
8454
8495
  );
8455
8496
  }
8456
- const privates = expressions.filter(($15) => $15[1]?.type === "CoffeeClassPrivate");
8497
+ const public_static_function_assignments = expressions.filter(($15) => $15[1]?.type === "CoffeeClassPublic" && $15[1].assignment?.expression?.type === "FunctionExpression").map(($16) => $16[1].assignment);
8498
+ for (const public_static_function_assignment of public_static_function_assignments) {
8499
+ const id = public_static_function_assignment.lhs[0][1];
8500
+ replaceNode(public_static_function_assignment, convertFunctionToMethod(id, public_static_function_assignment.expression));
8501
+ }
8502
+ const public_static_arrow_function_assignments = expressions.filter(($17) => $17[1]?.type === "CoffeeClassPublic" && $17[1].assignment?.expression?.type === "ArrowFunction").map(($18) => $18[1].assignment);
8503
+ for (const public_static_arrow_function_assignment of public_static_arrow_function_assignments) {
8504
+ const id = public_static_arrow_function_assignment.lhs[0][1];
8505
+ replaceNode(public_static_arrow_function_assignment, convertArrowFunctionToMethod(id, public_static_arrow_function_assignment.expression));
8506
+ }
8507
+ const privates = expressions.filter(($19) => $19[1]?.type === "CoffeeClassPrivate");
8457
8508
  if (!privates.length) {
8458
8509
  continue;
8459
8510
  }
@@ -8518,7 +8569,7 @@ function processProgram(root) {
8518
8569
  root.topLevelYield ? "*" : void 0
8519
8570
  );
8520
8571
  statements = [["", rootIIFE]];
8521
- root.children = root.children.map(($16) => $16 === root.expressions ? statements : $16);
8572
+ root.children = root.children.map(($20) => $20 === root.expressions ? statements : $20);
8522
8573
  root.expressions = statements;
8523
8574
  }
8524
8575
  hoistRefDecs(statements);
@@ -8549,9 +8600,9 @@ async function processProgramAsync(root) {
8549
8600
  await processComptime(statements);
8550
8601
  }
8551
8602
  function processRepl(root, rootIIFE) {
8552
- const topBlock = gatherRecursive(rootIIFE, ($17) => $17.type === "BlockStatement")[0];
8603
+ const topBlock = gatherRecursive(rootIIFE, ($21) => $21.type === "BlockStatement")[0];
8553
8604
  let i = 0;
8554
- for (let ref23 = gatherRecursiveWithinFunction(topBlock, ($18) => $18.type === "Declaration"), i14 = 0, len11 = ref23.length; i14 < len11; i14++) {
8605
+ for (let ref23 = gatherRecursiveWithinFunction(topBlock, ($22) => $22.type === "Declaration"), i14 = 0, len11 = ref23.length; i14 < len11; i14++) {
8555
8606
  const decl = ref23[i14];
8556
8607
  if (!decl.names?.length) {
8557
8608
  continue;
@@ -8565,7 +8616,7 @@ function processRepl(root, rootIIFE) {
8565
8616
  root.expressions.splice(i++, 0, ["", `var ${decl.names.join(",")}`, ";"]);
8566
8617
  }
8567
8618
  }
8568
- for (let ref24 = gatherRecursive(topBlock, ($19) => $19.type === "FunctionExpression"), i15 = 0, len12 = ref24.length; i15 < len12; i15++) {
8619
+ for (let ref24 = gatherRecursive(topBlock, ($23) => $23.type === "FunctionExpression"), i15 = 0, len12 = ref24.length; i15 < len12; i15++) {
8569
8620
  const func = ref24[i15];
8570
8621
  if (func.name && func.parent?.type === "BlockStatement") {
8571
8622
  if (func.parent === topBlock) {
@@ -8578,7 +8629,7 @@ function processRepl(root, rootIIFE) {
8578
8629
  }
8579
8630
  }
8580
8631
  }
8581
- for (let ref25 = gatherRecursiveWithinFunction(topBlock, ($20) => $20.type === "ClassExpression"), i16 = 0, len13 = ref25.length; i16 < len13; i16++) {
8632
+ for (let ref25 = gatherRecursiveWithinFunction(topBlock, ($24) => $24.type === "ClassExpression"), i16 = 0, len13 = ref25.length; i16 < len13; i16++) {
8582
8633
  const classExp = ref25[i16];
8583
8634
  let m8;
8584
8635
  if (classExp.name && classExp.parent === topBlock || (m8 = classExp.parent, typeof m8 === "object" && m8 != null && "type" in m8 && m8.type === "ReturnStatement" && "parent" in m8 && m8.parent === topBlock)) {
@@ -8590,7 +8641,7 @@ function processRepl(root, rootIIFE) {
8590
8641
  function processPlaceholders(statements) {
8591
8642
  const placeholderMap = /* @__PURE__ */ new Map();
8592
8643
  const liftedIfs = /* @__PURE__ */ new Set();
8593
- for (let ref26 = gatherRecursiveAll(statements, ($21) => $21.type === "Placeholder"), i17 = 0, len14 = ref26.length; i17 < len14; i17++) {
8644
+ for (let ref26 = gatherRecursiveAll(statements, ($25) => $25.type === "Placeholder"), i17 = 0, len14 = ref26.length; i17 < len14; i17++) {
8594
8645
  const exp = ref26[i17];
8595
8646
  let ancestor;
8596
8647
  if (exp.subtype === ".") {
@@ -8992,6 +9043,7 @@ var grammar = {
8992
9043
  AccessModifier,
8993
9044
  FieldDefinition,
8994
9045
  ThisLiteral,
9046
+ BasicThisLiteral,
8995
9047
  HashThis,
8996
9048
  LengthShorthand,
8997
9049
  AtThis,
@@ -9977,7 +10029,7 @@ var $R9 = (0, import_lib2.$R)(new RegExp("(?=[\\/?])", "suy"));
9977
10029
  var $R10 = (0, import_lib2.$R)(new RegExp("(?=[\\/\\[{?.!@#'\u2019:])", "suy"));
9978
10030
  var $R11 = (0, import_lib2.$R)(new RegExp("%%?", "suy"));
9979
10031
  var $R12 = (0, import_lib2.$R)(new RegExp("[.\\s]", "suy"));
9980
- var $R13 = (0, import_lib2.$R)(new RegExp("[)}]", "suy"));
10032
+ var $R13 = (0, import_lib2.$R)(new RegExp("[)\\]}]", "suy"));
9981
10033
  var $R14 = (0, import_lib2.$R)(new RegExp("[+-]", "suy"));
9982
10034
  var $R15 = (0, import_lib2.$R)(new RegExp("\\+\\+|--|\u29FA|\u2014|[\\+\\-&]\\S", "suy"));
9983
10035
  var $R16 = (0, import_lib2.$R)(new RegExp(`(?=[0-9.'"tfyno])`, "suy"));
@@ -11357,7 +11409,20 @@ var NestedClassElement$0 = (0, import_lib2.$S)(Nested, ClassElement, StatementDe
11357
11409
  function NestedClassElement(ctx, state2) {
11358
11410
  return (0, import_lib2.$EVENT)(ctx, state2, "NestedClassElement", NestedClassElement$0);
11359
11411
  }
11360
- var ClassElement$0 = (0, import_lib2.$TS)((0, import_lib2.$S)((0, import_lib2.$E)(Decorators), (0, import_lib2.$E)((0, import_lib2.$S)(Declare, (0, import_lib2.$E)(_))), (0, import_lib2.$E)(AccessModifier), (0, import_lib2.$E)((0, import_lib2.$S)(Static, (0, import_lib2.$E)(_))), (0, import_lib2.$E)((0, import_lib2.$S)(Override, (0, import_lib2.$E)(_))), ClassElementDefinition), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6) {
11412
+ var ClassElement$0 = (0, import_lib2.$TS)((0, import_lib2.$S)(CoffeeClassesEnabled, (0, import_lib2.$E)(Decorators), (0, import_lib2.$E)((0, import_lib2.$S)(Declare, (0, import_lib2.$E)(_))), (0, import_lib2.$E)(AccessModifier), (0, import_lib2.$E)((0, import_lib2.$S)(Static, (0, import_lib2.$E)(_))), (0, import_lib2.$E)((0, import_lib2.$S)(Override, (0, import_lib2.$E)(_))), ActualAssignment), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7) {
11413
+ var decorators = $2;
11414
+ var declare = $3;
11415
+ var access = $4;
11416
+ var static_ = $5;
11417
+ var override = $6;
11418
+ var assignment = $7;
11419
+ return {
11420
+ type: static_ ? "CoffeeClassPublic" : "CoffeeClassPrivate",
11421
+ children: [decorators, declare, access, static_, override, assignment],
11422
+ assignment
11423
+ };
11424
+ });
11425
+ var ClassElement$1 = (0, import_lib2.$TS)((0, import_lib2.$S)((0, import_lib2.$E)(Decorators), (0, import_lib2.$E)((0, import_lib2.$S)(Declare, (0, import_lib2.$E)(_))), (0, import_lib2.$E)(AccessModifier), (0, import_lib2.$E)((0, import_lib2.$S)(Static, (0, import_lib2.$E)(_))), (0, import_lib2.$E)((0, import_lib2.$S)(Override, (0, import_lib2.$E)(_))), ClassElementDefinition), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6) {
11361
11426
  var decorators = $1;
11362
11427
  var declare = $2;
11363
11428
  var access = $3;
@@ -11383,14 +11448,14 @@ var ClassElement$0 = (0, import_lib2.$TS)((0, import_lib2.$S)((0, import_lib2.$E
11383
11448
  children: [decorators, declare, access, static_, override, ...definition.children]
11384
11449
  };
11385
11450
  });
11386
- var ClassElement$1 = (0, import_lib2.$TS)((0, import_lib2.$S)(Static, BracedBlock), function($skip, $loc, $0, $1, $2) {
11451
+ var ClassElement$2 = (0, import_lib2.$TS)((0, import_lib2.$S)(Static, BracedBlock), function($skip, $loc, $0, $1, $2) {
11387
11452
  return {
11388
11453
  type: "ClassStaticBlock",
11389
11454
  children: $0
11390
11455
  };
11391
11456
  });
11392
- var ClassElement$2 = EmptyStatement;
11393
- var ClassElement$$ = [ClassElement$0, ClassElement$1, ClassElement$2];
11457
+ var ClassElement$3 = EmptyStatement;
11458
+ var ClassElement$$ = [ClassElement$0, ClassElement$1, ClassElement$2, ClassElement$3];
11394
11459
  function ClassElement(ctx, state2) {
11395
11460
  return (0, import_lib2.$EVENT_C)(ctx, state2, "ClassElement", ClassElement$$);
11396
11461
  }
@@ -11443,37 +11508,10 @@ var FieldDefinition$0 = (0, import_lib2.$TS)((0, import_lib2.$S)(CoffeeClassesEn
11443
11508
  var exp = $6;
11444
11509
  switch (exp.type) {
11445
11510
  case "FunctionExpression": {
11446
- const fnTokenIndex = exp.children.findIndex((c) => c?.token?.startsWith("function"));
11447
- const children = exp.children.slice();
11448
- if (exp.generator) {
11449
- children.splice(fnTokenIndex, 2, children[fnTokenIndex + 1], id);
11450
- } else {
11451
- children.splice(fnTokenIndex, 1, id);
11452
- }
11453
- return {
11454
- ...exp,
11455
- type: "MethodDefinition",
11456
- name: id.name,
11457
- signature: { ...exp.signature, id, name: id.name },
11458
- children
11459
- };
11511
+ return convertFunctionToMethod(id, exp);
11460
11512
  }
11461
11513
  case "ArrowFunction": {
11462
- const block = { ...exp.block };
11463
- const children = exp.children.filter((c) => !(Array.isArray(c) && c[c.length - 1]?.token?.includes("=>"))).map((c) => c === exp.block ? block : c);
11464
- children.unshift(id);
11465
- exp = {
11466
- ...exp,
11467
- type: "MethodDefinition",
11468
- name: id.name,
11469
- signature: { ...exp.signature, id, name: id.name },
11470
- block,
11471
- children,
11472
- autoBind: true
11473
- };
11474
- block.parent = exp;
11475
- braceBlock(block);
11476
- return exp;
11514
+ return convertArrowFunctionToMethod(id, exp);
11477
11515
  }
11478
11516
  default:
11479
11517
  return {
@@ -11500,15 +11538,7 @@ var FieldDefinition$1 = (0, import_lib2.$TS)((0, import_lib2.$S)(InsertReadonly,
11500
11538
  readonly
11501
11539
  };
11502
11540
  });
11503
- var FieldDefinition$2 = (0, import_lib2.$TS)((0, import_lib2.$S)(CoffeeClassesEnabled, ActualAssignment), function($skip, $loc, $0, $1, $2) {
11504
- var assignment = $2;
11505
- return {
11506
- type: "CoffeeClassPrivate",
11507
- children: [assignment],
11508
- assignment
11509
- };
11510
- });
11511
- var FieldDefinition$3 = (0, import_lib2.$TS)((0, import_lib2.$S)((0, import_lib2.$E)((0, import_lib2.$S)(Abstract, (0, import_lib2.$E)(_))), (0, import_lib2.$E)((0, import_lib2.$S)(Readonly, (0, import_lib2.$E)(_))), ClassElementName, (0, import_lib2.$E)(TypeSuffix), (0, import_lib2.$E)(Initializer)), function($skip, $loc, $0, $1, $2, $3, $4, $5) {
11541
+ var FieldDefinition$2 = (0, import_lib2.$TS)((0, import_lib2.$S)((0, import_lib2.$E)((0, import_lib2.$S)(Abstract, (0, import_lib2.$E)(_))), (0, import_lib2.$E)((0, import_lib2.$S)(Readonly, (0, import_lib2.$E)(_))), ClassElementName, (0, import_lib2.$E)(TypeSuffix), (0, import_lib2.$E)(Initializer)), function($skip, $loc, $0, $1, $2, $3, $4, $5) {
11512
11542
  var abstract = $1;
11513
11543
  var readonly = $2;
11514
11544
  var id = $3;
@@ -11525,15 +11555,12 @@ var FieldDefinition$3 = (0, import_lib2.$TS)((0, import_lib2.$S)((0, import_lib2
11525
11555
  initializer
11526
11556
  };
11527
11557
  });
11528
- var FieldDefinition$$ = [FieldDefinition$0, FieldDefinition$1, FieldDefinition$2, FieldDefinition$3];
11558
+ var FieldDefinition$$ = [FieldDefinition$0, FieldDefinition$1, FieldDefinition$2];
11529
11559
  function FieldDefinition(ctx, state2) {
11530
11560
  return (0, import_lib2.$EVENT_C)(ctx, state2, "FieldDefinition", FieldDefinition$$);
11531
11561
  }
11532
- var ThisLiteral$0 = (0, import_lib2.$T)((0, import_lib2.$S)(This), function(value) {
11533
- return { "type": "Identifier", "name": "this", "children": [value[0]] };
11534
- });
11535
- var ThisLiteral$1 = HashThis;
11536
- var ThisLiteral$2 = (0, import_lib2.$TS)((0, import_lib2.$S)(AtThis, (0, import_lib2.$TEXT)((0, import_lib2.$S)((0, import_lib2.$E)(Hash), IdentifierName))), function($skip, $loc, $0, $1, $2) {
11562
+ var ThisLiteral$0 = HashThis;
11563
+ var ThisLiteral$1 = (0, import_lib2.$TS)((0, import_lib2.$S)(AtThis, (0, import_lib2.$TEXT)((0, import_lib2.$S)((0, import_lib2.$E)(Hash), IdentifierName))), function($skip, $loc, $0, $1, $2) {
11537
11564
  var at = $1;
11538
11565
  var id = $2;
11539
11566
  return {
@@ -11552,11 +11579,19 @@ var ThisLiteral$2 = (0, import_lib2.$TS)((0, import_lib2.$S)(AtThis, (0, import_
11552
11579
  thisShorthand: true
11553
11580
  };
11554
11581
  });
11555
- var ThisLiteral$3 = AtThis;
11556
- var ThisLiteral$$ = [ThisLiteral$0, ThisLiteral$1, ThisLiteral$2, ThisLiteral$3];
11582
+ var ThisLiteral$2 = BasicThisLiteral;
11583
+ var ThisLiteral$$ = [ThisLiteral$0, ThisLiteral$1, ThisLiteral$2];
11557
11584
  function ThisLiteral(ctx, state2) {
11558
11585
  return (0, import_lib2.$EVENT_C)(ctx, state2, "ThisLiteral", ThisLiteral$$);
11559
11586
  }
11587
+ var BasicThisLiteral$0 = (0, import_lib2.$T)((0, import_lib2.$S)(This), function(value) {
11588
+ return { "type": "Identifier", "name": "this", "children": [value[0]] };
11589
+ });
11590
+ var BasicThisLiteral$1 = AtThis;
11591
+ var BasicThisLiteral$$ = [BasicThisLiteral$0, BasicThisLiteral$1];
11592
+ function BasicThisLiteral(ctx, state2) {
11593
+ return (0, import_lib2.$EVENT_C)(ctx, state2, "BasicThisLiteral", BasicThisLiteral$$);
11594
+ }
11560
11595
  var HashThis$0 = (0, import_lib2.$TS)((0, import_lib2.$S)((0, import_lib2.$E)(AtThis), LengthShorthand, (0, import_lib2.$E)((0, import_lib2.$S)((0, import_lib2.$Y)((0, import_lib2.$S)(_, (0, import_lib2.$E)((0, import_lib2.$S)(Not, __)), ActualIn)), (0, import_lib2.$EXPECT)($L0, 'HashThis ""')))), function($skip, $loc, $0, $1, $2, $3) {
11561
11596
  var at = $1;
11562
11597
  var id = $2;
@@ -11593,7 +11628,7 @@ var HashThis$$ = [HashThis$0, HashThis$1, HashThis$2];
11593
11628
  function HashThis(ctx, state2) {
11594
11629
  return (0, import_lib2.$EVENT_C)(ctx, state2, "HashThis", HashThis$$);
11595
11630
  }
11596
- var LengthShorthand$0 = (0, import_lib2.$TS)((0, import_lib2.$S)(Hash, NonIdContinue), function($skip, $loc, $0, $1, $2) {
11631
+ var LengthShorthand$0 = (0, import_lib2.$TS)((0, import_lib2.$S)((0, import_lib2.$N)(CoffeeCommentEnabled), Hash, NonIdContinue), function($skip, $loc, $0, $1, $2, $3) {
11597
11632
  const id = "length";
11598
11633
  return {
11599
11634
  type: "Identifier",
@@ -12291,7 +12326,7 @@ function ParameterElement(ctx, state2) {
12291
12326
  return (0, import_lib2.$EVENT)(ctx, state2, "ParameterElement", ParameterElement$0);
12292
12327
  }
12293
12328
  var ParameterElementDelimiter$0 = (0, import_lib2.$S)((0, import_lib2.$E)(_), Comma);
12294
- var ParameterElementDelimiter$1 = (0, import_lib2.$Y)((0, import_lib2.$S)(__, (0, import_lib2.$R$0)((0, import_lib2.$EXPECT)($R13, "ParameterElementDelimiter /[)}]/"))));
12329
+ var ParameterElementDelimiter$1 = (0, import_lib2.$Y)((0, import_lib2.$S)(__, (0, import_lib2.$R$0)((0, import_lib2.$EXPECT)($R13, "ParameterElementDelimiter /[)\\]}]/"))));
12295
12330
  var ParameterElementDelimiter$2 = (0, import_lib2.$T)((0, import_lib2.$S)((0, import_lib2.$Y)(EOS), InsertComma), function(value) {
12296
12331
  return value[1];
12297
12332
  });
@@ -14227,7 +14262,7 @@ function InlineObjectPropertyDelimiter(ctx, state2) {
14227
14262
  return (0, import_lib2.$EVENT)(ctx, state2, "InlineObjectPropertyDelimiter", InlineObjectPropertyDelimiter$0);
14228
14263
  }
14229
14264
  var ObjectPropertyDelimiter$0 = (0, import_lib2.$S)((0, import_lib2.$E)(_), Comma);
14230
- var ObjectPropertyDelimiter$1 = (0, import_lib2.$Y)((0, import_lib2.$S)(__, (0, import_lib2.$EXPECT)($L37, 'ObjectPropertyDelimiter "}"')));
14265
+ var ObjectPropertyDelimiter$1 = (0, import_lib2.$Y)((0, import_lib2.$S)(__, (0, import_lib2.$R$0)((0, import_lib2.$EXPECT)($R13, "ObjectPropertyDelimiter /[)\\]}]/"))));
14231
14266
  var ObjectPropertyDelimiter$2 = (0, import_lib2.$TS)((0, import_lib2.$S)((0, import_lib2.$Y)(EOS), InsertComma), function($skip, $loc, $0, $1, $2) {
14232
14267
  return { ...$2, implicit: true };
14233
14268
  });
@@ -19885,7 +19920,14 @@ var TypeIdentifier$1 = (0, import_lib2.$TS)((0, import_lib2.$S)((0, import_lib2.
19885
19920
  args
19886
19921
  };
19887
19922
  });
19888
- var TypeIdentifier$$ = [TypeIdentifier$0, TypeIdentifier$1];
19923
+ var TypeIdentifier$2 = (0, import_lib2.$TS)((0, import_lib2.$S)((0, import_lib2.$E)(_), BasicThisLiteral), function($skip, $loc, $0, $1, $2) {
19924
+ return {
19925
+ type: "TypeIdentifier",
19926
+ children: $0,
19927
+ raw: $2.name
19928
+ };
19929
+ });
19930
+ var TypeIdentifier$$ = [TypeIdentifier$0, TypeIdentifier$1, TypeIdentifier$2];
19889
19931
  function TypeIdentifier(ctx, state2) {
19890
19932
  return (0, import_lib2.$EVENT_C)(ctx, state2, "TypeIdentifier", TypeIdentifier$$);
19891
19933
  }
@@ -21171,6 +21213,7 @@ var sourcemap_civet_exports = {};
21171
21213
  __export(sourcemap_civet_exports, {
21172
21214
  SourceMap: () => SourceMap,
21173
21215
  base64Encode: () => base64Encode,
21216
+ decodeVLQ: () => decodeVLQ,
21174
21217
  locationTable: () => locationTable,
21175
21218
  lookupLineColumn: () => lookupLineColumn
21176
21219
  });
@@ -21206,7 +21249,6 @@ var SourceMap = class {
21206
21249
  // relative to previous entry
21207
21250
  srcLine;
21208
21251
  srcColumn;
21209
- srcOffset;
21210
21252
  srcTable;
21211
21253
  source;
21212
21254
  constructor(source1) {
@@ -21216,7 +21258,6 @@ var SourceMap = class {
21216
21258
  this.colOffset = 0;
21217
21259
  this.srcLine = 0;
21218
21260
  this.srcColumn = 0;
21219
- this.srcOffset = 0;
21220
21261
  this.srcTable = locationTable(this.source);
21221
21262
  }
21222
21263
  renderMappings() {
@@ -21260,6 +21301,10 @@ var SourceMap = class {
21260
21301
  }
21261
21302
  };
21262
21303
  }
21304
+ /** Generate a comment with the source mapping URL. */
21305
+ comment(srcFileName, outFileName) {
21306
+ return `//${"#"} sourceMappingURL=data:application/json;base64,${base64Encode(JSON.stringify(this.json(srcFileName, outFileName)))}`;
21307
+ }
21263
21308
  updateSourceMap(outputStr, inputPos, colOffset = 0) {
21264
21309
  const outLines = outputStr.split(EOL2);
21265
21310
  let srcLine, srcCol;
@@ -21268,7 +21313,6 @@ var SourceMap = class {
21268
21313
  srcCol += colOffset;
21269
21314
  this.srcLine = srcLine;
21270
21315
  this.srcColumn = srcCol;
21271
- this.srcOffset = inputPos + outputStr.length;
21272
21316
  }
21273
21317
  for (let i3 = 0, len22 = outLines.length; i3 < len22; i3++) {
21274
21318
  const i = i3;
@@ -21291,74 +21335,85 @@ var SourceMap = class {
21291
21335
  }
21292
21336
  return;
21293
21337
  }
21294
- };
21295
- var smRegexp = /\n\/\/# sourceMappingURL=data:application\/json;charset=utf-8;base64,([+a-zA-Z0-9\/]*=?=?)$/;
21296
- var remap = function(codeWithSourceMap, upstreamMap, sourcePath, targetPath) {
21297
- let sourceMapText;
21298
- const codeWithoutSourceMap = codeWithSourceMap.replace(smRegexp, (match, sm) => {
21299
- sourceMapText = sm;
21300
- return "";
21301
- });
21302
- if (sourceMapText) {
21303
- const parsed = parseWithLines(sourceMapText);
21304
- const composedLines = composeLines(upstreamMap.lines, parsed.lines);
21305
- upstreamMap.lines = composedLines;
21306
- }
21307
- const remappedSourceMapJSON = upstreamMap.json(sourcePath, targetPath);
21308
- const newSourceMap = `${"sourceMapping"}URL=data:application/json;charset=utf-8;base64,${base64Encode(JSON.stringify(remappedSourceMapJSON))}`;
21309
- const remappedCodeWithSourceMap = `${codeWithoutSourceMap}
21310
- //# ${newSourceMap}`;
21311
- return remappedCodeWithSourceMap;
21312
- };
21313
- var composeLines = function(upstreamMapping, lines) {
21314
- return lines.map((line) => {
21315
- return line.map((entry) => {
21316
- if (entry.length === 1) {
21317
- return entry;
21318
- }
21319
- const [colDelta, sourceFileIndex, srcLine, srcCol] = entry;
21320
- const srcPos = remapPosition([srcLine, srcCol], upstreamMapping);
21321
- if (!srcPos) {
21322
- return [entry[0]];
21323
- }
21324
- const [upstreamLine, upstreamCol] = srcPos;
21325
- if (entry.length === 4) {
21326
- return [colDelta, sourceFileIndex, upstreamLine, upstreamCol];
21327
- }
21328
- return [colDelta, sourceFileIndex, upstreamLine, upstreamCol, entry[4]];
21338
+ /**
21339
+ Remap a string with compiled code and a source map to use a new source map
21340
+ referencing upstream source files.
21341
+ This modifies the upstream map in place.
21342
+ */
21343
+ static remap = (codeWithSourceMap, upstreamMap, sourcePath, targetPath) => {
21344
+ let sourceMapText;
21345
+ const codeWithoutSourceMap = codeWithSourceMap.replace(smRegexp, (_match, sm) => {
21346
+ sourceMapText = sm;
21347
+ return "";
21329
21348
  });
21330
- });
21331
- };
21332
- var parseWithLines = function(base64encodedJSONstr) {
21333
- const json = JSON.parse(Buffer.from(base64encodedJSONstr, "base64").toString("utf8"));
21334
- let sourceLine = 0;
21335
- let sourceColumn = 0;
21336
- const lines = json.mappings.split(";").map((line) => {
21337
- if (line.length === 0) {
21338
- return [];
21349
+ if (sourceMapText) {
21350
+ const parsed = this.parseWithLines(sourceMapText);
21351
+ const composedLines = this.composeLines(upstreamMap.lines, parsed.lines);
21352
+ upstreamMap.lines = composedLines;
21339
21353
  }
21340
- return line.split(",").map((entry) => {
21341
- const result = decodeVLQ(entry);
21342
- switch (result.length) {
21343
- case 1: {
21344
- return [result[0]];
21345
- }
21346
- case 4: {
21347
- return [result[0], result[1], sourceLine += result[2], sourceColumn += result[3]];
21354
+ const remappedCodeWithSourceMap = `${codeWithoutSourceMap}
21355
+ ${upstreamMap.comment(sourcePath, targetPath)}`;
21356
+ return remappedCodeWithSourceMap;
21357
+ };
21358
+ /**
21359
+ Compose lines from an upstream source map with lines from a downstream source map.
21360
+ */
21361
+ static composeLines = (upstreamMapping, lines) => {
21362
+ return lines.map((line) => {
21363
+ return line.map((entry) => {
21364
+ if (entry.length === 1) {
21365
+ return entry;
21348
21366
  }
21349
- case 5: {
21350
- return [result[0], result[1], sourceLine += result[2], sourceColumn += result[3], result[4]];
21367
+ const [colDelta, sourceFileIndex, srcLine, srcCol] = entry;
21368
+ const srcPos = remapPosition([srcLine, srcCol], upstreamMapping);
21369
+ if (!srcPos) {
21370
+ return [entry[0]];
21351
21371
  }
21352
- default: {
21353
- throw new Error("Unknown source map entry", result);
21372
+ const [upstreamLine, upstreamCol] = srcPos;
21373
+ if (entry.length === 4) {
21374
+ return [colDelta, sourceFileIndex, upstreamLine, upstreamCol];
21354
21375
  }
21376
+ return [colDelta, sourceFileIndex, upstreamLine, upstreamCol, entry[4]];
21377
+ });
21378
+ });
21379
+ };
21380
+ /**
21381
+ Parse a base64 encoded source map string into a SourceMapJSON object with lines.
21382
+ */
21383
+ static parseWithLines = (base64encodedJSONstr) => {
21384
+ const json = JSON.parse(Buffer.from(base64encodedJSONstr, "base64").toString("utf8"));
21385
+ let sourceLine = 0;
21386
+ let sourceColumn = 0;
21387
+ const lines = json.mappings.split(";").map((line) => {
21388
+ if (line.length === 0) {
21389
+ return [];
21355
21390
  }
21391
+ return line.split(",").map((entry) => {
21392
+ const result = decodeVLQ(entry);
21393
+ switch (result.length) {
21394
+ case 1: {
21395
+ ;
21396
+ break;
21397
+ }
21398
+ case 4:
21399
+ case 5: {
21400
+ sourceLine += result[2];
21401
+ result[2] = sourceLine;
21402
+ sourceColumn += result[3];
21403
+ result[3] = sourceColumn;
21404
+ break;
21405
+ }
21406
+ default: {
21407
+ throw new Error(`Unknown source map entry ${JSON.stringify(result)}`);
21408
+ }
21409
+ }
21410
+ return result;
21411
+ });
21356
21412
  });
21357
- });
21358
- json.lines = lines;
21359
- return json;
21413
+ return { ...json, lines };
21414
+ };
21360
21415
  };
21361
- Object.assign(SourceMap, { remap, parseWithLines, composeLines });
21416
+ var smRegexp = /(?:\r?\n|\r)\/\/# sourceMappingURL=data:application\/json;(?:charset=[^;]*;)?base64,([+a-zA-Z0-9\/]*=?=?)(?:\s*)$/;
21362
21417
  var VLQ_SHIFT = 5;
21363
21418
  var VLQ_CONTINUATION_BIT = 1 << VLQ_SHIFT;
21364
21419
  var VLQ_VALUE_MASK = VLQ_CONTINUATION_BIT - 1;
@@ -21375,21 +21430,18 @@ var encodeVlq = function(value) {
21375
21430
  if (valueToEncode) {
21376
21431
  nextChunk |= VLQ_CONTINUATION_BIT;
21377
21432
  }
21378
- answer += encodeBase64(nextChunk);
21433
+ answer += BASE64_CHARS[nextChunk];
21379
21434
  }
21380
21435
  return answer;
21381
21436
  };
21382
21437
  var BASE64_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
21383
- var encodeBase64 = function(value) {
21384
- return BASE64_CHARS[value] || (() => {
21385
- throw new Error("Cannot Base64 encode value: ${value}");
21386
- })();
21387
- };
21388
21438
  var base64Encode = function(src) {
21389
21439
  if (typeof Buffer !== "undefined") {
21390
21440
  return Buffer.from(src).toString("base64");
21391
21441
  } else {
21392
- return btoa(src);
21442
+ const bytes = new TextEncoder().encode(src);
21443
+ const binaryString = String.fromCodePoint(...bytes);
21444
+ return btoa(binaryString);
21393
21445
  }
21394
21446
  };
21395
21447
  var vlqTable = new Uint8Array(128);
@@ -21411,7 +21463,7 @@ var vlqChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/
21411
21463
  var decodeError = function(message) {
21412
21464
  throw new Error(message);
21413
21465
  };
21414
- var decodeVLQ = function(mapping) {
21466
+ var decodeVLQ = (mapping) => {
21415
21467
  let i = 0;
21416
21468
  let l = mapping.length;
21417
21469
  let result = [];
@@ -21425,11 +21477,11 @@ var decodeVLQ = function(mapping) {
21425
21477
  }
21426
21478
  const c = mapping.charCodeAt(i);
21427
21479
  if ((c & 127) != c) {
21428
- decodeError("Invalid mapping character: ${JSON.stringify(String.fromCharCode(c))}");
21480
+ decodeError(`Invalid mapping character: ${JSON.stringify(String.fromCharCode(c))}`);
21429
21481
  }
21430
21482
  const index = vlqTable[c & 127];
21431
21483
  if (index === 255) {
21432
- decodeError("Invalid mapping character: ${JSON.stringify(String.fromCharCode(c))}");
21484
+ decodeError(`Invalid mapping character: ${JSON.stringify(String.fromCharCode(c))}`);
21433
21485
  }
21434
21486
  i++;
21435
21487
  vlq |= (index & 31) << shift;
@@ -21447,7 +21499,7 @@ var decodeVLQ = function(mapping) {
21447
21499
  }
21448
21500
  return result;
21449
21501
  };
21450
- var remapPosition = function(position, sourcemapLines) {
21502
+ var remapPosition = (position, sourcemapLines) => {
21451
21503
  const [line, character] = position;
21452
21504
  const textLine = sourcemapLines[line];
21453
21505
  if (!textLine?.length) {
@@ -21780,7 +21832,8 @@ ${counts}`;
21780
21832
  const code = generate_civet_default(ast2, options);
21781
21833
  checkErrors();
21782
21834
  if (options.inlineMap) {
21783
- return SourceMap2.remap(code, options.sourceMap, filename2, filename2 + ".tsx");
21835
+ return `${code}
21836
+ ${options.sourceMap.comment(filename2, filename2 + ".tsx")}`;
21784
21837
  } else {
21785
21838
  return {
21786
21839
  code,
@@ -342,7 +342,7 @@ var rawPlugin = (options = {}, meta) => {
342
342
  }
343
343
  if (options.emitDeclaration) {
344
344
  if (meta.framework === "esbuild" && !esbuildOptions.outdir) {
345
- console.log("WARNING: Civet unplugin's `emitDeclaration` requires esbuild's `outdir` option to be set;");
345
+ throw new Error("Civet unplugin's `emitDeclaration` requires esbuild's `outdir` option to be set;");
346
346
  }
347
347
  for (const file of fsMap.keys()) {
348
348
  const slashed = slash(file);
@@ -539,7 +539,7 @@ var rawPlugin = (options = {}, meta) => {
539
539
  }
540
540
  }
541
541
  const jsonSourceMap = sourceMap && (typeof sourceMap === "string" ? JSON.parse(sourceMap) : sourceMap.json(
542
- import_path.default.relative(rootDir, id.replace(/\.[jt]sx$/, "")),
542
+ import_path.default.relative(rootDir, extractCivetFilename(id, outExt).filename),
543
543
  import_path.default.relative(rootDir, id)
544
544
  ));
545
545
  let transformed = {
@@ -310,7 +310,7 @@ var rawPlugin = (options = {}, meta) => {
310
310
  }
311
311
  if (options.emitDeclaration) {
312
312
  if (meta.framework === "esbuild" && !esbuildOptions.outdir) {
313
- console.log("WARNING: Civet unplugin's `emitDeclaration` requires esbuild's `outdir` option to be set;");
313
+ throw new Error("Civet unplugin's `emitDeclaration` requires esbuild's `outdir` option to be set;");
314
314
  }
315
315
  for (const file of fsMap.keys()) {
316
316
  const slashed = slash(file);
@@ -507,7 +507,7 @@ var rawPlugin = (options = {}, meta) => {
507
507
  }
508
508
  }
509
509
  const jsonSourceMap = sourceMap && (typeof sourceMap === "string" ? JSON.parse(sourceMap) : sourceMap.json(
510
- path.relative(rootDir, id.replace(/\.[jt]sx$/, "")),
510
+ path.relative(rootDir, extractCivetFilename(id, outExt).filename),
511
511
  path.relative(rootDir, id)
512
512
  ));
513
513
  let transformed = {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@danielx/civet",
3
3
  "type": "commonjs",
4
- "version": "0.10.4",
4
+ "version": "0.10.6",
5
5
  "description": "CoffeeScript style syntax for TypeScript",
6
6
  "main": "dist/main.js",
7
7
  "module": "dist/main.mjs",