Skip to content
This repository has been archived by the owner on Jun 27, 2019. It is now read-only.

Commit

Permalink
13: retain leading comments when replacing the imports
Browse files Browse the repository at this point in the history
  • Loading branch information
reergymerej committed Jun 2, 2016
1 parent 6060473 commit 560f0aa
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 0 deletions.
61 changes: 61 additions & 0 deletions test/fixtures/comments.input.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* top of file
*/
'use strict';
// after use strict
var a = 'a';
/*
* after var a
*/

// before foo
// const foo = 123;
// after foo

// before other imports
// import Funk from 'funky-town';
// after other imports

// All comments between an expression and import React should remain.

// before blah
// const blah = 111;
// after blah

// before react import
import React, {
Platform,
NativeModules,
} from 'react-native';
// after imports

// before Spaghetti
import Spaghetti from 'food';
// after Spaghetti

/**
* comment above class
*/
export default class Foo extends React.Component {
static get propTypes() {
return {};
// bottom of propTypes
}

// above componentWillMount
componentWillMount() {}

/**
* multi-line comment above foo
* @param {String} blah
* @return {undefined}
*/
foo(blah) {}

render() {
// top of render
return;
}
}

// EOF
61 changes: 61 additions & 0 deletions test/fixtures/comments.output.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* top of file
*/
'use strict';
// after use strict
var a = 'a';

/*
* after var a
*/

// before foo
// const foo = 123;
// after foo

// before other imports
// import Funk from 'funky-town';
// after other imports

// All comments between an expression and import React should remain.

// before blah
// const blah = 111;
// after blah

// before react import
import React from 'react';

import {Platform, NativeModules} from 'react-native';
// after imports

// before Spaghetti
import Spaghetti from 'food';
// after Spaghetti

/**
* comment above class
*/
export default class Foo extends React.Component {
static get propTypes() {
return {};
// bottom of propTypes
}

// above componentWillMount
componentWillMount() {}

/**
* multi-line comment above foo
* @param {String} blah
* @return {undefined}
*/
foo(blah) {}

render() {
// top of render
return;
}
}

// EOF
1 change: 1 addition & 0 deletions transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ export default function(file, api, options) {
))
}

allImports[0].comments = path.node.comments;
j(path).replaceWith(
allImports
);
Expand Down

0 comments on commit 560f0aa

Please sign in to comment.