@witchcraft/expressit 0.1.2 → 0.2.0
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/README.md +9 -5
- package/dist/Lexer.js +2 -2
- package/dist/Parser.d.ts +14 -29
- package/dist/Parser.d.ts.map +1 -1
- package/dist/Parser.js +120 -135
- package/dist/ast/builders/array.d.ts +1 -3
- package/dist/ast/builders/array.d.ts.map +1 -1
- package/dist/ast/builders/array.js +3 -5
- package/dist/ast/builders/condition.d.ts +5 -11
- package/dist/ast/builders/condition.d.ts.map +1 -1
- package/dist/ast/builders/condition.js +2 -3
- package/dist/ast/builders/delim.d.ts +1 -1
- package/dist/ast/builders/error.d.ts +3 -4
- package/dist/ast/builders/error.d.ts.map +1 -1
- package/dist/ast/builders/error.js +6 -2
- package/dist/ast/builders/expression.d.ts +3 -7
- package/dist/ast/builders/expression.d.ts.map +1 -1
- package/dist/ast/builders/expression.js +3 -5
- package/dist/ast/builders/group.d.ts +3 -8
- package/dist/ast/builders/group.d.ts.map +1 -1
- package/dist/ast/builders/group.js +3 -3
- package/dist/ast/builders/pos.d.ts +1 -2
- package/dist/ast/builders/pos.d.ts.map +1 -1
- package/dist/ast/builders/token.d.ts +3 -5
- package/dist/ast/builders/token.d.ts.map +1 -1
- package/dist/ast/builders/token.js +3 -4
- package/dist/ast/builders/type.d.ts +1 -1
- package/dist/ast/builders/variable.d.ts +3 -5
- package/dist/ast/builders/variable.d.ts.map +1 -1
- package/dist/ast/builders/variable.js +2 -3
- package/dist/ast/createArrayNode.d.ts +3 -0
- package/dist/ast/createArrayNode.d.ts.map +1 -0
- package/dist/ast/createArrayNode.js +12 -0
- package/dist/ast/createConditionNode.d.ts +11 -0
- package/dist/ast/createConditionNode.d.ts.map +1 -0
- package/dist/ast/createConditionNode.js +18 -0
- package/dist/ast/createExpressionNode.d.ts +3 -0
- package/dist/ast/createExpressionNode.d.ts.map +1 -0
- package/dist/ast/createExpressionNode.js +14 -0
- package/dist/ast/createGroupNode.d.ts +5 -0
- package/dist/ast/createGroupNode.d.ts.map +1 -0
- package/dist/ast/createGroupNode.js +14 -0
- package/dist/ast/createNormalizedCondition.d.ts +3 -0
- package/dist/ast/createNormalizedCondition.d.ts.map +1 -0
- package/dist/ast/createNormalizedCondition.js +10 -0
- package/dist/ast/createNormalizedExpression.d.ts +3 -0
- package/dist/ast/createNormalizedExpression.d.ts.map +1 -0
- package/dist/ast/createNormalizedExpression.js +10 -0
- package/dist/ast/createToken.d.ts +6 -0
- package/dist/ast/createToken.d.ts.map +1 -0
- package/dist/ast/createToken.js +15 -0
- package/dist/ast/createVariableNode.d.ts +3 -0
- package/dist/ast/createVariableNode.d.ts.map +1 -0
- package/dist/ast/createVariableNode.js +12 -0
- package/dist/ast/error.d.ts +3 -0
- package/dist/ast/error.d.ts.map +1 -0
- package/dist/ast/error.js +9 -0
- package/dist/ast/handlers.d.ts +5 -12
- package/dist/ast/handlers.d.ts.map +1 -1
- package/dist/ast/handlers.js +21 -29
- package/dist/ast/index.d.ts +9 -1
- package/dist/ast/index.d.ts.map +1 -1
- package/dist/ast/index.js +18 -2
- package/dist/defaults/defaultConditionNormalizer.d.ts +3 -0
- package/dist/defaults/defaultConditionNormalizer.d.ts.map +1 -0
- package/dist/defaults/defaultKeyParser.d.ts +3 -0
- package/dist/defaults/defaultKeyParser.d.ts.map +1 -0
- package/dist/defaults/defaultPrefixApplier.d.ts +3 -0
- package/dist/defaults/defaultPrefixApplier.d.ts.map +1 -0
- package/dist/defaults/defaultValueComparer.d.ts +3 -0
- package/dist/defaults/defaultValueComparer.d.ts.map +1 -0
- package/dist/{helpers/general → defaults}/index.d.ts +0 -2
- package/dist/defaults/index.d.ts.map +1 -0
- package/dist/{helpers/general → defaults}/index.js +0 -4
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/{helpers/errors.d.ts → internal/ExpressitError.d.ts} +3 -2
- package/dist/internal/ExpressitError.d.ts.map +1 -0
- package/dist/{helpers/errors.js → internal/ExpressitError.js} +2 -2
- package/dist/internal/applyBoolean.d.ts.map +1 -0
- package/dist/{helpers/general → internal}/applyPrefix.d.ts +1 -1
- package/dist/internal/applyPrefix.d.ts.map +1 -0
- package/dist/{helpers/parser → internal}/checkParserOpts.d.ts +2 -1
- package/dist/internal/checkParserOpts.d.ts.map +1 -0
- package/dist/{helpers/parser → internal}/checkParserOpts.js +14 -14
- package/dist/internal/escapeVariableOrPrefix.d.ts +2 -0
- package/dist/internal/escapeVariableOrPrefix.d.ts.map +1 -0
- package/dist/internal/escapeVariableOrPrefix.js +38 -0
- package/dist/internal/extractPosition.d.ts +5 -0
- package/dist/internal/extractPosition.d.ts.map +1 -0
- package/dist/internal/getUnclosedRightParenCount.d.ts +4 -0
- package/dist/internal/getUnclosedRightParenCount.d.ts.map +1 -0
- package/dist/{helpers/parser → internal}/getUnclosedRightParenCount.js +1 -1
- package/dist/{helpers/parser → internal}/parseParserOptions.d.ts +1 -1
- package/dist/internal/parseParserOptions.d.ts.map +1 -0
- package/dist/{helpers/parser → internal}/parseParserOptions.js +4 -4
- package/dist/internal/unescape.d.ts.map +1 -0
- package/dist/package.json.js +7 -7
- package/dist/types/ast.d.ts +195 -6
- package/dist/types/ast.d.ts.map +1 -1
- package/dist/types/ast.js +2 -0
- package/dist/types/autocomplete.d.ts +5 -6
- package/dist/types/autocomplete.d.ts.map +1 -1
- package/dist/types/parser.d.ts +17 -22
- package/dist/types/parser.d.ts.map +1 -1
- package/dist/utils/extractTokens.d.ts +2 -4
- package/dist/utils/extractTokens.d.ts.map +1 -1
- package/dist/utils/extractTokens.js +14 -18
- package/dist/utils/generateParentsMap.d.ts +10 -0
- package/dist/utils/generateParentsMap.d.ts.map +1 -0
- package/dist/utils/generateParentsMap.js +73 -0
- package/dist/utils/getCursorInfo.d.ts +1 -1
- package/dist/utils/getCursorInfo.d.ts.map +1 -1
- package/dist/utils/getCursorInfo.js +3 -5
- package/dist/utils/getOppositeDelimiter.d.ts +2 -1
- package/dist/utils/getOppositeDelimiter.d.ts.map +1 -1
- package/dist/utils/getOppositeDelimiter.js +6 -5
- package/dist/utils/getParent.d.ts +5 -0
- package/dist/utils/getParent.d.ts.map +1 -0
- package/dist/utils/getParent.js +6 -0
- package/dist/utils/getSurroundingErrors.d.ts +3 -4
- package/dist/utils/getSurroundingErrors.d.ts.map +1 -1
- package/dist/utils/getSurroundingErrors.js +3 -3
- package/dist/utils/index.d.ts +4 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +8 -0
- package/dist/utils/isNode.d.ts +10 -0
- package/dist/utils/isNode.d.ts.map +1 -0
- package/dist/utils/isNode.js +6 -0
- package/dist/utils/isToken.d.ts +8 -0
- package/dist/utils/isToken.d.ts.map +1 -0
- package/dist/utils/isToken.js +6 -0
- package/dist/utils/prettyAst.d.ts +1 -2
- package/dist/utils/prettyAst.d.ts.map +1 -1
- package/dist/utils/prettyAst.js +19 -26
- package/package.json +7 -7
- package/src/Lexer.ts +2 -2
- package/src/Parser.ts +158 -165
- package/src/ast/builders/array.ts +4 -9
- package/src/ast/builders/condition.ts +10 -15
- package/src/ast/builders/delim.ts +1 -1
- package/src/ast/builders/error.ts +10 -6
- package/src/ast/builders/expression.ts +17 -23
- package/src/ast/builders/group.ts +7 -11
- package/src/ast/builders/pos.ts +2 -3
- package/src/ast/builders/token.ts +6 -7
- package/src/ast/builders/type.ts +1 -1
- package/src/ast/builders/variable.ts +6 -8
- package/src/ast/createArrayNode.ts +17 -0
- package/src/ast/createConditionNode.ts +58 -0
- package/src/ast/createExpressionNode.ts +21 -0
- package/src/ast/createGroupNode.ts +46 -0
- package/src/ast/createNormalizedCondition.ts +12 -0
- package/src/ast/createNormalizedExpression.ts +9 -0
- package/src/ast/createToken.ts +26 -0
- package/src/ast/createVariableNode.ts +18 -0
- package/src/ast/error.ts +9 -0
- package/src/ast/handlers.ts +26 -37
- package/src/ast/index.ts +9 -1
- package/src/{helpers/general → defaults}/defaultConditionNormalizer.ts +1 -1
- package/src/{helpers/general → defaults}/defaultKeyParser.ts +1 -1
- package/src/{helpers/general → defaults}/defaultPrefixApplier.ts +1 -1
- package/src/{helpers/general → defaults}/defaultValueComparer.ts +1 -1
- package/src/{helpers/general → defaults}/index.ts +0 -2
- package/src/index.ts +2 -1
- package/src/{helpers/errors.ts → internal/ExpressitError.ts} +2 -2
- package/src/{helpers/general → internal}/applyPrefix.ts +1 -1
- package/src/{helpers/parser → internal}/checkParserOpts.ts +16 -15
- package/src/internal/escapeVariableOrPrefix.ts +36 -0
- package/src/{helpers/parser → internal}/extractPosition.ts +2 -2
- package/src/{helpers/parser → internal}/getUnclosedRightParenCount.ts +1 -2
- package/src/{helpers/parser → internal}/parseParserOptions.ts +5 -5
- package/src/types/ast.ts +292 -7
- package/src/types/autocomplete.ts +5 -7
- package/src/types/parser.ts +17 -22
- package/src/utils/extractTokens.ts +16 -20
- package/src/utils/generateParentsMap.ts +60 -0
- package/src/utils/getCursorInfo.ts +4 -6
- package/src/utils/getOppositeDelimiter.ts +11 -10
- package/src/utils/getParent.ts +16 -0
- package/src/utils/getSurroundingErrors.ts +10 -9
- package/src/utils/index.ts +4 -0
- package/src/utils/isNode.ts +12 -0
- package/src/utils/isToken.ts +10 -0
- package/src/utils/prettyAst.ts +20 -17
- package/dist/ast/classes/ArrayNode.d.ts +0 -18
- package/dist/ast/classes/ArrayNode.d.ts.map +0 -1
- package/dist/ast/classes/ArrayNode.js +0 -55
- package/dist/ast/classes/Condition.d.ts +0 -13
- package/dist/ast/classes/Condition.d.ts.map +0 -1
- package/dist/ast/classes/Condition.js +0 -21
- package/dist/ast/classes/ConditionNode.d.ts +0 -73
- package/dist/ast/classes/ConditionNode.d.ts.map +0 -1
- package/dist/ast/classes/ConditionNode.js +0 -101
- package/dist/ast/classes/ErrorToken.d.ts +0 -27
- package/dist/ast/classes/ErrorToken.d.ts.map +0 -1
- package/dist/ast/classes/ErrorToken.js +0 -47
- package/dist/ast/classes/Expression.d.ts +0 -13
- package/dist/ast/classes/Expression.d.ts.map +0 -1
- package/dist/ast/classes/Expression.js +0 -19
- package/dist/ast/classes/ExpressionNode.d.ts +0 -21
- package/dist/ast/classes/ExpressionNode.d.ts.map +0 -1
- package/dist/ast/classes/ExpressionNode.js +0 -57
- package/dist/ast/classes/GroupNode.d.ts +0 -64
- package/dist/ast/classes/GroupNode.d.ts.map +0 -1
- package/dist/ast/classes/GroupNode.js +0 -69
- package/dist/ast/classes/Node.d.ts +0 -22
- package/dist/ast/classes/Node.d.ts.map +0 -1
- package/dist/ast/classes/Node.js +0 -28
- package/dist/ast/classes/Token.d.ts +0 -27
- package/dist/ast/classes/Token.d.ts.map +0 -1
- package/dist/ast/classes/Token.js +0 -28
- package/dist/ast/classes/ValidToken.d.ts +0 -26
- package/dist/ast/classes/ValidToken.d.ts.map +0 -1
- package/dist/ast/classes/ValidToken.js +0 -49
- package/dist/ast/classes/VariableNode.d.ts +0 -33
- package/dist/ast/classes/VariableNode.d.ts.map +0 -1
- package/dist/ast/classes/VariableNode.js +0 -58
- package/dist/ast/classes/index.d.ts +0 -12
- package/dist/ast/classes/index.d.ts.map +0 -1
- package/dist/ast/classes/index.js +0 -24
- package/dist/helpers/errors.d.ts.map +0 -1
- package/dist/helpers/general/applyBoolean.d.ts.map +0 -1
- package/dist/helpers/general/applyPrefix.d.ts.map +0 -1
- package/dist/helpers/general/defaultConditionNormalizer.d.ts +0 -3
- package/dist/helpers/general/defaultConditionNormalizer.d.ts.map +0 -1
- package/dist/helpers/general/defaultKeyParser.d.ts +0 -3
- package/dist/helpers/general/defaultKeyParser.d.ts.map +0 -1
- package/dist/helpers/general/defaultPrefixApplier.d.ts +0 -3
- package/dist/helpers/general/defaultPrefixApplier.d.ts.map +0 -1
- package/dist/helpers/general/defaultValueComparer.d.ts +0 -3
- package/dist/helpers/general/defaultValueComparer.d.ts.map +0 -1
- package/dist/helpers/general/index.d.ts.map +0 -1
- package/dist/helpers/index.d.ts +0 -4
- package/dist/helpers/index.d.ts.map +0 -1
- package/dist/helpers/index.js +0 -8
- package/dist/helpers/parser/assignParents.d.ts +0 -4
- package/dist/helpers/parser/assignParents.d.ts.map +0 -1
- package/dist/helpers/parser/assignParents.js +0 -71
- package/dist/helpers/parser/checkParserOpts.d.ts.map +0 -1
- package/dist/helpers/parser/extractPosition.d.ts +0 -5
- package/dist/helpers/parser/extractPosition.d.ts.map +0 -1
- package/dist/helpers/parser/getUnclosedRightParenCount.d.ts +0 -4
- package/dist/helpers/parser/getUnclosedRightParenCount.d.ts.map +0 -1
- package/dist/helpers/parser/index.d.ts +0 -9
- package/dist/helpers/parser/index.d.ts.map +0 -1
- package/dist/helpers/parser/index.js +0 -18
- package/dist/helpers/parser/parseParserOptions.d.ts.map +0 -1
- package/dist/helpers/parser/seal.d.ts +0 -8
- package/dist/helpers/parser/seal.d.ts.map +0 -1
- package/dist/helpers/parser/seal.js +0 -10
- package/dist/helpers/parser/setParent.d.ts +0 -6
- package/dist/helpers/parser/setParent.d.ts.map +0 -1
- package/dist/helpers/parser/setParent.js +0 -4
- package/dist/helpers/parser/unescape.d.ts.map +0 -1
- package/src/ast/classes/ArrayNode.ts +0 -46
- package/src/ast/classes/Condition.ts +0 -22
- package/src/ast/classes/ConditionNode.ts +0 -141
- package/src/ast/classes/ErrorToken.ts +0 -49
- package/src/ast/classes/Expression.ts +0 -26
- package/src/ast/classes/ExpressionNode.ts +0 -62
- package/src/ast/classes/GroupNode.ts +0 -127
- package/src/ast/classes/Node.ts +0 -47
- package/src/ast/classes/Token.ts +0 -59
- package/src/ast/classes/ValidToken.ts +0 -56
- package/src/ast/classes/VariableNode.ts +0 -67
- package/src/ast/classes/index.ts +0 -13
- package/src/helpers/index.ts +0 -6
- package/src/helpers/parser/assignParents.ts +0 -51
- package/src/helpers/parser/index.ts +0 -10
- package/src/helpers/parser/seal.ts +0 -14
- package/src/helpers/parser/setParent.ts +0 -5
- /package/dist/{helpers/general → defaults}/defaultConditionNormalizer.js +0 -0
- /package/dist/{helpers/general → defaults}/defaultKeyParser.js +0 -0
- /package/dist/{helpers/general → defaults}/defaultPrefixApplier.js +0 -0
- /package/dist/{helpers/general → defaults}/defaultValueComparer.js +0 -0
- /package/dist/{helpers/general → internal}/applyBoolean.d.ts +0 -0
- /package/dist/{helpers/general → internal}/applyBoolean.js +0 -0
- /package/dist/{helpers/general → internal}/applyPrefix.js +0 -0
- /package/dist/{helpers/parser → internal}/extractPosition.js +0 -0
- /package/dist/{helpers/parser → internal}/unescape.d.ts +0 -0
- /package/dist/{helpers/parser → internal}/unescape.js +0 -0
- /package/src/{helpers/general → internal}/applyBoolean.ts +0 -0
- /package/src/{helpers/parser → internal}/unescape.ts +0 -0
package/dist/ast/handlers.js
CHANGED
|
@@ -1,26 +1,25 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import { TOKEN_TYPE } from "../types/ast.js";
|
|
1
|
+
import { createArrayNode } from "./createArrayNode.js";
|
|
2
|
+
import { createConditionNode } from "./createConditionNode.js";
|
|
3
|
+
import { createExpressionNode } from "./createExpressionNode.js";
|
|
4
|
+
import { createGroupNode } from "./createGroupNode.js";
|
|
5
|
+
import { createToken } from "./createToken.js";
|
|
6
|
+
import { createVariableNode } from "./createVariableNode.js";
|
|
7
|
+
import { TOKEN_TYPE, AST_TYPE } from "../types/ast.js";
|
|
9
8
|
function error(pos, expected) {
|
|
10
9
|
if (pos === void 0)
|
|
11
10
|
throw new Error("should never happen, passed undefined position for error token");
|
|
12
|
-
return
|
|
11
|
+
return createToken({ expected, start: pos, end: pos });
|
|
13
12
|
}
|
|
14
|
-
const operators = (type) => (value, pos) =>
|
|
13
|
+
const operators = (type) => (value, pos) => createToken({ value, type, ...pos });
|
|
15
14
|
const delimiters = (type) => (value, pos) => (
|
|
16
15
|
// check must be falsy, we want to return undefined when given ""
|
|
17
|
-
value ?
|
|
16
|
+
value ? createToken({ value, type, ...pos }) : void 0
|
|
18
17
|
);
|
|
19
18
|
const maybeToken = (type) => (value, pos) => {
|
|
20
19
|
if (value === void 0) {
|
|
21
20
|
return error(pos.end, [type]);
|
|
22
21
|
} else {
|
|
23
|
-
return
|
|
22
|
+
return createToken({ value, type, ...pos });
|
|
24
23
|
}
|
|
25
24
|
};
|
|
26
25
|
const token = {
|
|
@@ -45,7 +44,7 @@ const operator = {
|
|
|
45
44
|
not: operators(TOKEN_TYPE.NOT)
|
|
46
45
|
};
|
|
47
46
|
function variable(prefix, quoteL, value, quoteR, flags) {
|
|
48
|
-
var _a;
|
|
47
|
+
var _a, _b;
|
|
49
48
|
const node = {
|
|
50
49
|
prefix: prefix ?? void 0,
|
|
51
50
|
value: value ?? error((prefix == null ? void 0 : prefix.end) ?? (quoteL == null ? void 0 : quoteL.end) ?? (quoteR == null ? void 0 : quoteR.start), [TOKEN_TYPE.VALUE]),
|
|
@@ -59,11 +58,10 @@ function variable(prefix, quoteL, value, quoteR, flags) {
|
|
|
59
58
|
};
|
|
60
59
|
if (flags) {
|
|
61
60
|
node.quote.flags = flags;
|
|
62
|
-
node.end = (_a = node.quote) == null ? void 0 : _a.flags.end;
|
|
61
|
+
node.end = ((_b = (_a = node.quote) == null ? void 0 : _a.flags) == null ? void 0 : _b.end) ?? node.end;
|
|
63
62
|
}
|
|
64
63
|
}
|
|
65
|
-
|
|
66
|
-
return instance;
|
|
64
|
+
return createVariableNode(node);
|
|
67
65
|
}
|
|
68
66
|
function condition(not, property, { propertyOperator, sepL, sepR } = {}, value) {
|
|
69
67
|
var _a;
|
|
@@ -90,27 +88,25 @@ function condition(not, property, { propertyOperator, sepL, sepR } = {}, value)
|
|
|
90
88
|
}
|
|
91
89
|
if (sepR)
|
|
92
90
|
node.sep.right = sepR;
|
|
93
|
-
else if (!node.value || node.value
|
|
91
|
+
else if (!node.value || node.value.type === AST_TYPE.VARIABLE) {
|
|
94
92
|
node.sep.right = error(((_a = node.value) == null ? void 0 : _a.start) ?? end, [TOKEN_TYPE.OP_EXPANDED_SEP]);
|
|
95
93
|
}
|
|
96
94
|
} else if (propertyOperator) {
|
|
97
95
|
node.property || (node.property = error(propertyOperator.start, [TOKEN_TYPE.VALUE]));
|
|
98
96
|
}
|
|
99
|
-
|
|
100
|
-
return instance;
|
|
97
|
+
return createConditionNode(node);
|
|
101
98
|
}
|
|
102
99
|
function expression(left, operator2, right) {
|
|
103
|
-
|
|
100
|
+
return createExpressionNode({
|
|
104
101
|
left: left ?? error((operator2 == null ? void 0 : operator2.start) ?? (right == null ? void 0 : right.start), [TOKEN_TYPE.VALUE]),
|
|
105
102
|
operator: operator2 ?? error((left == null ? void 0 : left.end) ?? (right == null ? void 0 : right.start), [TOKEN_TYPE.AND, TOKEN_TYPE.OR]),
|
|
106
103
|
right: right ?? error((operator2 == null ? void 0 : operator2.end) ?? (left == null ? void 0 : left.end), [TOKEN_TYPE.VALUE]),
|
|
107
104
|
start: (left == null ? void 0 : left.start) ?? (operator2 == null ? void 0 : operator2.start) ?? (right == null ? void 0 : right.start),
|
|
108
105
|
end: (right == null ? void 0 : right.end) ?? (operator2 == null ? void 0 : operator2.end) ?? (left == null ? void 0 : left.end)
|
|
109
106
|
});
|
|
110
|
-
return instance;
|
|
111
107
|
}
|
|
112
108
|
function group(operator2, prefix, parenL, condition2, parenR) {
|
|
113
|
-
|
|
109
|
+
return createGroupNode({
|
|
114
110
|
prefix: prefix ?? operator2 ?? void 0,
|
|
115
111
|
expression: condition2 ?? error((parenL == null ? void 0 : parenL.end) ?? (parenR == null ? void 0 : parenR.start), [TOKEN_TYPE.VALUE]),
|
|
116
112
|
paren: {
|
|
@@ -119,13 +115,11 @@ function group(operator2, prefix, parenL, condition2, parenR) {
|
|
|
119
115
|
},
|
|
120
116
|
start: (prefix == null ? void 0 : prefix.start) ?? (operator2 == null ? void 0 : operator2.start) ?? (parenL == null ? void 0 : parenL.start) ?? (condition2 == null ? void 0 : condition2.start) ?? (parenR == null ? void 0 : parenR.start),
|
|
121
117
|
end: (parenR == null ? void 0 : parenR.end) ?? (condition2 == null ? void 0 : condition2.end) ?? (parenL == null ? void 0 : parenL.end) ?? (operator2 == null ? void 0 : operator2.end) ?? (prefix == null ? void 0 : prefix.end)
|
|
122
|
-
};
|
|
123
|
-
const instance = new GroupNode(node);
|
|
124
|
-
return instance;
|
|
118
|
+
});
|
|
125
119
|
}
|
|
126
120
|
function array(bracketL, values, bracketR) {
|
|
127
121
|
var _a, _b;
|
|
128
|
-
|
|
122
|
+
return createArrayNode({
|
|
129
123
|
values,
|
|
130
124
|
bracket: {
|
|
131
125
|
left: bracketL,
|
|
@@ -134,9 +128,7 @@ function array(bracketL, values, bracketR) {
|
|
|
134
128
|
},
|
|
135
129
|
start: bracketL.start,
|
|
136
130
|
end: (bracketR == null ? void 0 : bracketR.end) ?? ((_b = values[values.length - 1]) == null ? void 0 : _b.end) ?? bracketL.end
|
|
137
|
-
};
|
|
138
|
-
const instance = new ArrayNode(node);
|
|
139
|
-
return instance;
|
|
131
|
+
});
|
|
140
132
|
}
|
|
141
133
|
export {
|
|
142
134
|
array,
|
package/dist/ast/index.d.ts
CHANGED
|
@@ -1,4 +1,12 @@
|
|
|
1
1
|
export * as builders from "./builders/index.js";
|
|
2
|
-
export
|
|
2
|
+
export { createArrayNode } from "./createArrayNode.js";
|
|
3
|
+
export { createCondition } from "./createNormalizedCondition.js";
|
|
4
|
+
export { createConditionNode } from "./createConditionNode.js";
|
|
5
|
+
export { createExpression } from "./createNormalizedExpression.js";
|
|
6
|
+
export { createExpressionNode } from "./createExpressionNode.js";
|
|
7
|
+
export { createGroupNode } from "./createGroupNode.js";
|
|
8
|
+
export { createToken } from "./createToken.js";
|
|
9
|
+
export { createVariableNode } from "./createVariableNode.js";
|
|
10
|
+
export { error } from "./error.js";
|
|
3
11
|
export { token } from "./handlers.js";
|
|
4
12
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/ast/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ast/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,QAAQ,MAAM,qBAAqB,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ast/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,QAAQ,MAAM,qBAAqB,CAAA;AAG/C,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AACtD,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAA;AAChE,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAA;AAC9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAA;AAClE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAA;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAC9C,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AAC5D,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAClC,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAA"}
|
package/dist/ast/index.js
CHANGED
|
@@ -1,8 +1,24 @@
|
|
|
1
1
|
import * as index from "./builders/index.js";
|
|
2
|
-
import
|
|
2
|
+
import { createArrayNode } from "./createArrayNode.js";
|
|
3
|
+
import { createCondition } from "./createNormalizedCondition.js";
|
|
4
|
+
import { createConditionNode } from "./createConditionNode.js";
|
|
5
|
+
import { createExpression } from "./createNormalizedExpression.js";
|
|
6
|
+
import { createExpressionNode } from "./createExpressionNode.js";
|
|
7
|
+
import { createGroupNode } from "./createGroupNode.js";
|
|
8
|
+
import { createToken } from "./createToken.js";
|
|
9
|
+
import { createVariableNode } from "./createVariableNode.js";
|
|
10
|
+
import { error } from "./error.js";
|
|
3
11
|
import { token } from "./handlers.js";
|
|
4
12
|
export {
|
|
5
13
|
index as builders,
|
|
6
|
-
|
|
14
|
+
createArrayNode,
|
|
15
|
+
createCondition,
|
|
16
|
+
createConditionNode,
|
|
17
|
+
createExpression,
|
|
18
|
+
createExpressionNode,
|
|
19
|
+
createGroupNode,
|
|
20
|
+
createToken,
|
|
21
|
+
createVariableNode,
|
|
22
|
+
error,
|
|
7
23
|
token
|
|
8
24
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defaultConditionNormalizer.d.ts","sourceRoot":"","sources":["../../src/defaults/defaultConditionNormalizer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAc,MAAM,oBAAoB,CAAA;AAGzE,eAAO,MAAM,0BAA0B,EAAE,mBAKxC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defaultKeyParser.d.ts","sourceRoot":"","sources":["../../src/defaults/defaultKeyParser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAGnD,eAAO,MAAM,gBAAgB,EAAE,SAI7B,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defaultPrefixApplier.d.ts","sourceRoot":"","sources":["../../src/defaults/defaultPrefixApplier.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAGvD,eAAO,MAAM,oBAAoB,EAAE,aAGlC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defaultValueComparer.d.ts","sourceRoot":"","sources":["../../src/defaults/defaultValueComparer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAGvD,eAAO,MAAM,oBAAoB,EAAE,aAGlC,CAAA"}
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
export { applyBoolean } from "./applyBoolean.js";
|
|
2
|
-
export { applyPrefix } from "./applyPrefix.js";
|
|
3
1
|
export { defaultConditionNormalizer } from "./defaultConditionNormalizer.js";
|
|
4
2
|
export { defaultKeyParser } from "./defaultKeyParser.js";
|
|
5
3
|
export { defaultPrefixApplier } from "./defaultPrefixApplier.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/defaults/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,0BAA0B,EAAE,MAAM,iCAAiC,CAAA;AAC5E,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AACxD,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAA;AAChE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAA"}
|
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
import { applyBoolean } from "./applyBoolean.js";
|
|
2
|
-
import { applyPrefix } from "./applyPrefix.js";
|
|
3
1
|
import { defaultConditionNormalizer } from "./defaultConditionNormalizer.js";
|
|
4
2
|
import { defaultKeyParser } from "./defaultKeyParser.js";
|
|
5
3
|
import { defaultPrefixApplier } from "./defaultPrefixApplier.js";
|
|
6
4
|
import { defaultValueComparer } from "./defaultValueComparer.js";
|
|
7
5
|
export {
|
|
8
|
-
applyBoolean,
|
|
9
|
-
applyPrefix,
|
|
10
6
|
defaultConditionNormalizer,
|
|
11
7
|
defaultKeyParser,
|
|
12
8
|
defaultPrefixApplier,
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
export * as ast from "./ast/
|
|
1
|
+
export * as ast from "./ast/index.js";
|
|
2
2
|
export { Parser } from "./Parser.js";
|
|
3
3
|
export * from "./types/index.js";
|
|
4
4
|
export * as utils from "./utils/index.js";
|
|
5
|
+
export * as defaults from "./defaults/index.js";
|
|
5
6
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,GAAG,MAAM,gBAAgB,CAAA;AACrC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,cAAc,kBAAkB,CAAA;AAChC,OAAO,KAAK,KAAK,MAAM,kBAAkB,CAAA;AACzC,OAAO,KAAK,QAAQ,MAAM,qBAAqB,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import * as index from "./ast/
|
|
1
|
+
import * as index from "./ast/index.js";
|
|
2
2
|
import { Parser } from "./Parser.js";
|
|
3
3
|
import { AST_TYPE, TOKEN_TYPE } from "./types/ast.js";
|
|
4
4
|
import { SUGGESTION_TYPE } from "./types/autocomplete.js";
|
|
5
5
|
import { ERROR_CODES } from "./types/errors.js";
|
|
6
6
|
import * as index$1 from "./utils/index.js";
|
|
7
|
+
import * as index$2 from "./defaults/index.js";
|
|
7
8
|
export {
|
|
8
9
|
AST_TYPE,
|
|
9
10
|
ERROR_CODES,
|
|
@@ -11,5 +12,6 @@ export {
|
|
|
11
12
|
SUGGESTION_TYPE,
|
|
12
13
|
TOKEN_TYPE,
|
|
13
14
|
index as ast,
|
|
15
|
+
index$2 as defaults,
|
|
14
16
|
index$1 as utils
|
|
15
17
|
};
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import type { ERROR_CODES, ErrorInfo } from "../types/errors.js";
|
|
2
|
-
|
|
2
|
+
/** @internal */
|
|
3
|
+
export declare class ExpressitError<T extends ERROR_CODES> extends Error {
|
|
3
4
|
version: string;
|
|
4
5
|
repo: string;
|
|
5
6
|
type: T;
|
|
6
7
|
info: ErrorInfo<T>;
|
|
7
8
|
constructor(type: T, info: ErrorInfo<T>, message?: string);
|
|
8
9
|
}
|
|
9
|
-
//# sourceMappingURL=
|
|
10
|
+
//# sourceMappingURL=ExpressitError.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ExpressitError.d.ts","sourceRoot":"","sources":["../../src/internal/ExpressitError.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAEhE,gBAAgB;AAChB,qBAAa,cAAc,CAAC,CAAC,SAAS,WAAW,CAAE,SAAQ,KAAK;IAC/D,OAAO,EAAE,MAAM,CAAU;IAEzB,IAAI,EAAE,MAAM,CAAa;IAEzB,IAAI,EAAE,CAAC,CAAA;IAEP,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC,CAAA;gBAEN,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,EAAE,MAAM;CAYzD"}
|
|
@@ -8,7 +8,7 @@ import { crop } from "@alanscodelog/utils/crop.js";
|
|
|
8
8
|
import { indent } from "@alanscodelog/utils/indent.js";
|
|
9
9
|
import { pretty } from "@alanscodelog/utils/pretty.js";
|
|
10
10
|
import { version, repository } from "../package.js";
|
|
11
|
-
class
|
|
11
|
+
class ExpressitError extends Error {
|
|
12
12
|
constructor(type, info, message) {
|
|
13
13
|
super(
|
|
14
14
|
message ? `${message}
|
|
@@ -39,5 +39,5 @@ function forceStringifyErrors(_key, value) {
|
|
|
39
39
|
return value;
|
|
40
40
|
}
|
|
41
41
|
export {
|
|
42
|
-
|
|
42
|
+
ExpressitError
|
|
43
43
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"applyBoolean.d.ts","sourceRoot":"","sources":["../../src/internal/applyBoolean.ts"],"names":[],"mappings":"AAAA,gBAAgB;AAChB,wBAAgB,YAAY,CAAC,IAAI,EAAE,OAAO,GAAG,SAAS,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAO/E"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { PrefixApplier } from "
|
|
1
|
+
import type { PrefixApplier } from "../types/parser.js";
|
|
2
2
|
/** @internal */
|
|
3
3
|
export declare function applyPrefix(left: string | undefined, right: string, prefixApplier: PrefixApplier): string;
|
|
4
4
|
//# sourceMappingURL=applyPrefix.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"applyPrefix.d.ts","sourceRoot":"","sources":["../../src/internal/applyPrefix.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAEvD,gBAAgB;AAChB,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,aAAa,GAAG,MAAM,CAGzG"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
import type { FullParserOptions } from "
|
|
1
|
+
import type { FullParserOptions } from "../types/parser.js";
|
|
2
|
+
/** @internal */
|
|
2
3
|
export declare function checkParserOpts<T extends {}>(opts: FullParserOptions<T>, evaluatorChecks?: boolean, validatorChecks?: boolean): void;
|
|
3
4
|
//# sourceMappingURL=checkParserOpts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checkParserOpts.d.ts","sourceRoot":"","sources":["../../src/internal/checkParserOpts.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,iBAAiB,EAAiB,MAAM,oBAAoB,CAAA;AAE1E,gBAAgB;AAChB,wBAAgB,eAAe,CAAC,CAAC,SAAS,EAAE,EAAE,IAAI,EAAE,iBAAiB,CAAC,CAAC,CAAC,EAAE,eAAe,GAAE,OAAe,EAAE,eAAe,GAAE,OAAe,GAAG,IAAI,CAoIlJ"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { isBlank } from "@alanscodelog/utils/isBlank.js";
|
|
2
2
|
import { pushIfNotIn } from "@alanscodelog/utils/pushIfNotIn.js";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
3
|
+
import { ExpressitError } from "./ExpressitError.js";
|
|
4
|
+
import { defaultConditionNormalizer } from "../defaults/defaultConditionNormalizer.js";
|
|
5
|
+
import { defaultValueComparer } from "../defaults/defaultValueComparer.js";
|
|
6
|
+
import { ERROR_CODES } from "../types/errors.js";
|
|
7
7
|
function checkParserOpts(opts, evaluatorChecks = false, validatorChecks = false) {
|
|
8
8
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
9
9
|
if (!evaluatorChecks) {
|
|
@@ -21,7 +21,7 @@ function checkParserOpts(opts, evaluatorChecks = false, validatorChecks = false)
|
|
|
21
21
|
if (opts.customPropertyOperators)
|
|
22
22
|
pushIfNotIn(extra, opts.customPropertyOperators);
|
|
23
23
|
if (opts.expandedPropertySeparator && isBlank(opts.expandedPropertySeparator)) {
|
|
24
|
-
throw new
|
|
24
|
+
throw new ExpressitError(
|
|
25
25
|
ERROR_CODES.PARSER_CONFLICTING_OPTIONS_ERROR,
|
|
26
26
|
{ prohibited: [""], invalid: opts.expandedPropertySeparator },
|
|
27
27
|
`expandedPropertySeparator cannot be blank`
|
|
@@ -29,7 +29,7 @@ function checkParserOpts(opts, evaluatorChecks = false, validatorChecks = false)
|
|
|
29
29
|
}
|
|
30
30
|
const customInvalid = (_a = opts.customPropertyOperators) == null ? void 0 : _a.find((_) => isBlank(_));
|
|
31
31
|
if (customInvalid !== void 0) {
|
|
32
|
-
throw new
|
|
32
|
+
throw new ExpressitError(
|
|
33
33
|
ERROR_CODES.PARSER_CONFLICTING_OPTIONS_ERROR,
|
|
34
34
|
{ prohibited: [""], invalid: customInvalid },
|
|
35
35
|
`customPropertyOperators cannot contain blank entries`
|
|
@@ -37,7 +37,7 @@ function checkParserOpts(opts, evaluatorChecks = false, validatorChecks = false)
|
|
|
37
37
|
}
|
|
38
38
|
const prefixInvalid = (_b = opts.prefixableStrings) == null ? void 0 : _b.find((_) => isBlank(_));
|
|
39
39
|
if (prefixInvalid !== void 0) {
|
|
40
|
-
throw new
|
|
40
|
+
throw new ExpressitError(
|
|
41
41
|
ERROR_CODES.PARSER_CONFLICTING_OPTIONS_ERROR,
|
|
42
42
|
{ prohibited: [""], invalid: prefixInvalid },
|
|
43
43
|
`prefixableStrings cannot contain blank entries`
|
|
@@ -46,7 +46,7 @@ function checkParserOpts(opts, evaluatorChecks = false, validatorChecks = false)
|
|
|
46
46
|
for (const key of ["and", "or", "not"]) {
|
|
47
47
|
const invalid = (_d = (_c = opts.keywords[key]) == null ? void 0 : _c.find((_) => isBlank(_.value))) == null ? void 0 : _d.value;
|
|
48
48
|
if (invalid !== void 0) {
|
|
49
|
-
throw new
|
|
49
|
+
throw new ExpressitError(
|
|
50
50
|
ERROR_CODES.PARSER_CONFLICTING_OPTIONS_ERROR,
|
|
51
51
|
{ prohibited: [""], invalid },
|
|
52
52
|
`keywords.${key} cannot contain entries with blank values`
|
|
@@ -59,7 +59,7 @@ function checkParserOpts(opts, evaluatorChecks = false, validatorChecks = false)
|
|
|
59
59
|
const messageInvalidBool = "cannot contain boolean operators or special symbols, but found";
|
|
60
60
|
const invalidPrefixableString = (_e = opts.prefixableStrings) == null ? void 0 : _e.find((val) => all.includes(val));
|
|
61
61
|
if (invalidPrefixableString) {
|
|
62
|
-
throw new
|
|
62
|
+
throw new ExpressitError(
|
|
63
63
|
ERROR_CODES.PARSER_CONFLICTING_OPTIONS_ERROR,
|
|
64
64
|
{ prohibited: all, invalid: invalidPrefixableString },
|
|
65
65
|
`prefixableStrings ${messageInvalidAny} "${invalidPrefixableString}"`
|
|
@@ -67,7 +67,7 @@ function checkParserOpts(opts, evaluatorChecks = false, validatorChecks = false)
|
|
|
67
67
|
}
|
|
68
68
|
const invalidExpandedPropertySeparator = allKeywords.find((_) => _ === opts.expandedPropertySeparator);
|
|
69
69
|
if (invalidExpandedPropertySeparator) {
|
|
70
|
-
throw new
|
|
70
|
+
throw new ExpressitError(
|
|
71
71
|
ERROR_CODES.PARSER_CONFLICTING_OPTIONS_ERROR,
|
|
72
72
|
{ prohibited: allKeywords, invalid: invalidExpandedPropertySeparator },
|
|
73
73
|
`expandedPropertySeparator ${messageInvalidBool} "${invalidExpandedPropertySeparator}"`
|
|
@@ -75,7 +75,7 @@ function checkParserOpts(opts, evaluatorChecks = false, validatorChecks = false)
|
|
|
75
75
|
}
|
|
76
76
|
const invalidCustomPropertyOperator = ((_f = opts.customPropertyOperators) == null ? void 0 : _f.find((val) => keywords.includes(val))) ? opts.expandedPropertySeparator : void 0;
|
|
77
77
|
if (invalidCustomPropertyOperator) {
|
|
78
|
-
throw new
|
|
78
|
+
throw new ExpressitError(
|
|
79
79
|
ERROR_CODES.PARSER_CONFLICTING_OPTIONS_ERROR,
|
|
80
80
|
{ prohibited: keywords, invalid: invalidCustomPropertyOperator },
|
|
81
81
|
`customPropertyOperator ${messageInvalidBool} "${invalidCustomPropertyOperator}"`
|
|
@@ -93,7 +93,7 @@ function checkParserOpts(opts, evaluatorChecks = false, validatorChecks = false)
|
|
|
93
93
|
if (opts.regexValues)
|
|
94
94
|
requireCustomNormalizer.push("regexValues");
|
|
95
95
|
if (requireCustomNormalizer.length > 0 && opts.conditionNormalizer === defaultConditionNormalizer) {
|
|
96
|
-
throw new
|
|
96
|
+
throw new ExpressitError(
|
|
97
97
|
ERROR_CODES.PARSER_OPTION_REQUIRED_ERROR,
|
|
98
98
|
{ options: requireCustomNormalizer, requires: "conditionNormalizer" },
|
|
99
99
|
`A custom conditionNormalizer function must be specified when using the following options: ${requireCustomNormalizer.join(", ")}`
|
|
@@ -105,7 +105,7 @@ function checkParserOpts(opts, evaluatorChecks = false, validatorChecks = false)
|
|
|
105
105
|
if (opts.regexValues)
|
|
106
106
|
requireCustomComparer.push("arrayValues");
|
|
107
107
|
if (requireCustomComparer.length > 0 && opts.valueComparer === defaultValueComparer) {
|
|
108
|
-
throw new
|
|
108
|
+
throw new ExpressitError(
|
|
109
109
|
ERROR_CODES.PARSER_OPTION_REQUIRED_ERROR,
|
|
110
110
|
{ options: requireCustomComparer, requires: "valueComparer" },
|
|
111
111
|
`A custom valueComparer function must be specified when using the following options: ${requireCustomComparer.join(", ")}`
|
|
@@ -114,7 +114,7 @@ function checkParserOpts(opts, evaluatorChecks = false, validatorChecks = false)
|
|
|
114
114
|
}
|
|
115
115
|
if (validatorChecks) {
|
|
116
116
|
if (opts.valueValidator === void 0) {
|
|
117
|
-
throw new
|
|
117
|
+
throw new ExpressitError(
|
|
118
118
|
ERROR_CODES.PARSER_OPTION_REQUIRED_ERROR,
|
|
119
119
|
{ requires: "valueValidator" },
|
|
120
120
|
`A custom valueValidator function must be specified when using the validate method.`
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"escapeVariableOrPrefix.d.ts","sourceRoot":"","sources":["../../src/internal/escapeVariableOrPrefix.ts"],"names":[],"mappings":"AAEA,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,GAAG,MAAM,CAiCvF"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { multisplice } from "@alanscodelog/utils/multisplice.js";
|
|
2
|
+
function escapeVariableOrPrefix(variable, preferredQuote) {
|
|
3
|
+
let doQuote = false;
|
|
4
|
+
for (const quoteType of ['"', "'", "`"]) {
|
|
5
|
+
if (!variable.includes(quoteType) && !variable.includes(" "))
|
|
6
|
+
continue;
|
|
7
|
+
if (variable.startsWith(quoteType) && variable.endsWith(quoteType)) {
|
|
8
|
+
break;
|
|
9
|
+
}
|
|
10
|
+
const indexes = [];
|
|
11
|
+
for (let i = 0; i < variable.length; i++) {
|
|
12
|
+
const char = variable[i];
|
|
13
|
+
if (char === void 0)
|
|
14
|
+
break;
|
|
15
|
+
if (char === "\\") {
|
|
16
|
+
i += 2;
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
if (char === " ") {
|
|
20
|
+
doQuote = true;
|
|
21
|
+
}
|
|
22
|
+
if (char === quoteType)
|
|
23
|
+
indexes.push(i);
|
|
24
|
+
}
|
|
25
|
+
if (indexes.length === 0)
|
|
26
|
+
break;
|
|
27
|
+
const newVal = multisplice(variable.split(""), indexes, 0, "\\").array.join("");
|
|
28
|
+
variable = newVal;
|
|
29
|
+
break;
|
|
30
|
+
}
|
|
31
|
+
if (doQuote) {
|
|
32
|
+
variable = `${preferredQuote}${variable}${preferredQuote}`;
|
|
33
|
+
}
|
|
34
|
+
return variable;
|
|
35
|
+
}
|
|
36
|
+
export {
|
|
37
|
+
escapeVariableOrPrefix
|
|
38
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Token } from "../Lexer.js";
|
|
2
|
+
import type { Position } from "../types/ast.js";
|
|
3
|
+
/** @internal */
|
|
4
|
+
export declare function extractPosition(pos: Pick<Token, "startOffset" | "endOffset">, shift: number): Position;
|
|
5
|
+
//# sourceMappingURL=extractPosition.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extractPosition.d.ts","sourceRoot":"","sources":["../../src/internal/extractPosition.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAA;AAG/C,gBAAgB;AAChB,wBAAgB,eAAe,CAAC,GAAG,EAAE,IAAI,CAAC,KAAK,EAAE,aAAa,GAAG,WAAW,CAAC,EAAE,KAAK,EAAE,MAAM,GAAG,QAAQ,CAKtG"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getUnclosedRightParenCount.d.ts","sourceRoot":"","sources":["../../src/internal/getUnclosedRightParenCount.ts"],"names":[],"mappings":"AAAA,OAAO,EAAM,KAAK,KAAK,EAAE,MAAM,aAAa,CAAA;AAG5C,gBAAgB;AAEhB,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,CAelE"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { FullParserOptions, ParserOptions } from "
|
|
1
|
+
import type { FullParserOptions, ParserOptions } from "../types/parser.js";
|
|
2
2
|
/** @internal */
|
|
3
3
|
export declare function parseParserOptions<T extends {} = {}>(options: ParserOptions<T>): FullParserOptions<T>;
|
|
4
4
|
//# sourceMappingURL=parseParserOptions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parseParserOptions.d.ts","sourceRoot":"","sources":["../../src/internal/parseParserOptions.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAE1E,gBAAgB;AAChB,wBAAgB,kBAAkB,CAAC,CAAC,SAAS,EAAE,GAAG,EAAE,EACnD,OAAO,EAAE,aAAa,CAAC,CAAC,CAAC,GACvB,iBAAiB,CAAC,CAAC,CAAC,CA4CtB"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { defaultConditionNormalizer } from "../
|
|
2
|
-
import { defaultKeyParser } from "../
|
|
3
|
-
import { defaultPrefixApplier } from "../
|
|
4
|
-
import { defaultValueComparer } from "../
|
|
1
|
+
import { defaultConditionNormalizer } from "../defaults/defaultConditionNormalizer.js";
|
|
2
|
+
import { defaultKeyParser } from "../defaults/defaultKeyParser.js";
|
|
3
|
+
import { defaultPrefixApplier } from "../defaults/defaultPrefixApplier.js";
|
|
4
|
+
import { defaultValueComparer } from "../defaults/defaultValueComparer.js";
|
|
5
5
|
function parseParserOptions(options) {
|
|
6
6
|
var _a, _b, _c;
|
|
7
7
|
const opts = {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unescape.d.ts","sourceRoot":"","sources":["../../src/internal/unescape.ts"],"names":[],"mappings":"AAAA,gBAAgB;AAChB,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE5C"}
|
package/dist/package.json.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const name = "@witchcraft/expressit";
|
|
2
2
|
const description = "A blazing fast, customizable, error-tolerant expression parser that creates safe to eval expressions + a few other goodies like autocomplete.";
|
|
3
|
-
const version = "0.
|
|
3
|
+
const version = "0.2.0";
|
|
4
4
|
const types = "./dist/index.d.ts";
|
|
5
5
|
const type = "module";
|
|
6
6
|
const module = "./dist/index.js";
|
|
@@ -18,13 +18,13 @@ const exports = {
|
|
|
18
18
|
types: "./dist/ast/*",
|
|
19
19
|
"import": "./dist/ast/*"
|
|
20
20
|
},
|
|
21
|
-
"./
|
|
22
|
-
types: "./dist/
|
|
23
|
-
"import": "./dist/
|
|
21
|
+
"./internal": {
|
|
22
|
+
types: "./dist/internal/index.d.ts",
|
|
23
|
+
"import": "./dist/internal/index.js"
|
|
24
24
|
},
|
|
25
|
-
"./
|
|
26
|
-
types: "./dist/
|
|
27
|
-
"import": "./dist/
|
|
25
|
+
"./internal/*": {
|
|
26
|
+
types: "./dist/internal/*",
|
|
27
|
+
"import": "./dist/internal/*"
|
|
28
28
|
},
|
|
29
29
|
"./methods": {
|
|
30
30
|
types: "./dist/methods/index.d.ts",
|