Skip to content

Commit 969e526

Browse files
committed
Protect getPathFromRoot when a child appears multiple times in a collection
1 parent 82c86da commit 969e526

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
All notable changes to this project from version 1.2.0 upwards are documented in this file.
33
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
44

5+
## [1.6.18] – 2024-03-21
6+
7+
### Fixed
8+
- Protect `getPathFromRoot` when a child appears multiple times in a collection
9+
510
## [1.6.17] – 2024-03-21
611

712
### Changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"description": "AST building blocks for TypeScript/JavaScript, part of the *lasu family, with optional integrations with ANTLR4 and Ecore.",
44
"author": "Strumenta s.r.l.",
55
"publisher": "strumenta",
6-
"version": "1.6.17",
6+
"version": "1.6.18",
77
"license": "Apache-2.0",
88
"keywords": [
99
"antlr",

src/trace/trace-node.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -242,12 +242,18 @@ export class TraceNode extends Node implements PossiblyNamed {
242242
path.push(ft.name.toString());
243243
if (ft.multiple) {
244244
const children = this.parent.getChildren(ft.name);
245+
let found = false;
245246
for (let index = 0; index < children.length; index++) {
246247
const child = children[index];
247-
if (child instanceof TraceNode && child.equals(this)) {
248+
if (child.equals(this)) {
248249
path.push(index);
250+
found = true;
251+
break;
249252
}
250253
}
254+
if (!found) {
255+
throw new Error(`Child node ${this} not found in ${ft.name.toString()}`);
256+
}
251257
}
252258
return path;
253259
} else {

0 commit comments

Comments
 (0)