@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/Parser.js
CHANGED
|
@@ -11,32 +11,27 @@ import { isWhitespace } from "@alanscodelog/utils/isWhitespace.js";
|
|
|
11
11
|
import { setReadOnly } from "@alanscodelog/utils/setReadOnly.js";
|
|
12
12
|
import { unreachable } from "@alanscodelog/utils/unreachable.js";
|
|
13
13
|
import { pos } from "./ast/builders/pos.js";
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import { ErrorToken } from "./ast/classes/ErrorToken.js";
|
|
17
|
-
import { ExpressionNode } from "./ast/classes/ExpressionNode.js";
|
|
18
|
-
import { GroupNode } from "./ast/classes/GroupNode.js";
|
|
19
|
-
import { Condition } from "./ast/classes/Condition.js";
|
|
20
|
-
import { Expression } from "./ast/classes/Expression.js";
|
|
21
|
-
import "@alanscodelog/utils/crop.js";
|
|
22
|
-
import "@alanscodelog/utils/indent.js";
|
|
23
|
-
import "@alanscodelog/utils/pretty.js";
|
|
24
|
-
import { ValidToken } from "./ast/classes/ValidToken.js";
|
|
25
|
-
import { VariableNode } from "./ast/classes/VariableNode.js";
|
|
14
|
+
import { createCondition } from "./ast/createNormalizedCondition.js";
|
|
15
|
+
import { createExpression } from "./ast/createNormalizedExpression.js";
|
|
26
16
|
import { token, operator, expression, variable, condition, group, array, delimiter } from "./ast/handlers.js";
|
|
27
|
-
import { applyBoolean } from "./
|
|
28
|
-
import { applyPrefix } from "./
|
|
29
|
-
import { checkParserOpts } from "./
|
|
30
|
-
import {
|
|
31
|
-
import {
|
|
32
|
-
import {
|
|
33
|
-
import {
|
|
17
|
+
import { applyBoolean } from "./internal/applyBoolean.js";
|
|
18
|
+
import { applyPrefix } from "./internal/applyPrefix.js";
|
|
19
|
+
import { checkParserOpts } from "./internal/checkParserOpts.js";
|
|
20
|
+
import { escapeVariableOrPrefix } from "./internal/escapeVariableOrPrefix.js";
|
|
21
|
+
import { extractPosition } from "./internal/extractPosition.js";
|
|
22
|
+
import { getUnclosedRightParenCount } from "./internal/getUnclosedRightParenCount.js";
|
|
23
|
+
import { parseParserOptions } from "./internal/parseParserOptions.js";
|
|
24
|
+
import { unescape } from "./internal/unescape.js";
|
|
34
25
|
import { Lexer, $C, $T } from "./Lexer.js";
|
|
35
|
-
import { TOKEN_TYPE } from "./types/ast.js";
|
|
26
|
+
import { TOKEN_TYPE, AST_TYPE } from "./types/ast.js";
|
|
36
27
|
import { SUGGESTION_TYPE } from "./types/autocomplete.js";
|
|
37
28
|
import { extractTokens } from "./utils/extractTokens.js";
|
|
29
|
+
import { generateParentsMap } from "./utils/generateParentsMap.js";
|
|
38
30
|
import { getCursorInfo } from "./utils/getCursorInfo.js";
|
|
31
|
+
import { getParent } from "./utils/getParent.js";
|
|
39
32
|
import { getSurroundingErrors } from "./utils/getSurroundingErrors.js";
|
|
33
|
+
import { isNode } from "./utils/isNode.js";
|
|
34
|
+
import { isToken } from "./utils/isToken.js";
|
|
40
35
|
const OPPOSITE = {
|
|
41
36
|
[TOKEN_TYPE.AND]: TOKEN_TYPE.OR,
|
|
42
37
|
[TOKEN_TYPE.OR]: TOKEN_TYPE.AND
|
|
@@ -62,10 +57,10 @@ const createDefaultRequires = (partial = {}) => ({
|
|
|
62
57
|
group: partial.group ?? false,
|
|
63
58
|
prefix: partial.prefix ?? false
|
|
64
59
|
});
|
|
65
|
-
const tokenRequiresWhitespace = (
|
|
66
|
-
if (whitespace ||
|
|
60
|
+
const tokenRequiresWhitespace = (valid, whitespace, wordOps) => {
|
|
61
|
+
if (whitespace || valid === void 0)
|
|
67
62
|
return false;
|
|
68
|
-
return
|
|
63
|
+
return valid.type === TOKEN_TYPE.VALUE || [TOKEN_TYPE.AND, TOKEN_TYPE.OR, TOKEN_TYPE.NOT].includes(valid.type) && wordOps.find((_) => _.value === valid.value) !== void 0;
|
|
69
64
|
};
|
|
70
65
|
const tokenVariable = [TOKEN_TYPE.BACKTICK, TOKEN_TYPE.DOUBLEQUOTE, TOKEN_TYPE.SINGLEQUOTE, TOKEN_TYPE.VALUE, TOKEN_TYPE.REGEX];
|
|
71
66
|
class Parser {
|
|
@@ -140,8 +135,6 @@ class Parser {
|
|
|
140
135
|
* It can also parse the result from `lex`, but that is really only for internal use.
|
|
141
136
|
*/
|
|
142
137
|
parse(input) {
|
|
143
|
-
var _a;
|
|
144
|
-
const doSeal = ((_a = arguments[1]) == null ? void 0 : _a.seal) ?? true;
|
|
145
138
|
if (typeof input === "string" && isWhitespace(input)) {
|
|
146
139
|
return token.value(void 0, { start: 0, end: 0 });
|
|
147
140
|
}
|
|
@@ -153,9 +146,6 @@ class Parser {
|
|
|
153
146
|
lexedTokens
|
|
154
147
|
};
|
|
155
148
|
const res = this.ruleMain();
|
|
156
|
-
if (doSeal) {
|
|
157
|
-
seal(res);
|
|
158
|
-
}
|
|
159
149
|
this.state = {
|
|
160
150
|
rawInput: "",
|
|
161
151
|
shift: 0,
|
|
@@ -349,26 +339,26 @@ class Parser {
|
|
|
349
339
|
return res;
|
|
350
340
|
}
|
|
351
341
|
ruleCondition() {
|
|
352
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
342
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
353
343
|
const not = this.ruleNot();
|
|
354
344
|
const property = this.ruleConditionProperty();
|
|
355
|
-
const propVal = ((_a = property == null ? void 0 : property.prop) == null ? void 0 : _a.value) === void 0 ? void 0 : property.prop.value
|
|
356
|
-
const propOpVal = ((_b = property == null ? void 0 : property.rest) == null ? void 0 : _b.propertyOperator) === void 0 ? void 0 : property.rest.propertyOperator
|
|
357
|
-
const isExpanded = (((
|
|
345
|
+
const propVal = ((_a = property == null ? void 0 : property.prop) == null ? void 0 : _a.value) === void 0 ? void 0 : !property.prop.value.valid ? "" : property.prop.value.value;
|
|
346
|
+
const propOpVal = ((_b = property == null ? void 0 : property.rest) == null ? void 0 : _b.propertyOperator) === void 0 ? void 0 : !((_c = property.rest.propertyOperator) == null ? void 0 : _c.valid) ? "" : (_d = property.rest.propertyOperator) == null ? void 0 : _d.value;
|
|
347
|
+
const isExpanded = (((_e = property == null ? void 0 : property.rest) == null ? void 0 : _e.sepL) ?? ((_f = property == null ? void 0 : property.rest) == null ? void 0 : _f.sepR)) !== void 0;
|
|
358
348
|
const convertRegexValues = typeof this.options.regexValues === "function" && !this.options.regexValues(propVal, propOpVal, isExpanded);
|
|
359
349
|
const convertArrayValues = typeof this.options.arrayValues === "function" && !this.options.arrayValues(propVal, propOpVal, isExpanded);
|
|
360
350
|
let value = this.ruleConditionValue(property, { convertRegexValues, convertArrayValues });
|
|
361
351
|
let group$1;
|
|
362
|
-
if (!(value
|
|
352
|
+
if (isNode(value) && !(value.type === AST_TYPE.ARRAY) && !isArray(value) && (!value || this.options.prefixableGroups) && this.isType(this.peek(1), $T.PAREN_L)) {
|
|
363
353
|
group$1 = this.rulePlainGroup({ onlyValues: property !== void 0, convertRegexValues, convertArrayValues });
|
|
364
354
|
}
|
|
365
355
|
if (isArray(value)) {
|
|
366
356
|
group$1 = value;
|
|
367
357
|
value = void 0;
|
|
368
358
|
}
|
|
369
|
-
if (convertRegexValues && value
|
|
359
|
+
if (convertRegexValues && isNode(value) && value.type === AST_TYPE.VARIABLE && ((_g = value.quote) == null ? void 0 : _g.left.type) === TOKEN_TYPE.REGEX) {
|
|
370
360
|
value = variable(void 0, void 0, token.value(
|
|
371
|
-
(((
|
|
361
|
+
(((_i = (_h = value.quote) == null ? void 0 : _h.left) == null ? void 0 : _i.value) ?? "") + (value.value.value ?? "") + (((_k = (_j = value.quote) == null ? void 0 : _j.right) == null ? void 0 : _k.value) ?? ""),
|
|
372
362
|
pos(value)
|
|
373
363
|
), void 0);
|
|
374
364
|
}
|
|
@@ -444,7 +434,7 @@ class Parser {
|
|
|
444
434
|
regexValues: convertRegexValues,
|
|
445
435
|
arrayValues: convertArrayValues
|
|
446
436
|
}, "One");
|
|
447
|
-
const parsed = this.subParserOne.parse(" ".repeat(start) + subInput
|
|
437
|
+
const parsed = this.subParserOne.parse(" ".repeat(start) + subInput);
|
|
448
438
|
return [parenL, parsed, parenR];
|
|
449
439
|
}
|
|
450
440
|
return [parenL, condition2, parenR];
|
|
@@ -481,11 +471,11 @@ class Parser {
|
|
|
481
471
|
expandedPropertySeparator: void 0,
|
|
482
472
|
arrayValues: false
|
|
483
473
|
}, "Two");
|
|
484
|
-
const parsed = this.subParserTwo.parse(" ".repeat(start) + subInput
|
|
485
|
-
if (parsed
|
|
474
|
+
const parsed = this.subParserTwo.parse(" ".repeat(start) + subInput);
|
|
475
|
+
if ("type" in parsed && parsed.type === AST_TYPE.CONDITION) {
|
|
486
476
|
return parsed.value;
|
|
487
477
|
}
|
|
488
|
-
if (parsed
|
|
478
|
+
if ("valid" in parsed && !parsed.valid || "type" in parsed && (parsed.type === AST_TYPE.EXPRESSION || parsed.type === AST_TYPE.GROUP)) {
|
|
489
479
|
unreachable("parsed.value should not be an ErrorToken, ExpressionNode, or GroupNode.");
|
|
490
480
|
}
|
|
491
481
|
return parsed;
|
|
@@ -689,15 +679,15 @@ class Parser {
|
|
|
689
679
|
return void 0;
|
|
690
680
|
}
|
|
691
681
|
/**
|
|
692
|
-
* Given a list of @
|
|
682
|
+
* Given the ast, a list of {@link Suggestion} entries, the parser options, and a list of variables, prefixes, operators, etc, and the preferred quote type, returns a list of {@link Completion} entries.
|
|
693
683
|
*
|
|
694
684
|
* It takes care of suggesting the correct delimiters for fixes, quoting variables/prefixes if it would not be possible to parse them unquoted, and separating symbol from non-symbol (word) operators.
|
|
695
685
|
*
|
|
696
|
-
* Does not add whitespace or group requirements. The suggestion information is still in the completion if you wish to show these. But they should not be added to the completion value if using @
|
|
686
|
+
* Does not add whitespace or group requirements. The suggestion information is still in the completion if you wish to show these. But they should not be added to the completion value if using {@link autoreplace} which will take care of it.
|
|
697
687
|
*
|
|
698
|
-
* Is not aware of existing values. You will have to use @
|
|
688
|
+
* Is not aware of existing values. You will have to use {@link getCursorInfo} to understand the context in which the suggestion was made, so that, for example, you could filter out used regex flags.
|
|
699
689
|
*/
|
|
700
|
-
autocomplete(suggestions, {
|
|
690
|
+
autocomplete(ast, suggestions, {
|
|
701
691
|
values = [],
|
|
702
692
|
arrayValues = [],
|
|
703
693
|
variables = [],
|
|
@@ -709,6 +699,7 @@ class Parser {
|
|
|
709
699
|
regexFlags = ["i", "m", "u"],
|
|
710
700
|
quote = '"'
|
|
711
701
|
} = {}) {
|
|
702
|
+
const parentMap = generateParentsMap(ast);
|
|
712
703
|
const self = this;
|
|
713
704
|
return suggestions.map((suggestion) => {
|
|
714
705
|
const type = suggestion.type;
|
|
@@ -735,7 +726,7 @@ class Parser {
|
|
|
735
726
|
return true;
|
|
736
727
|
}
|
|
737
728
|
const token2 = suggestion2.cursorInfo;
|
|
738
|
-
const flags = token2.at && ((_b = (_a = token2.at
|
|
729
|
+
const flags = token2.at && ((_b = (_a = getParent(token2.at, parentMap)) == null ? void 0 : _a.quote) == null ? void 0 : _b.flags) === suggestion2.cursorInfo.at ? token2.at : token2.next && ((_d = (_c = getParent(token2.next, parentMap)) == null ? void 0 : _c.quote) == null ? void 0 : _d.flags) === suggestion2.cursorInfo.next ? token2.next : token2.prev && ((_f = (_e = getParent(token2.prev, parentMap)) == null ? void 0 : _e.quote) == null ? void 0 : _f.flags) === suggestion2.cursorInfo.prev ? token2.prev : void 0;
|
|
739
730
|
if ((_g = flags == null ? void 0 : flags.value) == null ? void 0 : _g.includes(value)) {
|
|
740
731
|
return false;
|
|
741
732
|
}
|
|
@@ -767,31 +758,17 @@ class Parser {
|
|
|
767
758
|
case SUGGESTION_TYPE.ARRAY_VALUE:
|
|
768
759
|
case SUGGESTION_TYPE.VARIABLE: {
|
|
769
760
|
const arr = type === SUGGESTION_TYPE.VARIABLE ? variables : type === SUGGESTION_TYPE.ARRAY_VALUE ? arrayValues : type === SUGGESTION_TYPE.VALUE ? values : unreachable();
|
|
770
|
-
return arr.map((variable2) => {
|
|
771
|
-
const res = self.parse(variable2);
|
|
772
|
-
if (res instanceof ConditionNode && res.operator === void 0 && res.value instanceof VariableNode && res.value.quote === void 0) {
|
|
773
|
-
return { suggestion, value: res.value.value.value };
|
|
774
|
-
} else {
|
|
775
|
-
return { suggestion, value: quote + variable2.replace(new RegExp(quote, "g"), `\\${quote}`) + quote };
|
|
776
|
-
}
|
|
777
|
-
});
|
|
761
|
+
return arr.map((variable2) => ({ suggestion, value: escapeVariableOrPrefix(variable2, quote) }));
|
|
778
762
|
}
|
|
779
763
|
case SUGGESTION_TYPE.PREFIX:
|
|
780
|
-
return prefixes.map((prefix) => {
|
|
781
|
-
const res = self.parse(prefix);
|
|
782
|
-
if (res instanceof ConditionNode && res.operator === void 0 && res.value instanceof VariableNode && res.value.quote === void 0) {
|
|
783
|
-
return { suggestion, value: res.value.value.value };
|
|
784
|
-
} else {
|
|
785
|
-
return { suggestion, value: quote + prefix.replace(new RegExp(quote, "g"), `\\${quote}`) + quote };
|
|
786
|
-
}
|
|
787
|
-
});
|
|
764
|
+
return prefixes.map((prefix) => ({ suggestion, value: escapeVariableOrPrefix(prefix, quote) }));
|
|
788
765
|
}
|
|
789
766
|
}).flat();
|
|
790
767
|
}
|
|
791
768
|
/**
|
|
792
|
-
* Given the input string and a @
|
|
769
|
+
* Given the input string and a {@link Completion} consisting of the value of the replacement and a {@link Suggestion} entry, returns the replacement string and the new position of the cursor.
|
|
793
770
|
*
|
|
794
|
-
* The value passed should be escaped if it's needed (or quoted). @
|
|
771
|
+
* The value passed should be escaped if it's needed (or quoted). {@link autocomplete} already takes care of quoting variables if you're using it.
|
|
795
772
|
*/
|
|
796
773
|
autoreplace(input, { value, suggestion }) {
|
|
797
774
|
const isQuotedLeft = ['"', "'", "`"].includes(value[0]);
|
|
@@ -819,9 +796,9 @@ class Parser {
|
|
|
819
796
|
return { replacement, cursor };
|
|
820
797
|
}
|
|
821
798
|
/**
|
|
822
|
-
* Returns a list of suggestions ( @
|
|
799
|
+
* Returns a list of suggestions ( {@link Suggestion} ). These are not a list of autocomplete entries (with values), but more a list of entries describing possible suggestions. This list can then be passed to {@link Parser}["autocomplete"] to build a list to show users, from which you can then pick an entry to pass to {@link Parser}["autoreplace"] .
|
|
823
800
|
*
|
|
824
|
-
* The list returned is "unsorted", but there is still some logic to the order. Fixes for errors are suggested first, in the order returned by @
|
|
801
|
+
* The list returned is "unsorted", but there is still some logic to the order. Fixes for errors are suggested first, in the order returned by {@link getSurroundingErrors}. Regular suggestions come after in the following order: prefixes if enabled, variables, boolean symbol operators, then boolean word operators.
|
|
825
802
|
*
|
|
826
803
|
* When the cursor is between two tokens that have possible suggestions, only suggestion types for the token before are returned. For example:
|
|
827
804
|
*
|
|
@@ -841,7 +818,8 @@ class Parser {
|
|
|
841
818
|
* ```
|
|
842
819
|
*/
|
|
843
820
|
autosuggest(input, ast, index) {
|
|
844
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z
|
|
821
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z;
|
|
822
|
+
const parentMap = generateParentsMap(ast);
|
|
845
823
|
const opts = this.options;
|
|
846
824
|
const tokens = extractTokens(ast);
|
|
847
825
|
const token2 = getCursorInfo(input, tokens, index);
|
|
@@ -854,7 +832,7 @@ class Parser {
|
|
|
854
832
|
const requiresWhitespacePrevOp = canSuggestOpAfterPrev ? false : requiresWhitespacePrev;
|
|
855
833
|
const requireWhitespaceNextOp = !canSuggestOpAfterPrev && canSuggestOpBeforeNext ? false : requiresWhitespaceNext;
|
|
856
834
|
const suggestions = [];
|
|
857
|
-
if (ast
|
|
835
|
+
if (isToken(ast) && !ast.valid) {
|
|
858
836
|
suggestions.push({
|
|
859
837
|
type: SUGGESTION_TYPE.PREFIX,
|
|
860
838
|
requires: createDefaultRequires({ group: true }),
|
|
@@ -890,8 +868,9 @@ class Parser {
|
|
|
890
868
|
case TOKEN_TYPE.SINGLEQUOTE:
|
|
891
869
|
case TOKEN_TYPE.BACKTICK:
|
|
892
870
|
{
|
|
893
|
-
const
|
|
894
|
-
const
|
|
871
|
+
const errorParent = getParent(error, parentMap);
|
|
872
|
+
const isLeft = errorParent.quote.left === error;
|
|
873
|
+
const isRight = errorParent.quote.right === error;
|
|
895
874
|
suggestions.push({
|
|
896
875
|
...errorSuggestion,
|
|
897
876
|
type,
|
|
@@ -939,8 +918,9 @@ class Parser {
|
|
|
939
918
|
});
|
|
940
919
|
break;
|
|
941
920
|
case TOKEN_TYPE.VALUE: {
|
|
942
|
-
const
|
|
943
|
-
const
|
|
921
|
+
const errorParent = getParent(error, parentMap);
|
|
922
|
+
const prefixedValue = (errorParent == null ? void 0 : errorParent.type) === AST_TYPE.VARIABLE ? (_d = (_c = getParent(error, parentMap)) == null ? void 0 : _c.prefix) == null ? void 0 : _d.value : false;
|
|
923
|
+
const isRegexValue = (errorParent == null ? void 0 : errorParent.type) === AST_TYPE.VARIABLE && (((_e = errorParent.quote) == null ? void 0 : _e.left.type) === TOKEN_TYPE.REGEX || ((_f = errorParent.quote) == null ? void 0 : _f.right.type) === TOKEN_TYPE.REGEX);
|
|
944
924
|
if (!isRegexValue) {
|
|
945
925
|
if (!prefixedValue && opts.prefixableGroups) {
|
|
946
926
|
suggestions.push({
|
|
@@ -1005,41 +985,42 @@ class Parser {
|
|
|
1005
985
|
}
|
|
1006
986
|
}
|
|
1007
987
|
}
|
|
1008
|
-
const prevVar = (
|
|
1009
|
-
const nextVar = (
|
|
1010
|
-
const prevCondition = prevVar
|
|
1011
|
-
const nextCondition = nextVar
|
|
1012
|
-
const atVar = (
|
|
1013
|
-
const atCondition = atVar
|
|
1014
|
-
const isVarPrev = !token2.whitespace.prev && ((
|
|
1015
|
-
const isVarNext = !token2.whitespace.next && ((
|
|
1016
|
-
const isVarAt = atVar
|
|
1017
|
-
const isPropertyPrev = prevCondition
|
|
1018
|
-
const isPropertyNext = nextCondition
|
|
1019
|
-
const isPropertyAt = atCondition
|
|
1020
|
-
const isPropertyOperatorPrev = prevVar
|
|
1021
|
-
const isPropertyOperatorNext = nextVar
|
|
1022
|
-
const isPropertyOperatorAt = atVar
|
|
1023
|
-
const noArrayValuesTarget = ((
|
|
988
|
+
const prevVar = getParent(token2.valid.prev, parentMap);
|
|
989
|
+
const nextVar = getParent(token2.valid.next, parentMap);
|
|
990
|
+
const prevCondition = getParent(prevVar, parentMap);
|
|
991
|
+
const nextCondition = getParent(nextVar, parentMap);
|
|
992
|
+
const atVar = getParent(token2.at, parentMap);
|
|
993
|
+
const atCondition = getParent(atVar, parentMap);
|
|
994
|
+
const isVarPrev = !token2.whitespace.prev && ((_g = token2.valid.prev) == null ? void 0 : _g.type) !== TOKEN_TYPE.REGEX && (prevVar == null ? void 0 : prevVar.type) === AST_TYPE.VARIABLE && ((prevCondition == null ? void 0 : prevCondition.type) === AST_TYPE.CONDITION && prevCondition.value === prevVar && (((_h = prevVar.quote) == null ? void 0 : _h.right) === token2.valid.prev || prevVar.value === token2.valid.prev) || (prevCondition == null ? void 0 : prevCondition.type) === AST_TYPE.ARRAY);
|
|
995
|
+
const isVarNext = !token2.whitespace.next && ((_i = token2.valid.next) == null ? void 0 : _i.type) !== TOKEN_TYPE.REGEX && (nextVar == null ? void 0 : nextVar.type) === AST_TYPE.VARIABLE && ((nextCondition == null ? void 0 : nextCondition.type) === AST_TYPE.CONDITION && nextCondition.value === nextVar && (((_j = nextVar.quote) == null ? void 0 : _j.left) === token2.valid.next || nextVar.value === token2.valid.next) || (nextCondition == null ? void 0 : nextCondition.type) === AST_TYPE.ARRAY);
|
|
996
|
+
const isVarAt = (atVar == null ? void 0 : atVar.type) === AST_TYPE.VARIABLE && (atCondition == null ? void 0 : atCondition.type) === AST_TYPE.CONDITION || (prevVar == null ? void 0 : prevVar.type) === AST_TYPE.VARIABLE && token2.valid.prev === ((_k = prevVar == null ? void 0 : prevVar.quote) == null ? void 0 : _k.left) || (nextVar == null ? void 0 : nextVar.type) === AST_TYPE.VARIABLE && token2.valid.next === ((_l = nextVar == null ? void 0 : nextVar.quote) == null ? void 0 : _l.right);
|
|
997
|
+
const isPropertyPrev = (prevCondition == null ? void 0 : prevCondition.type) === AST_TYPE.CONDITION && prevVar !== void 0 && prevVar === (prevCondition == null ? void 0 : prevCondition.property);
|
|
998
|
+
const isPropertyNext = (nextCondition == null ? void 0 : nextCondition.type) === AST_TYPE.CONDITION && nextVar !== void 0 && nextVar === (nextCondition == null ? void 0 : nextCondition.property);
|
|
999
|
+
const isPropertyAt = (atCondition == null ? void 0 : atCondition.type) === AST_TYPE.CONDITION && atVar !== void 0 && atVar === (atCondition == null ? void 0 : atCondition.property);
|
|
1000
|
+
const isPropertyOperatorPrev = (prevVar == null ? void 0 : prevVar.type) === AST_TYPE.CONDITION && token2.valid.prev === (prevVar == null ? void 0 : prevVar.propertyOperator);
|
|
1001
|
+
const isPropertyOperatorNext = (nextVar == null ? void 0 : nextVar.type) === AST_TYPE.CONDITION && token2.valid.next === (nextVar == null ? void 0 : nextVar.propertyOperator);
|
|
1002
|
+
const isPropertyOperatorAt = (atVar == null ? void 0 : atVar.type) === AST_TYPE.CONDITION && token2.at === (atVar == null ? void 0 : atVar.propertyOperator);
|
|
1003
|
+
const noArrayValuesTarget = ((_m = token2.valid.prev) == null ? void 0 : _m.type) === TOKEN_TYPE.BRACKETL && (token2.valid.next === void 0 || ((_n = token2.valid.next) == null ? void 0 : _n.type) === TOKEN_TYPE.BRACKETR);
|
|
1024
1004
|
const target = isVarPrev ? token2.valid.prev : !noArrayValuesTarget && !isPropertyPrev && !isPropertyOperatorPrev && isVarNext ? token2.valid.next : isVarAt ? token2.at : void 0;
|
|
1025
1005
|
const propertyTarget = isPropertyPrev ? token2.valid.prev : !noArrayValuesTarget && !isVarPrev && !isPropertyOperatorPrev && isPropertyNext ? token2.valid.next : isPropertyAt ? token2.at : void 0;
|
|
1026
1006
|
const propOpTarget = isPropertyOperatorPrev ? token2.valid.prev : !noArrayValuesTarget && !isVarPrev && !isPropertyPrev && isPropertyOperatorNext ? token2.valid.next : isPropertyOperatorAt ? token2.at : void 0;
|
|
1027
1007
|
if (target) {
|
|
1028
|
-
const parent = target
|
|
1029
|
-
if (parent
|
|
1008
|
+
const parent = getParent(target, parentMap);
|
|
1009
|
+
if (parent && parent.type === AST_TYPE.VARIABLE) {
|
|
1030
1010
|
const range = pos(parent);
|
|
1031
|
-
const
|
|
1011
|
+
const parentParent = getParent(parent, parentMap);
|
|
1012
|
+
const condition2 = parentParent;
|
|
1032
1013
|
const isValue = condition2.propertyOperator !== void 0 && condition2.value === parent;
|
|
1033
|
-
const maybeGroup = (
|
|
1034
|
-
const isPrefix = maybeGroup
|
|
1014
|
+
const maybeGroup = getParent(parentParent, parentMap);
|
|
1015
|
+
const isPrefix = (maybeGroup == null ? void 0 : maybeGroup.type) === AST_TYPE.GROUP && maybeGroup.prefix === condition2;
|
|
1035
1016
|
const varStart = getCursorInfo(input, ast, parent.start);
|
|
1036
1017
|
const varEnd = getCursorInfo(input, ast, parent.end);
|
|
1037
1018
|
const targetRequiresWhitespacePrev = tokenRequiresWhitespace(varStart.valid.prev, varStart.whitespace.prev, wordOps);
|
|
1038
1019
|
const targetRequiresWhitespaceNext = tokenRequiresWhitespace(varEnd.valid.next, varEnd.whitespace.next, wordOps);
|
|
1039
|
-
const prefixedValue =
|
|
1040
|
-
const isSepPrev = ((
|
|
1041
|
-
const arrayValue = (
|
|
1042
|
-
const isRegexFlag = target === ((
|
|
1020
|
+
const prefixedValue = parent.type === AST_TYPE.VARIABLE ? (_o = parent == null ? void 0 : parent.prefix) == null ? void 0 : _o.value : false;
|
|
1021
|
+
const isSepPrev = ((_p = token2.prev) == null ? void 0 : _p.type) === TOKEN_TYPE.OP_EXPANDED_SEP;
|
|
1022
|
+
const arrayValue = (parentParent == null ? void 0 : parentParent.type) === AST_TYPE.ARRAY;
|
|
1023
|
+
const isRegexFlag = target === ((_q = parent.quote) == null ? void 0 : _q.flags);
|
|
1043
1024
|
if (!isRegexFlag && !isSepPrev && !isValue && !arrayValue && !prefixedValue && opts.prefixableGroups) {
|
|
1044
1025
|
suggestions.push({
|
|
1045
1026
|
...baseSuggestion,
|
|
@@ -1088,16 +1069,17 @@ class Parser {
|
|
|
1088
1069
|
});
|
|
1089
1070
|
}
|
|
1090
1071
|
if (propOpTarget) {
|
|
1072
|
+
const propOpTargetParent = getParent(propOpTarget, parentMap);
|
|
1091
1073
|
suggestions.push({
|
|
1092
1074
|
...baseSuggestion,
|
|
1093
|
-
type:
|
|
1075
|
+
type: propOpTargetParent.sep ? SUGGESTION_TYPE.EXPANDED_PROPERTY_OPERATOR : SUGGESTION_TYPE.CUSTOM_PROPERTY_OPERATOR,
|
|
1094
1076
|
requires: createDefaultRequires(),
|
|
1095
1077
|
range: pos(propOpTarget)
|
|
1096
1078
|
});
|
|
1097
1079
|
}
|
|
1098
|
-
const canSuggestValue = token2.whitespace.next && (token2.whitespace.prev || ((
|
|
1080
|
+
const canSuggestValue = token2.whitespace.next && (token2.whitespace.prev || ((_r = token2.prev) == null ? void 0 : _r.type) === TOKEN_TYPE.BRACKETL || ((_s = token2.prev) == null ? void 0 : _s.type) === TOKEN_TYPE.PARENL) || token2.whitespace.prev && (token2.whitespace.next || ((_t = token2.next) == null ? void 0 : _t.type) === TOKEN_TYPE.BRACKETR || ((_u = token2.next) == null ? void 0 : _u.type) === TOKEN_TYPE.PARENR);
|
|
1099
1081
|
if (canSuggestValue) {
|
|
1100
|
-
const inArrayNode = [nextCondition, prevCondition, nextVar, prevVar].find((_) => _
|
|
1082
|
+
const inArrayNode = [nextCondition, prevCondition, nextVar, prevVar].find((_) => (_ == null ? void 0 : _.type) === AST_TYPE.ARRAY) !== void 0;
|
|
1101
1083
|
const opsNotNeeded = ["and", "or"].includes(opts.onMissingBooleanOperator);
|
|
1102
1084
|
if (inArrayNode || opsNotNeeded) {
|
|
1103
1085
|
suggestions.push({
|
|
@@ -1118,10 +1100,13 @@ class Parser {
|
|
|
1118
1100
|
});
|
|
1119
1101
|
}
|
|
1120
1102
|
}
|
|
1103
|
+
const tokenAtParent = getParent(token2.at, parentMap);
|
|
1104
|
+
const tokenValidPrevParent = getParent(token2.valid.prev, parentMap);
|
|
1105
|
+
const tokenValidNextParent = getParent(token2.valid.next, parentMap);
|
|
1121
1106
|
const canSuggestRegexFlags = (
|
|
1122
1107
|
// has existing flags before/after
|
|
1123
|
-
token2.at && token2.at === ((
|
|
1124
|
-
((
|
|
1108
|
+
token2.at && token2.at === ((_v = tokenAtParent == null ? void 0 : tokenAtParent.quote) == null ? void 0 : _v.flags) || token2.valid.prev && token2.valid.prev === ((_w = tokenValidPrevParent == null ? void 0 : tokenValidPrevParent.quote) == null ? void 0 : _w.flags) || token2.valid.next && token2.valid.next === ((_x = tokenValidNextParent == null ? void 0 : tokenValidNextParent.quote) == null ? void 0 : _x.flags) || // no flags
|
|
1109
|
+
((_y = token2.valid.prev) == null ? void 0 : _y.type) === TOKEN_TYPE.REGEX && token2.valid.prev === ((_z = tokenValidPrevParent.quote) == null ? void 0 : _z.right)
|
|
1125
1110
|
);
|
|
1126
1111
|
if (canSuggestRegexFlags) {
|
|
1127
1112
|
suggestions.push({
|
|
@@ -1162,12 +1147,12 @@ class Parser {
|
|
|
1162
1147
|
evaluate(ast, context) {
|
|
1163
1148
|
this._checkEvaluationOptions();
|
|
1164
1149
|
const opts = this.options;
|
|
1165
|
-
if (ast
|
|
1150
|
+
if (ast.type === AST_TYPE.NORMALIZED_CONDITION) {
|
|
1166
1151
|
const contextValue = get(context, ast.property);
|
|
1167
|
-
const res = opts.valueComparer(
|
|
1152
|
+
const res = opts.valueComparer(ast, contextValue, context);
|
|
1168
1153
|
return ast.negate ? !res : res;
|
|
1169
1154
|
}
|
|
1170
|
-
if (ast
|
|
1155
|
+
if (ast.type === AST_TYPE.NORMALIZED_EXPRESSION) {
|
|
1171
1156
|
const left = this.evaluate(ast.left, context);
|
|
1172
1157
|
const right = this.evaluate(ast.right, context);
|
|
1173
1158
|
return ast.operator === TOKEN_TYPE.AND ? left && right : left || right;
|
|
@@ -1234,10 +1219,10 @@ class Parser {
|
|
|
1234
1219
|
* Queries like `(a || b) && (a || c)` would require all the variables to be indexed `[Set(a), Set(b), Set(c)]`.
|
|
1235
1220
|
*/
|
|
1236
1221
|
getIndexes(ast) {
|
|
1237
|
-
if (ast
|
|
1222
|
+
if (ast.type === AST_TYPE.NORMALIZED_CONDITION) {
|
|
1238
1223
|
return [new Set(ast.property.join("."))];
|
|
1239
1224
|
}
|
|
1240
|
-
if (ast
|
|
1225
|
+
if (ast.type === AST_TYPE.NORMALIZED_EXPRESSION) {
|
|
1241
1226
|
const left = this.getIndexes(ast.left);
|
|
1242
1227
|
const right = this.getIndexes(ast.right);
|
|
1243
1228
|
if (ast.operator === TOKEN_TYPE.AND) {
|
|
@@ -1304,20 +1289,20 @@ class Parser {
|
|
|
1304
1289
|
* Normalizes the ast by applying {@link GroupNode GroupNodes} and converting {@link ConditionNode ConditionNodes} to {@link NormalizedConditionNode NormalizedConditionNodes}.
|
|
1305
1290
|
*/
|
|
1306
1291
|
normalize(ast) {
|
|
1307
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
|
|
1292
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s;
|
|
1308
1293
|
this._checkEvaluationOptions();
|
|
1309
1294
|
const opts = this.options;
|
|
1310
|
-
if (
|
|
1295
|
+
if (!ast.valid) {
|
|
1311
1296
|
throw new Error("AST node must be valid.");
|
|
1312
1297
|
}
|
|
1313
1298
|
const prefix = arguments[1];
|
|
1314
1299
|
const groupValue = arguments[2];
|
|
1315
1300
|
let operator2 = arguments[3];
|
|
1316
1301
|
const self_ = this;
|
|
1317
|
-
if (ast
|
|
1318
|
-
if (!(ast.value
|
|
1319
|
-
const isValue = ast.value
|
|
1320
|
-
let name = ast.property ?
|
|
1302
|
+
if (ast.type === AST_TYPE.CONDITION) {
|
|
1303
|
+
if (!(ast.value.type === AST_TYPE.GROUP)) {
|
|
1304
|
+
const isValue = ast.value.type === AST_TYPE.ARRAY || ((_b = (_a = ast.value) == null ? void 0 : _a.quote) == null ? void 0 : _b.left.type) === TOKEN_TYPE.REGEX;
|
|
1305
|
+
let name = ((_d = (_c = ast.property) == null ? void 0 : _c.value) == null ? void 0 : _d.value) ? unescape(ast.property.value.value) : isValue ? void 0 : unescape(ast.value.value.value);
|
|
1321
1306
|
const isNested = operator2 !== void 0;
|
|
1322
1307
|
if (prefix !== void 0 && !isNested) {
|
|
1323
1308
|
name = name ? applyPrefix(prefix, name, opts.prefixApplier) : prefix;
|
|
@@ -1327,16 +1312,16 @@ class Parser {
|
|
|
1327
1312
|
value = name ?? true;
|
|
1328
1313
|
name = prefix;
|
|
1329
1314
|
} else {
|
|
1330
|
-
value = ast.value
|
|
1315
|
+
value = ast.value.type === AST_TYPE.ARRAY ? ast.value.values.map((val) => unescape(val.value.value)) : ((_f = (_e = ast.value) == null ? void 0 : _e.quote) == null ? void 0 : _f.left.type) === TOKEN_TYPE.REGEX ? (_g = ast.value.value) == null ? void 0 : _g.value : ast.property && ast.value.type === AST_TYPE.VARIABLE ? unescape(ast.value.value.value) : true;
|
|
1331
1316
|
}
|
|
1332
1317
|
const propertyKeys = name ? opts.keyParser(name) : [];
|
|
1333
1318
|
const boolValue = applyBoolean(groupValue, ast.operator === void 0);
|
|
1334
|
-
const valuePrefix = ast.value
|
|
1335
|
-
operator2 ?? (operator2 = (
|
|
1336
|
-
const isRegex = ((
|
|
1337
|
-
const isQuoted = ((
|
|
1319
|
+
const valuePrefix = ast.value.type === AST_TYPE.VARIABLE && ast.value.prefix ? unescape(ast.value.prefix.value) : void 0;
|
|
1320
|
+
operator2 ?? (operator2 = (_h = ast.propertyOperator) == null ? void 0 : _h.value);
|
|
1321
|
+
const isRegex = ((_j = (_i = ast.value) == null ? void 0 : _i.quote) == null ? void 0 : _j.left.type) === TOKEN_TYPE.REGEX;
|
|
1322
|
+
const isQuoted = ((_k = ast.value) == null ? void 0 : _k.quote) !== void 0;
|
|
1338
1323
|
const isExpanded = ast.sep !== void 0;
|
|
1339
|
-
const regexFlags = (
|
|
1324
|
+
const regexFlags = (_n = (_m = (_l = ast.value) == null ? void 0 : _l.quote) == null ? void 0 : _m.flags) == null ? void 0 : _n.value;
|
|
1340
1325
|
const query = {
|
|
1341
1326
|
value,
|
|
1342
1327
|
operator: operator2,
|
|
@@ -1350,28 +1335,28 @@ class Parser {
|
|
|
1350
1335
|
condition: ast
|
|
1351
1336
|
};
|
|
1352
1337
|
const res = opts.conditionNormalizer(query);
|
|
1353
|
-
return
|
|
1338
|
+
return createCondition({ property: propertyKeys, ...res });
|
|
1354
1339
|
} else {
|
|
1355
1340
|
let name = unescape(ast.property.value.value);
|
|
1356
1341
|
if (prefix !== void 0) {
|
|
1357
1342
|
name = applyPrefix(prefix, name, opts.prefixApplier);
|
|
1358
1343
|
}
|
|
1359
1344
|
const boolValue = applyBoolean(groupValue, ast.operator === void 0);
|
|
1360
|
-
const operator22 = (
|
|
1345
|
+
const operator22 = (_o = ast.propertyOperator) == null ? void 0 : _o.value;
|
|
1361
1346
|
return self_.normalize(ast.value, name, boolValue, operator22);
|
|
1362
1347
|
}
|
|
1363
1348
|
}
|
|
1364
|
-
if (ast
|
|
1365
|
-
const _prefix = ast.prefix
|
|
1366
|
-
const _groupValue = ast.prefix
|
|
1349
|
+
if (ast.type === AST_TYPE.GROUP) {
|
|
1350
|
+
const _prefix = ((_p = ast.prefix) == null ? void 0 : _p.type) === AST_TYPE.CONDITION && ((_q = ast.prefix) == null ? void 0 : _q.value.type) === AST_TYPE.VARIABLE ? unescape(ast.prefix.value.value.value) : void 0;
|
|
1351
|
+
const _groupValue = ((_r = ast.prefix) == null ? void 0 : _r.type) === AST_TYPE.CONDITION ? ast.prefix.operator === void 0 : !(((_s = ast.prefix) == null ? void 0 : _s.valid) === true);
|
|
1367
1352
|
const applied = applyPrefix(prefix, _prefix ?? "", opts.prefixApplier);
|
|
1368
1353
|
return self_.normalize(ast.expression, applied, applyBoolean(groupValue, _groupValue), operator2);
|
|
1369
1354
|
}
|
|
1370
|
-
if (ast
|
|
1355
|
+
if (ast.type === AST_TYPE.EXPRESSION) {
|
|
1371
1356
|
const left = self_.normalize(ast.left, prefix, groupValue, operator2);
|
|
1372
1357
|
const right = self_.normalize(ast.right, prefix, groupValue, operator2);
|
|
1373
1358
|
const type = groupValue === false ? OPPOSITE[ast.operator.type] : ast.operator.type;
|
|
1374
|
-
return
|
|
1359
|
+
return createExpression({ operator: type, left, right });
|
|
1375
1360
|
}
|
|
1376
1361
|
return unreachable();
|
|
1377
1362
|
}
|
|
@@ -1382,11 +1367,11 @@ class Parser {
|
|
|
1382
1367
|
* The context does not need to be passed. If it's not passed, the function will not attempt to get the values (so it will not error) and the contextValue param of the valueValidator will be undefined.
|
|
1383
1368
|
*/
|
|
1384
1369
|
validate(ast, context) {
|
|
1385
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
1370
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
1386
1371
|
const self = this;
|
|
1387
1372
|
self._checkValidationOptions();
|
|
1388
1373
|
const opts = self.options;
|
|
1389
|
-
if (
|
|
1374
|
+
if (!ast.valid) {
|
|
1390
1375
|
throw new Error("AST node must be valid.");
|
|
1391
1376
|
}
|
|
1392
1377
|
const prefix = arguments[2];
|
|
@@ -1395,9 +1380,9 @@ class Parser {
|
|
|
1395
1380
|
const prefixes = arguments[5] ?? [];
|
|
1396
1381
|
let operator2 = arguments[6];
|
|
1397
1382
|
const self_ = this;
|
|
1398
|
-
if (ast
|
|
1399
|
-
if (!(ast.value
|
|
1400
|
-
const isValue = ast.value
|
|
1383
|
+
if (ast.type === AST_TYPE.CONDITION) {
|
|
1384
|
+
if (!(ast.value.type === AST_TYPE.GROUP)) {
|
|
1385
|
+
const isValue = ast.value.type === AST_TYPE.ARRAY || ((_b = (_a = ast.value) == null ? void 0 : _a.quote) == null ? void 0 : _b.left.type) === TOKEN_TYPE.REGEX;
|
|
1401
1386
|
const nameNode = ast.property ? ast.property : isValue ? void 0 : ast.value;
|
|
1402
1387
|
let name = nameNode ? unescape(nameNode.value.value) : void 0;
|
|
1403
1388
|
const isNested = operator2 !== void 0;
|
|
@@ -1412,12 +1397,12 @@ class Parser {
|
|
|
1412
1397
|
propertyNodes = [...prefixes];
|
|
1413
1398
|
} else {
|
|
1414
1399
|
propertyNodes = [...prefixes, ...nameNode ? [nameNode] : []];
|
|
1415
|
-
value = ast.value
|
|
1400
|
+
value = ast.value.type === AST_TYPE.ARRAY ? ast.value.values : ((_d = (_c = ast.value) == null ? void 0 : _c.quote) == null ? void 0 : _d.left.type) === TOKEN_TYPE.REGEX ? ast.value : ast.property && ast.value.type === AST_TYPE.VARIABLE ? ast.value : true;
|
|
1416
1401
|
}
|
|
1417
1402
|
const propertyKeys = name ? opts.keyParser(name) : [];
|
|
1418
1403
|
const contextValue = context !== void 0 ? get(context, propertyKeys) : void 0;
|
|
1419
1404
|
const boolValue = applyBoolean(groupValue, ast.operator === void 0);
|
|
1420
|
-
const valuePrefix = ast.value
|
|
1405
|
+
const valuePrefix = ast.value.type === AST_TYPE.VARIABLE && ast.value.prefix ? ast.value.prefix : void 0;
|
|
1421
1406
|
operator2 ?? (operator2 = ast.propertyOperator);
|
|
1422
1407
|
const isRegex = ((_f = (_e = ast.value) == null ? void 0 : _e.quote) == null ? void 0 : _f.left.type) === TOKEN_TYPE.REGEX;
|
|
1423
1408
|
const isQuoted = ((_g = ast.value) == null ? void 0 : _g.quote) !== void 0;
|
|
@@ -1457,14 +1442,14 @@ class Parser {
|
|
|
1457
1442
|
self_.validate(ast.value, context, name, boolValue, results, prefixes, operator22);
|
|
1458
1443
|
}
|
|
1459
1444
|
}
|
|
1460
|
-
if (ast
|
|
1461
|
-
const _prefix = ast.prefix
|
|
1445
|
+
if (ast.type === AST_TYPE.GROUP) {
|
|
1446
|
+
const _prefix = ((_j = ast.prefix) == null ? void 0 : _j.type) === AST_TYPE.CONDITION && ast.prefix.value.type === AST_TYPE.VARIABLE ? ast.prefix.value : void 0;
|
|
1462
1447
|
if (_prefix)
|
|
1463
1448
|
prefixes.push(_prefix);
|
|
1464
|
-
const _groupValue = ast.prefix
|
|
1449
|
+
const _groupValue = ((_k = ast.prefix) == null ? void 0 : _k.type) === AST_TYPE.CONDITION ? ast.prefix.operator === void 0 : !(((_l = ast.prefix) == null ? void 0 : _l.valid) === true);
|
|
1465
1450
|
self_.validate(ast.expression, context, applyPrefix(prefix, (_prefix == null ? void 0 : _prefix.value.value) ?? "", opts.prefixApplier), applyBoolean(groupValue, _groupValue), results, prefixes, operator2);
|
|
1466
1451
|
}
|
|
1467
|
-
if (ast
|
|
1452
|
+
if (ast.type === AST_TYPE.EXPRESSION) {
|
|
1468
1453
|
self_.validate(ast.left, context, prefix, groupValue, results, [...prefixes], operator2);
|
|
1469
1454
|
self_.validate(ast.right, context, prefix, groupValue, results, [...prefixes], operator2);
|
|
1470
1455
|
}
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import { type Position } from "../../types/ast.js";
|
|
2
|
-
import { ArrayNode } from "../classes/ArrayNode.js";
|
|
3
|
-
import type { VariableNode } from "../classes/VariableNode.js";
|
|
1
|
+
import { type ArrayNode, type Position, type VariableNode } from "../../types/ast.js";
|
|
4
2
|
export declare function array(values: VariableNode[], bracket?: {
|
|
5
3
|
left?: boolean;
|
|
6
4
|
right?: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"array.d.ts","sourceRoot":"","sources":["../../../src/ast/builders/array.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"array.d.ts","sourceRoot":"","sources":["../../../src/ast/builders/array.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,SAAS,EAAkB,KAAK,QAAQ,EAAc,KAAK,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAIjH,wBAAgB,KAAK,CACpB,MAAM,EAAE,YAAY,EAAE,EACtB,OAAO,GAAE;IAAE,IAAI,CAAC,EAAE,OAAO,CAAC;IAAC,KAAK,CAAC,EAAE,OAAO,CAAA;CAAgC,EAC1E,YAAY,CAAC,EAAE,QAAQ,EACvB,aAAa,CAAC,EAAE,QAAQ,GACtB,SAAS,CA4BX"}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { token } from "./token.js";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { TOKEN_TYPE } from "../../types/ast.js";
|
|
3
|
+
import { createArrayNode } from "../createArrayNode.js";
|
|
4
4
|
function array(values, bracket = { right: true, left: true }, parenLeftPos, parenRightPos) {
|
|
5
5
|
var _a, _b, _c, _d, _e, _f;
|
|
6
6
|
const node = {
|
|
7
|
-
type: AST_TYPE.ARRAY,
|
|
8
7
|
values
|
|
9
8
|
};
|
|
10
9
|
node.bracket = {};
|
|
@@ -23,8 +22,7 @@ function array(values, bracket = { right: true, left: true }, parenLeftPos, pare
|
|
|
23
22
|
}
|
|
24
23
|
node.start = ((_c = node.bracket.left) == null ? void 0 : _c.start) ?? start ?? ((_d = node.bracket) == null ? void 0 : _d.right.start);
|
|
25
24
|
node.end = ((_f = (_e = node.bracket) == null ? void 0 : _e.right) == null ? void 0 : _f.end) ?? end ?? node.bracket.left.end;
|
|
26
|
-
|
|
27
|
-
return instance;
|
|
25
|
+
return createArrayNode(node);
|
|
28
26
|
}
|
|
29
27
|
export {
|
|
30
28
|
array
|