@@ -59,57 +59,57 @@ module.exports = {
5959 // not yet encountered any use of this.state which we have chosen not to
6060 // analyze. If we encounter any such usage (like this.state being spread as
6161 // JSX attributes), then this is again set to null.
62- let classInfo = null ;
62+ var classInfo = null ;
6363
6464 // Returns true if the given node is possibly a reference to `this.state`.
6565 function isStateReference ( node ) {
6666 node = uncast ( node ) ;
6767
68- const isDirectStateReference =
68+ var isDirectStateReference =
6969 node . type === 'MemberExpression' &&
7070 isThisExpression ( node . object ) &&
7171 node . property . name === 'state' ;
7272
73- const isAliasedStateReference =
73+ var isAliasedStateReference =
7474 node . type === 'Identifier' &&
7575 classInfo . aliases &&
76- classInfo . aliases . has ( node . name ) ;
76+ classInfo . aliases . indexOf ( node . name ) >= 0 ;
7777
7878 return isDirectStateReference || isAliasedStateReference ;
7979 }
8080
8181 // Takes an ObjectExpression node and adds all named Property nodes to the
8282 // current set of state fields.
8383 function addStateFields ( node ) {
84- for ( let prop of node . properties ) {
84+ node . properties . forEach ( function ( prop ) {
8585 if ( prop . type === 'Property' && getName ( prop . key ) !== null ) {
86- classInfo . stateFields . add ( prop ) ;
86+ classInfo . stateFields . push ( prop ) ;
8787 }
88- }
88+ } ) ;
8989 }
9090
9191 // Adds the name of the given node as a used state field if the node is an
9292 // Identifier or a Literal. Other node types are ignored.
9393 function addUsedStateField ( node ) {
94- let name = getName ( node ) ;
94+ var name = getName ( node ) ;
9595 if ( name ) {
96- classInfo . usedStateFields . add ( name ) ;
96+ classInfo . usedStateFields . push ( name ) ;
9797 }
9898 }
9999
100100 // Records used state fields and new aliases for an ObjectPattern which
101101 // destructures `this.state`.
102102 function handleStateDestructuring ( node ) {
103- for ( let prop of node . properties ) {
103+ node . properties . forEach ( function ( prop ) {
104104 if ( prop . type === 'Property' ) {
105105 addUsedStateField ( prop . key ) ;
106106 } else if (
107107 prop . type === 'ExperimentalRestProperty' &&
108108 classInfo . aliases
109109 ) {
110- classInfo . aliases . add ( getName ( prop . argument ) ) ;
110+ classInfo . aliases . push ( getName ( prop . argument ) ) ;
111111 }
112- }
112+ } ) ;
113113 }
114114
115115 // Used to record used state fields and new aliases for both
@@ -118,23 +118,23 @@ module.exports = {
118118 switch ( left . type ) {
119119 case 'Identifier' :
120120 if ( isStateReference ( right ) && classInfo . aliases ) {
121- classInfo . aliases . add ( left . name ) ;
121+ classInfo . aliases . push ( left . name ) ;
122122 }
123123 break ;
124124 case 'ObjectPattern' :
125125 if ( isStateReference ( right ) ) {
126126 handleStateDestructuring ( left ) ;
127127 } else if ( isThisExpression ( right ) && classInfo . aliases ) {
128- for ( let prop of left . properties ) {
128+ left . properties . forEach ( function ( prop ) {
129129 if ( prop . type === 'Property' && getName ( prop . key ) === 'state' ) {
130- let name = getName ( prop . value ) ;
130+ var name = getName ( prop . value ) ;
131131 if ( name ) {
132- classInfo . aliases . add ( name ) ;
132+ classInfo . aliases . push ( name ) ;
133133 } else if ( prop . value . type === 'ObjectPattern' ) {
134134 handleStateDestructuring ( prop . value ) ;
135135 }
136136 }
137- }
137+ } ) ;
138138 }
139139 break ;
140140 default :
@@ -143,19 +143,19 @@ module.exports = {
143143 }
144144
145145 return {
146- ClassDeclaration ( node ) {
146+ ClassDeclaration : function ( node ) {
147147 // Simple heuristic for determining whether we're in a React component.
148- const isReactComponent = node . body . body . some (
149- child => isMethodDefinitionWithName ( child , 'render' )
150- ) ;
148+ var isReactComponent = node . body . body . some ( function ( child ) {
149+ return isMethodDefinitionWithName ( child , 'render' ) ;
150+ } ) ;
151151
152152 if ( isReactComponent ) {
153153 classInfo = {
154154 // Set of nodes where state fields were defined.
155- stateFields : new Set ( ) ,
155+ stateFields : [ ] ,
156156
157157 // Set of names of state fields that we've seen used.
158- usedStateFields : new Set ( ) ,
158+ usedStateFields : [ ] ,
159159
160160 // Names of local variables that may be pointing to this.state. To
161161 // track this properly, we would need to keep track of all locals,
@@ -167,21 +167,21 @@ module.exports = {
167167 }
168168 } ,
169169
170- 'ClassDeclaration:exit' ( ) {
170+ 'ClassDeclaration:exit' : function ( ) {
171171 if ( ! classInfo ) {
172172 return ;
173173 }
174174 // Report all unused state fields.
175- for ( let node of classInfo . stateFields ) {
176- let name = getName ( node . key ) ;
177- if ( ! classInfo . usedStateFields . has ( name ) ) {
178- context . report ( node , ` Unused state field: ' ${ name } '` ) ;
175+ classInfo . stateFields . forEach ( function ( node ) {
176+ var name = getName ( node . key ) ;
177+ if ( classInfo . usedStateFields . indexOf ( name ) < 0 ) {
178+ context . report ( node , ' Unused state field: \'' + name + '\'' ) ;
179179 }
180- }
180+ } ) ;
181181 classInfo = null ;
182182 } ,
183183
184- CallExpression ( node ) {
184+ CallExpression : function ( node ) {
185185 if ( ! classInfo ) {
186186 return ;
187187 }
@@ -198,7 +198,7 @@ module.exports = {
198198 }
199199 } ,
200200
201- ClassProperty ( node ) {
201+ ClassProperty : function ( node ) {
202202 if ( ! classInfo ) {
203203 return ;
204204 }
@@ -214,23 +214,23 @@ module.exports = {
214214 }
215215 } ,
216216
217- MethodDefinition ( ) {
217+ MethodDefinition : function ( ) {
218218 if ( ! classInfo ) {
219219 return ;
220220 }
221221 // Create a new set for this.state aliases local to this method.
222- classInfo . aliases = new Set ( ) ;
222+ classInfo . aliases = [ ] ;
223223 } ,
224224
225- 'MethodDefinition:exit' ( ) {
225+ 'MethodDefinition:exit' : function ( ) {
226226 if ( ! classInfo ) {
227227 return ;
228228 }
229229 // Forget our set of local aliases.
230230 classInfo . aliases = null ;
231231 } ,
232232
233- AssignmentExpression ( node ) {
233+ AssignmentExpression : function ( node ) {
234234 if ( ! classInfo ) {
235235 return ;
236236 }
@@ -242,7 +242,7 @@ module.exports = {
242242 node . right . type === 'ObjectExpression'
243243 ) {
244244 // Find the nearest function expression containing this assignment.
245- let fn = node ;
245+ var fn = node ;
246246 while ( fn . type !== 'FunctionExpression' && fn . parent ) {
247247 fn = fn . parent ;
248248 }
@@ -261,14 +261,14 @@ module.exports = {
261261 }
262262 } ,
263263
264- VariableDeclarator ( node ) {
264+ VariableDeclarator : function ( node ) {
265265 if ( ! classInfo || ! node . init ) {
266266 return ;
267267 }
268268 handleAssignment ( node . id , node . init ) ;
269269 } ,
270270
271- MemberExpression ( node ) {
271+ MemberExpression : function ( node ) {
272272 if ( ! classInfo ) {
273273 return ;
274274 }
@@ -283,13 +283,13 @@ module.exports = {
283283 }
284284 } ,
285285
286- JSXSpreadAttribute ( node ) {
286+ JSXSpreadAttribute : function ( node ) {
287287 if ( classInfo && isStateReference ( node . argument ) ) {
288288 classInfo = null ;
289289 }
290290 } ,
291291
292- ExperimentalSpreadProperty ( node ) {
292+ ExperimentalSpreadProperty : function ( node ) {
293293 if ( classInfo && isStateReference ( node . argument ) ) {
294294 classInfo = null ;
295295 }
0 commit comments