diff --git a/fluent-bundle/src/resolver.ts b/fluent-bundle/src/resolver.ts index 5d13ef95..dd8afc35 100644 --- a/fluent-bundle/src/resolver.ts +++ b/fluent-bundle/src/resolver.ts @@ -154,15 +154,12 @@ function resolveVariableReference( let arg: FluentVariable; if (scope.params) { // We're inside a TermReference. It's OK to reference undefined parameters. - if (Object.prototype.hasOwnProperty.call(scope.params, name)) { + if (name in scope.params) { arg = scope.params[name]; } else { return new FluentNone(`$${name}`); } - } else if ( - scope.args && - Object.prototype.hasOwnProperty.call(scope.args, name) - ) { + } else if (scope.args && name in scope.args) { // We're in the top-level Pattern or inside a MessageReference. Missing // variables references produce ReferenceErrors. arg = scope.args[name]; diff --git a/fluent-bundle/test/object_prototype_test.js b/fluent-bundle/test/object_prototype_test.js index c44eb0ae..913c6508 100644 --- a/fluent-bundle/test/object_prototype_test.js +++ b/fluent-bundle/test/object_prototype_test.js @@ -26,7 +26,7 @@ suite("Interesting Object properties", function () { const val = bundle.formatPattern(msg.value, {}, errs); assert.strictEqual(val, "{$constructor}"); assert.strictEqual(errs.length, 1); - assert(errs[0] instanceof ReferenceError); // unknown variable + assert(errs[0] instanceof TypeError); // variable type not supported }); test("empty args with null prototype", function () { @@ -60,7 +60,7 @@ suite("Interesting Object properties", function () { const val = bundle.formatPattern(msg.value, {}, errs); assert.strictEqual(val, "{$hasOwnProperty}"); assert.strictEqual(errs.length, 1); - assert(errs[0] instanceof ReferenceError); // unknown variable + assert(errs[0] instanceof TypeError); // variable type not supported }); test("empty args with null prototype", function () { @@ -94,7 +94,7 @@ suite("Interesting Object properties", function () { const val = bundle.formatPattern(msg.value, {}, errs); assert.strictEqual(val, "{$isPrototypeOf}"); assert.strictEqual(errs.length, 1); - assert(errs[0] instanceof ReferenceError); // unknown variable + assert(errs[0] instanceof TypeError); // variable type not supported }); test("empty args with null prototype", function () { @@ -128,7 +128,7 @@ suite("Interesting Object properties", function () { const val = bundle.formatPattern(msg.value, {}, errs); assert.strictEqual(val, "{$propertyIsEnumerable}"); assert.strictEqual(errs.length, 1); - assert(errs[0] instanceof ReferenceError); // unknown variable + assert(errs[0] instanceof TypeError); // variable type not supported }); test("empty args with null prototype", function () { @@ -166,7 +166,7 @@ suite("Interesting Object properties", function () { const val = bundle.formatPattern(msg.value, {}, errs); assert.strictEqual(val, "{$toLocaleString}"); assert.strictEqual(errs.length, 1); - assert(errs[0] instanceof ReferenceError); // unknown variable + assert(errs[0] instanceof TypeError); // variable type not supported }); test("empty args with null prototype", function () { @@ -200,7 +200,7 @@ suite("Interesting Object properties", function () { const val = bundle.formatPattern(msg.value, {}, errs); assert.strictEqual(val, "{$toString}"); assert.strictEqual(errs.length, 1); - assert(errs[0] instanceof ReferenceError); // unknown variable + assert(errs[0] instanceof TypeError); // variable type not supported }); test("empty args with null prototype", function () { @@ -234,7 +234,7 @@ suite("Interesting Object properties", function () { const val = bundle.formatPattern(msg.value, {}, errs); assert.strictEqual(val, "{$valueOf}"); assert.strictEqual(errs.length, 1); - assert(errs[0] instanceof ReferenceError); // unknown variable + assert(errs[0] instanceof TypeError); // variable type not supported }); test("empty args with null property", function () {