Commit 933bb515 authored by neil.fraser@gmail.com's avatar neil.fraser@gmail.com

Stringify property names so they survive compilation.

git-svn-id: http://blockly.googlecode.com/svn/trunk@1711 c400ca83-b69d-9dd7-9705-49c6b8615e23
parent 0906f0f7
......@@ -288,12 +288,12 @@ Blockly.Blocks['logic_compare'] = {
this.setTooltip(function() {
var op = thisBlock.getFieldValue('OP');
var TOOLTIPS = {
EQ: Blockly.Msg.LOGIC_COMPARE_TOOLTIP_EQ,
NEQ: Blockly.Msg.LOGIC_COMPARE_TOOLTIP_NEQ,
LT: Blockly.Msg.LOGIC_COMPARE_TOOLTIP_LT,
LTE: Blockly.Msg.LOGIC_COMPARE_TOOLTIP_LTE,
GT: Blockly.Msg.LOGIC_COMPARE_TOOLTIP_GT,
GTE: Blockly.Msg.LOGIC_COMPARE_TOOLTIP_GTE
'EQ': Blockly.Msg.LOGIC_COMPARE_TOOLTIP_EQ,
'NEQ': Blockly.Msg.LOGIC_COMPARE_TOOLTIP_NEQ,
'LT': Blockly.Msg.LOGIC_COMPARE_TOOLTIP_LT,
'LTE': Blockly.Msg.LOGIC_COMPARE_TOOLTIP_LTE,
'GT': Blockly.Msg.LOGIC_COMPARE_TOOLTIP_GT,
'GTE': Blockly.Msg.LOGIC_COMPARE_TOOLTIP_GTE
};
return TOOLTIPS[op];
});
......@@ -323,8 +323,8 @@ Blockly.Blocks['logic_operation'] = {
this.setTooltip(function() {
var op = thisBlock.getFieldValue('OP');
var TOOLTIPS = {
AND: Blockly.Msg.LOGIC_OPERATION_TOOLTIP_AND,
OR: Blockly.Msg.LOGIC_OPERATION_TOOLTIP_OR
'AND': Blockly.Msg.LOGIC_OPERATION_TOOLTIP_AND,
'OR': Blockly.Msg.LOGIC_OPERATION_TOOLTIP_OR
};
return TOOLTIPS[op];
});
......
......@@ -93,8 +93,8 @@ Blockly.Blocks['controls_whileUntil'] = {
this.setTooltip(function() {
var op = thisBlock.getFieldValue('MODE');
var TOOLTIPS = {
WHILE: Blockly.Msg.CONTROLS_WHILEUNTIL_TOOLTIP_WHILE,
UNTIL: Blockly.Msg.CONTROLS_WHILEUNTIL_TOOLTIP_UNTIL
'WHILE': Blockly.Msg.CONTROLS_WHILEUNTIL_TOOLTIP_WHILE,
'UNTIL': Blockly.Msg.CONTROLS_WHILEUNTIL_TOOLTIP_UNTIL
};
return TOOLTIPS[op];
});
......@@ -238,8 +238,8 @@ Blockly.Blocks['controls_flow_statements'] = {
this.setTooltip(function() {
var op = thisBlock.getFieldValue('FLOW');
var TOOLTIPS = {
BREAK: Blockly.Msg.CONTROLS_FLOW_STATEMENTS_TOOLTIP_BREAK,
CONTINUE: Blockly.Msg.CONTROLS_FLOW_STATEMENTS_TOOLTIP_CONTINUE
'BREAK': Blockly.Msg.CONTROLS_FLOW_STATEMENTS_TOOLTIP_BREAK,
'CONTINUE': Blockly.Msg.CONTROLS_FLOW_STATEMENTS_TOOLTIP_CONTINUE
};
return TOOLTIPS[op];
});
......
......@@ -71,11 +71,11 @@ Blockly.Blocks['math_arithmetic'] = {
this.setTooltip(function() {
var mode = thisBlock.getFieldValue('OP');
var TOOLTIPS = {
ADD: Blockly.Msg.MATH_ARITHMETIC_TOOLTIP_ADD,
MINUS: Blockly.Msg.MATH_ARITHMETIC_TOOLTIP_MINUS,
MULTIPLY: Blockly.Msg.MATH_ARITHMETIC_TOOLTIP_MULTIPLY,
DIVIDE: Blockly.Msg.MATH_ARITHMETIC_TOOLTIP_DIVIDE,
POWER: Blockly.Msg.MATH_ARITHMETIC_TOOLTIP_POWER
'ADD': Blockly.Msg.MATH_ARITHMETIC_TOOLTIP_ADD,
'MINUS': Blockly.Msg.MATH_ARITHMETIC_TOOLTIP_MINUS,
'MULTIPLY': Blockly.Msg.MATH_ARITHMETIC_TOOLTIP_MULTIPLY,
'DIVIDE': Blockly.Msg.MATH_ARITHMETIC_TOOLTIP_DIVIDE,
'POWER': Blockly.Msg.MATH_ARITHMETIC_TOOLTIP_POWER
};
return TOOLTIPS[mode];
});
......@@ -108,13 +108,13 @@ Blockly.Blocks['math_single'] = {
this.setTooltip(function() {
var mode = thisBlock.getFieldValue('OP');
var TOOLTIPS = {
ROOT: Blockly.Msg.MATH_SINGLE_TOOLTIP_ROOT,
ABS: Blockly.Msg.MATH_SINGLE_TOOLTIP_ABS,
NEG: Blockly.Msg.MATH_SINGLE_TOOLTIP_NEG,
LN: Blockly.Msg.MATH_SINGLE_TOOLTIP_LN,
LOG10: Blockly.Msg.MATH_SINGLE_TOOLTIP_LOG10,
EXP: Blockly.Msg.MATH_SINGLE_TOOLTIP_EXP,
POW10: Blockly.Msg.MATH_SINGLE_TOOLTIP_POW10
'ROOT': Blockly.Msg.MATH_SINGLE_TOOLTIP_ROOT,
'ABS': Blockly.Msg.MATH_SINGLE_TOOLTIP_ABS,
'NEG': Blockly.Msg.MATH_SINGLE_TOOLTIP_NEG,
'LN': Blockly.Msg.MATH_SINGLE_TOOLTIP_LN,
'LOG10': Blockly.Msg.MATH_SINGLE_TOOLTIP_LOG10,
'EXP': Blockly.Msg.MATH_SINGLE_TOOLTIP_EXP,
'POW10': Blockly.Msg.MATH_SINGLE_TOOLTIP_POW10
};
return TOOLTIPS[mode];
});
......@@ -145,12 +145,12 @@ Blockly.Blocks['math_trig'] = {
this.setTooltip(function() {
var mode = thisBlock.getFieldValue('OP');
var TOOLTIPS = {
SIN: Blockly.Msg.MATH_TRIG_TOOLTIP_SIN,
COS: Blockly.Msg.MATH_TRIG_TOOLTIP_COS,
TAN: Blockly.Msg.MATH_TRIG_TOOLTIP_TAN,
ASIN: Blockly.Msg.MATH_TRIG_TOOLTIP_ASIN,
ACOS: Blockly.Msg.MATH_TRIG_TOOLTIP_ACOS,
ATAN: Blockly.Msg.MATH_TRIG_TOOLTIP_ATAN
'SIN': Blockly.Msg.MATH_TRIG_TOOLTIP_SIN,
'COS': Blockly.Msg.MATH_TRIG_TOOLTIP_COS,
'TAN': Blockly.Msg.MATH_TRIG_TOOLTIP_TAN,
'ASIN': Blockly.Msg.MATH_TRIG_TOOLTIP_ASIN,
'ACOS': Blockly.Msg.MATH_TRIG_TOOLTIP_ACOS,
'ATAN': Blockly.Msg.MATH_TRIG_TOOLTIP_ATAN
};
return TOOLTIPS[mode];
});
......@@ -347,14 +347,14 @@ Blockly.Blocks['math_on_list'] = {
this.setTooltip(function() {
var mode = thisBlock.getFieldValue('OP');
var TOOLTIPS = {
SUM: Blockly.Msg.MATH_ONLIST_TOOLTIP_SUM,
MIN: Blockly.Msg.MATH_ONLIST_TOOLTIP_MIN,
MAX: Blockly.Msg.MATH_ONLIST_TOOLTIP_MAX,
AVERAGE: Blockly.Msg.MATH_ONLIST_TOOLTIP_AVERAGE,
MEDIAN: Blockly.Msg.MATH_ONLIST_TOOLTIP_MEDIAN,
MODE: Blockly.Msg.MATH_ONLIST_TOOLTIP_MODE,
STD_DEV: Blockly.Msg.MATH_ONLIST_TOOLTIP_STD_DEV,
RANDOM: Blockly.Msg.MATH_ONLIST_TOOLTIP_RANDOM
'SUM': Blockly.Msg.MATH_ONLIST_TOOLTIP_SUM,
'MIN': Blockly.Msg.MATH_ONLIST_TOOLTIP_MIN,
'MAX': Blockly.Msg.MATH_ONLIST_TOOLTIP_MAX,
'AVERAGE': Blockly.Msg.MATH_ONLIST_TOOLTIP_AVERAGE,
'MEDIAN': Blockly.Msg.MATH_ONLIST_TOOLTIP_MEDIAN,
'MODE': Blockly.Msg.MATH_ONLIST_TOOLTIP_MODE,
'STD_DEV': Blockly.Msg.MATH_ONLIST_TOOLTIP_STD_DEV,
'RANDOM': Blockly.Msg.MATH_ONLIST_TOOLTIP_RANDOM
};
return TOOLTIPS[mode];
});
......
......@@ -52,12 +52,12 @@ Blockly.Dart['controls_if'] = function(block) {
Blockly.Dart['logic_compare'] = function(block) {
// Comparison operator.
var OPERATORS = {
EQ: '==',
NEQ: '!=',
LT: '<',
LTE: '<=',
GT: '>',
GTE: '>='
'EQ': '==',
'NEQ': '!=',
'LT': '<',
'LTE': '<=',
'GT': '>',
'GTE': '>='
};
var operator = OPERATORS[block.getFieldValue('OP')];
var order = (operator == '==' || operator == '!=') ?
......
......@@ -44,11 +44,11 @@ Blockly.Dart['math_number'] = function(block) {
Blockly.Dart['math_arithmetic'] = function(block) {
// Basic arithmetic operators, and power.
var OPERATORS = {
ADD: [' + ', Blockly.Dart.ORDER_ADDITIVE],
MINUS: [' - ', Blockly.Dart.ORDER_ADDITIVE],
MULTIPLY: [' * ', Blockly.Dart.ORDER_MULTIPLICATIVE],
DIVIDE: [' / ', Blockly.Dart.ORDER_MULTIPLICATIVE],
POWER: [null, Blockly.Dart.ORDER_NONE] // Handle power separately.
'ADD': [' + ', Blockly.Dart.ORDER_ADDITIVE],
'MINUS': [' - ', Blockly.Dart.ORDER_ADDITIVE],
'MULTIPLY': [' * ', Blockly.Dart.ORDER_MULTIPLICATIVE],
'DIVIDE': [' / ', Blockly.Dart.ORDER_MULTIPLICATIVE],
'POWER': [null, Blockly.Dart.ORDER_NONE] // Handle power separately.
};
var tuple = OPERATORS[block.getFieldValue('OP')];
var operator = tuple[0];
......@@ -159,12 +159,12 @@ Blockly.Dart['math_single'] = function(block) {
Blockly.Dart['math_constant'] = function(block) {
// Constants: PI, E, the Golden Ratio, sqrt(2), 1/sqrt(2), INFINITY.
var CONSTANTS = {
PI: ['Math.PI', Blockly.Dart.ORDER_UNARY_POSTFIX],
E: ['Math.E', Blockly.Dart.ORDER_UNARY_POSTFIX],
GOLDEN_RATIO: ['(1 + Math.sqrt(5)) / 2', Blockly.Dart.ORDER_MULTIPLICATIVE],
SQRT2: ['Math.SQRT2', Blockly.Dart.ORDER_UNARY_POSTFIX],
SQRT1_2: ['Math.SQRT1_2', Blockly.Dart.ORDER_UNARY_POSTFIX],
INFINITY: ['double.INFINITY', Blockly.Dart.ORDER_ATOMIC]
'PI': ['Math.PI', Blockly.Dart.ORDER_UNARY_POSTFIX],
'E': ['Math.E', Blockly.Dart.ORDER_UNARY_POSTFIX],
'GOLDEN_RATIO': ['(1 + Math.sqrt(5)) / 2', Blockly.Dart.ORDER_MULTIPLICATIVE],
'SQRT2': ['Math.SQRT2', Blockly.Dart.ORDER_UNARY_POSTFIX],
'SQRT1_2': ['Math.SQRT1_2', Blockly.Dart.ORDER_UNARY_POSTFIX],
'INFINITY': ['double.INFINITY', Blockly.Dart.ORDER_ATOMIC]
};
var constant = block.getFieldValue('CONSTANT');
if (constant != 'INFINITY') {
......
......@@ -188,9 +188,9 @@ Blockly.Dart['text_getSubstring'] = function(block) {
Blockly.Dart['text_changeCase'] = function(block) {
// Change capitalization.
var OPERATORS = {
UPPERCASE: '.toUpperCase()',
LOWERCASE: '.toLowerCase()',
TITLECASE: null
'UPPERCASE': '.toUpperCase()',
'LOWERCASE': '.toLowerCase()',
'TITLECASE': null
};
var operator = OPERATORS[block.getFieldValue('CASE')];
var code;
......@@ -228,9 +228,9 @@ Blockly.Dart['text_changeCase'] = function(block) {
Blockly.Dart['text_trim'] = function(block) {
// Trim spaces.
var OPERATORS = {
LEFT: '.replaceFirst(new RegExp(r\'^\\s+\'), \'\')',
RIGHT: '.replaceFirst(new RegExp(r\'\\s+$\'), \'\')',
BOTH: '.trim()'
'LEFT': '.replaceFirst(new RegExp(r\'^\\s+\'), \'\')',
'RIGHT': '.replaceFirst(new RegExp(r\'\\s+$\'), \'\')',
'BOTH': '.trim()'
};
var operator = OPERATORS[block.getFieldValue('MODE')];
var argument0 = Blockly.Dart.valueToCode(block, 'TEXT',
......
......@@ -52,12 +52,12 @@ Blockly.JavaScript['controls_if'] = function(block) {
Blockly.JavaScript['logic_compare'] = function(block) {
// Comparison operator.
var OPERATORS = {
EQ: '==',
NEQ: '!=',
LT: '<',
LTE: '<=',
GT: '>',
GTE: '>='
'EQ': '==',
'NEQ': '!=',
'LT': '<',
'LTE': '<=',
'GT': '>',
'GTE': '>='
};
var operator = OPERATORS[block.getFieldValue('OP')];
var order = (operator == '==' || operator == '!=') ?
......
......@@ -38,11 +38,11 @@ Blockly.JavaScript['math_number'] = function(block) {
Blockly.JavaScript['math_arithmetic'] = function(block) {
// Basic arithmetic operators, and power.
var OPERATORS = {
ADD: [' + ', Blockly.JavaScript.ORDER_ADDITION],
MINUS: [' - ', Blockly.JavaScript.ORDER_SUBTRACTION],
MULTIPLY: [' * ', Blockly.JavaScript.ORDER_MULTIPLICATION],
DIVIDE: [' / ', Blockly.JavaScript.ORDER_DIVISION],
POWER: [null, Blockly.JavaScript.ORDER_COMMA] // Handle power separately.
'ADD': [' + ', Blockly.JavaScript.ORDER_ADDITION],
'MINUS': [' - ', Blockly.JavaScript.ORDER_SUBTRACTION],
'MULTIPLY': [' * ', Blockly.JavaScript.ORDER_MULTIPLICATION],
'DIVIDE': [' / ', Blockly.JavaScript.ORDER_DIVISION],
'POWER': [null, Blockly.JavaScript.ORDER_COMMA] // Handle power separately.
};
var tuple = OPERATORS[block.getFieldValue('OP')];
var operator = tuple[0];
......@@ -146,12 +146,12 @@ Blockly.JavaScript['math_single'] = function(block) {
Blockly.JavaScript['math_constant'] = function(block) {
// Constants: PI, E, the Golden Ratio, sqrt(2), 1/sqrt(2), INFINITY.
var CONSTANTS = {
PI: ['Math.PI', Blockly.JavaScript.ORDER_MEMBER],
E: ['Math.E', Blockly.JavaScript.ORDER_MEMBER],
GOLDEN_RATIO: ['(1 + Math.sqrt(5)) / 2', Blockly.JavaScript.ORDER_DIVISION],
SQRT2: ['Math.SQRT2', Blockly.JavaScript.ORDER_MEMBER],
SQRT1_2: ['Math.SQRT1_2', Blockly.JavaScript.ORDER_MEMBER],
INFINITY: ['Infinity', Blockly.JavaScript.ORDER_ATOMIC]
'PI': ['Math.PI', Blockly.JavaScript.ORDER_MEMBER],
'E': ['Math.E', Blockly.JavaScript.ORDER_MEMBER],
'GOLDEN_RATIO': ['(1 + Math.sqrt(5)) / 2', Blockly.JavaScript.ORDER_DIVISION],
'SQRT2': ['Math.SQRT2', Blockly.JavaScript.ORDER_MEMBER],
'SQRT1_2': ['Math.SQRT1_2', Blockly.JavaScript.ORDER_MEMBER],
'INFINITY': ['Infinity', Blockly.JavaScript.ORDER_ATOMIC]
};
return CONSTANTS[block.getFieldValue('CONSTANT')];
};
......
......@@ -185,9 +185,9 @@ Blockly.JavaScript['text_getSubstring'] = function(block) {
Blockly.JavaScript['text_changeCase'] = function(block) {
// Change capitalization.
var OPERATORS = {
UPPERCASE: '.toUpperCase()',
LOWERCASE: '.toLowerCase()',
TITLECASE: null
'UPPERCASE': '.toUpperCase()',
'LOWERCASE': '.toLowerCase()',
'TITLECASE': null
};
var operator = OPERATORS[block.getFieldValue('CASE')];
var code;
......@@ -215,9 +215,9 @@ Blockly.JavaScript['text_changeCase'] = function(block) {
Blockly.JavaScript['text_trim'] = function(block) {
// Trim spaces.
var OPERATORS = {
LEFT: '.trimLeft()',
RIGHT: '.trimRight()',
BOTH: '.trim()'
'LEFT': '.trimLeft()',
'RIGHT': '.trimRight()',
'BOTH': '.trim()'
};
var operator = OPERATORS[block.getFieldValue('MODE')];
var argument0 = Blockly.JavaScript.valueToCode(block, 'TEXT',
......
......@@ -52,12 +52,12 @@ Blockly.Python['controls_if'] = function(block) {
Blockly.Python['logic_compare'] = function(block) {
// Comparison operator.
var OPERATORS = {
EQ: '==',
NEQ: '!=',
LT: '<',
LTE: '<=',
GT: '>',
GTE: '>='
'EQ': '==',
'NEQ': '!=',
'LT': '<',
'LTE': '<=',
'GT': '>',
'GTE': '>='
};
var operator = OPERATORS[block.getFieldValue('OP')];
var order = Blockly.Python.ORDER_RELATIONAL;
......
......@@ -43,11 +43,11 @@ Blockly.Python['math_number'] = function(block) {
Blockly.Python['math_arithmetic'] = function(block) {
// Basic arithmetic operators, and power.
var OPERATORS = {
ADD: [' + ', Blockly.Python.ORDER_ADDITIVE],
MINUS: [' - ', Blockly.Python.ORDER_ADDITIVE],
MULTIPLY: [' * ', Blockly.Python.ORDER_MULTIPLICATIVE],
DIVIDE: [' / ', Blockly.Python.ORDER_MULTIPLICATIVE],
POWER: [' ** ', Blockly.Python.ORDER_EXPONENTIATION]
'ADD': [' + ', Blockly.Python.ORDER_ADDITIVE],
'MINUS': [' - ', Blockly.Python.ORDER_ADDITIVE],
'MULTIPLY': [' * ', Blockly.Python.ORDER_MULTIPLICATIVE],
'DIVIDE': [' / ', Blockly.Python.ORDER_MULTIPLICATIVE],
'POWER': [' ** ', Blockly.Python.ORDER_EXPONENTIATION]
};
var tuple = OPERATORS[block.getFieldValue('OP')];
var operator = tuple[0];
......@@ -147,12 +147,12 @@ Blockly.Python['math_single'] = function(block) {
Blockly.Python['math_constant'] = function(block) {
// Constants: PI, E, the Golden Ratio, sqrt(2), 1/sqrt(2), INFINITY.
var CONSTANTS = {
PI: ['math.pi', Blockly.Python.ORDER_MEMBER],
E: ['math.e', Blockly.Python.ORDER_MEMBER],
GOLDEN_RATIO: ['(1 + math.sqrt(5)) / 2', Blockly.Python.ORDER_MULTIPLICATIVE],
SQRT2: ['math.sqrt(2)', Blockly.Python.ORDER_MEMBER],
SQRT1_2: ['math.sqrt(1.0 / 2)', Blockly.Python.ORDER_MEMBER],
INFINITY: ['float(\'inf\')', Blockly.Python.ORDER_ATOMIC]
'PI': ['math.pi', Blockly.Python.ORDER_MEMBER],
'E': ['math.e', Blockly.Python.ORDER_MEMBER],
'GOLDEN_RATIO': ['(1 + math.sqrt(5)) / 2', Blockly.Python.ORDER_MULTIPLICATIVE],
'SQRT2': ['math.sqrt(2)', Blockly.Python.ORDER_MEMBER],
'SQRT1_2': ['math.sqrt(1.0 / 2)', Blockly.Python.ORDER_MEMBER],
'INFINITY': ['float(\'inf\')', Blockly.Python.ORDER_ATOMIC]
};
var constant = block.getFieldValue('CONSTANT');
if (constant != 'INFINITY') {
......
......@@ -202,9 +202,9 @@ Blockly.Python['text_getSubstring'] = function(block) {
Blockly.Python['text_changeCase'] = function(block) {
// Change capitalization.
var OPERATORS = {
UPPERCASE: '.upper()',
LOWERCASE: '.lower()',
TITLECASE: '.title()'
'UPPERCASE': '.upper()',
'LOWERCASE': '.lower()',
'TITLECASE': '.title()'
};
var operator = OPERATORS[block.getFieldValue('CASE')];
var argument0 = Blockly.Python.valueToCode(block, 'TEXT',
......@@ -216,9 +216,9 @@ Blockly.Python['text_changeCase'] = function(block) {
Blockly.Python['text_trim'] = function(block) {
// Trim spaces.
var OPERATORS = {
LEFT: '.lstrip()',
RIGHT: '.rstrip()',
BOTH: '.strip()'
'LEFT': '.lstrip()',
'RIGHT': '.rstrip()',
'BOTH': '.strip()'
};
var operator = OPERATORS[block.getFieldValue('MODE')];
var argument0 = Blockly.Python.valueToCode(block, 'TEXT',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment