@danielx/civet 0.5.4 → 0.5.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -11,6 +11,11 @@ The CoffeeScript of TypeScript. Much closer to ES2015+ (for better or worse).
11
11
  - [Online Civet Playground](https://civet-web.vercel.app/)
12
12
  - [Civet VSCode Extension](https://marketplace.visualstudio.com/items?itemName=DanielX.civet)
13
13
  - [Discord Server](https://discord.gg/xkrW9GebBc)
14
+ - Plugins for
15
+ [Vite](https://github.com/lorefnon/vite-plugin-civet),
16
+ [esbuild](source/esbuild-plugin.civet),
17
+ [ESM module resolution](source/esm.civet)
18
+ - Starter templates for [Solid](https://github.com/orenelbaum/solid-civet-template) and [Solid Start](https://github.com/orenelbaum/solid-start-civet-template)
14
19
 
15
20
  Quickstart Guide
16
21
  ---
@@ -217,6 +222,11 @@ Things Added that CoffeeScript didn't
217
222
  `sum=x+1` → `sum={x+1}`, `list=[1, 2, 3]` → `list={[1, 2, 3]}`
218
223
  - Attributes can use computed property names:
219
224
  `[expr]={value}` → `{...{[expr]: value}}`
225
+ - `"civet solid"` flag adds correct types for JSX elements and fragments.
226
+ Use `"civet solid client"` (default) for client-only code,
227
+ `"civet solid server"` for server-only code (SSR only), or
228
+ `"civet solid client server"` for isomorphic code that runs on
229
+ client and server (SSR + hydration).
220
230
  - CoffeeScript improvements
221
231
  - Postfix loop `run() loop` → `while(true) run()`
222
232
  - Character range literals `["a".."z"]`, `['f'..'a']`, `['0'..'9']`
@@ -235,7 +245,7 @@ Things Changed from ES6
235
245
  behave more differently than they already do is bad. Passing an anonymous function to an
236
246
  application without parens is also convenient.
237
247
  - `for(i of x) ...` defaults to const declaration → `for(const i of x) ...`
238
- - Disallow comma operator in conditionals and many other places. `if x, y` is not allowed.
248
+ - Disallow comma operator in conditionals and many other places. `if x, y` is not allowed. But `for i = 0, l = a.length; i < l; i++, i *= 2` is allowed.
239
249
  - Comma operator in `case`/`when` instead becomes multiple conditions.
240
250
  - Numbers can't end with a dot (otherwise would be ambiguous with CoffeeScript slices `y[0..x]`). This also implies that you can't access properties
241
251
  of numbers with `1..toString()` use `1.toString()` instead. When exponent follows a dot it is treated as a property access since an exponent
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,
@@ -2003,8 +2005,8 @@ ${input.slice(result.pos)}
2003
2005
  var PrimaryExpression$7 = RegularExpressionLiteral;
2004
2006
  var PrimaryExpression$8 = TemplateLiteral;
2005
2007
  var PrimaryExpression$9 = ParenthesizedExpression;
2006
- var PrimaryExpression$10 = JSXElement;
2007
- var PrimaryExpression$11 = JSXFragment;
2008
+ var PrimaryExpression$10 = TypedJSXElement;
2009
+ var PrimaryExpression$11 = TypedJSXFragment;
2008
2010
  function PrimaryExpression(state) {
2009
2011
  if (state.events) {
2010
2012
  const result = state.events.enter?.("PrimaryExpression", state);
@@ -2720,6 +2722,7 @@ ${input.slice(result.pos)}
2720
2722
  }
2721
2723
  }
2722
2724
  var SuperProperty$0 = $S($EXPECT($L13, fail, 'SuperProperty "super["'), ExtendedExpression, __, CloseBracket);
2725
+ var SuperProperty$1 = $S($EXPECT($L10, fail, 'SuperProperty "super"'), $N($C(QuestionMark, NonNullAssertion)), PropertyAccess);
2723
2726
  function SuperProperty(state) {
2724
2727
  if (state.events) {
2725
2728
  const result = state.events.enter?.("SuperProperty", state);
@@ -2727,12 +2730,12 @@ ${input.slice(result.pos)}
2727
2730
  return result.cache;
2728
2731
  }
2729
2732
  if (state.tokenize) {
2730
- const result = $TOKEN("SuperProperty", state, SuperProperty$0(state));
2733
+ const result = $TOKEN("SuperProperty", state, SuperProperty$0(state) || SuperProperty$1(state));
2731
2734
  if (state.events)
2732
2735
  state.events.exit?.("SuperProperty", state, result);
2733
2736
  return result;
2734
2737
  } else {
2735
- const result = SuperProperty$0(state);
2738
+ const result = SuperProperty$0(state) || SuperProperty$1(state);
2736
2739
  if (state.events)
2737
2740
  state.events.exit?.("SuperProperty", state, result);
2738
2741
  return result;
@@ -10570,20 +10573,45 @@ ${input.slice(result.pos)}
10570
10573
  return result;
10571
10574
  }
10572
10575
  }
10576
+ var TypedJSXElement$0 = $TS($S(JSXElement), function($skip, $loc, $0, $1) {
10577
+ const type = module.typeOfJSXElement($1);
10578
+ return type ? [
10579
+ { ts: true, children: ["("] },
10580
+ $1,
10581
+ { ts: true, children: [" as any as ", type, ")"] }
10582
+ ] : $1;
10583
+ });
10584
+ function TypedJSXElement(state) {
10585
+ if (state.events) {
10586
+ const result = state.events.enter?.("TypedJSXElement", state);
10587
+ if (result)
10588
+ return result.cache;
10589
+ }
10590
+ if (state.tokenize) {
10591
+ const result = $TOKEN("TypedJSXElement", state, TypedJSXElement$0(state));
10592
+ if (state.events)
10593
+ state.events.exit?.("TypedJSXElement", state, result);
10594
+ return result;
10595
+ } else {
10596
+ const result = TypedJSXElement$0(state);
10597
+ if (state.events)
10598
+ state.events.exit?.("TypedJSXElement", state, result);
10599
+ return result;
10600
+ }
10601
+ }
10573
10602
  var JSXElement$0 = JSXSelfClosingElement;
10574
10603
  var JSXElement$1 = $TS($S(JSXOpeningElement, $E(JSXChildren), __, JSXClosingElement), function($skip, $loc, $0, $1, $2, $3, $4) {
10575
10604
  if ($1[1] !== $4[2])
10576
10605
  return $skip;
10577
- return $0;
10606
+ return { type: "JSXElement", children: $0 };
10578
10607
  });
10579
10608
  var JSXElement$2 = $TS($S(JSXOpeningElement, JSXMixedChildren, InsertNewline, InsertIndent), function($skip, $loc, $0, $1, $2, $3, $4) {
10580
10609
  var open = $1;
10581
10610
  var children = $2;
10582
- if (children.length) {
10583
- return [...$0, ["</", open[1], ">"]];
10584
- } else {
10585
- return [open.slice(0, -1), " />"];
10586
- }
10611
+ return {
10612
+ type: "JSXElement",
10613
+ children: children.jsxChildren.length ? [...$0, ["</", open[1], ">"]] : [open.slice(0, -1), " />"]
10614
+ };
10587
10615
  });
10588
10616
  var JSXElement$3 = $TS($S(JSXOpeningElement), function($skip, $loc, $0, $1) {
10589
10617
  throw new Error(`could not parse JSX element "${require_generate()($0)}" at pos ${$loc.pos}`);
@@ -10606,7 +10634,9 @@ ${input.slice(result.pos)}
10606
10634
  return result;
10607
10635
  }
10608
10636
  }
10609
- var JSXSelfClosingElement$0 = $S($EXPECT($L5, fail, 'JSXSelfClosingElement "<"'), $TEXT(JSXElementName), $E(CompactTypeArguments), $E(JSXAttributes), __, $EXPECT($L147, fail, 'JSXSelfClosingElement "/>"'));
10637
+ 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) {
10638
+ return { type: "JSXElement", children: $0 };
10639
+ });
10610
10640
  function JSXSelfClosingElement(state) {
10611
10641
  if (state.events) {
10612
10642
  const result = state.events.enter?.("JSXSelfClosingElement", state);
@@ -10663,9 +10693,41 @@ ${input.slice(result.pos)}
10663
10693
  return result;
10664
10694
  }
10665
10695
  }
10666
- var JSXFragment$0 = $S($EXPECT($L149, fail, 'JSXFragment "<>"'), $E(JSXChildren), __, $EXPECT($L150, fail, 'JSXFragment "</>"'));
10696
+ var TypedJSXFragment$0 = $TS($S(JSXFragment), function($skip, $loc, $0, $1) {
10697
+ const type = module.typeOfJSXFragment($1);
10698
+ return type ? [
10699
+ { ts: true, children: ["("] },
10700
+ $1,
10701
+ { ts: true, children: [" as any as ", type, ")"] }
10702
+ ] : $1;
10703
+ });
10704
+ function TypedJSXFragment(state) {
10705
+ if (state.events) {
10706
+ const result = state.events.enter?.("TypedJSXFragment", state);
10707
+ if (result)
10708
+ return result.cache;
10709
+ }
10710
+ if (state.tokenize) {
10711
+ const result = $TOKEN("TypedJSXFragment", state, TypedJSXFragment$0(state));
10712
+ if (state.events)
10713
+ state.events.exit?.("TypedJSXFragment", state, result);
10714
+ return result;
10715
+ } else {
10716
+ const result = TypedJSXFragment$0(state);
10717
+ if (state.events)
10718
+ state.events.exit?.("TypedJSXFragment", state, result);
10719
+ return result;
10720
+ }
10721
+ }
10722
+ var JSXFragment$0 = $TS($S($EXPECT($L149, fail, 'JSXFragment "<>"'), $E(JSXChildren), __, $EXPECT($L150, fail, 'JSXFragment "</>"')), function($skip, $loc, $0, $1, $2, $3, $4) {
10723
+ if ($2) {
10724
+ return { type: "JSXFragment", children: $0, jsxChildren: $2.jsxChildren };
10725
+ } else {
10726
+ return { type: "JSXFragment", children: $0, jsxChildren: [] };
10727
+ }
10728
+ });
10667
10729
  var JSXFragment$1 = $TS($S($EXPECT($L149, fail, 'JSXFragment "<>"'), JSXMixedChildren, InsertNewline, InsertIndent), function($skip, $loc, $0, $1, $2, $3, $4) {
10668
- return [...$0, "</>"];
10730
+ return { type: "JSXFragment", children: [...$0, "</>"], jsxChildren: $2.jsxChildren };
10669
10731
  });
10670
10732
  function JSXFragment(state) {
10671
10733
  if (state.events) {
@@ -11143,10 +11205,13 @@ ${input.slice(result.pos)}
11143
11205
  return result;
11144
11206
  }
11145
11207
  }
11146
- var JSXMixedChildren$0 = $TS($S($Q($C(_, JSXChild)), JSXNestedChildren), function($skip, $loc, $0, $1, $2) {
11208
+ var JSXMixedChildren$0 = $TS($S($Q(JSXChild), JSXNestedChildren), function($skip, $loc, $0, $1, $2) {
11147
11209
  var c1 = $1;
11148
11210
  var c2 = $2;
11149
- return c1.concat(c2);
11211
+ return {
11212
+ children: c1.concat(c2),
11213
+ jsxChildren: c1.concat(c2.jsxChildren)
11214
+ };
11150
11215
  });
11151
11216
  function JSXMixedChildren(state) {
11152
11217
  if (state.events) {
@@ -11166,7 +11231,12 @@ ${input.slice(result.pos)}
11166
11231
  return result;
11167
11232
  }
11168
11233
  }
11169
- var JSXChildren$0 = $Q($S(__, JSXChild));
11234
+ var JSXChildren$0 = $TV($Q($S($Q($S($E(NonNewlineWhitespace), EOL, $E(NonNewlineWhitespace))), JSXChild)), function($skip, $loc, $0, $1) {
11235
+ return {
11236
+ children: $1,
11237
+ jsxChildren: $1.map((children) => children[1])
11238
+ };
11239
+ });
11170
11240
  function JSXChildren(state) {
11171
11241
  if (state.events) {
11172
11242
  const result = state.events.enter?.("JSXChildren", state);
@@ -11186,12 +11256,16 @@ ${input.slice(result.pos)}
11186
11256
  }
11187
11257
  }
11188
11258
  var JSXNestedChildren$0 = $TS($S(PushIndent, $Q($S(Nested, $P(JSXChild))), PopIndent), function($skip, $loc, $0, $1, $2, $3) {
11189
- if ($2.length)
11190
- return $2;
11259
+ if ($2.length) {
11260
+ return {
11261
+ children: $2,
11262
+ jsxChildren: [].concat(...$2.map((nestedChildren) => nestedChildren[1]))
11263
+ };
11264
+ }
11191
11265
  return $skip;
11192
11266
  });
11193
11267
  var JSXNestedChildren$1 = $TV($Y(EOS), function($skip, $loc, $0, $1) {
11194
- return [];
11268
+ return { children: [], jsxChildren: [] };
11195
11269
  });
11196
11270
  function JSXNestedChildren(state) {
11197
11271
  if (state.events) {
@@ -11214,7 +11288,14 @@ ${input.slice(result.pos)}
11214
11288
  var JSXChild$0 = JSXText;
11215
11289
  var JSXChild$1 = JSXElement;
11216
11290
  var JSXChild$2 = JSXFragment;
11217
- var JSXChild$3 = $S(OpenBrace, $E(JSXChildExpression), __, CloseBrace);
11291
+ var JSXChild$3 = $TS($S(OpenBrace, $E(JSXChildExpression), __, CloseBrace), function($skip, $loc, $0, $1, $2, $3, $4) {
11292
+ var expression = $2;
11293
+ return {
11294
+ type: "JSXChildExpression",
11295
+ children: $0,
11296
+ expression
11297
+ };
11298
+ });
11218
11299
  function JSXChild(state) {
11219
11300
  if (state.events) {
11220
11301
  const result = state.events.enter?.("JSXChild", state);
@@ -11233,7 +11314,13 @@ ${input.slice(result.pos)}
11233
11314
  return result;
11234
11315
  }
11235
11316
  }
11236
- var JSXText$0 = $R$0($EXPECT($R46, fail, "JSXText /[^{}<>\\r\\n]+/"));
11317
+ var JSXText$0 = $TR($EXPECT($R46, fail, "JSXText /[^{}<>\\r\\n]+/"), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7, $8, $9) {
11318
+ return {
11319
+ type: "JSXText",
11320
+ token: $0,
11321
+ $loc
11322
+ };
11323
+ });
11237
11324
  function JSXText(state) {
11238
11325
  if (state.events) {
11239
11326
  const result = state.events.enter?.("JSXText", state);
@@ -12965,6 +13052,9 @@ ${input.slice(result.pos)}
12965
13052
  coffeeNot: false,
12966
13053
  coffeeOf: false,
12967
13054
  implicitReturns: true,
13055
+ solid: false,
13056
+ client: false,
13057
+ server: false,
12968
13058
  tab: void 0,
12969
13059
  verbose: false
12970
13060
  };
@@ -12987,6 +13077,34 @@ ${input.slice(result.pos)}
12987
13077
  children: [": <T>(this: T, prop: keyof T) => boolean"]
12988
13078
  };
12989
13079
  module.prelude.push(["", ["const ", hasPropRef, typeSuffix, " = {}.hasOwnProperty", module.asAny, "\n"]]);
13080
+ },
13081
+ JSX(jsxRef) {
13082
+ module.prelude.push({
13083
+ ts: true,
13084
+ children: [
13085
+ "import type { JSX as ",
13086
+ jsxRef,
13087
+ " } from 'solid-js';\n"
13088
+ ]
13089
+ });
13090
+ },
13091
+ IntrinsicElements(intrinsicElementsRef) {
13092
+ const JSX = module.getRef("JSX");
13093
+ module.prelude.push({
13094
+ ts: true,
13095
+ children: [
13096
+ "type ",
13097
+ intrinsicElementsRef,
13098
+ "<K extends keyof ",
13099
+ JSX,
13100
+ ".IntrinsicElements> =\n",
13101
+ " ",
13102
+ JSX,
13103
+ ".IntrinsicElements[K] extends ",
13104
+ JSX,
13105
+ ".DOMAttributes<infer T> ? T : unknown;\n"
13106
+ ]
13107
+ });
12990
13108
  }
12991
13109
  };
12992
13110
  const refs = {};
@@ -13004,11 +13122,55 @@ ${input.slice(result.pos)}
13004
13122
  };
13005
13123
  module.typeOfJSXElement = function($12) {
13006
13124
  if (module.config.solid) {
13007
- let open = $12;
13125
+ if (module.config.server && !module.config.client) {
13126
+ return ["string"];
13127
+ }
13128
+ let open = $12.children;
13008
13129
  while (Array.isArray(open[0]))
13009
13130
  open = open[0];
13010
13131
  open = open[1];
13011
- return typeof open === "string" && open[0] === open[0].toLowerCase() ? [module.getRef("IntrinsicElements"), '<"', open, '">'] : ["ReturnType<typeof ", open, ">"];
13132
+ const clientType = typeof open === "string" && open[0] === open[0].toLowerCase() ? [module.getRef("IntrinsicElements"), '<"', open, '">'] : ["ReturnType<typeof ", open, ">"];
13133
+ if (module.config.server) {
13134
+ return ["string", " | ", clientType];
13135
+ } else {
13136
+ return clientType;
13137
+ }
13138
+ }
13139
+ };
13140
+ module.typeOfJSXFragment = function($12) {
13141
+ if (module.config.solid) {
13142
+ let type = [];
13143
+ let lastType;
13144
+ for (let child of $12.jsxChildren) {
13145
+ switch (child.type) {
13146
+ case "JSXText":
13147
+ if (lastType !== "JSXText") {
13148
+ type.push("string");
13149
+ }
13150
+ break;
13151
+ case "JSXElement":
13152
+ type.push(module.typeOfJSXElement(child));
13153
+ break;
13154
+ case "JSXFragment":
13155
+ type.push(...module.typeOfJSXFragment(child));
13156
+ break;
13157
+ case "JSXChildExpression":
13158
+ if (child.expression) {
13159
+ type.push(["typeof ", child.expression]);
13160
+ }
13161
+ break;
13162
+ default:
13163
+ throw new Error(`unknown child in JSXFragment: ${JSON.stringify(child)}`);
13164
+ }
13165
+ lastType = child.type;
13166
+ }
13167
+ if (type.length === 1) {
13168
+ return type[0];
13169
+ } else {
13170
+ type = type.map((t) => [t, ", "]).flat();
13171
+ type.pop();
13172
+ return ["[", type, "]"];
13173
+ }
13012
13174
  }
13013
13175
  };
13014
13176
  Object.defineProperty(module.config, "coffeeCompat", {
@@ -13566,12 +13728,12 @@ ${input.slice(result.pos)}
13566
13728
  if (node == null)
13567
13729
  return [];
13568
13730
  if (Array.isArray(node)) {
13569
- return node.flatMap((n) => gatherNodes(n, predicate));
13731
+ return node.flatMap((n) => gatherRecursive(n, predicate));
13570
13732
  }
13571
13733
  if (predicate(node)) {
13572
13734
  return [node];
13573
13735
  }
13574
- return gatherNodes(node.children, predicate);
13736
+ return gatherRecursive(node.children, predicate);
13575
13737
  }
13576
13738
  function gatherRecursiveAll(node, predicate) {
13577
13739
  if (node == null)
@@ -13889,6 +14051,13 @@ ${input.slice(result.pos)}
13889
14051
  function hasDec(name) {
13890
14052
  return scopes.some((s) => s.has(name));
13891
14053
  }
14054
+ function findVarDecs(statements2, decs) {
14055
+ const declarationNames = gatherRecursive(
14056
+ statements2,
14057
+ (node) => node.type === "Declaration" && node.children && node.children.length > 0 && node.children[0].token && node.children[0].token.startsWith("var") || node.type === "FunctionExpression"
14058
+ ).filter((node) => node.type === "Declaration").flatMap((node) => node.names);
14059
+ return new Set(declarationNames);
14060
+ }
13892
14061
  function insertBeforeAssignment(assignment, content) {
13893
14062
  if (assignment.children && assignment.children.length) {
13894
14063
  let indent = assignment.children[0][0][0];
@@ -13901,10 +14070,11 @@ ${input.slice(result.pos)}
13901
14070
  scopes.push(currentScope);
13902
14071
  const fnNodes = gatherNodes(statements, (s) => s.type === "FunctionExpression");
13903
14072
  const forNodes = gatherNodes(statements, (s) => s.type === "ForStatement");
13904
- const nodes = gatherNodes(statements, (s) => s.type === "BlockStatement" || s.type === "AssignmentExpression");
14073
+ const nodes = gatherNodes(statements, (s) => s.type === "BlockStatement" || s.type === "AssignmentExpression" || s.type === "Declaration");
14074
+ let declaredIdentifiers = findVarDecs(statements);
13905
14075
  for (const node of nodes) {
13906
14076
  if (node.type == "AssignmentExpression") {
13907
- let undeclaredIdentifiers = node.names.filter((name) => !hasDec(name));
14077
+ let undeclaredIdentifiers = node.names.filter((name) => !(hasDec(name) || declaredIdentifiers.has(name)));
13908
14078
  if (node.children.length)
13909
14079
  createLetDecs(node.children, scopes);
13910
14080
  undeclaredIdentifiers.forEach((name) => currentScope.add(name));
@@ -13913,6 +14083,8 @@ ${input.slice(result.pos)}
13913
14083
  } else if (undeclaredIdentifiers.length > 0) {
13914
14084
  insertBeforeAssignment(node, ["let ", undeclaredIdentifiers.join(", "), "\n"]);
13915
14085
  }
14086
+ } else if (node.type == "Declaration") {
14087
+ node.names.forEach((name) => currentScope.add(name));
13916
14088
  } else {
13917
14089
  let block = node;
13918
14090
  let fnNode = fnNodes.find((fnNode2) => fnNode2.block === block);
@@ -14613,9 +14785,11 @@ ${"//#"} sourceMappingURL=data:application/json;base64,${base64Encode(JSON.strin
14613
14785
  case "SingleLineComment":
14614
14786
  case "Debugger":
14615
14787
  case "JSXElement":
14788
+ case "TypedJSXElement":
14789
+ case "JSXFragment":
14790
+ case "TypedJSXFragment":
14616
14791
  case "JSXChild":
14617
14792
  case "JSXChildren":
14618
- case "JSXFragment":
14619
14793
  case "JSXNestedChildren":
14620
14794
  case "JSXMixedChildren":
14621
14795
  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,
@@ -2002,8 +2004,8 @@ ${input.slice(result.pos)}
2002
2004
  var PrimaryExpression$7 = RegularExpressionLiteral;
2003
2005
  var PrimaryExpression$8 = TemplateLiteral;
2004
2006
  var PrimaryExpression$9 = ParenthesizedExpression;
2005
- var PrimaryExpression$10 = JSXElement;
2006
- var PrimaryExpression$11 = JSXFragment;
2007
+ var PrimaryExpression$10 = TypedJSXElement;
2008
+ var PrimaryExpression$11 = TypedJSXFragment;
2007
2009
  function PrimaryExpression(state) {
2008
2010
  if (state.events) {
2009
2011
  const result = state.events.enter?.("PrimaryExpression", state);
@@ -2719,6 +2721,7 @@ ${input.slice(result.pos)}
2719
2721
  }
2720
2722
  }
2721
2723
  var SuperProperty$0 = $S($EXPECT($L13, fail, 'SuperProperty "super["'), ExtendedExpression, __, CloseBracket);
2724
+ var SuperProperty$1 = $S($EXPECT($L10, fail, 'SuperProperty "super"'), $N($C(QuestionMark, NonNullAssertion)), PropertyAccess);
2722
2725
  function SuperProperty(state) {
2723
2726
  if (state.events) {
2724
2727
  const result = state.events.enter?.("SuperProperty", state);
@@ -2726,12 +2729,12 @@ ${input.slice(result.pos)}
2726
2729
  return result.cache;
2727
2730
  }
2728
2731
  if (state.tokenize) {
2729
- const result = $TOKEN("SuperProperty", state, SuperProperty$0(state));
2732
+ const result = $TOKEN("SuperProperty", state, SuperProperty$0(state) || SuperProperty$1(state));
2730
2733
  if (state.events)
2731
2734
  state.events.exit?.("SuperProperty", state, result);
2732
2735
  return result;
2733
2736
  } else {
2734
- const result = SuperProperty$0(state);
2737
+ const result = SuperProperty$0(state) || SuperProperty$1(state);
2735
2738
  if (state.events)
2736
2739
  state.events.exit?.("SuperProperty", state, result);
2737
2740
  return result;
@@ -10569,20 +10572,45 @@ ${input.slice(result.pos)}
10569
10572
  return result;
10570
10573
  }
10571
10574
  }
10575
+ var TypedJSXElement$0 = $TS($S(JSXElement), function($skip, $loc, $0, $1) {
10576
+ const type = module2.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
+ }
10572
10601
  var JSXElement$0 = JSXSelfClosingElement;
10573
10602
  var JSXElement$1 = $TS($S(JSXOpeningElement, $E(JSXChildren), __, JSXClosingElement), function($skip, $loc, $0, $1, $2, $3, $4) {
10574
10603
  if ($1[1] !== $4[2])
10575
10604
  return $skip;
10576
- return $0;
10605
+ return { type: "JSXElement", children: $0 };
10577
10606
  });
10578
10607
  var JSXElement$2 = $TS($S(JSXOpeningElement, JSXMixedChildren, InsertNewline, InsertIndent), function($skip, $loc, $0, $1, $2, $3, $4) {
10579
10608
  var open = $1;
10580
10609
  var children = $2;
10581
- if (children.length) {
10582
- return [...$0, ["</", open[1], ">"]];
10583
- } else {
10584
- return [open.slice(0, -1), " />"];
10585
- }
10610
+ return {
10611
+ type: "JSXElement",
10612
+ children: children.jsxChildren.length ? [...$0, ["</", open[1], ">"]] : [open.slice(0, -1), " />"]
10613
+ };
10586
10614
  });
10587
10615
  var JSXElement$3 = $TS($S(JSXOpeningElement), function($skip, $loc, $0, $1) {
10588
10616
  throw new Error(`could not parse JSX element "${require_generate()($0)}" at pos ${$loc.pos}`);
@@ -10605,7 +10633,9 @@ ${input.slice(result.pos)}
10605
10633
  return result;
10606
10634
  }
10607
10635
  }
10608
- 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
+ });
10609
10639
  function JSXSelfClosingElement(state) {
10610
10640
  if (state.events) {
10611
10641
  const result = state.events.enter?.("JSXSelfClosingElement", state);
@@ -10662,9 +10692,41 @@ ${input.slice(result.pos)}
10662
10692
  return result;
10663
10693
  }
10664
10694
  }
10665
- 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 = module2.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
+ });
10666
10728
  var JSXFragment$1 = $TS($S($EXPECT($L149, fail, 'JSXFragment "<>"'), JSXMixedChildren, InsertNewline, InsertIndent), function($skip, $loc, $0, $1, $2, $3, $4) {
10667
- return [...$0, "</>"];
10729
+ return { type: "JSXFragment", children: [...$0, "</>"], jsxChildren: $2.jsxChildren };
10668
10730
  });
10669
10731
  function JSXFragment(state) {
10670
10732
  if (state.events) {
@@ -11142,10 +11204,13 @@ ${input.slice(result.pos)}
11142
11204
  return result;
11143
11205
  }
11144
11206
  }
11145
- 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) {
11146
11208
  var c1 = $1;
11147
11209
  var c2 = $2;
11148
- return c1.concat(c2);
11210
+ return {
11211
+ children: c1.concat(c2),
11212
+ jsxChildren: c1.concat(c2.jsxChildren)
11213
+ };
11149
11214
  });
11150
11215
  function JSXMixedChildren(state) {
11151
11216
  if (state.events) {
@@ -11165,7 +11230,12 @@ ${input.slice(result.pos)}
11165
11230
  return result;
11166
11231
  }
11167
11232
  }
11168
- 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
+ });
11169
11239
  function JSXChildren(state) {
11170
11240
  if (state.events) {
11171
11241
  const result = state.events.enter?.("JSXChildren", state);
@@ -11185,12 +11255,16 @@ ${input.slice(result.pos)}
11185
11255
  }
11186
11256
  }
11187
11257
  var JSXNestedChildren$0 = $TS($S(PushIndent, $Q($S(Nested, $P(JSXChild))), PopIndent), function($skip, $loc, $0, $1, $2, $3) {
11188
- if ($2.length)
11189
- return $2;
11258
+ if ($2.length) {
11259
+ return {
11260
+ children: $2,
11261
+ jsxChildren: [].concat(...$2.map((nestedChildren) => nestedChildren[1]))
11262
+ };
11263
+ }
11190
11264
  return $skip;
11191
11265
  });
11192
11266
  var JSXNestedChildren$1 = $TV($Y(EOS), function($skip, $loc, $0, $1) {
11193
- return [];
11267
+ return { children: [], jsxChildren: [] };
11194
11268
  });
11195
11269
  function JSXNestedChildren(state) {
11196
11270
  if (state.events) {
@@ -11213,7 +11287,14 @@ ${input.slice(result.pos)}
11213
11287
  var JSXChild$0 = JSXText;
11214
11288
  var JSXChild$1 = JSXElement;
11215
11289
  var JSXChild$2 = JSXFragment;
11216
- 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
+ });
11217
11298
  function JSXChild(state) {
11218
11299
  if (state.events) {
11219
11300
  const result = state.events.enter?.("JSXChild", state);
@@ -11232,7 +11313,13 @@ ${input.slice(result.pos)}
11232
11313
  return result;
11233
11314
  }
11234
11315
  }
11235
- 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
+ });
11236
11323
  function JSXText(state) {
11237
11324
  if (state.events) {
11238
11325
  const result = state.events.enter?.("JSXText", state);
@@ -12964,6 +13051,9 @@ ${input.slice(result.pos)}
12964
13051
  coffeeNot: false,
12965
13052
  coffeeOf: false,
12966
13053
  implicitReturns: true,
13054
+ solid: false,
13055
+ client: false,
13056
+ server: false,
12967
13057
  tab: void 0,
12968
13058
  verbose: false
12969
13059
  };
@@ -12986,6 +13076,34 @@ ${input.slice(result.pos)}
12986
13076
  children: [": <T>(this: T, prop: keyof T) => boolean"]
12987
13077
  };
12988
13078
  module2.prelude.push(["", ["const ", hasPropRef, typeSuffix, " = {}.hasOwnProperty", module2.asAny, "\n"]]);
13079
+ },
13080
+ JSX(jsxRef) {
13081
+ module2.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 = module2.getRef("JSX");
13092
+ module2.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
+ });
12989
13107
  }
