@@ -117,16 +117,16 @@ function parseComputedDependencies(args) {
117
117
* or `this.get(…)`.
118
118
*
119
119
* @param {ASTNode } node
120
- * @param {string } importedEmberName
120
+ * @param {object } importedNames
121
121
* @returns {Array<ASTNode> }
122
122
*/
123
- function findEmberGetCalls ( node , importedEmberName ) {
123
+ function findEmberGetCalls ( node , importedNames ) {
124
124
const results = [ ] ;
125
125
126
126
new Traverser ( ) . traverse ( node , {
127
127
enter ( child ) {
128
128
if ( types . isCallExpression ( child ) ) {
129
- const dependency = extractEmberGetDependencies ( child , importedEmberName ) ;
129
+ const dependency = extractEmberGetDependencies ( child , importedNames ) ;
130
130
131
131
if ( dependency . length > 0 ) {
132
132
results . push ( child ) ;
@@ -211,10 +211,13 @@ function getArrayOrRest(args) {
211
211
* Extracts all static property keys used in the various forms of `Ember.get`.
212
212
*
213
213
* @param {ASTNode } call
214
- * @param {string } importedEmberName
214
+ * @param {object } importedNames
215
215
* @returns {Array<string> }
216
216
*/
217
- function extractEmberGetDependencies ( call , importedEmberName ) {
217
+ function extractEmberGetDependencies (
218
+ call ,
219
+ { importedEmberName, importedGetName, importedGetPropertiesName, importedGetWithDefaultName }
220
+ ) {
218
221
if (
219
222
isMemberExpression ( call . callee , 'this' , 'get' ) ||
220
223
isMemberExpression ( call . callee , 'this' , 'getWithDefault' )
@@ -226,7 +229,9 @@ function extractEmberGetDependencies(call, importedEmberName) {
226
229
}
227
230
} else if (
228
231
isMemberExpression ( call . callee , importedEmberName , 'get' ) ||
229
- isMemberExpression ( call . callee , importedEmberName , 'getWithDefault' )
232
+ isMemberExpression ( call . callee , importedEmberName , 'getWithDefault' ) ||
233
+ isIdentifier ( call . callee , importedGetName ) ||
234
+ isIdentifier ( call . callee , importedGetWithDefaultName )
230
235
) {
231
236
const firstArg = call . arguments [ 0 ] ;
232
237
const secondArgument = call . arguments [ 1 ] ;
@@ -238,7 +243,10 @@ function extractEmberGetDependencies(call, importedEmberName) {
238
243
return getArrayOrRest ( call . arguments )
239
244
. filter ( types . isStringLiteral )
240
245
. map ( ( arg ) => arg . value ) ;
241
- } else if ( isMemberExpression ( call . callee , importedEmberName , 'getProperties' ) ) {
246
+ } else if (
247
+ isMemberExpression ( call . callee , importedEmberName , 'getProperties' ) ||
248
+ isIdentifier ( call . callee , importedGetPropertiesName )
249
+ ) {
242
250
const firstArg = call . arguments [ 0 ] ;
243
251
const rest = call . arguments . slice ( 1 ) ;
244
252
@@ -313,8 +321,11 @@ module.exports = {
313
321
314
322
let importedEmberName ;
315
323
let importedComputedName ;
324
+ let importedGetName ;
325
+ let importedGetPropertiesName ;
326
+ let importedGetWithDefaultName ;
316
327
317
- function checkComputedDependencies ( node , nodeArguments , importedEmberName ) {
328
+ function checkComputedDependencies ( node , nodeArguments , importedNames ) {
318
329
const declaredDependencies = parseComputedDependencies ( nodeArguments ) ;
319
330
320
331
if ( ! allowDynamicKeys ) {
@@ -331,8 +342,8 @@ module.exports = {
331
342
) ;
332
343
333
344
const usedKeys1 = javascriptUtils . flatMap (
334
- findEmberGetCalls ( computedPropertyFunctionBody , importedEmberName ) ,
335
- ( node ) => extractEmberGetDependencies ( node , importedEmberName )
345
+ findEmberGetCalls ( computedPropertyFunctionBody , importedNames ) ,
346
+ ( node ) => extractEmberGetDependencies ( node , importedNames )
336
347
) ;
337
348
const usedKeys2 = javascriptUtils . flatMap (
338
349
findThisGetCalls ( computedPropertyFunctionBody ) ,
@@ -459,18 +470,35 @@ module.exports = {
459
470
if ( node . source . value === '@ember/object' ) {
460
471
importedComputedName =
461
472
importedComputedName || getImportIdentifier ( node , '@ember/object' , 'computed' ) ;
473
+ importedGetName = importedGetName || getImportIdentifier ( node , '@ember/object' , 'get' ) ;
474
+ importedGetPropertiesName =
475
+ importedGetPropertiesName ||
476
+ getImportIdentifier ( node , '@ember/object' , 'getProperties' ) ;
477
+ importedGetWithDefaultName =
478
+ importedGetWithDefaultName ||
479
+ getImportIdentifier ( node , '@ember/object' , 'getWithDefault' ) ;
462
480
}
463
481
} ,
464
482
465
483
Identifier ( node ) {
466
484
if ( isEmberComputed ( node , importedEmberName , importedComputedName ) ) {
467
- checkComputedDependencies ( node , [ ] , importedEmberName ) ;
485
+ checkComputedDependencies ( node , [ ] , {
486
+ importedEmberName,
487
+ importedGetName,
488
+ importedGetPropertiesName,
489
+ importedGetWithDefaultName,
490
+ } ) ;
468
491
}
469
492
} ,
470
493
471
494
CallExpression ( node ) {
472
495
if ( isEmberComputed ( node . callee , importedEmberName , importedComputedName ) ) {
473
- checkComputedDependencies ( node , node . arguments , importedEmberName ) ;
496
+ checkComputedDependencies ( node , node . arguments , {
497
+ importedEmberName,
498
+ importedGetName,
499
+ importedGetPropertiesName,
500
+ importedGetWithDefaultName,
501
+ } ) ;
474
502
}
475
503
} ,
476
504
} ;
0 commit comments