Skip to content

Commit 427f85d

Browse files
authored
Fall back to msgId.attrName when attribute is not found (#370)
1 parent c00b4c0 commit 427f85d

File tree

3 files changed

+44
-12
lines changed

3 files changed

+44
-12
lines changed

fluent/src/resolver.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ function MessageReference(scope, {name, attr}) {
199199
return Type(scope, attribute);
200200
}
201201
scope.errors.push(new ReferenceError(`Unknown attribute: ${attr}`));
202-
return Type(scope, message);
202+
return new FluentNone(`${name}.${attr}`);
203203
}
204204

205205
return Type(scope, message);
@@ -225,7 +225,7 @@ function TermReference(scope, {name, attr, args}) {
225225
return Type(local, attribute);
226226
}
227227
scope.errors.push(new ReferenceError(`Unknown attribute: ${attr}`));
228-
return Type(local, term);
228+
return new FluentNone(`${id}.${attr}`);
229229
}
230230

231231
return Type(local, term);
@@ -250,7 +250,7 @@ function FunctionReference(scope, {name, args}) {
250250
return func(...getArguments(scope, args));
251251
} catch (e) {
252252
// XXX Report errors.
253-
return new FluentNone();
253+
return new FluentNone(`${name}()`);
254254
}
255255
}
256256

fluent/test/attributes_test.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,34 +30,34 @@ suite('Attributes', function() {
3030
`);
3131
});
3232

33-
test('falls back gracefully for entities with string values and no attributes', function() {
33+
test('entities with string values and no attributes', function() {
3434
const msg = bundle.getMessage('ref-foo');
3535
const val = bundle.format(msg, args, errs);
36-
assert.equal(val, 'Foo');
36+
assert.equal(val, '{foo.missing}');
3737
assert.equal(errs.length, 1);
3838
assert(errs[0] instanceof ReferenceError); // unknown attribute
3939
});
4040

41-
test('falls back gracefully for entities with string values and other attributes', function() {
41+
test('entities with string values and other attributes', function() {
4242
const msg = bundle.getMessage('ref-bar');
4343
const val = bundle.format(msg, args, errs);
44-
assert.equal(val, 'Bar');
44+
assert.equal(val, '{bar.missing}');
4545
assert.equal(errs.length, 1);
4646
assert(errs[0] instanceof ReferenceError); // unknown attribute
4747
});
4848

49-
test('falls back gracefully for entities with pattern values and no attributes', function() {
49+
test('entities with pattern values and no attributes', function() {
5050
const msg = bundle.getMessage('ref-baz');
5151
const val = bundle.format(msg, args, errs);
52-
assert.equal(val, 'Foo Baz');
52+
assert.equal(val, '{baz.missing}');
5353
assert.equal(errs.length, 1);
5454
assert(errs[0] instanceof ReferenceError); // unknown attribute
5555
});
5656

57-
test('falls back gracefully for entities with pattern values and other attributes', function() {
57+
test('entities with pattern values and other attributes', function() {
5858
const msg = bundle.getMessage('ref-qux');
5959
const val = bundle.format(msg, args, errs);
60-
assert.equal(val, 'Foo Qux');
60+
assert.equal(val, '{qux.missing}');
6161
assert.equal(errs.length, 1);
6262
assert(errs[0] instanceof ReferenceError); // unknown attribute
6363
});

fluent/test/values_ref_test.js

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,15 @@ suite('Referencing values', function(){
3939
4040
ref10 = { key5.a }
4141
ref11 = { key5.b }
42+
ref12 = { key5.c }
43+
44+
ref13 = { key6 }
45+
ref14 = { key6.a }
46+
47+
ref15 = { -key6 }
48+
ref16 = { -key6.a ->
49+
*[a] A
50+
}
4251
`);
4352
});
4453

@@ -104,11 +113,34 @@ suite('Referencing values', function(){
104113
test('references the attributes', function(){
105114
const msg_a = bundle.getMessage('ref10');
106115
const msg_b = bundle.getMessage('ref11');
116+
const msg_c = bundle.getMessage('ref12');
107117
const val_a = bundle.format(msg_a, args, errs)
108118
const val_b = bundle.format(msg_b, args, errs)
119+
const val_c = bundle.format(msg_c, args, errs)
109120
assert.strictEqual(val_a, 'A5');
110121
assert.strictEqual(val_b, 'B5');
111-
assert.equal(errs.length, 0);
122+
assert.strictEqual(val_c, '{key5.c}');
123+
assert.equal(errs.length, 1);
124+
});
125+
126+
test('missing message reference', function(){
127+
const msg_a = bundle.getMessage('ref13');
128+
const msg_b = bundle.getMessage('ref14');
129+
const val_a = bundle.format(msg_a, args, errs)
130+
const val_b = bundle.format(msg_b, args, errs)
131+
assert.strictEqual(val_a, '{key6}');
132+
assert.strictEqual(val_b, '{key6}');
133+
assert.equal(errs.length, 2);
134+
});
135+
136+
test('missing term reference', function(){
137+
const msg_a = bundle.getMessage('ref15');
138+
const msg_b = bundle.getMessage('ref16');
139+
const val_a = bundle.format(msg_a, args, errs)
140+
const val_b = bundle.format(msg_b, args, errs)
141+
assert.strictEqual(val_a, '{-key6}');
142+
assert.strictEqual(val_b, 'A');
143+
assert.equal(errs.length, 2);
112144
});
113145

114146
});

0 commit comments

Comments
 (0)