Skip to content

Commit 9a6e7cb

Browse files
Merge pull request #2542 from johanrd/issue/2281-no-tracked-properties-from-args-crash
[BUGFIX]: `no-tracked-properties-from-args` crash on method calls
2 parents 6cd538d + 8433e0d commit 9a6e7cb

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)