@mojir/lits 2.1.35 → 2.1.37

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/lits.iife.js CHANGED
@@ -11719,7 +11719,6 @@ var Lits = (function (exports) {
11719
11719
  _b.arity = arity,
11720
11720
  _b.docString = docString,
11721
11721
  _b);
11722
- evaluatedFunction[2].self = { value: litsFunction };
11723
11722
  return litsFunction;
11724
11723
  },
11725
11724
  getUndefinedSymbols: function (node, contextStack, _a) {
@@ -12509,13 +12508,13 @@ var Lits = (function (exports) {
12509
12508
  var args = evaluatedFunction[0];
12510
12509
  var nbrOfNonRestArgs = args.filter(function (arg) { return arg[0] !== bindingTargetTypes.rest; }).length;
12511
12510
  var newContextStack = contextStack.create(fn.evaluatedfunction[2]);
12512
- var newContext = {};
12511
+ var newContext = { self: { value: fn } };
12513
12512
  var rest = [];
12514
12513
  for (var i = 0; i < params.length; i += 1) {
12515
12514
  if (i < nbrOfNonRestArgs) {
12516
12515
  var param = toAny(params[i]);
12517
- var valueRecord = evalueateBindingNodeValues(args[i], param, function (Node) {
12518
- return evaluateNode(Node, newContextStack.create(newContext));
12516
+ var valueRecord = evalueateBindingNodeValues(args[i], param, function (node) {
12517
+ return evaluateNode(node, newContextStack.create(newContext));
12519
12518
  });
12520
12519
  Object.entries(valueRecord).forEach(function (_a) {
12521
12520
  var _b = __read(_a, 2), key = _b[0], value = _b[1];
@@ -12529,8 +12528,8 @@ var Lits = (function (exports) {
12529
12528
  for (var i = params.length; i < nbrOfNonRestArgs; i++) {
12530
12529
  var arg = args[i];
12531
12530
  var defaultValue = evaluateNode(arg[1][1], contextStack.create(newContext));
12532
- var valueRecord = evalueateBindingNodeValues(arg, defaultValue, function (Node) {
12533
- return evaluateNode(Node, contextStack.create(newContext));
12531
+ var valueRecord = evalueateBindingNodeValues(arg, defaultValue, function (node) {
12532
+ return evaluateNode(node, contextStack.create(newContext));
12534
12533
  });
12535
12534
  Object.entries(valueRecord).forEach(function (_a) {
12536
12535
  var _b = __read(_a, 2), key = _b[0], value = _b[1];
@@ -12539,7 +12538,7 @@ var Lits = (function (exports) {
12539
12538
  }
12540
12539
  var restArgument = args.find(function (arg) { return arg[0] === bindingTargetTypes.rest; });
12541
12540
  if (restArgument !== undefined) {
12542
- var valueRecord = evalueateBindingNodeValues(restArgument, rest, function (Node) { return evaluateNode(Node, contextStack.create(newContext)); });
12541
+ var valueRecord = evalueateBindingNodeValues(restArgument, rest, function (node) { return evaluateNode(node, contextStack.create(newContext)); });
12543
12542
  Object.entries(valueRecord).forEach(function (_a) {
12544
12543
  var _b = __read(_a, 2), key = _b[0], value = _b[1];
12545
12544
  newContext[key] = { value: value };
@@ -13078,6 +13077,21 @@ var Lits = (function (exports) {
13078
13077
  };
13079
13078
  return ContextStackImpl;
13080
13079
  }());
13080
+ function checkNotDefined(name) {
13081
+ if (specialExpressionKeys.includes(name)) {
13082
+ console.warn("Cannot shadow special expression \"".concat(name, "\", ignoring."));
13083
+ return false;
13084
+ }
13085
+ if (normalExpressionKeys.includes(name)) {
13086
+ console.warn("Cannot shadow builtin function \"".concat(name, "\", ignoring."));
13087
+ return false;
13088
+ }
13089
+ if (name === 'self') {
13090
+ console.warn("Cannot shadow builtin value \"".concat(name, "\", ignoring."));
13091
+ return false;
13092
+ }
13093
+ return true;
13094
+ }
13081
13095
  function createContextStack(params) {
13082
13096
  var _a;
13083
13097
  if (params === void 0) { params = {}; }
@@ -13089,26 +13103,53 @@ var Lits = (function (exports) {
13089
13103
  values: params.values,
13090
13104
  nativeJsFunctions: params.jsFunctions
13091
13105
  && Object.entries(params.jsFunctions).reduce(function (acc, _a) {
13092
- var _b;
13093
- var _c, _d;
13094
- var _e = __read(_a, 2), name = _e[0], jsFunction = _e[1];
13095
- if (specialExpressionKeys.includes(name)) {
13096
- console.warn("Cannot shadow special expression \"".concat(name, "\", ignoring."));
13106
+ var e_5, _b, _c;
13107
+ var _d, _e;
13108
+ var _f = __read(_a, 2), identifier = _f[0], entry = _f[1];
13109
+ var identifierParts = identifier.split('.');
13110
+ var name = identifierParts.pop();
13111
+ if (/^[A-Z]/.test(name)) {
13112
+ console.warn("Invalid identifier \"".concat(identifier, "\" in jsFunctions, function name must not start with an uppercase letter"), undefined);
13097
13113
  return acc;
13098
13114
  }
13099
- if (normalExpressionKeys.includes(name)) {
13100
- console.warn("Cannot shadow builtin function \"".concat(name, "\", ignoring."));
13101
- return acc;
13115
+ var scope = acc;
13116
+ try {
13117
+ for (var identifierParts_1 = __values(identifierParts), identifierParts_1_1 = identifierParts_1.next(); !identifierParts_1_1.done; identifierParts_1_1 = identifierParts_1.next()) {
13118
+ var part = identifierParts_1_1.value;
13119
+ if (part.length === 0) {
13120
+ console.warn("Invalid empty identifier \"".concat(identifier, "\" in nativeJsFunctions"), undefined);
13121
+ return acc;
13122
+ }
13123
+ if (!/^[A-Z]/.test(part)) {
13124
+ console.warn("Invalid identifier \"".concat(identifier, "\" in jsFunctions, namespace must start with an uppercase letter"), undefined);
13125
+ return acc;
13126
+ }
13127
+ if (!scope[part]) {
13128
+ scope[part] = {};
13129
+ }
13130
+ scope = scope[part];
13131
+ }
13102
13132
  }
13103
- acc[name] = (_b = {
13133
+ catch (e_5_1) { e_5 = { error: e_5_1 }; }
13134
+ finally {
13135
+ try {
13136
+ if (identifierParts_1_1 && !identifierParts_1_1.done && (_b = identifierParts_1.return)) _b.call(identifierParts_1);
13137
+ }
13138
+ finally { if (e_5) throw e_5.error; }
13139
+ }
13140
+ var natifeFn = (_c = {
13104
13141
  functionType: 'NativeJsFunction',
13105
- nativeFn: jsFunction,
13142
+ nativeFn: entry,
13106
13143
  name: name
13107
13144
  },
13108
- _b[FUNCTION_SYMBOL] = true,
13109
- _b.arity = (_c = jsFunction.arity) !== null && _c !== void 0 ? _c : {},
13110
- _b.docString = (_d = jsFunction.docString) !== null && _d !== void 0 ? _d : '',
13111
- _b);
13145
+ _c[FUNCTION_SYMBOL] = true,
13146
+ _c.arity = (_d = entry.arity) !== null && _d !== void 0 ? _d : {},
13147
+ _c.docString = (_e = entry.docString) !== null && _e !== void 0 ? _e : '',
13148
+ _c);
13149
+ if (scope === acc && !checkNotDefined(name)) {
13150
+ return acc;
13151
+ }
13152
+ scope[name] = natifeFn;
13112
13153
  return acc;
13113
13154
  }, {}),
13114
13155
  });
@@ -13949,9 +13990,6 @@ var Lits = (function (exports) {
13949
13990
  case 'doseq':
13950
13991
  left = this.parseForOrDoseq(firstToken);
13951
13992
  break;
13952
- // cas:
13953
- // left = this.parseDo(firstToken)
13954
- // break
13955
13993
  case 'loop':
13956
13994
  left = this.parseLoop(firstToken);
13957
13995
  break;
@@ -14153,6 +14191,12 @@ var Lits = (function (exports) {
14153
14191
  params.push(withSourceCodeInfo([NodeTypes.String, value], token[2]));
14154
14192
  this.advance();
14155
14193
  }
14194
+ else if (isLBracketToken(token)) {
14195
+ this.advance();
14196
+ params.push(this.parseExpression());
14197
+ assertRBracketToken(this.peek());
14198
+ this.advance();
14199
+ }
14156
14200
  else {
14157
14201
  throw new LitsError('Expected key to be a symbol or a string', this.peekSourceCodeInfo());
14158
14202
  }
@@ -14283,9 +14327,17 @@ var Lits = (function (exports) {
14283
14327
  var nodes = void 0;
14284
14328
  var docString = '';
14285
14329
  if (isLBraceToken(this.peek())) {
14286
- var parsedBlock = this.parseBlock(true);
14287
- docString = parsedBlock[1];
14288
- nodes = parsedBlock[0][1][1];
14330
+ var positionBefore = this.parseState.position;
14331
+ try {
14332
+ var objectNode = this.parseObject();
14333
+ nodes = [objectNode];
14334
+ }
14335
+ catch (_a) {
14336
+ this.parseState.position = positionBefore;
14337
+ var parsedBlock = this.parseBlock(true);
14338
+ docString = parsedBlock[1];
14339
+ nodes = parsedBlock[0][1][1];
14340
+ }
14289
14341
  }
14290
14342
  else {
14291
14343
  nodes = [this.parseExpression()];
@@ -14302,7 +14354,7 @@ var Lits = (function (exports) {
14302
14354
  ],
14303
14355
  ], firstToken[2]);
14304
14356
  }
14305
- catch (_a) {
14357
+ catch (_b) {
14306
14358
  return null;
14307
14359
  }
14308
14360
  };
@@ -14352,9 +14404,17 @@ var Lits = (function (exports) {
14352
14404
  var nodes;
14353
14405
  var docString = '';
14354
14406
  if (isLBraceToken(this.peek())) {
14355
- var parsedBlock = this.parseBlock(true);
14356
- docString = parsedBlock[1];
14357
- nodes = parsedBlock[0][1][1];
14407
+ var positionBefore = this.parseState.position;
14408
+ try {
14409
+ var objectNode = this.parseObject();
14410
+ nodes = [objectNode];
14411
+ }
14412
+ catch (_b) {
14413
+ this.parseState.position = positionBefore;
14414
+ var parsedBlock = this.parseBlock(true);
14415
+ docString = parsedBlock[1];
14416
+ nodes = parsedBlock[0][1][1];
14417
+ }
14358
14418
  }
14359
14419
  else {
14360
14420
  nodes = [this.parseExpression()];
@@ -14552,9 +14612,6 @@ var Lits = (function (exports) {
14552
14612
  throw new LitsError('Expected }', this.peekSourceCodeInfo());
14553
14613
  }
14554
14614
  }
14555
- if (expressions.length === 0) {
14556
- expressions.push(withSourceCodeInfo([NodeTypes.ReservedSymbol, 'null'], token[2]));
14557
- }
14558
14615
  assertRBraceToken(this.peek());
14559
14616
  this.advance();
14560
14617
  return [
@@ -26691,6 +26748,50 @@ var Lits = (function (exports) {
26691
26748
  };
26692
26749
 
26693
26750
  var specialExpressionsReference = {
26751
+ 'doseq': {
26752
+ title: 'doseq',
26753
+ category: 'Special expression',
26754
+ customVariants: ['doseq (...binding) -> body'],
26755
+ details: [
26756
+ ['binding', 'loop-var in collection [...let-binding] [where whereExpr] [while whileExp]', 'A doseq loop binding'],
26757
+ ['loop-var', 'symbol', 'The name of the loop variable.'],
26758
+ ['collection', 'any', 'The collection to iterate over.'],
26759
+ ['let-binding', 'let binding', 'A let binding to create a local variable.'],
26760
+ ['whereExpr', 'expression', 'An expression that must evaluate to truthy for the loop body to be executed.'],
26761
+ ['whileExp', 'expression', 'An expression that must evaluate to truthy for the loop to continue.'],
26762
+ ['body', 'expressions', 'The expressions to evaluate for each iteration of the loop.'],
26763
+ ],
26764
+ returns: {
26765
+ type: 'null',
26766
+ },
26767
+ description: 'Iterates over `bindings`, evaluates `body` for each `binding` and returns `null`. This is useful for side effects.',
26768
+ examples: [
26769
+ "\ndoseq (i in [1, 2, 3]) -> write!(i * 2)\n ",
26770
+ ],
26771
+ },
26772
+ 'for': {
26773
+ title: 'for',
26774
+ category: 'Special expression',
26775
+ customVariants: ['for (...binding) -> body'],
26776
+ details: [
26777
+ ['binding', 'loop-var in collection [...let-binding] [where whereExpr] [while whileExp]', 'A for loop binding'],
26778
+ ['loop-var', 'symbol', 'The name of the loop variable.'],
26779
+ ['collection', 'any', 'The collection to iterate over.'],
26780
+ ['let-binding', 'let binding', 'A let binding to create a local variable.'],
26781
+ ['whereExpr', 'expression', 'An expression that must evaluate to truthy for the loop body to be executed.'],
26782
+ ['whileExp', 'expression', 'An expression that must evaluate to truthy for the loop to continue.'],
26783
+ ['body', 'expressions', 'The expressions to evaluate for each iteration of the loop.'],
26784
+ ],
26785
+ returns: {
26786
+ type: 'any',
26787
+ array: true,
26788
+ },
26789
+ description: 'Iterates over `bindings`, evaluates `body` for each `binding` and returns an `array` of results.',
26790
+ examples: [
26791
+ "\nfor (i in [1, 2, 3]) -> i * 2\n ",
26792
+ "\nfor (\n i in range(10) let ii = i ^ 2 while ii < 40 when ii % 3 == 0,\n j in range(10) when j % 2 == 1\n) -> ii + j\n ",
26793
+ ],
26794
+ },
26694
26795
  'array': {
26695
26796
  title: 'array',
26696
26797
  category: 'Special expression',