From 42ccbd24c84f82e1acc3c5c225f39373a6acf819 Mon Sep 17 00:00:00 2001 From: Caridy Patino Date: Sun, 7 Nov 2021 15:58:49 -0500 Subject: [PATCH 1/2] refactor: allow resolution of variables in the proto chain --- fluent-bundle/src/resolver.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fluent-bundle/src/resolver.ts b/fluent-bundle/src/resolver.ts index 297f4cd9..928cdd2c 100644 --- a/fluent-bundle/src/resolver.ts +++ b/fluent-bundle/src/resolver.ts @@ -156,14 +156,14 @@ 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 (Reflect.has(scope.params, name)) { arg = scope.params[name]; } else { return new FluentNone(`$${name}`); } } else if ( scope.args - && Object.prototype.hasOwnProperty.call(scope.args, name) + && Reflect.has(scope.args, name) ) { // We're in the top-level Pattern or inside a MessageReference. Missing // variables references produce ReferenceErrors. From c8cede682f4efd83faac0d9307c46fc0424b1000 Mon Sep 17 00:00:00 2001 From: Eemeli Aro Date: Thu, 1 Jan 2026 17:57:26 +0200 Subject: [PATCH 2/2] Update tests, use `name in ...` rather than `Reflect.has()` --- fluent-bundle/src/resolver.ts | 7 ++----- fluent-bundle/test/object_prototype_test.js | 14 +++++++------- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/fluent-bundle/src/resolver.ts b/fluent-bundle/src/resolver.ts index 05f56fdb..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 (Reflect.has(scope.params, name)) { + if (name in scope.params) { arg = scope.params[name]; } else { return new FluentNone(`$${name}`); } - } else if ( - scope.args - && Reflect.has(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 () {