@danielx/civet 0.6.38 → 0.6.39

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/dist/browser.js CHANGED
@@ -7,7 +7,14 @@ var Civet = (() => {
7
7
  var __getProtoOf = Object.getPrototypeOf;
8
8
  var __hasOwnProp = Object.prototype.hasOwnProperty;
9
9
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
10
- var __commonJS = (cb, mod) => function __require() {
10
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
11
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
12
+ }) : x)(function(x) {
13
+ if (typeof require !== "undefined")
14
+ return require.apply(this, arguments);
15
+ throw new Error('Dynamic require of "' + x + '" is not supported');
16
+ });
17
+ var __commonJS = (cb, mod) => function __require2() {
11
18
  return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
12
19
  };
13
20
  var __export = (target, all) => {
@@ -7119,7 +7126,7 @@ ${input.slice(result.pos)}
7119
7126
  names: exp.names
7120
7127
  };
7121
7128
  });
7122
- var ArrayElementExpression$2 = $TS($S($E($S($E($S(__, DotDotDot, __)), ExtendedExpression)), $Y(ArrayElementDelimiter)), function($skip, $loc, $0, $1, $2) {
7129
+ var ArrayElementExpression$2 = $TS($S($E($S($E($S(__, DotDotDot, __)), PostfixedExpression)), $Y(ArrayElementDelimiter)), function($skip, $loc, $0, $1, $2) {
7123
7130
  var expMaybeSpread = $1;
7124
7131
  if (expMaybeSpread) {
7125
7132
  const [spread, exp] = expMaybeSpread;
@@ -8673,7 +8680,7 @@ ${input.slice(result.pos)}
8673
8680
  children: $0
8674
8681
  };
8675
8682
  });
8676
- var ForStatementParameters$1 = $TS($S(InsertOpenParen, __, $C(LexicalDeclaration, VariableStatement, $E(Expression)), __, Semicolon, $E(Expression), Semicolon, $E($S($N(EOS), Expression)), InsertCloseParen), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7, $8, $9) {
8683
+ var ForStatementParameters$1 = $TS($S(InsertOpenParen, __, $C(LexicalDeclaration, VariableStatement, $E(Expression)), __, Semicolon, $E(Expression), Semicolon, $E($S($N(EOS), ExpressionWithIndentedApplicationForbidden)), InsertCloseParen), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7, $8, $9) {
8677
8684
  var declaration = $3;
8678
8685
  return {
8679
8686
  declaration,
@@ -13991,15 +13998,55 @@ ${input.slice(result.pos)}
13991
13998
  if (filename.endsWith(".coffee") && !/^(#![^\r\n]*(\r\n|\n|\r))?\s*['"]civet/.test(src)) {
13992
13999
  options.parseOptions.coffeeCompat = true;
13993
14000
  }
14001
+ ;
14002
+ const { hits, trace, noCache } = options;
13994
14003
  let events;
13995
- if (!options.noCache) {
13996
- events = makeCache();
14004
+ if (!noCache) {
14005
+ events = makeCache({
14006
+ hits: !!hits,
14007
+ trace: !!trace
14008
+ });
14009
+ }
14010
+ let ast;
14011
+ try {
14012
+ parse.config = options.parseOptions || {};
14013
+ ast = prune(parse(src, {
14014
+ filename,
14015
+ events
14016
+ }));
14017
+ } finally {
14018
+ if (hits || trace) {
14019
+ import("fs").then(function({ writeFileSync }) {
14020
+ let ref;
14021
+ if ((ref = events?.meta) && "logs" in ref) {
14022
+ const { logs } = ref;
14023
+ if (trace) {
14024
+ writeFileSync(trace, logs.join("\n"));
14025
+ }
14026
+ }
14027
+ if (hits) {
14028
+ let ref1;
14029
+ if (ref1 = events?.meta.hits) {
14030
+ const hitData = ref1;
14031
+ let total = 0;
14032
+ const data = [...hitData.entries()];
14033
+ const counts = data.sort(([, a], [, b]) => b - a).map(([k, v]) => {
14034
+ total += v;
14035
+ return `${k}: ${v}`;
14036
+ }).join("\n");
14037
+ const hitSummary = `Total: ${total}
14038
+
14039
+ ${counts}`;
14040
+ return writeFileSync(hits, hitSummary);
14041
+ }
14042
+ ;
14043
+ return;
14044
+ }
14045
+ ;
14046
+ return;
14047
+ });
14048
+ }
13997
14049
  }
13998
- parse.config = options.parseOptions || {};
13999
- const ast = prune(parse(src, {
14000
- filename,
14001
- events
14002
- }));
14003
14050
  if (options.ast) {
14004
14051
  return ast;
14005
14052
  }
@@ -14022,22 +14069,45 @@ ${input.slice(result.pos)}
14022
14069
  }
14023
14070
  return result;
14024
14071
  }
14025
- function makeCache() {
14072
+ function makeCache({ hits, trace } = {}) {
14073
+ const meta = {};
14074
+ let hitCount;
14075
+ if (hits) {
14076
+ hitCount = /* @__PURE__ */ new Map();
14077
+ meta.hits = hitCount;
14078
+ }
14079
+ let logs;
14080
+ if (trace) {
14081
+ logs = [];
14082
+ meta.logs = logs;
14083
+ }
14026
14084
  const stateCache = new StateCache();
14027
14085
  let getStateKey = null;
14086
+ const stack = [];
14028
14087
  const events = {
14088
+ meta,
14029
14089
  enter: function(ruleName, state) {
14090
+ if (hits) {
14091
+ hitCount.set(ruleName, (hitCount.get(ruleName) || 0) + 1);
14092
+ }
14030
14093
  if (uncacheable.has(ruleName)) {
14031
14094
  return;
14032
14095
  }
14033
14096
  ;
14034
14097
  const key = [ruleName, state.pos, ...getStateKey()];
14035
14098
  if (stateCache.has(key)) {
14099
+ if (trace) {
14100
+ logs.push("".padStart(stack.length * 2, " ") + ruleName + ":" + state.pos + "\u{1F4B0}");
14101
+ }
14036
14102
  const result = stateCache.get(key);
14037
14103
  return {
14038
14104
  cache: result ? { ...result } : void 0
14039
14105
  };
14040
14106
  }
14107
+ if (trace) {
14108
+ logs.push("".padStart(stack.length * 2, " ") + ruleName + ":" + state.pos + "\u2192");
14109
+ stack.push(ruleName);
14110
+ }
14041
14111
  return;
14042
14112
  },
14043
14113
  exit: function(ruleName, state, result) {
@@ -14055,6 +14125,10 @@ ${input.slice(result.pos)}
14055
14125
  if (parse.config.verbose && result) {
14056
14126
  console.log(`Parsed ${JSON.stringify(state.input.slice(state.pos, result.pos))} [pos ${state.pos}-${result.pos}] as ${ruleName}`);
14057
14127
  }
14128
+ if (trace) {
14129
+ stack.pop();
14130
+ logs.push("".padStart(stack.length * 2, " ") + ruleName + ":" + state.pos + " " + (result ? "\u2705" : "\u274C"));
14131
+ }
14058
14132
  return;
14059
14133
  }
14060
14134
  };
package/dist/civet CHANGED
@@ -153,6 +153,14 @@ parseArgs = function(args) {
153
153
  options.js = true;
154
154
  break;
155
155
  }
156
+ case "--hits": {
157
+ options.hits = args[++i];
158
+ break;
159
+ }
160
+ case "--trace": {
161
+ options.trace = args[++i];
162
+ break;
163
+ }
156
164
  case "--": {
157
165
  endOfArgs(++i);
158
166
  break;
package/dist/config.js CHANGED
@@ -84,7 +84,7 @@ async function loadConfig(path2) {
84
84
  const js = (0, import_main.compile)(config, { js: true });
85
85
  let exports;
86
86
  try {
87
- exports = await import(`data:text/javascript,${js}`);
87
+ exports = await import(`data:text/javascript,${encodeURIComponent(js)}`);
88
88
  } catch (e) {
89
89
  console.error("Error loading config file", path2, e);
90
90
  }
package/dist/main.js CHANGED
@@ -7118,7 +7118,7 @@ var require_parser = __commonJS({
7118
7118
  names: exp.names
7119
7119
  };
7120
7120
  });
7121
- var ArrayElementExpression$2 = $TS($S($E($S($E($S(__, DotDotDot, __)), ExtendedExpression)), $Y(ArrayElementDelimiter)), function($skip, $loc, $0, $1, $2) {
7121
+ var ArrayElementExpression$2 = $TS($S($E($S($E($S(__, DotDotDot, __)), PostfixedExpression)), $Y(ArrayElementDelimiter)), function($skip, $loc, $0, $1, $2) {
7122
7122
  var expMaybeSpread = $1;
7123
7123
  if (expMaybeSpread) {
7124
7124
  const [spread, exp] = expMaybeSpread;
@@ -8672,7 +8672,7 @@ var require_parser = __commonJS({
8672
8672
  children: $0
8673
8673
  };
8674
8674
  });
8675
- var ForStatementParameters$1 = $TS($S(InsertOpenParen, __, $C(LexicalDeclaration, VariableStatement, $E(Expression)), __, Semicolon, $E(Expression), Semicolon, $E($S($N(EOS), Expression)), InsertCloseParen), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7, $8, $9) {
8675
+ var ForStatementParameters$1 = $TS($S(InsertOpenParen, __, $C(LexicalDeclaration, VariableStatement, $E(Expression)), __, Semicolon, $E(Expression), Semicolon, $E($S($N(EOS), ExpressionWithIndentedApplicationForbidden)), InsertCloseParen), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7, $8, $9) {
8676
8676
  var declaration = $3;
8677
8677
  return {
8678
8678
  declaration,
@@ -13991,15 +13991,55 @@ function compile(src, options) {
13991
13991
  if (filename.endsWith(".coffee") && !/^(#![^\r\n]*(\r\n|\n|\r))?\s*['"]civet/.test(src)) {
13992
13992
  options.parseOptions.coffeeCompat = true;
13993
13993
  }
13994
+ ;
13995
+ const { hits, trace, noCache } = options;
13994
13996
  let events;
13995
- if (!options.noCache) {
13996
- events = makeCache();
13997
+ if (!noCache) {
13998
+ events = makeCache({
13999
+ hits: !!hits,
14000
+ trace: !!trace
14001
+ });
14002
+ }
14003
+ let ast;
14004
+ try {
14005
+ parse.config = options.parseOptions || {};
14006
+ ast = prune(parse(src, {
14007
+ filename,
14008
+ events
14009
+ }));
14010
+ } finally {
14011
+ if (hits || trace) {
14012
+ import("fs").then(function({ writeFileSync }) {
14013
+ let ref;
14014
+ if ((ref = events?.meta) && "logs" in ref) {
14015
+ const { logs } = ref;
14016
+ if (trace) {
14017
+ writeFileSync(trace, logs.join("\n"));
14018
+ }
14019
+ }
14020
+ if (hits) {
14021
+ let ref1;
14022
+ if (ref1 = events?.meta.hits) {
14023
+ const hitData = ref1;
14024
+ let total = 0;
14025
+ const data = [...hitData.entries()];
14026
+ const counts = data.sort(([, a], [, b]) => b - a).map(([k, v]) => {
14027
+ total += v;
14028
+ return `${k}: ${v}`;
14029
+ }).join("\n");
14030
+ const hitSummary = `Total: ${total}
14031
+
14032
+ ${counts}`;
14033
+ return writeFileSync(hits, hitSummary);
14034
+ }
14035
+ ;
14036
+ return;
14037
+ }
14038
+ ;
14039
+ return;
14040
+ });
14041
+ }
13997
14042
  }
13998
- parse.config = options.parseOptions || {};
13999
- const ast = prune(parse(src, {
14000
- filename,
14001
- events
14002
- }));
14003
14043
  if (options.ast) {
14004
14044
  return ast;
14005
14045
  }
@@ -14022,22 +14062,45 @@ function compile(src, options) {
14022
14062
  }
14023
14063
  return result;
14024
14064
  }
14025
- function makeCache() {
14065
+ function makeCache({ hits, trace } = {}) {
14066
+ const meta = {};
14067
+ let hitCount;
14068
+ if (hits) {
14069
+ hitCount = /* @__PURE__ */ new Map();
14070
+ meta.hits = hitCount;
14071
+ }
14072
+ let logs;
14073
+ if (trace) {
14074
+ logs = [];
14075
+ meta.logs = logs;
14076
+ }
14026
14077
  const stateCache = new StateCache();
14027
14078
  let getStateKey = null;
14079
+ const stack = [];
14028
14080
  const events = {
14081
+ meta,
14029
14082
  enter: function(ruleName, state) {
14083
+ if (hits) {
14084
+ hitCount.set(ruleName, (hitCount.get(ruleName) || 0) + 1);
14085
+ }
14030
14086
  if (uncacheable.has(ruleName)) {
14031
14087
  return;
14032
14088
  }
14033
14089
  ;
14034
14090
  const key = [ruleName, state.pos, ...getStateKey()];
14035
14091
  if (stateCache.has(key)) {
14092
+ if (trace) {
14093
+ logs.push("".padStart(stack.length * 2, " ") + ruleName + ":" + state.pos + "\u{1F4B0}");
14094
+ }
14036
14095
  const result = stateCache.get(key);
14037
14096
  return {
14038
14097
  cache: result ? { ...result } : void 0
14039
14098
  };
14040
14099
  }
14100
+ if (trace) {
14101
+ logs.push("".padStart(stack.length * 2, " ") + ruleName + ":" + state.pos + "\u2192");
14102
+ stack.push(ruleName);
14103
+ }
14041
14104
  return;
14042
14105
  },
14043
14106
  exit: function(ruleName, state, result) {
@@ -14055,6 +14118,10 @@ function makeCache() {
14055
14118
  if (parse.config.verbose && result) {
14056
14119
  console.log(`Parsed ${JSON.stringify(state.input.slice(state.pos, result.pos))} [pos ${state.pos}-${result.pos}] as ${ruleName}`);
14057
14120
  }
14121
+ if (trace) {
14122
+ stack.pop();
14123
+ logs.push("".padStart(stack.length * 2, " ") + ruleName + ":" + state.pos + " " + (result ? "\u2705" : "\u274C"));
14124
+ }
14058
14125
  return;
14059
14126
  }
14060
14127
  };
package/dist/main.mjs CHANGED
@@ -7116,7 +7116,7 @@ var require_parser = __commonJS({
7116
7116
  names: exp.names
7117
7117
  };
7118
7118
  });
7119
- var ArrayElementExpression$2 = $TS($S($E($S($E($S(__, DotDotDot, __)), ExtendedExpression)), $Y(ArrayElementDelimiter)), function($skip, $loc, $0, $1, $2) {
7119
+ var ArrayElementExpression$2 = $TS($S($E($S($E($S(__, DotDotDot, __)), PostfixedExpression)), $Y(ArrayElementDelimiter)), function($skip, $loc, $0, $1, $2) {
7120
7120
  var expMaybeSpread = $1;
7121
7121
  if (expMaybeSpread) {
7122
7122
  const [spread, exp] = expMaybeSpread;
@@ -8670,7 +8670,7 @@ var require_parser = __commonJS({
8670
8670
  children: $0
8671
8671
  };
8672
8672
  });
8673
- var ForStatementParameters$1 = $TS($S(InsertOpenParen, __, $C(LexicalDeclaration, VariableStatement, $E(Expression)), __, Semicolon, $E(Expression), Semicolon, $E($S($N(EOS), Expression)), InsertCloseParen), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7, $8, $9) {
8673
+ var ForStatementParameters$1 = $TS($S(InsertOpenParen, __, $C(LexicalDeclaration, VariableStatement, $E(Expression)), __, Semicolon, $E(Expression), Semicolon, $E($S($N(EOS), ExpressionWithIndentedApplicationForbidden)), InsertCloseParen), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7, $8, $9) {
8674
8674
  var declaration = $3;
8675
8675
  return {
8676
8676
  declaration,
@@ -13978,15 +13978,55 @@ function compile(src, options) {
13978
13978
  if (filename.endsWith(".coffee") && !/^(#![^\r\n]*(\r\n|\n|\r))?\s*['"]civet/.test(src)) {
13979
13979
  options.parseOptions.coffeeCompat = true;
13980
13980
  }
13981
+ ;
13982
+ const { hits, trace, noCache } = options;
13981
13983
  let events;
13982
- if (!options.noCache) {
13983
- events = makeCache();
13984
+ if (!noCache) {
13985
+ events = makeCache({
13986
+ hits: !!hits,
13987
+ trace: !!trace
13988
+ });
13989
+ }
13990
+ let ast;
13991
+ try {
13992
+ parse.config = options.parseOptions || {};
13993
+ ast = prune(parse(src, {
13994
+ filename,
13995
+ events
13996
+ }));
13997
+ } finally {
13998
+ if (hits || trace) {
13999
+ import("fs").then(function({ writeFileSync }) {
14000
+ let ref;
14001
+ if ((ref = events?.meta) && "logs" in ref) {
14002
+ const { logs } = ref;
14003
+ if (trace) {
14004
+ writeFileSync(trace, logs.join("\n"));
14005
+ }
14006
+ }
14007
+ if (hits) {
14008
+ let ref1;
14009
+ if (ref1 = events?.meta.hits) {
14010
+ const hitData = ref1;
14011
+ let total = 0;
14012
+ const data = [...hitData.entries()];
14013
+ const counts = data.sort(([, a], [, b]) => b - a).map(([k, v]) => {
14014
+ total += v;
14015
+ return `${k}: ${v}`;
14016
+ }).join("\n");
14017
+ const hitSummary = `Total: ${total}
14018
+
14019
+ ${counts}`;
14020
+ return writeFileSync(hits, hitSummary);
14021
+ }
14022
+ ;
14023
+ return;
14024
+ }
14025
+ ;
14026
+ return;
14027
+ });
14028
+ }
13984
14029
  }
13985
- parse.config = options.parseOptions || {};
13986
- const ast = prune(parse(src, {
13987
- filename,
13988
- events
13989
- }));
13990
14030
  if (options.ast) {
13991
14031
  return ast;
13992
14032
  }
@@ -14009,22 +14049,45 @@ function compile(src, options) {
14009
14049
  }
14010
14050
  return result;
14011
14051
  }
14012
- function makeCache() {
14052
+ function makeCache({ hits, trace } = {}) {
14053
+ const meta = {};
14054
+ let hitCount;
14055
+ if (hits) {
14056
+ hitCount = /* @__PURE__ */ new Map();
14057
+ meta.hits = hitCount;
14058
+ }
14059
+ let logs;
14060
+ if (trace) {
14061
+ logs = [];
14062
+ meta.logs = logs;
14063
+ }
14013
14064
  const stateCache = new StateCache();
14014
14065
  let getStateKey = null;
14066
+ const stack = [];
14015
14067
  const events = {
14068
+ meta,
14016
14069
  enter: function(ruleName, state) {
14070
+ if (hits) {
14071
+ hitCount.set(ruleName, (hitCount.get(ruleName) || 0) + 1);
14072
+ }
14017
14073
  if (uncacheable.has(ruleName)) {
14018
14074
  return;
14019
14075
  }
14020
14076
  ;
14021
14077
  const key = [ruleName, state.pos, ...getStateKey()];
14022
14078
  if (stateCache.has(key)) {
14079
+ if (trace) {
14080
+ logs.push("".padStart(stack.length * 2, " ") + ruleName + ":" + state.pos + "\u{1F4B0}");
14081
+ }
14023
14082
  const result = stateCache.get(key);
14024
14083
  return {
14025
14084
  cache: result ? { ...result } : void 0
14026
14085
  };
14027
14086
  }
14087
+ if (trace) {
14088
+ logs.push("".padStart(stack.length * 2, " ") + ruleName + ":" + state.pos + "\u2192");
14089
+ stack.push(ruleName);
14090
+ }
14028
14091
  return;
14029
14092
  },
14030
14093
  exit: function(ruleName, state, result) {
@@ -14042,6 +14105,10 @@ function makeCache() {
14042
14105
  if (parse.config.verbose && result) {
14043
14106
  console.log(`Parsed ${JSON.stringify(state.input.slice(state.pos, result.pos))} [pos ${state.pos}-${result.pos}] as ${ruleName}`);
14044
14107
  }
14108
+ if (trace) {
14109
+ stack.pop();
14110
+ logs.push("".padStart(stack.length * 2, " ") + ruleName + ":" + state.pos + " " + (result ? "\u2705" : "\u274C"));
14111
+ }
14045
14112
  return;
14046
14113
  }
14047
14114
  };
@@ -35,10 +35,13 @@ __export(ts_diagnostic_exports, {
35
35
  remapRange: () => remapRange
36
36
  });
37
37
  module.exports = __toCommonJS(ts_diagnostic_exports);
38
- var import_typescript = __toESM(require("typescript"));
39
38
  var import_vscode_languageserver = __toESM(require("vscode-languageserver"));
40
39
  var import_vscode_languageserver_textdocument = require("vscode-languageserver-textdocument");
41
- const { DiagnosticCategory } = import_typescript.default;
40
+ let DiagnosticCategory = {};
41
+ DiagnosticCategory[DiagnosticCategory["Warning"] = 0] = "Warning";
42
+ DiagnosticCategory[DiagnosticCategory["Error"] = 1] = "Error";
43
+ DiagnosticCategory[DiagnosticCategory["Suggestion"] = 2] = "Suggestion";
44
+ DiagnosticCategory[DiagnosticCategory["Message"] = 3] = "Message";
42
45
  function remapPosition(position, sourcemapLines) {
43
46
  if (!sourcemapLines)
44
47
  return position;
@@ -1,7 +1,10 @@
1
- import ts from "typescript";
1
+ let DiagnosticCategory = {};
2
+ DiagnosticCategory[DiagnosticCategory["Warning"] = 0] = "Warning";
3
+ DiagnosticCategory[DiagnosticCategory["Error"] = 1] = "Error";
4
+ DiagnosticCategory[DiagnosticCategory["Suggestion"] = 2] = "Suggestion";
5
+ DiagnosticCategory[DiagnosticCategory["Message"] = 3] = "Message";
2
6
  import vs, { DiagnosticSeverity, Position, Range } from "vscode-languageserver";
3
7
  import { TextDocument } from "vscode-languageserver-textdocument";
4
- const { DiagnosticCategory } = ts;
5
8
  function remapPosition(position, sourcemapLines) {
6
9
  if (!sourcemapLines)
7
10
  return position;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@danielx/civet",
3
3
  "type": "commonjs",
4
- "version": "0.6.38",
4
+ "version": "0.6.39",
5
5
  "description": "CoffeeScript style syntax for TypeScript",
6
6
  "main": "dist/main.js",
7
7
  "module": "dist/main.mjs",
@@ -70,7 +70,7 @@
70
70
  "unplugin": "^1.4.0"
71
71
  },
72
72
  "devDependencies": {
73
- "@danielx/civet": "0.6.34",
73
+ "@danielx/civet": "0.6.38",
74
74
  "@danielx/hera": "^0.8.10",
75
75
  "@types/assert": "^1.5.6",
76
76
  "@types/mocha": "^9.1.1",