Skip to content

Commit 3f523cc

Browse files
caridyeemeli
andauthored
fix(bundle): Allow resolution of variables in the proto chain (#578)
Co-authored-by: Eemeli Aro <eemeli@mozilla.com>
1 parent 6f78e74 commit 3f523cc

File tree

2 files changed

+9
-12
lines changed

2 files changed

+9
-12
lines changed

fluent-bundle/src/resolver.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,15 +154,12 @@ function resolveVariableReference(
154154
let arg: FluentVariable;
155155
if (scope.params) {
156156
// We're inside a TermReference. It's OK to reference undefined parameters.
157-
if (Object.prototype.hasOwnProperty.call(scope.params, name)) {
157+
if (name in scope.params) {
158158
arg = scope.params[name];
159159
} else {
160160
return new FluentNone(`$${name}`);
161161
}
162-
} else if (
163-
scope.args &&
164-
Object.prototype.hasOwnProperty.call(scope.args, name)
165-
) {
162+
} else if (scope.args && name in scope.args) {
166163
// We're in the top-level Pattern or inside a MessageReference. Missing
167164
// variables references produce ReferenceErrors.
168165
arg = scope.args[name];

fluent-bundle/test/object_prototype_test.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ suite("Interesting Object properties", function () {
2626
const val = bundle.formatPattern(msg.value, {}, errs);
2727
assert.strictEqual(val, "{$constructor}");
2828
assert.strictEqual(errs.length, 1);
29-
assert(errs[0] instanceof ReferenceError); // unknown variable
29+
assert(errs[0] instanceof TypeError); // variable type not supported
3030
});
3131

3232
test("empty args with null prototype", function () {
@@ -60,7 +60,7 @@ suite("Interesting Object properties", function () {
6060
const val = bundle.formatPattern(msg.value, {}, errs);
6161
assert.strictEqual(val, "{$hasOwnProperty}");
6262
assert.strictEqual(errs.length, 1);
63-
assert(errs[0] instanceof ReferenceError); // unknown variable
63+
assert(errs[0] instanceof TypeError); // variable type not supported
6464
});
6565

6666
test("empty args with null prototype", function () {
@@ -94,7 +94,7 @@ suite("Interesting Object properties", function () {
9494
const val = bundle.formatPattern(msg.value, {}, errs);
9595
assert.strictEqual(val, "{$isPrototypeOf}");
9696
assert.strictEqual(errs.length, 1);
97-
assert(errs[0] instanceof ReferenceError); // unknown variable
97+
assert(errs[0] instanceof TypeError); // variable type not supported
9898
});
9999

100100
test("empty args with null prototype", function () {
@@ -128,7 +128,7 @@ suite("Interesting Object properties", function () {
128128
const val = bundle.formatPattern(msg.value, {}, errs);
129129
assert.strictEqual(val, "{$propertyIsEnumerable}");
130130
assert.strictEqual(errs.length, 1);
131-
assert(errs[0] instanceof ReferenceError); // unknown variable
131+
assert(errs[0] instanceof TypeError); // variable type not supported
132132
});
133133

134134
test("empty args with null prototype", function () {
@@ -166,7 +166,7 @@ suite("Interesting Object properties", function () {
166166
const val = bundle.formatPattern(msg.value, {}, errs);
167167
assert.strictEqual(val, "{$toLocaleString}");
168168
assert.strictEqual(errs.length, 1);
169-
assert(errs[0] instanceof ReferenceError); // unknown variable
169+
assert(errs[0] instanceof TypeError); // variable type not supported
170170
});
171171

172172
test("empty args with null prototype", function () {
@@ -200,7 +200,7 @@ suite("Interesting Object properties", function () {
200200
const val = bundle.formatPattern(msg.value, {}, errs);
201201
assert.strictEqual(val, "{$toString}");
202202
assert.strictEqual(errs.length, 1);
203-
assert(errs[0] instanceof ReferenceError); // unknown variable
203+
assert(errs[0] instanceof TypeError); // variable type not supported
204204
});
205205

206206
test("empty args with null prototype", function () {
@@ -234,7 +234,7 @@ suite("Interesting Object properties", function () {
234234
const val = bundle.formatPattern(msg.value, {}, errs);
235235
assert.strictEqual(val, "{$valueOf}");
236236
assert.strictEqual(errs.length, 1);
237-
assert(errs[0] instanceof ReferenceError); // unknown variable
237+
assert(errs[0] instanceof TypeError); // variable type not supported
238238
});
239239

240240
test("empty args with null property", function () {

0 commit comments

Comments
 (0)