Skip to content

Commit 8433e0d

Browse files
committed
Fix no-tracked-properties-from-args crash on method calls
nodeToDependentKey returned non-string values for call expressions like this.array.indexOf(1). Use isThisGetCall to only extract the dependent key from this.get('property') calls. Fixes #2281
1 parent 131cd12 commit 8433e0d

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

lib/utils/property-getter.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,12 @@ function isSimpleThisExpression(node) {
8383
*/
8484
function nodeToDependentKey(nodeWithThisExpression, context) {
8585
if (types.isCallExpression(nodeWithThisExpression)) {
86-
if (nodeWithThisExpression.arguments[0]) {
86+
if (isThisGetCall(nodeWithThisExpression)) {
8787
// Looks like: this.get('property')
8888
return nodeWithThisExpression.arguments[0].value;
8989
}
9090

91-
// Looks like: this.someMethod()
91+
// Looks like: this.someMethod() or this.foo.bar(1)
9292
return undefined;
9393
}
9494

tests/lib/rules/no-tracked-properties-from-args.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,14 @@ ruleTester.run('no-tracked-properties-from-args', rule, {
8181
someProperty = this.someMethod();
8282
}
8383
`,
84+
// Should not crash on method calls with non-string arguments
85+
`
86+
import { tracked } from '@glimmer/tracking';
87+
88+
class Test {
89+
@tracked test = this.array.indexOf(1);
90+
}
91+
`,
8492
],
8593
invalid: [
8694
{

0 commit comments

Comments
 (0)