diff --git a/src/transform.js b/src/transform.js index 9e06dc7..0e5603c 100644 --- a/src/transform.js +++ b/src/transform.js @@ -261,10 +261,13 @@ export default function transformCommonjs ( code, id, isEntry, ignoreGlobal, ign if ( declarator._shouldRemove ) { magicString.remove( c, declarator.end ); } else { - keepDeclaration = true; - } + if ( !keepDeclaration ) { + magicString.remove( c, declarator.start ); + keepDeclaration = true; + } - c = declarator.end; + c = declarator.end; + } } if ( !keepDeclaration ) { diff --git a/test/form/multiple-var-declarations-b/input.js b/test/form/multiple-var-declarations-b/input.js new file mode 100644 index 0000000..c080007 --- /dev/null +++ b/test/form/multiple-var-declarations-b/input.js @@ -0,0 +1,4 @@ +var a = require('./a') + , b = 42; + +console.log( a, b ); \ No newline at end of file diff --git a/test/form/multiple-var-declarations-b/output.js b/test/form/multiple-var-declarations-b/output.js new file mode 100644 index 0000000..c2af7f4 --- /dev/null +++ b/test/form/multiple-var-declarations-b/output.js @@ -0,0 +1,13 @@ +import './a'; +import a from 'commonjs-proxy:./a'; + +var b = 42; + +console.log( a, b ); + +var input = { + +}; + +export default input; +export { input as __moduleExports }; \ No newline at end of file diff --git a/test/form/multiple-var-declarations-c/input.js b/test/form/multiple-var-declarations-c/input.js new file mode 100644 index 0000000..da506ce --- /dev/null +++ b/test/form/multiple-var-declarations-c/input.js @@ -0,0 +1,5 @@ +var a = 'a' + , b = require( './b' ) + , c = 'c'; + +console.log( a, b, c ); \ No newline at end of file diff --git a/test/form/multiple-var-declarations-c/output.js b/test/form/multiple-var-declarations-c/output.js new file mode 100644 index 0000000..cd331c6 --- /dev/null +++ b/test/form/multiple-var-declarations-c/output.js @@ -0,0 +1,14 @@ +import './b'; +import b from 'commonjs-proxy:./b'; + +var a = 'a' + , c = 'c'; + +console.log( a, b, c ); + +var input = { + +}; + +export default input; +export { input as __moduleExports }; \ No newline at end of file