Skip to content

Commit b164805

Browse files
yayaliceyannickcr
authored andcommitted
Fix jsx-uses-var to handle nested object properties
1 parent 8661917 commit b164805

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

lib/rules/jsx-uses-vars.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,13 @@ module.exports = {
3838
} else if (node.name.name) {
3939
// <Foo>
4040
name = node.name.name;
41-
} else if (node.name.object && node.name.object.name) {
42-
// <Foo.Bar> - node.name.object.name
43-
name = node.name.object.name;
41+
} else if (node.name.object) {
42+
// <Foo...Bar>
43+
var parent = node.name.object;
44+
while (parent.object) {
45+
parent = parent.object;
46+
}
47+
name = parent.name;
4448
} else {
4549
return;
4650
}

tests/lib/rules/jsx-uses-vars.js

+20
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,26 @@ ruleTester.run('no-unused-vars', rule, {
9797
}\
9898
<HelloMessage />',
9999
parserOptions: parserOptions
100+
}, {
101+
code: '\
102+
/*eslint jsx-uses-vars:1*/\
103+
function foo() {\
104+
var App = { Foo: { Bar: {}}};\
105+
var bar = React.render(<App.Foo.Bar/>);\
106+
return bar;\
107+
};\
108+
foo()',
109+
parserOptions: parserOptions
110+
}, {
111+
code: '\
112+
/*eslint jsx-uses-vars:1*/\
113+
function foo() {\
114+
var App = { Foo: { Bar: { Baz: {}}}};\
115+
var bar = React.render(<App.Foo.Bar.Baz/>);\
116+
return bar;\
117+
};\
118+
foo()',
119+
parserOptions: parserOptions
100120
}
101121
],
102122
invalid: [

0 commit comments

Comments
 (0)