@mojir/lits 2.1.1 → 2.1.2

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/index.esm.js CHANGED
@@ -3736,31 +3736,6 @@ var switchSpecialExpression = {
3736
3736
  },
3737
3737
  };
3738
3738
 
3739
- var specialExpressionTypes = {
3740
- '??': 0,
3741
- '&&': 1,
3742
- '||': 2,
3743
- 'array': 3,
3744
- 'cond': 4,
3745
- 'def': 5,
3746
- 'defined?': 6,
3747
- 'defn': 7,
3748
- 'do': 8,
3749
- 'doseq': 9,
3750
- 'fn': 10,
3751
- 'for': 11,
3752
- 'function': 12,
3753
- 'if': 13,
3754
- 'let': 14,
3755
- 'loop': 15,
3756
- 'object': 16,
3757
- 'recur': 17,
3758
- 'switch': 18,
3759
- 'throw': 19,
3760
- 'try': 20,
3761
- 'unless': 21,
3762
- };
3763
-
3764
3739
  function isSymbolNode(node) {
3765
3740
  var nodeType = node[0];
3766
3741
  return NodeTypes.UserDefinedSymbol === nodeType
@@ -3785,25 +3760,9 @@ function assertUserDefinedSymbolNode(node, sourceCodeInfo) {
3785
3760
  function isNormalBuiltinSymbolNode(node) {
3786
3761
  return NodeTypes.NormalBuiltinSymbol === node[0];
3787
3762
  }
3788
- function isSpecialBuiltinSymbolNode(node, name) {
3789
- if (NodeTypes.SpecialBuiltinSymbol !== node[0]) {
3790
- return false;
3791
- }
3792
- {
3793
- return true;
3794
- }
3763
+ function isSpecialBuiltinSymbolNode(node) {
3764
+ return NodeTypes.SpecialBuiltinSymbol === node[0];
3795
3765
  }
3796
- // export function isNumberNode(node: Node): node is NumberNode {
3797
- // return node[0] === NodeTypes.Number
3798
- // }
3799
- // export function asNumberNode(node: Node, sourceCodeInfo?: SourceCodeInfo): NumberNode {
3800
- // assertNumberNode(node, sourceCodeInfo)
3801
- // return node
3802
- // }
3803
- // export function assertNumberNode(node: Node, sourceCodeInfo?: SourceCodeInfo): asserts node is NumberNode {
3804
- // if (!isNumberNode(node))
3805
- // throw getAssertionError('NumberNode', node, sourceCodeInfo)
3806
- // }
3807
3766
  function isNormalExpressionNode(node) {
3808
3767
  return node[0] === NodeTypes.NormalExpression;
3809
3768
  }
@@ -3841,6 +3800,29 @@ var bindingTargetTypes = {
3841
3800
  array: 14,
3842
3801
  };
3843
3802
 
3803
+ function walkDefaults(bindingTarget, onDefault) {
3804
+ var _a;
3805
+ if (bindingTarget[0] === bindingTargetTypes.object) {
3806
+ Object.values(bindingTarget[1][0]).forEach(function (element) {
3807
+ if (element[1][1]) {
3808
+ onDefault(element[1][1]);
3809
+ }
3810
+ walkDefaults(element, onDefault);
3811
+ });
3812
+ }
3813
+ else if (bindingTarget[0] === bindingTargetTypes.array) {
3814
+ for (var index = 0; index < bindingTarget[1][0].length; index += 1) {
3815
+ var element = (_a = bindingTarget[1][0][index]) !== null && _a !== void 0 ? _a : null;
3816
+ if (element === null) {
3817
+ continue;
3818
+ }
3819
+ if (element[1][1]) {
3820
+ onDefault(element[1][1]);
3821
+ }
3822
+ walkDefaults(element, onDefault);
3823
+ }
3824
+ }
3825
+ }
3844
3826
  function evalueateBindingNodeValues(target, value, evaluate) {
3845
3827
  var sourceCodeInfo = target[2];
3846
3828
  var record = {};
@@ -3980,6 +3962,9 @@ var defSpecialExpression = {
3980
3962
  var target = bindingNode[1][0];
3981
3963
  var value = bindingNode[1][1];
3982
3964
  var bindingResult = getUndefinedSymbols([value], contextStack, builtin, evaluateNode);
3965
+ walkDefaults(target, function (defaultNode) {
3966
+ addToSet(bindingResult, getUndefinedSymbols([defaultNode], contextStack, builtin, evaluateNode));
3967
+ });
3983
3968
  contextStack.addValues(getAllBindingTargetNames(target));
3984
3969
  return bindingResult;
3985
3970
  },
@@ -4068,6 +4053,31 @@ function isNumberReservedSymbol(symbol) {
4068
4053
  return symbol in numberReservedSymbolRecord;
4069
4054
  }
4070
4055
 
4056
+ var specialExpressionTypes = {
4057
+ '??': 0,
4058
+ '&&': 1,
4059
+ '||': 2,
4060
+ 'array': 3,
4061
+ 'cond': 4,
4062
+ '0_def': 5,
4063
+ 'defined?': 6,
4064
+ '0_defn': 7,
4065
+ 'do': 8,
4066
+ 'doseq': 9,
4067
+ '0_fn': 10,
4068
+ 'for': 11,
4069
+ 'function': 12,
4070
+ 'if': 13,
4071
+ 'let': 14,
4072
+ 'loop': 15,
4073
+ 'object': 16,
4074
+ 'recur': 17,
4075
+ 'switch': 18,
4076
+ 'throw': 19,
4077
+ 'try': 20,
4078
+ 'unless': 21,
4079
+ };
4080
+
4071
4081
  function assertNameNotDefined(name, contextStack, builtin, sourceCodeInfo) {
4072
4082
  if (typeof name !== 'string')
4073
4083
  return;
@@ -4107,7 +4117,7 @@ var functionSpecialExpression = {
4107
4117
  var functionName = node[1][1][1];
4108
4118
  contextStack.addValues((_b = {}, _b[functionName] = true, _b));
4109
4119
  var newContext = (_c = {}, _c[functionName] = { value: true }, _c);
4110
- return addFunctionUnresolvedSymbols(node[1][2], contextStack, getUndefinedSymbols, builtin, evaluateNode, newContext);
4120
+ return getFunctionUnresolvedSymbols(node[1][2], contextStack, getUndefinedSymbols, builtin, evaluateNode, newContext);
4111
4121
  },
4112
4122
  };
4113
4123
  var defnSpecialExpression = {
@@ -4136,7 +4146,7 @@ var defnSpecialExpression = {
4136
4146
  var fn = node[1][2];
4137
4147
  contextStack.exportValues((_b = {}, _b[functionName] = true, _b));
4138
4148
  var newContext = (_c = {}, _c[functionName] = { value: true }, _c);
4139
- return addFunctionUnresolvedSymbols(fn, contextStack, getUndefinedSymbols, builtin, evaluateNode, newContext);
4149
+ return getFunctionUnresolvedSymbols(fn, contextStack, getUndefinedSymbols, builtin, evaluateNode, newContext);
4140
4150
  },
4141
4151
  };
4142
4152
  var fnSpecialExpression = {
@@ -4158,7 +4168,7 @@ var fnSpecialExpression = {
4158
4168
  getUndefinedSymbols: function (node, contextStack, _a) {
4159
4169
  var getUndefinedSymbols = _a.getUndefinedSymbols, builtin = _a.builtin, evaluateNode = _a.evaluateNode;
4160
4170
  var fn = node[1][1];
4161
- return addFunctionUnresolvedSymbols(fn, contextStack, getUndefinedSymbols, builtin, evaluateNode);
4171
+ return getFunctionUnresolvedSymbols(fn, contextStack, getUndefinedSymbols, builtin, evaluateNode);
4162
4172
  },
4163
4173
  };
4164
4174
  function evaluateFunction(fn, contextStack, builtin, getUndefinedSymbols, evaluateNode) {
@@ -4183,12 +4193,15 @@ function evaluateFunction(fn, contextStack, builtin, getUndefinedSymbols, evalua
4183
4193
  ];
4184
4194
  return evaluatedFunction;
4185
4195
  }
4186
- function addFunctionUnresolvedSymbols(fn, contextStack, getUndefinedSymbols, builtin, evaluateNode, functionNameContext) {
4196
+ function getFunctionUnresolvedSymbols(fn, contextStack, getUndefinedSymbols, builtin, evaluateNode, functionNameContext) {
4187
4197
  var result = new Set();
4188
4198
  var contextStackWithFunctionName = functionNameContext ? contextStack.create(functionNameContext) : contextStack;
4189
4199
  var newContext = {};
4190
4200
  fn[0].forEach(function (arg) {
4191
4201
  Object.assign(newContext, getAllBindingTargetNames(arg));
4202
+ walkDefaults(arg, function (defaultNode) {
4203
+ addToSet(result, getUndefinedSymbols([defaultNode], contextStack, builtin, evaluateNode));
4204
+ });
4192
4205
  });
4193
4206
  var newContextStack = contextStackWithFunctionName.create(newContext);
4194
4207
  var overloadResult = getUndefinedSymbols(fn[1], newContextStack, builtin, evaluateNode);
@@ -4252,6 +4265,9 @@ var letSpecialExpression = {
4252
4265
  var target = bindingNode[1][0];
4253
4266
  var value = bindingNode[1][1];
4254
4267
  var bindingResult = getUndefinedSymbols([value], contextStack, builtin, evaluateNode);
4268
+ walkDefaults(target, function (defaultNode) {
4269
+ addToSet(bindingResult, getUndefinedSymbols([defaultNode], contextStack, builtin, evaluateNode));
4270
+ });
4255
4271
  contextStack.addValues(getAllBindingTargetNames(target));
4256
4272
  return bindingResult;
4257
4273
  },
@@ -4746,6 +4762,7 @@ function findUnresolvedSymbolsInNode(node, contextStack, builtin, evaluateNode)
4746
4762
  case NodeTypes.String:
4747
4763
  case NodeTypes.Number:
4748
4764
  case NodeTypes.ReservedSymbol:
4765
+ case NodeTypes.Binding:
4749
4766
  return null;
4750
4767
  case NodeTypes.NormalExpression: {
4751
4768
  var normalExpressionNode = node;
@@ -4790,10 +4807,7 @@ function findUnresolvedSymbolsInNode(node, contextStack, builtin, evaluateNode)
4790
4807
  }
4791
4808
  case NodeTypes.Spread:
4792
4809
  return findUnresolvedSymbolsInNode(node[1], contextStack, builtin, evaluateNode);
4793
- case NodeTypes.Binding: {
4794
- var bindingNode = node;
4795
- return findUnresolvedSymbolsInNode(bindingNode[1][1], contextStack, builtin, evaluateNode);
4796
- }
4810
+ /* v8 ignore next 2 */
4797
4811
  default:
4798
4812
  throw new Error("Unhandled node type: ".concat(nodeType));
4799
4813
  }
@@ -5295,8 +5309,6 @@ var ContextStackImpl = /** @class */ (function () {
5295
5309
  var lookUpResult = this.lookUp(node);
5296
5310
  if (isContextEntry(lookUpResult))
5297
5311
  return lookUpResult.value;
5298
- else if (isBuiltinFunction(lookUpResult))
5299
- return lookUpResult;
5300
5312
  throw new UndefinedSymbolError(node[1], node[2]);
5301
5313
  };
5302
5314
  return ContextStackImpl;
@@ -5380,10 +5392,10 @@ var nonFunctionOperators = [
5380
5392
  'cond',
5381
5393
  'def',
5382
5394
  'defined?',
5383
- 'defn',
5395
+ // 'defn',
5384
5396
  'do',
5385
5397
  'doseq',
5386
- 'fn',
5398
+ // 'fn',
5387
5399
  'if',
5388
5400
  'let',
5389
5401
  'loop',
@@ -6228,10 +6240,7 @@ var Parser = /** @class */ (function () {
6228
6240
  if (specialExpressionTypes[operatorName] !== undefined) {
6229
6241
  return withSourceCodeInfo([NodeTypes.SpecialBuiltinSymbol, specialExpressionTypes[operatorName]], token[2]);
6230
6242
  }
6231
- else if (normalExpressionTypes[operatorName] !== undefined) {
6232
- return withSourceCodeInfo([NodeTypes.NormalBuiltinSymbol, normalExpressionTypes[operatorName]], token[2]);
6233
- }
6234
- return withSourceCodeInfo([NodeTypes.UserDefinedSymbol, operatorName], token[2]);
6243
+ return withSourceCodeInfo([NodeTypes.NormalBuiltinSymbol, normalExpressionTypes[operatorName]], token[2]);
6235
6244
  }
6236
6245
  if (operatorName === '->') {
6237
6246
  return this.parseShorthandLamdaFunction();
@@ -6391,9 +6400,9 @@ var Parser = /** @class */ (function () {
6391
6400
  var _b = __read(params, 1), param = _b[0];
6392
6401
  return withSourceCodeInfo([NodeTypes.SpecialExpression, [type, param]], symbol[2]);
6393
6402
  }
6394
- case specialExpressionTypes.fn:
6395
- case specialExpressionTypes.def:
6396
- case specialExpressionTypes.defn:
6403
+ case specialExpressionTypes['0_fn']:
6404
+ case specialExpressionTypes['0_def']:
6405
+ case specialExpressionTypes['0_defn']:
6397
6406
  throw new LitsError("".concat(type, " is not allowed"), symbol[2]);
6398
6407
  /* v8 ignore next 2 */
6399
6408
  default:
@@ -6421,7 +6430,7 @@ var Parser = /** @class */ (function () {
6421
6430
  }
6422
6431
  this.advance();
6423
6432
  var body = this.parseExpression();
6424
- return withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.fn, [
6433
+ return withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes['0_fn'], [
6425
6434
  functionArguments,
6426
6435
  [body],
6427
6436
  ]]], firstToken[2]);
@@ -6504,7 +6513,7 @@ var Parser = /** @class */ (function () {
6504
6513
  functionArguments.push(withSourceCodeInfo([bindingTargetTypes.symbol, [[NodeTypes.UserDefinedSymbol, "$".concat(i)], undefined]], firstToken[2]));
6505
6514
  }
6506
6515
  }
6507
- var node = withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.fn, [
6516
+ var node = withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes['0_fn'], [
6508
6517
  functionArguments,
6509
6518
  [exprNode],
6510
6519
  ]]], firstToken[2]);
@@ -7023,7 +7032,7 @@ var Parser = /** @class */ (function () {
7023
7032
  this.advance();
7024
7033
  if (isSymbolToken(this.peek(), 'let')) {
7025
7034
  var letNode = this.parseLet(asSymbolToken(this.peek()));
7026
- return withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.def, letNode[1][1]]], token[2]);
7035
+ return withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes['0_def'], letNode[1][1]]], token[2]);
7027
7036
  }
7028
7037
  else if (isReservedSymbolToken(this.peek(), 'function')) {
7029
7038
  this.advance();
@@ -7041,7 +7050,7 @@ var Parser = /** @class */ (function () {
7041
7050
  }
7042
7051
  assertReservedSymbolToken(this.peek(), 'end');
7043
7052
  this.advance();
7044
- return withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.defn, symbol, [
7053
+ return withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes['0_defn'], symbol, [
7045
7054
  functionArguments,
7046
7055
  body,
7047
7056
  ]]], token[2]);
@@ -7051,7 +7060,7 @@ var Parser = /** @class */ (function () {
7051
7060
  }
7052
7061
  };
7053
7062
  Parser.prototype.stringToSymbolNode = function (value, sourceCodeInfo) {
7054
- if (specialExpressionTypes[value] !== undefined) {
7063
+ if (specialExpressionTypes[value] !== undefined && value !== 'fn' && value !== 'def' && value !== 'defn') {
7055
7064
  return withSourceCodeInfo([NodeTypes.SpecialBuiltinSymbol, specialExpressionTypes[value]], sourceCodeInfo);
7056
7065
  }
7057
7066
  if (normalExpressionTypes[value] !== undefined) {
@@ -7509,28 +7518,6 @@ var api = {
7509
7518
  'replace',
7510
7519
  'replace-all',
7511
7520
  ],
7512
- specialExpressions: [
7513
- '&&',
7514
- '||',
7515
- 'def',
7516
- 'let',
7517
- 'fn',
7518
- 'defn',
7519
- 'function',
7520
- 'try',
7521
- 'throw',
7522
- 'if',
7523
- 'unless',
7524
- 'cond',
7525
- 'switch',
7526
- 'do',
7527
- 'recur',
7528
- 'loop',
7529
- 'doseq',
7530
- 'for',
7531
- 'defined?',
7532
- '??',
7533
- ],
7534
7521
  string: [
7535
7522
  'string-repeat',
7536
7523
  'str',