@@ -218,7 +218,7 @@ function matchRegular(node, ctx) {
218
218
const args = node . arguments ;
219
219
const target = ( is . someof ( method . name , [ "config" , "run" ] ) ?
220
220
args . length === 1 && args [ 0 ] :
221
- args . length === 2 && args [ 0 ] . type === "Literal" && is . string ( args [ 0 ] . value ) && args [ 1 ] ) ;
221
+ args . length === 2 && args [ 0 ] . type === "Literal" && is . string ( args [ 0 ] . value ) && [ args [ 0 ] , args [ 1 ] ] ) ;
222
222
223
223
if ( target ) {
224
224
target . $always = true ;
@@ -266,16 +266,20 @@ function matchResolve(props) {
266
266
return [ ] ;
267
267
} ;
268
268
269
- function stringify ( arr , quot ) {
269
+ function getReplaceString ( ctx , originalString ) {
270
+ return ( ctx . rename [ originalString ] || originalString ) ;
271
+ }
272
+
273
+ function stringify ( ctx , arr , quot ) {
270
274
return "[" + arr . map ( function ( arg ) {
271
- return quot + arg . name + quot ;
275
+ return quot + getReplaceString ( ctx , arg . name ) + quot ;
272
276
} ) . join ( ", " ) + "]" ;
273
277
}
274
278
275
- function insertArray ( functionExpression , fragments , quot ) {
279
+ function insertArray ( ctx , functionExpression , fragments , quot ) {
276
280
const range = functionExpression . range ;
277
281
278
- const args = stringify ( functionExpression . params , quot ) ;
282
+ const args = stringify ( ctx , functionExpression . params , quot ) ;
279
283
fragments . push ( {
280
284
start : range [ 0 ] ,
281
285
end : range [ 0 ] ,
@@ -288,13 +292,14 @@ function insertArray(functionExpression, fragments, quot) {
288
292
} ) ;
289
293
}
290
294
291
- function replaceArray ( array , fragments , quot ) {
295
+ function replaceArray ( ctx , array , fragments , quot ) {
292
296
const functionExpression = last ( array . elements ) ;
293
297
294
298
if ( functionExpression . params . length === 0 ) {
295
299
return removeArray ( array , fragments ) ;
296
300
}
297
- const args = stringify ( functionExpression . params , quot ) ;
301
+
302
+ const args = stringify ( ctx , functionExpression . params , quot ) ;
298
303
fragments . push ( {
299
304
start : array . range [ 0 ] ,
300
305
end : functionExpression . range [ 0 ] ,
@@ -317,6 +322,15 @@ function removeArray(array, fragments) {
317
322
} ) ;
318
323
}
319
324
325
+ function replaceString ( ctx , string , fragments , quot ) {
326
+ var customReplace = getReplaceString ( ctx , string . value ) ;
327
+ fragments . push ( {
328
+ start : string . range [ 0 ] ,
329
+ end : string . range [ 1 ] ,
330
+ str : quot + customReplace + quot
331
+ } ) ;
332
+ }
333
+
320
334
function judgeSuspects ( ctx ) {
321
335
const suspects = ctx . suspects ;
322
336
const mode = ctx . mode ;
@@ -341,11 +355,13 @@ function judgeSuspects(ctx) {
341
355
}
342
356
343
357
if ( mode === "rebuild" && isAnnotatedArray ( target ) ) {
344
- replaceArray ( target , fragments , quot ) ;
358
+ replaceArray ( ctx , target , fragments , quot ) ;
345
359
} else if ( mode === "remove" && isAnnotatedArray ( target ) ) {
346
360
removeArray ( target , fragments ) ;
347
361
} else if ( is . someof ( mode , [ "add" , "rebuild" ] ) && isFunctionExpressionWithArgs ( target ) ) {
348
- insertArray ( target , fragments , quot ) ;
362
+ insertArray ( ctx , target , fragments , quot ) ;
363
+ } else if ( isGenericProviderName ( target ) ) {
364
+ replaceString ( ctx , target , fragments , quot ) ;
349
365
}
350
366
}
351
367
}
@@ -368,6 +384,9 @@ function isFunctionExpressionWithArgs(node) {
368
384
function isFunctionDeclarationWithArgs ( node ) {
369
385
return node . type === "FunctionDeclaration" && node . params . length >= 1 ;
370
386
}
387
+ function isGenericProviderName ( node ) {
388
+ return node . type === "Literal" && is . string ( node . value ) ;
389
+ }
371
390
372
391
module . exports = function ngAnnotate ( src , options ) {
373
392
const mode = ( options . add && options . remove ? "rebuild" :
@@ -380,6 +399,7 @@ module.exports = function ngAnnotate(src, options) {
380
399
381
400
const quot = options . single_quotes ? "'" : '"' ;
382
401
const re = ( options . regexp ? new RegExp ( options . regexp ) : / ^ [ a - z A - Z 0 - 9 _ \$ \. \s ] + $ / ) ;
402
+ const rename = options . rename || { } ;
383
403
let ast ;
384
404
const stats = { } ;
385
405
try {
@@ -437,6 +457,7 @@ module.exports = function ngAnnotate(src, options) {
437
457
return src . slice ( range [ 0 ] , range [ 1 ] ) ;
438
458
} ,
439
459
re : re ,
460
+ rename : rename ,
440
461
comments : comments ,
441
462
fragments : fragments ,
442
463
triggers : triggers ,
0 commit comments