@@ -123,7 +123,8 @@ module.exports = function( grunt ) {
123
123
paths : {
124
124
cldr : "../external/cldrjs/dist/cldr" ,
125
125
"make-plural" : "../external/make-plural/make-plural" ,
126
- messageformat : "../external/messageformat/messageformat"
126
+ "messageformat-parser" : "../node_modules/messageformat-parser/parser" ,
127
+ "reserved-words" : "../node_modules/reserved-words/lib/reserved-words"
127
128
} ,
128
129
skipSemiColonInsertion : true ,
129
130
skipModuleInsertion : true ,
@@ -136,8 +137,7 @@ module.exports = function( grunt ) {
136
137
// Only for root id's (the ones in src, not in src's subpaths). Note there's no
137
138
// conditional code checking for this type.
138
139
onBuildWrite : function ( id , path , contents ) {
139
- var messageformat ,
140
- name = camelCase ( id . replace ( / u t i l \/ | c o m m o n \/ / , "" ) ) ;
140
+ var name = camelCase ( id . replace ( / u t i l \/ | c o m m o n \/ / , "" ) ) ;
141
141
142
142
// MakePlural
143
143
if ( ( / m a k e - p l u r a l / ) . test ( id ) ) {
@@ -185,67 +185,38 @@ module.exports = function( grunt ) {
185
185
"/* jshint ignore:end */"
186
186
] . join ( "\n" ) ) ;
187
187
188
- // messageformat
189
- } else if ( ( / m e s s a g e f o r m a t / ) . test ( id ) ) {
190
- return contents
188
+ // messageformat-parser
189
+ } else if ( ( / m e s s a g e f o r m a t - p a r s e r / . test ( id ) ) ) {
191
190
192
- // Remove browserify wrappers.
193
- . replace ( / ^ \( f u n c t i o n \( f \) \{ i f \( t y p e o f e x p o r t s = = = " o b j e c t " & & t y p e .* / , "" )
194
- . replace ( "},{}],2:[function(require,module,exports){" , "" )
195
- . replace ( / \} , \{ " \. \/ m e s s a g e f o r m a t - p a r s e r " : 1 , " m a k e - p l u r a l \/ p l u r a l .* / , "" )
196
- . replace ( / \} , \{ \} \] \} , \{ \} , \[ 2 \] \) \( 2 \) [ \s \S ] * ?$ / , "" )
197
-
198
- // Set `MessageFormat.plurals` and remove `make-plural/plurals`
199
- // completely. This is populated by Globalize on demand.
200
- . replace ( / v a r _ c p = \[ [ \s \S ] * ?$ / , "" )
201
- . replace (
202
- "MessageFormat.plurals = require('make-plural/plurals')" ,
203
- "MessageFormat.plurals = {}"
204
- )
205
-
206
- // Set `MessageFormat._parse`
207
- . replace (
208
- "MessageFormat._parse = require('./messageformat-parser').parse;" ,
209
- ""
210
- )
211
- . replace ( / m o d u l e \. e x p o r t s = \( f u n c t i o n \( \) \{ ( [ \s \S ] * ?) \n \} \) \( \) ; / , [
212
- "MessageFormat._parse = (function() {" ,
213
- "$1" ,
214
- "}()).parse;"
191
+ return contents
192
+ . replace ( / ^ / , [
193
+ "var Parser;" ,
194
+ "/* jshint ignore:start */\n" ,
195
+ "Parser = (function() {"
215
196
] . join ( "\n" ) )
197
+ . replace ( "module.exports = " , "return " )
198
+ . replace ( / $ / , [
199
+ "}());" ,
200
+ "/* jshint ignore:end */"
201
+ ] . join ( "\n" ) ) ;
216
202
217
- // Remove unused code.
218
- . replace ( / i f \( ! p l u r a l F u n c \) \{ \n [ \s \S ] * ?\n \} / , "" )
219
- . replace ( / i f \( ! l o c a l e \) \{ \n [ \s \S ] * ? \} \n / , "this.lc = [locale];" )
220
- . replace ( / ( M e s s a g e F o r m a t \. f o r m a t t e r s ) = \{ [ \s \S ] * ?\n \} ; / , "$1 = {};" )
221
- . replace ( / M e s s a g e F o r m a t \. p r o t o t y p e \. s e t I n t l S u p p o r t [ \s \S ] * ?\n \} ; / , "" )
203
+ // reserved-words
204
+ } else if ( ( / r e s e r v e d - w o r d s / . test ( id ) ) ) {
222
205
223
- // Wrap everything into a var assignment.
224
- . replace ( "module.exports = MessageFormat;" , "" )
206
+ return contents
225
207
. replace ( / ^ / , [
226
- "var MessageFormat;" ,
227
- "/* jshint ignore:start */" ,
228
- "MessageFormat = (function() {"
208
+ "var reserved;" ,
209
+ "/* jshint ignore:start */\n" ,
210
+ "reserved = (function() {" ,
211
+ "var exports = {};"
229
212
] . join ( "\n" ) )
213
+ . replace ( "var assert = require\('assert'\);" , "" )
214
+ . replace ( / ^ \s * a s s e r t \( .* ; \s * $ / gm, "" )
230
215
. replace ( / $ / , [
231
- "return MessageFormat ;" ,
216
+ "return exports ;" ,
232
217
"}());" ,
233
218
"/* jshint ignore:end */"
234
219
] . join ( "\n" ) ) ;
235
-
236
- // message-runtime
237
- } else if ( ( / m e s s a g e - r u n t i m e / ) . test ( id ) ) {
238
- messageformat = require ( "./external/messageformat/messageformat" ) ;
239
- delete messageformat . prototype . runtime . fmt ;
240
- delete messageformat . prototype . runtime . pluralFuncs ;
241
- contents = contents . replace ( "Globalize._messageFormat = {};" , [
242
- "/* jshint ignore:start */" ,
243
- "Globalize._messageFormat = (function() {" ,
244
- messageformat . prototype . runtime . toString ( ) ,
245
- "return {number: number, plural: plural, select: select};" ,
246
- "}());" ,
247
- "/* jshint ignore:end */"
248
- ] . join ( "\n" ) ) ;
249
220
}
250
221
251
222
// 1, and 2: Remove define() wrap.
0 commit comments