summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Newton <kddnewton@gmail.com>2023-08-18 09:16:10 -0400
committerJemma Issroff <jemmaissroff@gmail.com>2023-08-21 10:43:12 -0700
commit0fd57ee01d60f75f653e72f0b8647748bd422b5d (patch)
tree06b238facd5269d5dbf043780fd8280488142093
parent524d99daaf14269e7bd1611051fffb35898e3fce (diff)
[ruby/yarp] Handle interpolated regular expressions with the o flag for locals checking
https://github.com/ruby/yarp/commit/db95191207
-rw-r--r--lib/yarp.rb2
-rw-r--r--test/yarp/fixtures/regex.txt2
-rw-r--r--test/yarp/snapshots/regex.txt27
3 files changed, 29 insertions, 2 deletions
diff --git a/lib/yarp.rb b/lib/yarp.rb
index b761d2e4a5..97b8bd9ade 100644
--- a/lib/yarp.rb
+++ b/lib/yarp.rb
@@ -481,6 +481,8 @@ module YARP
locals << []
when PostExecutionNode
locals.push([], [])
+ when InterpolatedRegularExpressionNode
+ locals << [] if node.once?
end
stack.concat(node.child_nodes.compact)
diff --git a/test/yarp/fixtures/regex.txt b/test/yarp/fixtures/regex.txt
index fe7b848b1b..1e917e7de7 100644
--- a/test/yarp/fixtures/regex.txt
+++ b/test/yarp/fixtures/regex.txt
@@ -26,3 +26,5 @@ foo /bar/
/(?#\))/ =~ "hi"
%r#pound#
+
+/aaa #{bbb}/o
diff --git a/test/yarp/snapshots/regex.txt b/test/yarp/snapshots/regex.txt
index 67d7ab0480..6ba394271a 100644
--- a/test/yarp/snapshots/regex.txt
+++ b/test/yarp/snapshots/regex.txt
@@ -1,6 +1,6 @@
-ProgramNode(0...278)(
+ProgramNode(0...293)(
[:foo],
- StatementsNode(0...278)(
+ StatementsNode(0...293)(
[CallNode(0...9)(
nil,
nil,
@@ -138,6 +138,29 @@ ProgramNode(0...278)(
(277...278),
"pound",
0
+ ),
+ InterpolatedRegularExpressionNode(280...293)(
+ (280...281),
+ [StringNode(281...285)(nil, (281...285), nil, "aaa "),
+ EmbeddedStatementsNode(285...291)(
+ (285...287),
+ StatementsNode(287...290)(
+ [CallNode(287...290)(
+ nil,
+ nil,
+ (287...290),
+ nil,
+ nil,
+ nil,
+ nil,
+ 2,
+ "bbb"
+ )]
+ ),
+ (290...291)
+ )],
+ (291...293),
+ 128
)]
)
)