Skip to content

Commit ea5e6f4

Browse files
authored
Merge pull request #225 from Shopify/emily/assoc-splat
Implement translation for `PM_ASSOC_SPLAT_NODE`
2 parents 5a41d77 + 05612c4 commit ea5e6f4

File tree

3 files changed

+74
-1
lines changed

3 files changed

+74
-1
lines changed

parser/prism/Translator.cc

+8-1
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,14 @@ std::unique_ptr<parser::Node> Translator::translate(pm_node_t *node) {
8484

8585
return make_unique<parser::Pair>(parser.translateLocation(loc), std::move(key), std::move(value));
8686
}
87+
case PM_ASSOC_SPLAT_NODE: {
88+
auto assocSplatNode = reinterpret_cast<pm_assoc_splat_node *>(node);
89+
pm_location_t *loc = &assocSplatNode->base.location;
90+
91+
auto value = translate(assocSplatNode->value);
92+
93+
return make_unique<parser::Kwsplat>(parser.translateLocation(loc), std::move(value));
94+
}
8795
case PM_BEGIN_NODE: {
8896
auto beginNode = reinterpret_cast<pm_begin_node *>(node);
8997
auto loc = &beginNode->base.location;
@@ -767,7 +775,6 @@ std::unique_ptr<parser::Node> Translator::translate(pm_node_t *node) {
767775
case PM_ALIAS_METHOD_NODE:
768776
case PM_ALTERNATION_PATTERN_NODE:
769777
case PM_ARRAY_PATTERN_NODE:
770-
case PM_ASSOC_SPLAT_NODE:
771778
case PM_BACK_REFERENCE_READ_NODE:
772779
case PM_BLOCK_LOCAL_VARIABLE_NODE:
773780
case PM_CALL_AND_WRITE_NODE:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
Begin {
2+
stmts = [
3+
Hash {
4+
kwargs = false
5+
pairs = [
6+
Kwsplat {
7+
expr = Send {
8+
receiver = NULL
9+
method = <U foo>
10+
args = [
11+
]
12+
}
13+
}
14+
]
15+
}
16+
Hash {
17+
kwargs = false
18+
pairs = [
19+
Pair {
20+
key = Symbol {
21+
val = <U a>
22+
}
23+
value = Integer {
24+
val = "1"
25+
}
26+
}
27+
Kwsplat {
28+
expr = Send {
29+
receiver = NULL
30+
method = <U foo>
31+
args = [
32+
]
33+
}
34+
}
35+
]
36+
}
37+
Hash {
38+
kwargs = false
39+
pairs = [
40+
Kwsplat {
41+
expr = Send {
42+
receiver = NULL
43+
method = <U foo>
44+
args = [
45+
]
46+
}
47+
}
48+
Pair {
49+
key = Symbol {
50+
val = <U a>
51+
}
52+
value = Integer {
53+
val = "1"
54+
}
55+
}
56+
]
57+
}
58+
]
59+
}

test/prism_regression/assoc_splat.rb

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# typed: false
2+
3+
{ **foo }
4+
5+
# with other hash keys
6+
{ a: 1, **foo }
7+
{ **foo, a: 1 }

0 commit comments

Comments
 (0)