Don't add anonymous locals when ISEQ binary debug is on

This commit is contained in:
Matt Valentine-House 2023-10-19 15:31:16 +01:00
parent 9d9aa63e82
commit 62e340251b

View File

@ -69,6 +69,8 @@ module Prism
# For the given source, parses with prism and returns a list of all of the # For the given source, parses with prism and returns a list of all of the
# sets of local variables that were encountered. # sets of local variables that were encountered.
def self.prism_locals(source) def self.prism_locals(source)
check_to_debug = ENV["RUBY_ISEQ_DUMP_DEBUG"] == "to_binary"
locals = [] locals = []
stack = [Prism.parse(source).value] stack = [Prism.parse(source).value]
@ -106,7 +108,7 @@ module Prism
*params.keywords.select(&:value).map(&:name) *params.keywords.select(&:value).map(&:name)
] ]
sorted << AnonymousLocal if params.keywords.any? sorted << AnonymousLocal if params.keywords.any? && !check_to_debug
# Recurse down the parameter tree to find any destructured # Recurse down the parameter tree to find any destructured
# parameters and add them after the other parameters. # parameters and add them after the other parameters.
@ -127,17 +129,17 @@ module Prism
names.map!.with_index do |name, index| names.map!.with_index do |name, index|
if name == AnonymousLocal if name == AnonymousLocal
names.length - index + 1 names.length - index + 1 unless check_to_debug
else else
name name
end end
end end
locals << names locals << names.compact
when ClassNode, ModuleNode, ProgramNode, SingletonClassNode when ClassNode, ModuleNode, ProgramNode, SingletonClassNode
locals << node.locals locals << node.locals
when ForNode when ForNode
locals << [2] locals << (check_to_debug ? [] : [2])
when PostExecutionNode when PostExecutionNode
locals.push([], []) locals.push([], [])
when InterpolatedRegularExpressionNode when InterpolatedRegularExpressionNode