@danielx/civet 0.5.5 → 0.5.7

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
  ---
@@ -240,7 +245,7 @@ Things Changed from ES6
240
245
  behave more differently than they already do is bad. Passing an anonymous function to an
241
246
  application without parens is also convenient.
242
247
  - `for(i of x) ...` defaults to const declaration → `for(const i of x) ...`
243
- - 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.
244
249
  - Comma operator in `case`/`when` instead becomes multiple conditions.
245
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
246
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
@@ -2302,9 +2302,8 @@ ${input.slice(result.pos)}
2302
2302
  return result;
2303
2303
  }
2304
2304
  }
2305
- var ClassElement$0 = MethodDefinition;
2306
- var ClassElement$1 = $S($E($S(Static, $Q(TrailingComment))), $C(MethodDefinition, FieldDefinition));
2307
- var ClassElement$2 = $S(Static, BracedBlock);
2305
+ var ClassElement$0 = $S($E(Decorators), $E($S(Static, $Q(TrailingComment))), $C(MethodDefinition, FieldDefinition));
2306
+ var ClassElement$1 = $S(Static, BracedBlock);
2308
2307
  function ClassElement(state) {
2309
2308
  if (state.events) {
2310
2309
  const result = state.events.enter?.("ClassElement", state);
@@ -2312,12 +2311,12 @@ ${input.slice(result.pos)}
2312
2311
  return result.cache;
2313
2312
  }
2314
2313
  if (state.tokenize) {
2315
- const result = $TOKEN("ClassElement", state, ClassElement$0(state) || ClassElement$1(state) || ClassElement$2(state));
2314
+ const result = $TOKEN("ClassElement", state, ClassElement$0(state) || ClassElement$1(state));
2316
2315
  if (state.events)
2317
2316
  state.events.exit?.("ClassElement", state, result);
2318
2317
  return result;
2319
2318
  } else {
2320
- const result = ClassElement$0(state) || ClassElement$1(state) || ClassElement$2(state);
2319
+ const result = ClassElement$0(state) || ClassElement$1(state);
2321
2320
  if (state.events)
2322
2321
  state.events.exit?.("ClassElement", state, result);
2323
2322
  return result;
@@ -2722,6 +2721,7 @@ ${input.slice(result.pos)}
2722
2721
  }
2723
2722
  }
2724
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);
2725
2725
  function SuperProperty(state) {
2726
2726
  if (state.events) {
2727
2727
  const result = state.events.enter?.("SuperProperty", state);
@@ -2729,12 +2729,12 @@ ${input.slice(result.pos)}
2729
2729
  return result.cache;
2730
2730
  }
2731
2731
  if (state.tokenize) {
2732
- const result = $TOKEN("SuperProperty", state, SuperProperty$0(state));
2732
+ const result = $TOKEN("SuperProperty", state, SuperProperty$0(state) || SuperProperty$1(state));
2733
2733
  if (state.events)
2734
2734
  state.events.exit?.("SuperProperty", state, result);
2735
2735
  return result;
2736
2736
  } else {
2737
- const result = SuperProperty$0(state);
2737
+ const result = SuperProperty$0(state) || SuperProperty$1(state);
2738
2738
  if (state.events)
2739
2739
  state.events.exit?.("SuperProperty", state, result);
2740
2740
  return result;
@@ -5103,15 +5103,13 @@ ${input.slice(result.pos)}
5103
5103
  return result;
5104
5104
  }
5105
5105
  }
