Skip to content

Commit

Permalink
Teach invalid-requires to better handle comments
Browse files Browse the repository at this point in the history
When converting a require block like:

```js
var foo = require('foo'),
  // A comment
  bar = require('bar');
```

this transform was producing the unusual output:

```js
var foo = require('foo');

var // A comment
bar = require('bar');
```

This commit fixes this by moving the comment from the require statement
declaration up to the variable declaration.
  • Loading branch information
lencioni committed Feb 26, 2016
1 parent f7e98d0 commit 8954850
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 1 deletion.
1 change: 0 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
node_modules
test/invalid-requires-test.js
2 changes: 2 additions & 0 deletions test/invalid-requires-test.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
/* eslint-disable one-var */
var foo = require('foo'),
// A comment
bar = require('bar');
3 changes: 3 additions & 0 deletions test/invalid-requires-test.output.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
/* eslint-disable one-var */
var foo = require('foo');

// A comment
var bar = require('bar');
3 changes: 3 additions & 0 deletions transforms/invalid-requires.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ module.exports = function(file, api) {

if (i == 0) {
variableDeclaration.comments = requireStatement.value.comments;
} else if (declaration.comments) {
variableDeclaration.comments = declaration.comments;
declaration.comments = null;
}

return variableDeclaration;
Expand Down

0 comments on commit 8954850

Please sign in to comment.