@mojir/lits 2.1.28 → 2.1.30

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
@@ -13347,7 +13347,7 @@ var Lits = (function (exports) {
13347
13347
  nextThreeChars = input.slice(position + length, position + length + 3);
13348
13348
  }
13349
13349
  if (!char) {
13350
- throw new LitsError("Unclosed doc string at position ".concat(position, "."), undefined);
13350
+ return [length, ['Error', value, undefined, "Unclosed doc string at position ".concat(position)]];
13351
13351
  }
13352
13352
  value += '"""'; // closing quote
13353
13353
  return [length + 3, ['DocString', value]];
@@ -13374,7 +13374,7 @@ var Lits = (function (exports) {
13374
13374
  char = input[position + length];
13375
13375
  }
13376
13376
  if (!char) {
13377
- throw new LitsError("Unclosed string at position ".concat(position, "."), undefined);
13377
+ return [length, ['Error', value, undefined, "Unclosed string at position ".concat(position)]];
13378
13378
  }
13379
13379
  value += '"'; // closing quote
13380
13380
  return [length + 1, ['String', value]];
@@ -13385,16 +13385,20 @@ var Lits = (function (exports) {
13385
13385
  var _a = __read(tokenizeString(input, position + 1), 2), stringLength = _a[0], token = _a[1];
13386
13386
  if (!token)
13387
13387
  return NO_MATCH;
13388
+ if (token[0] === 'Error') {
13389
+ var errorToken = ['Error', "#".concat(token[1]), undefined, "Unclosed regexp at position ".concat(position)];
13390
+ return [stringLength + 1, errorToken];
13391
+ }
13388
13392
  position += stringLength + 1;
13389
13393
  var length = stringLength + 1;
13390
13394
  var options = '';
13391
13395
  while (input[position] === 'g' || input[position] === 'i') {
13392
- if (options.includes(input[position])) {
13393
- throw new LitsError("Duplicated regexp option \"".concat(input[position], "\" at position ").concat(position, "."), undefined);
13394
- }
13395
13396
  options += input[position];
13396
13397
  length += 1;
13397
13398
  position += 1;
13399
+ if (options.includes(input[position])) {
13400
+ return [length, ['Error', "#".concat(token[1]).concat(options), undefined, "Duplicated regexp option \"".concat(input[position], "\"")]];
13401
+ }
13398
13402
  }
13399
13403
  return [length, ['RegexpShorthand', "#".concat(token[1]).concat(options)]];
13400
13404
  };
@@ -13438,7 +13442,7 @@ var Lits = (function (exports) {
13438
13442
  if (i === start) {
13439
13443
  return NO_MATCH;
13440
13444
  }
13441
- throw new LitsError("Invalid number format at position ".concat(i, "."), undefined);
13445
+ return [i - position + 1, ['Error', input.substring(position, i + 1), undefined, "Invalid number format at position ".concat(i + 1)]];
13442
13446
  }
13443
13447
  }
13444
13448
  else if (char === '.') {
@@ -13446,7 +13450,7 @@ var Lits = (function (exports) {
13446
13450
  return NO_MATCH;
13447
13451
  }
13448
13452
  if (hasDecimalPoint || hasExponent) {
13449
- throw new LitsError("Invalid number format at position ".concat(i, "."), undefined);
13453
+ return [i - position + 1, ['Error', input.substring(position, i + 1), undefined, "Invalid number format at position ".concat(i + 1)]];
13450
13454
  }
13451
13455
  hasDecimalPoint = true;
13452
13456
  }
@@ -13455,10 +13459,10 @@ var Lits = (function (exports) {
13455
13459
  return NO_MATCH;
13456
13460
  }
13457
13461
  if (hasExponent) {
13458
- throw new LitsError("Invalid number format at position ".concat(i, "."), undefined);
13462
+ return [i - position + 1, ['Error', input.substring(position, i + 1), undefined, "Invalid number format at position ".concat(i + 1)]];
13459
13463
  }
13460
13464
  if (input[i - 1] === '.' || input[i - 1] === '+' || input[i - 1] === '-') {
13461
- throw new LitsError("Invalid number format at position ".concat(i, "."), undefined);
13465
+ return [i - position + 1, ['Error', input.substring(position, i + 1), undefined, "Invalid number format at position ".concat(i + 1)]];
13462
13466
  }
13463
13467
  if (input[i + 1] === '+' || input[i + 1] === '-') {
13464
13468
  i += 1;
@@ -13478,7 +13482,7 @@ var Lits = (function (exports) {
13478
13482
  }
13479
13483
  var nextChar = input[i];
13480
13484
  if (nextChar && nextChar !== ':' && !postNumberRegExp.test(nextChar)) {
13481
- throw new LitsError("Invalid number format at position ".concat(i, "."), undefined);
13485
+ return [i - position + 1, ['Error', input.substring(position, i + 1), undefined, "Invalid number format at position ".concat(i + 1)]];
13482
13486
  }
13483
13487
  return [length, ['Number', input.substring(position, i)]];
13484
13488
  };
@@ -13528,7 +13532,7 @@ var Lits = (function (exports) {
13528
13532
  var escaping = false;
13529
13533
  while (char !== '\'' || escaping) {
13530
13534
  if (char === undefined)
13531
- throw new LitsError("Unclosed string at position ".concat(position, "."), undefined);
13535
+ return [length_1, ['Error', value, undefined, "Unclosed quoted symbol at position ".concat(position)]];
13532
13536
  length_1 += 1;
13533
13537
  if (escaping) {
13534
13538
  escaping = false;
@@ -13599,7 +13603,7 @@ var Lits = (function (exports) {
13599
13603
  length_2 += 1;
13600
13604
  }
13601
13605
  if (position + length_2 + 1 >= input.length) {
13602
- throw new LitsError('Comment not closed', undefined);
13606
+ return [length_2, ['Error', value, undefined, "Unclosed multi-line comment at position ".concat(position)]];
13603
13607
  }
13604
13608
  value += '*/';
13605
13609
  length_2 += 2;
@@ -13652,9 +13656,6 @@ var Lits = (function (exports) {
13652
13656
  ? createSourceCodeInfo(input, position, filePath)
13653
13657
  : undefined;
13654
13658
  var tokenDescriptor = getCurrentToken(input, position);
13655
- if (!tokenDescriptor) {
13656
- throw new LitsError("Unrecognized character '".concat(input[position], "'."), sourceCodeInfo);
13657
- }
13658
13659
  var _a = __read(tokenDescriptor, 2), count = _a[0], token = _a[1];
13659
13660
  position += count;
13660
13661
  if (token) {
@@ -13705,7 +13706,7 @@ var Lits = (function (exports) {
13705
13706
  }
13706
13707
  finally { if (e_1) throw e_1.error; }
13707
13708
  }
13708
- return null;
13709
+ return [1, ['Error', input[initialPosition], undefined, 'Unrecognized character']];
13709
13710
  }
13710
13711
 
13711
13712
  function isSymbolToken(token, symbolName) {
@@ -13993,6 +13994,11 @@ var Lits = (function (exports) {
13993
13994
  this.parseState.position += 1;
13994
13995
  };
13995
13996
  Parser.prototype.parse = function () {
13997
+ this.tokenStream.tokens.forEach(function (token) {
13998
+ if (token[0] === 'Error') {
13999
+ throw new LitsError(token[3], token[2]);
14000
+ }
14001
+ });
13996
14002
  var nodes = [];
13997
14003
  while (!this.isAtEnd()) {
13998
14004
  nodes.push(this.parseExpression(0, true));
@@ -15059,20 +15065,14 @@ var Lits = (function (exports) {
15059
15065
  this.suggestions = [];
15060
15066
  this.suggestionIndex = null;
15061
15067
  var partialProgram = this.originalProgram.slice(0, this.originalPosition);
15062
- var tokenStream = null;
15063
- try {
15064
- tokenStream = lits.tokenize(partialProgram);
15065
- }
15066
- catch (_a) {
15067
- // do nothing
15068
- }
15069
- if (!tokenStream) {
15070
- return;
15071
- }
15068
+ var tokenStream = lits.tokenize(partialProgram);
15072
15069
  var lastToken = tokenStream.tokens.at(-1);
15073
15070
  if (!lastToken) {
15074
15071
  return;
15075
15072
  }
15073
+ if (lastToken[0] === 'Error') {
15074
+ return;
15075
+ }
15076
15076
  this.searchString = lastToken[1];
15077
15077
  this.prefixProgram = this.originalProgram.slice(0, this.originalPosition - this.searchString.length);
15078
15078
  this.suffixProgram = this.originalProgram.slice(this.prefixProgram.length + this.searchString.length);