Skip to content

Commit 23e368b

Browse files
committed
日本語に対応
1 parent db57d04 commit 23e368b

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/lib/ruby-generator/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,9 @@ export default function (Blockly) {
450450
return null;
451451
};
452452

453+
const escapeIdentityRegexp =
454+
/[\x00-\x1f\x7f-\x9f !"#$%&'()*+,-./:;<=>?@[\\\]^`{|}~]/g; // eslint-disable-line no-control-regex
455+
453456
Blockly.Ruby.variableName = function (id, type = SCALAR_TYPE) {
454457
let currVar;
455458
let prefix;
@@ -470,7 +473,7 @@ export default function (Blockly) {
470473
}
471474
}
472475
if (currVar && currVar.type === type) {
473-
return `${prefix}${currVar.name.replace(/[^a-zA-Z0-9_]/g, '_')}`;
476+
return `${prefix}${currVar.name.replace(escapeIdentityRegexp, '_')}`;
474477
}
475478
return null;
476479
};

test/unit/lib/ruby-generator.test.jsx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,18 @@ describe('RubyGenerator', () => {
7777
id2_2: {
7878
name: 'List of Symbols.',
7979
type: LIST_TYPE
80+
},
81+
id2_3: {
82+
name: ' !"#$%&\'()*+,-./:;<=>?@[\\]^`{|}~]',
83+
type: SCALAR_TYPE
84+
},
85+
id2_4: {
86+
name: '平均(合計 / 件数)',
87+
type: SCALAR_TYPE
88+
},
89+
id2_5: {
90+
name: 'シンボル 配列。',
91+
type: LIST_TYPE
8092
}
8193
},
8294
runtime: {
@@ -138,9 +150,21 @@ describe('RubyGenerator', () => {
138150
test('escape except alphabet, number and _ to _', () => {
139151
expect(Ruby.variableName('id2_1')).toEqual('@Avg_Total___Count_');
140152
expect(Ruby.listName('id2_2')).toEqual('@List_of_Symbols_');
153+
expect(Ruby.variableName('id2_3')).toEqual('@_________________________________');
154+
141155
renderedTarget.isStage = true;
142156
expect(Ruby.variableName('id2_1')).toEqual('$Avg_Total___Count_');
143157
expect(Ruby.listName('id2_2')).toEqual('$List_of_Symbols_');
158+
expect(Ruby.variableName('id2_3')).toEqual('$_________________________________');
159+
});
160+
161+
test('do not escape multibyte character like Japanese', () => {
162+
expect(Ruby.variableName('id2_4')).toEqual('@平均_合計___件数_');
163+
expect(Ruby.listName('id2_5')).toEqual('@シンボル 配列。');
164+
165+
renderedTarget.isStage = true;
166+
expect(Ruby.variableName('id2_4')).toEqual('$平均_合計___件数_');
167+
expect(Ruby.listName('id2_5')).toEqual('$シンボル 配列。');
144168
});
145169
});
146170

0 commit comments

Comments
 (0)