Skip to content

Commit b267d19

Browse files
committed
Fix jsx-curly-spacing crash with ESLint 3 (fixes #1779)
1 parent 0e9f1b1 commit b267d19

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

lib/rules/jsx-curly-spacing.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,16 @@ module.exports = {
228228
message: `There should be no space after '${token.value}'`,
229229
fix: function(fixer) {
230230
const nextToken = sourceCode.getTokenAfter(token);
231-
const nextComment = sourceCode.getCommentsAfter(token);
231+
let nextComment;
232+
233+
// ESLint >=4.x
234+
if (sourceCode.getCommentsAfter) {
235+
nextComment = sourceCode.getCommentsAfter(token);
236+
// ESLint 3.x
237+
} else {
238+
const potentialComment = sourceCode.getTokenAfter(token, {includeComments: true});
239+
nextComment = nextToken === potentialComment ? [] : [potentialComment];
240+
}
232241

233242
// Take comments into consideration to narrow the fix range to what is actually affected. (See #1414)
234243
if (nextComment.length > 0) {
@@ -253,7 +262,16 @@ module.exports = {
253262
message: `There should be no space before '${token.value}'`,
254263
fix: function(fixer) {
255264
const previousToken = sourceCode.getTokenBefore(token);
256-
const previousComment = sourceCode.getCommentsBefore(token);
265+
let previousComment;
266+
267+
// ESLint >=4.x
268+
if (sourceCode.getCommentsBefore) {
269+
previousComment = sourceCode.getCommentsBefore(token);
270+
// ESLint 3.x
271+
} else {
272+
const potentialComment = sourceCode.getTokenBefore(token, {includeComments: true});
273+
previousComment = previousToken === potentialComment ? [] : [potentialComment];
274+
}
257275

258276
// Take comments into consideration to narrow the fix range to what is actually affected. (See #1414)
259277
if (previousComment.length > 0) {

0 commit comments

Comments
 (0)