Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ab10c28

Browse files
committed
change the default sorting order for print children to be location based
1 parent 74243d3 commit ab10c28

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

javascript/ql/src/semmle/javascript/PrintAst.qll

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,18 @@ private module PrintJavaScript {
200200
* Gets the `i`th child of `element`.
201201
* Can be overriden in subclasses to get more specific behavior for `getChild()`.
202202
*/
203-
ASTNode getChildNode(int childIndex) { result = element.getChild(childIndex) }
203+
ASTNode getChildNode(int childIndex) { result = getLocationSortedChild(element, childIndex) }
204+
}
205+
206+
private ASTNode getLocationSortedChild(ASTNode parent, int i) {
207+
result =
208+
rank[i](ASTNode child, int childIndex |
209+
child = parent.getChild(childIndex)
210+
|
211+
child
212+
order by
213+
child.getLocation().getStartLine(), child.getLocation().getStartColumn(), childIndex
214+
)
204215
}
205216

206217
/**

0 commit comments

Comments
 (0)