@danielx/civet 0.6.7 → 0.6.9

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.
@@ -0,0 +1,24 @@
1
+ import { compile } from "./main.mjs"
2
+
3
+ export default function (api, civetOptions) {
4
+ return {
5
+ parserOverride(code, opts, parse) {
6
+ let src
7
+ if (opts.sourceFileName.endsWith(".civet")) {
8
+ const config = Object.assign({}, civetOptions, {
9
+ filename: opts.sourceFileName,
10
+ sourceMap: false,
11
+ })
12
+
13
+ config.inlineMap ??= true
14
+ config.js = true
15
+ src = compile(code, config)
16
+ } else {
17
+ src = code
18
+ }
19
+
20
+ const ast = parse(src, opts)
21
+ return ast
22
+ }
23
+ }
24
+ }
package/dist/browser.js CHANGED
@@ -798,13 +798,14 @@ var Civet = (() => {
798
798
  }
799
799
  function hoistRefDecs(statements) {
800
800
  gatherRecursiveAll(statements, (s) => s.hoistDec).forEach((node) => {
801
- const { hoistDec } = node;
801
+ let { hoistDec, parent } = node;
802
802
  node.hoistDec = null;
803
- while (node.parent?.type !== "BlockStatement") {
804
- node = node.parent;
803
+ while (parent?.type !== "BlockStatement" || parent.bare && !parent.root) {
804
+ node = parent;
805
+ parent = node.parent;
805
806
  }
806
- if (node.parent) {
807
- insertHoistDec(node.parent, node, hoistDec);
807
+ if (parent) {
808
+ insertHoistDec(parent, node, hoistDec);
808
809
  } else {
809
810
  throw new Error("Couldn't find block to hoist declaration into.");
810
811
  }
@@ -1331,8 +1332,27 @@ var Civet = (() => {
1331
1332
  thisAssignments
1332
1333
  };
1333
1334
  }
1335
+ function implicitFunctionBlock(f) {
1336
+ if (f.abstract || f.block)
1337
+ return;
1338
+ const { name, parent } = f;
1339
+ const expressions = parent?.expressions ?? parent?.elements;
1340
+ const currentIndex = expressions?.findIndex(([, def]) => def === f);
1341
+ const following = currentIndex >= 0 && expressions[currentIndex + 1]?.[1];
1342
+ if (f.type === following?.type && name && name === following.name) {
1343
+ f.ts = true;
1344
+ } else {
1345
+ const block = makeEmptyBlock();
1346
+ block.parent = f;
1347
+ f.block = block;
1348
+ f.children.push(block);
1349
+ f.ts = false;
1350
+ }
1351
+ }
1334
1352
  function processFunctions(statements, config) {
1335
1353
  gatherRecursiveAll(statements, ({ type }) => type === "FunctionExpression" || type === "ArrowFunction").forEach((f) => {
1354
+ if (f.type === "FunctionExpression")
1355
+ implicitFunctionBlock(f);
1336
1356
  processParams(f);
1337
1357
  if (!processReturnValue(f) && config.implicitReturns) {
1338
1358
  const { block, returnType } = f;
@@ -1344,25 +1364,15 @@ var Civet = (() => {
1344
1364
  }
1345
1365
  });
1346
1366
  gatherRecursiveAll(statements, ({ type }) => type === "MethodDefinition").forEach((f) => {
1347
- const { abstract, block, signature } = f;
1348
- if (!abstract && !block) {
1349
- const { name } = signature, { parent } = f, { elements } = parent, currentIndex = elements.findIndex(([, def]) => def === f);
1350
- const following = elements[currentIndex + 1]?.[1];
1351
- if (following?.signature?.name !== name) {
1352
- const block2 = makeEmptyBlock();
1353
- block2.parent = f;
1354
- f.block = block2;
1355
- f.children.push(block2);
1356
- }
1357
- }
1367
+ implicitFunctionBlock(f);
1358
1368
  processParams(f);
1359
1369
  if (!processReturnValue(f) && config.implicitReturns) {
1360
- const { signature: signature2, block: block2 } = f;
1361
- const isConstructor = signature2.name === "constructor";
1362
- const isVoid = isVoidType(signature2.returnType?.t);
1363
- const isSet = signature2.modifier?.set;
1370
+ const { signature, block } = f;
1371
+ const isConstructor = signature.name === "constructor";
1372
+ const isVoid = isVoidType(signature.returnType?.t);
1373
+ const isSet = signature.modifier?.set;
1364
1374
  if (!isConstructor && !isSet && !isVoid) {
1365
- insertReturn(block2);
1375
+ insertReturn(block);
1366
1376
  }
1367
1377
  }
1368
1378
  });
@@ -3457,6 +3467,7 @@ ${input.slice(result.pos)}
3457
3467
  NestedEnumProperties,
3458
3468
  NestedEnumProperty,
3459
3469
  EnumProperty,
3470
+ TypeProperty,
3460
3471
  TypeIndexSignature,
3461
3472
  TypeIndex,
3462
3473
  TypeSuffix,
@@ -4256,10 +4267,9 @@ ${input.slice(result.pos)}
4256
4267
  }
4257
4268
  var ForbiddenImplicitCalls$0 = $R$0($EXPECT($R0, fail, "ForbiddenImplicitCalls /(as|of|satisfies|then|when|implements|xor|xnor)(?!\\p{ID_Continue}|[\\u200C\\u200D$])/"));
4258
4269
  var ForbiddenImplicitCalls$1 = $EXPECT($L1, fail, 'ForbiddenImplicitCalls "/ "');
4259
- var ForbiddenImplicitCalls$2 = $S(ClassImplicitCallForbidden, Class);
4260
- var ForbiddenImplicitCalls$3 = AtAt;
4261
- var ForbiddenImplicitCalls$4 = $S(Identifier, $EXPECT($L2, fail, 'ForbiddenImplicitCalls "="'), Whitespace);
4262
- var ForbiddenImplicitCalls$5 = $TS($S(Identifier, $N($EXPECT($L3, fail, 'ForbiddenImplicitCalls "("'))), function($skip, $loc, $0, $1, $2) {
4270
+ var ForbiddenImplicitCalls$2 = $S(ClassImplicitCallForbidden, $C(Class, AtAt));
4271
+ var ForbiddenImplicitCalls$3 = $S(Identifier, $EXPECT($L2, fail, 'ForbiddenImplicitCalls "="'), Whitespace);
4272
+ var ForbiddenImplicitCalls$4 = $TS($S(Identifier, $N($EXPECT($L3, fail, 'ForbiddenImplicitCalls "("'))), function($skip, $loc, $0, $1, $2) {
4263
4273
  if (module.operators.has($1.name))
4264
4274
  return $1;
4265
4275
  return $skip;
@@ -4275,12 +4285,12 @@ ${input.slice(result.pos)}
4275
4285
  }
4276
4286
  }
4277
4287
  if (state.tokenize) {
4278
- const result = $TOKEN("ForbiddenImplicitCalls", state, ForbiddenImplicitCalls$0(state) || ForbiddenImplicitCalls$1(state) || ForbiddenImplicitCalls$2(state) || ForbiddenImplicitCalls$3(state) || ForbiddenImplicitCalls$4(state) || ForbiddenImplicitCalls$5(state));
4288
+ const result = $TOKEN("ForbiddenImplicitCalls", state, ForbiddenImplicitCalls$0(state) || ForbiddenImplicitCalls$1(state) || ForbiddenImplicitCalls$2(state) || ForbiddenImplicitCalls$3(state) || ForbiddenImplicitCalls$4(state));
4279
4289
  if (state.events)
4280
4290
  state.events.exit?.("ForbiddenImplicitCalls", state, result, eventData);
4281
4291
  return result;
4282
4292
  } else {
4283
- const result = ForbiddenImplicitCalls$0(state) || ForbiddenImplicitCalls$1(state) || ForbiddenImplicitCalls$2(state) || ForbiddenImplicitCalls$3(state) || ForbiddenImplicitCalls$4(state) || ForbiddenImplicitCalls$5(state);
4293
+ const result = ForbiddenImplicitCalls$0(state) || ForbiddenImplicitCalls$1(state) || ForbiddenImplicitCalls$2(state) || ForbiddenImplicitCalls$3(state) || ForbiddenImplicitCalls$4(state);
4284
4294
  if (state.events)
4285
4295
  state.events.exit?.("ForbiddenImplicitCalls", state, result, eventData);
4286
4296
  return result;
@@ -5984,7 +5994,7 @@ ${input.slice(result.pos)}
5984
5994
  return result;
5985
5995
  }
5986
5996
  }
5987
- var AccessModifier$0 = $TS($S($E($S($C(Public, Private, Protected), __)), $E($S(Readonly, __))), function($skip, $loc, $0, $1, $2) {
5997
+ var AccessModifier$0 = $TS($S($E($S($C(Public, Private, Protected), NotDedented)), $E($S(Readonly, NotDedented))), function($skip, $loc, $0, $1, $2) {
5988
5998
  if (!($1 || $2))
5989
5999
  return $skip;
5990
6000
  return {
@@ -7740,9 +7750,11 @@ ${input.slice(result.pos)}
7740
7750
  async = [];
7741
7751
  if (!generator)
7742
7752
  generator = [];
7753
+ const id = wid?.[1];
7743
7754
  return {
7744
7755
  type: "FunctionSignature",
7745
- id: wid?.[1],
7756
+ id,
7757
+ name: id?.name,
7746
7758
  parameters,
7747
7759
  returnType: suffix,
7748
7760
  ts: false,
@@ -7778,8 +7790,11 @@ ${input.slice(result.pos)}
7778
7790
  var signature = $1;
7779
7791
  var block = $2;
7780
7792
  if (!block) {
7781
- signature.ts = true;
7782
- return signature;
7793
+ return {
7794
+ ...signature,
7795
+ type: "FunctionExpression",
7796
+ ts: true
7797
+ };
7783
7798
  }
7784
7799
  if (hasAwait(block) && !signature.async.length) {
7785
7800
  signature.async.push("async ");
@@ -13047,7 +13062,7 @@ ${input.slice(result.pos)}
13047
13062
  }
13048
13063
  }
13049
13064
  var ForbidClassImplicitCall$0 = $TV($EXPECT($L0, fail, 'ForbidClassImplicitCall ""'), function($skip, $loc, $0, $1) {
13050
- module.forbidIndentedApplication.push(true);
13065
+ module.forbidClassImplicitCall.push(true);
13051
13066
  });
13052
13067
  function ForbidClassImplicitCall(state) {
13053
13068
  let eventData;
@@ -13072,7 +13087,7 @@ ${input.slice(result.pos)}
13072
13087
  }
13073
13088
  }
13074
13089
  var AllowClassImplicitCall$0 = $TV($EXPECT($L0, fail, 'AllowClassImplicitCall ""'), function($skip, $loc, $0, $1) {
13075
- module.forbidIndentedApplication.push(false);
13090
+ module.forbidClassImplicitCall.push(false);
13076
13091
  });
13077
13092
  function AllowClassImplicitCall(state) {
13078
13093
  let eventData;
@@ -13097,7 +13112,7 @@ ${input.slice(result.pos)}
13097
13112
  }
13098
13113
  }
13099
13114
  var RestoreClassImplicitCall$0 = $TV($EXPECT($L0, fail, 'RestoreClassImplicitCall ""'), function($skip, $loc, $0, $1) {
13100
- module.forbidIndentedApplication.pop();
13115
+ module.forbidClassImplicitCall.pop();
13101
13116
  });
13102
13117
  function RestoreClassImplicitCall(state) {
13103
13118
  let eventData;
@@ -13122,7 +13137,7 @@ ${input.slice(result.pos)}
13122
13137
  }
13123
13138
  }
13124
13139
  var ClassImplicitCallForbidden$0 = $TV($EXPECT($L0, fail, 'ClassImplicitCallForbidden ""'), function($skip, $loc, $0, $1) {
13125
- if (module.classImplicitCallForbidden)
13140
+ if (!module.classImplicitCallForbidden)
13126
13141
  return $skip;
13127
13142
  return;
13128
13143
  });
@@ -20331,7 +20346,7 @@ ${input.slice(result.pos)}
20331
20346
  return result;
20332
20347
  }
20333
20348
  }
20334
- var BasicInterfaceProperty$0 = $S($C(TypeIndexSignature, PropertyName), TypeSuffix, InterfacePropertyDelimiter);
20349
+ var BasicInterfaceProperty$0 = $S($C(TypeIndexSignature, TypeProperty), $E(_), TypeSuffix, InterfacePropertyDelimiter);
20335
20350
  function BasicInterfaceProperty(state) {
20336
20351
  let eventData;
20337
20352
  if (state.events) {
@@ -20772,7 +20787,30 @@ ${input.slice(result.pos)}
20772
20787
  return result;
20773
20788
  }
20774
20789
  }
20775
- var TypeIndexSignature$0 = $S($E($S($R$0($EXPECT($R58, fail, "TypeIndexSignature /[+-]?/")), $EXPECT($L141, fail, 'TypeIndexSignature "readonly"'), __)), OpenBracket, TypeIndex, CloseBracket, $E($S(__, $R$0($EXPECT($R59, fail, "TypeIndexSignature /[+-]/")), QuestionMark)));
20790
+ var TypeProperty$0 = $S($E($S(Readonly, NotDedented)), PropertyName);
20791
+ function TypeProperty(state) {
20792
+ let eventData;
20793
+ if (state.events) {
20794
+ const result = state.events.enter?.("TypeProperty", state);
20795
+ if (result) {
20796
+ if (result.cache)
20797
+ return result.cache;
20798
+ eventData = result.data;
20799
+ }
20800
+ }
20801
+ if (state.tokenize) {
20802
+ const result = $TOKEN("TypeProperty", state, TypeProperty$0(state));
20803
+ if (state.events)
20804
+ state.events.exit?.("TypeProperty", state, result, eventData);
20805
+ return result;
20806
+ } else {
20807
+ const result = TypeProperty$0(state);
20808
+ if (state.events)
20809
+ state.events.exit?.("TypeProperty", state, result, eventData);
20810
+ return result;
20811
+ }
20812
+ }
20813
+ var TypeIndexSignature$0 = $S($E($S($R$0($EXPECT($R58, fail, "TypeIndexSignature /[+-]?/")), Readonly, NotDedented)), OpenBracket, TypeIndex, CloseBracket, $E($S(__, $R$0($EXPECT($R59, fail, "TypeIndexSignature /[+-]/")), $Y($S($E(_), QuestionMark)))));
20776
20814
  function TypeIndexSignature(state) {
20777
20815
  let eventData;
20778
20816
  if (state.events) {
@@ -21456,7 +21494,7 @@ ${input.slice(result.pos)}
21456
21494
  return result;
21457
21495
  }
21458
21496
  }
21459
- var InlineBasicInterfaceProperty$0 = $S($C(TypeIndexSignature, PropertyName), $E(QuestionMark), Colon, Type, InlineInterfacePropertyDelimiter);
21497
+ var InlineBasicInterfaceProperty$0 = $S($C(TypeIndexSignature, TypeProperty), $E(QuestionMark), Colon, Type, InlineInterfacePropertyDelimiter);
21460
21498
  function InlineBasicInterfaceProperty(state) {
21461
21499
  let eventData;
21462
21500
  if (state.events) {
@@ -22941,7 +22979,7 @@ ${input.slice(result.pos)}
22941
22979
  }
22942
22980
  });
22943
22981
  }
22944
- module.config = parse2.config = {
22982
+ module.config = {
22945
22983
  autoVar: false,
22946
22984
  autoLet: false,
22947
22985
  coffeeBinaryExistential: false,
@@ -23102,6 +23140,8 @@ ${input.slice(result.pos)}
23102
23140
  }
23103
23141
  }
23104
23142
  });
23143
+ Object.assign(module.config, parse2.config);
23144
+ parse2.config = module.config;
23105
23145
  });
23106
23146
  function Reset(state) {
23107
23147
  let eventData;
@@ -23915,13 +23955,17 @@ ${input.slice(result.pos)}
23915
23955
  } else {
23916
23956
  options = { ...options };
23917
23957
  }
23958
+ if (options.parseOptions == null) {
23959
+ options.parseOptions = {};
23960
+ }
23918
23961
  filename = options.filename || "unknown";
23919
23962
  if (filename.endsWith(".coffee") && !/^(#![^\r\n]*(\r\n|\n|\r))?\s*['"]civet/.test(src)) {
23920
- src = `"civet coffeeCompat"; ${src}`;
23963
+ options.parseOptions.coffeeCompat = true;
23921
23964
  }
23922
23965
  if (!options.noCache) {
23923
23966
  events = makeCache();
23924
23967
  }
23968
+ parse.config = options.parseOptions || {};
23925
23969
  ast = prune(parse(src, { filename, events }));
23926
23970
  if (options.ast) {
23927
23971
  return ast;
package/dist/civet CHANGED
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  "use strict";
3
3
  var import_main = require("./main");
4
+ var import_config = require("./config");
4
5
  var cli, encoding, fs, parseArgs, path, prune, readFiles, repl, version, splice = [].splice;
5
6
  ({ prune } = import_main.generate);
6
7
  version = function() {
@@ -36,6 +37,8 @@ Options:
36
37
  --version Show the version number
37
38
  -o / --output XX Specify output directory and/or extension, or filename
38
39
  -c / --compile Compile input files to TypeScript (or JavaScript)
40
+ --config XX Specify a config file (default scans for a config.civet, civet.json, civetconfig.civet or civetconfig.json file, optionally in a .config directory, or starting with a .)
41
+ --no-config Don't scan for a config file
39
42
  --js Strip out all type annotations; default to .jsx extension
40
43
  --ast Print the AST instead of the compiled code
41
44
  --inline-map Generate a sourcemap
@@ -96,6 +99,12 @@ parseArgs = function(args) {
96
99
  case "--output":
97
100
  options.output = args[++i];
98
101
  break;
102
+ case "--config":
103
+ options.config = args[++i];
104
+ break;
105
+ case "--no-config":
106
+ options.config = false;
107
+ break;
99
108
  case "--ast":
100
109
  options.ast = true;
101
110
  break;
@@ -254,6 +263,14 @@ cli = async function() {
254
263
  var argv, child, content, e, error, esm, filename, filenames, options, optionsPath, output, outputFilename, outputPath, ref, results, scriptArgs, stat, stdin, x;
255
264
  argv = process.argv;
256
265
  ({ filenames, scriptArgs, options } = parseArgs(argv.slice(2)));
266
+ if (options.config !== false) {
267
+ if (options.config == null) {
268
+ options.config = await (0, import_config.findConfig)(process.cwd());
269
+ }
270
+ }
271
+ if (options.config) {
272
+ options = { ...await (0, import_config.loadConfig)(options.config), ...options };
273
+ }
257
274
  if (!filenames.length) {
258
275
  if (process.stdin.isTTY) {
259
276
  options.repl = true;
package/dist/config.js ADDED
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
22
+ mod
23
+ ));
24
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
25
+ var config_exports = {};
26
+ __export(config_exports, {
27
+ findConfig: () => findConfig,
28
+ loadConfig: () => loadConfig
29
+ });
30
+ module.exports = __toCommonJS(config_exports);
31
+ var import_path = __toESM(require("path"));
32
+ var import_promises = __toESM(require("fs/promises"));
33
+ var import_main = require("./main");
34
+ var import_url = require("url");
35
+ var findInDir;
36
+ findInDir = async function(dirPath) {
37
+ var dir, entry, name;
38
+ dir = await import_promises.default.opendir(dirPath);
39
+ for await (entry of dir) {
40
+ if (entry.isDirectory() && entry.name === ".config") {
41
+ return findInDir(import_path.default.join(dirPath, entry.name));
42
+ }
43
+ if (entry.isFile()) {
44
+ name = entry.name.replace(/^\./, "");
45
+ if (name === "config.civet" || name === "civet.json" || name === "civetconfig.civet" || name === "civetconfig.json") {
46
+ return import_path.default.join(dirPath, entry.name);
47
+ }
48
+ }
49
+ }
50
+ return null;
51
+ };
52
+ var findConfig = async function(startDir) {
53
+ var configPath, curr, parent;
54
+ curr = startDir;
55
+ parent = import_path.default.dirname(curr);
56
+ while (curr !== parent) {
57
+ if (configPath = await findInDir(curr)) {
58
+ return configPath;
59
+ }
60
+ curr = parent;
61
+ parent = import_path.default.dirname(curr);
62
+ }
63
+ return null;
64
+ };
65
+ var loadConfig = async function(path2) {
66
+ var config, exports, js, tmpPath;
67
+ config = await import_promises.default.readFile(path2, "utf8");
68
+ if (path2.endsWith(".json")) {
69
+ return JSON.parse(config);
70
+ } else {
71
+ js = (0, import_main.compile)(config, {
72
+ js: true
73
+ });
74
+ tmpPath = path2 + `.civet-tmp-${Date.now()}.mjs`;
75
+ await import_promises.default.writeFile(tmpPath, js);
76
+ try {
77
+ exports = await import((0, import_url.pathToFileURL)(tmpPath));
78
+ } finally {
79
+ await import_promises.default.unlink(tmpPath);
80
+ }
81
+ if (typeof exports.default !== "object" || exports.default === null) {
82
+ throw new Error("civet config file must export an object");
83
+ }
84
+ return exports.default;
85
+ }
86
+ };
87
+ // Annotate the CommonJS export names for ESM import in node:
88
+ 0 && (module.exports = {
89
+ findConfig,
90
+ loadConfig
91
+ });
package/dist/main.js CHANGED
@@ -797,13 +797,14 @@ var require_lib = __commonJS({
797
797
  }
798
798
  function hoistRefDecs(statements) {
799
799
  gatherRecursiveAll(statements, (s) => s.hoistDec).forEach((node) => {
800
- const { hoistDec } = node;
800
+ let { hoistDec, parent } = node;
801
801
  node.hoistDec = null;
802
- while (node.parent?.type !== "BlockStatement") {
803
- node = node.parent;
802
+ while (parent?.type !== "BlockStatement" || parent.bare && !parent.root) {
803
+ node = parent;
804
+ parent = node.parent;
804
805
  }
805
- if (node.parent) {
806
- insertHoistDec(node.parent, node, hoistDec);
806
+ if (parent) {
807
+ insertHoistDec(parent, node, hoistDec);
807
808
  } else {
808
809
  throw new Error("Couldn't find block to hoist declaration into.");
809
810
  }
@@ -1330,8 +1331,27 @@ var require_lib = __commonJS({
1330
1331
  thisAssignments
1331
1332
  };
1332
1333
  }
1334
+ function implicitFunctionBlock(f) {
1335
+ if (f.abstract || f.block)
1336
+ return;
1337
+ const { name, parent } = f;
1338
+ const expressions = parent?.expressions ?? parent?.elements;
1339
+ const currentIndex = expressions?.findIndex(([, def]) => def === f);
1340
+ const following = currentIndex >= 0 && expressions[currentIndex + 1]?.[1];
1341
+ if (f.type === following?.type && name && name === following.name) {
1342
+ f.ts = true;
1343
+ } else {
1344
+ const block = makeEmptyBlock();
1345
+ block.parent = f;
1346
+ f.block = block;
1347
+ f.children.push(block);
1348
+ f.ts = false;
1349
+ }
1350
+ }
1333
1351
  function processFunctions(statements, config) {
1334
1352
  gatherRecursiveAll(statements, ({ type }) => type === "FunctionExpression" || type === "ArrowFunction").forEach((f) => {
1353
+ if (f.type === "FunctionExpression")
1354
+ implicitFunctionBlock(f);
1335
1355
  processParams(f);
1336
1356
  if (!processReturnValue(f) && config.implicitReturns) {
1337
1357
  const { block, returnType } = f;
@@ -1343,25 +1363,15 @@ var require_lib = __commonJS({
1343
1363
  }
1344
1364
  });
1345
1365
  gatherRecursiveAll(statements, ({ type }) => type === "MethodDefinition").forEach((f) => {
1346
- const { abstract, block, signature } = f;
1347
- if (!abstract && !block) {
1348
- const { name } = signature, { parent } = f, { elements } = parent, currentIndex = elements.findIndex(([, def]) => def === f);
1349
- const following = elements[currentIndex + 1]?.[1];
1350
- if (following?.signature?.name !== name) {
1351
- const block2 = makeEmptyBlock();
1352
- block2.parent = f;
1353
- f.block = block2;
1354
- f.children.push(block2);
1355
- }
1356
- }
1366
+ implicitFunctionBlock(f);
1357
1367
  processParams(f);
1358
1368
  if (!processReturnValue(f) && config.implicitReturns) {
1359
- const { signature: signature2, block: block2 } = f;
1360
- const isConstructor = signature2.name === "constructor";
1361
- const isVoid = isVoidType(signature2.returnType?.t);
1362
- const isSet = signature2.modifier?.set;
1369
+ const { signature, block } = f;
1370
+ const isConstructor = signature.name === "constructor";
1371
+ const isVoid = isVoidType(signature.returnType?.t);
1372
+ const isSet = signature.modifier?.set;
1363
1373
  if (!isConstructor && !isSet && !isVoid) {
1364
- insertReturn(block2);
1374
+ insertReturn(block);
1365
1375
  }
1366
1376
  }
1367
1377
  });
@@ -3456,6 +3466,7 @@ ${input.slice(result.pos)}
3456
3466
  NestedEnumProperties,
3457
3467
  NestedEnumProperty,
3458
3468
  EnumProperty,
3469
+ TypeProperty,
3459
3470
  TypeIndexSignature,
3460
3471
  TypeIndex,
3461
3472
  TypeSuffix,
@@ -4255,10 +4266,9 @@ ${input.slice(result.pos)}
4255
4266
  }
4256
4267
  var ForbiddenImplicitCalls$0 = $R$0($EXPECT($R0, fail, "ForbiddenImplicitCalls /(as|of|satisfies|then|when|implements|xor|xnor)(?!\\p{ID_Continue}|[\\u200C\\u200D$])/"));
4257
4268
  var ForbiddenImplicitCalls$1 = $EXPECT($L1, fail, 'ForbiddenImplicitCalls "/ "');
4258
- var ForbiddenImplicitCalls$2 = $S(ClassImplicitCallForbidden, Class);
4259
- var ForbiddenImplicitCalls$3 = AtAt;
4260
- var ForbiddenImplicitCalls$4 = $S(Identifier, $EXPECT($L2, fail, 'ForbiddenImplicitCalls "="'), Whitespace);
4261
- var ForbiddenImplicitCalls$5 = $TS($S(Identifier, $N($EXPECT($L3, fail, 'ForbiddenImplicitCalls "("'))), function($skip, $loc, $0, $1, $2) {
4269
+ var ForbiddenImplicitCalls$2 = $S(ClassImplicitCallForbidden, $C(Class, AtAt));
4270
+ var ForbiddenImplicitCalls$3 = $S(Identifier, $EXPECT($L2, fail, 'ForbiddenImplicitCalls "="'), Whitespace);
4271
+ var ForbiddenImplicitCalls$4 = $TS($S(Identifier, $N($EXPECT($L3, fail, 'ForbiddenImplicitCalls "("'))), function($skip, $loc, $0, $1, $2) {
4262
4272
  if (module2.operators.has($1.name))
4263
4273
  return $1;
4264
4274
  return $skip;
@@ -4274,12 +4284,12 @@ ${input.slice(result.pos)}
4274
4284
  }
4275
4285
  }
4276
4286
  if (state.tokenize) {
4277
- const result = $TOKEN("ForbiddenImplicitCalls", state, ForbiddenImplicitCalls$0(state) || ForbiddenImplicitCalls$1(state) || ForbiddenImplicitCalls$2(state) || ForbiddenImplicitCalls$3(state) || ForbiddenImplicitCalls$4(state) || ForbiddenImplicitCalls$5(state));
4287
+ const result = $TOKEN("ForbiddenImplicitCalls", state, ForbiddenImplicitCalls$0(state) || ForbiddenImplicitCalls$1(state) || ForbiddenImplicitCalls$2(state) || ForbiddenImplicitCalls$3(state) || ForbiddenImplicitCalls$4(state));
4278
4288
  if (state.events)
4279
4289
  state.events.exit?.("ForbiddenImplicitCalls", state, result, eventData);
4280
4290
  return result;
4281
4291
  } else {
4282
- const result = ForbiddenImplicitCalls$0(state) || ForbiddenImplicitCalls$1(state) || ForbiddenImplicitCalls$2(state) || ForbiddenImplicitCalls$3(state) || ForbiddenImplicitCalls$4(state) || ForbiddenImplicitCalls$5(state);
4292
+ const result = ForbiddenImplicitCalls$0(state) || ForbiddenImplicitCalls$1(state) || ForbiddenImplicitCalls$2(state) || ForbiddenImplicitCalls$3(state) || ForbiddenImplicitCalls$4(state);
4283
4293
  if (state.events)
4284
4294
  state.events.exit?.("ForbiddenImplicitCalls", state, result, eventData);
4285
4295
  return result;
@@ -5983,7 +5993,7 @@ ${input.slice(result.pos)}
5983
5993
  return result;
5984
5994
  }
5985
5995
  }
5986
- var AccessModifier$0 = $TS($S($E($S($C(Public, Private, Protected), __)), $E($S(Readonly, __))), function($skip, $loc, $0, $1, $2) {
5996
+ var AccessModifier$0 = $TS($S($E($S($C(Public, Private, Protected), NotDedented)), $E($S(Readonly, NotDedented))), function($skip, $loc, $0, $1, $2) {
5987
5997
  if (!($1 || $2))
5988
5998
  return $skip;
5989
5999
  return {
@@ -7739,9 +7749,11 @@ ${input.slice(result.pos)}
7739
7749
  async = [];
7740
7750
  if (!generator)
7741
7751
  generator = [];
7752
+ const id = wid?.[1];
7742
7753
  return {
7743
7754
  type: "FunctionSignature",
7744
- id: wid?.[1],
7755
+ id,
7756
+ name: id?.name,
7745
7757
  parameters,
7746
7758
  returnType: suffix,
7747
7759
  ts: false,
@@ -7777,8 +7789,11 @@ ${input.slice(result.pos)}
7777
7789
  var signature = $1;
7778
7790
  var block = $2;
7779
7791
  if (!block) {
7780
- signature.ts = true;
7781
- return signature;
7792
+ return {
7793
+ ...signature,
7794
+ type: "FunctionExpression",
7795
+ ts: true
7796
+ };
7782
7797
  }
7783
7798
  if (hasAwait(block) && !signature.async.length) {
7784
7799
  signature.async.push("async ");
@@ -13046,7 +13061,7 @@ ${input.slice(result.pos)}
13046
13061
  }
13047
13062
  }
13048
13063
  var ForbidClassImplicitCall$0 = $TV($EXPECT($L0, fail, 'ForbidClassImplicitCall ""'), function($skip, $loc, $0, $1) {
13049
- module2.forbidIndentedApplication.push(true);
13064
+ module2.forbidClassImplicitCall.push(true);
13050
13065
  });
13051
13066
  function ForbidClassImplicitCall(state) {
13052
13067
  let eventData;
@@ -13071,7 +13086,7 @@ ${input.slice(result.pos)}
13071
13086
  }
13072
13087
  }
13073
13088
  var AllowClassImplicitCall$0 = $TV($EXPECT($L0, fail, 'AllowClassImplicitCall ""'), function($skip, $loc, $0, $1) {
13074
- module2.forbidIndentedApplication.push(false);
13089
+ module2.forbidClassImplicitCall.push(false);
13075
13090
  });
13076
13091
  function AllowClassImplicitCall(state) {
13077
13092
  let eventData;
@@ -13096,7 +13111,7 @@ ${input.slice(result.pos)}
13096
13111
  }
13097
13112
  }
13098
13113
  var RestoreClassImplicitCall$0 = $TV($EXPECT($L0, fail, 'RestoreClassImplicitCall ""'), function($skip, $loc, $0, $1) {
13099
- module2.forbidIndentedApplication.pop();
13114
+ module2.forbidClassImplicitCall.pop();
13100
13115
  });
13101
13116
  function RestoreClassImplicitCall(state) {
13102
13117
  let eventData;
@@ -13121,7 +13136,7 @@ ${input.slice(result.pos)}
13121
13136
  }
13122
13137
  }
13123
13138
  var ClassImplicitCallForbidden$0 = $TV($EXPECT($L0, fail, 'ClassImplicitCallForbidden ""'), function($skip, $loc, $0, $1) {
13124
- if (module2.classImplicitCallForbidden)
13139
+ if (!module2.classImplicitCallForbidden)
13125
13140
  return $skip;
13126
13141
  return;
13127
13142
  });
@@ -20330,7 +20345,7 @@ ${input.slice(result.pos)}
20330
20345
  return result;
20331
20346
  }
20332
20347
  }
20333
- var BasicInterfaceProperty$0 = $S($C(TypeIndexSignature, PropertyName), TypeSuffix, InterfacePropertyDelimiter);
20348
+ var BasicInterfaceProperty$0 = $S($C(TypeIndexSignature, TypeProperty), $E(_), TypeSuffix, InterfacePropertyDelimiter);
20334
20349
  function BasicInterfaceProperty(state) {
20335
20350
  let eventData;
20336
20351
  if (state.events) {
@@ -20771,7 +20786,30 @@ ${input.slice(result.pos)}
20771
20786
  return result;
20772
20787
  }
20773
20788
  }
20774
- var TypeIndexSignature$0 = $S($E($S($R$0($EXPECT($R58, fail, "TypeIndexSignature /[+-]?/")), $EXPECT($L141, fail, 'TypeIndexSignature "readonly"'), __)), OpenBracket, TypeIndex, CloseBracket, $E($S(__, $R$0($EXPECT($R59, fail, "TypeIndexSignature /[+-]/")), QuestionMark)));
20789
+ var TypeProperty$0 = $S($E($S(Readonly, NotDedented)), PropertyName);
20790
+ function TypeProperty(state) {
20791
+ let eventData;
20792
+ if (state.events) {
20793
+ const result = state.events.enter?.("TypeProperty", state);
20794
+ if (result) {
20795
+ if (result.cache)
20796
+ return result.cache;
20797
+ eventData = result.data;
20798
+ }
20799
+ }
20800
+ if (state.tokenize) {
20801
+ const result = $TOKEN("TypeProperty", state, TypeProperty$0(state));
20802
+ if (state.events)
20803
+ state.events.exit?.("TypeProperty", state, result, eventData);
20804
+ return result;
20805
+ } else {
20806
+ const result = TypeProperty$0(state);
20807
+ if (state.events)
20808
+ state.events.exit?.("TypeProperty", state, result, eventData);
20809
+ return result;
20810
+ }
20811
+ }
20812
+ var TypeIndexSignature$0 = $S($E($S($R$0($EXPECT($R58, fail, "TypeIndexSignature /[+-]?/")), Readonly, NotDedented)), OpenBracket, TypeIndex, CloseBracket, $E($S(__, $R$0($EXPECT($R59, fail, "TypeIndexSignature /[+-]/")), $Y($S($E(_), QuestionMark)))));
20775
20813
  function TypeIndexSignature(state) {
20776
20814
  let eventData;
20777
20815
  if (state.events) {
@@ -21455,7 +21493,7 @@ ${input.slice(result.pos)}
21455
21493
  return result;
21456
21494
  }
21457
21495
  }
21458
- var InlineBasicInterfaceProperty$0 = $S($C(TypeIndexSignature, PropertyName), $E(QuestionMark), Colon, Type, InlineInterfacePropertyDelimiter);
21496
+ var InlineBasicInterfaceProperty$0 = $S($C(TypeIndexSignature, TypeProperty), $E(QuestionMark), Colon, Type, InlineInterfacePropertyDelimiter);
21459
21497
  function InlineBasicInterfaceProperty(state) {
21460
21498
  let eventData;
21461
21499
  if (state.events) {
@@ -22940,7 +22978,7 @@ ${input.slice(result.pos)}
22940
22978
  }
22941
22979
  });
22942
22980
  }
22943
- module2.config = parse2.config = {
22981
+ module2.config = {
22944
22982
  autoVar: false,
22945
22983
  autoLet: false,
22946
22984
  coffeeBinaryExistential: false,
@@ -23101,6 +23139,8 @@ ${input.slice(result.pos)}
23101
23139
  }
23102
23140
  }
23103
23141
  });
23142
+ Object.assign(module2.config, parse2.config);
23143
+ parse2.config = module2.config;
23104
23144
  });
23105
23145
  function Reset(state) {
23106
23146
  let eventData;
@@ -23915,13 +23955,17 @@ var compile = function(src, options) {
23915
23955
  } else {
23916
23956
  options = { ...options };
23917
23957
  }
23958
+ if (options.parseOptions == null) {
23959
+ options.parseOptions = {};
23960
+ }
23918
23961
  filename = options.filename || "unknown";
23919
23962
  if (filename.endsWith(".coffee") && !/^(#![^\r\n]*(\r\n|\n|\r))?\s*['"]civet/.test(src)) {
23920
- src = `"civet coffeeCompat"; ${src}`;
23963
+ options.parseOptions.coffeeCompat = true;
23921
23964
  }
23922
23965
  if (!options.noCache) {
23923
23966
  events = makeCache();
23924
23967
  }
23968
+ parse.config = options.parseOptions || {};
23925
23969
  ast = prune(parse(src, { filename, events }));
23926
23970
  if (options.ast) {
23927
23971
  return ast;
package/dist/main.mjs CHANGED
@@ -795,13 +795,14 @@ var require_lib = __commonJS({
795
795
  }
796
796
  function hoistRefDecs(statements) {
797
797
  gatherRecursiveAll(statements, (s) => s.hoistDec).forEach((node) => {
798
- const { hoistDec } = node;
798
+ let { hoistDec, parent } = node;
799
799
  node.hoistDec = null;
800
- while (node.parent?.type !== "BlockStatement") {
801
- node = node.parent;
800
+ while (parent?.type !== "BlockStatement" || parent.bare && !parent.root) {
801
+ node = parent;
802
+ parent = node.parent;
802
803
  }
803
- if (node.parent) {
804
- insertHoistDec(node.parent, node, hoistDec);
804
+ if (parent) {
805
+ insertHoistDec(parent, node, hoistDec);
805
806
  } else {
806
807
  throw new Error("Couldn't find block to hoist declaration into.");
807
808
  }
@@ -1328,8 +1329,27 @@ var require_lib = __commonJS({
1328
1329
  thisAssignments
1329
1330
  };
1330
1331
  }
1332
+ function implicitFunctionBlock(f) {
1333
+ if (f.abstract || f.block)
1334
+ return;
1335
+ const { name, parent } = f;
1336
+ const expressions = parent?.expressions ?? parent?.elements;
1337
+ const currentIndex = expressions?.findIndex(([, def]) => def === f);
1338
+ const following = currentIndex >= 0 && expressions[currentIndex + 1]?.[1];
1339
+ if (f.type === following?.type && name && name === following.name) {
1340
+ f.ts = true;
1341
+ } else {
1342
+ const block = makeEmptyBlock();
1343
+ block.parent = f;
1344
+ f.block = block;
1345
+ f.children.push(block);
1346
+ f.ts = false;
1347
+ }
1348
+ }
1331
1349
  function processFunctions(statements, config) {
1332
1350
  gatherRecursiveAll(statements, ({ type }) => type === "FunctionExpression" || type === "ArrowFunction").forEach((f) => {
1351
+ if (f.type === "FunctionExpression")
1352
+ implicitFunctionBlock(f);
1333
1353
  processParams(f);
1334
1354
  if (!processReturnValue(f) && config.implicitReturns) {
1335
1355
  const { block, returnType } = f;
@@ -1341,25 +1361,15 @@ var require_lib = __commonJS({
1341
1361
  }
1342
1362
  });
1343
1363
  gatherRecursiveAll(statements, ({ type }) => type === "MethodDefinition").forEach((f) => {
1344
- const { abstract, block, signature } = f;
1345
- if (!abstract && !block) {
1346
- const { name } = signature, { parent } = f, { elements } = parent, currentIndex = elements.findIndex(([, def]) => def === f);
1347
- const following = elements[currentIndex + 1]?.[1];
1348
- if (following?.signature?.name !== name) {
1349
- const block2 = makeEmptyBlock();
1350
- block2.parent = f;
1351
- f.block = block2;
1352
- f.children.push(block2);
1353
- }
1354
- }
1364
+ implicitFunctionBlock(f);
1355
1365
  processParams(f);
1356
1366
  if (!processReturnValue(f) && config.implicitReturns) {
1357
- const { signature: signature2, block: block2 } = f;
1358
- const isConstructor = signature2.name === "constructor";
1359
- const isVoid = isVoidType(signature2.returnType?.t);
1360
- const isSet = signature2.modifier?.set;
1367
+ const { signature, block } = f;
1368
+ const isConstructor = signature.name === "constructor";
1369
+ const isVoid = isVoidType(signature.returnType?.t);
1370
+ const isSet = signature.modifier?.set;
1361
1371
  if (!isConstructor && !isSet && !isVoid) {
1362
- insertReturn(block2);
1372
+ insertReturn(block);
1363
1373
  }
1364
1374
  }
1365
1375
  });
@@ -3454,6 +3464,7 @@ ${input.slice(result.pos)}
3454
3464
  NestedEnumProperties,
3455
3465
  NestedEnumProperty,
3456
3466
  EnumProperty,
3467
+ TypeProperty,
3457
3468
  TypeIndexSignature,
3458
3469
  TypeIndex,
3459
3470
  TypeSuffix,
@@ -4253,10 +4264,9 @@ ${input.slice(result.pos)}
4253
4264
  }
4254
4265
  var ForbiddenImplicitCalls$0 = $R$0($EXPECT($R0, fail, "ForbiddenImplicitCalls /(as|of|satisfies|then|when|implements|xor|xnor)(?!\\p{ID_Continue}|[\\u200C\\u200D$])/"));
4255
4266
  var ForbiddenImplicitCalls$1 = $EXPECT($L1, fail, 'ForbiddenImplicitCalls "/ "');
4256
- var ForbiddenImplicitCalls$2 = $S(ClassImplicitCallForbidden, Class);
4257
- var ForbiddenImplicitCalls$3 = AtAt;
4258
- var ForbiddenImplicitCalls$4 = $S(Identifier, $EXPECT($L2, fail, 'ForbiddenImplicitCalls "="'), Whitespace);
4259
- var ForbiddenImplicitCalls$5 = $TS($S(Identifier, $N($EXPECT($L3, fail, 'ForbiddenImplicitCalls "("'))), function($skip, $loc, $0, $1, $2) {
4267
+ var ForbiddenImplicitCalls$2 = $S(ClassImplicitCallForbidden, $C(Class, AtAt));
4268
+ var ForbiddenImplicitCalls$3 = $S(Identifier, $EXPECT($L2, fail, 'ForbiddenImplicitCalls "="'), Whitespace);
4269
+ var ForbiddenImplicitCalls$4 = $TS($S(Identifier, $N($EXPECT($L3, fail, 'ForbiddenImplicitCalls "("'))), function($skip, $loc, $0, $1, $2) {
4260
4270
  if (module.operators.has($1.name))
4261
4271
  return $1;
4262
4272
  return $skip;
@@ -4272,12 +4282,12 @@ ${input.slice(result.pos)}
4272
4282
  }
4273
4283
  }
4274
4284
  if (state.tokenize) {
4275
- const result = $TOKEN("ForbiddenImplicitCalls", state, ForbiddenImplicitCalls$0(state) || ForbiddenImplicitCalls$1(state) || ForbiddenImplicitCalls$2(state) || ForbiddenImplicitCalls$3(state) || ForbiddenImplicitCalls$4(state) || ForbiddenImplicitCalls$5(state));
4285
+ const result = $TOKEN("ForbiddenImplicitCalls", state, ForbiddenImplicitCalls$0(state) || ForbiddenImplicitCalls$1(state) || ForbiddenImplicitCalls$2(state) || ForbiddenImplicitCalls$3(state) || ForbiddenImplicitCalls$4(state));
4276
4286
  if (state.events)
4277
4287
  state.events.exit?.("ForbiddenImplicitCalls", state, result, eventData);
4278
4288
  return result;
4279
4289
  } else {
4280
- const result = ForbiddenImplicitCalls$0(state) || ForbiddenImplicitCalls$1(state) || ForbiddenImplicitCalls$2(state) || ForbiddenImplicitCalls$3(state) || ForbiddenImplicitCalls$4(state) || ForbiddenImplicitCalls$5(state);
4290
+ const result = ForbiddenImplicitCalls$0(state) || ForbiddenImplicitCalls$1(state) || ForbiddenImplicitCalls$2(state) || ForbiddenImplicitCalls$3(state) || ForbiddenImplicitCalls$4(state);
4281
4291
  if (state.events)
4282
4292
  state.events.exit?.("ForbiddenImplicitCalls", state, result, eventData);
4283
4293
  return result;
@@ -5981,7 +5991,7 @@ ${input.slice(result.pos)}
5981
5991
  return result;
5982
5992
  }
5983
5993
  }
5984
- var AccessModifier$0 = $TS($S($E($S($C(Public, Private, Protected), __)), $E($S(Readonly, __))), function($skip, $loc, $0, $1, $2) {
5994
+ var AccessModifier$0 = $TS($S($E($S($C(Public, Private, Protected), NotDedented)), $E($S(Readonly, NotDedented))), function($skip, $loc, $0, $1, $2) {
5985
5995
  if (!($1 || $2))
5986
5996
  return $skip;
5987
5997
  return {
@@ -7737,9 +7747,11 @@ ${input.slice(result.pos)}
7737
7747
  async = [];
7738
7748
  if (!generator)
7739
7749
  generator = [];
7750
+ const id = wid?.[1];
7740
7751
  return {
7741
7752
  type: "FunctionSignature",
7742
- id: wid?.[1],
7753
+ id,
7754
+ name: id?.name,
7743
7755
  parameters,
7744
7756
  returnType: suffix,
7745
7757
  ts: false,
@@ -7775,8 +7787,11 @@ ${input.slice(result.pos)}
7775
7787
  var signature = $1;
7776
7788
  var block = $2;
7777
7789
  if (!block) {
7778
- signature.ts = true;
7779
- return signature;
7790
+ return {
7791
+ ...signature,
7792
+ type: "FunctionExpression",
7793
+ ts: true
7794
+ };
7780
7795
  }
7781
7796
  if (hasAwait(block) && !signature.async.length) {
7782
7797
  signature.async.push("async ");
@@ -13044,7 +13059,7 @@ ${input.slice(result.pos)}
13044
13059
  }
13045
13060
  }
13046
13061
  var ForbidClassImplicitCall$0 = $TV($EXPECT($L0, fail, 'ForbidClassImplicitCall ""'), function($skip, $loc, $0, $1) {
13047
- module.forbidIndentedApplication.push(true);
13062
+ module.forbidClassImplicitCall.push(true);
13048
13063
  });
13049
13064
  function ForbidClassImplicitCall(state) {
13050
13065
  let eventData;
@@ -13069,7 +13084,7 @@ ${input.slice(result.pos)}
13069
13084
  }
13070
13085
  }
13071
13086
  var AllowClassImplicitCall$0 = $TV($EXPECT($L0, fail, 'AllowClassImplicitCall ""'), function($skip, $loc, $0, $1) {
13072
- module.forbidIndentedApplication.push(false);
13087
+ module.forbidClassImplicitCall.push(false);
13073
13088
  });
13074
13089
  function AllowClassImplicitCall(state) {
13075
13090
  let eventData;
@@ -13094,7 +13109,7 @@ ${input.slice(result.pos)}
13094
13109
  }
13095
13110
  }
13096
13111
  var RestoreClassImplicitCall$0 = $TV($EXPECT($L0, fail, 'RestoreClassImplicitCall ""'), function($skip, $loc, $0, $1) {
13097
- module.forbidIndentedApplication.pop();
13112
+ module.forbidClassImplicitCall.pop();
13098
13113
  });
13099
13114
  function RestoreClassImplicitCall(state) {
13100
13115
  let eventData;
@@ -13119,7 +13134,7 @@ ${input.slice(result.pos)}
13119
13134
  }
13120
13135
  }
13121
13136
  var ClassImplicitCallForbidden$0 = $TV($EXPECT($L0, fail, 'ClassImplicitCallForbidden ""'), function($skip, $loc, $0, $1) {
13122
- if (module.classImplicitCallForbidden)
13137
+ if (!module.classImplicitCallForbidden)
13123
13138
  return $skip;
13124
13139
  return;
13125
13140
  });
@@ -20328,7 +20343,7 @@ ${input.slice(result.pos)}
20328
20343
  return result;
20329
20344
  }
20330
20345
  }
20331
- var BasicInterfaceProperty$0 = $S($C(TypeIndexSignature, PropertyName), TypeSuffix, InterfacePropertyDelimiter);
20346
+ var BasicInterfaceProperty$0 = $S($C(TypeIndexSignature, TypeProperty), $E(_), TypeSuffix, InterfacePropertyDelimiter);
20332
20347
  function BasicInterfaceProperty(state) {
20333
20348
  let eventData;
20334
20349
  if (state.events) {
@@ -20769,7 +20784,30 @@ ${input.slice(result.pos)}
20769
20784
  return result;
20770
20785
  }
20771
20786
  }
20772
- var TypeIndexSignature$0 = $S($E($S($R$0($EXPECT($R58, fail, "TypeIndexSignature /[+-]?/")), $EXPECT($L141, fail, 'TypeIndexSignature "readonly"'), __)), OpenBracket, TypeIndex, CloseBracket, $E($S(__, $R$0($EXPECT($R59, fail, "TypeIndexSignature /[+-]/")), QuestionMark)));
20787
+ var TypeProperty$0 = $S($E($S(Readonly, NotDedented)), PropertyName);
20788
+ function TypeProperty(state) {
20789
+ let eventData;
20790
+ if (state.events) {
20791
+ const result = state.events.enter?.("TypeProperty", state);
20792
+ if (result) {
20793
+ if (result.cache)
20794
+ return result.cache;
20795
+ eventData = result.data;
20796
+ }
20797
+ }
20798
+ if (state.tokenize) {
20799
+ const result = $TOKEN("TypeProperty", state, TypeProperty$0(state));
20800
+ if (state.events)
20801
+ state.events.exit?.("TypeProperty", state, result, eventData);
20802
+ return result;
20803
+ } else {
20804
+ const result = TypeProperty$0(state);
20805
+ if (state.events)
20806
+ state.events.exit?.("TypeProperty", state, result, eventData);
20807
+ return result;
20808
+ }
20809
+ }
20810
+ var TypeIndexSignature$0 = $S($E($S($R$0($EXPECT($R58, fail, "TypeIndexSignature /[+-]?/")), Readonly, NotDedented)), OpenBracket, TypeIndex, CloseBracket, $E($S(__, $R$0($EXPECT($R59, fail, "TypeIndexSignature /[+-]/")), $Y($S($E(_), QuestionMark)))));
20773
20811
  function TypeIndexSignature(state) {
20774
20812
  let eventData;
20775
20813
  if (state.events) {
@@ -21453,7 +21491,7 @@ ${input.slice(result.pos)}
21453
21491
  return result;
21454
21492
  }
21455
21493
  }
21456
- var InlineBasicInterfaceProperty$0 = $S($C(TypeIndexSignature, PropertyName), $E(QuestionMark), Colon, Type, InlineInterfacePropertyDelimiter);
21494
+ var InlineBasicInterfaceProperty$0 = $S($C(TypeIndexSignature, TypeProperty), $E(QuestionMark), Colon, Type, InlineInterfacePropertyDelimiter);
21457
21495
  function InlineBasicInterfaceProperty(state) {
21458
21496
  let eventData;
21459
21497
  if (state.events) {
@@ -22938,7 +22976,7 @@ ${input.slice(result.pos)}
22938
22976
  }
22939
22977
  });
22940
22978
  }
22941
- module.config = parse2.config = {
22979
+ module.config = {
22942
22980
  autoVar: false,
22943
22981
  autoLet: false,
22944
22982
  coffeeBinaryExistential: false,
@@ -23099,6 +23137,8 @@ ${input.slice(result.pos)}
23099
23137
  }
23100
23138
  }
23101
23139
  });
23140
+ Object.assign(module.config, parse2.config);
23141
+ parse2.config = module.config;
23102
23142
  });
23103
23143
  function Reset(state) {
23104
23144
  let eventData;
@@ -23903,13 +23943,17 @@ var compile = function(src, options) {
23903
23943
  } else {
23904
23944
  options = { ...options };
23905
23945
  }
23946
+ if (options.parseOptions == null) {
23947
+ options.parseOptions = {};
23948
+ }
23906
23949
  filename = options.filename || "unknown";
23907
23950
  if (filename.endsWith(".coffee") && !/^(#![^\r\n]*(\r\n|\n|\r))?\s*['"]civet/.test(src)) {
23908
- src = `"civet coffeeCompat"; ${src}`;
23951
+ options.parseOptions.coffeeCompat = true;
23909
23952
  }
23910
23953
  if (!options.noCache) {
23911
23954
  events = makeCache();
23912
23955
  }
23956
+ parse.config = options.parseOptions || {};
23913
23957
  ast = prune(parse(src, { filename, events }));
23914
23958
  if (options.ast) {
23915
23959
  return ast;
package/dist/types.d.ts CHANGED
@@ -1,9 +1,38 @@
1
1
  declare module "@danielx/civet" {
2
2
  export type CivetAST = unknown
3
+ export type ParseOptions = Partial<{
4
+ autoVar: boolean
5
+ autoLet: boolean
6
+ coffeeBinaryExistential: boolean
7
+ coffeeBooleans: boolean
8
+ coffeeClasses: boolean
9
+ coffeeComment: boolean
10
+ coffeeDo: boolean
11
+ coffeeEq: boolean
12
+ coffeeForLoops: boolean
13
+ coffeeInterpolation: boolean
14
+ coffeeIsnt: boolean
15
+ coffeeJSX: boolean
16
+ coffeeLineContinuation: boolean
17
+ coffeeNot: boolean
18
+ coffeeOf: boolean
19
+ coffeePrototype: boolean
20
+ defaultElement: string
21
+ implicitReturns: boolean
22
+ objectIs: boolean
23
+ react: boolean
24
+ solid: boolean
25
+ client: boolean
26
+ rewriteTsImports: boolean
27
+ server: boolean
28
+ tab: number
29
+ verbose: boolean
30
+ }>
3
31
  export type CompileOptions = {
4
32
  filename?: string
5
33
  js?: boolean
6
34
  sourceMap?: boolean
35
+ parseOptions?: ParseOptions
7
36
  }
8
37
 
9
38
  export type SourceMapping = [number] | [number, number, number, number]
@@ -62,3 +91,13 @@ declare module "@danielx/civet/esbuild-plugin" {
62
91
  const plugin: ((options: Options) => Plugin) & Plugin
63
92
  export default plugin
64
93
  }
94
+
95
+ declare module "@danielx/civet/config" {
96
+ const Config: {
97
+ findConfig: (path: string) => Promise<string | null>
98
+ loadConfig: (
99
+ path: string
100
+ ) => Promise<import("@danielx/civet").CompileOptions>
101
+ }
102
+ export default Config
103
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@danielx/civet",
3
- "version": "0.6.7",
3
+ "version": "0.6.9",
4
4
  "description": "CoffeeScript style syntax for TypeScript",
5
5
  "main": "dist/main.js",
6
6
  "module": "dist/main.mjs",
@@ -13,6 +13,7 @@
13
13
  "./esbuild-plugin": "./dist/esbuild-plugin.js",
14
14
  "./bun-civet": "./dist/bun-civet.mjs",
15
15
  "./register": "./register.js",
16
+ "./config": "./dist/config.js",
16
17
  "./*": "./*",
17
18
  "./dist/*": "./dist/*"
18
19
  },