     # and will be skipped when instrumenting code.
     #
     insertBefore: (csSource) ->
-        assert _.isArray @parent.node[@childAttr]
+        assert _.isArray @parent.node[@childName]
 
         compiled = compile csSource, @node
 
         # childIndex is more of a hint, since nodes can move around.
-        if @parent.node[@childAttr][@childIndex] isnt @node
-            childIndex = _.indexOf @parent.node[@childAttr], @node
+        if @parent.node[@childName][@childIndex] isnt @node
+            childIndex = _.indexOf @parent.node[@childName], @node
             if childIndex is -1 then throw new Error "Can't find node in parent"
             @childIndex = childIndex
 
-        @parent.node[@childAttr].splice(@childIndex, 0, compiled)
+        @parent.node[@childName].splice(@childIndex, 0, compiled)
 
     # Insert a chunk of code at the start of a child of this node.  E.g. if this is a Block,
     # then `insertAtStart('expressions', 'console.log "foo"'')` would add a `console.log`

# * `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

    # Note that generated nodes will have the `node.coffeeCoverage.generated` flag set,
    # and will be skipped when instrumenting code.
    #
    insertAtStart: (childName, csSource) ->
        child = @node[childName]

        if @type is 'Block' and childName is 'expressions'
            if !child
                @node[childName] = [compile(csSource, @node)]
            else
                @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[childName] = compile(csSource, @node)

        else
            throw new Error "Don't know how to insert statement into #{@type}.#{childName}: #{@type[childName]}"

    toString: ->
        answer = ''
        if @childName then answer += "#{@childName}[#{@childIndex}]:"
        answer += @type
        if @node.locationData? then answer += " (#{@node.locationData?.first_line + 1}:#{@node.locationData.first_column + 1})"

