@mojir/lits 2.1.36 → 2.1.38

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.
@@ -11800,7 +11800,6 @@ var lambdaSpecialExpression = {
11800
11800
  _b.arity = arity,
11801
11801
  _b.docString = docString,
11802
11802
  _b);
11803
- evaluatedFunction[2].self = { value: litsFunction };
11804
11803
  return litsFunction;
11805
11804
  },
11806
11805
  getUndefinedSymbols: function (node, contextStack, _a) {
@@ -12475,13 +12474,13 @@ var functionExecutors = {
12475
12474
  var args = evaluatedFunction[0];
12476
12475
  var nbrOfNonRestArgs = args.filter(function (arg) { return arg[0] !== bindingTargetTypes.rest; }).length;
12477
12476
  var newContextStack = contextStack.create(fn.evaluatedfunction[2]);
12478
- var newContext = {};
12477
+ var newContext = { self: { value: fn } };
12479
12478
  var rest = [];
12480
12479
  for (var i = 0; i < params.length; i += 1) {
12481
12480
  if (i < nbrOfNonRestArgs) {
12482
12481
  var param = toAny(params[i]);
12483
- var valueRecord = evalueateBindingNodeValues(args[i], param, function (Node) {
12484
- return evaluateNode(Node, newContextStack.create(newContext));
12482
+ var valueRecord = evalueateBindingNodeValues(args[i], param, function (node) {
12483
+ return evaluateNode(node, newContextStack.create(newContext));
12485
12484
  });
12486
12485
  Object.entries(valueRecord).forEach(function (_a) {
12487
12486
  var _b = __read(_a, 2), key = _b[0], value = _b[1];
@@ -12495,8 +12494,8 @@ var functionExecutors = {
12495
12494
  for (var i = params.length; i < nbrOfNonRestArgs; i++) {
12496
12495
  var arg = args[i];
12497
12496
  var defaultValue = evaluateNode(arg[1][1], contextStack.create(newContext));
12498
- var valueRecord = evalueateBindingNodeValues(arg, defaultValue, function (Node) {
12499
- return evaluateNode(Node, contextStack.create(newContext));
12497
+ var valueRecord = evalueateBindingNodeValues(arg, defaultValue, function (node) {
12498
+ return evaluateNode(node, contextStack.create(newContext));
12500
12499
  });
12501
12500
  Object.entries(valueRecord).forEach(function (_a) {
12502
12501
  var _b = __read(_a, 2), key = _b[0], value = _b[1];
@@ -12505,7 +12504,7 @@ var functionExecutors = {
12505
12504
  }
12506
12505
  var restArgument = args.find(function (arg) { return arg[0] === bindingTargetTypes.rest; });
12507
12506
  if (restArgument !== undefined) {
12508
- var valueRecord = evalueateBindingNodeValues(restArgument, rest, function (Node) { return evaluateNode(Node, contextStack.create(newContext)); });
12507
+ var valueRecord = evalueateBindingNodeValues(restArgument, rest, function (node) { return evaluateNode(node, contextStack.create(newContext)); });
12509
12508
  Object.entries(valueRecord).forEach(function (_a) {
12510
12509
  var _b = __read(_a, 2), key = _b[0], value = _b[1];
12511
12510
  newContext[key] = { value: value };
@@ -13044,6 +13043,21 @@ var ContextStackImpl = /** @class */ (function () {
13044
13043
  };
13045
13044
  return ContextStackImpl;
13046
13045
  }());
13046
+ function checkNotDefined(name) {
13047
+ if (specialExpressionKeys.includes(name)) {
13048
+ console.warn("Cannot shadow special expression \"".concat(name, "\", ignoring."));
13049
+ return false;
13050
+ }
13051
+ if (normalExpressionKeys.includes(name)) {
13052
+ console.warn("Cannot shadow builtin function \"".concat(name, "\", ignoring."));
13053
+ return false;
13054
+ }
13055
+ if (name === 'self') {
13056
+ console.warn("Cannot shadow builtin value \"".concat(name, "\", ignoring."));
13057
+ return false;
13058
+ }
13059
+ return true;
13060
+ }
13047
13061
  function createContextStack(params) {
13048
13062
  var _a;
13049
13063
  if (params === void 0) { params = {}; }
@@ -13055,26 +13069,53 @@ function createContextStack(params) {
13055
13069
  values: params.values,
13056
13070
  nativeJsFunctions: params.jsFunctions
13057
13071
  && Object.entries(params.jsFunctions).reduce(function (acc, _a) {
13058
- var _b;
13059
- var _c, _d;
13060
- var _e = __read(_a, 2), name = _e[0], jsFunction = _e[1];
13061
- if (specialExpressionKeys.includes(name)) {
13062
- console.warn("Cannot shadow special expression \"".concat(name, "\", ignoring."));
13072
+ var e_5, _b, _c;
13073
+ var _d, _e;
13074
+ var _f = __read(_a, 2), identifier = _f[0], entry = _f[1];
13075
+ var identifierParts = identifier.split('.');
13076
+ var name = identifierParts.pop();
13077
+ if (/^[A-Z]/.test(name)) {
13078
+ console.warn("Invalid identifier \"".concat(identifier, "\" in jsFunctions, function name must not start with an uppercase letter"), undefined);
13063
13079
  return acc;
13064
13080
  }
13065
- if (normalExpressionKeys.includes(name)) {
13066
- console.warn("Cannot shadow builtin function \"".concat(name, "\", ignoring."));
13067
- return acc;
13081
+ var scope = acc;
13082
+ try {
13083
+ for (var identifierParts_1 = __values(identifierParts), identifierParts_1_1 = identifierParts_1.next(); !identifierParts_1_1.done; identifierParts_1_1 = identifierParts_1.next()) {
13084
+ var part = identifierParts_1_1.value;
13085
+ if (part.length === 0) {
13086
+ console.warn("Invalid empty identifier \"".concat(identifier, "\" in nativeJsFunctions"), undefined);
13087
+ return acc;
13088
+ }
13089
+ if (!/^[A-Z]/.test(part)) {
13090
+ console.warn("Invalid identifier \"".concat(identifier, "\" in jsFunctions, namespace must start with an uppercase letter"), undefined);
13091
+ return acc;
13092
+ }
13093
+ if (!scope[part]) {
13094
+ scope[part] = {};
13095
+ }
13096
+ scope = scope[part];
13097
+ }
13098
+ }
13099
+ catch (e_5_1) { e_5 = { error: e_5_1 }; }
13100
+ finally {
13101
+ try {
13102
+ if (identifierParts_1_1 && !identifierParts_1_1.done && (_b = identifierParts_1.return)) _b.call(identifierParts_1);
13103
+ }
13104
+ finally { if (e_5) throw e_5.error; }
13068
13105
  }
13069
- acc[name] = (_b = {
13106
+ var natifeFn = (_c = {
13070
13107
  functionType: 'NativeJsFunction',
13071
- nativeFn: jsFunction,
13108
+ nativeFn: entry,
13072
13109
  name: name
13073
13110
  },
13074
- _b[FUNCTION_SYMBOL] = true,
13075
- _b.arity = (_c = jsFunction.arity) !== null && _c !== void 0 ? _c : {},
13076
- _b.docString = (_d = jsFunction.docString) !== null && _d !== void 0 ? _d : '',
13077
- _b);
13111
+ _c[FUNCTION_SYMBOL] = true,
13112
+ _c.arity = (_d = entry.arity) !== null && _d !== void 0 ? _d : {},
13113
+ _c.docString = (_e = entry.docString) !== null && _e !== void 0 ? _e : '',
13114
+ _c);
13115
+ if (scope === acc && !checkNotDefined(name)) {
13116
+ return acc;
13117
+ }
13118
+ scope[name] = natifeFn;
13078
13119
  return acc;
13079
13120
  }, {}),
13080
13121
  });
@@ -13490,10 +13531,10 @@ var tokenizeMultiLineComment = function (input, position) {
13490
13531
  }
13491
13532
  return NO_MATCH;
13492
13533
  };
13493
- var tokenizeSingleLineComment = function (input, position) {
13494
- if (input[position] === '/' && input[position + 1] === '/') {
13534
+ var tokenizeShebang = function (input, position) {
13535
+ if (input[position] === '#' && input[position + 1] === '!') {
13495
13536
  var length_3 = 2;
13496
- var value = '//';
13537
+ var value = '#!';
13497
13538
  while (input[position + length_3] !== '\n' && position + length_3 < input.length) {
13498
13539
  value += input[position + length_3];
13499
13540
  length_3 += 1;
@@ -13502,6 +13543,18 @@ var tokenizeSingleLineComment = function (input, position) {
13502
13543
  }
13503
13544
  return NO_MATCH;
13504
13545
  };
13546
+ var tokenizeSingleLineComment = function (input, position) {
13547
+ if (input[position] === '/' && input[position + 1] === '/') {
13548
+ var length_4 = 2;
13549
+ var value = '//';
13550
+ while (input[position + length_4] !== '\n' && position + length_4 < input.length) {
13551
+ value += input[position + length_4];
13552
+ length_4 += 1;
13553
+ }
13554
+ return [length_4, ['SingleLineComment', value]];
13555
+ }
13556
+ return NO_MATCH;
13557
+ };
13505
13558
  // All tokenizers, order matters!
13506
13559
  var tokenizers = [
13507
13560
  tokenizeWhitespace,
@@ -13567,10 +13620,17 @@ function createSourceCodeInfo(input, position, filePath) {
13567
13620
  function getCurrentToken(input, position) {
13568
13621
  var e_1, _a;
13569
13622
  var initialPosition = position;
13623
+ if (position === 0) {
13624
+ var _b = __read(tokenizeShebang(input, position), 2), nbrOfCharacters = _b[0], token = _b[1];
13625
+ position += nbrOfCharacters;
13626
+ if (nbrOfCharacters > 0) {
13627
+ return [position - initialPosition, token];
13628
+ }
13629
+ }
13570
13630
  try {
13571
13631
  for (var tokenizers_1 = __values(tokenizers), tokenizers_1_1 = tokenizers_1.next(); !tokenizers_1_1.done; tokenizers_1_1 = tokenizers_1.next()) {
13572
13632
  var tokenizer = tokenizers_1_1.value;
13573
- var _b = __read(tokenizer(input, position), 2), nbrOfCharacters = _b[0], token = _b[1];
13633
+ var _c = __read(tokenizer(input, position), 2), nbrOfCharacters = _c[0], token = _c[1];
13574
13634
  position += nbrOfCharacters;
13575
13635
  if (nbrOfCharacters === 0) {
13576
13636
  continue;
@@ -13624,6 +13684,9 @@ function asReservedSymbolToken(token, symbolName) {
13624
13684
  assertReservedSymbolToken(token, symbolName);
13625
13685
  return token;
13626
13686
  }
13687
+ function isShebangToken(token) {
13688
+ return (token === null || token === void 0 ? void 0 : token[0]) === 'Shebang';
13689
+ }
13627
13690
  function isSingleLineCommentToken(token) {
13628
13691
  return (token === null || token === void 0 ? void 0 : token[0]) === 'SingleLineComment';
13629
13692
  }
@@ -13723,6 +13786,7 @@ function minifyTokenStream(tokenStream, _a) {
13723
13786
  .filter(function (token) {
13724
13787
  if (isSingleLineCommentToken(token)
13725
13788
  || isMultiLineCommentToken(token)
13789
+ || isShebangToken(token)
13726
13790
  || (removeWhiteSpace && isWhitespaceToken(token))) {
13727
13791
  return false;
13728
13792
  }