mevento 2.0.1 → 2.0.4

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.
@@ -871,14 +871,16 @@ class Parser {
871
871
  return this._arrayExpression();
872
872
  case TokenType.lbrace:
873
873
  return this._objectExpression();
874
+ case TokenType.IF:
875
+ return this._ifStatement();
874
876
  default:
875
877
  return this._variable();
876
878
  }
877
879
  }
878
880
  _term() {
879
881
  let node = this._factor();
880
- node = this._tryParsingMemberExpression(node);
881
882
  node = this._tryParsingFunctionCall(node);
883
+ node = this._tryParsingMemberExpression(node);
882
884
  return node;
883
885
  }
884
886
  _expression() {
@@ -1208,8 +1210,8 @@ class Parser {
1208
1210
  case TokenType.eol:
1209
1211
  this._eatEOL();
1210
1212
  return this._statement();
1211
- case TokenType.IF:
1212
- return this._ifStatement();
1213
+ // case TokenType.IF:
1214
+ // return this._ifStatement();
1213
1215
  case TokenType.WHILE_TILL:
1214
1216
  return this._whileLoop();
1215
1217
  case TokenType.FOR_LOOP:
@@ -1535,7 +1537,7 @@ class MEvento extends NodeVisitor {
1535
1537
  if (op.type === TokenType.not) {
1536
1538
  return _boolValue(argValue) === false;
1537
1539
  }
1538
- if (isNum(argValue)) {
1540
+ if (!isNum(argValue)) {
1539
1541
  throw new Error(`Operation ${op.value} not allowed no num value`);
1540
1542
  }
1541
1543
  if (op.type === TokenType.plus) {
@@ -1746,8 +1748,11 @@ class MEvento extends NodeVisitor {
1746
1748
  unregisterFunction(id) {
1747
1749
  delete this._functionsRegistry[id];
1748
1750
  }
1749
- execute(source, cache = true) {
1751
+ execute(source, cache = true, input) {
1750
1752
  const module = MEvento.compile(source, cache);
1753
+ if (input) {
1754
+ Object.keys(input).forEach(k => this.changeVariable(k, input[k]));
1755
+ }
1751
1756
  return this.visit(module);
1752
1757
  }
1753
1758
  static compile(source, cache = false) {
@@ -1768,9 +1773,12 @@ class MEvento extends NodeVisitor {
1768
1773
  static unregister(id) {
1769
1774
  delete MEvento._globalFunctionsRegistry[id];
1770
1775
  }
1771
- static run(source, cache = false) {
1776
+ static run(source, cache = false, input) {
1772
1777
  const mevento = new MEvento();
1773
1778
  const module = MEvento.compile(source, cache);
1779
+ if (input) {
1780
+ Object.keys(input).forEach(k => mevento.changeVariable(k, input[k]));
1781
+ }
1774
1782
  return mevento.visit(module);
1775
1783
  }
1776
1784
  static newInstance() {
@@ -1940,7 +1948,7 @@ class MEventoAsync extends MEvento {
1940
1948
  if (op.type === TokenType.not) {
1941
1949
  return _boolValue(argValue) === false;
1942
1950
  }
1943
- if (isNum(argValue)) {
1951
+ if (!isNum(argValue)) {
1944
1952
  throw new Error(`Operation ${op.value} not allowed no num value`);
1945
1953
  }
1946
1954
  if (op.type === TokenType.plus) {
@@ -2129,13 +2137,19 @@ class MEventoAsync extends MEvento {
2129
2137
  unregisterFunction(id) {
2130
2138
  delete this._functionsRegistry[id];
2131
2139
  }
2132
- async execute(source, cache = true) {
2140
+ async execute(source, cache = true, input) {
2133
2141
  const module = MEvento.compile(source, cache);
2142
+ if (input) {
2143
+ Object.keys(input).forEach(k => this.changeVariable(k, input[k]));
2144
+ }
2134
2145
  return await this.visit(module);
2135
2146
  }
2136
- static async run(source, cache = false) {
2147
+ static async run(source, cache = false, input) {
2137
2148
  const mevento = new MEventoAsync();
2138
2149
  const module = MEvento.compile(source, cache);
2150
+ if (input) {
2151
+ Object.keys(input).forEach(k => mevento.changeVariable(k, input[k]));
2152
+ }
2139
2153
  return await mevento.visit(module);
2140
2154
  }
2141
2155
  static newInstance() {