clarity-pattern-parser 11.1.0 → 11.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.browser.js +6 -4
- package/dist/index.browser.js.map +1 -1
- package/dist/index.esm.js +6 -4
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +6 -4
- package/dist/index.js.map +1 -1
- package/dist/patterns/Expression.d.ts +1 -0
- package/package.json +1 -1
- package/src/grammar/Grammar.test.ts +14 -0
- package/src/grammar/patterns/decoratorStatement.ts +3 -3
- package/src/patterns/Expression.test.ts +8 -0
- package/src/patterns/Expression.ts +4 -1
package/package.json
CHANGED
|
@@ -682,4 +682,18 @@ describe("Grammar", () => {
|
|
|
682
682
|
expect(allRecordedPatterns).toEqual(["spaces", "digits"]);
|
|
683
683
|
});
|
|
684
684
|
|
|
685
|
+
test("Decorator With Empty Object Literal", () => {
|
|
686
|
+
patterns`
|
|
687
|
+
@method({})
|
|
688
|
+
spaces = /\\s+/
|
|
689
|
+
`;
|
|
690
|
+
});
|
|
691
|
+
|
|
692
|
+
test("Decorator With Object Literal", () => {
|
|
693
|
+
patterns`
|
|
694
|
+
@method({"prop": 2})
|
|
695
|
+
spaces = /\\s+/
|
|
696
|
+
`;
|
|
697
|
+
});
|
|
698
|
+
|
|
685
699
|
});
|
|
@@ -17,13 +17,13 @@ const closeSquareBracket = new Literal("close-square-bracket", "]");
|
|
|
17
17
|
const optionalAllSpaces = new Optional("optional-all-spaces", allSpaces);
|
|
18
18
|
|
|
19
19
|
const stringLiteral = new Regex("string-literal", '"(?:\\\\.|[^"\\\\])*"');
|
|
20
|
-
const numberLiteral = new Regex("number-literal", '[+-]?\\d+(
|
|
20
|
+
const numberLiteral = new Regex("number-literal", '[+-]?\\d+(\\.\\d+)?([eE][+-]?\\d+)?');
|
|
21
21
|
const nullLiteral = new Literal("null-literal", "null");
|
|
22
22
|
const trueLiteral = new Literal("true-literal", "true");
|
|
23
23
|
const falseLiteral = new Literal("false-literal", "false");
|
|
24
24
|
const booleanLiteral = new Options("", [trueLiteral, falseLiteral]);
|
|
25
25
|
|
|
26
|
-
const objectKey =
|
|
26
|
+
const objectKey = stringLiteral.clone("object-key");
|
|
27
27
|
const objectProperty = new Sequence("object-property", [
|
|
28
28
|
objectKey,
|
|
29
29
|
optionalAllSpaces,
|
|
@@ -44,7 +44,7 @@ const arrayItems = new Repeat("array-items", new Reference("literal"), { divider
|
|
|
44
44
|
const arrayLiteral = new Sequence("array-literal", [
|
|
45
45
|
openSquareBracket,
|
|
46
46
|
optionalAllSpaces,
|
|
47
|
-
arrayItems,
|
|
47
|
+
new Optional("optional-array-items", arrayItems),
|
|
48
48
|
optionalAllSpaces,
|
|
49
49
|
closeSquareBracket,
|
|
50
50
|
]);
|
|
@@ -166,4 +166,12 @@ describe("Expression Pattern", () => {
|
|
|
166
166
|
const suggestion = autoComplete.suggestFor("a ? b ");
|
|
167
167
|
expect(suggestion).toBe(suggestion);
|
|
168
168
|
});
|
|
169
|
+
|
|
170
|
+
test("Clone With New Name", ()=>{
|
|
171
|
+
const expression = createTailExpression();
|
|
172
|
+
const clone = expression.clone("new-expression");
|
|
173
|
+
|
|
174
|
+
const result = clone.exec("a.b");
|
|
175
|
+
expect(result).toBe(result);
|
|
176
|
+
});
|
|
169
177
|
});
|
|
@@ -15,6 +15,7 @@ export class Expression implements Pattern {
|
|
|
15
15
|
private _id: string;
|
|
16
16
|
private _type: string;
|
|
17
17
|
private _name: string;
|
|
18
|
+
private _originalName: string;
|
|
18
19
|
private _parent: Pattern | null;
|
|
19
20
|
private _firstIndex: number;
|
|
20
21
|
private _originalPatterns: Pattern[];
|
|
@@ -88,6 +89,7 @@ export class Expression implements Pattern {
|
|
|
88
89
|
this._id = `expression-${indexId++}`;
|
|
89
90
|
this._type = "expression";
|
|
90
91
|
this._name = name;
|
|
92
|
+
this._originalName = name;
|
|
91
93
|
this._parent = null;
|
|
92
94
|
this._firstIndex = 0;
|
|
93
95
|
this._atomPatterns = [];
|
|
@@ -253,7 +255,7 @@ export class Expression implements Pattern {
|
|
|
253
255
|
if (pattern == null) {
|
|
254
256
|
return false;
|
|
255
257
|
}
|
|
256
|
-
return pattern.name === this.
|
|
258
|
+
return pattern.name === this._originalName;
|
|
257
259
|
}
|
|
258
260
|
|
|
259
261
|
build() {
|
|
@@ -550,6 +552,7 @@ export class Expression implements Pattern {
|
|
|
550
552
|
|
|
551
553
|
clone(name = this._name): Pattern {
|
|
552
554
|
const clone = new Expression(name, this._originalPatterns);
|
|
555
|
+
clone._originalName = this.name;
|
|
553
556
|
clone._id = this._id;
|
|
554
557
|
return clone;
|
|
555
558
|
}
|