@mojir/lits 1.2.2-alpha.6 → 1.3.0

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.
Files changed (53) hide show
  1. package/dist/cli/cli.js +541 -1125
  2. package/dist/cli/src/Lits/Lits.d.ts +1 -6
  3. package/dist/cli/src/index.d.ts +3 -8
  4. package/dist/cli/src/tokenizer/tokenizers.d.ts +1 -0
  5. package/dist/index.esm.js +18 -7442
  6. package/dist/index.esm.js.map +1 -1
  7. package/dist/index.js +17 -7452
  8. package/dist/index.js.map +1 -1
  9. package/dist/lits.iife.js +17 -7452
  10. package/dist/lits.iife.js.map +1 -1
  11. package/dist/src/Lits/Lits.d.ts +1 -6
  12. package/dist/src/index.d.ts +3 -8
  13. package/dist/src/tokenizer/tokenizers.d.ts +1 -0
  14. package/dist/testFramework.esm.js +3 -586
  15. package/dist/testFramework.esm.js.map +1 -1
  16. package/dist/testFramework.js +3 -586
  17. package/dist/testFramework.js.map +1 -1
  18. package/package.json +1 -1
  19. package/dist/cli/src/identifier.d.ts +0 -8
  20. package/dist/cli/src/transformer/index.d.ts +0 -2
  21. package/dist/cli/src/unparser/UnparseOptions.d.ts +0 -15
  22. package/dist/cli/src/unparser/unparse.d.ts +0 -5
  23. package/dist/cli/src/unparser/unparseArrayLiteral.d.ts +0 -3
  24. package/dist/cli/src/unparser/unparseBindings.d.ts +0 -3
  25. package/dist/cli/src/unparser/unparseNormalExpression.d.ts +0 -3
  26. package/dist/cli/src/unparser/unparseObjectLiteral.d.ts +0 -3
  27. package/dist/cli/src/unparser/unparseParams.d.ts +0 -17
  28. package/dist/cli/src/unparser/unparseSpecialExpression/index.d.ts +0 -3
  29. package/dist/cli/src/unparser/unparseSpecialExpression/unparseCond.d.ts +0 -3
  30. package/dist/cli/src/unparser/unparseSpecialExpression/unparseDo.d.ts +0 -3
  31. package/dist/cli/src/unparser/unparseSpecialExpression/unparseIfLet.d.ts +0 -3
  32. package/dist/cli/src/unparser/unparseSpecialExpression/unparseIfOrWhenLike.d.ts +0 -6
  33. package/dist/cli/src/unparser/unparseSpecialExpression/unparseLet.d.ts +0 -3
  34. package/dist/cli/src/unparser/utils.d.ts +0 -5
  35. package/dist/cli/src/untokenizer/index.d.ts +0 -2
  36. package/dist/src/identifier.d.ts +0 -8
  37. package/dist/src/transformer/index.d.ts +0 -2
  38. package/dist/src/unparser/UnparseOptions.d.ts +0 -15
  39. package/dist/src/unparser/__tests__/testFormatter.d.ts +0 -1
  40. package/dist/src/unparser/unparse.d.ts +0 -5
  41. package/dist/src/unparser/unparseArrayLiteral.d.ts +0 -3
  42. package/dist/src/unparser/unparseBindings.d.ts +0 -3
  43. package/dist/src/unparser/unparseNormalExpression.d.ts +0 -3
  44. package/dist/src/unparser/unparseObjectLiteral.d.ts +0 -3
  45. package/dist/src/unparser/unparseParams.d.ts +0 -17
  46. package/dist/src/unparser/unparseSpecialExpression/index.d.ts +0 -3
  47. package/dist/src/unparser/unparseSpecialExpression/unparseCond.d.ts +0 -3
  48. package/dist/src/unparser/unparseSpecialExpression/unparseDo.d.ts +0 -3
  49. package/dist/src/unparser/unparseSpecialExpression/unparseIfLet.d.ts +0 -3
  50. package/dist/src/unparser/unparseSpecialExpression/unparseIfOrWhenLike.d.ts +0 -6
  51. package/dist/src/unparser/unparseSpecialExpression/unparseLet.d.ts +0 -3
  52. package/dist/src/unparser/utils.d.ts +0 -5
  53. package/dist/src/untokenizer/index.d.ts +0 -2
package/dist/cli/cli.js CHANGED
@@ -92,7 +92,7 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
92
92
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
93
93
  };
94
94
 
95
- var version = "1.2.2-alpha.6";
95
+ var version = "1.3.0";
96
96
 
97
97
  var AstNodeType;
