Browse Source

prevent content around synthetic nodes being overwritten twice - fixes #105

module-order
Rich-Harris 9 years ago
parent
commit
c903bb2e4e
  1. 6
      src/Module.js
  2. 3
      test/function/handles-multiple-declarations/_config.js
  3. 2
      test/function/handles-multiple-declarations/main.js

6
src/Module.js

@ -515,8 +515,12 @@ export default class Module {
// should be split up. Otherwise, we may end up including code we
// don't need, just because an unwanted declarator is included
if ( node.type === 'VariableDeclaration' && node.declarations.length > 1 ) {
// remove the leading var/let/const
// remove the leading var/let/const... UNLESS the previous node
// was also a synthetic node, in which case it'll get removed anyway
const lastStatement = statements[ statements.length - 1 ];
if ( !lastStatement || !lastStatement.node.isSynthetic ) {
this.magicString.remove( node.start, node.declarations[0].start );
}
node.declarations.forEach( declarator => {
const { start, end } = declarator;

3
test/function/handles-multiple-declarations/_config.js

@ -0,0 +1,3 @@
module.exports = {
description: 'handles multiple declaration blocks with multiple declarations (#105)'
};

2
test/function/handles-multiple-declarations/main.js

@ -0,0 +1,2 @@
var a, b;
var c, d;
Loading…
Cancel
Save