 class Transformer extends TransformerBase
   Program: (node) ->
     @pushStack node
-    @fixScope node, node
+    new ScopeTransformer(node, @options).run(node)
   ProgramExit: (node) ->
     @popStack()
   BlockStatementExit: (node) ->

    @warnAboutLabeledStatements node, parent
  WithStatement: (node) ->
    @syntaxError node, "'with' is not supported in CoffeeScript"
  VariableDeclarator: (node, parent, skip) ->
    @addShadowingIfNeeded(node)
    @addExplicitUndefinedInitializer node, parent, skip

  fixScope: (root, scope) ->
    prebody = []
    self = this

    @estraverse().replace root,
      enter: (node, parent) ->
        if node is root
          return node

        else if node.type is 'FunctionDeclaration'
          @skip()
          prebody.push self.buildFunctionDeclaration(node)
          { type: 'EmptyStatement' }

        else if node.type is 'FunctionExpression' and node.id?
          @skip()
          prebody.push self.buildFunctionDeclaration(node)
          { type: 'Identifier', name: node.id.name }

        else
          node

    if prebody.length
      scope.body = prebody.concat(scope.body)

    root

  ###
  # Returns a `a = -> ...` statement out of a FunctionDeclaration node.
  ###

  buildFunctionDeclaration: (node) ->
    type: 'ExpressionStatement'
    expression:
      type: 'AssignmentExpression'
      operator: '='
      left: node.id
      right:
        type: 'FunctionExpression'
        params: node.params
        body: node.body

  ###
  # Remove `{type: 'EmptyStatement'}` from the body.

    throw buildError(err, source, options.filename)

  Transformer.run(ast, options)

  {code, map} = new Builder(ast, options).get()
  {code, ast, map}

# ----------------------------------------------------------------------------

###*
# TransformerBase:
