@danielx/civet 0.6.24 → 0.6.26

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
@@ -17,6 +17,7 @@ The modern way to write TypeScript.
17
17
  - Plugins for
18
18
  [esbuild](source/esbuild-plugin.civet),
19
19
  [Vite](https://github.com/lorefnon/vite-plugin-civet),
20
+ [Babel](source/babel-plugin.mjs),
20
21
  [Gulp](integrations/gulp),
21
22
  [ESM module resolution](source/esm.civet),
22
23
  [CJS](register.js),
@@ -1,3 +1,18 @@
1
+ // Babel plugin for compiling .civet files
2
+
3
+ /* Example babel.config.json:
4
+
5
+ {
6
+ "plugins": [
7
+ [
8
+ "@danielx/civet/babel-plugin"
9
+ ]
10
+ ],
11
+ "sourceMaps": "inline"
12
+ }
13
+
14
+ */
15
+
1
16
  import { compile } from "./main.mjs"
2
17
 
3
18
  export default function (api, civetOptions) {
package/dist/browser.js CHANGED
@@ -1534,12 +1534,7 @@ var Civet = (() => {
1534
1534
  ...exp,
1535
1535
  children: [...exp.children.slice(0, i), " ", id, suffix, ws, ...exp.children.slice(i)]
1536
1536
  };
1537
- return {
1538
- type: "Declaration",
1539
- decl,
1540
- children: [exp],
1541
- names: id.names
1542
- };
1537
+ return exp;
1543
1538
  }
1544
1539
  }
1545
1540
  let [splices, thisAssignments] = gatherBindingCode(id);
@@ -2106,8 +2101,7 @@ var Civet = (() => {
2106
2101
  const [ws, , body] = s.children;
2107
2102
  let [, arg] = s.children;
2108
2103
  let i = 0, l = body.length;
2109
- const refDec = [];
2110
- const children = [ws, refDec];
2104
+ const children = [ws];
2111
2105
  let usingRef = null;
2112
2106
  for (i = 0; i < l; i++) {
2113
2107
  const step = body[i];
@@ -2148,9 +2142,8 @@ var Civet = (() => {
2148
2142
  };
2149
2143
  break;
2150
2144
  }
2151
- children.pop();
2152
2145
  const lhs = [[
2153
- [refDec, initRef],
2146
+ [initRef],
2154
2147
  arg,
2155
2148
  [],
2156
2149
  { token: "=", children: [" = "] }
@@ -2220,7 +2213,11 @@ var Civet = (() => {
2220
2213
  }
2221
2214
  }
2222
2215
  if (usingRef) {
2223
- refDec.unshift("let ", usingRef, ";");
2216
+ s.hoistDec = {
2217
+ type: "Declaration",
2218
+ children: ["let ", usingRef],
2219
+ names: []
2220
+ };
2224
2221
  }
2225
2222
  children.push(arg);
2226
2223
  addParentPointers(s, s.parent);
@@ -2238,14 +2235,16 @@ var Civet = (() => {
2238
2235
  processPipelineExpressions(statements);
2239
2236
  processAssignments(statements);
2240
2237
  processPatternMatching(statements, ReservedWord);
2241
- processFunctions(statements, config);
2242
2238
  processSwitchExpressions(statements);
2243
2239
  processTryExpressions(statements);
2244
2240
  gatherRecursiveAll(statements, (n) => n.type === "IterationExpression").forEach((e) => expressionizeIteration(e));
2245
2241
  hoistRefDecs(statements);
2242
+ processFunctions(statements, config);
2246
2243
  statements.unshift(...m.prelude);
2247
2244
  if (config.autoLet) {
2248
- createLetDecs(statements, []);
2245
+ createConstLetDecs(statements, [], "let");
2246
+ } else if (config.autoConst) {
2247
+ createConstLetDecs(statements, [], "const");
2249
2248
  } else if (config.autoVar) {
2250
2249
  createVarDecs(statements, []);
2251
2250
  }
@@ -2333,7 +2332,7 @@ var Civet = (() => {
2333
2332
  }
2334
2333
  scopes.pop();
2335
2334
  }
2336
- function createLetDecs(statements, scopes) {
2335
+ function createConstLetDecs(statements, scopes, letOrConst) {
2337
2336
  function findVarDecs(statements2, decs) {
2338
2337
  const declarationNames = gatherRecursive(
2339
2338
  statements2,
@@ -2370,14 +2369,14 @@ var Civet = (() => {
2370
2369
  let forNode = forNodes.find((forNode2) => forNode2.block === block);
2371
2370
  if (fnNode != null) {
2372
2371
  scopes.push(new Set(fnNode.parameters.names));
2373
- createLetDecs(block.expressions, scopes);
2372
+ createConstLetDecs(block.expressions, scopes, letOrConst);
2374
2373
  scopes.pop();
2375
2374
  } else if (forNode != null) {
2376
2375
  scopes.push(new Set(forNode.declaration.names));
2377
- createLetDecs(block.expressions, scopes);
2376
+ createConstLetDecs(block.expressions, scopes, letOrConst);
2378
2377
  scopes.pop();
2379
2378
  } else
2380
- createLetDecs(block.expressions, scopes);
2379
+ createConstLetDecs(block.expressions, scopes, letOrConst);
2381
2380
  continue;
2382
2381
  }
2383
2382
  if (node.names == null)
@@ -2391,12 +2390,12 @@ var Civet = (() => {
2391
2390
  let indent = statement[0];
2392
2391
  let firstIdentifier = gatherNodes(statement[1], (node) => node.type == "Identifier")[0];
2393
2392
  if (undeclaredIdentifiers.length == 1 && statement[1].type == "AssignmentExpression" && statement[1].names.length == 1 && statement[1].names[0] == undeclaredIdentifiers[0] && firstIdentifier && firstIdentifier.names == undeclaredIdentifiers[0] && gatherNodes(statement[1], (node) => node.type === "ObjectBindingPattern").length == 0)
2394
- statement[1].children.unshift(["let "]);
2393
+ statement[1].children.unshift([`${letOrConst} `]);
2395
2394
  else {
2396
2395
  let tail = "\n";
2397
2396
  if (gatherNodes(indent, (node) => node.token && node.token.endsWith("\n")).length > 0)
2398
2397
  tail = void 0;
2399
- targetStatements.push([indent, "let ", undeclaredIdentifiers.join(", "), tail]);
2398
+ targetStatements.push([indent, `let `, undeclaredIdentifiers.join(", "), tail]);
2400
2399
  }
2401
2400
  }
2402
2401
  targetStatements.push(statement);
@@ -3216,6 +3215,7 @@ ${input.slice(result.pos)}
3216
3215
  YieldTail,
3217
3216
  ArrowFunction,
3218
3217
  FatArrow,
3218
+ TrailingDeclaration,
3219
3219
  FatArrowBody,
3220
3220
  ConditionalExpression,
3221
3221
  TernaryRest,
@@ -3319,6 +3319,7 @@ ${input.slice(result.pos)}
3319
3319
  BracedBlock,
3320
3320
  NoPostfixBracedBlock,
3321
3321
  NonSingleBracedBlock,
3322
+ DeclarationOrStatement,
3322
3323
  SingleLineStatements,
3323
3324
  PostfixedSingleLineStatements,
3324
3325
  BracedContent,
@@ -5540,7 +5541,30 @@ ${input.slice(result.pos)}
5540
5541
  return result;
5541
5542
  }
5542
5543
  }
5543
- var FatArrowBody$0 = $T($S($N(EOS), NonPipelinePostfixedExpression, $N(SemicolonDelimiter)), function(value) {
5544
+ var TrailingDeclaration$0 = $S($Q(_), $C(ConstAssignment, LetAssignment));
5545
+ function TrailingDeclaration(state) {
5546
+ let eventData;
5547
+ if (state.events) {
5548
+ const result = state.events.enter?.("TrailingDeclaration", state);
5549
+ if (result) {
5550
+ if ("cache" in result)
5551
+ return result.cache;
5552
+ eventData = result.data;
5553
+ }
5554
+ }
5555
+ if (state.tokenize) {
5556
+ const result = $TOKEN("TrailingDeclaration", state, TrailingDeclaration$0(state));
5557
+ if (state.events)
5558
+ state.events.exit?.("TrailingDeclaration", state, result, eventData);
5559
+ return result;
5560
+ } else {
5561
+ const result = TrailingDeclaration$0(state);
5562
+ if (state.events)
5563
+ state.events.exit?.("TrailingDeclaration", state, result, eventData);
5564
+ return result;
5565
+ }
5566
+ }
5567
+ var FatArrowBody$0 = $T($S($N(EOS), NonPipelinePostfixedExpression, $N(TrailingDeclaration), $N(SemicolonDelimiter)), function(value) {
5544
5568
  var exp = value[1];
5545
5569
  return exp;
5546
5570
  });
@@ -9014,7 +9038,31 @@ ${input.slice(result.pos)}
9014
9038
  return result;
9015
9039
  }
9016
9040
  }
9017
- var SingleLineStatements$0 = $TS($S(ForbidNewlineBinaryOp, $Q($S($S($E(_), $N(EOS)), Statement, SemicolonDelimiter)), $E($S($S($E(_), $N(EOS)), Statement, $E(SemicolonDelimiter))), RestoreNewlineBinaryOp), function($skip, $loc, $0, $1, $2, $3, $4) {
9041
+ var DeclarationOrStatement$0 = Declaration;
9042
+ var DeclarationOrStatement$1 = Statement;
9043
+ function DeclarationOrStatement(state) {
9044
+ let eventData;
9045
+ if (state.events) {
9046
+ const result = state.events.enter?.("DeclarationOrStatement", state);
9047
+ if (result) {
9048
+ if ("cache" in result)
9049
+ return result.cache;
9050
+ eventData = result.data;
9051
+ }
9052
+ }
9053
+ if (state.tokenize) {
9054
+ const result = $TOKEN("DeclarationOrStatement", state, DeclarationOrStatement$0(state) || DeclarationOrStatement$1(state));
9055
+ if (state.events)
9056
+ state.events.exit?.("DeclarationOrStatement", state, result, eventData);
9057
+ return result;
9058
+ } else {
9059
+ const result = DeclarationOrStatement$0(state) || DeclarationOrStatement$1(state);
9060
+ if (state.events)
9061
+ state.events.exit?.("DeclarationOrStatement", state, result, eventData);
9062
+ return result;
9063
+ }
9064
+ }
9065
+ var SingleLineStatements$0 = $TS($S(ForbidNewlineBinaryOp, $Q($S($S($E(_), $N(EOS)), DeclarationOrStatement, SemicolonDelimiter)), $E($S($S($E(_), $N(EOS)), DeclarationOrStatement, $E(SemicolonDelimiter))), RestoreNewlineBinaryOp), function($skip, $loc, $0, $1, $2, $3, $4) {
9018
9066
  var stmts = $2;
9019
9067
  var last = $3;
9020
9068
  const expressions = [...stmts];
@@ -9049,7 +9097,7 @@ ${input.slice(result.pos)}
9049
9097
  return result;
9050
9098
  }
9051
9099
  }
9052
- var PostfixedSingleLineStatements$0 = $TS($S($Q($S($S($E(_), $N(EOS)), PostfixedStatement, SemicolonDelimiter)), $E($S($S($E(_), $N(EOS)), PostfixedStatement, $E(SemicolonDelimiter)))), function($skip, $loc, $0, $1, $2) {
9100
+ var PostfixedSingleLineStatements$0 = $TS($S($Q($S($S($E(_), $N(EOS)), StatementListItem, SemicolonDelimiter)), $E($S($S($E(_), $N(EOS)), StatementListItem, $E(SemicolonDelimiter)))), function($skip, $loc, $0, $1, $2) {
9053
9101
  var stmts = $1;
9054
9102
  var last = $2;
9055
9103
  const children = [...stmts];
@@ -9085,14 +9133,7 @@ ${input.slice(result.pos)}
9085
9133
  }
9086
9134
  }
9087
9135
  var BracedContent$0 = NestedBlockStatements;
9088
- var BracedContent$1 = $TS($S($E(_), Statement), function($skip, $loc, $0, $1, $2) {
9089
- const expressions = [["", $2]];
9090
- return {
9091
- type: "BlockStatement",
9092
- expressions,
9093
- children: [$1, expressions]
9094
- };
9095
- });
9136
+ var BracedContent$1 = SingleLineStatements;
9096
9137
  var BracedContent$2 = $TV($Y($S(__, $EXPECT($L24, fail, 'BracedContent "}"'))), function($skip, $loc, $0, $1) {
9097
9138
  const expressions = [];
9098
9139
  return {
@@ -16808,6 +16849,7 @@ ${input.slice(result.pos)}
16808
16849
  var StatementDelimiter$0 = SemicolonDelimiter;
16809
16850
  var StatementDelimiter$1 = $S($Y($S(Nested, $C($EXPECT($L4, fail, 'StatementDelimiter "("'), $EXPECT($L111, fail, 'StatementDelimiter "["'), $EXPECT($L112, fail, 'StatementDelimiter "`"'), $EXPECT($L57, fail, 'StatementDelimiter "+"'), $EXPECT($L18, fail, 'StatementDelimiter "-"'), $EXPECT($L53, fail, 'StatementDelimiter "*"'), $EXPECT($L54, fail, 'StatementDelimiter "/"'), ObjectLiteral, Arrow, FatArrow, $S(Function, $E($S($E(_), Star)), $E(_), $EXPECT($L4, fail, 'StatementDelimiter "("'))))), InsertSemicolon);
16810
16851
  var StatementDelimiter$2 = $Y(EOS);
16852
+ var StatementDelimiter$3 = $Y($S($Q(_), $EXPECT($L24, fail, 'StatementDelimiter "}"')));
16811
16853
  function StatementDelimiter(state) {
16812
16854
  let eventData;
16813
16855
  if (state.events) {
@@ -16819,12 +16861,12 @@ ${input.slice(result.pos)}
16819
16861
  }
16820
16862
  }
16821
16863
  if (state.tokenize) {
16822
- const result = $TOKEN("StatementDelimiter", state, StatementDelimiter$0(state) || StatementDelimiter$1(state) || StatementDelimiter$2(state));
16864
+ const result = $TOKEN("StatementDelimiter", state, StatementDelimiter$0(state) || StatementDelimiter$1(state) || StatementDelimiter$2(state) || StatementDelimiter$3(state));
16823
16865
  if (state.events)
16824
16866
  state.events.exit?.("StatementDelimiter", state, result, eventData);
16825
16867
  return result;
16826
16868
  } else {
16827
- const result = StatementDelimiter$0(state) || StatementDelimiter$1(state) || StatementDelimiter$2(state);
16869
+ const result = StatementDelimiter$0(state) || StatementDelimiter$1(state) || StatementDelimiter$2(state) || StatementDelimiter$3(state);
16828
16870
  if (state.events)
16829
16871
  state.events.exit?.("StatementDelimiter", state, result, eventData);
16830
16872
  return result;
@@ -21282,8 +21324,6 @@ ${input.slice(result.pos)}
21282
21324
  ts: true,
21283
21325
  children: $0
21284
21326
  };
21285
- if (isConst)
21286
- return ts;
21287
21327
  const names = new Set(block.properties.map((p) => p.name.name));
21288
21328
  return [
21289
21329
  ts,
@@ -23780,6 +23820,7 @@ ${input.slice(result.pos)}
23780
23820
  });
23781
23821
  }
23782
23822
  module.config = {
23823
+ autoConst: false,
23783
23824
  autoVar: false,
23784
23825
  autoLet: false,
23785
23826
  coffeeBinaryExistential: false,
package/dist/main.js CHANGED
@@ -1533,12 +1533,7 @@ var require_lib = __commonJS({
1533
1533
  ...exp,
1534
1534
  children: [...exp.children.slice(0, i), " ", id, suffix, ws, ...exp.children.slice(i)]
1535
1535
  };
1536
- return {
1537
- type: "Declaration",
1538
- decl,
1539
- children: [exp],
1540
- names: id.names
1541
- };
1536
+ return exp;
1542
1537
  }
1543
1538
  }
1544
1539
  let [splices, thisAssignments] = gatherBindingCode(id);
@@ -2105,8 +2100,7 @@ var require_lib = __commonJS({
2105
2100
  const [ws, , body] = s.children;
2106
2101
  let [, arg] = s.children;
2107
2102
  let i = 0, l = body.length;
2108
- const refDec = [];
2109
- const children = [ws, refDec];
2103
+ const children = [ws];
2110
2104
  let usingRef = null;
2111
2105
  for (i = 0; i < l; i++) {
2112
2106
  const step = body[i];
@@ -2147,9 +2141,8 @@ var require_lib = __commonJS({
2147
2141
  };
2148
2142
  break;
2149
2143
  }
2150
- children.pop();
2151
2144
  const lhs = [[
2152
- [refDec, initRef],
2145
+ [initRef],
2153
2146
  arg,
2154
2147
  [],
2155
2148
  { token: "=", children: [" = "] }
@@ -2219,7 +2212,11 @@ var require_lib = __commonJS({
2219
2212
  }
2220
2213
  }
2221
2214
  if (usingRef) {
2222
- refDec.unshift("let ", usingRef, ";");
2215
+ s.hoistDec = {
2216
+ type: "Declaration",
2217
+ children: ["let ", usingRef],
2218
+ names: []
2219
+ };
2223
2220
  }
2224
2221
  children.push(arg);
2225
2222
  addParentPointers(s, s.parent);
@@ -2237,14 +2234,16 @@ var require_lib = __commonJS({
2237
2234
  processPipelineExpressions(statements);
2238
2235
  processAssignments(statements);
2239
2236
  processPatternMatching(statements, ReservedWord);
2240
- processFunctions(statements, config);
2241
2237
  processSwitchExpressions(statements);
2242
2238
  processTryExpressions(statements);
2243
2239
  gatherRecursiveAll(statements, (n) => n.type === "IterationExpression").forEach((e) => expressionizeIteration(e));
2244
2240
  hoistRefDecs(statements);
2241
+ processFunctions(statements, config);
2245
2242
  statements.unshift(...m.prelude);
2246
2243
  if (config.autoLet) {
2247
- createLetDecs(statements, []);
2244
+ createConstLetDecs(statements, [], "let");
2245
+ } else if (config.autoConst) {
2246
+ createConstLetDecs(statements, [], "const");
2248
2247
  } else if (config.autoVar) {
2249
2248
  createVarDecs(statements, []);
2250
2249
  }
@@ -2332,7 +2331,7 @@ var require_lib = __commonJS({
2332
2331
  }
2333
2332
  scopes.pop();
2334
2333
  }
2335
- function createLetDecs(statements, scopes) {
2334
+ function createConstLetDecs(statements, scopes, letOrConst) {
2336
2335
  function findVarDecs(statements2, decs) {
2337
2336
  const declarationNames = gatherRecursive(
2338
2337
  statements2,
@@ -2369,14 +2368,14 @@ var require_lib = __commonJS({
2369
2368
  let forNode = forNodes.find((forNode2) => forNode2.block === block);
2370
2369
  if (fnNode != null) {
2371
2370
  scopes.push(new Set(fnNode.parameters.names));
2372
- createLetDecs(block.expressions, scopes);
2371
+ createConstLetDecs(block.expressions, scopes, letOrConst);
2373
2372
  scopes.pop();
2374
2373
  } else if (forNode != null) {
2375
2374
  scopes.push(new Set(forNode.declaration.names));
2376
- createLetDecs(block.expressions, scopes);
2375
+ createConstLetDecs(block.expressions, scopes, letOrConst);
2377
2376
  scopes.pop();
2378
2377
  } else
2379
- createLetDecs(block.expressions, scopes);
2378
+ createConstLetDecs(block.expressions, scopes, letOrConst);
2380
2379
  continue;
2381
2380
  }
2382
2381
  if (node.names == null)
@@ -2390,12 +2389,12 @@ var require_lib = __commonJS({
2390
2389
  let indent = statement[0];
2391
2390
  let firstIdentifier = gatherNodes(statement[1], (node) => node.type == "Identifier")[0];
2392
2391
  if (undeclaredIdentifiers.length == 1 && statement[1].type == "AssignmentExpression" && statement[1].names.length == 1 && statement[1].names[0] == undeclaredIdentifiers[0] && firstIdentifier && firstIdentifier.names == undeclaredIdentifiers[0] && gatherNodes(statement[1], (node) => node.type === "ObjectBindingPattern").length == 0)
2393
- statement[1].children.unshift(["let "]);
2392
+ statement[1].children.unshift([`${letOrConst} `]);
2394
2393
  else {
2395
2394
  let tail = "\n";
2396
2395
  if (gatherNodes(indent, (node) => node.token && node.token.endsWith("\n")).length > 0)
2397
2396
  tail = void 0;
2398
- targetStatements.push([indent, "let ", undeclaredIdentifiers.join(", "), tail]);
2397
+ targetStatements.push([indent, `let `, undeclaredIdentifiers.join(", "), tail]);
2399
2398
  }
2400
2399
  }
2401
2400
  targetStatements.push(statement);
@@ -3215,6 +3214,7 @@ ${input.slice(result.pos)}
3215
3214
  YieldTail,
3216
3215
  ArrowFunction,
3217
3216
  FatArrow,
3217
+ TrailingDeclaration,
3218
3218
  FatArrowBody,
3219
3219
  ConditionalExpression,
3220
3220
  TernaryRest,
@@ -3318,6 +3318,7 @@ ${input.slice(result.pos)}
3318
3318
  BracedBlock,
3319
3319
  NoPostfixBracedBlock,
3320
3320
  NonSingleBracedBlock,
3321
+ DeclarationOrStatement,
3321
3322
  SingleLineStatements,
3322
3323
  PostfixedSingleLineStatements,
3323
3324
  BracedContent,
@@ -5539,7 +5540,30 @@ ${input.slice(result.pos)}
5539
5540
  return result;
5540
5541
  }
5541
5542
  }
5542
- var FatArrowBody$0 = $T($S($N(EOS), NonPipelinePostfixedExpression, $N(SemicolonDelimiter)), function(value) {
5543
+ var TrailingDeclaration$0 = $S($Q(_), $C(ConstAssignment, LetAssignment));
5544
+ function TrailingDeclaration(state) {
5545
+ let eventData;
5546
+ if (state.events) {
5547
+ const result = state.events.enter?.("TrailingDeclaration", state);
5548
+ if (result) {
5549
+ if ("cache" in result)
5550
+ return result.cache;
5551
+ eventData = result.data;
5552
+ }
5553
+ }
5554
+ if (state.tokenize) {
5555
+ const result = $TOKEN("TrailingDeclaration", state, TrailingDeclaration$0(state));
5556
+ if (state.events)
5557
+ state.events.exit?.("TrailingDeclaration", state, result, eventData);
5558
+ return result;
5559
+ } else {
5560
+ const result = TrailingDeclaration$0(state);
5561
+ if (state.events)
5562
+ state.events.exit?.("TrailingDeclaration", state, result, eventData);
5563
+ return result;
5564
+ }
5565
+ }
5566
+ var FatArrowBody$0 = $T($S($N(EOS), NonPipelinePostfixedExpression, $N(TrailingDeclaration), $N(SemicolonDelimiter)), function(value) {
5543
5567
  var exp = value[1];
5544
5568
  return exp;
5545
5569
  });
@@ -9013,7 +9037,31 @@ ${input.slice(result.pos)}
9013
9037
  return result;
9014
9038
  }
9015
9039
  }
9016
- var SingleLineStatements$0 = $TS($S(ForbidNewlineBinaryOp, $Q($S($S($E(_), $N(EOS)), Statement, SemicolonDelimiter)), $E($S($S($E(_), $N(EOS)), Statement, $E(SemicolonDelimiter))), RestoreNewlineBinaryOp), function($skip, $loc, $0, $1, $2, $3, $4) {
9040
+ var DeclarationOrStatement$0 = Declaration;
9041
+ var DeclarationOrStatement$1 = Statement;
9042
+ function DeclarationOrStatement(state) {
9043
+ let eventData;
9044
+ if (state.events) {
9045
+ const result = state.events.enter?.("DeclarationOrStatement", state);
9046
+ if (result) {
9047
+ if ("cache" in result)
9048
+ return result.cache;
9049
+ eventData = result.data;
9050
+ }
9051
+ }
9052
+ if (state.tokenize) {
9053
+ const result = $TOKEN("DeclarationOrStatement", state, DeclarationOrStatement$0(state) || DeclarationOrStatement$1(state));
9054
+ if (state.events)
9055
+ state.events.exit?.("DeclarationOrStatement", state, result, eventData);
9056
+ return result;
9057
+ } else {
9058
+ const result = DeclarationOrStatement$0(state) || DeclarationOrStatement$1(state);
9059
+ if (state.events)
9060
+ state.events.exit?.("DeclarationOrStatement", state, result, eventData);
9061
+ return result;
9062
+ }
9063
+ }
9064
+ var SingleLineStatements$0 = $TS($S(ForbidNewlineBinaryOp, $Q($S($S($E(_), $N(EOS)), DeclarationOrStatement, SemicolonDelimiter)), $E($S($S($E(_), $N(EOS)), DeclarationOrStatement, $E(SemicolonDelimiter))), RestoreNewlineBinaryOp), function($skip, $loc, $0, $1, $2, $3, $4) {
9017
9065
  var stmts = $2;
9018
9066
  var last = $3;
9019
9067
  const expressions = [...stmts];
@@ -9048,7 +9096,7 @@ ${input.slice(result.pos)}
9048
9096
  return result;
9049
9097
  }
9050
9098
  }
9051
- var PostfixedSingleLineStatements$0 = $TS($S($Q($S($S($E(_), $N(EOS)), PostfixedStatement, SemicolonDelimiter)), $E($S($S($E(_), $N(EOS)), PostfixedStatement, $E(SemicolonDelimiter)))), function($skip, $loc, $0, $1, $2) {
9099
+ var PostfixedSingleLineStatements$0 = $TS($S($Q($S($S($E(_), $N(EOS)), StatementListItem, SemicolonDelimiter)), $E($S($S($E(_), $N(EOS)), StatementListItem, $E(SemicolonDelimiter)))), function($skip, $loc, $0, $1, $2) {
9052
9100
  var stmts = $1;
9053
9101
  var last = $2;
9054
9102
  const children = [...stmts];
@@ -9084,14 +9132,7 @@ ${input.slice(result.pos)}
9084
9132
  }
9085
9133
  }
9086
9134
  var BracedContent$0 = NestedBlockStatements;
9087
- var BracedContent$1 = $TS($S($E(_), Statement), function($skip, $loc, $0, $1, $2) {
9088
- const expressions = [["", $2]];
9089
- return {
9090
- type: "BlockStatement",
9091
- expressions,
9092
- children: [$1, expressions]
9093
- };
9094
- });
9135
+ var BracedContent$1 = SingleLineStatements;
9095
9136
  var BracedContent$2 = $TV($Y($S(__, $EXPECT($L24, fail, 'BracedContent "}"'))), function($skip, $loc, $0, $1) {
9096
9137
  const expressions = [];
9097
9138
  return {
@@ -16807,6 +16848,7 @@ ${input.slice(result.pos)}
16807
16848
  var StatementDelimiter$0 = SemicolonDelimiter;
16808
16849
  var StatementDelimiter$1 = $S($Y($S(Nested, $C($EXPECT($L4, fail, 'StatementDelimiter "("'), $EXPECT($L111, fail, 'StatementDelimiter "["'), $EXPECT($L112, fail, 'StatementDelimiter "`"'), $EXPECT($L57, fail, 'StatementDelimiter "+"'), $EXPECT($L18, fail, 'StatementDelimiter "-"'), $EXPECT($L53, fail, 'StatementDelimiter "*"'), $EXPECT($L54, fail, 'StatementDelimiter "/"'), ObjectLiteral, Arrow, FatArrow, $S(Function, $E($S($E(_), Star)), $E(_), $EXPECT($L4, fail, 'StatementDelimiter "("'))))), InsertSemicolon);
16809
16850
  var StatementDelimiter$2 = $Y(EOS);
16851
+ var StatementDelimiter$3 = $Y($S($Q(_), $EXPECT($L24, fail, 'StatementDelimiter "}"')));
16810
16852
  function StatementDelimiter(state) {
16811
16853
  let eventData;
16812
16854
  if (state.events) {
@@ -16818,12 +16860,12 @@ ${input.slice(result.pos)}
16818
16860
  }
16819
16861
  }
16820
16862
  if (state.tokenize) {
16821
- const result = $TOKEN("StatementDelimiter", state, StatementDelimiter$0(state) || StatementDelimiter$1(state) || StatementDelimiter$2(state));
16863
+ const result = $TOKEN("StatementDelimiter", state, StatementDelimiter$0(state) || StatementDelimiter$1(state) || StatementDelimiter$2(state) || StatementDelimiter$3(state));
16822
16864
  if (state.events)
16823
16865
  state.events.exit?.("StatementDelimiter", state, result, eventData);
16824
16866
  return result;
16825
16867
  } else {
16826
- const result = StatementDelimiter$0(state) || StatementDelimiter$1(state) || StatementDelimiter$2(state);
16868
+ const result = StatementDelimiter$0(state) || StatementDelimiter$1(state) || StatementDelimiter$2(state) || StatementDelimiter$3(state);
16827
16869
  if (state.events)
16828
16870
  state.events.exit?.("StatementDelimiter", state, result, eventData);
16829
16871
  return result;
@@ -21281,8 +21323,6 @@ ${input.slice(result.pos)}
21281
21323
  ts: true,
21282
21324
  children: $0
21283
21325
  };
21284
- if (isConst)
21285
- return ts;
21286
21326
  const names = new Set(block.properties.map((p) => p.name.name));
21287
21327
  return [
21288
21328
  ts,
@@ -23779,6 +23819,7 @@ ${input.slice(result.pos)}
23779
23819
  });
23780
23820
  }
23781
23821
  module2.config = {
23822
+ autoConst: false,
23782
23823
  autoVar: false,
23783
23824
  autoLet: false,
23784
23825
  coffeeBinaryExistential: false,
package/dist/main.mjs CHANGED
@@ -1531,12 +1531,7 @@ var require_lib = __commonJS({
1531
1531
  ...exp,
1532
1532
  children: [...exp.children.slice(0, i), " ", id, suffix, ws, ...exp.children.slice(i)]
1533
1533
  };
1534
- return {
1535
- type: "Declaration",
1536
- decl,
1537
- children: [exp],
1538
- names: id.names
1539
- };
1534
+ return exp;
1540
1535
  }
1541
1536
  }
1542
1537
  let [splices, thisAssignments] = gatherBindingCode(id);
@@ -2103,8 +2098,7 @@ var require_lib = __commonJS({
2103
2098
  const [ws, , body] = s.children;
2104
2099
  let [, arg] = s.children;
2105
2100
  let i = 0, l = body.length;
2106
- const refDec = [];
2107
- const children = [ws, refDec];
2101
+ const children = [ws];
2108
2102
  let usingRef = null;
2109
2103
  for (i = 0; i < l; i++) {
2110
2104
  const step = body[i];
@@ -2145,9 +2139,8 @@ var require_lib = __commonJS({
2145
2139
  };
2146
2140
  break;
2147
2141
  }
2148
- children.pop();
2149
2142
  const lhs = [[
2150
- [refDec, initRef],
2143
+ [initRef],
2151
2144
  arg,
2152
2145
  [],
2153
2146
  { token: "=", children: [" = "] }
@@ -2217,7 +2210,11 @@ var require_lib = __commonJS({
2217
2210
  }
2218
2211
  }
2219
2212
  if (usingRef) {
2220
- refDec.unshift("let ", usingRef, ";");
2213
+ s.hoistDec = {
2214
+ type: "Declaration",
2215
+ children: ["let ", usingRef],
2216
+ names: []
2217
+ };
2221
2218
  }
2222
2219
  children.push(arg);
2223
2220
  addParentPointers(s, s.parent);
@@ -2235,14 +2232,16 @@ var require_lib = __commonJS({
2235
2232
  processPipelineExpressions(statements);
2236
2233
  processAssignments(statements);
2237
2234
  processPatternMatching(statements, ReservedWord);
2238
- processFunctions(statements, config);
2239
2235
  processSwitchExpressions(statements);
2240
2236
  processTryExpressions(statements);
2241
2237
  gatherRecursiveAll(statements, (n) => n.type === "IterationExpression").forEach((e) => expressionizeIteration(e));
2242
2238
  hoistRefDecs(statements);
2239
+ processFunctions(statements, config);
2243
2240
  statements.unshift(...m.prelude);
2244
2241
  if (config.autoLet) {
2245
- createLetDecs(statements, []);
2242
+ createConstLetDecs(statements, [], "let");
2243
+ } else if (config.autoConst) {
2244
+ createConstLetDecs(statements, [], "const");
2246
2245
  } else if (config.autoVar) {
2247
2246
  createVarDecs(statements, []);
2248
2247
  }
@@ -2330,7 +2329,7 @@ var require_lib = __commonJS({
2330
2329
  }
2331
2330
  scopes.pop();
2332
2331
  }
2333
- function createLetDecs(statements, scopes) {
2332
+ function createConstLetDecs(statements, scopes, letOrConst) {
2334
2333
  function findVarDecs(statements2, decs) {
2335
2334
  const declarationNames = gatherRecursive(
2336
2335
  statements2,
@@ -2367,14 +2366,14 @@ var require_lib = __commonJS({
2367
2366
  let forNode = forNodes.find((forNode2) => forNode2.block === block);
2368
2367
  if (fnNode != null) {
2369
2368
  scopes.push(new Set(fnNode.parameters.names));
2370
- createLetDecs(block.expressions, scopes);
2369
+ createConstLetDecs(block.expressions, scopes, letOrConst);
2371
2370
  scopes.pop();
2372
2371
  } else if (forNode != null) {
2373
2372
  scopes.push(new Set(forNode.declaration.names));
2374
- createLetDecs(block.expressions, scopes);
2373
+ createConstLetDecs(block.expressions, scopes, letOrConst);
2375
2374
  scopes.pop();
2376
2375
  } else
2377
- createLetDecs(block.expressions, scopes);
2376
+ createConstLetDecs(block.expressions, scopes, letOrConst);
2378
2377
  continue;
2379
2378
  }
2380
2379
  if (node.names == null)
@@ -2388,12 +2387,12 @@ var require_lib = __commonJS({
2388
2387
  let indent = statement[0];
2389
2388
  let firstIdentifier = gatherNodes(statement[1], (node) => node.type == "Identifier")[0];
2390
2389
  if (undeclaredIdentifiers.length == 1 && statement[1].type == "AssignmentExpression" && statement[1].names.length == 1 && statement[1].names[0] == undeclaredIdentifiers[0] && firstIdentifier && firstIdentifier.names == undeclaredIdentifiers[0] && gatherNodes(statement[1], (node) => node.type === "ObjectBindingPattern").length == 0)
2391
- statement[1].children.unshift(["let "]);
2390
+ statement[1].children.unshift([`${letOrConst} `]);
2392
2391
  else {
2393
2392
  let tail = "\n";
2394
2393
  if (gatherNodes(indent, (node) => node.token && node.token.endsWith("\n")).length > 0)
2395
2394
  tail = void 0;
2396
- targetStatements.push([indent, "let ", undeclaredIdentifiers.join(", "), tail]);
2395
+ targetStatements.push([indent, `let `, undeclaredIdentifiers.join(", "), tail]);
2397
2396
  }
2398
2397
  }
2399
2398
  targetStatements.push(statement);
@@ -3213,6 +3212,7 @@ ${input.slice(result.pos)}
3213
3212
  YieldTail,
3214
3213
  ArrowFunction,
3215
3214
  FatArrow,
3215
+ TrailingDeclaration,
3216
3216
  FatArrowBody,
3217
3217
  ConditionalExpression,
3218
3218
  TernaryRest,
@@ -3316,6 +3316,7 @@ ${input.slice(result.pos)}
3316
3316
  BracedBlock,
3317
3317
  NoPostfixBracedBlock,
3318
3318
  NonSingleBracedBlock,
3319
+ DeclarationOrStatement,
3319
3320
  SingleLineStatements,
3320
3321
  PostfixedSingleLineStatements,
3321
3322
  BracedContent,
@@ -5537,7 +5538,30 @@ ${input.slice(result.pos)}
5537
5538
  return result;
5538
5539
  }
5539
5540
  }
5540
- var FatArrowBody$0 = $T($S($N(EOS), NonPipelinePostfixedExpression, $N(SemicolonDelimiter)), function(value) {
5541
+ var TrailingDeclaration$0 = $S($Q(_), $C(ConstAssignment, LetAssignment));
5542
+ function TrailingDeclaration(state) {
5543
+ let eventData;
5544
+ if (state.events) {
5545
+ const result = state.events.enter?.("TrailingDeclaration", state);
5546
+ if (result) {
5547
+ if ("cache" in result)
5548
+ return result.cache;
5549
+ eventData = result.data;
5550
+ }
5551
+ }
5552
+ if (state.tokenize) {
5553
+ const result = $TOKEN("TrailingDeclaration", state, TrailingDeclaration$0(state));
5554
+ if (state.events)
5555
+ state.events.exit?.("TrailingDeclaration", state, result, eventData);
5556
+ return result;
5557
+ } else {
5558
+ const result = TrailingDeclaration$0(state);
5559
+ if (state.events)
5560
+ state.events.exit?.("TrailingDeclaration", state, result, eventData);
5561
+ return result;
5562
+ }
5563
+ }
5564
+ var FatArrowBody$0 = $T($S($N(EOS), NonPipelinePostfixedExpression, $N(TrailingDeclaration), $N(SemicolonDelimiter)), function(value) {
5541
5565
  var exp = value[1];
5542
5566
  return exp;
5543
5567
  });
@@ -9011,7 +9035,31 @@ ${input.slice(result.pos)}
9011
9035
  return result;
9012
9036
  }
9013
9037
  }
9014
- var SingleLineStatements$0 = $TS($S(ForbidNewlineBinaryOp, $Q($S($S($E(_), $N(EOS)), Statement, SemicolonDelimiter)), $E($S($S($E(_), $N(EOS)), Statement, $E(SemicolonDelimiter))), RestoreNewlineBinaryOp), function($skip, $loc, $0, $1, $2, $3, $4) {
9038
+ var DeclarationOrStatement$0 = Declaration;
9039
+ var DeclarationOrStatement$1 = Statement;
9040
+ function DeclarationOrStatement(state) {
9041
+ let eventData;
9042
+ if (state.events) {
9043
+ const result = state.events.enter?.("DeclarationOrStatement", state);
9044
+ if (result) {
9045
+ if ("cache" in result)
9046
+ return result.cache;
9047
+ eventData = result.data;
9048
+ }
9049
+ }
9050
+ if (state.tokenize) {
9051
+ const result = $TOKEN("DeclarationOrStatement", state, DeclarationOrStatement$0(state) || DeclarationOrStatement$1(state));
9052
+ if (state.events)
9053
+ state.events.exit?.("DeclarationOrStatement", state, result, eventData);
9054
+ return result;
9055
+ } else {
9056
+ const result = DeclarationOrStatement$0(state) || DeclarationOrStatement$1(state);
9057
+ if (state.events)
9058
+ state.events.exit?.("DeclarationOrStatement", state, result, eventData);
9059
+ return result;
9060
+ }
9061
+ }
9062
+ var SingleLineStatements$0 = $TS($S(ForbidNewlineBinaryOp, $Q($S($S($E(_), $N(EOS)), DeclarationOrStatement, SemicolonDelimiter)), $E($S($S($E(_), $N(EOS)), DeclarationOrStatement, $E(SemicolonDelimiter))), RestoreNewlineBinaryOp), function($skip, $loc, $0, $1, $2, $3, $4) {
9015
9063
  var stmts = $2;
9016
9064
  var last = $3;
9017
9065
  const expressions = [...stmts];
@@ -9046,7 +9094,7 @@ ${input.slice(result.pos)}
9046
9094
  return result;
9047
9095
  }
9048
9096
  }
9049
- var PostfixedSingleLineStatements$0 = $TS($S($Q($S($S($E(_), $N(EOS)), PostfixedStatement, SemicolonDelimiter)), $E($S($S($E(_), $N(EOS)), PostfixedStatement, $E(SemicolonDelimiter)))), function($skip, $loc, $0, $1, $2) {
9097
+ var PostfixedSingleLineStatements$0 = $TS($S($Q($S($S($E(_), $N(EOS)), StatementListItem, SemicolonDelimiter)), $E($S($S($E(_), $N(EOS)), StatementListItem, $E(SemicolonDelimiter)))), function($skip, $loc, $0, $1, $2) {
9050
9098
  var stmts = $1;
9051
9099
  var last = $2;
9052
9100
  const children = [...stmts];
@@ -9082,14 +9130,7 @@ ${input.slice(result.pos)}
9082
9130
  }
9083
9131
  }
9084
9132
  var BracedContent$0 = NestedBlockStatements;
9085
- var BracedContent$1 = $TS($S($E(_), Statement), function($skip, $loc, $0, $1, $2) {
9086
- const expressions = [["", $2]];
9087
- return {
9088
- type: "BlockStatement",
9089
- expressions,
9090
- children: [$1, expressions]
9091
- };
9092
- });
9133
+ var BracedContent$1 = SingleLineStatements;
9093
9134
  var BracedContent$2 = $TV($Y($S(__, $EXPECT($L24, fail, 'BracedContent "}"'))), function($skip, $loc, $0, $1) {
9094
9135
  const expressions = [];
9095
9136
  return {
@@ -16805,6 +16846,7 @@ ${input.slice(result.pos)}
16805
16846
  var StatementDelimiter$0 = SemicolonDelimiter;
16806
16847
  var StatementDelimiter$1 = $S($Y($S(Nested, $C($EXPECT($L4, fail, 'StatementDelimiter "("'), $EXPECT($L111, fail, 'StatementDelimiter "["'), $EXPECT($L112, fail, 'StatementDelimiter "`"'), $EXPECT($L57, fail, 'StatementDelimiter "+"'), $EXPECT($L18, fail, 'StatementDelimiter "-"'), $EXPECT($L53, fail, 'StatementDelimiter "*"'), $EXPECT($L54, fail, 'StatementDelimiter "/"'), ObjectLiteral, Arrow, FatArrow, $S(Function, $E($S($E(_), Star)), $E(_), $EXPECT($L4, fail, 'StatementDelimiter "("'))))), InsertSemicolon);
16807
16848
  var StatementDelimiter$2 = $Y(EOS);
16849
+ var StatementDelimiter$3 = $Y($S($Q(_), $EXPECT($L24, fail, 'StatementDelimiter "}"')));
16808
16850
  function StatementDelimiter(state) {
16809
16851
  let eventData;
16810
16852
  if (state.events) {
@@ -16816,12 +16858,12 @@ ${input.slice(result.pos)}
16816
16858
  }
16817
16859
  }
16818
16860
  if (state.tokenize) {
16819
- const result = $TOKEN("StatementDelimiter", state, StatementDelimiter$0(state) || StatementDelimiter$1(state) || StatementDelimiter$2(state));
16861
+ const result = $TOKEN("StatementDelimiter", state, StatementDelimiter$0(state) || StatementDelimiter$1(state) || StatementDelimiter$2(state) || StatementDelimiter$3(state));
16820
16862
  if (state.events)
16821
16863
  state.events.exit?.("StatementDelimiter", state, result, eventData);
16822
16864
  return result;
16823
16865
  } else {
16824
- const result = StatementDelimiter$0(state) || StatementDelimiter$1(state) || StatementDelimiter$2(state);
16866
+ const result = StatementDelimiter$0(state) || StatementDelimiter$1(state) || StatementDelimiter$2(state) || StatementDelimiter$3(state);
16825
16867
  if (state.events)
16826
16868
  state.events.exit?.("StatementDelimiter", state, result, eventData);
16827
16869
  return result;
@@ -21279,8 +21321,6 @@ ${input.slice(result.pos)}
21279
21321
  ts: true,
21280
21322
  children: $0
21281
21323
  };
21282
- if (isConst)
21283
- return ts;
21284
21324
  const names = new Set(block.properties.map((p) => p.name.name));
21285
21325
  return [
21286
21326
  ts,
@@ -23777,6 +23817,7 @@ ${input.slice(result.pos)}
23777
23817
  });
23778
23818
  }
23779
23819
  module.config = {
23820
+ autoConst: false,
23780
23821
  autoVar: false,
23781
23822
  autoLet: false,
23782
23823
  coffeeBinaryExistential: false,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@danielx/civet",
3
- "version": "0.6.24",
3
+ "version": "0.6.26",
4
4
  "description": "CoffeeScript style syntax for TypeScript",
5
5
  "main": "dist/main.js",
6
6
  "module": "dist/main.mjs",
@@ -9,9 +9,10 @@
9
9
  "import": "./dist/main.mjs",
10
10
  "require": "./dist/main.js"
11
11
  },
12
+ "./babel-plugin": "./dist/babel-plugin.mjs",
13
+ "./bun-civet": "./dist/bun-civet.mjs",
12
14
  "./esm": "./dist/esm.mjs",
13
15
  "./esbuild-plugin": "./dist/esbuild-plugin.js",
14
- "./bun-civet": "./dist/bun-civet.mjs",
15
16
  "./register": "./register.js",
16
17
  "./config": "./dist/config.js",
17
18
  "./*": "./*",