@danielx/civet 0.5.73 → 0.5.74

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -74,6 +74,11 @@ Civet is essentially a tasteful superset of TypeScript.
74
74
 
75
75
  ### Implementations of New and Proposed ES Features
76
76
 
77
+ See the [documentation](https://civet.dev/) for examples of these
78
+ and other features.
79
+
80
+ - Pattern matching (based on [TC39 proposal](https://github.com/tc39/proposal-pattern-matching))
81
+ - `switch` can match patterns like `[{type: "text", name}, ...rest]`
77
82
  - Pipe operator (based on [F# pipes](https://learn.microsoft.com/en-us/dotnet/fsharp/language-reference/symbol-and-operator-reference/#function-symbols-and-operators), [Hack pipes](https://docs.hhvm.com/hack/expressions-and-operators/pipe) and the [TC39 proposal](https://github.com/tc39/proposal-pipeline-operator))
78
83
  - `data |> Object.keys |> console.log` equivalent to
79
84
  `console.log(Object.keys(data))`
@@ -82,14 +87,19 @@ Civet is essentially a tasteful superset of TypeScript.
82
87
  - `|> await`, `|> yield`, and `|> return` (at end)
83
88
  for wrapping left-hand side with that operation
84
89
  - Short function block syntax like [Ruby symbol to proc](https://ruby-doc.org/core-3.1.2/Symbol.html#method-i-to_proc), [Crystal](https://crystal-lang.org/reference/1.6/syntax_and_semantics/blocks_and_procs.html#short-one-parameter-syntax), [Elm record access](https://elm-lang.org/docs/records#access)
85
- - Access: `x.map &.name` → `x.map(a => a.name)`
90
+ - Access: `x.map &.name` or `x.map .name` → `x.map(a => a.name)`
86
91
  - Nested access + slices: `x.map &.profile?.name[0...3]` → `x.map(a => a.profile?.name.slice(0, 3))`
87
92
  - Function call: `x.map &.callback a, b` → `x.map($ => $.callback(a, b))`
88
93
  - Unary operators: `x.map !!&` → `x.map($ => !!$)`
89
94
  - Binary operators: `x.map &+1` → `x.map($ => $+1)`
90
- - Flagging shorthand based on [from LiveScript](https://livescript.net/#literals-objects):
91
- `{+debug, -live, !verbose}` → `{debug: true, live: false, verbose: false}`
92
-
95
+ - Object literal shorthand
96
+ - `{foo()}` → `{foo: foo()}`, `{props.foo}` `{foo: props.foo}`
97
+ - ``{`${x}${y}`: z}`` → ``{[`${x}${y}`]: z}``
98
+ - `data.{x,y}` or `data{x,y}` → `{x: data.x, y: data.y}`
99
+ - Flagging shorthand based on [from LiveScript](https://livescript.net/#literals-objects):
100
+ `{+debug, -live, !verbose}` → `{debug: true, live: false, verbose: false}`
101
+ - Custom infix operators from any two-argument function
102
+ - `do` expressions, `if` expressions, `for` expressions
93
103
 
94
104
  ### Convenience for ES6+ Features
95
105
 
@@ -194,7 +204,7 @@ could be a valid property `1.e10` → `1..e10`. The workaround is to add a trail
194
204
  - `when` inside switch automatically breaks and adds block scope.
195
205
  - `else` inside switch adds block scope.
196
206
  - No whitespace between unary operators and operands. Mandatory whitespace between condition and ternary `?` ex. `x ? a : b` since `x?` is the unary existential operator.
197
- - No labels (yet...)
207
+ - Labels written `:label` (except for special case `$:` for Svelte)
198
208
 
199
209
  ### Scripting Improvements
200
210
 
package/dist/browser.js CHANGED
@@ -642,6 +642,7 @@ ${input.slice(result.pos)}
642
642
  StatementListItem,
643
643
  PostfixedStatement,
644
644
  PostfixedExpression,
645
+ NonPipelinePostfixedExpression,
645
646
  PostfixStatement,
646
647
  Statement,
647
648
  EmptyStatement,
@@ -665,6 +666,7 @@ ${input.slice(result.pos)}
665
666
  LoopStatement,
666
667
  LoopClause,
667
668
  DoWhileStatement,
669
+ DoStatement,
668
670
  WhileStatement,
669
671
  WhileClause,
670
672
  ForStatement,
@@ -1038,6 +1040,7 @@ ${input.slice(result.pos)}
1038
1040
  TrackIndented,
1039
1041
  Samedent,
1040
1042
  IndentedFurther,
1043
+ NotDedented,
1041
1044
  PushIndent,
1042
1045
  PopIndent,
1043
1046
  Nested
@@ -1966,7 +1969,7 @@ ${input.slice(result.pos)}
1966
1969
  var rhs = $2;
1967
1970
  return [[], op, [], rhs];
1968
1971
  });
1969
- var BinaryOpRHS$1 = $S(__, BinaryOp, $C(_, $S(EOS, __)), RHS);
1972
+ var BinaryOpRHS$1 = $S(NotDedented, BinaryOp, $C(_, $S(EOS, __)), RHS);
1970
1973
  function BinaryOpRHS(state) {
1971
1974
  let eventData;
1972
1975
  if (state.events) {
@@ -2448,7 +2451,7 @@ ${input.slice(result.pos)}
2448
2451
  return result;
2449
2452
  }
2450
2453
  }
2451
- var FatArrowBody$0 = $T($S($N(EOS), PostfixedExpression, $N(SemicolonDelimiter)), function(value) {
2454
+ var FatArrowBody$0 = $T($S($N(EOS), NonPipelinePostfixedExpression, $N(SemicolonDelimiter)), function(value) {
2452
2455
  var exp = value[1];
2453
2456
  return exp;
2454
2457
  });
@@ -2579,12 +2582,13 @@ ${input.slice(result.pos)}
2579
2582
  return result;
2580
2583
  }
2581
2584
  }
2582
- var PipelineExpression$0 = $TS($S(PipelineHeadItem, $P($S(__, Pipe, __, PipelineTailItem))), function($skip, $loc, $0, $1, $2) {
2583
- var head = $1;
2584
- var body = $2;
2585
+ var PipelineExpression$0 = $TS($S($E(_), PipelineHeadItem, $P($S(NotDedented, Pipe, __, PipelineTailItem))), function($skip, $loc, $0, $1, $2, $3) {
2586
+ var ws = $1;
2587
+ var head = $2;
2588
+ var body = $3;
2585
2589
  return {
2586
2590
  type: "PipelineExpression",
2587
- children: [head, body]
2591
+ children: [ws, head, body]
2588
2592
  };
2589
2593
  });
2590
2594
  function PipelineExpression(state) {
@@ -8365,6 +8369,35 @@ ${input.slice(result.pos)}
8365
8369
  return result;
8366
8370
  }
8367
8371
  }
8372
+ var NonPipelinePostfixedExpression$0 = $TS($S(NonPipelineExtendedExpression, $E($S($Q(TrailingComment), PostfixStatement))), function($skip, $loc, $0, $1, $2) {
8373
+ var expression = $1;
8374
+ var post = $2;
8375
+ if (post)
8376
+ return module.attachPostfixStatementAsExpression(expression, post);
8377
+ return expression;
8378
+ });
8379
+ function NonPipelinePostfixedExpression(state) {
8380
+ let eventData;
8381
+ if (state.events) {
8382
+ const result = state.events.enter?.("NonPipelinePostfixedExpression", state);
8383
+ if (result) {
8384
+ if (result.cache)
8385
+ return result.cache;
8386
+ eventData = result.data;
8387
+ }
8388
+ }
8389
+ if (state.tokenize) {
8390
+ const result = $TOKEN("NonPipelinePostfixedExpression", state, NonPipelinePostfixedExpression$0(state));
8391
+ if (state.events)
8392
+ state.events.exit?.("NonPipelinePostfixedExpression", state, result, eventData);
8393
+ return result;
8394
+ } else {
8395
+ const result = NonPipelinePostfixedExpression$0(state);
8396
+ if (state.events)
8397
+ state.events.exit?.("NonPipelinePostfixedExpression", state, result, eventData);
8398
+ return result;
8399
+ }
8400
+ }
8368
8401
  var PostfixStatement$0 = ForClause;
8369
8402
  var PostfixStatement$1 = IfClause;
8370
8403
  var PostfixStatement$2 = LoopClause;
@@ -8901,8 +8934,11 @@ ${input.slice(result.pos)}
8901
8934
  var IterationStatement$1 = $T($S($N(CoffeeDoEnabled), DoWhileStatement), function(value) {
8902
8935
  return value[1];
8903
8936
  });
8904
- var IterationStatement$2 = WhileStatement;
8905
- var IterationStatement$3 = ForStatement;
8937
+ var IterationStatement$2 = $T($S($N(CoffeeDoEnabled), DoStatement), function(value) {
8938
+ return value[1];
8939
+ });
8940
+ var IterationStatement$3 = WhileStatement;
8941
+ var IterationStatement$4 = ForStatement;
8906
8942
  function IterationStatement(state) {
8907
8943
  let eventData;
8908
8944
  if (state.events) {
@@ -8914,12 +8950,12 @@ ${input.slice(result.pos)}
8914
8950
  }
8915
8951
  }
8916
8952
  if (state.tokenize) {
8917
- const result = $TOKEN("IterationStatement", state, IterationStatement$0(state) || IterationStatement$1(state) || IterationStatement$2(state) || IterationStatement$3(state));
8953
+ const result = $TOKEN("IterationStatement", state, IterationStatement$0(state) || IterationStatement$1(state) || IterationStatement$2(state) || IterationStatement$3(state) || IterationStatement$4(state));
8918
8954
  if (state.events)
8919
8955
  state.events.exit?.("IterationStatement", state, result, eventData);
8920
8956
  return result;
8921
8957
  } else {
8922
- const result = IterationStatement$0(state) || IterationStatement$1(state) || IterationStatement$2(state) || IterationStatement$3(state);
8958
+ const result = IterationStatement$0(state) || IterationStatement$1(state) || IterationStatement$2(state) || IterationStatement$3(state) || IterationStatement$4(state);
8923
8959
  if (state.events)
8924
8960
  state.events.exit?.("IterationStatement", state, result, eventData);
8925
8961
  return result;
@@ -8928,6 +8964,7 @@ ${input.slice(result.pos)}
8928
8964
  var IterationExpression$0 = $TS($S(IterationStatement), function($skip, $loc, $0, $1) {
8929
8965
  return {
8930
8966
  type: "IterationExpression",
8967
+ subtype: $1.type,
8931
8968
  children: [$1],
8932
8969
  block: $1.block
8933
8970
  };
@@ -9036,6 +9073,37 @@ ${input.slice(result.pos)}
9036
9073
  return result;
9037
9074
  }
9038
9075
  }
9076
+ var DoStatement$0 = $TS($S(Do, NoPostfixBracedBlock), function($skip, $loc, $0, $1, $2) {
9077
+ var block = $2;
9078
+ block = module.insertTrimmingSpace(block, "");
9079
+ return {
9080
+ type: "DoStatement",
9081
+ children: [block],
9082
+ block
9083
+ };
9084
+ });
9085
+ function DoStatement(state) {
9086
+ let eventData;
9087
+ if (state.events) {
9088
+ const result = state.events.enter?.("DoStatement", state);
9089
+ if (result) {
9090
+ if (result.cache)
9091
+ return result.cache;
9092
+ eventData = result.data;
9093
+ }
9094
+ }
9095
+ if (state.tokenize) {
9096
+ const result = $TOKEN("DoStatement", state, DoStatement$0(state));
9097
+ if (state.events)
9098
+ state.events.exit?.("DoStatement", state, result, eventData);
9099
+ return result;
9100
+ } else {
9101
+ const result = DoStatement$0(state);
9102
+ if (state.events)
9103
+ state.events.exit?.("DoStatement", state, result, eventData);
9104
+ return result;
9105
+ }
9106
+ }
9039
9107
  var WhileStatement$0 = $TS($S(WhileClause, Block), function($skip, $loc, $0, $1, $2) {
9040
9108
  var clause = $1;
9041
9109
  var block = $2;
@@ -9977,13 +10045,31 @@ ${input.slice(result.pos)}
9977
10045
  var c = $3;
9978
10046
  var f = $4;
9979
10047
  if (!c && !f) {
10048
+ const e = [];
10049
+ const emptyCatchBlock = {
10050
+ type: "BlockStatement",
10051
+ expressions: e,
10052
+ children: ["{", e, "}"],
10053
+ bare: false,
10054
+ empty: true
10055
+ };
10056
+ c = {
10057
+ type: "CatchClause",
10058
+ children: [" catch(e) ", emptyCatchBlock],
10059
+ block: emptyCatchBlock
10060
+ };
9980
10061
  return {
9981
10062
  type: "TryStatement",
9982
- children: [t, b, " catch(e) {}"]
10063
+ blocks: [b, emptyCatchBlock],
10064
+ children: [t, b, c]
9983
10065
  };
9984
10066
  }
10067
+ const blocks = [b];
10068
+ if (c)
10069
+ blocks.push(c.block);
9985
10070
  return {
9986
10071
  type: "TryStatement",
10072
+ blocks,
9987
10073
  children: [t, b, c, f]
9988
10074
  };
9989
10075
  });
@@ -10013,7 +10099,7 @@ ${input.slice(result.pos)}
10013
10099
  var t = $0;
10014
10100
  return {
10015
10101
  type: "TryExpression",
10016
- blocks: [t.children[1], t.children[2]?.[3]],
10102
+ blocks: t.blocks,
10017
10103
  children: ["(()=>{", t, "})()"]
10018
10104
  };
10019
10105
  });
@@ -10039,7 +10125,14 @@ ${input.slice(result.pos)}
10039
10125
  return result;
10040
10126
  }
10041
10127
  }
10042
- var CatchClause$0 = $S($C(Samedent, _), Catch, $E(CatchBind), $C(ThenClause, BracedOrEmptyBlock));
10128
+ var CatchClause$0 = $TS($S($C(Samedent, _), Catch, $E(CatchBind), $C(ThenClause, BracedOrEmptyBlock)), function($skip, $loc, $0, $1, $2, $3, $4) {
10129
+ var block = $4;
10130
+ return {
10131
+ type: "CatchClause",
10132
+ children: $0,
10133
+ block
10134
+ };
10135
+ });
10043
10136
  function CatchClause(state) {
10044
10137
  let eventData;
10045
10138
  if (state.events) {
@@ -13221,7 +13314,7 @@ ${input.slice(result.pos)}
13221
13314
  }
13222
13315
  }
13223
13316
  var StatementDelimiter$0 = SemicolonDelimiter;
13224
- var StatementDelimiter$1 = $S($Y($S(Samedent, $C($EXPECT($L2, fail, 'StatementDelimiter "("'), $EXPECT($L97, fail, 'StatementDelimiter "["'), $EXPECT($L98, fail, 'StatementDelimiter "`"'), $EXPECT($L58, fail, 'StatementDelimiter "+"'), $EXPECT($L17, fail, 'StatementDelimiter "-"'), $EXPECT($L54, fail, 'StatementDelimiter "*"'), $EXPECT($L55, fail, 'StatementDelimiter "/"'), ObjectLiteral, Arrow, $S(Function, $E($S($E(_), Star)), $E(_), $EXPECT($L2, fail, 'StatementDelimiter "("'))))), InsertSemicolon);
13317
+ var StatementDelimiter$1 = $S($Y($S(Samedent, $C($EXPECT($L2, fail, 'StatementDelimiter "("'), $EXPECT($L97, fail, 'StatementDelimiter "["'), $EXPECT($L98, fail, 'StatementDelimiter "`"'), $EXPECT($L58, fail, 'StatementDelimiter "+"'), $EXPECT($L17, fail, 'StatementDelimiter "-"'), $EXPECT($L54, fail, 'StatementDelimiter "*"'), $EXPECT($L55, fail, 'StatementDelimiter "/"'), ObjectLiteral, Arrow, FatArrow, $S(Function, $E($S($E(_), Star)), $E(_), $EXPECT($L2, fail, 'StatementDelimiter "("'))))), InsertSemicolon);
13225
13318
  var StatementDelimiter$2 = $Y(EOS);
13226
13319
  function StatementDelimiter(state) {
13227
13320
  let eventData;
@@ -17454,6 +17547,9 @@ ${input.slice(result.pos)}
17454
17547
  var TypeSuffix$1 = $T($S(QuestionMark, $E(_)), function(value) {
17455
17548
  return { "type": "TypeSuffix", "ts": true, "children": value };
17456
17549
  });
17550
+ var TypeSuffix$2 = $T($S(NonNullAssertion, $E(_), $E($S(Colon, Type))), function(value) {
17551
+ return { "type": "TypeSuffix", "ts": true, "children": value };
17552
+ });
17457
17553
  function TypeSuffix(state) {
17458
17554
  let eventData;
17459
17555
  if (state.events) {
@@ -17465,12 +17561,12 @@ ${input.slice(result.pos)}
17465
17561
  }
17466
17562
  }
17467
17563
  if (state.tokenize) {
17468
- const result = $TOKEN("TypeSuffix", state, TypeSuffix$0(state) || TypeSuffix$1(state));
17564
+ const result = $TOKEN("TypeSuffix", state, TypeSuffix$0(state) || TypeSuffix$1(state) || TypeSuffix$2(state));
17469
17565
  if (state.events)
17470
17566
  state.events.exit?.("TypeSuffix", state, result, eventData);
17471
17567
  return result;
17472
17568
  } else {
17473
- const result = TypeSuffix$0(state) || TypeSuffix$1(state);
17569
+ const result = TypeSuffix$0(state) || TypeSuffix$1(state) || TypeSuffix$2(state);
17474
17570
  if (state.events)
17475
17571
  state.events.exit?.("TypeSuffix", state, result, eventData);
17476
17572
  return result;
@@ -19875,15 +19971,29 @@ ${input.slice(result.pos)}
19875
19971
  return post;
19876
19972
  };
19877
19973
  function expressionizeIteration(exp) {
19974
+ const i = exp.children.indexOf(exp.block);
19975
+ if (exp.subtype === "DoStatement") {
19976
+ insertReturn(exp.block);
19977
+ exp.children.splice(i, 1, "(()=>", ...exp.children, ")()");
19978
+ return;
19979
+ }
19878
19980
  const resultsRef = {
19879
19981
  type: "Ref",
19880
19982
  base: "results",
19881
19983
  id: "results"
19882
19984
  };
19883
19985
  insertPush(exp.block, resultsRef);
19884
- exp.children = ["(()=>{const ", resultsRef, "=[];", ...exp.children, "; return ", resultsRef, "})()"];
19986
+ exp.children.splice(i, 1, "(()=>{const ", resultsRef, "=[];", ...exp.children, "; return ", resultsRef, "})()");
19885
19987
  }
19886
19988
  function wrapIterationReturningResults(statement, outerRef) {
19989
+ if (statement.type === "DoStatement") {
19990
+ if (outerRef) {
19991
+ insertPush(statement.block, outerRef);
19992
+ } else {
19993
+ insertReturn(statement.block);
19994
+ }
19995
+ return;
19996
+ }
19887
19997
  const resultsRef = {
19888
19998
  type: "Ref",
19889
19999
  base: "results",
@@ -19906,7 +20016,12 @@ ${input.slice(result.pos)}
19906
20016
  return;
19907
20017
  switch (node.type) {
19908
20018
  case "BlockStatement":
19909
- insertPush(node.expressions[node.expressions.length - 1], ref);
20019
+ if (node.expressions.length) {
20020
+ const last = node.expressions[node.expressions.length - 1];
20021
+ insertPush(last, ref);
20022
+ } else {
20023
+ node.expressions.push([ref, ".push(void 0);"]);
20024
+ }
19910
20025
  return;
19911
20026
  case "CaseBlock":
19912
20027
  node.clauses.forEach((clause) => {
@@ -19939,6 +20054,7 @@ ${input.slice(result.pos)}
19939
20054
  return;
19940
20055
  case "ForStatement":
19941
20056
  case "IterationStatement":
20057
+ case "DoStatement":
19942
20058
  wrapIterationReturningResults(exp, ref);
19943
20059
  return;
19944
20060
  case "BlockStatement":
@@ -19958,9 +20074,7 @@ ${input.slice(result.pos)}
19958
20074
  insertPush(exp.children[2], ref);
19959
20075
  return;
19960
20076
  case "TryStatement":
19961
- insertPush(exp.children[1], ref);
19962
- if (exp.children[2])
19963
- insertPush(exp.children[2][2], ref);
20077
+ exp.blocks.forEach((block) => insertPush(block, ref));
19964
20078
  return;
19965
20079
  }
19966
20080
  node.splice(1, 0, ref, ".push(");
@@ -19996,7 +20110,14 @@ ${input.slice(result.pos)}
19996
20110
  return;
19997
20111
  switch (node.type) {
19998
20112
  case "BlockStatement":
19999
- insertReturn(node.expressions[node.expressions.length - 1]);
20113
+ if (node.expressions.length) {
20114
+ const last = node.expressions[node.expressions.length - 1];
20115
+ insertReturn(last);
20116
+ } else {
20117
+ if (node.parent.type === "CatchClause") {
20118
+ node.expressions.push(["return"]);
20119
+ }
20120
+ }
20000
20121
  return;
20001
20122
  case "WhenClause":
20002
20123
  node.children.splice(node.children.indexOf(node.break), 1);
@@ -20029,6 +20150,7 @@ ${input.slice(result.pos)}
20029
20150
  return;
20030
20151
  case "ForStatement":
20031
20152
  case "IterationStatement":
20153
+ case "DoStatement":
20032
20154
  wrapIterationReturningResults(exp);
20033
20155
  return;
20034
20156
  case "BlockStatement":
@@ -20048,9 +20170,7 @@ ${input.slice(result.pos)}
20048
20170
  insertSwitchReturns(exp);
20049
20171
  return;
20050
20172
  case "TryStatement":
20051
- insertReturn(exp.children[1]);
20052
- if (exp.children[2])
20053
- insertReturn(exp.children[2][3]);
20173
+ exp.blocks.forEach((block) => insertReturn(block));
20054
20174
  return;
20055
20175
  }
20056
20176
  if (node[node.length - 1]?.type === "SemicolonDelimiter")
@@ -20226,10 +20346,12 @@ ${input.slice(result.pos)}
20226
20346
  if (Array.isArray(target)) {
20227
20347
  if (target.length === 1) {
20228
20348
  return module.skipIfOnlyWS(target[0]);
20349
+ } else if (target.every((e) => module.skipIfOnlyWS(e) === void 0)) {
20350
+ return void 0;
20229
20351
  }
20230
20352
  return target;
20231
20353
  }
20232
- if (target.token && target.token.trim() === "") {
20354
+ if (target.token != null && target.token.trim() === "") {
20233
20355
  return void 0;
20234
20356
  }
20235
20357
  return target;
@@ -20764,8 +20886,9 @@ ${input.slice(result.pos)}
20764
20886
  module.attachPostfixStatementAsExpression = function(exp, post) {
20765
20887
  let clause;
20766
20888
  switch (post[1].type) {
20767
- case "IterationStatement":
20768
20889
  case "ForStatement":
20890
+ case "IterationStatement":
20891
+ case "DoStatement":
20769
20892
  clause = module.addPostfixStatement(exp, ...post);
20770
20893
  return {
20771
20894
  type: "IterationExpression",
@@ -20970,6 +21093,37 @@ ${input.slice(result.pos)}
20970
21093
  return pattern;
20971
21094
  }
20972
21095
  }
21096
+ function aggregateDuplicateBindings(bindings) {
21097
+ const props2 = gatherRecursiveAll(bindings, (n) => n.type === "BindingMatchProperty");
21098
+ const declarations = [];
21099
+ const propsGroupedByName = /* @__PURE__ */ new Map();
21100
+ for (const p of props2) {
21101
+ const { name } = p;
21102
+ const key = name.name;
21103
+ if (propsGroupedByName.has(key)) {
21104
+ propsGroupedByName.get(key).push(p);
21105
+ } else {
21106
+ propsGroupedByName.set(key, [p]);
21107
+ }
21108
+ }
21109
+ propsGroupedByName.forEach((shared, key) => {
21110
+ if (shared.length === 1)
21111
+ return;
21112
+ const refs = shared.map((p) => {
21113
+ const ref = {
21114
+ type: "Ref",
21115
+ base: key,
21116
+ id: key
21117
+ };
21118
+ p.children.push(": ", ref);
21119
+ return ref;
21120
+ });
21121
+ declarations.push(["const ", key, " = [", ...refs.map((r, i) => {
21122
+ return i === 0 ? r : [", ", r];
21123
+ }), "]"]);
21124
+ });
21125
+ return declarations;
21126
+ }
20973
21127
  function processPatternMatching(statements) {
20974
21128
  gatherRecursiveAll(statements, (n) => n.type === "SwitchStatement" || n.type === "SwitchExpression").forEach((s) => {
20975
21129
  const { caseBlock } = s;
@@ -21036,10 +21190,13 @@ ${input.slice(result.pos)}
21036
21190
  if (pattern.properties?.length === 0)
21037
21191
  break;
21038
21192
  let [splices, thisAssignments] = gatherBindingCode(pattern);
21193
+ const patternBindings = nonMatcherBindings(pattern);
21039
21194
  splices = splices.map((s2) => [", ", nonMatcherBindings(s2)]);
21040
21195
  thisAssignments = thisAssignments.map((a) => [indent, a, ";\n"]);
21041
- prefix.push([indent, "const ", nonMatcherBindings(pattern), " = ", ref, splices, ";\n"]);
21196
+ const duplicateDeclarations = aggregateDuplicateBindings([patternBindings, splices]);
21197
+ prefix.push([indent, "const ", patternBindings, " = ", ref, splices, ";\n"]);
21042
21198
  prefix.push(...thisAssignments);
21199
+ prefix.push(...duplicateDeclarations.map((d) => [indent, d, ";\n"]));
21043
21200
  break;
21044
21201
  }
21045
21202
  }
@@ -21071,10 +21228,10 @@ ${input.slice(result.pos)}
21071
21228
  }
21072
21229
  function processPipelineExpressions(statements) {
21073
21230
  gatherRecursiveAll(statements, (n) => n.type === "PipelineExpression").forEach((s) => {
21074
- const [, body] = s.children;
21075
- let [arg] = s.children;
21231
+ const [ws, , body] = s.children;
21232
+ let [, arg] = s.children;
21076
21233
  let i = 0, l = body.length;
21077
- const children = [];
21234
+ const children = [ws];
21078
21235
  for (i = 0; i < l; i++) {
21079
21236
  const step = body[i];
21080
21237
  const [leadingComment, pipe, trailingComment, expr] = step;
@@ -21099,7 +21256,17 @@ ${input.slice(result.pos)}
21099
21256
  returns ? arg : null
21100
21257
  );
21101
21258
  if (result.type === "ReturnStatement") {
21259
+ if (i < l - 1) {
21260
+ result.children.push({
21261
+ type: "Error",
21262
+ message: "Can't continue a pipeline after returning"
21263
+ });
21264
+ }
21102
21265
  arg = result;
21266
+ if (children[children.length - 1] === ",") {
21267
+ children.pop();
21268
+ children.push(";");
21269
+ }
21103
21270
  break;
21104
21271
  }
21105
21272
  if (returning) {
@@ -21530,6 +21697,36 @@ ${input.slice(result.pos)}
21530
21697
  return result;
21531
21698
  }
21532
21699
  }
21700
+ var NotDedented$0 = $TS($S($E($C(Samedent, IndentedFurther)), $E(_)), function($skip, $loc, $0, $1, $2) {
21701
+ const ws = [];
21702
+ if ($1)
21703
+ ws.push(...$1);
21704
+ if ($2)
21705
+ ws.push(...$2);
21706
+ return ws.flat(Infinity).filter(Boolean);
21707
+ });
21708
+ function NotDedented(state) {
21709
+ let eventData;
21710
+ if (state.events) {
21711
+ const result = state.events.enter?.("NotDedented", state);
21712
+ if (result) {
21713
+ if (result.cache)
21714
+ return result.cache;
21715
+ eventData = result.data;
21716
+ }
21717
+ }
21718
+ if (state.tokenize) {
21719
+ const result = $TOKEN("NotDedented", state, NotDedented$0(state));
21720
+ if (state.events)
21721
+ state.events.exit?.("NotDedented", state, result, eventData);
21722
+ return result;
21723
+ } else {
21724
+ const result = NotDedented$0(state);
21725
+ if (state.events)
21726
+ state.events.exit?.("NotDedented", state, result, eventData);
21727
+ return result;
21728
+ }
21729
+ }
21533
21730
  var PushIndent$0 = $Y($S(EOS, TrackIndented));
21534
21731
  function PushIndent(state) {
21535
21732
  let eventData;
@@ -22057,7 +22254,7 @@ ${input.slice(result.pos)}
22057
22254
  var uncacheable;
22058
22255
  ({ parse } = import_parser.default);
22059
22256
  ({ SourceMap: SourceMap2, base64Encode: base64Encode2 } = util_exports);
22060
- uncacheable = /* @__PURE__ */ new Set(["ActualAssignment", "AllowAll", "AllowIndentedApplication", "AllowTrailingMemberProperty", "AllowedTrailingMemberExpressions", "ApplicationStart", "Arguments", "ArgumentsWithTrailingMemberExpressions", "ArrowFunction", "ArrowFunctionTail", "AssignmentExpression", "AssignmentExpressionTail", "BinaryOpExpression", "BinaryOpRHS", "BracedBlock", "BracedObjectLiteralContent", "BracedOrEmptyBlock", "CallExpression", "CallExpressionRest", "CoffeeCommentEnabled", "CommaDelimiter", "ConditionalExpression", "Declaration", "Debugger", "ElseClause", "Expression", "ExpressionStatement", "ExpressionWithIndentedApplicationForbidden", "ExtendedExpression", "FatArrowBody", "ForbidIndentedApplication", "ForbidTrailingMemberProperty", "FunctionDeclaration", "FunctionExpression", "HoistableDeclaration", "ImplicitArguments", "ImplicitInlineObjectPropertyDelimiter", "ImplicitNestedBlock", "IndentedApplicationAllowed", "IndentedFurther", "IndentedJSXChildExpression", "InlineObjectLiteral", "InsertIndent", "JSXChild", "JSXChildren", "JSXElement", "JSXFragment", "JSXImplicitFragment", "JSXMixedChildren", "JSXNested", "JSXNestedChildren", "JSXOptionalClosingElement", "JSXOptionalClosingFragment", "JSXTag", "LeftHandSideExpression", "MemberExpression", "MemberExpressionRest", "Nested", "NestedBindingElement", "NestedBindingElements", "NestedBlockExpression", "NestedBlockExpression", "NestedBlockStatement", "NestedBlockStatements", "NestedClassSignatureElement", "NestedClassSignatureElements", "NestedDeclareElement", "NestedDeclareElements", "NestedElement", "NestedElementList", "NestedImplicitObjectLiteral", "NestedImplicitPropertyDefinition", "NestedImplicitPropertyDefinitions", "NestedInterfaceProperty", "NestedJSXChildExpression", "NestedModuleItem", "NestedModuleItems", "NestedObject", "NestedPropertyDefinitions", "NonSingleBracedBlock", "ObjectLiteral", "PopIndent", "PopJSXStack", "PostfixedExpression", "PostfixedStatement", "PrimaryExpression", "PushIndent", "PushJSXOpeningElement", "PushJSXOpeningFragment", "RestoreAll", "RestoreIndentedApplication", "RestoreTrailingMemberProperty", "RHS", "Samedent", "ShortCircuitExpression", "SingleLineAssignmentExpression", "SingleLineComment", "SingleLineStatements", "SnugNamedProperty", "Statement", "StatementListItem", "SuffixedExpression", "SuffixedStatement", "ThinArrowFunction", "TrackIndented", "TrailingMemberExpressions", "TrailingMemberPropertyAllowed", "TypedJSXElement", "TypedJSXFragment", "UnaryExpression", "UpdateExpression"]);
22257
+ uncacheable = /* @__PURE__ */ new Set(["ActualAssignment", "AllowAll", "AllowIndentedApplication", "AllowTrailingMemberProperty", "AllowedTrailingMemberExpressions", "ApplicationStart", "Arguments", "ArgumentsWithTrailingMemberExpressions", "ArrowFunction", "ArrowFunctionTail", "AssignmentExpression", "AssignmentExpressionTail", "BinaryOpExpression", "BinaryOpRHS", "BracedBlock", "BracedObjectLiteralContent", "BracedOrEmptyBlock", "CallExpression", "CallExpressionRest", "CoffeeCommentEnabled", "CommaDelimiter", "ConditionalExpression", "Declaration", "Debugger", "ElseClause", "Expression", "ExpressionStatement", "ExpressionWithIndentedApplicationForbidden", "ExtendedExpression", "FatArrowBody", "ForbidIndentedApplication", "ForbidTrailingMemberProperty", "FunctionDeclaration", "FunctionExpression", "HoistableDeclaration", "ImplicitArguments", "ImplicitInlineObjectPropertyDelimiter", "ImplicitNestedBlock", "IndentedApplicationAllowed", "IndentedFurther", "IndentedJSXChildExpression", "InlineObjectLiteral", "InsertIndent", "JSXChild", "JSXChildren", "JSXElement", "JSXFragment", "JSXImplicitFragment", "JSXMixedChildren", "JSXNested", "JSXNestedChildren", "JSXOptionalClosingElement", "JSXOptionalClosingFragment", "JSXTag", "LeftHandSideExpression", "MemberExpression", "MemberExpressionRest", "Nested", "NestedBindingElement", "NestedBindingElements", "NestedBlockExpression", "NestedBlockExpression", "NestedBlockStatement", "NestedBlockStatements", "NestedClassSignatureElement", "NestedClassSignatureElements", "NestedDeclareElement", "NestedDeclareElements", "NestedElement", "NestedElementList", "NestedImplicitObjectLiteral", "NestedImplicitPropertyDefinition", "NestedImplicitPropertyDefinitions", "NestedInterfaceProperty", "NestedJSXChildExpression", "NestedModuleItem", "NestedModuleItems", "NestedObject", "NestedPropertyDefinitions", "NonSingleBracedBlock", "NotDedented", "ObjectLiteral", "PopIndent", "PopJSXStack", "PostfixedExpression", "PostfixedStatement", "PrimaryExpression", "PushIndent", "PushJSXOpeningElement", "PushJSXOpeningFragment", "RestoreAll", "RestoreIndentedApplication", "RestoreTrailingMemberProperty", "RHS", "Samedent", "ShortCircuitExpression", "SingleLineAssignmentExpression", "SingleLineComment", "SingleLineStatements", "SnugNamedProperty", "Statement", "StatementListItem", "SuffixedExpression", "SuffixedStatement", "ThinArrowFunction", "TrackIndented", "TrailingMemberExpressions", "TrailingMemberPropertyAllowed", "TypedJSXElement", "TypedJSXFragment", "UnaryExpression", "UpdateExpression"]);
22061
22258
  var compile = function(src, options) {
22062
22259
  var ast, code, events, filename, ref, result, sm, srcMapJSON;
22063
22260
  if (!options) {
package/dist/civet CHANGED
File without changes