Skip to content

Commit 1bb62de

Browse files
authored
Merge pull request #159 from smalruby/issues/134_fix_empty_ruby
fixed bug, error empty ruby to code. (refs #134)
2 parents 926139d + d3133dd commit 1bb62de

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ class RubyToBlocksConverter {
7777
try {
7878
const root = RubyParser.$parse(code);
7979
let blocks = this._process(root);
80+
if (blocks === null || blocks === Opal.nil) {
81+
return true;
82+
}
8083
if (!_.isArray(blocks)) {
8184
blocks = [blocks];
8285
}

test/unit/lib/ruby-to-blocks-converter/index.test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,15 @@ describe('RubyToBlocksConverter', () => {
2626
expect(Object.keys(converter.lists)).toHaveLength(0);
2727
});
2828

29+
test('empty', () => {
30+
expect(converter.targetCodeToBlocks(target, '')).toBeTruthy();
31+
expect(Object.keys(converter.blocks)).toHaveLength(0);
32+
expect(converter.errors).toHaveLength(0);
33+
expect(Object.keys(converter.variables)).toHaveLength(0);
34+
expect(Object.keys(converter.lists)).toHaveLength(0);
35+
});
36+
37+
2938
describe('top level blocks', () => {
3039
test('statements', () => {
3140
expected = [

0 commit comments

Comments
 (0)