Skip to content

Commit

Permalink
Protect getPathFromRoot when a child appears multiple times in a co…
Browse files Browse the repository at this point in the history
…llection
  • Loading branch information
alessiostalla committed Mar 21, 2024
1 parent 82c86da commit 969e526
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
All notable changes to this project from version 1.2.0 upwards are documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [1.6.18] – 2024-03-21

### Fixed
- Protect `getPathFromRoot` when a child appears multiple times in a collection

## [1.6.17] – 2024-03-21

### Changed
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "AST building blocks for TypeScript/JavaScript, part of the *lasu family, with optional integrations with ANTLR4 and Ecore.",
"author": "Strumenta s.r.l.",
"publisher": "strumenta",
"version": "1.6.17",
"version": "1.6.18",
"license": "Apache-2.0",
"keywords": [
"antlr",
Expand Down
8 changes: 7 additions & 1 deletion src/trace/trace-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,12 +242,18 @@ export class TraceNode extends Node implements PossiblyNamed {
path.push(ft.name.toString());
if (ft.multiple) {
const children = this.parent.getChildren(ft.name);
let found = false;
for (let index = 0; index < children.length; index++) {
const child = children[index];
if (child instanceof TraceNode && child.equals(this)) {
if (child.equals(this)) {
path.push(index);
found = true;
break;
}
}
if (!found) {
throw new Error(`Child node ${this} not found in ${ft.name.toString()}`);
}
}
return path;
} else {
Expand Down

0 comments on commit 969e526

Please sign in to comment.