@mojir/lits 1.2.2-alpha.1 → 1.2.2-alpha.3
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/cli/cli.js +58 -10
- package/dist/cli/src/Lits/Lits.d.ts +2 -0
- package/dist/cli/src/analyze/index.d.ts +1 -2
- package/dist/cli/src/index.d.ts +0 -1
- package/dist/cli/src/transformer/index.d.ts +2 -0
- package/dist/cli/src/untokenizer/index.d.ts +2 -0
- package/dist/index.esm.js +59 -31
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +58 -31
- package/dist/index.js.map +1 -1
- package/dist/lits.iife.js +58 -31
- package/dist/lits.iife.js.map +1 -1
- package/dist/src/Lits/Lits.d.ts +2 -0
- package/dist/src/analyze/index.d.ts +1 -2
- package/dist/src/index.d.ts +0 -1
- package/dist/src/transformer/index.d.ts +2 -0
- package/dist/src/untokenizer/index.d.ts +2 -0
- package/dist/testFramework.esm.js +58 -10
- package/dist/testFramework.esm.js.map +1 -1
- package/dist/testFramework.js +58 -10
- package/dist/testFramework.js.map +1 -1
- package/package.json +1 -1
package/dist/src/Lits/Lits.d.ts
CHANGED
|
@@ -47,6 +47,8 @@ export declare class Lits {
|
|
|
47
47
|
tokenize(program: string, tokenizeParams?: TokenizeParams): TokenStream;
|
|
48
48
|
parse(tokenStream: TokenStream): Ast;
|
|
49
49
|
evaluate(ast: Ast, params: LitsParams): Any;
|
|
50
|
+
transform(tokenStream: TokenStream, transformer: (name: string) => string): TokenStream;
|
|
51
|
+
untokenize(tokenStream: TokenStream): string;
|
|
50
52
|
apply(fn: LitsFunction, fnParams: unknown[], params?: LitsParams): Any;
|
|
51
53
|
private generateAst;
|
|
52
54
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { LitsParams } from '../Lits/Lits';
|
|
2
2
|
import type { Builtin } from '../builtin/interface';
|
|
3
3
|
import { type ContextStack } from '../evaluator/ContextStack';
|
|
4
|
-
import type { Ast, AstNode
|
|
4
|
+
import type { Ast, AstNode } from '../parser/interface';
|
|
5
5
|
import type { Token } from '../tokenizer/interface';
|
|
6
6
|
export interface UnresolvedIdentifier {
|
|
7
7
|
symbol: string;
|
|
@@ -15,4 +15,3 @@ export interface Analysis {
|
|
|
15
15
|
}
|
|
16
16
|
export type FindUnresolvedIdentifiers = (ast: Ast | AstNode[], contextStack: ContextStack, builtin: Builtin) => UnresolvedIdentifiers;
|
|
17
17
|
export declare function analyze(ast: Ast, params: LitsParams): Analysis;
|
|
18
|
-
export declare function findUnresolvedIdentifiersInFunction(fun: LitsFunction, params: LitsParams): UnresolvedIdentifiers;
|
package/dist/src/index.d.ts
CHANGED
|
@@ -14,4 +14,3 @@ export { apiReference, isDatatypeReference, isFunctionReference, isNormalExpress
|
|
|
14
14
|
export type { Argument, CommonReference, DatatypeReference, FunctionReference, Reference, ShorthandReference } from '../reference';
|
|
15
15
|
export type { ApiName, FunctionName, ShorthandName, DatatypeName } from '../reference/api';
|
|
16
16
|
export { isApiName, isDataType } from '../reference/api';
|
|
17
|
-
export { findUnresolvedIdentifiersInFunction } from './analyze';
|
|
@@ -2827,7 +2827,7 @@ var mathNormalExpression = {
|
|
|
2827
2827
|
},
|
|
2828
2828
|
};
|
|
2829
2829
|
|
|
2830
|
-
var version = "1.2.2-alpha.
|
|
2830
|
+
var version = "1.2.2-alpha.3";
|
|
2831
2831
|
|
|
2832
2832
|
var uuidTemplate = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx';
|
|
2833
2833
|
var xyRegexp = /[xy]/g;
|
|
@@ -6283,15 +6283,6 @@ function evaluateNumberAsFunction(fn, params, sourceCodeInfo) {
|
|
|
6283
6283
|
return toAny(param[fn]);
|
|
6284
6284
|
}
|
|
6285
6285
|
|
|
6286
|
-
// export function findUnresolvedIdentifiersInFunction(ast, contextStack, builtin: Builtin) => {
|
|
6287
|
-
// const astNodes = Array.isArray(ast) ? ast : ast.b
|
|
6288
|
-
// const unresolvedIdentifiers = new Set<UnresolvedIdentifier>()
|
|
6289
|
-
// for (const subNode of astNodes) {
|
|
6290
|
-
// findUnresolvedIdentifiersInAstNode(subNode, contextStack, builtin)
|
|
6291
|
-
// .forEach(symbol => unresolvedIdentifiers.add(symbol))
|
|
6292
|
-
// }
|
|
6293
|
-
// return unresolvedIdentifiers
|
|
6294
|
-
// }
|
|
6295
6286
|
var findUnresolvedIdentifiers = function (ast, contextStack, builtin) {
|
|
6296
6287
|
var e_1, _a;
|
|
6297
6288
|
var astNodes = Array.isArray(ast) ? ast : ast.b;
|
|
@@ -8022,6 +8013,12 @@ function assertNewLineToken(token) {
|
|
|
8022
8013
|
throw new LitsError("Expected newline token, got ".concat(token === null || token === void 0 ? void 0 : token.t, "."));
|
|
8023
8014
|
}
|
|
8024
8015
|
|
|
8016
|
+
function transformTokens(tokenStram, transformer) {
|
|
8017
|
+
return __assign(__assign({}, tokenStram), { tokens: tokenStram.tokens.map(function (token) {
|
|
8018
|
+
return __assign(__assign({}, token), { v: transformer(token.v) });
|
|
8019
|
+
}) });
|
|
8020
|
+
}
|
|
8021
|
+
|
|
8025
8022
|
var UnparseOptions = /** @class */ (function () {
|
|
8026
8023
|
function UnparseOptions(unparse, lineLength, col, inlined, locked) {
|
|
8027
8024
|
if (col === void 0) { col = 0; }
|
|
@@ -8540,6 +8537,51 @@ function unparseAst(ast, lineLength) {
|
|
|
8540
8537
|
return result.trim();
|
|
8541
8538
|
}
|
|
8542
8539
|
|
|
8540
|
+
function isNoSpaceNeededBefore(token) {
|
|
8541
|
+
switch (token.t) {
|
|
8542
|
+
case TokenType.Bracket:
|
|
8543
|
+
return [')', ']'].includes(token.v);
|
|
8544
|
+
case TokenType.CollectionAccessor:
|
|
8545
|
+
return true;
|
|
8546
|
+
case TokenType.NewLine:
|
|
8547
|
+
return true;
|
|
8548
|
+
default:
|
|
8549
|
+
return false;
|
|
8550
|
+
}
|
|
8551
|
+
}
|
|
8552
|
+
function isNoSpaceNeededAfter(token) {
|
|
8553
|
+
switch (token.t) {
|
|
8554
|
+
case TokenType.Bracket:
|
|
8555
|
+
return ['(', '['].includes(token.v);
|
|
8556
|
+
case TokenType.CollectionAccessor:
|
|
8557
|
+
return true;
|
|
8558
|
+
case TokenType.FnShorthand:
|
|
8559
|
+
return true;
|
|
8560
|
+
case TokenType.NewLine:
|
|
8561
|
+
return true;
|
|
8562
|
+
case TokenType.RegexpShorthand:
|
|
8563
|
+
return true;
|
|
8564
|
+
default:
|
|
8565
|
+
return false;
|
|
8566
|
+
}
|
|
8567
|
+
}
|
|
8568
|
+
function untokenize(tokenStream) {
|
|
8569
|
+
var lastToken;
|
|
8570
|
+
return tokenStream.tokens.reduce(function (acc, token) {
|
|
8571
|
+
var joiner = !lastToken || isNoSpaceNeededAfter(lastToken) || isNoSpaceNeededBefore(token) ? '' : ' ';
|
|
8572
|
+
lastToken = token;
|
|
8573
|
+
return "".concat(acc).concat(joiner).concat(untokenizeToken(token));
|
|
8574
|
+
}, '');
|
|
8575
|
+
}
|
|
8576
|
+
function untokenizeToken(token) {
|
|
8577
|
+
switch (token.t) {
|
|
8578
|
+
case TokenType.String:
|
|
8579
|
+
return "\"".concat(token.v, "\"");
|
|
8580
|
+
default:
|
|
8581
|
+
return token.v;
|
|
8582
|
+
}
|
|
8583
|
+
}
|
|
8584
|
+
|
|
8543
8585
|
var Cache = /** @class */ (function () {
|
|
8544
8586
|
function Cache(maxSize) {
|
|
8545
8587
|
this.cache = {};
|
|
@@ -8671,6 +8713,12 @@ var Lits = /** @class */ (function () {
|
|
|
8671
8713
|
var contextStack = createContextStack(params);
|
|
8672
8714
|
return evaluate(ast, contextStack);
|
|
8673
8715
|
};
|
|
8716
|
+
Lits.prototype.transform = function (tokenStream, transformer) {
|
|
8717
|
+
return transformTokens(tokenStream, transformer);
|
|
8718
|
+
};
|
|
8719
|
+
Lits.prototype.untokenize = function (tokenStream) {
|
|
8720
|
+
return untokenize(tokenStream);
|
|
8721
|
+
};
|
|
8674
8722
|
Lits.prototype.apply = function (fn, fnParams, params) {
|
|
8675
8723
|
var _a;
|
|
8676
8724
|
if (params === void 0) { params = {}; }
|