Revert runtime/util

This commit is contained in:
HirokiUchikawa 2018-05-09 19:19:37 +09:00
parent 0be9c88106
commit e30f8628db
2 changed files with 6 additions and 4 deletions

View File

@ -240,7 +240,7 @@ function getMessageProperty(msg,expr) {
var msgPropParts = normalisePropertyExpression(expr); var msgPropParts = normalisePropertyExpression(expr);
var m; var m;
msgPropParts.reduce(function(obj, key) { msgPropParts.reduce(function(obj, key) {
result = ((typeof obj !== "undefined") && (typeof obj[key] !== "undefined") ? obj[key] : undefined); result = (typeof obj[key] !== "undefined" ? obj[key] : undefined);
return result; return result;
}, msg); }, msg);
return result; return result;

View File

@ -153,9 +153,11 @@ describe("red/util", function() {
var v = util.getMessageProperty({a:"foo"},"msg.b"); var v = util.getMessageProperty({a:"foo"},"msg.b");
should.not.exist(v); should.not.exist(v);
}); });
it('should return undefined if property parent does not exist', function() { it('should throw error if property parent does not exist', function() {
var v = util.getMessageProperty({a:"foo"},"msg.a.b.c"); /*jshint immed: false */
should.not.exist(v); (function() {
util.getMessageProperty({a:"foo"},"msg.a.b.c");
}).should.throw();
}); });
it('retrieves a property with array syntax', function() { it('retrieves a property with array syntax', function() {
var v = util.getMessageProperty({a:["foo","bar"]},"msg.a[0]"); var v = util.getMessageProperty({a:["foo","bar"]},"msg.a[0]");