@@ -22,6 +22,16 @@ pub enum OutputError {
22
22
Conversion ,
23
23
}
24
24
25
+ impl OutputError {
26
+ pub fn to_string ( & self ) -> String {
27
+ match self {
28
+ OutputError :: ParseJs => "OutputError::ParseJs" . into ( ) ,
29
+ OutputError :: Serialize => "OutputError::Serialize" . into ( ) ,
30
+ OutputError :: Conversion => "OutputError::Conversion" . into ( ) ,
31
+ }
32
+ }
33
+ }
34
+
25
35
impl ParsedConfig {
26
36
///
27
37
/// Parse a Magento 2 generated requirejs-config.js file pulling out
@@ -110,10 +120,9 @@ fn process_shim(xs: &Vec<ObjectMember>, output: &mut ParsedConfig) {
110
120
. map ( |s| serde_json:: Value :: String ( s) )
111
121
. collect ( ) ;
112
122
113
- let mut map_item = output
123
+ output
114
124
. shim
115
- . entry ( strip_literal ( s) )
116
- . or_insert ( serde_json:: Value :: Array ( as_serde) ) ;
125
+ . insert ( strip_literal ( s) , serde_json:: Value :: Array ( as_serde) ) ;
117
126
}
118
127
Expression :: Object ( vs) => {
119
128
let mut m = serde_json:: Map :: new ( ) ;
@@ -154,10 +163,9 @@ fn process_shim(xs: &Vec<ObjectMember>, output: &mut ParsedConfig) {
154
163
_ => { }
155
164
}
156
165
}
157
- let mut map_item = output
166
+ output
158
167
. shim
159
- . entry ( strip_literal ( s) )
160
- . or_insert ( serde_json:: Value :: Object ( m) ) ;
168
+ . insert ( strip_literal ( s) , serde_json:: Value :: Object ( m) ) ;
161
169
}
162
170
_ => { /* */ }
163
171
}
@@ -178,8 +186,10 @@ fn process_config(xs: &Vec<ObjectMember>, output: &mut ParsedConfig) {
178
186
key : ObjectKey :: Literal ( s) ,
179
187
value,
180
188
} => {
181
- let mut map_item =
182
- output. config . entry ( strip_literal ( s) . to_string ( ) ) . or_insert ( HashMap :: new ( ) ) ;
189
+ let mut map_item = output
190
+ . config
191
+ . entry ( strip_literal ( s) . to_string ( ) )
192
+ . or_insert ( HashMap :: new ( ) ) ;
183
193
184
194
match value {
185
195
Expression :: Object ( vs) => {
@@ -287,7 +297,10 @@ fn process_map(xs: &Vec<ObjectMember>, output: &mut ParsedConfig) {
287
297
key : ObjectKey :: Literal ( k) ,
288
298
value : Expression :: Literal ( Value :: String ( v) ) ,
289
299
} => {
290
- map_item. insert ( strip_literal ( k) . to_string ( ) , strip_literal ( v) ) ;
300
+ map_item. insert (
301
+ strip_literal ( k) . to_string ( ) ,
302
+ strip_literal ( v) ,
303
+ ) ;
291
304
}
292
305
_ => { /* */ }
293
306
}
@@ -411,6 +424,18 @@ mod tests {
411
424
};
412
425
require.config(config);
413
426
})();
427
+ (function() {
428
+ var config = {
429
+ shim: {
430
+ "jquery/jquery-migrate": {
431
+ "deps": [
432
+ "jquery",
433
+ 'jquery/jquery.cookie'
434
+ ]
435
+ }
436
+ }
437
+ }
438
+ })();
414
439
"# ;
415
440
416
441
let o = ParsedConfig :: from_str ( input) . expect ( "parses fixture" ) ;
@@ -431,7 +456,8 @@ mod tests {
431
456
"shim": {
432
457
"jquery/jquery-migrate": {
433
458
"deps": [
434
- "jquery"
459
+ "jquery",
460
+ "jquery/jquery.cookie"
435
461
]
436
462
},
437
463
"paypalInContextExpressCheckout": {
@@ -461,7 +487,6 @@ mod tests {
461
487
let expected: serde_json:: Value = serde_json:: from_str ( & from) . expect ( "serde from (fixture)" ) ;
462
488
let actual = serde_json:: to_value ( & o) . expect ( "Output serialized" ) ;
463
489
464
- // println!("{:#?}", actual);
465
490
assert_eq ! ( actual, expected) ;
466
491
467
492
let _as_require: RequireJsClientConfig =
0 commit comments