@danielx/civet 0.6.49 → 0.6.51

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
@@ -2049,6 +2049,20 @@ var require_lib = __commonJS({
2049
2049
  implicit: true
2050
2050
  });
2051
2051
  }
2052
+ function makeExpressionStatement(expression) {
2053
+ if (Array.isArray(expression) && expression[1]?.[0]?.[0]?.[1]?.token === ",") {
2054
+ return [
2055
+ makeExpressionStatement(expression[0]),
2056
+ expression[1].map(([comma, exp]) => {
2057
+ return [comma, makeExpressionStatement(exp)];
2058
+ })
2059
+ ];
2060
+ } else if (expression?.type === "ObjectExpression" || expression?.type === "FunctionExpression" && !expression.id) {
2061
+ return makeLeftHandSideExpression(expression);
2062
+ } else {
2063
+ return expression;
2064
+ }
2065
+ }
2052
2066
  function modifyString(str) {
2053
2067
  return str.replace(/(^.?|[^\\]{2})(\\\\)*\n/g, "$1$2\\n");
2054
2068
  }
@@ -3682,6 +3696,7 @@ var require_lib = __commonJS({
3682
3696
  literalValue,
3683
3697
  makeAsConst,
3684
3698
  makeEmptyBlock,
3699
+ makeExpressionStatement,
3685
3700
  makeGetterMethod,
3686
3701
  makeLeftHandSideExpression,
3687
3702
  makeRef,
@@ -3746,6 +3761,7 @@ var require_parser = __commonJS({
3746
3761
  NestedTopLevelStatements,
3747
3762
  TopLevelSingleLineStatements,
3748
3763
  TopLevelStatement,
3764
+ ExtendedCommaExpression,
3749
3765
  ExtendedExpression,
3750
3766
  SingleLineExtendedExpression,
3751
3767
  NonPipelineExtendedExpression,
@@ -3754,7 +3770,7 @@ var require_parser = __commonJS({
3754
3770
  ExpressionizedStatementWithTrailingCallExpressions,
3755
3771
  ExpressionizedStatement,
3756
3772
  _ExpressionizedStatement,
3757
- Expression,
3773
+ CommaExpression,
3758
3774
  Arguments,
3759
3775
  ImplicitArguments,
3760
3776
  ExplicitArguments,
@@ -3899,15 +3915,18 @@ var require_parser = __commonJS({
3899
3915
  BareBlock,
3900
3916
  ThenClause,
3901
3917
  BracedOrEmptyBlock,
3918
+ NoCommaBracedOrEmptyBlock,
3902
3919
  NoPostfixBracedOrEmptyBlock,
3903
3920
  EmptyBlock,
3904
3921
  EmptyBareBlock,
3905
3922
  BracedBlock,
3906
3923
  NoPostfixBracedBlock,
3924
+ NoCommaBracedBlock,
3907
3925
  NonSingleBracedBlock,
3908
3926
  DeclarationOrStatement,
3909
3927
  SingleLineStatements,
3910
3928
  PostfixedSingleLineStatements,
3929
+ PostfixedSingleLineNoCommaStatements,
3911
3930
  BracedContent,
3912
3931
  NestedBlockStatements,
3913
3932
  NestedBlockStatement,
@@ -3975,11 +3994,15 @@ var require_parser = __commonJS({
3975
3994
  ModuleItem,
3976
3995
  StatementListItem,
3977
3996
  PostfixedStatement,
3997
+ NoCommaStatementListItem,
3998
+ PostfixedNoCommaStatement,
3978
3999
  PostfixedExpression,
4000
+ PostfixedCommaExpression,
3979
4001
  NonPipelinePostfixedExpression,
3980
4002
  PostfixStatement,
3981
4003
  _PostfixStatement,
3982
4004
  Statement,
4005
+ NoCommaStatement,
3983
4006
  EmptyStatement,
3984
4007
  BlockStatement,
3985
4008
  LabelledStatement,
@@ -4063,6 +4086,7 @@ var require_parser = __commonJS({
4063
4086
  NewlineBinaryOpAllowed,
4064
4087
  AllowAll,
4065
4088
  RestoreAll,
4089
+ CommaExpressionStatement,
4066
4090
  ExpressionStatement,
4067
4091
  KeywordStatement,
4068
4092
  DebuggerStatement,
@@ -4799,6 +4823,12 @@ var require_parser = __commonJS({
4799
4823
  function TopLevelStatement(ctx, state) {
4800
4824
  return $EVENT(ctx, state, "TopLevelStatement", TopLevelStatement$0);
4801
4825
  }
4826
+ var ExtendedCommaExpression$0 = NonAssignmentExtendedExpression;
4827
+ var ExtendedCommaExpression$1 = CommaExpression;
4828
+ var ExtendedCommaExpression$$ = [ExtendedCommaExpression$0, ExtendedCommaExpression$1];
4829
+ function ExtendedCommaExpression(ctx, state) {
4830
+ return $EVENT_C(ctx, state, "ExtendedCommaExpression", ExtendedCommaExpression$$);
4831
+ }
4802
4832
  var ExtendedExpression$0 = NonAssignmentExtendedExpression;
4803
4833
  var ExtendedExpression$1 = AssignmentExpression;
4804
4834
  var ExtendedExpression$$ = [ExtendedExpression$0, ExtendedExpression$1];
@@ -4877,13 +4907,13 @@ var require_parser = __commonJS({
4877
4907
  function _ExpressionizedStatement(ctx, state) {
4878
4908
  return $EVENT_C(ctx, state, "_ExpressionizedStatement", _ExpressionizedStatement$$);
4879
4909
  }
4880
- var Expression$0 = $TS($S(AssignmentExpression, $Q($S(CommaDelimiter, AssignmentExpression))), function($skip, $loc, $0, $1, $2) {
4910
+ var CommaExpression$0 = $TS($S(AssignmentExpression, $Q($S(CommaDelimiter, AssignmentExpression))), function($skip, $loc, $0, $1, $2) {
4881
4911
  if ($2.length == 0)
4882
4912
  return $1;
4883
4913
  return $0;
4884
4914
  });
4885
- function Expression(ctx, state) {
4886
- return $EVENT(ctx, state, "Expression", Expression$0);
4915
+ function CommaExpression(ctx, state) {
4916
+ return $EVENT(ctx, state, "CommaExpression", CommaExpression$0);
4887
4917
  }
4888
4918
  var Arguments$0 = ExplicitArguments;
4889
4919
  var Arguments$1 = $TS($S(ForbidTrailingMemberProperty, $E(ImplicitArguments), RestoreTrailingMemberProperty), function($skip, $loc, $0, $1, $2, $3) {
@@ -5288,11 +5318,14 @@ var require_parser = __commonJS({
5288
5318
  function TrailingDeclaration(ctx, state) {
5289
5319
  return $EVENT(ctx, state, "TrailingDeclaration", TrailingDeclaration$0);
5290
5320
  }
5291
- var FatArrowBody$0 = $T($S($N(EOS), NonPipelinePostfixedExpression, $N(TrailingDeclaration), $N(SemicolonDelimiter)), function(value) {
5292
- var exp = value[1];
5321
+ var FatArrowBody$0 = $TS($S($N(EOS), NonPipelinePostfixedExpression, $N(TrailingDeclaration), $N(SemicolonDelimiter)), function($skip, $loc, $0, $1, $2, $3, $4) {
5322
+ var exp = $2;
5323
+ if (exp.type === "ObjectExpression") {
5324
+ return makeLeftHandSideExpression(exp);
5325
+ }
5293
5326
  return exp;
5294
5327
  });
5295
- var FatArrowBody$1 = BracedOrEmptyBlock;
5328
+ var FatArrowBody$1 = NoCommaBracedOrEmptyBlock;
5296
5329
  var FatArrowBody$$ = [FatArrowBody$0, FatArrowBody$1];
5297
5330
  function FatArrowBody(ctx, state) {
5298
5331
  return $EVENT_C(ctx, state, "FatArrowBody", FatArrowBody$$);
@@ -5404,7 +5437,7 @@ var require_parser = __commonJS({
5404
5437
  function PrimaryExpression(ctx, state) {
5405
5438
  return $EVENT_C(ctx, state, "PrimaryExpression", PrimaryExpression$$);
5406
5439
  }
5407
- var ParenthesizedExpression$0 = $TS($S(OpenParen, AllowAll, $E($S(PostfixedExpression, __, CloseParen)), RestoreAll), function($skip, $loc, $0, $1, $2, $3, $4) {
5440
+ var ParenthesizedExpression$0 = $TS($S(OpenParen, AllowAll, $E($S(PostfixedCommaExpression, __, CloseParen)), RestoreAll), function($skip, $loc, $0, $1, $2, $3, $4) {
5408
5441
  var open = $1;
5409
5442
  if (!$3)
5410
5443
  return $skip;
@@ -6798,7 +6831,7 @@ var require_parser = __commonJS({
6798
6831
  function AmpersandUnaryPrefix(ctx, state) {
6799
6832
  return $EVENT(ctx, state, "AmpersandUnaryPrefix", AmpersandUnaryPrefix$0);
6800
6833
  }
6801
- var ThinArrowFunction$0 = $TS($S($E($S(Async, _)), ArrowParameters, $E(ReturnTypeSuffix), $E(_), Arrow, BracedOrEmptyBlock), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6) {
6834
+ var ThinArrowFunction$0 = $TS($S($E($S(Async, _)), ArrowParameters, $E(ReturnTypeSuffix), $E(_), Arrow, NoCommaBracedOrEmptyBlock), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6) {
6802
6835
  var async = $1;
6803
6836
  var parameters = $2;
6804
6837
  var suffix = $3;
@@ -6940,6 +6973,12 @@ var require_parser = __commonJS({
6940
6973
  function BracedOrEmptyBlock(ctx, state) {
6941
6974
  return $EVENT_C(ctx, state, "BracedOrEmptyBlock", BracedOrEmptyBlock$$);
6942
6975
  }
6976
+ var NoCommaBracedOrEmptyBlock$0 = NoCommaBracedBlock;
6977
+ var NoCommaBracedOrEmptyBlock$1 = EmptyBlock;
6978
+ var NoCommaBracedOrEmptyBlock$$ = [NoCommaBracedOrEmptyBlock$0, NoCommaBracedOrEmptyBlock$1];
6979
+ function NoCommaBracedOrEmptyBlock(ctx, state) {
6980
+ return $EVENT_C(ctx, state, "NoCommaBracedOrEmptyBlock", NoCommaBracedOrEmptyBlock$$);
6981
+ }
6943
6982
  var NoPostfixBracedOrEmptyBlock$0 = NoPostfixBracedBlock;
6944
6983
  var NoPostfixBracedOrEmptyBlock$1 = EmptyBlock;
6945
6984
  var NoPostfixBracedOrEmptyBlock$$ = [NoPostfixBracedOrEmptyBlock$0, NoPostfixBracedOrEmptyBlock$1];
@@ -7009,6 +7048,25 @@ var require_parser = __commonJS({
7009
7048
  function NoPostfixBracedBlock(ctx, state) {
7010
7049
  return $EVENT_C(ctx, state, "NoPostfixBracedBlock", NoPostfixBracedBlock$$);
7011
7050
  }
7051
+ var NoCommaBracedBlock$0 = NonSingleBracedBlock;
7052
+ var NoCommaBracedBlock$1 = $TS($S(InsertOpenBrace, $N(EOS), PostfixedSingleLineNoCommaStatements, InsertSpace, InsertCloseBrace), function($skip, $loc, $0, $1, $2, $3, $4, $5) {
7053
+ var o = $1;
7054
+ var s = $3;
7055
+ var ws = $4;
7056
+ var c = $5;
7057
+ if (!s.children.length)
7058
+ return $skip;
7059
+ return {
7060
+ type: "BlockStatement",
7061
+ expressions: s.expressions,
7062
+ // Remove !EOS assertion
7063
+ children: [o, s.children, ws, c]
7064
+ };
7065
+ });
7066
+ var NoCommaBracedBlock$$ = [NoCommaBracedBlock$0, NoCommaBracedBlock$1];
7067
+ function NoCommaBracedBlock(ctx, state) {
7068
+ return $EVENT_C(ctx, state, "NoCommaBracedBlock", NoCommaBracedBlock$$);
7069
+ }
7012
7070
  var NonSingleBracedBlock$0 = $TS($S($E(_), OpenBrace, AllowAll, $E($S(BracedContent, __, CloseBrace)), RestoreAll), function($skip, $loc, $0, $1, $2, $3, $4, $5) {
7013
7071
  var ws1 = $1;
7014
7072
  var open = $2;
@@ -7076,6 +7134,22 @@ var require_parser = __commonJS({
7076
7134
  function PostfixedSingleLineStatements(ctx, state) {
7077
7135
  return $EVENT(ctx, state, "PostfixedSingleLineStatements", PostfixedSingleLineStatements$0);
7078
7136
  }
7137
+ var PostfixedSingleLineNoCommaStatements$0 = $TS($S($Q($S($S($E(_), $N(EOS)), NoCommaStatementListItem, SemicolonDelimiter)), $E($S($S($E(_), $N(EOS)), NoCommaStatementListItem, $E(SemicolonDelimiter)))), function($skip, $loc, $0, $1, $2) {
7138
+ var stmts = $1;
7139
+ var last = $2;
7140
+ const children = [...stmts];
7141
+ if (last)
7142
+ children.push(last);
7143
+ return {
7144
+ type: "BlockStatement",
7145
+ expressions: children,
7146
+ children,
7147
+ bare: true
7148
+ };
7149
+ });
7150
+ function PostfixedSingleLineNoCommaStatements(ctx, state) {
7151
+ return $EVENT(ctx, state, "PostfixedSingleLineNoCommaStatements", PostfixedSingleLineNoCommaStatements$0);
7152
+ }
7079
7153
  var BracedContent$0 = NestedBlockStatements;
7080
7154
  var BracedContent$1 = SingleLineStatements;
7081
7155
  var BracedContent$2 = $TV($Y($S(__, $EXPECT($L25, 'BracedContent "}"'))), function($skip, $loc, $0, $1) {
@@ -8470,6 +8544,22 @@ var require_parser = __commonJS({
8470
8544
  function PostfixedStatement(ctx, state) {
8471
8545
  return $EVENT(ctx, state, "PostfixedStatement", PostfixedStatement$0);
8472
8546
  }
8547
+ var NoCommaStatementListItem$0 = Declaration;
8548
+ var NoCommaStatementListItem$1 = PostfixedNoCommaStatement;
8549
+ var NoCommaStatementListItem$$ = [NoCommaStatementListItem$0, NoCommaStatementListItem$1];
8550
+ function NoCommaStatementListItem(ctx, state) {
8551
+ return $EVENT_C(ctx, state, "NoCommaStatementListItem", NoCommaStatementListItem$$);
8552
+ }
8553
+ var PostfixedNoCommaStatement$0 = $TS($S(NoCommaStatement, $E($S($E(_), PostfixStatement))), function($skip, $loc, $0, $1, $2) {
8554
+ var statement = $1;
8555
+ var post = $2;
8556
+ if (post)
8557
+ return addPostfixStatement(statement, ...post);
8558
+ return statement;
8559
+ });
8560
+ function PostfixedNoCommaStatement(ctx, state) {
8561
+ return $EVENT(ctx, state, "PostfixedNoCommaStatement", PostfixedNoCommaStatement$0);
8562
+ }
8473
8563
  var PostfixedExpression$0 = $TS($S(ExtendedExpression, $E($S($E(_), PostfixStatement))), function($skip, $loc, $0, $1, $2) {
8474
8564
  var expression = $1;
8475
8565
  var post = $2;
@@ -8480,6 +8570,19 @@ var require_parser = __commonJS({
8480
8570
  function PostfixedExpression(ctx, state) {
8481
8571
  return $EVENT(ctx, state, "PostfixedExpression", PostfixedExpression$0);
8482
8572
  }
8573
+ var PostfixedCommaExpression$0 = $TS($S(PostfixedExpression, $C($S($E(_), PostfixStatement), $Q($S(CommaDelimiter, AssignmentExpression)))), function($skip, $loc, $0, $1, $2) {
8574
+ var expression = $1;
8575
+ var post = $2;
8576
+ if (!post.length)
8577
+ return $1;
8578
+ if (post.length === 2 && !Array.isArray(post[1])) {
8579
+ return attachPostfixStatementAsExpression(expression, post);
8580
+ }
8581
+ return $0;
8582
+ });
8583
+ function PostfixedCommaExpression(ctx, state) {
8584
+ return $EVENT(ctx, state, "PostfixedCommaExpression", PostfixedCommaExpression$0);
8585
+ }
8483
8586
  var NonPipelinePostfixedExpression$0 = $TS($S(NonPipelineExtendedExpression, $E($S($E(_), PostfixStatement))), function($skip, $loc, $0, $1, $2) {
8484
8587
  var expression = $1;
8485
8588
  var post = $2;
@@ -8513,17 +8616,26 @@ var require_parser = __commonJS({
8513
8616
  var Statement$5 = TryStatement;
8514
8617
  var Statement$6 = EmptyStatement;
8515
8618
  var Statement$7 = LabelledStatement;
8516
- var Statement$8 = $TS($S(ExpressionStatement), function($skip, $loc, $0, $1) {
8517
- if ($1.type === "ObjectExpression" || $1.type === "FunctionExpression" && !$1.id) {
8518
- return makeLeftHandSideExpression($1);
8519
- }
8520
- return $1;
8521
- });
8619
+ var Statement$8 = CommaExpressionStatement;
8522
8620
  var Statement$9 = BlockStatement;
8523
8621
  var Statement$$ = [Statement$0, Statement$1, Statement$2, Statement$3, Statement$4, Statement$5, Statement$6, Statement$7, Statement$8, Statement$9];
8524
8622
  function Statement(ctx, state) {
8525
8623
  return $EVENT_C(ctx, state, "Statement", Statement$$);
8526
8624
  }
8625
+ var NoCommaStatement$0 = KeywordStatement;
8626
+ var NoCommaStatement$1 = VariableStatement;
8627
+ var NoCommaStatement$2 = IfStatement;
8628
+ var NoCommaStatement$3 = IterationStatement;
8629
+ var NoCommaStatement$4 = SwitchStatement;
8630
+ var NoCommaStatement$5 = TryStatement;
8631
+ var NoCommaStatement$6 = EmptyStatement;
8632
+ var NoCommaStatement$7 = LabelledStatement;
8633
+ var NoCommaStatement$8 = ExpressionStatement;
8634
+ var NoCommaStatement$9 = BlockStatement;
8635
+ var NoCommaStatement$$ = [NoCommaStatement$0, NoCommaStatement$1, NoCommaStatement$2, NoCommaStatement$3, NoCommaStatement$4, NoCommaStatement$5, NoCommaStatement$6, NoCommaStatement$7, NoCommaStatement$8, NoCommaStatement$9];
8636
+ function NoCommaStatement(ctx, state) {
8637
+ return $EVENT_C(ctx, state, "NoCommaStatement", NoCommaStatement$$);
8638
+ }
8527
8639
  var EmptyStatement$0 = $TS($S($E(_), $Y($EXPECT($L99, 'EmptyStatement ";"'))), function($skip, $loc, $0, $1, $2) {
8528
8640
  return { type: "EmptyStatement", children: $1 || [] };
8529
8641
  });
@@ -9002,14 +9114,14 @@ var require_parser = __commonJS({
9002
9114
  function CoffeeForDeclaration(ctx, state) {
9003
9115
  return $EVENT(ctx, state, "CoffeeForDeclaration", CoffeeForDeclaration$0);
9004
9116
  }
9005
- var ForStatementParameters$0 = $TS($S(OpenParen, __, $C(LexicalDeclaration, VariableStatement, $E(Expression)), __, Semicolon, $E(Expression), Semicolon, $E(Expression), __, CloseParen), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7, $8, $9, $10) {
9117
+ var ForStatementParameters$0 = $TS($S(OpenParen, __, $C(LexicalDeclaration, VariableStatement, $E(CommaExpression)), __, Semicolon, $E(CommaExpression), Semicolon, $E(CommaExpression), __, CloseParen), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7, $8, $9, $10) {
9006
9118
  var declaration = $3;
9007
9119
  return {
9008
9120
  declaration,
9009
9121
  children: $0
9010
9122
  };
9011
9123
  });
9012
- var ForStatementParameters$1 = $TS($S(InsertOpenParen, __, $C(LexicalDeclaration, VariableStatement, $E(Expression)), __, Semicolon, $E(Expression), Semicolon, $E($S($N(EOS), ExpressionWithIndentedApplicationForbidden)), InsertCloseParen), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7, $8, $9) {
9124
+ var ForStatementParameters$1 = $TS($S(InsertOpenParen, __, $C(LexicalDeclaration, VariableStatement, $E(CommaExpression)), __, Semicolon, $E(CommaExpression), Semicolon, $E($S($N(EOS), ExpressionWithIndentedApplicationForbidden)), InsertCloseParen), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7, $8, $9) {
9013
9125
  var declaration = $3;
9014
9126
  return {
9015
9127
  declaration,
@@ -9585,8 +9697,18 @@ var require_parser = __commonJS({
9585
9697
  function RestoreAll(ctx, state) {
9586
9698
  return $EVENT(ctx, state, "RestoreAll", RestoreAll$0);
9587
9699
  }
9700
+ var CommaExpressionStatement$0 = IterationExpression;
9701
+ var CommaExpressionStatement$1 = $TS($S(CommaExpression), function($skip, $loc, $0, $1) {
9702
+ return makeExpressionStatement($1);
9703
+ });
9704
+ var CommaExpressionStatement$$ = [CommaExpressionStatement$0, CommaExpressionStatement$1];
9705
+ function CommaExpressionStatement(ctx, state) {
9706
+ return $EVENT_C(ctx, state, "CommaExpressionStatement", CommaExpressionStatement$$);
9707
+ }
9588
9708
  var ExpressionStatement$0 = IterationExpression;
9589
- var ExpressionStatement$1 = Expression;
9709
+ var ExpressionStatement$1 = $TS($S(AssignmentExpression), function($skip, $loc, $0, $1) {
9710
+ return makeExpressionStatement($1);
9711
+ });
9590
9712
  var ExpressionStatement$$ = [ExpressionStatement$0, ExpressionStatement$1];
9591
9713
  function ExpressionStatement(ctx, state) {
9592
9714
  return $EVENT_C(ctx, state, "ExpressionStatement", ExpressionStatement$$);
@@ -12220,7 +12342,7 @@ var require_parser = __commonJS({
12220
12342
  args
12221
12343
  };
12222
12344
  });
12223
- var TypePrimary$8 = $S(__, OpenParen, $C(Type, $S(EOS, Type)), __, CloseParen);
12345
+ var TypePrimary$8 = $S($E(_), OpenParen, $C(Type, $S(EOS, Type)), __, CloseParen);
12224
12346
  var TypePrimary$$ = [TypePrimary$0, TypePrimary$1, TypePrimary$2, TypePrimary$3, TypePrimary$4, TypePrimary$5, TypePrimary$6, TypePrimary$7, TypePrimary$8];
12225
12347
  function TypePrimary(ctx, state) {
12226
12348
  return $EVENT_C(ctx, state, "TypePrimary", TypePrimary$$);
@@ -12869,19 +12991,45 @@ var require_parser = __commonJS({
12869
12991
  };
12870
12992
  module.prelude.push(["", [preludeVar, moduloRef, typeSuffix, " = (a, b) => (a % b + b) % b;", "\n"]]);
12871
12993
  },
12994
+ Falsy(FalsyRef) {
12995
+ module.prelude.push(["", [{
12996
+ ts: true,
12997
+ children: ["type ", FalsyRef, " = false | 0 | '' | 0n | null | undefined;", "\n"]
12998
+ }]]);
12999
+ },
12872
13000
  xor(xorRef) {
13001
+ const Falsy = module.getRef("Falsy");
12873
13002
  const typeSuffix = {
12874
13003
  ts: true,
12875
- children: [": (a: unknown, b: unknown) => boolean"]
13004
+ children: [
13005
+ ": <A, B>(a: A, b: B) => A extends ",
13006
+ Falsy,
13007
+ " ? B : B extends ",
13008
+ Falsy,
13009
+ " ? A : (false | (A & ",
13010
+ Falsy,
13011
+ " extends never ? never : B) | (B & ",
13012
+ Falsy,
13013
+ " extends never ? never : A))"
13014
+ ]
12876
13015
  };
12877
- module.prelude.push(["", [preludeVar, xorRef, typeSuffix, " = (a, b) => a ? !b && a : b;", "\n"]]);
13016
+ module.prelude.push(["", [preludeVar, xorRef, typeSuffix, " = (a, b) => (a ? !b && a : b)", asAny, ";", "\n"]]);
12878
13017
  },
12879
13018
  xnor(xnorRef) {
13019
+ const Falsy = module.getRef("Falsy");
12880
13020
  const typeSuffix = {
12881
13021
  ts: true,
12882
- children: [": (a: unknown, b: unknown) => boolean"]
13022
+ children: [
13023
+ ": <A, B>(a: A, b: B) => A & ",
13024
+ Falsy,
13025
+ " extends never ? B : (true | (B extends ",
13026
+ Falsy,
13027
+ " ? never : A) | (A extends ",
13028
+ Falsy,
13029
+ " ? never : B))"
13030
+ ]
12883
13031
  };
12884
- module.prelude.push(["", [preludeVar, xnorRef, typeSuffix, " = (a, b) => a ? b : !b || a;", "\n"]]);
13032
+ module.prelude.push(["", [preludeVar, xnorRef, typeSuffix, " = (a, b) => (a ? b : !b || a)", asAny, ";", "\n"]]);
12885
13033
  },
12886
13034
  returnSymbol(ref) {
12887
13035
  module.prelude.push({
@@ -13109,6 +13257,7 @@ var require_parser = __commonJS({
13109
13257
  exports.NestedTopLevelStatements = NestedTopLevelStatements;
13110
13258
  exports.TopLevelSingleLineStatements = TopLevelSingleLineStatements;
13111
13259
  exports.TopLevelStatement = TopLevelStatement;
13260
+ exports.ExtendedCommaExpression = ExtendedCommaExpression;
13112
13261
  exports.ExtendedExpression = ExtendedExpression;
13113
13262
  exports.SingleLineExtendedExpression = SingleLineExtendedExpression;
13114
13263
  exports.NonPipelineExtendedExpression = NonPipelineExtendedExpression;
@@ -13117,7 +13266,7 @@ var require_parser = __commonJS({
13117
13266
  exports.ExpressionizedStatementWithTrailingCallExpressions = ExpressionizedStatementWithTrailingCallExpressions;
13118
13267
  exports.ExpressionizedStatement = ExpressionizedStatement;
13119
13268
  exports._ExpressionizedStatement = _ExpressionizedStatement;
13120
- exports.Expression = Expression;
13269
+ exports.CommaExpression = CommaExpression;
13121
13270
  exports.Arguments = Arguments;
13122
13271
  exports.ImplicitArguments = ImplicitArguments;
13123
13272
  exports.ExplicitArguments = ExplicitArguments;
@@ -13262,15 +13411,18 @@ var require_parser = __commonJS({
13262
13411
  exports.BareBlock = BareBlock;
13263
13412
  exports.ThenClause = ThenClause;
13264
13413
  exports.BracedOrEmptyBlock = BracedOrEmptyBlock;
13414
+ exports.NoCommaBracedOrEmptyBlock = NoCommaBracedOrEmptyBlock;
13265
13415
  exports.NoPostfixBracedOrEmptyBlock = NoPostfixBracedOrEmptyBlock;
13266
13416
  exports.EmptyBlock = EmptyBlock;
13267
13417
  exports.EmptyBareBlock = EmptyBareBlock;
13268
13418
  exports.BracedBlock = BracedBlock;
13269
13419
  exports.NoPostfixBracedBlock = NoPostfixBracedBlock;
13420
+ exports.NoCommaBracedBlock = NoCommaBracedBlock;
13270
13421
  exports.NonSingleBracedBlock = NonSingleBracedBlock;
13271
13422
  exports.DeclarationOrStatement = DeclarationOrStatement;
13272
13423
  exports.SingleLineStatements = SingleLineStatements;
13273
13424
  exports.PostfixedSingleLineStatements = PostfixedSingleLineStatements;
13425
+ exports.PostfixedSingleLineNoCommaStatements = PostfixedSingleLineNoCommaStatements;
13274
13426
  exports.BracedContent = BracedContent;
13275
13427
  exports.NestedBlockStatements = NestedBlockStatements;
13276
13428
  exports.NestedBlockStatement = NestedBlockStatement;
@@ -13338,11 +13490,15 @@ var require_parser = __commonJS({
13338
13490
  exports.ModuleItem = ModuleItem;
13339
13491
  exports.StatementListItem = StatementListItem;
13340
13492
  exports.PostfixedStatement = PostfixedStatement;
13493
+ exports.NoCommaStatementListItem = NoCommaStatementListItem;
13494
+ exports.PostfixedNoCommaStatement = PostfixedNoCommaStatement;
13341
13495
  exports.PostfixedExpression = PostfixedExpression;
13496
+ exports.PostfixedCommaExpression = PostfixedCommaExpression;
13342
13497
  exports.NonPipelinePostfixedExpression = NonPipelinePostfixedExpression;
13343
13498
  exports.PostfixStatement = PostfixStatement;
13344
13499
  exports._PostfixStatement = _PostfixStatement;
13345
13500
  exports.Statement = Statement;
13501
+ exports.NoCommaStatement = NoCommaStatement;
13346
13502
  exports.EmptyStatement = EmptyStatement;
13347
13503
  exports.BlockStatement = BlockStatement;
13348
13504
  exports.LabelledStatement = LabelledStatement;
@@ -13426,6 +13582,7 @@ var require_parser = __commonJS({
13426
13582
  exports.NewlineBinaryOpAllowed = NewlineBinaryOpAllowed;
13427
13583
  exports.AllowAll = AllowAll;
13428
13584
  exports.RestoreAll = RestoreAll;
13585
+ exports.CommaExpressionStatement = CommaExpressionStatement;
13429
13586
  exports.ExpressionStatement = ExpressionStatement;
13430
13587
  exports.KeywordStatement = KeywordStatement;
13431
13588
  exports.DebuggerStatement = DebuggerStatement;
@@ -13815,6 +13972,7 @@ var require_parser = __commonJS({
13815
13972
  lastAccessInCallExpression,
13816
13973
  literalValue,
13817
13974
  makeEmptyBlock,
13975
+ makeExpressionStatement,
13818
13976
  makeGetterMethod,
13819
13977
  makeLeftHandSideExpression,
13820
13978
  makeRef,
package/dist/rollup.js CHANGED
@@ -42,14 +42,46 @@ var fs = __toESM(require("fs"));
42
42
  var import_path = __toESM(require("path"));
43
43
  var import_typescript = __toESM(require("typescript"));
44
44
  var tsvfs = __toESM(require("@typescript/vfs"));
45
+ var import_os = __toESM(require("os"));
45
46
  var formatHost = {
46
47
  getCurrentDirectory: () => import_typescript.default.sys.getCurrentDirectory(),
47
48
  getNewLine: () => import_typescript.default.sys.newLine,
48
49
  getCanonicalFileName: import_typescript.default.sys.useCaseSensitiveFileNames ? (f) => f : (f) => f.toLowerCase()
49
50
  };
50
51
  var isCivet = (id) => /\.civet$/.test(id);
51
- var isCivetTranspiled = (id) => /\.civet\.(m?)(j|t)s(x?)(\?transform)?$/.test(id);
52
- var isCivetTranspiledTS = (id) => /\.civet\.(m?)ts(x?)$/.test(id);
52
+ var isCivetTranspiled = (id) => /\.civet\.[jt]sx(\?transform)?$/.test(id);
53
+ var isCivetTranspiledTS = (id) => /\.civet\.tsx$/.test(id);
54
+ var postfixRE = /(\.[jt]sx)?[?#].*$/s;
55
+ var isWindows = import_os.default.platform() === "win32";
56
+ var windowsSlashRE = /\\/g;
57
+ function cleanCivetId(id) {
58
+ return id.replace(postfixRE, "");
59
+ }
60
+ function tryStatSync(file) {
61
+ try {
62
+ return fs.statSync(file, { throwIfNoEntry: false });
63
+ } catch {
64
+ return void 0;
65
+ }
66
+ }
67
+ function slash(p) {
68
+ return p.replace(windowsSlashRE, "/");
69
+ }
70
+ function normalizePath(id) {
71
+ return import_path.default.posix.normalize(isWindows ? slash(id) : id);
72
+ }
73
+ function tryFsResolve(file) {
74
+ const fileStat = tryStatSync(file);
75
+ if (fileStat?.isFile())
76
+ return normalizePath(file);
77
+ return void 0;
78
+ }
79
+ function resolveAbsolutePath(rootDir, id) {
80
+ const resolved = tryFsResolve(import_path.default.join(rootDir, id));
81
+ if (!resolved)
82
+ return tryFsResolve(id);
83
+ return resolved;
84
+ }
53
85
  var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
54
86
  if (options.dts && options.js) {
55
87
  throw new Error("Can't have both `dts` and `js` be set to `true`.");
@@ -62,7 +94,7 @@ var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
62
94
  let fsMap = /* @__PURE__ */ new Map();
63
95
  const sourceMaps = /* @__PURE__ */ new Map();
64
96
  let compilerOptions;
65
- let rootDir;
97
+ let rootDir = process.cwd();
66
98
  return {
67
99
  name: "unplugin-civet",
68
100
  enforce: "pre",
@@ -162,10 +194,11 @@ var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
162
194
  return null;
163
195
  if (!isCivet(id) && !isCivetTranspiled(id))
164
196
  return null;
165
- const absolutePath = rootDir != null && import_path.default.isAbsolute(id) ? import_path.default.join(rootDir, id) : import_path.default.resolve(import_path.default.dirname(importer ?? ""), id);
197
+ id = cleanCivetId(id);
198
+ const absolutePath = import_path.default.isAbsolute(id) ? resolveAbsolutePath(rootDir, id) : import_path.default.resolve(import_path.default.dirname(importer ?? ""), id);
199
+ if (!absolutePath)
200
+ return null;
166
201
  const relativeId = import_path.default.relative(process.cwd(), absolutePath);
167
- if (isCivetTranspiled(id))
168
- return relativeId.replace(/\?transform$/, "");
169
202
  const relativePath = relativeId + outExt;
170
203
  return relativePath;
171
204
  },
@@ -206,9 +239,9 @@ var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
206
239
  if (options.dts || options.typecheck) {
207
240
  const resolved = import_path.default.resolve(process.cwd(), id);
208
241
  fsMap.set(resolved, code);
209
- const slash = resolved.replace(/\\/g, "/");
210
- if (resolved !== slash)
211
- fsMap.set(slash, code);
242
+ const slashed = slash(resolved);
243
+ if (resolved !== slashed)
244
+ fsMap.set(slashed, code);
212
245
  }
213
246
  return null;
214
247
  },
@@ -11,14 +11,46 @@ import * as fs from "fs";
11
11
  import path from "path";
12
12
  import ts from "typescript";
13
13
  import * as tsvfs from "@typescript/vfs";
14
+ import os from "os";
14
15
  var formatHost = {
15
16
  getCurrentDirectory: () => ts.sys.getCurrentDirectory(),
16
17
  getNewLine: () => ts.sys.newLine,
17
18
  getCanonicalFileName: ts.sys.useCaseSensitiveFileNames ? (f) => f : (f) => f.toLowerCase()
18
19
  };
19
20
  var isCivet = (id) => /\.civet$/.test(id);
20
- var isCivetTranspiled = (id) => /\.civet\.(m?)(j|t)s(x?)(\?transform)?$/.test(id);
21
- var isCivetTranspiledTS = (id) => /\.civet\.(m?)ts(x?)$/.test(id);
21
+ var isCivetTranspiled = (id) => /\.civet\.[jt]sx(\?transform)?$/.test(id);
22
+ var isCivetTranspiledTS = (id) => /\.civet\.tsx$/.test(id);
23
+ var postfixRE = /(\.[jt]sx)?[?#].*$/s;
24
+ var isWindows = os.platform() === "win32";
25
+ var windowsSlashRE = /\\/g;
26
+ function cleanCivetId(id) {
27
+ return id.replace(postfixRE, "");
28
+ }
29
+ function tryStatSync(file) {
30
+ try {
31
+ return fs.statSync(file, { throwIfNoEntry: false });
32
+ } catch {
33
+ return void 0;
34
+ }
35
+ }
36
+ function slash(p) {
37
+ return p.replace(windowsSlashRE, "/");
38
+ }
39
+ function normalizePath(id) {
40
+ return path.posix.normalize(isWindows ? slash(id) : id);
41
+ }
42
+ function tryFsResolve(file) {
43
+ const fileStat = tryStatSync(file);
44
+ if (fileStat?.isFile())
45
+ return normalizePath(file);
46
+ return void 0;
47
+ }
48
+ function resolveAbsolutePath(rootDir, id) {
49
+ const resolved = tryFsResolve(path.join(rootDir, id));
50
+ if (!resolved)
51
+ return tryFsResolve(id);
52
+ return resolved;
53
+ }
22
54
  var civetUnplugin = createUnplugin((options = {}) => {
23
55
  if (options.dts && options.js) {
24
56
  throw new Error("Can't have both `dts` and `js` be set to `true`.");
@@ -31,7 +63,7 @@ var civetUnplugin = createUnplugin((options = {}) => {
31
63
  let fsMap = /* @__PURE__ */ new Map();
32
64
  const sourceMaps = /* @__PURE__ */ new Map();
33
65
  let compilerOptions;
34
- let rootDir;
66
+ let rootDir = process.cwd();
35
67
  return {
36
68
  name: "unplugin-civet",
37
69
  enforce: "pre",
@@ -131,10 +163,11 @@ var civetUnplugin = createUnplugin((options = {}) => {
131
163
  return null;
132
164
  if (!isCivet(id) && !isCivetTranspiled(id))
133
165
  return null;
134
- const absolutePath = rootDir != null && path.isAbsolute(id) ? path.join(rootDir, id) : path.resolve(path.dirname(importer ?? ""), id);
166
+ id = cleanCivetId(id);
167
+ const absolutePath = path.isAbsolute(id) ? resolveAbsolutePath(rootDir, id) : path.resolve(path.dirname(importer ?? ""), id);
168
+ if (!absolutePath)
169
+ return null;
135
170
  const relativeId = path.relative(process.cwd(), absolutePath);
136
- if (isCivetTranspiled(id))
137
- return relativeId.replace(/\?transform$/, "");
138
171
  const relativePath = relativeId + outExt;
139
172
  return relativePath;
140
173
  },
@@ -175,9 +208,9 @@ var civetUnplugin = createUnplugin((options = {}) => {
175
208
  if (options.dts || options.typecheck) {
176
209
  const resolved = path.resolve(process.cwd(), id);
177
210
  fsMap.set(resolved, code);
178
- const slash = resolved.replace(/\\/g, "/");
179
- if (resolved !== slash)
180
- fsMap.set(slash, code);
211
+ const slashed = slash(resolved);
212
+ if (resolved !== slashed)
213
+ fsMap.set(slashed, code);
181
214
  }
182
215
  return null;
183
216
  },
@@ -218,5 +251,6 @@ var civetUnplugin = createUnplugin((options = {}) => {
218
251
  var src_default = civetUnplugin;
219
252
 
220
253
  export {
254
+ slash,
221
255
  src_default
222
256
  };
@@ -13,6 +13,7 @@ type PluginOptions = {
13
13
  typecheck?: true;
14
14
  js?: false;
15
15
  });
16
+ declare function slash(p: string): string;
16
17
  declare const civetUnplugin: unplugin.UnpluginInstance<PluginOptions, boolean>;
17
18
 
18
- export { PluginOptions, civetUnplugin as default };
19
+ export { PluginOptions, civetUnplugin as default, slash };
@@ -13,6 +13,7 @@ type PluginOptions = {
13
13
  typecheck?: true;
14
14
  js?: false;
15
15
  });
16
+ declare function slash(p: string): string;
16
17
  declare const civetUnplugin: unplugin.UnpluginInstance<PluginOptions, boolean>;
17
18
 
18
- export { PluginOptions, civetUnplugin as default };
19
+ export { PluginOptions, civetUnplugin as default, slash };