     # Note that generated nodes will have the `node.coffeeCoverage.generated` flag set,
     # and will be skipped when instrumenting code.
     #
-    insertAtStart: (attr, csSource) ->
-        child = @node[attr]
+    insertAtStart: (childName, csSource) ->
+        child = @node[childName]
 
-        if @type is 'Block' and attr is 'expressions'
+        if @type is 'Block' and childName is 'expressions'
             if !child
-                @node[attr] = [compile(csSource, @node)]
+                @node[childName] = [compile(csSource, @node)]
             else
-                @node[attr].unshift compile(csSource, @node)
+                @node[childName].unshift compile(csSource, @node)
 
         else if child?.constructor?.name is 'Block'
             child.expressions.unshift compile(csSource, child)
 
         else if !child
             # This will generate a 'Block'
-            @node[attr] = compile(csSource, @node)
+            @node[childName] = compile(csSource, @node)
 
         else
-            throw new Error "Don't know how to insert statement into #{@type}.#{attr}: #{@type[attr]}"
+            throw new Error "Don't know how to insert statement into #{@type}.#{childName}: #{@type[childName]}"
 
     toString: ->
         answer = ''
-        if @childAttr then answer += "#{@childAttr}[#{@childIndex}]:"
+        if @childName then answer += "#{@childName}[#{@childIndex}]:"
         answer += @type
         if @node.locationData? then answer += " (#{@node.locationData?.first_line + 1}:#{@node.locationData.first_column + 1})"
 

# * `isStatement` - true if this node is a statement.
#
module.exports = class NodeWrapper
    constructor: (@node, @parent, @childAttr, @childIndex, @depth=0) ->
        assert @node
        @locationData = @node.locationData
        @type = @node.constructor?.name or null

        # TODO: Is this too naive?  coffee-script nodes have a `isStatement(o)` function, which
        # really only cares about `o.level`.  Should we be working out the level and calling
        # this function?
        @isStatement = @parent? and @parent.type is 'Block' and @childName is 'expressions' and @type isnt 'Comment'

    # Run `fn(node)` for each child of this node.  Child nodes will be automatically wrapped in a
    # `NodeWrapper`.
    #
    forEachChild: (fn) ->
        if @node.children?
            @node.children.forEach (childName) => @forEachChildOfType childName, fn

    # Like `forEachChild`, but only
    forEachChildOfType: (childName, fn) ->
        children = @node[childName]
        if children?
            childNodes = _.flatten [children], true

            index = 0
            while index < childNodes.length
                child = childNodes[index]
                if child.constructor.name?
                    fn new NodeWrapper(child, this, childName, index, @depth + 1)

                # Bump index up in case we inserted nodes
                # TODO: Guard against incrementing forever?
                index++ while (child != childNodes[index])
                index++

    # Returns a NodeWrapper for the given child.  This only works if the child is not an array
    # (e.g. `Block.expressions`)
    child: (name, index=null) ->
        child = @node[name]
        if !child then return null

        if !index?
            assert !_.isArray child
            return new NodeWrapper child, this, name, 0, @depth + 1
        else
            assert _.isArray child
            if !child[index] then return null
            return new NodeWrapper child[index], this, name, index, @depth + 1


    # Insert a new node before this node (only works if this node is in an array-based attribute,
    # like `Block.expressions`.)
