Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 1262b52

Browse files
committed
newarraykwsplat
1 parent f35c452 commit 1262b52

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

lib/syntax_tree/compiler.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,15 @@ def visit_args(node)
311311
def visit_array(node)
312312
if (compiled = RubyVisitor.compile(node))
313313
iseq.duparray(compiled)
314+
elsif node.contents && node.contents.parts.length == 1 &&
315+
node.contents.parts.first.is_a?(BareAssocHash) &&
316+
node.contents.parts.first.assocs.length == 1 &&
317+
node.contents.parts.first.assocs.first.is_a?(AssocSplat)
318+
iseq.putspecialobject(YARV::VM_SPECIAL_OBJECT_VMCORE)
319+
iseq.newhash(0)
320+
visit(node.contents.parts.first)
321+
iseq.send(:"core#hash_merge_kwd", 2)
322+
iseq.newarraykwsplat(1)
314323
else
315324
length = 0
316325

lib/syntax_tree/yarv.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,11 @@ def newarray(length)
502502
push([:newarray, length])
503503
end
504504

505+
def newarraykwsplat(length)
506+
stack.change_by(-length + 1)
507+
push([:newarraykwsplat, length])
508+
end
509+
505510
def newhash(length)
506511
stack.change_by(-length + 1)
507512
push([:newhash, length])

test/compiler_test.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,7 @@ class CompilerTest < Minitest::Test
311311
"[1, 2, 3].min",
312312
"[foo, bar, baz].min",
313313
"[foo, bar, baz].min(1)",
314+
"[**{ x: true }][0][:x]",
314315
# Core method calls
315316
"alias foo bar",
316317
"alias :foo :bar",

0 commit comments

Comments
 (0)