@danielx/civet 0.5.3 → 0.5.5

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
@@ -217,6 +217,11 @@ Things Added that CoffeeScript didn't
217
217
  `sum=x+1` → `sum={x+1}`, `list=[1, 2, 3]` → `list={[1, 2, 3]}`
218
218
  - Attributes can use computed property names:
219
219
  `[expr]={value}` → `{...{[expr]: value}}`
220
+ - `"civet solid"` flag adds correct types for JSX elements and fragments.
221
+ Use `"civet solid client"` (default) for client-only code,
222
+ `"civet solid server"` for server-only code (SSR only), or
223
+ `"civet solid client server"` for isomorphic code that runs on
224
+ client and server (SSR + hydration).
220
225
  - CoffeeScript improvements
221
226
  - Postfix loop `run() loop` → `while(true) run()`
222
227
  - Character range literals `["a".."z"]`, `['f'..'a']`, `['0'..'9']`
package/dist/browser.js CHANGED
@@ -833,10 +833,12 @@ ${input.slice(result.pos)}
833
833
  When,
834
834
  While,
835
835
  Yield,
836
+ TypedJSXElement,
836
837
  JSXElement,
837
838
  JSXSelfClosingElement,
838
839
  JSXOpeningElement,
839
840
  JSXClosingElement,
841
+ TypedJSXFragment,
840
842
  JSXFragment,
841
843
  JSXElementName,
842
844
  JSXIdentifierName,
@@ -898,6 +900,8 @@ ${input.slice(result.pos)}
898
900
  FunctionType,
899
901
  TypeArguments,
900
902
  CompactTypeArguments,
903
+ TypeArgument,
904
+ TypeArgumentDelimiter,
901
905
  TypeParameters,
902
906
  TypeParameter,
903
907
  TypeConstraint,
@@ -2001,8 +2005,8 @@ ${input.slice(result.pos)}
2001
2005
  var PrimaryExpression$7 = RegularExpressionLiteral;
2002
2006
  var PrimaryExpression$8 = TemplateLiteral;
2003
2007
  var PrimaryExpression$9 = ParenthesizedExpression;
2004
- var PrimaryExpression$10 = JSXElement;
2005
- var PrimaryExpression$11 = JSXFragment;
2008
+ var PrimaryExpression$10 = TypedJSXElement;
2009
+ var PrimaryExpression$11 = TypedJSXFragment;
2006
2010
  function PrimaryExpression(state) {
2007
2011
  if (state.events) {
2008
2012
  const result = state.events.enter?.("PrimaryExpression", state);
@@ -10568,20 +10572,45 @@ ${input.slice(result.pos)}
10568
10572
  return result;
10569
10573
  }
10570
10574
  }
10575
+ var TypedJSXElement$0 = $TS($S(JSXElement), function($skip, $loc, $0, $1) {
10576
+ const type = module.typeOfJSXElement($1);
10577
+ return type ? [
10578
+ { ts: true, children: ["("] },
10579
+ $1,
10580
+ { ts: true, children: [" as any as ", type, ")"] }
10581
+ ] : $1;
10582
+ });
10583
+ function TypedJSXElement(state) {
10584
+ if (state.events) {
10585
+ const result = state.events.enter?.("TypedJSXElement", state);
10586
+ if (result)
10587
+ return result.cache;
10588
+ }
10589
+ if (state.tokenize) {
10590
+ const result = $TOKEN("TypedJSXElement", state, TypedJSXElement$0(state));
10591
+ if (state.events)
10592
+ state.events.exit?.("TypedJSXElement", state, result);
10593
+ return result;
10594
+ } else {
10595
+ const result = TypedJSXElement$0(state);
10596
+ if (state.events)
10597
+ state.events.exit?.("TypedJSXElement", state, result);
10598
+ return result;
10599
+ }
10600
+ }
10571
10601
  var JSXElement$0 = JSXSelfClosingElement;
10572
10602
  var JSXElement$1 = $TS($S(JSXOpeningElement, $E(JSXChildren), __, JSXClosingElement), function($skip, $loc, $0, $1, $2, $3, $4) {
10573
10603
  if ($1[1] !== $4[2])
10574
10604
  return $skip;
10575
- return $0;
10605
+ return { type: "JSXElement", children: $0 };
10576
10606
  });
10577
10607
  var JSXElement$2 = $TS($S(JSXOpeningElement, JSXMixedChildren, InsertNewline, InsertIndent), function($skip, $loc, $0, $1, $2, $3, $4) {
10578
10608
  var open = $1;
10579
10609
  var children = $2;
10580
- if (children.length) {
10581
- return [...$0, ["</", open[1], ">"]];
10582
- } else {
10583
- return [open.slice(0, -1), " />"];
10584
- }
10610
+ return {
10611
+ type: "JSXElement",
10612
+ children: children.jsxChildren.length ? [...$0, ["</", open[1], ">"]] : [open.slice(0, -1), " />"]
10613
+ };
10585
10614
  });
10586
10615
  var JSXElement$3 = $TS($S(JSXOpeningElement), function($skip, $loc, $0, $1) {
10587
10616
  throw new Error(`could not parse JSX element "${require_generate()($0)}" at pos ${$loc.pos}`);
@@ -10604,7 +10633,9 @@ ${input.slice(result.pos)}
10604
10633
  return result;
10605
10634
  }
10606
10635
  }
