@mojir/lits 2.0.4 → 2.0.6

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
@@ -3163,7 +3163,7 @@ var Lits = (function (exports) {
3163
3163
  },
3164
3164
  };
3165
3165
 
3166
- var version = "2.0.4";
3166
+ var version = "2.0.6";
3167
3167
 
3168
3168
  var uuidTemplate = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx';
3169
3169
  var xyRegexp = /[xy]/g;
@@ -7386,14 +7386,22 @@ var Lits = (function (exports) {
7386
7386
  return parseReservedSymbol(this.tokenStream, this.parseState);
7387
7387
  case 'PolNotation': {
7388
7388
  this.parseState.algebraic = false;
7389
- var astNode = void 0;
7389
+ var astNodes = [];
7390
7390
  this.advance();
7391
7391
  do {
7392
- astNode = this.parseState.parseToken(this.tokenStream, this.parseState);
7392
+ astNodes.push(this.parseState.parseToken(this.tokenStream, this.parseState));
7393
7393
  } while (!isEndNotationToken(this.peek()));
7394
7394
  this.advance();
7395
7395
  this.parseState.algebraic = true;
7396
- return astNode;
7396
+ if (astNodes.length === 1) {
7397
+ return astNodes[0];
7398
+ }
7399
+ return {
7400
+ t: exports.AstNodeType.SpecialExpression,
7401
+ n: 'do',
7402
+ p: astNodes,
7403
+ token: getTokenDebugData(token) && token,
7404
+ };
7397
7405
  }
7398
7406
  case 'AlgNotation': {
7399
7407
  this.advance();
@@ -7888,13 +7896,21 @@ var Lits = (function (exports) {
7888
7896
  return node;
7889
7897
  }
7890
7898
  case 'PolNotation': {
7891
- var node = void 0;
7899
+ var astNodes = [];
7892
7900
  parseState.position += 1;
7893
7901
  do {
7894
- node = parsePolishToken(tokenStream, parseState);
7902
+ astNodes.push(parsePolishToken(tokenStream, parseState));
7895
7903
  } while (!isEndNotationToken(asToken(tokenStream.tokens[parseState.position])));
7896
7904
  parseState.position += 1;
7897
- return node;
7905
+ if (astNodes.length === 1) {
7906
+ return astNodes[0];
7907
+ }
7908
+ return {
7909
+ t: exports.AstNodeType.SpecialExpression,
7910
+ n: 'do',
7911
+ p: astNodes,
7912
+ token: astNodes[0].token,
7913
+ };
7898
7914
  }
7899
7915
  case 'P_CollectionAccessor':
7900
7916
  case 'P_Modifier':
@@ -8815,10 +8831,9 @@ var Lits = (function (exports) {
8815
8831
  return analyze(ast, params);
8816
8832
  };
8817
8833
  Lits.prototype.tokenize = function (program, tokenizeParams) {
8818
- var _a, _b;
8819
8834
  if (tokenizeParams === void 0) { tokenizeParams = {}; }
8820
- var debug = (_a = tokenizeParams.debug) !== null && _a !== void 0 ? _a : this.debug;
8821
- var algebraic = (_b = tokenizeParams.algebraic) !== null && _b !== void 0 ? _b : this.algebraic;
8835
+ var debug = this.debug;
8836
+ var algebraic = this.algebraic;
8822
8837
  return tokenize(program, __assign(__assign({}, tokenizeParams), { debug: debug, algebraic: algebraic }));
8823
8838
  };
8824
8839
  Lits.prototype.parse = function (tokenStream) {
@@ -8838,12 +8853,7 @@ var Lits = (function (exports) {
8838
8853
  var _a;
8839
8854
  if (params === void 0) { params = {}; }
8840
8855
  var fnName = 'FN_2eb7b316-471c-5bfa-90cb-d3dfd9164a59';
8841
- var paramsString = fnParams
8842
- .map(function (_, index) {
8843
- return "".concat(fnName, "_").concat(index);
8844
- })
8845
- .join(' ');
8846
- var program = "(".concat(fnName, " ").concat(paramsString, ")");
8856
+ var program = this.generateApplyFunctionCall(fnName, fnParams);
8847
8857
  var ast = this.generateAst(program, params);
8848
8858
  var hostValues = fnParams.reduce(function (result, param, index) {
8849
8859
  result["".concat(fnName, "_").concat(index)] = param;
@@ -8852,20 +8862,26 @@ var Lits = (function (exports) {
8852
8862
  params.values = __assign(__assign({}, params.values), hostValues);
8853
8863
  return this.evaluate(ast, params);
8854
8864
  };
8865
+ Lits.prototype.generateApplyFunctionCall = function (fnName, fnParams) {
8866
+ var paramsString = fnParams
8867
+ .map(function (_, index) {
8868
+ return "".concat(fnName, "_").concat(index);
8869
+ })
8870
+ .join(this.algebraic ? ', ' : ' ');
8871
+ return this.algebraic ? "".concat(fnName, "(").concat(paramsString, ")") : "(".concat(fnName, " ").concat(paramsString, ")");
8872
+ };
8855
8873
  Lits.prototype.generateAst = function (program, params) {
8856
- var _a, _b, _c;
8874
+ var _a;
8857
8875
  if (this.astCache) {
8858
8876
  var cachedAst = this.astCache.get(program);
8859
8877
  if (cachedAst)
8860
8878
  return cachedAst;
8861
8879
  }
8862
8880
  var tokenStream = this.tokenize(program, {
8863
- debug: (_a = params.debug) !== null && _a !== void 0 ? _a : this.debug,
8864
8881
  filePath: params.filePath,
8865
- algebraic: (_b = params.algebraic) !== null && _b !== void 0 ? _b : this.algebraic,
8866
8882
  });
8867
8883
  var ast = this.parse(tokenStream);
8868
- (_c = this.astCache) === null || _c === void 0 ? void 0 : _c.set(program, ast);
8884
+ (_a = this.astCache) === null || _a === void 0 ? void 0 : _a.set(program, ast);
8869
8885
  return ast;
8870
8886
  };
8871
8887
  return Lits;