Class: JsShuffle::Methods::ParameterRenaming
- Defined in:
- lib/jsshuffle/methods/parameter_renaming.rb
Overview
Replaces local variable names with a randomly generated new one
pass :parameter_renaming in the :use array of a Parser to use this Method.
Instance Method Summary collapse
Methods inherited from Method
#configure, #default_config, inherited, #postprocess, #preprocess
Instance Method Details
#process(ast, shuffler) ⇒ Object
8 9 10 11 12 13 14 15 |
# File 'lib/jsshuffle/methods/parameter_renaming.rb', line 8 def process( ast, shuffler ) functionNodes = ast.select { |node| node.is_a? RKelly::Nodes::FunctionDeclNode } functionNodes.each do |node| renamed_parameters = {} node.arguments.each { |arg| renamed_parameters[arg.value] = (arg.value = shuffler.random_new_name) } node.function_body.value.each { |child| child.value = renamed_parameters[child.value] if child.is_a? RKelly::Nodes::ResolveNode and renamed_parameters.has_key? child.value } end end |