10607
- var JSXSelfClosingElement$0 = $S($EXPECT($L5, fail, 'JSXSelfClosingElement "<"'), $TEXT(JSXElementName), $E(CompactTypeArguments), $E(JSXAttributes), __, $EXPECT($L147, fail, 'JSXSelfClosingElement "/>"'));
10636
+ var JSXSelfClosingElement$0 = $TS($S($EXPECT($L5, fail, 'JSXSelfClosingElement "<"'), $TEXT(JSXElementName), $E(CompactTypeArguments), $E(JSXAttributes), __, $EXPECT($L147, fail, 'JSXSelfClosingElement "/>"')), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6) {
10637
+ return { type: "JSXElement", children: $0 };
10638
+ });
10608
10639
  function JSXSelfClosingElement(state) {
10609
10640
  if (state.events) {
10610
10641
  const result = state.events.enter?.("JSXSelfClosingElement", state);
@@ -10661,9 +10692,41 @@ ${input.slice(result.pos)}
10661
10692
  return result;
10662
10693
  }
10663
10694
  }
10664
- var JSXFragment$0 = $S($EXPECT($L149, fail, 'JSXFragment "<>"'), $E(JSXChildren), $EXPECT($L150, fail, 'JSXFragment "</>"'));
10695
+ var TypedJSXFragment$0 = $TS($S(JSXFragment), function($skip, $loc, $0, $1) {
10696
+ const type = module.typeOfJSXFragment($1);
10697
+ return type ? [
10698
+ { ts: true, children: ["("] },
10699
+ $1,
10700
+ { ts: true, children: [" as any as ", type, ")"] }
10701
+ ] : $1;
10702
+ });
10703
+ function TypedJSXFragment(state) {
10704
+ if (state.events) {
10705
+ const result = state.events.enter?.("TypedJSXFragment", state);
10706
+ if (result)
10707
+ return result.cache;
10708
+ }
10709
+ if (state.tokenize) {
10710
+ const result = $TOKEN("TypedJSXFragment", state, TypedJSXFragment$0(state));
10711
+ if (state.events)
10712
+ state.events.exit?.("TypedJSXFragment", state, result);
10713
+ return result;
10714
+ } else {
10715
+ const result = TypedJSXFragment$0(state);
10716
+ if (state.events)
10717
+ state.events.exit?.("TypedJSXFragment", state, result);
10718
+ return result;
10719
+ }
10720
+ }
10721
+ var JSXFragment$0 = $TS($S($EXPECT($L149, fail, 'JSXFragment "<>"'), $E(JSXChildren), __, $EXPECT($L150, fail, 'JSXFragment "</>"')), function($skip, $loc, $0, $1, $2, $3, $4) {
10722
+ if ($2) {
10723
+ return { type: "JSXFragment", children: $0, jsxChildren: $2.jsxChildren };
10724
+ } else {
10725
+ return { type: "JSXFragment", children: $0, jsxChildren: [] };
10726
+ }
10727
+ });
10665
10728
  var JSXFragment$1 = $TS($S($EXPECT($L149, fail, 'JSXFragment "<>"'), JSXMixedChildren, InsertNewline, InsertIndent), function($skip, $loc, $0, $1, $2, $3, $4) {
10666
- return [...$0, "</>"];
10729
+ return { type: "JSXFragment", children: [...$0, "</>"], jsxChildren: $2.jsxChildren };
10667
10730
  });
10668
10731
  function JSXFragment(state) {
10669
10732
  if (state.events) {
@@ -11141,10 +11204,13 @@ ${input.slice(result.pos)}
11141
11204
  return result;
11142
11205
  }
11143
11206
  }
