@mojir/lits 2.0.20 → 2.0.21

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.
@@ -40,7 +40,9 @@ export declare class Lits {
40
40
  run(program: string, params?: LitsParams): unknown;
41
41
  context(program: string, params?: LitsParams): Context;
42
42
  analyze(program: string, params?: LitsParams): Analysis;
43
- tokenize(program: string, tokenizeParams?: Pick<TokenizeParams, 'filePath'>): TokenStream;
43
+ tokenize(program: string, tokenizeParams?: Pick<TokenizeParams, 'filePath'> & {
44
+ minify?: boolean;
45
+ }): TokenStream;
44
46
  parse(tokenStream: TokenStream): Ast;
45
47
  evaluate(ast: Ast, params: LitsParams): Any;
46
48
  transform(tokenStream: TokenStream, transformer: (name: string) => string): TokenStream;
@@ -0,0 +1,2 @@
1
+ import type { TokenStream } from './interface';
2
+ export declare function minifyTokenStream(tokenStream: TokenStream): TokenStream;
@@ -6103,6 +6103,20 @@ function analyze(ast, params) {
6103
6103
  };
6104
6104
  }
6105
6105
 
6106
+ function minifyTokenStream(tokenStream) {
6107
+ var tokens = tokenStream.tokens.filter(function (token) {
6108
+ if (isP_CommentToken(token)
6109
+ || isA_CommentToken(token)
6110
+ || isA_MultiLineCommentToken(token)
6111
+ || isA_WhitespaceToken(token)
6112
+ || isP_WhitespaceToken(token)) {
6113
+ return false;
6114
+ }
6115
+ return true;
6116
+ });
6117
+ return __assign(__assign({}, tokenStream), { tokens: tokens });
6118
+ }
6119
+
6106
6120
  function parseSymbol(tokenStream, parseState) {
6107
6121
  var _a;
6108
6122
  var tkn = asToken(tokenStream.tokens[parseState.position++]);
@@ -7621,7 +7635,7 @@ function parsePolishToken(tokenStream, parseState) {
7621
7635
  }
7622
7636
 
7623
7637
  function parse(tokenStream) {
7624
- tokenStream = removeUnnecessaryTokens(tokenStream);
7638
+ tokenStream = minifyTokenStream(tokenStream);
7625
7639
  var algebraic = tokenStream.algebraic;
7626
7640
  var ast = {
7627
7641
  b: [],
@@ -7642,19 +7656,6 @@ function parse(tokenStream) {
7642
7656
  }
7643
7657
  return ast;
7644
7658
  }
7645
- function removeUnnecessaryTokens(tokenStream) {
7646
- var tokens = tokenStream.tokens.filter(function (token) {
7647
- if (isP_CommentToken(token)
7648
- || isA_CommentToken(token)
7649
- || isA_MultiLineCommentToken(token)
7650
- || isA_WhitespaceToken(token)
7651
- || isP_WhitespaceToken(token)) {
7652
- return false;
7653
- }
7654
- return true;
7655
- });
7656
- return __assign(__assign({}, tokenStream), { tokens: tokens });
7657
- }
7658
7659
  function parseToken(tokenStream, parseState) {
7659
7660
  return parsePolishToken(tokenStream, parseState);
7660
7661
  }
@@ -8481,7 +8482,8 @@ var Lits = /** @class */ (function () {
8481
8482
  if (tokenizeParams === void 0) { tokenizeParams = {}; }
8482
8483
  var debug = this.debug;
8483
8484
  var algebraic = this.algebraic;
8484
- return tokenize(program, __assign(__assign({}, tokenizeParams), { debug: debug, algebraic: algebraic }));
8485
+ var tokenStream = tokenize(program, __assign(__assign({}, tokenizeParams), { debug: debug, algebraic: algebraic }));
8486
+ return tokenizeParams.minify ? minifyTokenStream(tokenStream) : tokenStream;
8485
8487
  };
8486
8488
  Lits.prototype.parse = function (tokenStream) {
8487
8489
  return parse(tokenStream);