clarity-pattern-parser 10.2.12 → 10.2.13
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 +7 -1
- package/dist/index.browser.js.map +1 -1
- package/dist/index.esm.js +7 -1
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +7 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/ast/Node.test.ts +20 -2
- package/src/ast/Node.ts +7 -1
package/package.json
CHANGED
package/src/ast/Node.test.ts
CHANGED
|
@@ -392,6 +392,26 @@ describe("Node", () => {
|
|
|
392
392
|
expect(parent.endIndex).toBe(11);
|
|
393
393
|
});
|
|
394
394
|
|
|
395
|
+
test("Normalize values and index deep", () => {
|
|
396
|
+
const firstChild = new Node("literal", "first", 0, 0, [], "first");
|
|
397
|
+
const secondChild = new Node("literal", "second", 0, 0, [], "second");
|
|
398
|
+
const grandChild = new Node("literal", "three", 0, 0, [], "three");
|
|
399
|
+
const parent = new Node("literal", "parent", 0, 0);
|
|
400
|
+
|
|
401
|
+
parent.appendChild(firstChild);
|
|
402
|
+
parent.appendChild(secondChild);
|
|
403
|
+
|
|
404
|
+
parent.normalize();
|
|
405
|
+
|
|
406
|
+
secondChild.appendChild(grandChild);
|
|
407
|
+
parent.normalize();
|
|
408
|
+
|
|
409
|
+
expect(parent.startIndex).toBe(0);
|
|
410
|
+
expect(parent.firstIndex).toBe(0);
|
|
411
|
+
expect(parent.lastIndex).toBe(9);
|
|
412
|
+
expect(parent.endIndex).toBe(10);
|
|
413
|
+
});
|
|
414
|
+
|
|
395
415
|
test("Normalize values with no values", () => {
|
|
396
416
|
const node = new Node("literal", "node", 0, 0, [], "");
|
|
397
417
|
node.normalize();
|
|
@@ -451,8 +471,6 @@ describe("Node", () => {
|
|
|
451
471
|
Node.createValueNode("aunt", "aunt")
|
|
452
472
|
]);
|
|
453
473
|
|
|
454
|
-
|
|
455
|
-
|
|
456
474
|
expect(result.toJson()).toBe(expected.toJson());
|
|
457
475
|
});
|
|
458
476
|
|
package/src/ast/Node.ts
CHANGED
|
@@ -291,11 +291,17 @@ export class Node {
|
|
|
291
291
|
|
|
292
292
|
normalize(startIndex = this._firstIndex): number {
|
|
293
293
|
let length = 0;
|
|
294
|
+
let runningOffset = startIndex;
|
|
294
295
|
|
|
295
296
|
if (this.children.length === 0) {
|
|
296
297
|
length = this._value.length;
|
|
297
298
|
} else {
|
|
298
|
-
|
|
299
|
+
for (let x = 0; x < this.children.length; x++) {
|
|
300
|
+
const child = this.children[x];
|
|
301
|
+
const childLength = child.normalize(runningOffset);
|
|
302
|
+
runningOffset += childLength;
|
|
303
|
+
length += childLength;
|
|
304
|
+
}
|
|
299
305
|
}
|
|
300
306
|
|
|
301
307
|
this._firstIndex = startIndex;
|