File tree Expand file tree Collapse file tree 2 files changed +14
-3
lines changed Expand file tree Collapse file tree 2 files changed +14
-3
lines changed Original file line number Diff line number Diff line change @@ -113,8 +113,16 @@ export class MessageContext {
113
113
if ( id . startsWith ( "-" ) ) {
114
114
// Identifiers starting with a dash (-) define terms. Terms are private
115
115
// and cannot be retrieved from MessageContext.
116
+ if ( this . _terms . has ( id ) ) {
117
+ errors . push ( `Attempt to override an existing term: "${ id } "` ) ;
118
+ continue ;
119
+ }
116
120
this . _terms . set ( id , entries [ id ] ) ;
117
121
} else {
122
+ if ( this . _messages . has ( id ) ) {
123
+ errors . push ( `Attempt to override an existing message: "${ id } "` ) ;
124
+ continue ;
125
+ }
118
126
this . _messages . set ( id , entries [ id ] ) ;
119
127
}
120
128
}
Original file line number Diff line number Diff line change @@ -53,16 +53,19 @@ suite('Context', function() {
53
53
} ) ;
54
54
55
55
56
- test ( 'overwrites existing messages if the ids are the same' , function ( ) {
57
- ctx . addMessages ( ftl `
56
+ test ( 'does not overwrite existing messages if the ids are the same' , function ( ) {
57
+ const errors = ctx . addMessages ( ftl `
58
58
foo = New Foo
59
59
` ) ;
60
60
61
+ // Attempt to overwrite error reported
62
+ assert . equal ( errors . length , 1 ) ;
63
+
61
64
assert . equal ( ctx . _messages . size , 2 ) ;
62
65
63
66
const msg = ctx . getMessage ( 'foo' ) ;
64
67
const val = ctx . format ( msg , args , errs ) ;
65
- assert . equal ( val , 'New Foo' ) ;
68
+ assert . equal ( val , 'Foo' ) ;
66
69
assert . equal ( errs . length , 0 ) ;
67
70
} ) ;
68
71
} ) ;
You can’t perform that action at this time.
0 commit comments