11144
- var JSXMixedChildren$0 = $TS($S($Q($C(_, JSXChild)), JSXNestedChildren), function($skip, $loc, $0, $1, $2) {
11207
+ var JSXMixedChildren$0 = $TS($S($Q(JSXChild), JSXNestedChildren), function($skip, $loc, $0, $1, $2) {
11145
11208
  var c1 = $1;
11146
11209
  var c2 = $2;
11147
- return c1.concat(c2);
11210
+ return {
11211
+ children: c1.concat(c2),
11212
+ jsxChildren: c1.concat(c2.jsxChildren)
11213
+ };
11148
11214
  });
11149
11215
  function JSXMixedChildren(state) {
11150
11216
  if (state.events) {
@@ -11164,7 +11230,12 @@ ${input.slice(result.pos)}
11164
11230
  return result;
11165
11231
  }
11166
11232
  }
11167
- var JSXChildren$0 = $Q($S(__, JSXChild));
11233
+ var JSXChildren$0 = $TV($Q($S($Q($S($E(NonNewlineWhitespace), EOL, $E(NonNewlineWhitespace))), JSXChild)), function($skip, $loc, $0, $1) {
11234
+ return {
11235
+ children: $1,
11236
+ jsxChildren: $1.map((children) => children[1])
11237
+ };
11238
+ });
11168
11239
  function JSXChildren(state) {
11169
11240
  if (state.events) {
11170
11241
  const result = state.events.enter?.("JSXChildren", state);
@@ -11184,12 +11255,16 @@ ${input.slice(result.pos)}
11184
11255
  }
11185
11256
  }
11186
11257
  var JSXNestedChildren$0 = $TS($S(PushIndent, $Q($S(Nested, $P(JSXChild))), PopIndent), function($skip, $loc, $0, $1, $2, $3) {
11187
- if ($2.length)
11188
- return $2;
11258
+ if ($2.length) {
11259
+ return {
11260
+ children: $2,
11261
+ jsxChildren: [].concat(...$2.map((nestedChildren) => nestedChildren[1]))
11262
+ };
11263
+ }
11189
11264
  return $skip;
11190
11265
  });
11191
11266
  var JSXNestedChildren$1 = $TV($Y(EOS), function($skip, $loc, $0, $1) {
11192
- return [];
11267
+ return { children: [], jsxChildren: [] };
11193
11268
  });
11194
11269
  function JSXNestedChildren(state) {
11195
11270
  if (state.events) {
@@ -11212,7 +11287,14 @@ ${input.slice(result.pos)}
11212
11287
  var JSXChild$0 = JSXText;
11213
11288
  var JSXChild$1 = JSXElement;
11214
11289
  var JSXChild$2 = JSXFragment;
11215
- var JSXChild$3 = $S(OpenBrace, $E(JSXChildExpression), __, CloseBrace);
11290
+ var JSXChild$3 = $TS($S(OpenBrace, $E(JSXChildExpression), __, CloseBrace), function($skip, $loc, $0, $1, $2, $3, $4) {
11291
+ var expression = $2;
11292
+ return {
11293
+ type: "JSXChildExpression",
11294
+ children: $0,
11295
+ expression
11296
+ };
11297
+ });
11216
11298
  function JSXChild(state) {
11217
11299
  if (state.events) {
11218
11300
  const result = state.events.enter?.("JSXChild", state);
@@ -11231,7 +11313,13 @@ ${input.slice(result.pos)}
11231
11313
  return result;
11232
11314
  }
11233
11315
  }
11234
- var JSXText$0 = $R$0($EXPECT($R46, fail, "JSXText /[^{}<>\\r\\n]+/"));
11316
+ var JSXText$0 = $TR($EXPECT($R46, fail, "JSXText /[^{}<>\\r\\n]+/"), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7, $8, $9) {
11317
+ return {
11318
+ type: "JSXText",
11319
+ token: $0,
11320
+ $loc
11321
+ };
11322
+ });
11235
11323
  function JSXText(state) {
11236
11324
  if (state.events) {
11237
11325
  const result = state.events.enter?.("JSXText", state);
@@ -11993,7 +12081,7 @@ ${input.slice(result.pos)}
11993
12081
  return result;
11994
12082
  }
11995
12083
  }
11996
- var TypeArguments$0 = $TS($S(__, $EXPECT($L5, fail, 'TypeArguments "<"'), __, Type, $Q($S(__, Comma, __, Type)), $E($S(__, Comma)), __, $EXPECT($L27, fail, 'TypeArguments ">"')), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7, $8) {
12084
+ var TypeArguments$0 = $TS($S(__, $EXPECT($L5, fail, 'TypeArguments "<"'), $P(TypeArgument), __, $EXPECT($L27, fail, 'TypeArguments ">"')), function($skip, $loc, $0, $1, $2, $3, $4, $5) {
11997
12085
  return { ts: true, children: $0 };
11998
12086
  });
11999
12087
  function TypeArguments(state) {
@@ -12014,7 +12102,7 @@ ${input.slice(result.pos)}
12014
12102
  return result;
12015
12103
  }
12016
12104
  }
12017
- var CompactTypeArguments$0 = $TS($S($EXPECT($L5, fail, 'CompactTypeArguments "<"'), __, Type, $Q($S(__, Comma, __, Type)), $E($S(__, Comma)), __, $EXPECT($L27, fail, 'CompactTypeArguments ">"')), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7) {
12105
+ var CompactTypeArguments$0 = $TS($S($EXPECT($L5, fail, 'CompactTypeArguments "<"'), $P(TypeArgument), __, $EXPECT($L27, fail, 'CompactTypeArguments ">"')), function($skip, $loc, $0, $1, $2, $3, $4) {
12018
12106
  return { ts: true, children: $0 };
12019
12107
  });
12020
12108
  function CompactTypeArguments(state) {
@@ -12035,6 +12123,44 @@ ${input.slice(result.pos)}
12035
12123
  return result;
12036
12124
  }
12037
12125
  }
12126
+ var TypeArgument$0 = $S(__, Type, TypeArgumentDelimiter);
12127
+ function TypeArgument(state) {
12128
+ if (state.events) {
12129
+ const result = state.events.enter?.("TypeArgument", state);
12130
+ if (result)
12131
+ return result.cache;
12132
+ }
12133
+ if (state.tokenize) {
12134
+ const result = $TOKEN("TypeArgument", state, TypeArgument$0(state));
12135
+ if (state.events)
12136
+ state.events.exit?.("TypeArgument", state, result);
12137
+ return result;
12138
+ } else {
12139
+ const result = TypeArgument$0(state);
12140
+ if (state.events)
12141
+ state.events.exit?.("TypeArgument", state, result);
12142
+ return result;
12143
+ }
12144
+ }
12145
+ var TypeArgumentDelimiter$0 = TypeParameterDelimiter;
12146
+ function TypeArgumentDelimiter(state) {
12147
+ if (state.events) {
12148
+ const result = state.events.enter?.("TypeArgumentDelimiter", state);
12149
+ if (result)
12150
+ return result.cache;
12151
+ }
12152
+ if (state.tokenize) {
12153
+ const result = $TOKEN("TypeArgumentDelimiter", state, TypeArgumentDelimiter$0(state));
12154
+ if (state.events)
12155
+ state.events.exit?.("TypeArgumentDelimiter", state, result);
12156
+ return result;
12157
+ } else {
12158
+ const result = TypeArgumentDelimiter$0(state);
12159
+ if (state.events)
12160
+ state.events.exit?.("TypeArgumentDelimiter", state, result);
12161
+ return result;
12162
+ }
12163
+ }
12038
12164
  var TypeParameters$0 = $TS($S(__, $EXPECT($L5, fail, 'TypeParameters "<"'), $P(TypeParameter), __, $EXPECT($L27, fail, 'TypeParameters ">"')), function($skip, $loc, $0, $1, $2, $3, $4, $5) {
12039
12165
  var parameters = $3;
12040
12166
  return {
@@ -12925,6 +13051,9 @@ ${input.slice(result.pos)}
12925
13051
  coffeeNot: false,
12926
13052
  coffeeOf: false,
12927
13053
  implicitReturns: true,
13054
+ solid: false,
13055
+ client: false,
13056
+ server: false,
12928
13057
  tab: void 0,
12929
13058
  verbose: false
12930
13059
  };
@@ -12947,6 +13076,34 @@ ${input.slice(result.pos)}
12947
13076
  children: [": <T>(this: T, prop: keyof T) => boolean"]
12948
13077
  };
12949
13078
  module.prelude.push(["", ["const ", hasPropRef, typeSuffix, " = {}.hasOwnProperty", module.asAny, "\n"]]);
13079
+ },
13080
+ JSX(jsxRef) {
13081
+ module.prelude.push({
13082
+ ts: true,
13083
+ children: [
13084
+ "import type { JSX as ",
13085
+ jsxRef,
13086
+ " } from 'solid-js';\n"
13087
+ ]
13088
+ });
13089
+ },
13090
+ IntrinsicElements(intrinsicElementsRef) {
13091
+ const JSX = module.getRef("JSX");
13092
+ module.prelude.push({
13093
+ ts: true,
13094
+ children: [
13095
+ "type ",
13096
+ intrinsicElementsRef,
13097
+ "<K extends keyof ",
13098
+ JSX,
13099
+ ".IntrinsicElements> =\n",
13100
+ " ",
13101
+ JSX,
13102
+ ".IntrinsicElements[K] extends ",
13103
+ JSX,
13104
+ ".DOMAttributes<infer T> ? T : unknown;\n"
13105
+ ]
13106
+ });
12950
13107
  }
12951
13108
  };
12952
13109
  const refs = {};
@@ -12964,11 +13121,55 @@ ${input.slice(result.pos)}
12964
13121
  };
12965
13122
  module.typeOfJSXElement = function($12) {
12966
13123
  if (module.config.solid) {
12967
- let open = $12;
13124
+ if (module.config.server && !module.config.client) {
13125
+ return ["string"];
13126
+ }
13127
+ let open = $12.children;
12968
13128
  while (Array.isArray(open[0]))
12969
13129
  open = open[0];
12970
13130
  open = open[1];
12971
- return typeof open === "string" && open[0] === open[0].toLowerCase() ? [module.getRef("IntrinsicElements"), '<"', open, '">'] : ["ReturnType<typeof ", open, ">"];
13131
+ const clientType = typeof open === "string" && open[0] === open[0].toLowerCase() ? [module.getRef("IntrinsicElements"), '<"', open, '">'] : ["ReturnType<typeof ", open, ">"];
13132
+ if (module.config.server) {
13133
+ return ["string", " | ", clientType];
13134
+ } else {
13135
+ return clientType;
13136
+ }
13137
+ }
13138
+ };
13139
+ module.typeOfJSXFragment = function($12) {
13140
+ if (module.config.solid) {
13141
+ let type = [];
13142
+ let lastType;
13143
+ for (let child of $12.jsxChildren) {
13144
+ switch (child.type) {
13145
+ case "JSXText":
13146
+ if (lastType !== "JSXText") {
13147
+ type.push("string");
13148
+ }
13149
+ break;
13150
+ case "JSXElement":
13151
+ type.push(module.typeOfJSXElement(child));
13152
+ break;
13153
+ case "JSXFragment":
13154
+ type.push(...module.typeOfJSXFragment(child));
13155
+ break;
13156
+ case "JSXChildExpression":
13157
+ if (child.expression) {
13158
+ type.push(["typeof ", child.expression]);
13159
+ }
13160
+ break;
13161
+ default:
13162
+ throw new Error(`unknown child in JSXFragment: ${JSON.stringify(child)}`);
13163
+ }
13164
+ lastType = child.type;
13165
+ }
13166
+ if (type.length === 1) {
13167
+ return type[0];
13168
+ } else {
13169
+ type = type.map((t) => [t, ", "]).flat();
13170
+ type.pop();
13171
+ return ["[", type, "]"];
13172
+ }
12972
13173
  }
12973
13174
  };
12974
13175
  Object.defineProperty(module.config, "coffeeCompat", {
@@ -14573,9 +14774,11 @@ ${"//#"} sourceMappingURL=data:application/json;base64,${base64Encode(JSON.strin
14573
14774
  case "SingleLineComment":
14574
14775
  case "Debugger":
14575
14776
  case "JSXElement":
14777
+ case "TypedJSXElement":
14778
+ case "JSXFragment":
14779
+ case "TypedJSXFragment":
14576
14780
  case "JSXChild":
14577
14781
  case "JSXChildren":
14578
- case "JSXFragment":
14579
14782
  case "JSXNestedChildren":
14580
14783
  case "JSXMixedChildren":
14581
14784
  break;
package/dist/main.js CHANGED
@@ -832,10 +832,12 @@ ${input.slice(result.pos)}
832
832
  When,
833
833
  While,
834
834
  Yield,
835
+ TypedJSXElement,
835
836
  JSXElement,
836
837
  JSXSelfClosingElement,
837
838
  JSXOpeningElement,
838
839
  JSXClosingElement,
840
+ TypedJSXFragment,
839
841
  JSXFragment,
840
842
  JSXElementName,
841
843
  JSXIdentifierName,
@@ -897,6 +899,8 @@ ${input.slice(result.pos)}
897
899
  FunctionType,
898
900
  TypeArguments,
899
901
  CompactTypeArguments,
902
+ TypeArgument,
903
+ TypeArgumentDelimiter,
900
904
  TypeParameters,
901
905
  TypeParameter,
902
906
  TypeConstraint,
@@ -2000,8 +2004,8 @@ ${input.slice(result.pos)}
2000
2004
  var PrimaryExpression$7 = RegularExpressionLiteral;
2001
2005
  var PrimaryExpression$8 = TemplateLiteral;
2002
2006
  var PrimaryExpression$9 = ParenthesizedExpression;
2003
- var PrimaryExpression$10 = JSXElement;
2004
- var PrimaryExpression$11 = JSXFragment;
2007
+ var PrimaryExpression$10 = TypedJSXElement;
2008
+ var PrimaryExpression$11 = TypedJSXFragment;
2005
2009
  function PrimaryExpression(state) {
2006
2010
  if (state.events) {
2007
2011
  const result = state.events.enter?.("PrimaryExpression", state);
@@ -10567,20 +10571,45 @@ ${input.slice(result.pos)}
10567
10571
  return result;
10568
10572
  }
10569
10573
  }
10574
+ var TypedJSXElement$0 = $TS($S(JSXElement), function($skip, $loc, $0, $1) {
10575
+ const type = module2.typeOfJSXElement($1);
10576
+ return type ? [
10577
+ { ts: true, children: ["("] },
10578
+ $1,
10579
+ { ts: true, children: [" as any as ", type, ")"] }
10580
+ ] : $1;
10581
+ });
10582
+ function TypedJSXElement(state) {
10583
+ if (state.events) {
10584
+ const result = state.events.enter?.("TypedJSXElement", state);
10585
+ if (result)
10586
+ return result.cache;
10587
+ }
10588
+ if (state.tokenize) {
10589
+ const result = $TOKEN("TypedJSXElement", state, TypedJSXElement$0(state));
10590
+ if (state.events)
10591
+ state.events.exit?.("TypedJSXElement", state, result);
10592
+ return result;
10593
+ } else {
10594
+ const result = TypedJSXElement$0(state);
10595
+ if (state.events)
10596
+ state.events.exit?.("TypedJSXElement", state, result);
10597
+ return result;
10598
+ }
10599
+ }
10570
10600
  var JSXElement$0 = JSXSelfClosingElement;
10571
10601
  var JSXElement$1 = $TS($S(JSXOpeningElement, $E(JSXChildren), __, JSXClosingElement), function($skip, $loc, $0, $1, $2, $3, $4) {
10572
10602
  if ($1[1] !== $4[2])
10573
10603
  return $skip;
10574
- return $0;
10604
+ return { type: "JSXElement", children: $0 };
10575
10605
  });
10576
10606
  var JSXElement$2 = $TS($S(JSXOpeningElement, JSXMixedChildren, InsertNewline, InsertIndent), function($skip, $loc, $0, $1, $2, $3, $4) {
10577
10607
  var open = $1;
10578
10608
  var children = $2;
10579
- if (children.length) {
10580
- return [...$0, ["</", open[1], ">"]];
10581
- } else {
10582
- return [open.slice(0, -1), " />"];
10583
- }
10609
+ return {
10610
+ type: "JSXElement",
10611
+ children: children.jsxChildren.length ? [...$0, ["</", open[1], ">"]] : [open.slice(0, -1), " />"]
10612
+ };
10584
10613
  });
10585
10614
  var JSXElement$3 = $TS($S(JSXOpeningElement), function($skip, $loc, $0, $1) {
10586
10615
  throw new Error(`could not parse JSX element "${require_generate()($0)}" at pos ${$loc.pos}`);
@@ -10603,7 +10632,9 @@ ${input.slice(result.pos)}
10603
10632
  return result;
10604
10633
  }
10605
10634
  }
10606
- var JSXSelfClosingElement$0 = $S($EXPECT($L5, fail, 'JSXSelfClosingElement "<"'), $TEXT(JSXElementName), $E(CompactTypeArguments), $E(JSXAttributes), __, $EXPECT($L147, fail, 'JSXSelfClosingElement "/>"'));
10635
+ var JSXSelfClosingElement$0 = $TS($S($EXPECT($L5, fail, 'JSXSelfClosingElement "<"'), $TEXT(JSXElementName), $E(CompactTypeArguments), $E(JSXAttributes), __, $EXPECT($L147, fail, 'JSXSelfClosingElement "/>"')), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6) {
10636
+ return { type: "JSXElement", children: $0 };
10637
+ });
10607
10638
  function JSXSelfClosingElement(state) {
10608
10639
  if (state.events) {
10609
10640
  const result = state.events.enter?.("JSXSelfClosingElement", state);
@@ -10660,9 +10691,41 @@ ${input.slice(result.pos)}
10660
10691
  return result;
10661
10692
  }
10662
10693
  }
10663
- var JSXFragment$0 = $S($EXPECT($L149, fail, 'JSXFragment "<>"'), $E(JSXChildren), $EXPECT($L150, fail, 'JSXFragment "</>"'));
10694
+ var TypedJSXFragment$0 = $TS($S(JSXFragment), function($skip, $loc, $0, $1) {
10695
+ const type = module2.typeOfJSXFragment($1);
10696
+ return type ? [
10697
+ { ts: true, children: ["("] },
10698
+ $1,
10699
+ { ts: true, children: [" as any as ", type, ")"] }
10700
+ ] : $1;
10701
+ });
10702
+ function TypedJSXFragment(state) {
10703
+ if (state.events) {
10704
+ const result = state.events.enter?.("TypedJSXFragment", state);
10705
+ if (result)
10706
+ return result.cache;
10707
+ }
10708
+ if (state.tokenize) {
10709
+ const result = $TOKEN("TypedJSXFragment", state, TypedJSXFragment$0(state));
10710
+ if (state.events)
10711
+ state.events.exit?.("TypedJSXFragment", state, result);
10712
+ return result;
10713
+ } else {
10714
+ const result = TypedJSXFragment$0(state);
10715
+ if (state.events)
10716
+ state.events.exit?.("TypedJSXFragment", state, result);
10717
+ return result;
10718
+ }
10719
+ }
10720
+ var JSXFragment$0 = $TS($S($EXPECT($L149, fail, 'JSXFragment "<>"'), $E(JSXChildren), __, $EXPECT($L150, fail, 'JSXFragment "</>"')), function($skip, $loc, $0, $1, $2, $3, $4) {
10721
+ if ($2) {
10722
+ return { type: "JSXFragment", children: $0, jsxChildren: $2.jsxChildren };
10723
+ } else {
10724
+ return { type: "JSXFragment", children: $0, jsxChildren: [] };
10725
+ }
10726
+ });
10664
10727
  var JSXFragment$1 = $TS($S($EXPECT($L149, fail, 'JSXFragment "<>"'), JSXMixedChildren, InsertNewline, InsertIndent), function($skip, $loc, $0, $1, $2, $3, $4) {
10665
- return [...$0, "</>"];
10728
+ return { type: "JSXFragment", children: [...$0, "</>"], jsxChildren: $2.jsxChildren };
10666
10729
  });
10667
10730
  function JSXFragment(state) {
10668
10731
  if (state.events) {
@@ -11140,10 +11203,13 @@ ${input.slice(result.pos)}
11140
11203
  return result;
11141
11204
  }
11142
11205
  }
11143
- var JSXMixedChildren$0 = $TS($S($Q($C(_, JSXChild)), JSXNestedChildren), function($skip, $loc, $0, $1, $2) {
11206
+ var JSXMixedChildren$0 = $TS($S($Q(JSXChild), JSXNestedChildren), function($skip, $loc, $0, $1, $2) {
11144
11207
  var c1 = $1;
11145
11208
  var c2 = $2;
11146
- return c1.concat(c2);
11209
+ return {
11210
+ children: c1.concat(c2),
11211
+ jsxChildren: c1.concat(c2.jsxChildren)
11212
+ };
11147
11213
  });
11148
11214
  function JSXMixedChildren(state) {
11149
11215
  if (state.events) {
@@ -11163,7 +11229,12 @@ ${input.slice(result.pos)}
11163
11229
  return result;
11164
11230
  }
11165
11231
  }
11166
- var JSXChildren$0 = $Q($S(__, JSXChild));
11232
+ var JSXChildren$0 = $TV($Q($S($Q($S($E(NonNewlineWhitespace), EOL, $E(NonNewlineWhitespace))), JSXChild)), function($skip, $loc, $0, $1) {
11233
+ return {
11234
+ children: $1,
11235
+ jsxChildren: $1.map((children) => children[1])
11236
+ };
11237
+ });
11167
11238
  function JSXChildren(state) {
11168
11239
  if (state.events) {
11169
11240
  const result = state.events.enter?.("JSXChildren", state);
@@ -11183,12 +11254,16 @@ ${input.slice(result.pos)}
11183
11254
  }
11184
11255
  }
11185
11256
  var JSXNestedChildren$0 = $TS($S(PushIndent, $Q($S(Nested, $P(JSXChild))), PopIndent), function($skip, $loc, $0, $1, $2, $3) {
11186
- if ($2.length)
11187
- return $2;
11257
+ if ($2.length) {
11258
+ return {
11259
+ children: $2,
11260
+ jsxChildren: [].concat(...$2.map((nestedChildren) => nestedChildren[1]))
11261
+ };
11262
+ }
11188
11263
  return $skip;
11189
11264
  });
11190
11265
  var JSXNestedChildren$1 = $TV($Y(EOS), function($skip, $loc, $0, $1) {
11191
- return [];
11266
+ return { children: [], jsxChildren: [] };
11192
11267
  });
11193
11268
  function JSXNestedChildren(state) {
11194
11269
  if (state.events) {
@@ -11211,7 +11286,14 @@ ${input.slice(result.pos)}
11211
11286
  var JSXChild$0 = JSXText;
11212
11287
  var JSXChild$1 = JSXElement;
11213
11288
  var JSXChild$2 = JSXFragment;
11214
- var JSXChild$3 = $S(OpenBrace, $E(JSXChildExpression), __, CloseBrace);
11289
+ var JSXChild$3 = $TS($S(OpenBrace, $E(JSXChildExpression), __, CloseBrace), function($skip, $loc, $0, $1, $2, $3, $4) {
11290
+ var expression = $2;
11291
+ return {
11292
+ type: "JSXChildExpression",
11293
+ children: $0,
11294
+ expression
11295
+ };
11296
+ });
11215
11297
  function JSXChild(state) {
11216
11298
  if (state.events) {
11217
11299
  const result = state.events.enter?.("JSXChild", state);
@@ -11230,7 +11312,13 @@ ${input.slice(result.pos)}
11230
11312
  return result;
11231
11313
  }
11232
11314
  }
11233
- var JSXText$0 = $R$0($EXPECT($R46, fail, "JSXText /[^{}<>\\r\\n]+/"));
11315
+ var JSXText$0 = $TR($EXPECT($R46, fail, "JSXText /[^{}<>\\r\\n]+/"), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7, $8, $9) {
11316
+ return {
11317
+ type: "JSXText",
11318
+ token: $0,
11319
+ $loc
11320
+ };
11321
+ });
11234
11322
  function JSXText(state) {
11235
11323
  if (state.events) {
11236
11324
  const result = state.events.enter?.("JSXText", state);
@@ -11992,7 +12080,7 @@ ${input.slice(result.pos)}
11992
12080
  return result;
11993
12081
  }
11994
12082
  }
11995
- var TypeArguments$0 = $TS($S(__, $EXPECT($L5, fail, 'TypeArguments "<"'), __, Type, $Q($S(__, Comma, __, Type)), $E($S(__, Comma)), __, $EXPECT($L27, fail, 'TypeArguments ">"')), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7, $8) {
12083
+ var TypeArguments$0 = $TS($S(__, $EXPECT($L5, fail, 'TypeArguments "<"'), $P(TypeArgument), __, $EXPECT($L27, fail, 'TypeArguments ">"')), function($skip, $loc, $0, $1, $2, $3, $4, $5) {
11996
12084
  return { ts: true, children: $0 };
11997
12085
  });
11998
12086
  function TypeArguments(state) {
@@ -12013,7 +12101,7 @@ ${input.slice(result.pos)}
12013
12101
  return result;
12014
12102
  }
12015
12103
  }
12016
- var CompactTypeArguments$0 = $TS($S($EXPECT($L5, fail, 'CompactTypeArguments "<"'), __, Type, $Q($S(__, Comma, __, Type)), $E($S(__, Comma)), __, $EXPECT($L27, fail, 'CompactTypeArguments ">"')), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7) {
12104
+ var CompactTypeArguments$0 = $TS($S($EXPECT($L5, fail, 'CompactTypeArguments "<"'), $P(TypeArgument), __, $EXPECT($L27, fail, 'CompactTypeArguments ">"')), function($skip, $loc, $0, $1, $2, $3, $4) {
12017
12105
  return { ts: true, children: $0 };
12018
12106
  });
12019
12107
  function CompactTypeArguments(state) {
@@ -12034,6 +12122,44 @@ ${input.slice(result.pos)}
12034
12122
  return result;
12035
12123
  }
12036
12124
  }
12125
+ var TypeArgument$0 = $S(__, Type, TypeArgumentDelimiter);
12126
+ function TypeArgument(state) {
12127
+ if (state.events) {
12128
+ const result = state.events.enter?.("TypeArgument", state);
12129
+ if (result)
12130
+ return result.cache;
12131
+ }
12132
+ if (state.tokenize) {
12133
+ const result = $TOKEN("TypeArgument", state, TypeArgument$0(state));
12134
+ if (state.events)
12135
+ state.events.exit?.("TypeArgument", state, result);
12136
+ return result;
12137
+ } else {
12138
+ const result = TypeArgument$0(state);
12139
+ if (state.events)
12140
+ state.events.exit?.("TypeArgument", state, result);
12141
+ return result;
12142
+ }
12143
+ }
12144
+ var TypeArgumentDelimiter$0 = TypeParameterDelimiter;
12145
+ function TypeArgumentDelimiter(state) {
12146
+ if (state.events) {
12147
+ const result = state.events.enter?.("TypeArgumentDelimiter", state);
12148
+ if (result)
12149
+ return result.cache;
12150
+ }
12151
+ if (state.tokenize) {
12152
+ const result = $TOKEN("TypeArgumentDelimiter", state, TypeArgumentDelimiter$0(state));
12153
+ if (state.events)
12154
+ state.events.exit?.("TypeArgumentDelimiter", state, result);
12155
+ return result;
12156
+ } else {
12157
+ const result = TypeArgumentDelimiter$0(state);
12158
+ if (state.events)
12159
+ state.events.exit?.("TypeArgumentDelimiter", state, result);
12160
+ return result;
12161
+ }
12162
+ }
12037
12163
  var TypeParameters$0 = $TS($S(__, $EXPECT($L5, fail, 'TypeParameters "<"'), $P(TypeParameter), __, $EXPECT($L27, fail, 'TypeParameters ">"')), function($skip, $loc, $0, $1, $2, $3, $4, $5) {
12038
12164
  var parameters = $3;
12039
12165
  return {
@@ -12924,6 +13050,9 @@ ${input.slice(result.pos)}
12924
13050
  coffeeNot: false,
12925
13051
  coffeeOf: false,
12926
13052
  implicitReturns: true,
13053
+ solid: false,
13054
+ client: false,
13055
+ server: false,
12927
13056
  tab: void 0,
12928
13057
  verbose: false
12929
13058
  };
@@ -12946,6 +13075,34 @@ ${input.slice(result.pos)}
12946
13075
  children: [": <T>(this: T, prop: keyof T) => boolean"]
12947
13076
  };
12948
13077
  module2.prelude.push(["", ["const ", hasPropRef, typeSuffix, " = {}.hasOwnProperty", module2.asAny, "\n"]]);
13078
+ },
13079
+ JSX(jsxRef) {
13080
+ module2.prelude.push({
13081
+ ts: true,
13082
+ children: [
13083
+ "import type { JSX as ",
13084
+ jsxRef,
13085
+ " } from 'solid-js';\n"
13086
+ ]
13087
+ });
13088
+ },
13089
+ IntrinsicElements(intrinsicElementsRef) {
13090
+ const JSX = module2.getRef("JSX");
13091
+ module2.prelude.push({
13092
+ ts: true,
13093
+ children: [
13094
+ "type ",
13095
+ intrinsicElementsRef,
13096
+ "<K extends keyof ",
13097
+ JSX,
13098
+ ".IntrinsicElements> =\n",
13099
+ " ",
13100
+ JSX,
13101
+ ".IntrinsicElements[K] extends ",
13102
+ JSX,
13103
+ ".DOMAttributes<infer T> ? T : unknown;\n"
13104
+ ]
13105
+ });
12949
13106
  }
12950
13107
  };
12951
13108
  const refs = {};
@@ -12963,11 +13120,55 @@ ${input.slice(result.pos)}
12963
13120
  };
12964
13121
  module2.typeOfJSXElement = function($12) {
12965
13122
  if (module2.config.solid) {
12966
- let open = $12;
13123
+ if (module2.config.server && !module2.config.client) {
13124
+ return ["string"];
13125
+ }
13126
+ let open = $12.children;
12967
13127
  while (Array.isArray(open[0]))
12968
13128
  open = open[0];
12969
13129
  open = open[1];
12970
- return typeof open === "string" && open[0] === open[0].toLowerCase() ? [module2.getRef("IntrinsicElements"), '<"', open, '">'] : ["ReturnType<typeof ", open, ">"];
13130
+ const clientType = typeof open === "string" && open[0] === open[0].toLowerCase() ? [module2.getRef("IntrinsicElements"), '<"', open, '">'] : ["ReturnType<typeof ", open, ">"];
13131
+ if (module2.config.server) {
13132
+ return ["string", " | ", clientType];
13133
+ } else {
13134
+ return clientType;
13135
+ }
13136
+ }
13137
+ };
13138
+ module2.typeOfJSXFragment = function($12) {
13139
+ if (module2.config.solid) {
13140
+ let type = [];
13141
+ let lastType;
13142
+ for (let child of $12.jsxChildren) {
13143
+ switch (child.type) {
13144
+ case "JSXText":
13145
+ if (lastType !== "JSXText") {
13146
+ type.push("string");
13147
+ }
13148
+ break;
13149
+ case "JSXElement":
13150
+ type.push(module2.typeOfJSXElement(child));
13151
+ break;
13152
+ case "JSXFragment":
13153
+ type.push(...module2.typeOfJSXFragment(child));
13154
+ break;
13155
+ case "JSXChildExpression":
13156
+ if (child.expression) {
13157
+ type.push(["typeof ", child.expression]);
13158
+ }
13159
+ break;
13160
+ default:
13161
+ throw new Error(`unknown child in JSXFragment: ${JSON.stringify(child)}`);
13162
+ }
13163
+ lastType = child.type;
13164
+ }
13165
+ if (type.length === 1) {
13166
+ return type[0];
13167
+ } else {
13168
+ type = type.map((t) => [t, ", "]).flat();
13169
+ type.pop();
13170
+ return ["[", type, "]"];
13171
+ }
12971
13172
  }
12972
13173
  };
12973
13174
  Object.defineProperty(module2.config, "coffeeCompat", {
@@ -14570,9 +14771,11 @@ makeCache = function() {
14570
14771
  case "SingleLineComment":
14571
14772
  case "Debugger":
14572
14773
  case "JSXElement":
14774
+ case "TypedJSXElement":
14775
+ case "JSXFragment":
14776
+ case "TypedJSXFragment":
14573
14777
  case "JSXChild":
14574
14778
  case "JSXChildren":
14575
- case "JSXFragment":
14576
14779
  case "JSXNestedChildren":
14577
14780
  case "JSXMixedChildren":
14578
14781
  break;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@danielx/civet",
3
- "version": "0.5.3",
3
+ "version": "0.5.5",
4
4
  "description": "CoffeeScript style syntax for TypeScript",
5
5
  "main": "dist/main.js",
6
6
  "exports": {
@@ -75,4 +75,4 @@
75
75
  "test"
76
76
  ]
77
77
  }
78
- }
78
+ }