12990
13108
  };
12991
13109
  const refs = {};
@@ -13003,11 +13121,55 @@ ${input.slice(result.pos)}
13003
13121
  };
13004
13122
  module2.typeOfJSXElement = function($12) {
13005
13123
  if (module2.config.solid) {
13006
- let open = $12;
13124
+ if (module2.config.server && !module2.config.client) {
13125
+ return ["string"];
13126
+ }
13127
+ let open = $12.children;
13007
13128
  while (Array.isArray(open[0]))
13008
13129
  open = open[0];
13009
13130
  open = open[1];
13010
- return typeof open === "string" && open[0] === open[0].toLowerCase() ? [module2.getRef("IntrinsicElements"), '<"', open, '">'] : ["ReturnType<typeof ", open, ">"];
13131
+ const clientType = typeof open === "string" && open[0] === open[0].toLowerCase() ? [module2.getRef("IntrinsicElements"), '<"', open, '">'] : ["ReturnType<typeof ", open, ">"];
13132
+ if (module2.config.server) {
13133
+ return ["string", " | ", clientType];
13134
+ } else {
13135
+ return clientType;
13136
+ }
13137
+ }
13138
+ };
13139
+ module2.typeOfJSXFragment = function($12) {
13140
+ if (module2.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(module2.typeOfJSXElement(child));
13152
+ break;
13153
+ case "JSXFragment":
13154
+ type.push(...module2.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
+ }
13011
13173
  }
13012
13174
  };
