@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/cli/cli.js
CHANGED
|
@@ -92,7 +92,7 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
92
92
|
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
93
93
|
};
|
|
94
94
|
|
|
95
|
-
var version = "1.2.2-alpha.
|
|
95
|
+
var version = "1.2.2-alpha.3";
|
|
96
96
|
|
|
97
97
|
var AstNodeType;
|
|
98
98
|
(function (AstNodeType) {
|
|
@@ -6289,15 +6289,6 @@ function evaluateNumberAsFunction(fn, params, sourceCodeInfo) {
|
|
|
6289
6289
|
return toAny(param[fn]);
|
|
6290
6290
|
}
|
|
6291
6291
|
|
|
6292
|
-
// export function findUnresolvedIdentifiersInFunction(ast, contextStack, builtin: Builtin) => {
|
|
6293
|
-
// const astNodes = Array.isArray(ast) ? ast : ast.b
|
|
6294
|
-
// const unresolvedIdentifiers = new Set<UnresolvedIdentifier>()
|
|
6295
|
-
// for (const subNode of astNodes) {
|
|
6296
|
-
// findUnresolvedIdentifiersInAstNode(subNode, contextStack, builtin)
|
|
6297
|
-
// .forEach(symbol => unresolvedIdentifiers.add(symbol))
|
|
6298
|
-
// }
|
|
6299
|
-
// return unresolvedIdentifiers
|
|
6300
|
-
// }
|
|
6301
6292
|
var findUnresolvedIdentifiers = function (ast, contextStack, builtin) {
|
|
6302
6293
|
var e_1, _a;
|
|
6303
6294
|
var astNodes = Array.isArray(ast) ? ast : ast.b;
|
|
@@ -8028,6 +8019,12 @@ function assertNewLineToken(token) {
|
|
|
8028
8019
|
throw new LitsError("Expected newline token, got ".concat(token === null || token === void 0 ? void 0 : token.t, "."));
|
|
8029
8020
|
}
|
|
8030
8021
|
|
|
8022
|
+
function transformTokens(tokenStram, transformer) {
|
|
8023
|
+
return __assign(__assign({}, tokenStram), { tokens: tokenStram.tokens.map(function (token) {
|
|
8024
|
+
return __assign(__assign({}, token), { v: transformer(token.v) });
|
|
8025
|
+
}) });
|
|
8026
|
+
}
|
|
8027
|
+
|
|
8031
8028
|
var UnparseOptions = /** @class */ (function () {
|
|
8032
8029
|
function UnparseOptions(unparse, lineLength, col, inlined, locked) {
|
|
8033
8030
|
if (col === void 0) { col = 0; }
|
|
@@ -8546,6 +8543,51 @@ function unparseAst(ast, lineLength) {
|
|
|
8546
8543
|
return result.trim();
|
|
8547
8544
|
}
|
|
8548
8545
|
|
|
8546
|
+
function isNoSpaceNeededBefore(token) {
|
|
8547
|
+
switch (token.t) {
|
|
8548
|
+
case TokenType.Bracket:
|
|
8549
|
+
return [')', ']'].includes(token.v);
|
|
8550
|
+
case TokenType.CollectionAccessor:
|
|
8551
|
+
return true;
|
|
8552
|
+
case TokenType.NewLine:
|
|
8553
|
+
return true;
|
|
8554
|
+
default:
|
|
8555
|
+
return false;
|
|
8556
|
+
}
|
|
8557
|
+
}
|
|
8558
|
+
function isNoSpaceNeededAfter(token) {
|
|
8559
|
+
switch (token.t) {
|
|
8560
|
+
case TokenType.Bracket:
|
|
8561
|
+
return ['(', '['].includes(token.v);
|
|
8562
|
+
case TokenType.CollectionAccessor:
|
|
8563
|
+
return true;
|
|
8564
|
+
case TokenType.FnShorthand:
|
|
8565
|
+
return true;
|
|
8566
|
+
case TokenType.NewLine:
|
|
8567
|
+
return true;
|
|
8568
|
+
case TokenType.RegexpShorthand:
|
|
8569
|
+
return true;
|
|
8570
|
+
default:
|
|
8571
|
+
return false;
|
|
8572
|
+
}
|
|
8573
|
+
}
|
|
8574
|
+
function untokenize(tokenStream) {
|
|
8575
|
+
var lastToken;
|
|
8576
|
+
return tokenStream.tokens.reduce(function (acc, token) {
|
|
8577
|
+
var joiner = !lastToken || isNoSpaceNeededAfter(lastToken) || isNoSpaceNeededBefore(token) ? '' : ' ';
|
|
8578
|
+
lastToken = token;
|
|
8579
|
+
return "".concat(acc).concat(joiner).concat(untokenizeToken(token));
|
|
8580
|
+
}, '');
|
|
8581
|
+
}
|
|
8582
|
+
function untokenizeToken(token) {
|
|
8583
|
+
switch (token.t) {
|
|
8584
|
+
case TokenType.String:
|
|
8585
|
+
return "\"".concat(token.v, "\"");
|
|
8586
|
+
default:
|
|
8587
|
+
return token.v;
|
|
8588
|
+
}
|
|
8589
|
+
}
|
|
8590
|
+
|
|
8549
8591
|
var Cache = /** @class */ (function () {
|
|
8550
8592
|
function Cache(maxSize) {
|
|
8551
8593
|
this.cache = {};
|
|
@@ -8677,6 +8719,12 @@ var Lits = /** @class */ (function () {
|
|
|
8677
8719
|
var contextStack = createContextStack(params);
|
|
8678
8720
|
return evaluate(ast, contextStack);
|
|
8679
8721
|
};
|
|
8722
|
+
Lits.prototype.transform = function (tokenStream, transformer) {
|
|
8723
|
+
return transformTokens(tokenStream, transformer);
|
|
8724
|
+
};
|
|
8725
|
+
Lits.prototype.untokenize = function (tokenStream) {
|
|
8726
|
+
return untokenize(tokenStream);
|
|
8727
|
+
};
|
|
8680
8728
|
Lits.prototype.apply = function (fn, fnParams, params) {
|
|
8681
8729
|
var _a;
|
|
8682
8730
|
if (params === void 0) { params = {}; }
|
|
@@ -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/cli/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';
|
package/dist/index.esm.js
CHANGED
|
@@ -2864,7 +2864,7 @@ var mathNormalExpression = {
|
|
|
2864
2864
|
},
|
|
2865
2865
|
};
|
|
2866
2866
|
|
|
2867
|
-
var version = "1.2.2-alpha.
|
|
2867
|
+
var version = "1.2.2-alpha.3";
|
|
2868
2868
|
|
|
2869
2869
|
var uuidTemplate = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx';
|
|
2870
2870
|
var xyRegexp = /[xy]/g;
|
|
@@ -6321,15 +6321,6 @@ function evaluateNumberAsFunction(fn, params, sourceCodeInfo) {
|
|
|
6321
6321
|
return toAny(param[fn]);
|
|
6322
6322
|
}
|
|
6323
6323
|
|
|
6324
|
-
// export function findUnresolvedIdentifiersInFunction(ast, contextStack, builtin: Builtin) => {
|
|
6325
|
-
// const astNodes = Array.isArray(ast) ? ast : ast.b
|
|
6326
|
-
// const unresolvedIdentifiers = new Set<UnresolvedIdentifier>()
|
|
6327
|
-
// for (const subNode of astNodes) {
|
|
6328
|
-
// findUnresolvedIdentifiersInAstNode(subNode, contextStack, builtin)
|
|
6329
|
-
// .forEach(symbol => unresolvedIdentifiers.add(symbol))
|
|
6330
|
-
// }
|
|
6331
|
-
// return unresolvedIdentifiers
|
|
6332
|
-
// }
|
|
6333
6324
|
var findUnresolvedIdentifiers = function (ast, contextStack, builtin) {
|
|
6334
6325
|
var e_1, _a;
|
|
6335
6326
|
var astNodes = Array.isArray(ast) ? ast : ast.b;
|
|
@@ -6938,26 +6929,6 @@ function analyze(ast, params) {
|
|
|
6938
6929
|
outcomes: calculateOutcomes(createContextStack(params), ast.b),
|
|
6939
6930
|
};
|
|
6940
6931
|
}
|
|
6941
|
-
function findUnresolvedIdentifiersInFunction(fun, params) {
|
|
6942
|
-
if (!isUserDefinedFunction(fun)) {
|
|
6943
|
-
return new Set();
|
|
6944
|
-
}
|
|
6945
|
-
var result = new Set();
|
|
6946
|
-
var contextStack = createContextStack(params);
|
|
6947
|
-
fun.o.forEach(function (overload) {
|
|
6948
|
-
var innerContextStack = contextStack.clone();
|
|
6949
|
-
var newContext = overload.as.mandatoryArguments.reduce(function (acc, arg) {
|
|
6950
|
-
acc[arg] = { value: null };
|
|
6951
|
-
return acc;
|
|
6952
|
-
}, {});
|
|
6953
|
-
if (overload.as.restArgument) {
|
|
6954
|
-
newContext[overload.as.restArgument] = { value: null };
|
|
6955
|
-
}
|
|
6956
|
-
var overloadSymbols = findUnresolvedIdentifiers(overload.b, innerContextStack.create(newContext), builtin);
|
|
6957
|
-
overloadSymbols.forEach(function (symbol) { return result.add(symbol); });
|
|
6958
|
-
});
|
|
6959
|
-
return result;
|
|
6960
|
-
}
|
|
6961
6932
|
|
|
6962
6933
|
function parseNumber(tokenStream, position) {
|
|
6963
6934
|
var _a;
|
|
@@ -8080,6 +8051,12 @@ function assertNewLineToken(token) {
|
|
|
8080
8051
|
throw new LitsError("Expected newline token, got ".concat(token === null || token === void 0 ? void 0 : token.t, "."));
|
|
8081
8052
|
}
|
|
8082
8053
|
|
|
8054
|
+
function transformTokens(tokenStram, transformer) {
|
|
8055
|
+
return __assign(__assign({}, tokenStram), { tokens: tokenStram.tokens.map(function (token) {
|
|
8056
|
+
return __assign(__assign({}, token), { v: transformer(token.v) });
|
|
8057
|
+
}) });
|
|
8058
|
+
}
|
|
8059
|
+
|
|
8083
8060
|
var UnparseOptions = /** @class */ (function () {
|
|
8084
8061
|
function UnparseOptions(unparse, lineLength, col, inlined, locked) {
|
|
8085
8062
|
if (col === void 0) { col = 0; }
|
|
@@ -8598,6 +8575,51 @@ function unparseAst(ast, lineLength) {
|
|
|
8598
8575
|
return result.trim();
|
|
8599
8576
|
}
|
|
8600
8577
|
|
|
8578
|
+
function isNoSpaceNeededBefore(token) {
|
|
8579
|
+
switch (token.t) {
|
|
8580
|
+
case TokenType.Bracket:
|
|
8581
|
+
return [')', ']'].includes(token.v);
|
|
8582
|
+
case TokenType.CollectionAccessor:
|
|
8583
|
+
return true;
|
|
8584
|
+
case TokenType.NewLine:
|
|
8585
|
+
return true;
|
|
8586
|
+
default:
|
|
8587
|
+
return false;
|
|
8588
|
+
}
|
|
8589
|
+
}
|
|
8590
|
+
function isNoSpaceNeededAfter(token) {
|
|
8591
|
+
switch (token.t) {
|
|
8592
|
+
case TokenType.Bracket:
|
|
8593
|
+
return ['(', '['].includes(token.v);
|
|
8594
|
+
case TokenType.CollectionAccessor:
|
|
8595
|
+
return true;
|
|
8596
|
+
case TokenType.FnShorthand:
|
|
8597
|
+
return true;
|
|
8598
|
+
case TokenType.NewLine:
|
|
8599
|
+
return true;
|
|
8600
|
+
case TokenType.RegexpShorthand:
|
|
8601
|
+
return true;
|
|
8602
|
+
default:
|
|
8603
|
+
return false;
|
|
8604
|
+
}
|
|
8605
|
+
}
|
|
8606
|
+
function untokenize(tokenStream) {
|
|
8607
|
+
var lastToken;
|
|
8608
|
+
return tokenStream.tokens.reduce(function (acc, token) {
|
|
8609
|
+
var joiner = !lastToken || isNoSpaceNeededAfter(lastToken) || isNoSpaceNeededBefore(token) ? '' : ' ';
|
|
8610
|
+
lastToken = token;
|
|
8611
|
+
return "".concat(acc).concat(joiner).concat(untokenizeToken(token));
|
|
8612
|
+
}, '');
|
|
8613
|
+
}
|
|
8614
|
+
function untokenizeToken(token) {
|
|
8615
|
+
switch (token.t) {
|
|
8616
|
+
case TokenType.String:
|
|
8617
|
+
return "\"".concat(token.v, "\"");
|
|
8618
|
+
default:
|
|
8619
|
+
return token.v;
|
|
8620
|
+
}
|
|
8621
|
+
}
|
|
8622
|
+
|
|
8601
8623
|
var Cache = /** @class */ (function () {
|
|
8602
8624
|
function Cache(maxSize) {
|
|
8603
8625
|
this.cache = {};
|
|
@@ -8729,6 +8751,12 @@ var Lits = /** @class */ (function () {
|
|
|
8729
8751
|
var contextStack = createContextStack(params);
|
|
8730
8752
|
return evaluate(ast, contextStack);
|
|
8731
8753
|
};
|
|
8754
|
+
Lits.prototype.transform = function (tokenStream, transformer) {
|
|
8755
|
+
return transformTokens(tokenStream, transformer);
|
|
8756
|
+
};
|
|
8757
|
+
Lits.prototype.untokenize = function (tokenStream) {
|
|
8758
|
+
return untokenize(tokenStream);
|
|
8759
|
+
};
|
|
8732
8760
|
Lits.prototype.apply = function (fn, fnParams, params) {
|
|
8733
8761
|
var _a;
|
|
8734
8762
|
if (params === void 0) { params = {}; }
|
|
@@ -15592,5 +15620,5 @@ function isDataType(arg) {
|
|
|
15592
15620
|
return dataTypes.includes(arg);
|
|
15593
15621
|
}
|
|
15594
15622
|
|
|
15595
|
-
export { AstNodeType, FunctionType, Lits, TokenType, apiReference, asLitsFunction, asNativeJsFunction, asUserDefinedFunction, assertLitsFunction, assertNativeJsFunction, assertUserDefinedFunction, createNativeJsFunction,
|
|
15623
|
+
export { AstNodeType, FunctionType, Lits, TokenType, apiReference, asLitsFunction, asNativeJsFunction, asUserDefinedFunction, assertLitsFunction, assertNativeJsFunction, assertUserDefinedFunction, createNativeJsFunction, isApiName, isBuiltinFunction, isDataType, isDatatypeReference, isFunctionReference, isLitsError, isLitsFunction, isNativeJsFunction, isNormalExpressionArgument, isShorthandReference, isSpecialExpressionArgument, isTypedValue, isUserDefinedFunction, normalExpressionKeys, reservedNames, specialExpressionKeys };
|
|
15596
15624
|
//# sourceMappingURL=index.esm.js.map
|