Commit ebae2a19 authored by aniket-engg's avatar aniket-engg

comments

parent 2a2cc93f
......@@ -8,8 +8,10 @@ function forLoopIteratesOverDynamicArray () {
}
forLoopIteratesOverDynamicArray.prototype.visit = function (node) {
if (common.isForLoop(node) && (common.isDynamicArrayLengthAccess(node.children[1].children[1]) ||
(node.children[1].children[1].children && common.isDynamicArrayLengthAccess(node.children[1].children[1].children[0])))) {
if (common.isForLoop(node) &&
(common.isDynamicArrayLengthAccess(node.children[1].children[1]) || // condition uses dynamic array length like `i < array.length`
(node.children[1].children[1].children && common.isDynamicArrayLengthAccess(node.children[1].children[1].children[0]))) // or like `i < array.length (operator like -,+,*,/) number` e.g; i < array.length -1
) {
this.relevantNodes.push(node)
}
}
......
......@@ -523,7 +523,10 @@ function isDynamicArrayAccess (node) {
* @return {bool}
*/
function isDynamicArrayLengthAccess (node) {
return node && nodeType(node, exactMatch(nodeTypes.MEMBERACCESS)) && (node.attributes.member_name === 'length') && node.children[0].attributes.type.indexOf('[]') !== -1
return node && // if node exists
nodeType(node, exactMatch(nodeTypes.MEMBERACCESS)) && // is memberAccess Node
(node.attributes.member_name === 'length') && // accessing 'length' member
node.children[0].attributes.type.indexOf('[]') !== -1 // member is accessed from array
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment