11'use strict' ;
22const {
33 isParenthesized,
4- isArrowToken,
54 isCommaToken,
65 isSemicolonToken,
76 isClosingParenToken,
@@ -13,7 +12,7 @@ const {extendFixRange} = require('./fix/index.js');
1312const needsSemicolon = require ( './utils/needs-semicolon.js' ) ;
1413const shouldAddParenthesesToExpressionStatementExpression = require ( './utils/should-add-parentheses-to-expression-statement-expression.js' ) ;
1514const shouldAddParenthesesToMemberExpressionObject = require ( './utils/should-add-parentheses-to-member-expression-object.js' ) ;
16- const { getParentheses} = require ( './utils/parentheses.js' ) ;
15+ const { getParentheses, getParenthesizedRange } = require ( './utils/parentheses.js' ) ;
1716const isFunctionSelfUsedInside = require ( './utils/is-function-self-used-inside.js' ) ;
1817const { isNodeMatches} = require ( './utils/is-node-matches.js' ) ;
1918const assertToken = require ( './utils/assert-token.js' ) ;
@@ -119,17 +118,7 @@ function getFixFunction(callExpression, functionInfo, context) {
119118
120119 const getForOfLoopHeadRange = ( ) => {
121120 const [ start ] = callExpression . range ;
122- let end ;
123- if ( callback . body . type === 'BlockStatement' ) {
124- end = callback . body . range [ 0 ] ;
125- } else {
126- // In this case, parentheses are not included in body location, so we look for `=>` token
127- // foo.forEach(bar => ({bar}))
128- // ^
129- const arrowToken = sourceCode . getTokenBefore ( callback . body , isArrowToken ) ;
130- end = arrowToken . range [ 1 ] ;
131- }
132-
121+ const [ end ] = getParenthesizedRange ( callback . body , sourceCode ) ;
133122 return [ start , end ] ;
134123 } ;
135124
@@ -215,7 +204,9 @@ function getFixFunction(callExpression, functionInfo, context) {
215204
216205 // Replace these with `for (const … of …) `
217206 // foo.forEach(bar => bar)
218- // ^^^^^^^^^^^^^^^^^^ (space after `=>` didn't included)
207+ // ^^^^^^^^^^^^^^^^^^^^^^
208+ // foo.forEach(bar => (bar))
209+ // ^^^^^^^^^^^^^^^^^^^^^^
219210 // foo.forEach(bar => {})
220211 // ^^^^^^^^^^^^^^^^^^^^^^
221212 // foo.forEach(function(bar) {})
0 commit comments