@mojir/lits 1.2.2-alpha.2 → 1.2.2-alpha.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.
- package/dist/cli/cli.js +58 -1
- package/dist/cli/src/Lits/Lits.d.ts +2 -1
- package/dist/cli/src/index.d.ts +1 -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 +58 -1
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +58 -1
- package/dist/index.js.map +1 -1
- package/dist/lits.iife.js +58 -1
- package/dist/lits.iife.js.map +1 -1
- package/dist/src/Lits/Lits.d.ts +2 -1
- package/dist/src/index.d.ts +1 -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 -1
- package/dist/testFramework.esm.js.map +1 -1
- package/dist/testFramework.js +58 -1
- 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.4";
|
|
96
96
|
|
|
97
97
|
var AstNodeType;
|
|
98
98
|
(function (AstNodeType) {
|
|
@@ -8019,6 +8019,12 @@ function assertNewLineToken(token) {
|
|
|
8019
8019
|
throw new LitsError("Expected newline token, got ".concat(token === null || token === void 0 ? void 0 : token.t, "."));
|
|
8020
8020
|
}
|
|
8021
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
|
+
|
|
8022
8028
|
var UnparseOptions = /** @class */ (function () {
|
|
8023
8029
|
function UnparseOptions(unparse, lineLength, col, inlined, locked) {
|
|
8024
8030
|
if (col === void 0) { col = 0; }
|
|
@@ -8537,6 +8543,51 @@ function unparseAst(ast, lineLength) {
|
|
|
8537
8543
|
return result.trim();
|
|
8538
8544
|
}
|
|
8539
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
|
+
|
|
8540
8591
|
var Cache = /** @class */ (function () {
|
|
8541
8592
|
function Cache(maxSize) {
|
|
8542
8593
|
this.cache = {};
|
|
@@ -8668,6 +8719,12 @@ var Lits = /** @class */ (function () {
|
|
|
8668
8719
|
var contextStack = createContextStack(params);
|
|
8669
8720
|
return evaluate(ast, contextStack);
|
|
8670
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
|
+
};
|
|
8671
8728
|
Lits.prototype.apply = function (fn, fnParams, params) {
|
|
8672
8729
|
var _a;
|
|
8673
8730
|
if (params === void 0) { params = {}; }
|
|
@@ -15,7 +15,6 @@ export interface LazyValue {
|
|
|
15
15
|
}
|
|
16
16
|
export interface JsFunction {
|
|
17
17
|
fn: (...args: any[]) => unknown;
|
|
18
|
-
[key: string]: unknown;
|
|
19
18
|
}
|
|
20
19
|
export interface LitsParams {
|
|
21
20
|
globalContext?: Context;
|
|
@@ -47,6 +46,8 @@ export declare class Lits {
|
|
|
47
46
|
tokenize(program: string, tokenizeParams?: TokenizeParams): TokenStream;
|
|
48
47
|
parse(tokenStream: TokenStream): Ast;
|
|
49
48
|
evaluate(ast: Ast, params: LitsParams): Any;
|
|
49
|
+
transform(tokenStream: TokenStream, transformer: (name: string) => string): TokenStream;
|
|
50
|
+
untokenize(tokenStream: TokenStream): string;
|
|
50
51
|
apply(fn: LitsFunction, fnParams: unknown[], params?: LitsParams): Any;
|
|
51
52
|
private generateAst;
|
|
52
53
|
}
|
package/dist/cli/src/index.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ export { normalExpressionKeys, specialExpressionKeys } from './builtin';
|
|
|
8
8
|
export { reservedNames } from './reservedNames';
|
|
9
9
|
export { Lits } from './Lits/Lits';
|
|
10
10
|
export { type LitsError, isLitsError } from './errors';
|
|
11
|
-
export type { LitsParams, LitsRuntimeInfo, LazyValue } from './Lits/Lits';
|
|
11
|
+
export type { LitsParams, LitsRuntimeInfo, LazyValue, JsFunction } from './Lits/Lits';
|
|
12
12
|
export { createNativeJsFunction } from './utils';
|
|
13
13
|
export { apiReference, isDatatypeReference, isFunctionReference, isNormalExpressionArgument, isShorthandReference, isSpecialExpressionArgument, isTypedValue } from '../reference';
|
|
14
14
|
export type { Argument, CommonReference, DatatypeReference, FunctionReference, Reference, ShorthandReference } from '../reference';
|
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.4";
|
|
2868
2868
|
|
|
2869
2869
|
var uuidTemplate = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx';
|
|
2870
2870
|
var xyRegexp = /[xy]/g;
|
|
@@ -8051,6 +8051,12 @@ function assertNewLineToken(token) {
|
|
|
8051
8051
|
throw new LitsError("Expected newline token, got ".concat(token === null || token === void 0 ? void 0 : token.t, "."));
|
|
8052
8052
|
}
|
|
8053
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
|
+
|
|
8054
8060
|
var UnparseOptions = /** @class */ (function () {
|
|
8055
8061
|
function UnparseOptions(unparse, lineLength, col, inlined, locked) {
|
|
8056
8062
|
if (col === void 0) { col = 0; }
|
|
@@ -8569,6 +8575,51 @@ function unparseAst(ast, lineLength) {
|
|
|
8569
8575
|
return result.trim();
|
|
8570
8576
|
}
|
|
8571
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
|
+
|
|
8572
8623
|
var Cache = /** @class */ (function () {
|
|
8573
8624
|
function Cache(maxSize) {
|
|
8574
8625
|
this.cache = {};
|
|
@@ -8700,6 +8751,12 @@ var Lits = /** @class */ (function () {
|
|
|
8700
8751
|
var contextStack = createContextStack(params);
|
|
8701
8752
|
return evaluate(ast, contextStack);
|
|
8702
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
|
+
};
|
|
8703
8760
|
Lits.prototype.apply = function (fn, fnParams, params) {
|
|
8704
8761
|
var _a;
|
|
8705
8762
|
if (params === void 0) { params = {}; }
|