13013
13175
  Object.defineProperty(module2.config, "coffeeCompat", {
@@ -13565,12 +13727,12 @@ ${input.slice(result.pos)}
13565
13727
  if (node == null)
13566
13728
  return [];
13567
13729
  if (Array.isArray(node)) {
13568
- return node.flatMap((n) => gatherNodes(n, predicate));
13730
+ return node.flatMap((n) => gatherRecursive(n, predicate));
13569
13731
  }
13570
13732
  if (predicate(node)) {
13571
13733
  return [node];
13572
13734
  }
13573
- return gatherNodes(node.children, predicate);
13735
+ return gatherRecursive(node.children, predicate);
13574
13736
  }
13575
13737
  function gatherRecursiveAll(node, predicate) {
13576
13738
  if (node == null)
@@ -13888,6 +14050,13 @@ ${input.slice(result.pos)}
13888
14050
  function hasDec(name) {
13889
14051
  return scopes.some((s) => s.has(name));
13890
14052
  }
14053
+ function findVarDecs(statements2, decs) {
14054
+ const declarationNames = gatherRecursive(
14055
+ statements2,
14056
+ (node) => node.type === "Declaration" && node.children && node.children.length > 0 && node.children[0].token && node.children[0].token.startsWith("var") || node.type === "FunctionExpression"
14057
+ ).filter((node) => node.type === "Declaration").flatMap((node) => node.names);
14058
+ return new Set(declarationNames);
14059
+ }
13891
14060
  function insertBeforeAssignment(assignment, content) {
13892
14061
  if (assignment.children && assignment.children.length) {
13893
14062
  let indent = assignment.children[0][0][0];
@@ -13900,10 +14069,11 @@ ${input.slice(result.pos)}
13900
14069
  scopes.push(currentScope);
13901
14070
  const fnNodes = gatherNodes(statements, (s) => s.type === "FunctionExpression");
13902
14071
  const forNodes = gatherNodes(statements, (s) => s.type === "ForStatement");
13903
- const nodes = gatherNodes(statements, (s) => s.type === "BlockStatement" || s.type === "AssignmentExpression");
14072
+ const nodes = gatherNodes(statements, (s) => s.type === "BlockStatement" || s.type === "AssignmentExpression" || s.type === "Declaration");
14073
+ let declaredIdentifiers = findVarDecs(statements);
13904
14074
  for (const node of nodes) {
13905
14075
  if (node.type == "AssignmentExpression") {
13906
- let undeclaredIdentifiers = node.names.filter((name) => !hasDec(name));
14076
+ let undeclaredIdentifiers = node.names.filter((name) => !(hasDec(name) || declaredIdentifiers.has(name)));
13907
14077
  if (node.children.length)
13908
14078
  createLetDecs(node.children, scopes);
13909
14079
  undeclaredIdentifiers.forEach((name) => currentScope.add(name));
@@ -13912,6 +14082,8 @@ ${input.slice(result.pos)}
13912
14082
  } else if (undeclaredIdentifiers.length > 0) {
13913
14083
  insertBeforeAssignment(node, ["let ", undeclaredIdentifiers.join(", "), "\n"]);
13914
14084
  }
14085
+ } else if (node.type == "Declaration") {
14086
+ node.names.forEach((name) => currentScope.add(name));
13915
14087
  } else {
13916
14088
  let block = node;
13917
14089
  let fnNode = fnNodes.find((fnNode2) => fnNode2.block === block);
@@ -14610,9 +14782,11 @@ makeCache = function() {
14610
14782
  case "SingleLineComment":
14611
14783
  case "Debugger":
14612
14784
  case "JSXElement":
14785
+ case "TypedJSXElement":
14786
+ case "JSXFragment":
14787
+ case "TypedJSXFragment":
14613
14788
  case "JSXChild":
14614
14789
  case "JSXChildren":
14615
- case "JSXFragment":
14616
14790
  case "JSXNestedChildren":
14617
14791
  case "JSXMixedChildren":
14618
14792
  break;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@danielx/civet",
3
- "version": "0.5.4",
3
+ "version": "0.5.6",
4
4
  "description": "CoffeeScript style syntax for TypeScript",
5
5
  "main": "dist/main.js",
6
6
  "exports": {