5106
- var MethodDefinition$0 = $TS($S($E(Decorators), MethodSignature, BracedBlock), function($skip, $loc, $0, $1, $2, $3) {
5107
- var decorators = $1;
5108
- var signature = $2;
5109
- var block = $3;
5106
+ var MethodDefinition$0 = $TS($S(MethodSignature, BracedBlock), function($skip, $loc, $0, $1, $2) {
5107
+ var signature = $1;
5108
+ var block = $2;
5110
5109
  return {
5111
5110
  type: "MethodDefinition",
5112
5111
  children: $0,
5113
5112
  name: signature.name,
5114
- decorators,
5115
5113
  signature,
5116
5114
  block,
5117
5115
  parameters: signature.parameters
@@ -7001,8 +6999,8 @@ ${input.slice(result.pos)}
7001
6999
  return result;
7002
7000
  }
7003
7001
  }
7004
- var CatchParameter$0 = BindingIdentifier;
7005
- var CatchParameter$1 = BindingPattern;
7002
+ var CatchParameter$0 = $S(BindingIdentifier, $E(TypeSuffix));
7003
+ var CatchParameter$1 = $S(BindingPattern, $E(TypeSuffix));
7006
7004
  function CatchParameter(state) {
7007
7005
  if (state.events) {
7008
7006
  const result = state.events.enter?.("CatchParameter", state);
@@ -13727,12 +13725,12 @@ ${input.slice(result.pos)}
13727
13725
  if (node == null)
13728
13726
  return [];
13729
13727
  if (Array.isArray(node)) {
13730
- return node.flatMap((n) => gatherNodes(n, predicate));
13728
+ return node.flatMap((n) => gatherRecursive(n, predicate));
13731
13729
  }
13732
13730
  if (predicate(node)) {
13733
13731
  return [node];
13734
13732
  }
13735
- return gatherNodes(node.children, predicate);
13733
+ return gatherRecursive(node.children, predicate);
13736
13734
  }
13737
13735
  function gatherRecursiveAll(node, predicate) {
13738
13736
  if (node == null)
@@ -13911,7 +13909,7 @@ ${input.slice(result.pos)}
13911
13909
  }
13912
13910
  };
13913
13911
  module.convertMethodToFunction = function(method) {
13914
- const { decorators, signature, block } = method;
13912
+ const { signature, block } = method;
13915
13913
  let opening = signature.children[0];
13916
13914
  if (opening) {
13917
13915
  if (opening[0].type === "GetOrSet") {
@@ -13929,7 +13927,6 @@ ${input.slice(result.pos)}
13929
13927
  id: signature.name,
13930
13928
  type: "FunctionExpression",
13931
13929
  children: [
13932
- decorators,
13933
13930
  [opening, ...signature.children.slice(1)],
13934
13931
  block
13935
13932
  ],
@@ -14050,6 +14047,13 @@ ${input.slice(result.pos)}
14050
14047
  function hasDec(name) {
14051
14048
  return scopes.some((s) => s.has(name));
14052
14049
  }
14050
+ function findVarDecs(statements2, decs) {
14051
+ const declarationNames = gatherRecursive(
14052
+ statements2,
14053
+ (node) => node.type === "Declaration" && node.children && node.children.length > 0 && node.children[0].token && node.children[0].token.startsWith("var") || node.type === "FunctionExpression"
14054
+ ).filter((node) => node.type === "Declaration").flatMap((node) => node.names);
14055
+ return new Set(declarationNames);
14056
+ }
14053
14057
  function insertBeforeAssignment(assignment, content) {
14054
14058
  if (assignment.children && assignment.children.length) {
14055
14059
  let indent = assignment.children[0][0][0];
@@ -14062,10 +14066,11 @@ ${input.slice(result.pos)}
14062
14066
  scopes.push(currentScope);
14063
14067
  const fnNodes = gatherNodes(statements, (s) => s.type === "FunctionExpression");
14064
14068
  const forNodes = gatherNodes(statements, (s) => s.type === "ForStatement");
14065
- const nodes = gatherNodes(statements, (s) => s.type === "BlockStatement" || s.type === "AssignmentExpression");
14069
+ const nodes = gatherNodes(statements, (s) => s.type === "BlockStatement" || s.type === "AssignmentExpression" || s.type === "Declaration");
14070
+ let declaredIdentifiers = findVarDecs(statements);
14066
14071
  for (const node of nodes) {
14067
14072
  if (node.type == "AssignmentExpression") {
14068
- let undeclaredIdentifiers = node.names.filter((name) => !hasDec(name));
14073
+ let undeclaredIdentifiers = node.names.filter((name) => !(hasDec(name) || declaredIdentifiers.has(name)));
14069
14074
  if (node.children.length)
14070
14075
  createLetDecs(node.children, scopes);
14071
14076
  undeclaredIdentifiers.forEach((name) => currentScope.add(name));
@@ -14074,6 +14079,8 @@ ${input.slice(result.pos)}
14074
14079
  } else if (undeclaredIdentifiers.length > 0) {
14075
14080
  insertBeforeAssignment(node, ["let ", undeclaredIdentifiers.join(", "), "\n"]);
14076
14081
  }
14082
+ } else if (node.type == "Declaration") {
14083
+ node.names.forEach((name) => currentScope.add(name));
14077
14084
  } else {
14078
14085
  let block = node;
14079
14086
  let fnNode = fnNodes.find((fnNode2) => fnNode2.block === block);
package/dist/main.js CHANGED
@@ -2301,9 +2301,8 @@ ${input.slice(result.pos)}
2301
2301
  return result;
2302
2302
  }
2303
2303
  }
2304
- var ClassElement$0 = MethodDefinition;
2305
- var ClassElement$1 = $S($E($S(Static, $Q(TrailingComment))), $C(MethodDefinition, FieldDefinition));
2306
- var ClassElement$2 = $S(Static, BracedBlock);
2304
+ var ClassElement$0 = $S($E(Decorators), $E($S(Static, $Q(TrailingComment))), $C(MethodDefinition, FieldDefinition));
2305
+ var ClassElement$1 = $S(Static, BracedBlock);
2307
2306
  function ClassElement(state) {
2308
2307
  if (state.events) {
2309
2308
  const result = state.events.enter?.("ClassElement", state);
@@ -2311,12 +2310,12 @@ ${input.slice(result.pos)}
2311
2310
  return result.cache;
2312
2311
  }
2313
2312
  if (state.tokenize) {
2314
- const result = $TOKEN("ClassElement", state, ClassElement$0(state) || ClassElement$1(state) || ClassElement$2(state));
2313
+ const result = $TOKEN("ClassElement", state, ClassElement$0(state) || ClassElement$1(state));
2315
2314
  if (state.events)
2316
2315
  state.events.exit?.("ClassElement", state, result);
2317
2316
  return result;
2318
2317
  } else {
2319
- const result = ClassElement$0(state) || ClassElement$1(state) || ClassElement$2(state);
2318
+ const result = ClassElement$0(state) || ClassElement$1(state);
2320
2319
  if (state.events)
2321
2320
  state.events.exit?.("ClassElement", state, result);
2322
2321
  return result;
@@ -2721,6 +2720,7 @@ ${input.slice(result.pos)}
2721
2720
  }
2722
2721
  }
2723
2722
  var SuperProperty$0 = $S($EXPECT($L13, fail, 'SuperProperty "super["'), ExtendedExpression, __, CloseBracket);
2723
+ var SuperProperty$1 = $S($EXPECT($L10, fail, 'SuperProperty "super"'), $N($C(QuestionMark, NonNullAssertion)), PropertyAccess);
2724
2724
  function SuperProperty(state) {
2725
2725
  if (state.events) {
2726
2726
  const result = state.events.enter?.("SuperProperty", state);
@@ -2728,12 +2728,12 @@ ${input.slice(result.pos)}
2728
2728
  return result.cache;
2729
2729
  }
2730
2730
  if (state.tokenize) {
2731
- const result = $TOKEN("SuperProperty", state, SuperProperty$0(state));
2731
+ const result = $TOKEN("SuperProperty", state, SuperProperty$0(state) || SuperProperty$1(state));
2732
2732
  if (state.events)
2733
2733
  state.events.exit?.("SuperProperty", state, result);
2734
2734
  return result;
2735
2735
  } else {
2736
- const result = SuperProperty$0(state);
2736
+ const result = SuperProperty$0(state) || SuperProperty$1(state);
2737
2737
  if (state.events)
2738
2738
  state.events.exit?.("SuperProperty", state, result);
2739
2739
  return result;
@@ -5102,15 +5102,13 @@ ${input.slice(result.pos)}
5102
5102
  return result;
5103
5103
  }
5104
5104
  }
5105
- var MethodDefinition$0 = $TS($S($E(Decorators), MethodSignature, BracedBlock), function($skip, $loc, $0, $1, $2, $3) {
5106
- var decorators = $1;
5107
- var signature = $2;
5108
- var block = $3;
5105
+ var MethodDefinition$0 = $TS($S(MethodSignature, BracedBlock), function($skip, $loc, $0, $1, $2) {
5106
+ var signature = $1;
5107
+ var block = $2;
5109
5108
  return {
5110
5109
  type: "MethodDefinition",
5111
5110
  children: $0,
5112
5111
  name: signature.name,
5113
- decorators,
5114
5112
  signature,
5115
5113
  block,
5116
5114
  parameters: signature.parameters
@@ -7000,8 +6998,8 @@ ${input.slice(result.pos)}
7000
6998
  return result;
7001
6999
  }
7002
7000
  }
7003
- var CatchParameter$0 = BindingIdentifier;
7004
- var CatchParameter$1 = BindingPattern;
7001
+ var CatchParameter$0 = $S(BindingIdentifier, $E(TypeSuffix));
7002
+ var CatchParameter$1 = $S(BindingPattern, $E(TypeSuffix));
7005
7003
  function CatchParameter(state) {
7006
7004
  if (state.events) {
7007
7005
  const result = state.events.enter?.("CatchParameter", state);
@@ -13726,12 +13724,12 @@ ${input.slice(result.pos)}
13726
13724
  if (node == null)
13727
13725
  return [];
13728
13726
  if (Array.isArray(node)) {
13729
- return node.flatMap((n) => gatherNodes(n, predicate));
13727
+ return node.flatMap((n) => gatherRecursive(n, predicate));
13730
13728
  }
13731
13729
  if (predicate(node)) {
13732
13730
  return [node];
13733
13731
  }
13734
- return gatherNodes(node.children, predicate);
13732
+ return gatherRecursive(node.children, predicate);
13735
13733
  }
13736
13734
  function gatherRecursiveAll(node, predicate) {
13737
13735
  if (node == null)
@@ -13910,7 +13908,7 @@ ${input.slice(result.pos)}
13910
13908
  }
13911
13909
  };
13912
13910
  module2.convertMethodToFunction = function(method) {
13913
- const { decorators, signature, block } = method;
13911
+ const { signature, block } = method;
13914
13912
  let opening = signature.children[0];
13915
13913
  if (opening) {
13916
13914
  if (opening[0].type === "GetOrSet") {
@@ -13928,7 +13926,6 @@ ${input.slice(result.pos)}
13928
13926
  id: signature.name,
13929
13927
  type: "FunctionExpression",
13930
13928
  children: [
13931
- decorators,
13932
13929
  [opening, ...signature.children.slice(1)],
13933
13930
  block
13934
13931
  ],
@@ -14049,6 +14046,13 @@ ${input.slice(result.pos)}
14049
14046
  function hasDec(name) {
14050
14047
  return scopes.some((s) => s.has(name));
14051
14048
  }
14049
+ function findVarDecs(statements2, decs) {
14050
+ const declarationNames = gatherRecursive(
14051
+ statements2,
14052
+ (node) => node.type === "Declaration" && node.children && node.children.length > 0 && node.children[0].token && node.children[0].token.startsWith("var") || node.type === "FunctionExpression"
14053
+ ).filter((node) => node.type === "Declaration").flatMap((node) => node.names);
14054
+ return new Set(declarationNames);
14055
+ }
14052
14056
  function insertBeforeAssignment(assignment, content) {
14053
14057
  if (assignment.children && assignment.children.length) {
14054
14058
  let indent = assignment.children[0][0][0];
@@ -14061,10 +14065,11 @@ ${input.slice(result.pos)}
14061
14065
  scopes.push(currentScope);
14062
14066
  const fnNodes = gatherNodes(statements, (s) => s.type === "FunctionExpression");
14063
14067
  const forNodes = gatherNodes(statements, (s) => s.type === "ForStatement");
14064
- const nodes = gatherNodes(statements, (s) => s.type === "BlockStatement" || s.type === "AssignmentExpression");
14068
+ const nodes = gatherNodes(statements, (s) => s.type === "BlockStatement" || s.type === "AssignmentExpression" || s.type === "Declaration");
14069
+ let declaredIdentifiers = findVarDecs(statements);
14065
14070
  for (const node of nodes) {
14066
14071
  if (node.type == "AssignmentExpression") {
14067
- let undeclaredIdentifiers = node.names.filter((name) => !hasDec(name));
14072
+ let undeclaredIdentifiers = node.names.filter((name) => !(hasDec(name) || declaredIdentifiers.has(name)));
14068
14073
  if (node.children.length)
14069
14074
  createLetDecs(node.children, scopes);
14070
14075
  undeclaredIdentifiers.forEach((name) => currentScope.add(name));
@@ -14073,6 +14078,8 @@ ${input.slice(result.pos)}
14073
14078
  } else if (undeclaredIdentifiers.length > 0) {
14074
14079
  insertBeforeAssignment(node, ["let ", undeclaredIdentifiers.join(", "), "\n"]);
14075
14080
  }
14081
+ } else if (node.type == "Declaration") {
14082
+ node.names.forEach((name) => currentScope.add(name));
14076
14083
  } else {
14077
14084
  let block = node;
14078
14085
  let fnNode = fnNodes.find((fnNode2) => fnNode2.block === block);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@danielx/civet",
3
- "version": "0.5.5",
3
+ "version": "0.5.7",
4
4
  "description": "CoffeeScript style syntax for TypeScript",
5
5
  "main": "dist/main.js",
6
6
  "exports": {