Skip to content

ReWriteVisitor Generates Incorrect Syntax For "alias" and "def" #11

@esheri3

Description

@esheri3

An attempt to parse the AST and write the AST back to disk using ReWriteVisitor produces incorrect syntax for aliases and function declarations. The right-hand side of the alias expression seems to be missing and arguments for function declarations seem to be skipped. Also, a period is showing up after some identifiers.

== sample before ==

class ActionController::Base
  alias orig_params params
  def params
    if orig_params != nil && !orig_params.respond_to?("in")
      orig_params.extend(ActionController_Parameters_Mixin)
    end

    return orig_params
  end

  alias orig_redirect_to redirect_to
  def redirect_to(options={}, response_status={})
    if options.kind_of? String

    elsif options.kind_of? Hash

    else
      # give up
    end

    orig_redirect_to options, response_status
  end
end

== rewritevisitor result ==

class ActionController::Base
  alias  
  def params
    if orig_params.!=(nil) and orig_params.respond_to?("in").!
      orig_params.extend(ActionController_Parameters_Mixin)
    end
    return orig_params
  end
  alias  
  def redirect_to , 
    if options.kind_of? String
    elsif options.kind_of? Hash
    end
    orig_redirect_to(options, response_status)
  end
end

Note the "alias" statements, the arguments for defs (ex: "redirect_to") and the extra period after "orig_params" in the "def params" function.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions