mevento 1.9.0 → 1.9.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.
@@ -1,7 +1,7 @@
1
1
  import { __awaiter } from 'tslib';
2
2
 
3
- function error(token) {
4
- const text = `Invalid token ${token.type}[${token.value}] at ${token.line}, ${token.col}\n`;
3
+ function error(token, expected) {
4
+ const text = `Invalid token ${token.type}[${token.value}] at ${token.line}, ${token.col} ${expected ? `: expecting ${expected} token` : ''}\n`;
5
5
  throw (text);
6
6
  }
7
7
  function isNum(value) {
@@ -240,8 +240,7 @@ class Lexer {
240
240
  ['\n', '\r', '\u2028', '\u2029'].includes(String.fromCharCode(c));
241
241
  }
242
242
  _isWhiteSpace(c) {
243
- return String.fromCharCode(c).trim() === "" &&
244
- String.fromCharCode(c).length > 0;
243
+ return [' ', '\t'].includes(String.fromCharCode(c));
245
244
  }
246
245
  _isDigit(c) {
247
246
  // tslint:disable-next-line:no-bitwise
@@ -767,7 +766,7 @@ class Parser {
767
766
  this.currentToken = this.lexer.nextToken();
768
767
  }
769
768
  else {
770
- error(this.currentToken);
769
+ error(this.currentToken, type);
771
770
  }
772
771
  }
773
772
  _eatEOL() {
@@ -893,11 +892,14 @@ class Parser {
893
892
  var _a, _b;
894
893
  const properties = [];
895
894
  if (((_a = this.currentToken) === null || _a === void 0 ? void 0 : _a.type) != TokenType.rbrace) {
895
+ this._eatEOL();
896
896
  properties.push(this._property());
897
897
  }
898
898
  while (((_b = this.currentToken) === null || _b === void 0 ? void 0 : _b.type) === TokenType.comma) {
899
899
  this._eat(TokenType.comma);
900
+ this._eatEOL();
900
901
  properties.push(this._property());
902
+ this._eatEOL();
901
903
  }
902
904
  return properties;
903
905
  }
@@ -983,6 +985,7 @@ class Parser {
983
985
  const node = this._expression();
984
986
  if (![TokenType.semi, TokenType.eol, TokenType.eof]
985
987
  .includes(this.currentToken.type)) {
988
+ console.log('DDDMMMS', this.currentToken);
986
989
  error(this.currentToken);
987
990
  }
988
991
  return node;
@@ -1256,10 +1259,15 @@ class NodeVisitor extends ANodeVisitor {
1256
1259
  this.registerVisitor(ContinueAST, this.visitContinueAST);
1257
1260
  }
1258
1261
  visit(node) {
1259
- const methodName = `visit${node.constructor.name}`;
1260
- // const fn = Object.getPrototypeOf(this)[methodName];
1261
- const fn = this._nodesVisitors[methodName];
1262
- return fn === null || fn === void 0 ? void 0 : fn.call(this, node);
1262
+ try {
1263
+ const methodName = `visit${node.constructor.name}`;
1264
+ // const fn = Object.getPrototypeOf(this)[methodName];
1265
+ const fn = this._nodesVisitors[methodName];
1266
+ return fn === null || fn === void 0 ? void 0 : fn.call(this, node);
1267
+ }
1268
+ catch (error) {
1269
+ return null;
1270
+ }
1263
1271
  }
1264
1272
  assignProperty(owner, property, value) {
1265
1273
  if (Array.isArray(owner)) {
@@ -1279,7 +1287,8 @@ class MEventScope {
1279
1287
  this.parent = parent;
1280
1288
  }
1281
1289
  resolve(key) {
1282
- return Object.keys(this.memory).includes(key) ? this.memory[key] : (this.parent ? this.parent.resolve(key) : null);
1290
+ var _a, _b;
1291
+ return Object.keys(this.memory).includes(key) ? this.memory[key] : ((_b = (_a = this.parent) === null || _a === void 0 ? void 0 : _a.resolve(key)) !== null && _b !== void 0 ? _b : null);
1283
1292
  }
1284
1293
  change(key, value, declare = true) {
1285
1294
  if (Object.keys(this.memory).includes(key)) {
@@ -1301,30 +1310,30 @@ class MEvento extends NodeVisitor {
1301
1310
  constructor() {
1302
1311
  super();
1303
1312
  this.rootScope = new MEventScope("Program", {});
1304
- this.currentScrope = this.rootScope;
1313
+ this.currentScope = this.rootScope;
1305
1314
  this.debug = false;
1306
1315
  this._functionsRegistry = {};
1307
1316
  this._functionsRegistry = Object.assign({}, MEvento._globalFunctionsRegistry);
1308
1317
  }
1309
1318
  resolve(name) {
1310
1319
  var _a, _b;
1311
- return (_b = (_a = this.currentScrope) === null || _a === void 0 ? void 0 : _a.resolve(name)) !== null && _b !== void 0 ? _b : null;
1320
+ return (_b = (_a = this.currentScope) === null || _a === void 0 ? void 0 : _a.resolve(name)) !== null && _b !== void 0 ? _b : null;
1312
1321
  }
1313
1322
  changeVariable(name, value) {
1314
1323
  var _a;
1315
- if ((_a = this.currentScrope) === null || _a === void 0 ? void 0 : _a.change(name, value)) {
1324
+ if ((_a = this.currentScope) === null || _a === void 0 ? void 0 : _a.change(name, value)) {
1316
1325
  return value;
1317
1326
  }
1318
1327
  else
1319
1328
  return null;
1320
1329
  }
1321
1330
  pushScope(name) {
1322
- const scope = new MEventScope(name, {}, this.currentScrope);
1323
- this.currentScrope = scope;
1331
+ const scope = new MEventScope(name, {}, this.currentScope);
1332
+ this.currentScope = scope;
1324
1333
  }
1325
1334
  popScope() {
1326
1335
  var _a;
1327
- this.currentScrope = (_a = this.currentScrope) === null || _a === void 0 ? void 0 : _a.parent;
1336
+ this.currentScope = (_a = this.currentScope) === null || _a === void 0 ? void 0 : _a.parent;
1328
1337
  }
1329
1338
  log(message) {
1330
1339
  if (this.debug) {
@@ -1353,9 +1362,9 @@ class MEvento extends NodeVisitor {
1353
1362
  return last;
1354
1363
  }
1355
1364
  visitIdentifierAST(node) {
1356
- var _a, _b;
1365
+ var _a;
1357
1366
  const id = node.value;
1358
- return (_b = (_a = this.currentScrope) === null || _a === void 0 ? void 0 : _a.resolve(id)) !== null && _b !== void 0 ? _b : null;
1367
+ return (_a = this === null || this === void 0 ? void 0 : this.resolve(id)) !== null && _a !== void 0 ? _a : null;
1359
1368
  }
1360
1369
  visitLiteralAST(node) {
1361
1370
  const value = node.value;
@@ -1504,6 +1513,9 @@ class MEvento extends NodeVisitor {
1504
1513
  visitIndexAccessorAST(node) {
1505
1514
  const ownerNode = node.owner;
1506
1515
  const owner = this.visit(ownerNode);
1516
+ if (owner === null || owner === undefined) {
1517
+ return null;
1518
+ }
1507
1519
  if (typeof owner === 'object') {
1508
1520
  const key = this.visit(node.key);
1509
1521
  return owner[key];
@@ -1891,6 +1903,9 @@ class MEventoAsync extends MEvento {
1891
1903
  return __awaiter(this, void 0, void 0, function* () {
1892
1904
  const ownerNode = node.owner;
1893
1905
  const owner = yield this.visit(ownerNode);
1906
+ if (owner === null || owner === undefined) {
1907
+ return null;
1908
+ }
1894
1909
  if (typeof owner === 'object') {
1895
1910
  const key = yield this.visit(node.key);
1896
1911
  return owner[key];