98
98
  (function (AstNodeType) {
@@ -7450,11 +7450,9 @@ function getSugar() {
7450
7450
  return [applyCollectionAccessors];
7451
7451
  }
7452
7452
 
7453
- var identifierCharacterClass = '[\\w@%^?=!$<>+*/:-]';
7454
- var identifierFirstCharacterClass = '[a-zA-Z_@%^?=!$<>+*/-]';
7455
-
7456
7453
  var NO_MATCH = [0, undefined];
7457
- var nameRegExp$1 = new RegExp(identifierCharacterClass);
7454
+ var nameCharacters = '[\\w@%^?=!$<>+*/-]';
7455
+ var nameRegExp$1 = new RegExp(nameCharacters);
7458
7456
  var whitespaceRegExp = /\s|,/;
7459
7457
  var newLineRegExp = /\n/;
7460
7458
  var tokenizeNewLine = function (input, current, debugData) {
@@ -8021,575 +8019,6 @@ function assertNewLineToken(token) {
8021
8019
  throw new LitsError("Expected newline token, got ".concat(token === null || token === void 0 ? void 0 : token.t, "."));
8022
8020
  }
8023
8021
 
8024
- function transformTokens(tokenStram, transformer) {
8025
- return __assign(__assign({}, tokenStram), { tokens: tokenStram.tokens.map(function (token) {
8026
- return __assign(__assign({}, token), { v: transformer(token.v) });
8027
- }) });
8028
- }
8029
-
8030
- var UnparseOptions = /** @class */ (function () {
8031
- function UnparseOptions(unparse, lineLength, col, inlined, locked) {
8032
- if (col === void 0) { col = 0; }
8033
- if (inlined === void 0) { inlined = false; }
8034
- if (locked === void 0) { locked = false; }
8035
- this.unparse = unparse;
8036
- this.lineLength = lineLength;
8037
- this.col = col;
8038
- this.inlined = inlined;
8039
- this.locked = locked;
8040
- this.indent = ' '.repeat(col);
8041
- }
8042
- UnparseOptions.prototype.inc = function (count) {
8043
- if (count === void 0) { count = 1; }
8044
- return new UnparseOptions(this.unparse, this.lineLength, this.col + count, this.inlined, this.locked);
8045
- };
8046
- UnparseOptions.prototype.inline = function () {
8047
- return new UnparseOptions(this.unparse, this.lineLength, this.col, true, this.locked);
8048
- };
8049
- UnparseOptions.prototype.noInline = function () {
8050
- return new UnparseOptions(this.unparse, this.lineLength, this.col, false, this.locked);
8051
- };
8052
- UnparseOptions.prototype.lock = function () {
8053
- return new UnparseOptions(this.unparse, this.lineLength, this.col, this.inlined, true);
8054
- };
8055
- UnparseOptions.prototype.assertNotOverflown = function (value) {
8056
- var _this = this;
8057
- value.split('\n').forEach(function (line, index) {
8058
- var fullLine = (index === 0 && _this.inlined) ? _this.indent + line : line;
8059
- var length = fullLine.length;
8060
- if (length > _this.lineLength)
8061
- throw new Error("Line length exceeded ".concat(_this.lineLength, " chars, value: \"").concat(fullLine, "\" (").concat(fullLine.length, " chars)"));
8062
- });
8063
- return value;
8064
- };
8065
- return UnparseOptions;
8066
- }());
8067
-
8068
- function ensureNewlineSeparator(a, b) {
8069
- return !a || !b || a.endsWith('\n') || b.startsWith('\n') ? "".concat(a).concat(b) : "".concat(a, "\n").concat(b);
8070
- }
8071
- function ensureSpaceSeparator(a, b) {
8072
- return !a || !b || a.endsWith(' ') || b.startsWith(' ') || b.startsWith('\n')
8073
- ? "".concat(a).concat(b)
8074
- : "".concat(a, " ").concat(b);
8075
- }
8076
- function applyMetaTokens(value, metaTokens, options) {
8077
- if (!metaTokens) {
8078
- return "".concat(options.inlined ? '' : options.indent).concat(value);
8079
- }
8080
- else {
8081
- var result = "".concat(metaTokensToString(metaTokens.leadingMetaTokens, value)).concat(value).concat((metaTokens === null || metaTokens === void 0 ? void 0 : metaTokens.inlineCommentToken) ? " ".concat(metaTokens.inlineCommentToken.v, "\n") : '');
8082
- return result.split('\n').map(function (line, index) {
8083
- return "".concat(line && (!options.inlined || index > 0) ? options.indent : '').concat(line);
8084
- }).join('\n');
8085
- }
8086
- }
8087
- function metaTokensToString(metaTokens, tokenValue) {
8088
- var isEndBracket = tokenValue === ')' || tokenValue === ']' || tokenValue === '}';
8089
- var isOnlyNewLine = metaTokens.length === 1 && isNewLineToken(metaTokens[0]);
8090
- if (isEndBracket && isOnlyNewLine)
8091
- return '';
8092
- return metaTokens.map(function (metaToken) {
8093
- return isNewLineToken(metaToken) ? metaToken.v : "".concat(metaToken.v, "\n");
8094
- }).join('');
8095
- }
8096
-
8097
- function unparseParams(_a) {
8098
- var params = _a.params, options = _a.options, prefix = _a.prefix, inline = _a.inline, endBracket = _a.endBracket, _b = _a.body, body = _b === void 0 ? false : _b, _c = _a.name, name = _c === void 0 ? '' : _c, _d = _a.noMultilineInline, noMultilineInline = _d === void 0 ? false : _d, _e = _a.pairs, pairs = _e === void 0 ? false : _e;
8099
- // If no parameters, return the expression with brackets
8100
- if (params.length === 0)
8101
- return "".concat(prefix).concat(endBracket);
8102
- // 1. Try to unparse the parameters as a single line
8103
- try {
8104
- var unparsedParams = pairs
8105
- ? unparseSingleLinePairs(params, options.inline().lock())
8106
- : unparseSingleLineParams(params, options.inline().lock());
8107
- if (!unparsedParams.includes('\n'))
8108
- return options.assertNotOverflown("".concat(prefix, " ").concat(unparsedParams).concat(endBracket));
8109
- }
8110
- catch (error) {
8111
- // If locked, we do not try anything else
8112
- if (options.locked)
8113
- throw error;
8114
- }
8115
- if (pairs) {
8116
- if (name && !name.includes('\n')) {
8117
- try {
8118
- var unparsedParams = unparseMultilinePairwise(params, options.inline().inc(name.length + 2).lock());
8119
- var result = options.assertNotOverflown("".concat(prefix, " ").concat(unparsedParams).concat(endBracket));
8120
- return result;
8121
- }
8122
- catch (_f) {
8123
- }
8124
- }
8125
- try {
8126
- var unparsedParams = unparseMultilinePairwise(params, options.noInline().inc(body ? 2 : 1));
8127
- return options.assertNotOverflown(ensureNewlineSeparator(prefix, "".concat(unparsedParams).concat(endBracket)));
8128
- }
8129
- catch (_g) {
8130
- }
8131
- }
8132
- // 2. Try to unparse the parameters in multiple lines, first parameter on the same line
8133
- // e.g. (round 1 2 3 4 5)
8134
- // ==> (round 1
8135
- // 2
8136
- // 3
8137
- // 4
8138
- // 5)
8139
- else if (inline) {
8140
- var newOptions = options.inc(name.length + 2).lock();
8141
- try {
8142
- var firstParam = options.unparse(params[0], noMultilineInline ? newOptions.noInline() : newOptions.inline());
8143
- // If the first parameter is multiline, fallback to option 3
8144
- if (!firstParam.startsWith('\n')) {
8145
- var indentedParams = unparseMultilineParams(params.slice(1), newOptions.noInline());
8146
- return noMultilineInline
8147
- ? options.assertNotOverflown("".concat(ensureNewlineSeparator(prefix, ensureNewlineSeparator(firstParam, indentedParams))).concat(endBracket))
8148
- : options.assertNotOverflown("".concat(prefix, " ").concat(ensureNewlineSeparator(firstParam, indentedParams)).concat(endBracket));
8149
- }
8150
- }
8151
- catch (_h) {
8152
- // Try option 3
8153
- }
8154
- }
8155
- // 3. Try to unparse the parameters in multiple lines
8156
- // e.g. (round 1 2 3 4 5)
8157
- // ==> (round
8158
- // 1
8159
- // 2
8160
- // 3
8161
- // 4
8162
- // 5)
8163
- return "".concat(ensureNewlineSeparator(prefix, unparseMultilineParams(params, options.noInline().inc(body ? 2 : 1)))).concat(endBracket);
8164
- }
8165
- function unparseSingleLineParams(params, options) {
8166
- return params.reduce(function (acc, param) {
8167
- return ensureSpaceSeparator(acc, options.unparse(param, options.inline()));
8168
- }, '');
8169
- }
8170
- function unparseSingleLinePairs(params, options) {
8171
- return params.reduce(function (acc, param, index) {
8172
- if (index > 0 && index % 2 === 0)
8173
- acc += ',';
8174
- return ensureSpaceSeparator(acc, options.unparse(param, options.inline()));
8175
- }, '');
8176
- }
8177
- function unparseMultilineParams(params, options) {
8178
- return params.reduce(function (acc, param, index) { return ensureNewlineSeparator(acc, options.unparse(param, index === 0 && options.inlined ? options.inline() : options.noInline())); }, '');
8179
- }
8180
- function unparseMultilinePairwise(params, options) {
8181
- var keyLength;
8182
- return params.reduce(function (acc, param, index) {
8183
- var _a, _b;
8184
- if (index % 2 === 0) {
8185
- var key = options.unparse(param, options.inline());
8186
- var leadingMetaTokens = (_b = (_a = param.debugData) === null || _a === void 0 ? void 0 : _a.token.debugData) === null || _b === void 0 ? void 0 : _b.metaTokens.leadingMetaTokens;
8187
- if (index === 0 && options.inlined && leadingMetaTokens && leadingMetaTokens.length > 0)
8188
- throw new Error('First key with leading meta tokens is not allowed.');
8189
- key = key.trimStart();
8190
- keyLength = key.length;
8191
- key = index === 0 && options.inlined ? key : "".concat(options.indent).concat(key);
8192
- if (key.includes('\n'))
8193
- throw new Error('Key with new line character is not allowed.');
8194
- return index > 0 ? ensureNewlineSeparator(acc, key) : "".concat(acc).concat(key);
8195
- }
8196
- else {
8197
- var value = options.unparse(param, options.inline().inc(keyLength + 1));
8198
- return ensureSpaceSeparator(acc, value);
8199
- }
8200
- }, '');
8201
- }
8202
-
8203
- function unparseArrayLiteral(node, options) {
8204
- var _a, _b, _c, _d, _e;
8205
- var startBracket = applyMetaTokens('[', (_b = (_a = node.debugData) === null || _a === void 0 ? void 0 : _a.token.debugData) === null || _b === void 0 ? void 0 : _b.metaTokens, options);
8206
- var endBracket = applyMetaTokens(']', (_e = (_d = (_c = node.debugData) === null || _c === void 0 ? void 0 : _c.lastToken) === null || _d === void 0 ? void 0 : _d.debugData) === null || _e === void 0 ? void 0 : _e.metaTokens, options.inline());
8207
- // If no parameters, return empty array literal
8208
- if (node.p.length === 0)
8209
- return "".concat(startBracket).concat(endBracket);
8210
- var firstElementOptions = startBracket.endsWith('\n') ? options.noInline().inc() : options.inline().inc();
8211
- var unparsedFirstElement = options.unparse(node.p[0], firstElementOptions);
8212
- var params = node.p.slice(1);
8213
- var prefix = startBracket + unparsedFirstElement;
8214
- // 1. Try to unparse the parameters
8215
- try {
8216
- var unparsedParams = unparseSingleLineParams(params, options.inline().lock());
8217
- if (!unparsedParams.includes('\n')) {
8218
- return options.assertNotOverflown("".concat(ensureSpaceSeparator(prefix, unparsedParams)).concat(endBracket));
8219
- }
8220
- }
8221
- catch (error) {
8222
- // If locked, we do not try anything else
8223
- if (options.locked)
8224
- throw error;
8225
- }
8226
- // 2. Try to unparse the parameters in multiple lines
8227
- // e.g. [1 2 3 4 5]
8228
- // ==> [
8229
- // 1
8230
- // 2
8231
- // 3
8232
- // 4
8233
- // 5]
8234
- return "".concat(ensureNewlineSeparator(prefix, unparseMultilineParams(params, options.noInline().inc()))).concat(endBracket);
8235
- }
8236
-
8237
- function unparseObjectLiteral(node, options) {
8238
- var _a, _b, _c, _d, _e;
8239
- var startBracket = applyMetaTokens('{', (_b = (_a = node.debugData) === null || _a === void 0 ? void 0 : _a.token.debugData) === null || _b === void 0 ? void 0 : _b.metaTokens, options);
8240
- var endBracket = applyMetaTokens('}', (_e = (_d = (_c = node.debugData) === null || _c === void 0 ? void 0 : _c.lastToken) === null || _d === void 0 ? void 0 : _d.debugData) === null || _e === void 0 ? void 0 : _e.metaTokens, options.inline());
8241
- // If no parameters, return empty object literal
8242
- if (node.p.length === 0)
8243
- return "".concat(startBracket).concat(endBracket);
8244
- var params = node.p;
8245
- if (!startBracket.endsWith('\n')) {
8246
- // 1. Try to unparse the parameters as one line
8247
- try {
8248
- var unparsedParams = unparseSingleLinePairs(params, options.inline().lock());
8249
- if (!unparsedParams.includes('\n')) {
8250
- var result = "".concat(startBracket).concat(unparsedParams).concat(endBracket);
8251
- return options.assertNotOverflown(result);
8252
- }
8253
- }
8254
- catch (error) {
8255
- // If locked, we do not try anything else
8256
- if (options.locked)
8257
- throw error;
8258
- }
8259
- }
8260
- // 2. Try to unparse the parameters pairwise on multiple lines
8261
- // e.g. {:a 1 :b 2 :c 3 :d 4 :e 5}
8262
- // ==> {:a 1
8263
- // :b 2
8264
- // :c 3
8265
- // :d 4
8266
- // :e 5}
8267
- var multilineOptions = startBracket.endsWith('\n') ? options.noInline().inc() : options.inline().inc();
8268
- try {
8269
- var paiwise = unparseMultilinePairwise(params, multilineOptions);
8270
- var result = "".concat(startBracket).concat(paiwise).concat(endBracket);
8271
- return options.assertNotOverflown(result);
8272
- }
8273
- catch (_f) {
8274
- // Continue to the next step
8275
- }
8276
- // 3. Try to unparse the parameters in multiple lines
8277
- return startBracket + unparseMultilineParams(node.p, multilineOptions) + endBracket;
8278
- }
8279
-
8280
- function unparseNormalExpression(node, options) {
8281
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
8282
- if (isNormalExpressionNode(node)) {
8283
- if (((_a = node.debugData) === null || _a === void 0 ? void 0 : _a.token.t) === TokenType.Bracket && node.debugData.token.v === '[')
8284
- return unparseArrayLiteral(node, options);
8285
- else if (((_b = node.debugData) === null || _b === void 0 ? void 0 : _b.token.t) === TokenType.Bracket && node.debugData.token.v === '{')
8286
- return unparseObjectLiteral(node, options);
8287
- }
8288
- var startBracket = applyMetaTokens('(', (_d = (_c = node.debugData) === null || _c === void 0 ? void 0 : _c.token.debugData) === null || _d === void 0 ? void 0 : _d.metaTokens, options);
8289
- var endBracket = applyMetaTokens(')', (_g = (_f = (_e = node.debugData) === null || _e === void 0 ? void 0 : _e.lastToken) === null || _f === void 0 ? void 0 : _f.debugData) === null || _g === void 0 ? void 0 : _g.metaTokens, options.inline());
8290
- // if expression node e.g. ("Albert" 2), first parameter is the name ("Albert")
8291
- var nameOptions = startBracket.endsWith('\n') ? options.noInline().inc() : options.inline().inc();
8292
- var name = node.n
8293
- ? applyMetaTokens(node.n, (_k = (_j = (_h = node.debugData) === null || _h === void 0 ? void 0 : _h.nameToken) === null || _j === void 0 ? void 0 : _j.debugData) === null || _k === void 0 ? void 0 : _k.metaTokens, nameOptions)
8294
- : options.unparse(node.p[0], nameOptions);
8295
- var params = node.n ? node.p : node.p.slice(1);
8296
- var prefix = startBracket + name;
8297
- var inline = !name.includes('\n');
8298
- return unparseParams({ params: params, options: options, prefix: prefix, inline: inline, name: name, endBracket: endBracket });
8299
- }
8300
-
8301
- function unparseCond(node, options) {
8302
- var _a, _b, _c, _d, _e, _f, _g, _h;
8303
- var startBracket = applyMetaTokens('(', (_b = (_a = node.debugData) === null || _a === void 0 ? void 0 : _a.token.debugData) === null || _b === void 0 ? void 0 : _b.metaTokens, options);
8304
- var endBracket = applyMetaTokens(')', (_e = (_d = (_c = node.debugData) === null || _c === void 0 ? void 0 : _c.lastToken) === null || _d === void 0 ? void 0 : _d.debugData) === null || _e === void 0 ? void 0 : _e.metaTokens, options.inline());
8305
- var name = applyMetaTokens(node.n, (_h = (_g = (_f = node.debugData) === null || _f === void 0 ? void 0 : _f.nameToken) === null || _g === void 0 ? void 0 : _g.debugData) === null || _h === void 0 ? void 0 : _h.metaTokens, options.inline());
8306
- var prefix = startBracket + name;
8307
- var inline = !name.includes('\n');
8308
- return unparseParams({
8309
- params: node.p,
8310
- options: options,
8311
- prefix: prefix,
8312
- inline: inline,
8313
- name: name,
8314
- endBracket: endBracket,
8315
- body: true,
8316
- pairs: true,
8317
- });
8318
- }
8319
-
8320
- function unparseDo(node, options) {
8321
- var _a, _b, _c, _d, _e, _f, _g, _h;
8322
- var startBracket = applyMetaTokens('(', (_b = (_a = node.debugData) === null || _a === void 0 ? void 0 : _a.token.debugData) === null || _b === void 0 ? void 0 : _b.metaTokens, options);
8323
- var endBracket = applyMetaTokens(')', (_e = (_d = (_c = node.debugData) === null || _c === void 0 ? void 0 : _c.lastToken) === null || _d === void 0 ? void 0 : _d.debugData) === null || _e === void 0 ? void 0 : _e.metaTokens, options.inline());
8324
- var name = applyMetaTokens(node.n, (_h = (_g = (_f = node.debugData) === null || _f === void 0 ? void 0 : _f.nameToken) === null || _g === void 0 ? void 0 : _g.debugData) === null || _h === void 0 ? void 0 : _h.metaTokens, options.inline());
8325
- var prefix = startBracket + name;
8326
- var inline = !name.includes('\n');
8327
- return unparseParams({
8328
- params: node.p,
8329
- options: options,
8330
- prefix: prefix,
8331
- inline: inline,
8332
- name: name,
8333
- endBracket: endBracket,
8334
- body: true,
8335
- });
8336
- }
8337
-
8338
- function unparseBindings(node, options) {
8339
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
8340
- var startBracket = applyMetaTokens('[', (_b = (_a = node.debugData) === null || _a === void 0 ? void 0 : _a.token.debugData) === null || _b === void 0 ? void 0 : _b.metaTokens, options);
8341
- // If no parameters, return empty array literal
8342
- if (node.p.length === 0) {
8343
- var endBracket = applyMetaTokens(']', (_e = (_d = (_c = node.debugData) === null || _c === void 0 ? void 0 : _c.lastToken) === null || _d === void 0 ? void 0 : _d.debugData) === null || _e === void 0 ? void 0 : _e.metaTokens, options.inline());
8344
- return "".concat(startBracket).concat(endBracket);
8345
- }
8346
- var params = node.p;
8347
- // 1. Try to unparse the bindings as one line
8348
- try {
8349
- var unparsedParams = unparseSingleLinePairs(params, options.inline().lock());
8350
- var endBracket = applyMetaTokens(']', (_h = (_g = (_f = node.debugData) === null || _f === void 0 ? void 0 : _f.lastToken) === null || _g === void 0 ? void 0 : _g.debugData) === null || _h === void 0 ? void 0 : _h.metaTokens, options.inline());
8351
- if (!unparsedParams.includes('\n')) {
8352
- var result = "".concat(startBracket).concat(unparsedParams).concat(endBracket);
8353
- return options.assertNotOverflown(result);
8354
- }
8355
- }
8356
- catch (error) {
8357
- // If locked, we do not try anything else
8358
- if (options.locked)
8359
- throw error;
8360
- }
8361
- // 2. Try to unparse the bindings pairwise on multiple lines
8362
- // e.g. [a 1 b 2]
8363
- // ==> [a 1
8364
- // b 2]
8365
- try {
8366
- var endBracket = applyMetaTokens(']', (_l = (_k = (_j = node.debugData) === null || _j === void 0 ? void 0 : _j.lastToken) === null || _k === void 0 ? void 0 : _k.debugData) === null || _l === void 0 ? void 0 : _l.metaTokens, options.inline());
8367
- var result = startBracket + unparseMultilinePairwise(params, options.inline().inc()) + endBracket;
8368
- return options.assertNotOverflown(result);
8369
- }
8370
- catch (_t) {
8371
- // 2. Unparse the bindings on multiple lines
8372
- // e.g. [a 1 b 2]
8373
- // ==> [a
8374
- // 1,
8375
- // b
8376
- // 2]
8377
- var unparsedParams = unparseMultilineParams(params, options.inline().inc());
8378
- var endBracket = unparsedParams.endsWith('\n')
8379
- ? applyMetaTokens(']', (_p = (_o = (_m = node.debugData) === null || _m === void 0 ? void 0 : _m.lastToken) === null || _o === void 0 ? void 0 : _o.debugData) === null || _p === void 0 ? void 0 : _p.metaTokens, options.noInline())
8380
- : applyMetaTokens(']', (_s = (_r = (_q = node.debugData) === null || _q === void 0 ? void 0 : _q.lastToken) === null || _r === void 0 ? void 0 : _r.debugData) === null || _s === void 0 ? void 0 : _s.metaTokens, options.inline());
8381
- return startBracket + unparseMultilineParams(params, options.inline().inc()) + endBracket;
8382
- }
8383
- }
8384
-
8385
- function unparseIfLet(node, options) {
8386
- var _a, _b, _c, _d, _e, _f, _g, _h;
8387
- var startBracket = applyMetaTokens('(', (_b = (_a = node.debugData) === null || _a === void 0 ? void 0 : _a.token.debugData) === null || _b === void 0 ? void 0 : _b.metaTokens, options);
8388
- var endBracket = applyMetaTokens(')', (_e = (_d = (_c = node.debugData) === null || _c === void 0 ? void 0 : _c.lastToken) === null || _d === void 0 ? void 0 : _d.debugData) === null || _e === void 0 ? void 0 : _e.metaTokens, options.inline());
8389
- var name = applyMetaTokens(node.n, (_h = (_g = (_f = node.debugData) === null || _f === void 0 ? void 0 : _f.nameToken) === null || _g === void 0 ? void 0 : _g.debugData) === null || _h === void 0 ? void 0 : _h.metaTokens, options.inline());
8390
- var letArray = node.debugData ? node.debugData.bindingArray : createLetArray$1(node.b);
8391
- var inc = name.includes('\n') ? 1 : name.length + 2;
8392
- var unparsedLetArray = unparseBindings(letArray, options.inc(inc).inline());
8393
- var prefix = "".concat(startBracket + name, " ").concat(unparsedLetArray);
8394
- var inline = !(name + unparsedLetArray).includes('\n');
8395
- return unparseParams({
8396
- params: node.p,
8397
- options: options,
8398
- prefix: prefix,
8399
- inline: inline,
8400
- endBracket: endBracket,
8401
- body: true,
8402
- noMultilineInline: true,
8403
- });
8404
- }
8405
- function createLetArray$1(bindingNode) {
8406
- var params = [
8407
- {
8408
- t: AstNodeType.Name,
8409
- n: undefined,
8410
- p: [],
8411
- debugData: undefined,
8412
- v: bindingNode.n,
8413
- },
8414
- bindingNode.v,
8415
- ];
8416
- var node = {
8417
- t: AstNodeType.NormalExpression,
8418
- n: 'array',
8419
- p: params,
8420
- debugData: undefined,
8421
- };
8422
- return node;
8423
- }
8424
-
8425
- function unparseLet(node, options) {
8426
- var _a, _b, _c, _d, _e, _f, _g, _h;
8427
- var startBracket = applyMetaTokens('(', (_b = (_a = node.debugData) === null || _a === void 0 ? void 0 : _a.token.debugData) === null || _b === void 0 ? void 0 : _b.metaTokens, options);
8428
- var endBracket = applyMetaTokens(')', (_e = (_d = (_c = node.debugData) === null || _c === void 0 ? void 0 : _c.lastToken) === null || _d === void 0 ? void 0 : _d.debugData) === null || _e === void 0 ? void 0 : _e.metaTokens, options.inline());
8429
- var name = applyMetaTokens(node.n, (_h = (_g = (_f = node.debugData) === null || _f === void 0 ? void 0 : _f.nameToken) === null || _g === void 0 ? void 0 : _g.debugData) === null || _h === void 0 ? void 0 : _h.metaTokens, options.inline());
8430
- var letArray = node.debugData ? node.debugData.bindingArray : createLetArray(node.bs);
8431
- var inc = name.includes('\n') ? 1 : name.length + 2;
8432
- var unparsedLetArray = unparseBindings(letArray, options.inc(inc).inline());
8433
- var prefix = "".concat(startBracket + name, " ").concat(unparsedLetArray);
8434
- var inline = !(name + unparsedLetArray).includes('\n');
8435
- return unparseParams({
8436
- params: node.p,
8437
- options: options,
8438
- prefix: prefix,
8439
- inline: inline,
8440
- endBracket: endBracket,
8441
- body: true,
8442
- noMultilineInline: true,
8443
- });
8444
- }
8445
- function createLetArray(bindingNodes) {
8446
- var params = bindingNodes.flatMap(function (binding) { return [
8447
- {
8448
- t: AstNodeType.Name,
8449
- n: undefined,
8450
- p: [],
8451
- debugData: undefined,
8452
- v: binding.n,
8453
- },
8454
- binding.v,
8455
- ]; });
8456
- var node = {
8457
- t: AstNodeType.NormalExpression,
8458
- n: 'array',
8459
- p: params,
8460
- debugData: undefined,
8461
- };
8462
- return node;
8463
- }
8464
-
8465
- function unparseIfOrWhenLike(node, options) {
8466
- var _a, _b, _c, _d, _e, _f, _g, _h;
8467
- var startBracket = applyMetaTokens('(', (_b = (_a = node.debugData) === null || _a === void 0 ? void 0 : _a.token.debugData) === null || _b === void 0 ? void 0 : _b.metaTokens, options);
8468
- var endBracket = applyMetaTokens(')', (_e = (_d = (_c = node.debugData) === null || _c === void 0 ? void 0 : _c.lastToken) === null || _d === void 0 ? void 0 : _d.debugData) === null || _e === void 0 ? void 0 : _e.metaTokens, options.inline());
8469
- var nameOptions = startBracket.endsWith('\n') ? options.noInline().inc() : options.inline().inc();
8470
- var name = applyMetaTokens(node.n, (_h = (_g = (_f = node.debugData) === null || _f === void 0 ? void 0 : _f.nameToken) === null || _g === void 0 ? void 0 : _g.debugData) === null || _h === void 0 ? void 0 : _h.metaTokens, nameOptions);
8471
- var inc = name.includes('\n') ? 1 : name.length + 2;
8472
- var unparsedCondition = options.unparse(node.p[0], options.inc(inc).inline());
8473
- var prefix = "".concat(startBracket + name, " ").concat(unparsedCondition);
8474
- var params = node.p.slice(1);
8475
- // const inline = !(name + unparsedCondition).includes('\n')
8476
- var inline = false;
8477
- return unparseParams({ params: params, options: options, prefix: prefix, inline: inline, name: name, endBracket: endBracket, body: node.n === 'when' || node.n === 'when-not' });
8478
- }
8479
-
8480
- // type ExpressionWithSingleParamNode = Pick<NormalExpressionNode, 'debug' | 'n'> & { p: AstNode }
8481
- // function expressionWithSingleParamUnparser(astNode: ExpressionWithSingleParamNode, options: UnparseOptions) {
8482
- // return unparseNormalExpressionNode({ ...astNode, p: [astNode.p] }, options)
8483
- // }
8484
- var specialExpressionUnparser = {
8485
- 'and': unparseNormalExpression,
8486
- 'comment': unparseNormalExpression,
8487
- 'cond': unparseCond,
8488
- 'declared?': unparseNormalExpression,
8489
- // 'defn': (astNode: DefnNode, options: UnparseOptions) => unparseNormalExpressionNode({ ...astNode, t }, options),
8490
- 'def': unparseNormalExpression,
8491
- // 'defns': (astNode: DefnsNode, options: UnparseOptions) => unparseNormalExpressionNode({ ...astNode, t }, options),
8492
- 'defs': unparseNormalExpression,
8493
- 'do': unparseDo,
8494
- // 'doseq': (astNode: DoSeqNode, options: UnparseOptions) => unparseNormalExpressionNode({ ...astNode, t }, options),
8495
- // 'fn': (astNode: FnNode, options: UnparseOptions) => unparseNormalExpressionNode({ ...astNode, t }, options),
8496
- // 'for': (astNode: ForNode, options: UnparseOptions) => unparseNormalExpressionNode({ ...astNode, t }, options),
8497
- 'if-let': unparseIfLet,
8498
- 'if': unparseIfOrWhenLike,
8499
- 'if-not': unparseIfOrWhenLike,
8500
- 'let': unparseLet,
8501
- // 'loop': (astNode: LoopNode, options: UnparseOptions) => unparseNormalExpressionNode({ ...astNode, t }, options),
8502
- 'or': unparseNormalExpression,
8503
- '??': unparseNormalExpression,
8504
- 'recur': unparseNormalExpression,
8505
- 'time!': unparseNormalExpression,
8506
- 'throw': unparseNormalExpression,
8507
- // 'try': (astNode: TryNode, options: UnparseOptions) => unparseNormalExpressionNode({ ...astNode, t }, options),
8508
- // 'when-first': (astNode: WhenFirstNode, options: UnparseOptions) => unparseNormalExpressionNode({ ...astNode, t }, options),
8509
- // 'when-let': (astNode: WhenLetNode, options: UnparseOptions) => unparseNormalExpressionNode({ ...astNode, t }, options),
8510
- 'when': unparseIfOrWhenLike,
8511
- 'when-not': unparseIfOrWhenLike,
8512
- };
8513
- function unparseSpecialExpression(node, options) {
8514
- var unparser = specialExpressionUnparser[node.n];
8515
- return unparser(node, options);
8516
- }
8517
-
8518
- var unparse = function (node, options) {
8519
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
8520
- switch (node.t) {
8521
- case AstNodeType.String:
8522
- return ((_b = (_a = node.debugData) === null || _a === void 0 ? void 0 : _a.token.o) === null || _b === void 0 ? void 0 : _b.s)
8523
- ? applyMetaTokens(":".concat(node.v), (_d = (_c = node.debugData) === null || _c === void 0 ? void 0 : _c.token.debugData) === null || _d === void 0 ? void 0 : _d.metaTokens, options) // Keyword
8524
- : applyMetaTokens("\"".concat(node.v, "\""), (_f = (_e = node.debugData) === null || _e === void 0 ? void 0 : _e.token.debugData) === null || _f === void 0 ? void 0 : _f.metaTokens, options);
8525
- case AstNodeType.Number:
8526
- case AstNodeType.Name:
8527
- case AstNodeType.Modifier:
8528
- case AstNodeType.ReservedName:
8529
- return applyMetaTokens(node.v, (_h = (_g = node.debugData) === null || _g === void 0 ? void 0 : _g.token.debugData) === null || _h === void 0 ? void 0 : _h.metaTokens, options);
8530
- case AstNodeType.Comment:
8531
- return "".concat(applyMetaTokens(node.v, (_k = (_j = node.debugData) === null || _j === void 0 ? void 0 : _j.token.debugData) === null || _k === void 0 ? void 0 : _k.metaTokens, options), "\n");
8532
- case AstNodeType.NormalExpression: {
8533
- return unparseNormalExpression(node, options);
8534
- }
8535
- case AstNodeType.SpecialExpression:
8536
- return unparseSpecialExpression(node, options);
8537
- }
8538
- };
8539
- function unparseAst(ast, lineLength) {
8540
- var options = new UnparseOptions(unparse, lineLength || Number.MAX_SAFE_INTEGER);
8541
- var result = ast.b.reduce(function (acc, node) {
8542
- var nodeUnparsed = unparse(node, options);
8543
- return ensureNewlineSeparator(acc, nodeUnparsed);
8544
- }, '');
8545
- return result.trim();
8546
- }
8547
-
8548
- function isNoSpaceNeededBefore(token) {
8549
- switch (token.t) {
8550
- case TokenType.Bracket:
8551
- return [')', ']'].includes(token.v);
8552
- case TokenType.CollectionAccessor:
8553
- return true;
8554
- case TokenType.NewLine:
8555
- return true;
8556
- default:
8557
- return false;
8558
- }
8559
- }
8560
- function isNoSpaceNeededAfter(token) {
8561
- switch (token.t) {
8562
- case TokenType.Bracket:
8563
- return ['(', '['].includes(token.v);
8564
- case TokenType.CollectionAccessor:
8565
- return true;
8566
- case TokenType.FnShorthand:
8567
- return true;
8568
- case TokenType.NewLine:
8569
- return true;
8570
- case TokenType.RegexpShorthand:
8571
- return true;
8572
- default:
8573
- return false;
8574
- }
8575
- }
8576
- function untokenize(tokenStream) {
8577
- var lastToken;
8578
- return tokenStream.tokens.reduce(function (acc, token) {
8579
- var joiner = !lastToken || isNoSpaceNeededAfter(lastToken) || isNoSpaceNeededBefore(token) ? '' : ' ';
8580
- lastToken = token;
8581
- return "".concat(acc).concat(joiner).concat(untokenizeToken(token));
8582
- }, '');
8583
- }
8584
- function untokenizeToken(token) {
8585
- switch (token.t) {
8586
- case TokenType.String:
8587
- return "\"".concat(token.v, "\"");
8588
- default:
8589
- return token.v;
8590
- }
8591
- }
8592
-
8593
8022
  var Cache = /** @class */ (function () {
8594
8023
  function Cache(maxSize) {
8595
8024
  this.cache = {};
@@ -8690,13 +8119,6 @@ var Lits = /** @class */ (function () {
8690
8119
  var ast = this.generateAst(program, params);
8691
8120
  return this.evaluate(ast, params);
8692
8121
  };
8693
- Lits.prototype.format = function (program, params) {
8694
- var _a;
8695
- if (params === void 0) { params = {}; }
8696
- var lineLength = (_a = params.lineLength) !== null && _a !== void 0 ? _a : 80;
8697
- var ast = this.generateAst(program, params);
8698
- return unparseAst(ast, lineLength);
8699
- };
8700
8122
  Lits.prototype.context = function (program, params) {
8701
8123
  if (params === void 0) { params = {}; }
8702
8124
  var contextStack = createContextStack(params);
@@ -8721,12 +8143,6 @@ var Lits = /** @class */ (function () {
8721
8143
  var contextStack = createContextStack(params);
8722
8144
  return evaluate(ast, contextStack);
8723
8145
  };
8724
- Lits.prototype.transform = function (tokenStream, transformer) {
8725
- return transformTokens(tokenStream, transformer);
8726
- };
8727
- Lits.prototype.untokenize = function (tokenStream) {
8728
- return untokenize(tokenStream);
8729
- };
8730
8146
  Lits.prototype.apply = function (fn, fnParams, params) {
8731
8147
  var _a;
8732
8148
  if (params === void 0) { params = {}; }
@@ -8760,86 +8176,243 @@ var Lits = /** @class */ (function () {
8760
8176
  return Lits;
8761
8177
  }());
8762
8178
 
8763
- var collectionReference = {
8764
- 'count': {
8765
- title: 'count',
8766
- category: 'Collection',
8767
- linkName: 'count',
8768
- returns: {
8769
- type: 'number',
8770
- },
8771
- args: {
8772
- coll: {
8773
- type: ['collection', 'string', 'nil'],
8774
- },
8775
- },
8776
- variants: [
8777
- { argumentNames: ['coll'] },
8778
- ],
8779
- description: 'Returns number of elements in $coll.',
8780
- examples: [
8781
- '(count [1 2 3])',
8782
- '(count [])',
8783
- '(count (object :a 1))',
8784
- '(count "")',
8785
- '(count "Albert")',
8786
- '(count nil)',
8787
- ],
8788
- },
8789
- 'get': {
8790
- title: 'get',
8791
- category: 'Collection',
8792
- linkName: 'get',
8793
- returns: {
8794
- type: 'any',
8795
- },
8796
- args: {
8797
- 'coll': {
8798
- type: 'collection',
8799
- },
8800
- 'key': {
8801
- type: ['string', 'integer'],
8802
- },
8803
- 'not-found': {
8804
- type: 'any',
8805
- description: 'Default value to return if $key is not found.',
8806
- },
8807
- },
8808
- variants: [
8809
- { argumentNames: ['coll', 'key'] },
8810
- { argumentNames: ['coll', 'key', 'not-found'] },
8811
- ],
8812
- description: 'Returns value in $coll mapped at \`key\`.',
8813
- examples: [
8814
- "\n(get\n [1 2 3]\n 1)",
8815
- "\n(get\n []\n 1)",
8816
- "\n(get\n []\n 1\n \"default\")",
8817
- "\n(get\n (object :a 1)\n :a)",
8818
- "\n(get\n (object :a 1)\n :b)",
8819
- "\n(get\n (object :a 1)\n :b\n \"default\")",
8820
- "\n(get\n nil\n :a)",
8821
- "\n(get\n nil\n :b\n \"default\")",
8822
- ],
8823
- },
8824
- 'get-in': {
8825
- title: 'get-in',
8826
- category: 'Collection',
8827
- linkName: 'get-in',
8828
- returns: {
8829
- type: 'any',
8830
- },
8831
- args: {
8832
- 'coll': {
8833
- type: 'collection',
8834
- },
8835
- 'keys': {
8836
- type: 'array',
8837
- },
8838
- 'not-found': {
8839
- type: 'any',
8840
- },
8841
- },
8842
- variants: [
8179
+ function runTest(_a) {
8180
+ var filePath = _a.testPath, testNamePattern = _a.testNamePattern;
8181
+ var includedFilePaths = getIncludedFilePaths(filePath);
8182
+ var testResult = {
8183
+ tap: 'TAP version 13\n',
8184
+ success: true,
8185
+ };
8186
+ try {
8187
+ var testChunks = getTestChunks(filePath);
8188
+ testResult.tap += "1..".concat(testChunks.length, "\n");
8189
+ testChunks.forEach(function (testChunkProgram, index) {
8190
+ var testNumber = index + 1;
8191
+ if (testNamePattern && !testNamePattern.test(testChunkProgram.name)) {
8192
+ testResult.tap += "ok ".concat(testNumber, " ").concat(testChunkProgram.name, " # skip - Not matching testNamePattern ").concat(testNamePattern, "\n");
8193
+ }
8194
+ else if (testChunkProgram.directive === 'SKIP') {
8195
+ testResult.tap += "ok ".concat(testNumber, " ").concat(testChunkProgram.name, " # skip\n");
8196
+ }
8197
+ else {
8198
+ try {
8199
+ var lits = new Lits({ debug: true });
8200
+ var contexts = getContexts(includedFilePaths, lits);
8201
+ lits.run(testChunkProgram.program, {
8202
+ contexts: contexts,
8203
+ filePath: filePath,
8204
+ });
8205
+ testResult.tap += "ok ".concat(testNumber, " ").concat(testChunkProgram.name, "\n");
8206
+ }
8207
+ catch (error) {
8208
+ testResult.success = false;
8209
+ testResult.tap += "not ok ".concat(testNumber, " ").concat(testChunkProgram.name).concat(getErrorYaml(error));
8210
+ }
8211
+ }
8212
+ });
8213
+ }
8214
+ catch (error) {
8215
+ testResult.tap += "Bail out! ".concat(getErrorMessage$1(error), "\n");
8216
+ testResult.success = false;
8217
+ }
8218
+ return testResult;
8219
+ }
8220
+ function readLitsFile(litsPath) {
8221
+ if (!litsPath.endsWith('.lits'))
8222
+ throw new Error("Expected .lits file, got ".concat(litsPath));
8223
+ return fs.readFileSync(litsPath, { encoding: 'utf-8' });
8224
+ }
8225
+ function getContexts(includedFilePaths, lits) {
8226
+ return includedFilePaths.reduce(function (acc, filePath) {
8227
+ var fileContent = readLitsFile(filePath);
8228
+ acc.push(lits.context(fileContent, { filePath: filePath, contexts: acc }));
8229
+ return acc;
8230
+ }, []);
8231
+ }
8232
+ function getIncludedFilePaths(absoluteFilePath) {
8233
+ var result = [];
8234
+ getIncludesRecursively(absoluteFilePath, result);
8235
+ return result.reduce(function (acc, entry) {
8236
+ if (!acc.includes(entry))
8237
+ acc.push(entry);
8238
+ return acc;
8239
+ }, []);
8240
+ function getIncludesRecursively(filePath, includedFilePaths) {
8241
+ var includeFilePaths = readIncludeDirectives(filePath);
8242
+ includeFilePaths.forEach(function (includeFilePath) {
8243
+ getIncludesRecursively(includeFilePath, includedFilePaths);
8244
+ includedFilePaths.push(includeFilePath);
8245
+ });
8246
+ }
8247
+ }
8248
+ function readIncludeDirectives(filePath) {
8249
+ var fileContent = readLitsFile(filePath);
8250
+ var dirname = path.dirname(filePath);
8251
+ var okToInclude = true;
8252
+ return fileContent.split('\n').reduce(function (acc, line) {
8253
+ var includeMatch = line.match(/^\s*;+\s*@include\s*(\S+)\s*$/);
8254
+ if (includeMatch) {
8255
+ if (!okToInclude)
8256
+ throw new Error("@include must be in the beginning of file: ".concat(filePath, ":").concat(line + 1));
8257
+ var relativeFilePath = includeMatch[1];
8258
+ acc.push(path.resolve(dirname, relativeFilePath));
8259
+ }
8260
+ if (!line.match(/^\s*;.*$/))
8261
+ okToInclude = false;
8262
+ return acc;
8263
+ }, []);
8264
+ }
8265
+ // Splitting test file based on @test annotations
8266
+ function getTestChunks(testPath) {
8267
+ var testProgram = readLitsFile(testPath);
8268
+ var currentTest;
8269
+ var setupCode = '';
8270
+ return testProgram.split('\n').reduce(function (result, line, index) {
8271
+ var _a;
8272
+ var currentLineNbr = index + 1;
8273
+ // eslint-disable-next-line regexp/no-super-linear-backtracking
8274
+ var testNameAnnotationMatch = line.match(/^\s*;+\s*@(?:(skip)-)?test\s*(.*)$/);
8275
+ if (testNameAnnotationMatch) {
8276
+ var directive = ((_a = testNameAnnotationMatch[1]) !== null && _a !== void 0 ? _a : '').toUpperCase();
8277
+ var testName_1 = testNameAnnotationMatch[2];
8278
+ if (!testName_1)
8279
+ throw new Error("Missing test name on line ".concat(currentLineNbr));
8280
+ if (result.find(function (chunk) { return chunk.name === testName_1; }))
8281
+ throw new Error("Duplicate test name ".concat(testName_1));
8282
+ currentTest = {
8283
+ directive: (directive || null),
8284
+ name: testName_1,
8285
+ // Adding new-lines to make lits debug information report correct rows
8286
+ program: setupCode + __spreadArray([], __read(Array(currentLineNbr + 2 - setupCode.split('\n').length).keys()), false).map(function () { return ''; }).join('\n'),
8287
+ };
8288
+ result.push(currentTest);
8289
+ return result;
8290
+ }
8291
+ if (!currentTest)
8292
+ setupCode += "".concat(line, "\n");
8293
+ else
8294
+ currentTest.program += "".concat(line, "\n");
8295
+ return result;
8296
+ }, []);
8297
+ }
8298
+ function getErrorYaml(error) {
8299
+ var message = getErrorMessage$1(error);
8300
+ /* v8 ignore next 7 */
8301
+ if (!isAbstractLitsError(error)) {
8302
+ return "\n ---\n message: ".concat(JSON.stringify(message), "\n ...\n");
8303
+ }
8304
+ var sourceCodeInfo = error.sourceCodeInfo;
8305
+ /* v8 ignore next 8 */
8306
+ if (!sourceCodeInfo || typeof sourceCodeInfo === 'string') {
8307
+ return "\n ---\n message: ".concat(JSON.stringify(message), "\n error: ").concat(JSON.stringify(error.name), "\n ...\n");
8308
+ }
8309
+ var formattedMessage = message.includes('\n')
8310
+ ? "|\n ".concat(message.split(/\r?\n/).join('\n '))
8311
+ : JSON.stringify(message);
8312
+ return "\n ---\n error: ".concat(JSON.stringify(error.name), "\n message: ").concat(formattedMessage, "\n location: ").concat(JSON.stringify(getLocation(sourceCodeInfo)), "\n code:\n - \"").concat(sourceCodeInfo.code, "\"\n - \"").concat(getCodeMarker(sourceCodeInfo), "\"\n ...\n");
8313
+ }
8314
+ function getLocation(sourceCodeInfo) {
8315
+ var terms = [];
8316
+ if (sourceCodeInfo.filePath)
8317
+ terms.push(sourceCodeInfo.filePath);
8318
+ if (sourceCodeInfo.position) {
8319
+ terms.push("".concat(sourceCodeInfo.position.line));
8320
+ terms.push("".concat(sourceCodeInfo.position.column));
8321
+ }
8322
+ return terms.join(':');
8323
+ }
8324
+ function getErrorMessage$1(error) {
8325
+ if (!isAbstractLitsError(error)) {
8326
+ // error should always be an Error (other cases is just for kicks)
8327
+ /* v8 ignore next 1 */
8328
+ return typeof error === 'string' ? error : error instanceof Error ? error.message : 'Unknown error';
8329
+ }
8330
+ return error.shortMessage;
8331
+ }
8332
+ function isAbstractLitsError(error) {
8333
+ return error instanceof LitsError;
8334
+ }
8335
+
8336
+ var collectionReference = {
8337
+ 'count': {
8338
+ title: 'count',
8339
+ category: 'Collection',
8340
+ linkName: 'count',
8341
+ returns: {
8342
+ type: 'number',
8343
+ },
8344
+ args: {
8345
+ coll: {
8346
+ type: ['collection', 'string', 'nil'],
8347
+ },
8348
+ },
8349
+ variants: [
8350
+ { argumentNames: ['coll'] },
8351
+ ],
8352
+ description: 'Returns number of elements in $coll.',
8353
+ examples: [
8354
+ '(count [1 2 3])',
8355
+ '(count [])',
8356
+ '(count (object :a 1))',
8357
+ '(count "")',
8358
+ '(count "Albert")',
8359
+ '(count nil)',
8360
+ ],
8361
+ },
8362
+ 'get': {
8363
+ title: 'get',
8364
+ category: 'Collection',
8365
+ linkName: 'get',
8366
+ returns: {
8367
+ type: 'any',
8368
+ },
8369
+ args: {
8370
+ 'coll': {
8371
+ type: 'collection',
8372
+ },
8373
+ 'key': {
8374
+ type: ['string', 'integer'],
8375
+ },
8376
+ 'not-found': {
8377
+ type: 'any',
8378
+ description: 'Default value to return if $key is not found.',
8379
+ },
8380
+ },
8381
+ variants: [
8382
+ { argumentNames: ['coll', 'key'] },
8383
+ { argumentNames: ['coll', 'key', 'not-found'] },
8384
+ ],
8385
+ description: 'Returns value in $coll mapped at \`key\`.',
8386
+ examples: [
8387
+ "\n(get\n [1 2 3]\n 1)",
8388
+ "\n(get\n []\n 1)",
8389
+ "\n(get\n []\n 1\n \"default\")",
8390
+ "\n(get\n (object :a 1)\n :a)",
8391
+ "\n(get\n (object :a 1)\n :b)",
8392
+ "\n(get\n (object :a 1)\n :b\n \"default\")",
8393
+ "\n(get\n nil\n :a)",
8394
+ "\n(get\n nil\n :b\n \"default\")",
8395
+ ],
8396
+ },
8397
+ 'get-in': {
8398
+ title: 'get-in',
8399
+ category: 'Collection',
8400
+ linkName: 'get-in',
8401
+ returns: {
8402
+ type: 'any',
8403
+ },
8404
+ args: {
8405
+ 'coll': {
8406
+ type: 'collection',
8407
+ },
8408
+ 'keys': {
8409
+ type: 'array',
8410
+ },
8411
+ 'not-found': {
8412
+ type: 'any',
8413
+ },
8414
+ },
8415
+ variants: [
8843
8416
  { argumentNames: ['coll', 'keys'] },
8844
8417
  { argumentNames: ['coll', 'keys', 'not-found'] },
8845
8418
  ],
@@ -15219,25 +14792,276 @@ Object.values(apiReference).forEach(function (ref) {
15219
14792
  ref.title = ref.title.replace(/"/g, '&quot;');
15220
14793
  });
15221
14794
 
15222
- var e_1, _a$1, e_2, _b;
15223
- var api = {
15224
- collection: [
15225
- 'count',
15226
- 'get',
15227
- 'get-in',
15228
- 'contains?',
15229
- 'has?',
15230
- 'has-some?',
15231
- 'has-every?',
15232
- 'assoc',
15233
- 'assoc-in',
15234
- 'concat',
15235
- 'not-empty',
15236
- 'every?',
15237
- 'not-every?',
15238
- 'any?',
15239
- 'not-any?',
15240
- 'update',
14795
+ function stringifyValue(value, html) {
14796
+ var _a;
14797
+ var gt = '>';
14798
+ var lt = '<';
14799
+ if (isLitsFunction(value)) {
14800
+ if (value.t === FunctionType.Builtin)
14801
+ return "".concat(lt, "builtin function ").concat(value.n).concat(gt);
14802
+ else
14803
+ return "".concat(lt, "function ").concat((_a = value.n) !== null && _a !== void 0 ? _a : '\u03BB').concat(gt);
14804
+ }
14805
+ if (value === null)
14806
+ return 'null';
14807
+ if (typeof value === 'object' && value instanceof Error)
14808
+ return value.toString();
14809
+ if (typeof value === 'object' && value instanceof RegExp)
14810
+ return "".concat(value);
14811
+ if (value === Number.POSITIVE_INFINITY)
14812
+ return "".concat(Number.POSITIVE_INFINITY);
14813
+ if (value === Number.NEGATIVE_INFINITY)
14814
+ return "".concat(Number.NEGATIVE_INFINITY);
14815
+ if (typeof value === 'number' && Number.isNaN(value))
14816
+ return 'NaN';
14817
+ if (isRegularExpression(value))
14818
+ return "/".concat(value.s, "/").concat(value.f);
14819
+ return JSON.stringify(value, null, 2);
14820
+ }
14821
+ function findAllOccurrences(input, pattern) {
14822
+ var matches = __spreadArray([], __read(input.matchAll(pattern)), false);
14823
+ return new Set(matches.map(function (match) { return match[0]; }));
14824
+ }
14825
+
14826
+ var ColorEnum;
14827
+ (function (ColorEnum) {
14828
+ ColorEnum["Reset"] = "\u001B[0m";
14829
+ ColorEnum["Bright"] = "\u001B[1m";
14830
+ ColorEnum["ResetBright"] = "\u001B[21m";
14831
+ ColorEnum["Dim"] = "\u001B[2m";
14832
+ ColorEnum["ResetDim"] = "\u001B[22m";
14833
+ ColorEnum["Italic"] = "\u001B[3m";
14834
+ ColorEnum["ResetItalic"] = "\u001B[23m";
14835
+ ColorEnum["Underscore"] = "\u001B[4m";
14836
+ ColorEnum["ResetUnderscore"] = "\u001B[24m";
14837
+ ColorEnum["Blink"] = "\u001B[5m";
14838
+ ColorEnum["ResetBlink"] = "\u001B[25m";
14839
+ ColorEnum["Reverse"] = "\u001B[7m";
14840
+ ColorEnum["ResetReverse"] = "\u001B[27m";
14841
+ ColorEnum["Hidden"] = "\u001B[8m";
14842
+ ColorEnum["ResetHidden"] = "\u001B[28m";
14843
+ ColorEnum["FgBlack"] = "\u001B[30m";
14844
+ ColorEnum["FgRed"] = "\u001B[31m";
14845
+ ColorEnum["FgGreen"] = "\u001B[32m";
14846
+ ColorEnum["FgYellow"] = "\u001B[33m";
14847
+ ColorEnum["FgBlue"] = "\u001B[34m";
14848
+ ColorEnum["FgMagenta"] = "\u001B[35m";
14849
+ ColorEnum["FgCyan"] = "\u001B[36m";
14850
+ ColorEnum["FgWhite"] = "\u001B[37m";
14851
+ ColorEnum["FgGray"] = "\u001B[90m";
14852
+ ColorEnum["BgBlack"] = "\u001B[40m";
14853
+ ColorEnum["BgRed"] = "\u001B[41m";
14854
+ ColorEnum["BgGreen"] = "\u001B[42m";
14855
+ ColorEnum["BgYellow"] = "\u001B[43m";
14856
+ ColorEnum["BgBlue"] = "\u001B[44m";
14857
+ ColorEnum["BgMagenta"] = "\u001B[45m";
14858
+ ColorEnum["BgCyan"] = "\u001B[46m";
14859
+ ColorEnum["BgWhite"] = "\u001B[47m";
14860
+ ColorEnum["BgGray"] = "\u001B[100m";
14861
+ })(ColorEnum || (ColorEnum = {}));
14862
+ function createLeftPad(length, char) {
14863
+ if (char === void 0) { char = ' '; }
14864
+ return function (text) {
14865
+ return text.padStart(length, char);
14866
+ };
14867
+ }
14868
+ function createRightPad(length, char) {
14869
+ if (char === void 0) { char = ' '; }
14870
+ return function (text) {
14871
+ return text.padEnd(length, char);
14872
+ };
14873
+ }
14874
+ function createFormatter$1(enableColors, colors, formatters) {
14875
+ var fn = function (text) {
14876
+ var e_1, _a;
14877
+ try {
14878
+ for (var formatters_1 = __values(formatters), formatters_1_1 = formatters_1.next(); !formatters_1_1.done; formatters_1_1 = formatters_1.next()) {
14879
+ var formatter = formatters_1_1.value;
14880
+ text = formatter(text);
14881
+ }
14882
+ }
14883
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
14884
+ finally {
14885
+ try {
14886
+ if (formatters_1_1 && !formatters_1_1.done && (_a = formatters_1.return)) _a.call(formatters_1);
14887
+ }
14888
+ finally { if (e_1) throw e_1.error; }
14889
+ }
14890
+ return enableColors
14891
+ ? colors.join('') + text + ColorEnum.Reset
14892
+ : text;
14893
+ };
14894
+ Object.defineProperty(fn, 'black', {
14895
+ get: function () { return createFormatter$1(enableColors, __spreadArray(__spreadArray([], __read(colors), false), [ColorEnum.FgBlack], false), formatters); },
14896
+ });
14897
+ Object.defineProperty(fn, 'red', {
14898
+ get: function () { return createFormatter$1(enableColors, __spreadArray(__spreadArray([], __read(colors), false), [ColorEnum.FgRed], false), formatters); },
14899
+ });
14900
+ Object.defineProperty(fn, 'green', {
14901
+ get: function () { return createFormatter$1(enableColors, __spreadArray(__spreadArray([], __read(colors), false), [ColorEnum.FgGreen], false), formatters); },
14902
+ });
14903
+ Object.defineProperty(fn, 'yellow', {
14904
+ get: function () { return createFormatter$1(enableColors, __spreadArray(__spreadArray([], __read(colors), false), [ColorEnum.FgYellow], false), formatters); },
14905
+ });
14906
+ Object.defineProperty(fn, 'blue', {
14907
+ get: function () { return createFormatter$1(enableColors, __spreadArray(__spreadArray([], __read(colors), false), [ColorEnum.FgBlue], false), formatters); },
14908
+ });
14909
+ Object.defineProperty(fn, 'magenta', {
14910
+ get: function () { return createFormatter$1(enableColors, __spreadArray(__spreadArray([], __read(colors), false), [ColorEnum.FgMagenta], false), formatters); },
14911
+ });
14912
+ Object.defineProperty(fn, 'cyan', {
14913
+ get: function () { return createFormatter$1(enableColors, __spreadArray(__spreadArray([], __read(colors), false), [ColorEnum.FgCyan], false), formatters); },
14914
+ });
14915
+ Object.defineProperty(fn, 'white', {
14916
+ get: function () { return createFormatter$1(enableColors, __spreadArray(__spreadArray([], __read(colors), false), [ColorEnum.FgWhite], false), formatters); },
14917
+ });
14918
+ Object.defineProperty(fn, 'gray', {
14919
+ get: function () { return createFormatter$1(enableColors, __spreadArray(__spreadArray([], __read(colors), false), [ColorEnum.FgGray], false), formatters); },
14920
+ });
14921
+ Object.defineProperty(fn, 'bgBlack', {
14922
+ get: function () { return createFormatter$1(enableColors, __spreadArray(__spreadArray([], __read(colors), false), [ColorEnum.BgBlack], false), formatters); },
14923
+ });
14924
+ Object.defineProperty(fn, 'bgRed', {
14925
+ get: function () { return createFormatter$1(enableColors, __spreadArray(__spreadArray([], __read(colors), false), [ColorEnum.BgRed], false), formatters); },
14926
+ });
14927
+ Object.defineProperty(fn, 'bgGreen', {
14928
+ get: function () { return createFormatter$1(enableColors, __spreadArray(__spreadArray([], __read(colors), false), [ColorEnum.BgGreen], false), formatters); },
14929
+ });
14930
+ Object.defineProperty(fn, 'bgYellow', {
14931
+ get: function () { return createFormatter$1(enableColors, __spreadArray(__spreadArray([], __read(colors), false), [ColorEnum.BgYellow], false), formatters); },
14932
+ });
14933
+ Object.defineProperty(fn, 'bgBlue', {
14934
+ get: function () { return createFormatter$1(enableColors, __spreadArray(__spreadArray([], __read(colors), false), [ColorEnum.BgBlue], false), formatters); },
14935
+ });
14936
+ Object.defineProperty(fn, 'bgMagenta', {
14937
+ get: function () { return createFormatter$1(enableColors, __spreadArray(__spreadArray([], __read(colors), false), [ColorEnum.BgMagenta], false), formatters); },
14938
+ });
14939
+ Object.defineProperty(fn, 'bgCyan', {
14940
+ get: function () { return createFormatter$1(enableColors, __spreadArray(__spreadArray([], __read(colors), false), [ColorEnum.BgCyan], false), formatters); },
14941
+ });
14942
+ Object.defineProperty(fn, 'bgWhite', {
14943
+ get: function () { return createFormatter$1(enableColors, __spreadArray(__spreadArray([], __read(colors), false), [ColorEnum.BgWhite], false), formatters); },
14944
+ });
14945
+ Object.defineProperty(fn, 'bgGray', {
14946
+ get: function () { return createFormatter$1(enableColors, __spreadArray(__spreadArray([], __read(colors), false), [ColorEnum.BgGray], false), formatters); },
14947
+ });
14948
+ Object.defineProperty(fn, 'reset', {
14949
+ get: function () { return createFormatter$1(enableColors, __spreadArray(__spreadArray([], __read(colors), false), [ColorEnum.Reset], false), formatters); },
14950
+ });
14951
+ Object.defineProperty(fn, 'bright', {
14952
+ get: function () { return createFormatter$1(enableColors, __spreadArray(__spreadArray([], __read(colors), false), [ColorEnum.Bright], false), formatters); },
14953
+ });
14954
+ Object.defineProperty(fn, 'dim', {
14955
+ get: function () { return createFormatter$1(enableColors, __spreadArray(__spreadArray([], __read(colors), false), [ColorEnum.Dim], false), formatters); },
14956
+ });
14957
+ Object.defineProperty(fn, 'italic', {
14958
+ get: function () { return createFormatter$1(enableColors, __spreadArray(__spreadArray([], __read(colors), false), [ColorEnum.Dim], false), formatters); },
14959
+ });
14960
+ Object.defineProperty(fn, 'underscore', {
14961
+ get: function () { return createFormatter$1(enableColors, __spreadArray(__spreadArray([], __read(colors), false), [ColorEnum.Underscore], false), formatters); },
14962
+ });
14963
+ Object.defineProperty(fn, 'blink', {
14964
+ get: function () { return createFormatter$1(enableColors, __spreadArray(__spreadArray([], __read(colors), false), [ColorEnum.Blink], false), formatters); },
14965
+ });
14966
+ Object.defineProperty(fn, 'reverse', {
14967
+ get: function () { return createFormatter$1(enableColors, __spreadArray(__spreadArray([], __read(colors), false), [ColorEnum.Reverse], false), formatters); },
14968
+ });
14969
+ Object.defineProperty(fn, 'hidden', {
14970
+ get: function () { return createFormatter$1(enableColors, __spreadArray(__spreadArray([], __read(colors), false), [ColorEnum.Hidden], false), formatters); },
14971
+ });
14972
+ fn.leftPad = function (length, char) { return createFormatter$1(enableColors, colors, [createLeftPad(length, char)]); };
14973
+ fn.rightPad = function (length, char) { return createFormatter$1(enableColors, colors, [createRightPad(length, char)]); };
14974
+ return fn;
14975
+ }
14976
+ function createColorizer(enableColors) {
14977
+ if (enableColors === void 0) { enableColors = true; }
14978
+ return {
14979
+ black: createFormatter$1(enableColors, [ColorEnum.FgBlack], []),
14980
+ red: createFormatter$1(enableColors, [ColorEnum.FgRed], []),
14981
+ green: createFormatter$1(enableColors, [ColorEnum.FgGreen], []),
14982
+ yellow: createFormatter$1(enableColors, [ColorEnum.FgYellow], []),
14983
+ blue: createFormatter$1(enableColors, [ColorEnum.FgBlue], []),
14984
+ magenta: createFormatter$1(enableColors, [ColorEnum.FgMagenta], []),
14985
+ cyan: createFormatter$1(enableColors, [ColorEnum.FgCyan], []),
14986
+ white: createFormatter$1(enableColors, [ColorEnum.FgWhite], []),
14987
+ gray: createFormatter$1(enableColors, [ColorEnum.FgGray], []),
14988
+ bgBlack: createFormatter$1(enableColors, [ColorEnum.BgBlack], []),
14989
+ bgRed: createFormatter$1(enableColors, [ColorEnum.BgRed], []),
14990
+ bgGreen: createFormatter$1(enableColors, [ColorEnum.BgGreen], []),
14991
+ bgYellow: createFormatter$1(enableColors, [ColorEnum.BgYellow], []),
14992
+ bgBlue: createFormatter$1(enableColors, [ColorEnum.BgBlue], []),
14993
+ bgMagenta: createFormatter$1(enableColors, [ColorEnum.BgMagenta], []),
14994
+ bgCyan: createFormatter$1(enableColors, [ColorEnum.BgCyan], []),
14995
+ bgWhite: createFormatter$1(enableColors, [ColorEnum.BgWhite], []),
14996
+ bgGray: createFormatter$1(enableColors, [ColorEnum.BgGray], []),
14997
+ reset: createFormatter$1(enableColors, [ColorEnum.Reset], []),
14998
+ bright: createFormatter$1(enableColors, [ColorEnum.Bright], []),
14999
+ dim: createFormatter$1(enableColors, [ColorEnum.Dim], []),
15000
+ italic: createFormatter$1(enableColors, [ColorEnum.Italic], []),
15001
+ underscore: createFormatter$1(enableColors, [ColorEnum.Underscore], []),
15002
+ blink: createFormatter$1(enableColors, [ColorEnum.Blink], []),
15003
+ reverse: createFormatter$1(enableColors, [ColorEnum.Reverse], []),
15004
+ hidden: createFormatter$1(enableColors, [ColorEnum.Hidden], []),
15005
+ leftPad: function (length, char) { return createFormatter$1(enableColors, [], [createLeftPad(length, char)]); },
15006
+ rightPad: function (length, char) { return createFormatter$1(enableColors, [], [createRightPad(length, char)]); },
15007
+ };
15008
+ }
15009
+
15010
+ function getCliType(fmt, arg) {
15011
+ var argType = isSpecialExpressionArgument(arg) ? arg.type.slice(1) : arg.type;
15012
+ var types = Array.isArray(argType) ? argType : [argType];
15013
+ var typeString = types.map(function (type) {
15014
+ return fmt.dim.red(type);
15015
+ }).join(' | ');
15016
+ return arg.array || arg.rest
15017
+ ? "".concat(fmt.bright.blue('Array')).concat(fmt.bright.gray('<')).concat(fmt.white(typeString)).concat(fmt.bright.gray('>'))
15018
+ : fmt.white(typeString);
15019
+ }
15020
+
15021
+ function getCliFunctionSignature(fmt, _a) {
15022
+ var name = _a.title, variants = _a.variants, args = _a.args, returns = _a.returns;
15023
+ return variants.map(function (variant) {
15024
+ var form = (variant.argumentNames.length === 0)
15025
+ ? "".concat(fmt.white('(')).concat(fmt.blue(name)).concat(fmt.white(')'))
15026
+ : "".concat(fmt.white('(')).concat(fmt.blue(name), " ").concat(variant.argumentNames.map(function (argName) {
15027
+ var result = '';
15028
+ var arg = args[argName];
15029
+ if (arg) {
15030
+ if (arg.rest)
15031
+ result += fmt.white('& ');
15032
+ result += "".concat(fmt.green(argName));
15033
+ if (arg.type === '*binding' || arg.type === '*for-binding')
15034
+ result = "".concat(fmt.white('[')).concat(result).concat(fmt.white(']'));
15035
+ else if (arg.type === '*arguments')
15036
+ result = "".concat(fmt.white('[')).concat(result).concat(fmt.white(']'));
15037
+ else if (arg.type === '*catch-expression')
15038
+ result = "".concat(fmt.white('(')).concat(result, " ").concat(fmt.bright.blue('body')).concat(fmt.white(')'));
15039
+ }
15040
+ return result;
15041
+ }).join(' ')).concat(fmt.white(')'));
15042
+ return "".concat(form, " ").concat(fmt.gray('=>'), " ").concat(getCliType(fmt, returns));
15043
+ }).join('\n');
15044
+ }
15045
+
15046
+ var e_1, _a$1, e_2, _b;
15047
+ var api = {
15048
+ collection: [
15049
+ 'count',
15050
+ 'get',
15051
+ 'get-in',
15052
+ 'contains?',
15053
+ 'has?',
15054
+ 'has-some?',
15055
+ 'has-every?',
15056
+ 'assoc',
15057
+ 'assoc-in',
15058
+ 'concat',
15059
+ 'not-empty',
15060
+ 'every?',
15061
+ 'not-every?',
15062
+ 'any?',
15063
+ 'not-any?',
15064
+ 'update',
15241
15065
  'update-in',
15242
15066
  ],
15243
15067
  array: [
@@ -15532,440 +15356,32 @@ try {
15532
15356
  for (var functionNamesFromLitsSrc_1 = __values(functionNamesFromLitsSrc), functionNamesFromLitsSrc_1_1 = functionNamesFromLitsSrc_1.next(); !functionNamesFromLitsSrc_1_1.done; functionNamesFromLitsSrc_1_1 = functionNamesFromLitsSrc_1.next()) {
15533
15357
  var functionName = functionNamesFromLitsSrc_1_1.value;
15534
15358
  if (!apiNames.includes(functionName))
15535
- throw new Error("Function name \"".concat(functionName, "\" is not included in the API"));
15536
- }
15537
- }
15538
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
15539
- finally {
15540
- try {
15541
- if (functionNamesFromLitsSrc_1_1 && !functionNamesFromLitsSrc_1_1.done && (_a$1 = functionNamesFromLitsSrc_1.return)) _a$1.call(functionNamesFromLitsSrc_1);
15542
- }
15543
- finally { if (e_1) throw e_1.error; }
15544
- }
15545
- try {
15546
- for (var functionNames_1 = __values(functionNames), functionNames_1_1 = functionNames_1.next(); !functionNames_1_1.done; functionNames_1_1 = functionNames_1.next()) {
15547
- var functionName = functionNames_1_1.value;
15548
- if (!functionNamesFromLitsSrc.includes(functionName))
15549
- throw new Error("Function name \"".concat(functionName, "\" is not included in the Lits source"));
15550
- }
15551
- }
15552
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
15553
- finally {
15554
- try {
15555
- if (functionNames_1_1 && !functionNames_1_1.done && (_b = functionNames_1.return)) _b.call(functionNames_1);
15556
- }
15557
- finally { if (e_2) throw e_2.error; }
15558
- }
15559
- function isApiName(arg) {
15560
- return apiNames.includes(arg);
15561
- }
15562
-
15563
- function runTest(_a) {
15564
- var filePath = _a.testPath, testNamePattern = _a.testNamePattern;
15565
- var includedFilePaths = getIncludedFilePaths(filePath);
15566
- var testResult = {
15567
- tap: 'TAP version 13\n',
15568
- success: true,
15569
- };
15570
- try {
15571
- var testChunks = getTestChunks(filePath);
15572
- testResult.tap += "1..".concat(testChunks.length, "\n");
15573
- testChunks.forEach(function (testChunkProgram, index) {
15574
- var testNumber = index + 1;
15575
- if (testNamePattern && !testNamePattern.test(testChunkProgram.name)) {
15576
- testResult.tap += "ok ".concat(testNumber, " ").concat(testChunkProgram.name, " # skip - Not matching testNamePattern ").concat(testNamePattern, "\n");
15577
- }
15578
- else if (testChunkProgram.directive === 'SKIP') {
15579
- testResult.tap += "ok ".concat(testNumber, " ").concat(testChunkProgram.name, " # skip\n");
15580
- }
15581
- else {
15582
- try {
15583
- var lits = new Lits({ debug: true });
15584
- var contexts = getContexts(includedFilePaths, lits);
15585
- lits.run(testChunkProgram.program, {
15586
- contexts: contexts,
15587
- filePath: filePath,
15588
- });
15589
- testResult.tap += "ok ".concat(testNumber, " ").concat(testChunkProgram.name, "\n");
15590
- }
15591
- catch (error) {
15592
- testResult.success = false;
15593
- testResult.tap += "not ok ".concat(testNumber, " ").concat(testChunkProgram.name).concat(getErrorYaml(error));
15594
- }
15595
- }
15596
- });
15597
- }
15598
- catch (error) {
15599
- testResult.tap += "Bail out! ".concat(getErrorMessage$1(error), "\n");
15600
- testResult.success = false;
15601
- }
15602
- return testResult;
15603
- }
15604
- function readLitsFile(litsPath) {
15605
- if (!litsPath.endsWith('.lits'))
15606
- throw new Error("Expected .lits file, got ".concat(litsPath));
15607
- return fs.readFileSync(litsPath, { encoding: 'utf-8' });
15608
- }
15609
- function getContexts(includedFilePaths, lits) {
15610
- return includedFilePaths.reduce(function (acc, filePath) {
15611
- var fileContent = readLitsFile(filePath);
15612
- acc.push(lits.context(fileContent, { filePath: filePath, contexts: acc }));
15613
- return acc;
15614
- }, []);
15615
- }
15616
- function getIncludedFilePaths(absoluteFilePath) {
15617
- var result = [];
15618
- getIncludesRecursively(absoluteFilePath, result);
15619
- return result.reduce(function (acc, entry) {
15620
- if (!acc.includes(entry))
15621
- acc.push(entry);
15622
- return acc;
15623
- }, []);
15624
- function getIncludesRecursively(filePath, includedFilePaths) {
15625
- var includeFilePaths = readIncludeDirectives(filePath);
15626
- includeFilePaths.forEach(function (includeFilePath) {
15627
- getIncludesRecursively(includeFilePath, includedFilePaths);
15628
- includedFilePaths.push(includeFilePath);
15629
- });
15630
- }
15631
- }
15632
- function readIncludeDirectives(filePath) {
15633
- var fileContent = readLitsFile(filePath);
15634
- var dirname = path.dirname(filePath);
15635
- var okToInclude = true;
15636
- return fileContent.split('\n').reduce(function (acc, line) {
15637
- var includeMatch = line.match(/^\s*;+\s*@include\s*(\S+)\s*$/);
15638
- if (includeMatch) {
15639
- if (!okToInclude)
15640
- throw new Error("@include must be in the beginning of file: ".concat(filePath, ":").concat(line + 1));
15641
- var relativeFilePath = includeMatch[1];
15642
- acc.push(path.resolve(dirname, relativeFilePath));
15643
- }
15644
- if (!line.match(/^\s*;.*$/))
15645
- okToInclude = false;
15646
- return acc;
15647
- }, []);
15648
- }
15649
- // Splitting test file based on @test annotations
15650
- function getTestChunks(testPath) {
15651
- var testProgram = readLitsFile(testPath);
15652
- var currentTest;
15653
- var setupCode = '';
15654
- return testProgram.split('\n').reduce(function (result, line, index) {
15655
- var _a;
15656
- var currentLineNbr = index + 1;
15657
- // eslint-disable-next-line regexp/no-super-linear-backtracking
15658
- var testNameAnnotationMatch = line.match(/^\s*;+\s*@(?:(skip)-)?test\s*(.*)$/);
15659
- if (testNameAnnotationMatch) {
15660
- var directive = ((_a = testNameAnnotationMatch[1]) !== null && _a !== void 0 ? _a : '').toUpperCase();
15661
- var testName_1 = testNameAnnotationMatch[2];
15662
- if (!testName_1)
15663
- throw new Error("Missing test name on line ".concat(currentLineNbr));
15664
- if (result.find(function (chunk) { return chunk.name === testName_1; }))
15665
- throw new Error("Duplicate test name ".concat(testName_1));
15666
- currentTest = {
15667
- directive: (directive || null),
15668
- name: testName_1,
15669
- // Adding new-lines to make lits debug information report correct rows
15670
- program: setupCode + __spreadArray([], __read(Array(currentLineNbr + 2 - setupCode.split('\n').length).keys()), false).map(function () { return ''; }).join('\n'),
15671
- };
15672
- result.push(currentTest);
15673
- return result;
15674
- }
15675
- if (!currentTest)
15676
- setupCode += "".concat(line, "\n");
15677
- else
15678
- currentTest.program += "".concat(line, "\n");
15679
- return result;
15680
- }, []);
15681
- }
15682
- function getErrorYaml(error) {
15683
- var message = getErrorMessage$1(error);
15684
- /* v8 ignore next 7 */
15685
- if (!isAbstractLitsError(error)) {
15686
- return "\n ---\n message: ".concat(JSON.stringify(message), "\n ...\n");
15687
- }
15688
- var sourceCodeInfo = error.sourceCodeInfo;
15689
- /* v8 ignore next 8 */
15690
- if (!sourceCodeInfo || typeof sourceCodeInfo === 'string') {
15691
- return "\n ---\n message: ".concat(JSON.stringify(message), "\n error: ").concat(JSON.stringify(error.name), "\n ...\n");
15692
- }
15693
- var formattedMessage = message.includes('\n')
15694
- ? "|\n ".concat(message.split(/\r?\n/).join('\n '))
15695
- : JSON.stringify(message);
15696
- return "\n ---\n error: ".concat(JSON.stringify(error.name), "\n message: ").concat(formattedMessage, "\n location: ").concat(JSON.stringify(getLocation(sourceCodeInfo)), "\n code:\n - \"").concat(sourceCodeInfo.code, "\"\n - \"").concat(getCodeMarker(sourceCodeInfo), "\"\n ...\n");
15697
- }
15698
- function getLocation(sourceCodeInfo) {
15699
- var terms = [];
15700
- if (sourceCodeInfo.filePath)
15701
- terms.push(sourceCodeInfo.filePath);
15702
- if (sourceCodeInfo.position) {
15703
- terms.push("".concat(sourceCodeInfo.position.line));
15704
- terms.push("".concat(sourceCodeInfo.position.column));
15705
- }
15706
- return terms.join(':');
15707
- }
15708
- function getErrorMessage$1(error) {
15709
- if (!isAbstractLitsError(error)) {
15710
- // error should always be an Error (other cases is just for kicks)
15711
- /* v8 ignore next 1 */
15712
- return typeof error === 'string' ? error : error instanceof Error ? error.message : 'Unknown error';
15713
- }
15714
- return error.shortMessage;
15715
- }
15716
- function isAbstractLitsError(error) {
15717
- return error instanceof LitsError;
15718
- }
15719
-
15720
- function stringifyValue(value, html) {
15721
- var _a;
15722
- var gt = '>';
15723
- var lt = '<';
15724
- if (isLitsFunction(value)) {
15725
- if (value.t === FunctionType.Builtin)
15726
- return "".concat(lt, "builtin function ").concat(value.n).concat(gt);
15727
- else
15728
- return "".concat(lt, "function ").concat((_a = value.n) !== null && _a !== void 0 ? _a : '\u03BB').concat(gt);
15359
+ throw new Error("Function name \"".concat(functionName, "\" is not included in the API"));
15729
15360
  }
15730
- if (value === null)
15731
- return 'null';
15732
- if (typeof value === 'object' && value instanceof Error)
15733
- return value.toString();
15734
- if (typeof value === 'object' && value instanceof RegExp)
15735
- return "".concat(value);
15736
- if (value === Number.POSITIVE_INFINITY)
15737
- return "".concat(Number.POSITIVE_INFINITY);
15738
- if (value === Number.NEGATIVE_INFINITY)
15739
- return "".concat(Number.NEGATIVE_INFINITY);
15740
- if (typeof value === 'number' && Number.isNaN(value))
15741
- return 'NaN';
15742
- if (isRegularExpression(value))
15743
- return "/".concat(value.s, "/").concat(value.f);
15744
- return JSON.stringify(value, null, 2);
15745
- }
15746
- function findAllOccurrences(input, pattern) {
15747
- var matches = __spreadArray([], __read(input.matchAll(pattern)), false);
15748
- return new Set(matches.map(function (match) { return match[0]; }));
15749
- }
15750
-
15751
- var ColorEnum;
15752
- (function (ColorEnum) {
15753
- ColorEnum["Reset"] = "\u001B[0m";
15754
- ColorEnum["Bright"] = "\u001B[1m";
15755
- ColorEnum["ResetBright"] = "\u001B[21m";
15756
- ColorEnum["Dim"] = "\u001B[2m";
15757
- ColorEnum["ResetDim"] = "\u001B[22m";
15758
- ColorEnum["Italic"] = "\u001B[3m";
15759
- ColorEnum["ResetItalic"] = "\u001B[23m";
15760
- ColorEnum["Underscore"] = "\u001B[4m";
15761
- ColorEnum["ResetUnderscore"] = "\u001B[24m";
15762
- ColorEnum["Blink"] = "\u001B[5m";
15763
- ColorEnum["ResetBlink"] = "\u001B[25m";
15764
- ColorEnum["Reverse"] = "\u001B[7m";
15765
- ColorEnum["ResetReverse"] = "\u001B[27m";
15766
- ColorEnum["Hidden"] = "\u001B[8m";
15767
- ColorEnum["ResetHidden"] = "\u001B[28m";
15768
- ColorEnum["FgBlack"] = "\u001B[30m";
15769
- ColorEnum["FgRed"] = "\u001B[31m";
15770
- ColorEnum["FgGreen"] = "\u001B[32m";
15771
- ColorEnum["FgYellow"] = "\u001B[33m";
15772
- ColorEnum["FgBlue"] = "\u001B[34m";
15773
- ColorEnum["FgMagenta"] = "\u001B[35m";
15774
- ColorEnum["FgCyan"] = "\u001B[36m";
15775
- ColorEnum["FgWhite"] = "\u001B[37m";
15776
- ColorEnum["FgGray"] = "\u001B[90m";
15777
- ColorEnum["BgBlack"] = "\u001B[40m";
15778
- ColorEnum["BgRed"] = "\u001B[41m";
15779
- ColorEnum["BgGreen"] = "\u001B[42m";
15780
- ColorEnum["BgYellow"] = "\u001B[43m";
15781
- ColorEnum["BgBlue"] = "\u001B[44m";
15782
- ColorEnum["BgMagenta"] = "\u001B[45m";
15783
- ColorEnum["BgCyan"] = "\u001B[46m";
15784
- ColorEnum["BgWhite"] = "\u001B[47m";
15785
- ColorEnum["BgGray"] = "\u001B[100m";
15786
- })(ColorEnum || (ColorEnum = {}));
15787
- function createLeftPad(length, char) {
15788
- if (char === void 0) { char = ' '; }
15789
- return function (text) {
15790
- return text.padStart(length, char);
15791
- };
15792
- }
15793
- function createRightPad(length, char) {
15794
- if (char === void 0) { char = ' '; }
15795
- return function (text) {
15796
- return text.padEnd(length, char);
15797
- };
15798
15361
  }
15799
- function createFormatter$1(enableColors, colors, formatters) {
15800
- var fn = function (text) {
15801
- var e_1, _a;
15802
- try {
15803
- for (var formatters_1 = __values(formatters), formatters_1_1 = formatters_1.next(); !formatters_1_1.done; formatters_1_1 = formatters_1.next()) {
15804
- var formatter = formatters_1_1.value;
15805
- text = formatter(text);
15806
- }
15807
- }
15808
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
15809
- finally {
15810
- try {
15811
- if (formatters_1_1 && !formatters_1_1.done && (_a = formatters_1.return)) _a.call(formatters_1);
15812
- }
15813
- finally { if (e_1) throw e_1.error; }
15814
- }
15815
- return enableColors
15816
- ? colors.join('') + text + ColorEnum.Reset
15817
- : text;
15818
- };
15819
- Object.defineProperty(fn, 'black', {
15820
- get: function () { return createFormatter$1(enableColors, __spreadArray(__spreadArray([], __read(colors), false), [ColorEnum.FgBlack], false), formatters); },
15821
- });
15822
- Object.defineProperty(fn, 'red', {
15823
- get: function () { return createFormatter$1(enableColors, __spreadArray(__spreadArray([], __read(colors), false), [ColorEnum.FgRed], false), formatters); },
15824
- });
15825
- Object.defineProperty(fn, 'green', {
15826
- get: function () { return createFormatter$1(enableColors, __spreadArray(__spreadArray([], __read(colors), false), [ColorEnum.FgGreen], false), formatters); },
15827
- });
15828
- Object.defineProperty(fn, 'yellow', {
15829
- get: function () { return createFormatter$1(enableColors, __spreadArray(__spreadArray([], __read(colors), false), [ColorEnum.FgYellow], false), formatters); },
15830
- });
15831
- Object.defineProperty(fn, 'blue', {
15832
- get: function () { return createFormatter$1(enableColors, __spreadArray(__spreadArray([], __read(colors), false), [ColorEnum.FgBlue], false), formatters); },
15833
- });
15834
- Object.defineProperty(fn, 'magenta', {
15835
- get: function () { return createFormatter$1(enableColors, __spreadArray(__spreadArray([], __read(colors), false), [ColorEnum.FgMagenta], false), formatters); },
15836
- });
15837
- Object.defineProperty(fn, 'cyan', {
15838
- get: function () { return createFormatter$1(enableColors, __spreadArray(__spreadArray([], __read(colors), false), [ColorEnum.FgCyan], false), formatters); },
15839
- });
15840
- Object.defineProperty(fn, 'white', {
15841
- get: function () { return createFormatter$1(enableColors, __spreadArray(__spreadArray([], __read(colors), false), [ColorEnum.FgWhite], false), formatters); },
15842
- });
15843
- Object.defineProperty(fn, 'gray', {
15844
- get: function () { return createFormatter$1(enableColors, __spreadArray(__spreadArray([], __read(colors), false), [ColorEnum.FgGray], false), formatters); },
15845
- });
15846
- Object.defineProperty(fn, 'bgBlack', {
15847
- get: function () { return createFormatter$1(enableColors, __spreadArray(__spreadArray([], __read(colors), false), [ColorEnum.BgBlack], false), formatters); },
15848
- });
15849
- Object.defineProperty(fn, 'bgRed', {
15850
- get: function () { return createFormatter$1(enableColors, __spreadArray(__spreadArray([], __read(colors), false), [ColorEnum.BgRed], false), formatters); },
15851
- });
15852
- Object.defineProperty(fn, 'bgGreen', {
15853
- get: function () { return createFormatter$1(enableColors, __spreadArray(__spreadArray([], __read(colors), false), [ColorEnum.BgGreen], false), formatters); },
15854
- });
15855
- Object.defineProperty(fn, 'bgYellow', {
15856
- get: function () { return createFormatter$1(enableColors, __spreadArray(__spreadArray([], __read(colors), false), [ColorEnum.BgYellow], false), formatters); },
15857
- });
15858
- Object.defineProperty(fn, 'bgBlue', {
15859
- get: function () { return createFormatter$1(enableColors, __spreadArray(__spreadArray([], __read(colors), false), [ColorEnum.BgBlue], false), formatters); },
15860
- });
15861
- Object.defineProperty(fn, 'bgMagenta', {
15862
- get: function () { return createFormatter$1(enableColors, __spreadArray(__spreadArray([], __read(colors), false), [ColorEnum.BgMagenta], false), formatters); },
15863
- });
15864
- Object.defineProperty(fn, 'bgCyan', {
15865
- get: function () { return createFormatter$1(enableColors, __spreadArray(__spreadArray([], __read(colors), false), [ColorEnum.BgCyan], false), formatters); },
15866
- });
15867
- Object.defineProperty(fn, 'bgWhite', {
15868
- get: function () { return createFormatter$1(enableColors, __spreadArray(__spreadArray([], __read(colors), false), [ColorEnum.BgWhite], false), formatters); },
15869
- });
15870
- Object.defineProperty(fn, 'bgGray', {
15871
- get: function () { return createFormatter$1(enableColors, __spreadArray(__spreadArray([], __read(colors), false), [ColorEnum.BgGray], false), formatters); },
15872
- });
15873
- Object.defineProperty(fn, 'reset', {
15874
- get: function () { return createFormatter$1(enableColors, __spreadArray(__spreadArray([], __read(colors), false), [ColorEnum.Reset], false), formatters); },
15875
- });
15876
- Object.defineProperty(fn, 'bright', {
15877
- get: function () { return createFormatter$1(enableColors, __spreadArray(__spreadArray([], __read(colors), false), [ColorEnum.Bright], false), formatters); },
15878
- });
15879
- Object.defineProperty(fn, 'dim', {
15880
- get: function () { return createFormatter$1(enableColors, __spreadArray(__spreadArray([], __read(colors), false), [ColorEnum.Dim], false), formatters); },
15881
- });
15882
- Object.defineProperty(fn, 'italic', {
15883
- get: function () { return createFormatter$1(enableColors, __spreadArray(__spreadArray([], __read(colors), false), [ColorEnum.Dim], false), formatters); },
15884
- });
15885
- Object.defineProperty(fn, 'underscore', {
15886
- get: function () { return createFormatter$1(enableColors, __spreadArray(__spreadArray([], __read(colors), false), [ColorEnum.Underscore], false), formatters); },
15887
- });
15888
- Object.defineProperty(fn, 'blink', {
15889
- get: function () { return createFormatter$1(enableColors, __spreadArray(__spreadArray([], __read(colors), false), [ColorEnum.Blink], false), formatters); },
15890
- });
15891
- Object.defineProperty(fn, 'reverse', {
15892
- get: function () { return createFormatter$1(enableColors, __spreadArray(__spreadArray([], __read(colors), false), [ColorEnum.Reverse], false), formatters); },
15893
- });
15894
- Object.defineProperty(fn, 'hidden', {
15895
- get: function () { return createFormatter$1(enableColors, __spreadArray(__spreadArray([], __read(colors), false), [ColorEnum.Hidden], false), formatters); },
15896
- });
15897
- fn.leftPad = function (length, char) { return createFormatter$1(enableColors, colors, [createLeftPad(length, char)]); };
15898
- fn.rightPad = function (length, char) { return createFormatter$1(enableColors, colors, [createRightPad(length, char)]); };
15899
- return fn;
15362
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
15363
+ finally {
15364
+ try {
15365
+ if (functionNamesFromLitsSrc_1_1 && !functionNamesFromLitsSrc_1_1.done && (_a$1 = functionNamesFromLitsSrc_1.return)) _a$1.call(functionNamesFromLitsSrc_1);
15366
+ }
15367
+ finally { if (e_1) throw e_1.error; }
15900
15368
  }
15901
- function createColorizer(enableColors) {
15902
- if (enableColors === void 0) { enableColors = true; }
15903
- return {
15904
- black: createFormatter$1(enableColors, [ColorEnum.FgBlack], []),
15905
- red: createFormatter$1(enableColors, [ColorEnum.FgRed], []),
15906
- green: createFormatter$1(enableColors, [ColorEnum.FgGreen], []),
15907
- yellow: createFormatter$1(enableColors, [ColorEnum.FgYellow], []),
15908
- blue: createFormatter$1(enableColors, [ColorEnum.FgBlue], []),
15909
- magenta: createFormatter$1(enableColors, [ColorEnum.FgMagenta], []),
15910
- cyan: createFormatter$1(enableColors, [ColorEnum.FgCyan], []),
15911
- white: createFormatter$1(enableColors, [ColorEnum.FgWhite], []),
15912
- gray: createFormatter$1(enableColors, [ColorEnum.FgGray], []),
15913
- bgBlack: createFormatter$1(enableColors, [ColorEnum.BgBlack], []),
15914
- bgRed: createFormatter$1(enableColors, [ColorEnum.BgRed], []),
15915
- bgGreen: createFormatter$1(enableColors, [ColorEnum.BgGreen], []),
15916
- bgYellow: createFormatter$1(enableColors, [ColorEnum.BgYellow], []),
15917
- bgBlue: createFormatter$1(enableColors, [ColorEnum.BgBlue], []),
15918
- bgMagenta: createFormatter$1(enableColors, [ColorEnum.BgMagenta], []),
15919
- bgCyan: createFormatter$1(enableColors, [ColorEnum.BgCyan], []),
15920
- bgWhite: createFormatter$1(enableColors, [ColorEnum.BgWhite], []),
15921
- bgGray: createFormatter$1(enableColors, [ColorEnum.BgGray], []),
15922
- reset: createFormatter$1(enableColors, [ColorEnum.Reset], []),
15923
- bright: createFormatter$1(enableColors, [ColorEnum.Bright], []),
15924
- dim: createFormatter$1(enableColors, [ColorEnum.Dim], []),
15925
- italic: createFormatter$1(enableColors, [ColorEnum.Italic], []),
15926
- underscore: createFormatter$1(enableColors, [ColorEnum.Underscore], []),
15927
- blink: createFormatter$1(enableColors, [ColorEnum.Blink], []),
15928
- reverse: createFormatter$1(enableColors, [ColorEnum.Reverse], []),
15929
- hidden: createFormatter$1(enableColors, [ColorEnum.Hidden], []),
15930
- leftPad: function (length, char) { return createFormatter$1(enableColors, [], [createLeftPad(length, char)]); },
15931
- rightPad: function (length, char) { return createFormatter$1(enableColors, [], [createRightPad(length, char)]); },
15932
- };
15369
+ try {
15370
+ for (var functionNames_1 = __values(functionNames), functionNames_1_1 = functionNames_1.next(); !functionNames_1_1.done; functionNames_1_1 = functionNames_1.next()) {
15371
+ var functionName = functionNames_1_1.value;
15372
+ if (!functionNamesFromLitsSrc.includes(functionName))
15373
+ throw new Error("Function name \"".concat(functionName, "\" is not included in the Lits source"));
15374
+ }
15933
15375
  }
15934
-
15935
- function getCliType(fmt, arg) {
15936
- var argType = isSpecialExpressionArgument(arg) ? arg.type.slice(1) : arg.type;
15937
- var types = Array.isArray(argType) ? argType : [argType];
15938
- var typeString = types.map(function (type) {
15939
- return fmt.dim.red(type);
15940
- }).join(' | ');
15941
- return arg.array || arg.rest
15942
- ? "".concat(fmt.bright.blue('Array')).concat(fmt.bright.gray('<')).concat(fmt.white(typeString)).concat(fmt.bright.gray('>'))
15943
- : fmt.white(typeString);
15376
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
15377
+ finally {
15378
+ try {
15379
+ if (functionNames_1_1 && !functionNames_1_1.done && (_b = functionNames_1.return)) _b.call(functionNames_1);
15380
+ }
15381
+ finally { if (e_2) throw e_2.error; }
15944
15382
  }
15945
-
15946
- function getCliFunctionSignature(fmt, _a) {
15947
- var name = _a.title, variants = _a.variants, args = _a.args, returns = _a.returns;
15948
- return variants.map(function (variant) {
15949
- var form = (variant.argumentNames.length === 0)
15950
- ? "".concat(fmt.white('(')).concat(fmt.blue(name)).concat(fmt.white(')'))
15951
- : "".concat(fmt.white('(')).concat(fmt.blue(name), " ").concat(variant.argumentNames.map(function (argName) {
15952
- var result = '';
15953
- var arg = args[argName];
15954
- if (arg) {
15955
- if (arg.rest)
15956
- result += fmt.white('& ');
15957
- result += "".concat(fmt.green(argName));
15958
- if (arg.type === '*binding' || arg.type === '*for-binding')
15959
- result = "".concat(fmt.white('[')).concat(result).concat(fmt.white(']'));
15960
- else if (arg.type === '*arguments')
15961
- result = "".concat(fmt.white('[')).concat(result).concat(fmt.white(']'));
15962
- else if (arg.type === '*catch-expression')
15963
- result = "".concat(fmt.white('(')).concat(result, " ").concat(fmt.bright.blue('body')).concat(fmt.white(')'));
15964
- }
15965
- return result;
15966
- }).join(' ')).concat(fmt.white(')'));
15967
- return "".concat(form, " ").concat(fmt.gray('=>'), " ").concat(getCliType(fmt, returns));
15968
- }).join('\n');
15383
+ function isApiName(arg) {
15384
+ return apiNames.includes(arg);
15969
15385
  }
15970
15386
 
15971
15387
  function getClojureDocsLink(functionName, clojureDocs) {
@@ -16013,7 +15429,7 @@ function createFormatter(rules, options) {
16013
15429
  return format;
16014
15430
  }
16015
15431
 
16016
- var variableRegExp$1 = new RegExp("^\\$".concat(identifierFirstCharacterClass).concat(identifierCharacterClass, "*"));
15432
+ var variableRegExp$1 = new RegExp("^\\$".concat(nameCharacters, "+"));
16017
15433
  var noMatch = { count: 0, formattedText: '' };
16018
15434
  function createVariableRule(formatVariableName, variableNamePredicate) {
16019
15435
  return function (text, index) {
@@ -16036,11 +15452,11 @@ var getNumberRule = function (fmt) { return function (text, index) {
16036
15452
  var count = startMatch[0].length;
16037
15453
  var characterBefor = text[index - 1];
16038
15454
  var characterAfter = text[index + count];
16039
- if (characterBefor && new RegExp(identifierCharacterClass).test(characterBefor))
15455
+ if (characterBefor && new RegExp(nameCharacters).test(characterBefor))
16040
15456
  return noMatch;
16041
15457
  if (characterBefor && numberRegExp.test(characterBefor))
16042
15458
  return noMatch;
16043
- if (characterAfter && new RegExp(identifierCharacterClass).test(characterAfter))
15459
+ if (characterAfter && new RegExp(nameCharacters).test(characterAfter))
16044
15460
  return noMatch;
16045
15461
  if (characterAfter && numberRegExp.test(characterAfter))
16046
15462
  return noMatch;
@@ -16071,7 +15487,7 @@ var stringRule = createRule({
16071
15487
  });
16072
15488
  var shortcutStringRule = createRule({
16073
15489
  name: 'string',
16074
- startPattern: new RegExp("^:".concat(identifierCharacterClass, "+")),
15490
+ startPattern: new RegExp("^:".concat(nameCharacters, "+")),
16075
15491
  startTag: ColorEnum.FgRed,
16076
15492
  endTag: ColorEnum.Reset,
16077
15493
  keepPatterns: true,
@@ -16080,7 +15496,7 @@ var shortcutStringRule = createRule({
16080
15496
  });
16081
15497
  var functionNameRule = createRule({
16082
15498
  name: 'functionName',
16083
- startPattern: new RegExp("^\\((?=".concat(identifierCharacterClass, "+)")),
15499
+ startPattern: new RegExp("^\\((?=".concat(nameCharacters, "+)")),
16084
15500
  endPattern: /^[) \n]/,
16085
15501
  startTag: ColorEnum.FgBlue,
16086
15502
  endTag: ColorEnum.Reset,
@@ -16090,7 +15506,7 @@ var functionNameRule = createRule({
16090
15506
  });
16091
15507
  var nameRule = createRule({
16092
15508
  name: 'functionName',
16093
- startPattern: new RegExp("^".concat(identifierCharacterClass, "+")),
15509
+ startPattern: new RegExp("^".concat(nameCharacters, "+")),
16094
15510
  startTag: "".concat(ColorEnum.Bright).concat(ColorEnum.FgBlue),
16095
15511
  endTag: ColorEnum.Reset,
16096
15512
  keepPatterns: true,
@@ -16231,7 +15647,7 @@ function createRule(_a) {
16231
15647
  };
16232
15648
  }
16233
15649
 
16234
- var variableRegExp = new RegExp("\\$".concat(identifierFirstCharacterClass).concat(identifierCharacterClass, "*"), 'g');
15650
+ var variableRegExp = new RegExp("\\$".concat(nameCharacters, "+"), 'g');
16235
15651
  function formatCliDescription(fmt, description, reference) {
16236
15652
  if (isFunctionReference(reference))
16237
15653
  return formatFunctionDescription(fmt, description, reference);
@@ -16374,9 +15790,9 @@ var historyResults = [];
16374
15790
  var lits = new Lits({ debug: true });
16375
15791
  var formatValue = getInlineCodeFormatter(fmt);
16376
15792
  var commands = ['`help', '`quit', '`builtins', '`context'];
16377
- var expressionRegExp = new RegExp("^(.*\\(\\s*)(".concat(identifierFirstCharacterClass).concat(identifierCharacterClass, "*)$"));
16378
- var nameRegExp = new RegExp("^(.*?)(".concat(identifierFirstCharacterClass).concat(identifierCharacterClass, "*)$"));
16379
- var helpRegExp = new RegExp("^`help\\s+(".concat(identifierFirstCharacterClass).concat(identifierCharacterClass, "+)\\s*$"));
15793
+ var expressionRegExp = new RegExp("^(.*\\(\\s*)(".concat(nameCharacters, "*)$"));
15794
+ var nameRegExp = new RegExp("^(.*?)(".concat(nameCharacters, "*)$"));
15795
+ var helpRegExp = new RegExp("^`help\\s+(".concat(nameCharacters, "+)\\s*$"));
16380
15796
  var expressions = __spreadArray(__spreadArray([], __read(normalExpressionKeys), false), __read(specialExpressionKeys), false);
16381
15797
  var config = processArguments(process.argv.slice(2));
16382
15798
  if (config.eval) {