Browse Source

ensure at least one newline between each statement

contingency-plan
Rich-Harris 10 years ago
parent
commit
2993d92776
  1. 5
      src/Bundle.js
  2. 2
      src/Module.js
  3. 9
      test/function/newline-after-comment/_config.js
  4. 4
      test/function/newline-after-comment/main.js

5
src/Bundle.js

@ -240,8 +240,9 @@ export default class Bundle {
magicString.addSource( new MagicString( commentBlock ) );
}
// add margin
const margin = Math.max( statement.margin[0], previousMargin );
// ensure there is always a newline between statements, and add
// additional newlines as necessary to reflect original source
const margin = Math.max( 2, statement.margin[0], previousMargin );
const newLines = new Array( margin ).join( '\n' );
// add the statement itself

2
src/Module.js

@ -43,7 +43,7 @@ export default class Module {
});
this.statements = ast.body.map( node => {
const magicString = this.magicString.snip( node.start, node.end ).prepend( '\n' ).append( '\n' );
const magicString = this.magicString.snip( node.start, node.end ).trim();
return new Statement( node, magicString, this );
});
} catch ( err ) {

9
test/function/newline-after-comment/_config.js

@ -0,0 +1,9 @@
var assert = require( 'assert' );
module.exports = {
description: 'inserts newline after comment',
exports: function ( exports ) {
assert.equal( exports(), 42 );
},
// solo: true
};

4
test/function/newline-after-comment/main.js

@ -0,0 +1,4 @@
// this comment should not affect the line below
export default function () {
return 42;
}
Loading…
Cancel
Save