Skip to content

Commit 72b9454

Browse files
committed
refactor: converting ruby to control block
1 parent c362dbf commit 72b9454

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

src/lib/ruby-to-blocks-converter/control.js

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -68,17 +68,6 @@ const ControlConverter = {
6868
block = this._createBlock('control_delete_this_clone', 'statement');
6969
}
7070
break;
71-
case 'when':
72-
if (args.length === 1 &&
73-
args[0].type === 'sym' && args[0].value === 'start_as_a_clone' &&
74-
rubyBlockArgs && rubyBlockArgs.length === 0) {
75-
block = this._createBlock('control_start_as_clone', 'hat');
76-
if (this._isBlock(rubyBlock)) {
77-
rubyBlock.parent = block.id;
78-
block.next = rubyBlock.id;
79-
}
80-
}
81-
break;
8271
}
8372
} else if (this._isNumberOrBlock(receiver)) {
8473
switch (name) {
@@ -132,6 +121,22 @@ const ControlConverter = {
132121
converter.setParent(rubyBlock, block);
133122
return block;
134123
});
124+
125+
// backward compatibility
126+
converter.registerCallMethodWithBlock('self', 'when', 1, 0, params => {
127+
const {args} = params;
128+
129+
if (args[0].type !== 'sym') return null;
130+
131+
switch (args[0].value) {
132+
case 'start_as_a_clone':
133+
return converter.callMethod(
134+
params.receiver, 'when_start_as_a_clone', params.args.slice(1),
135+
params.rubyBlockArgs, params.rubyBlock, params.node);
136+
}
137+
138+
return null;
139+
});
135140
}
136141
};
137142

0 commit comments

Comments
 (0)