Skip to content
This repository has been archived by the owner on Aug 4, 2021. It is now read-only.

Commit

Permalink
fix another var rewrite bug (#181)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich-Harris committed Mar 11, 2017
1 parent 91fbafb commit 9bf49e1
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/transform.js
Expand Up @@ -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 ) {
Expand Down
4 changes: 4 additions & 0 deletions test/form/multiple-var-declarations-b/input.js
@@ -0,0 +1,4 @@
var a = require('./a')
, b = 42;

console.log( a, b );
13 changes: 13 additions & 0 deletions 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 };
5 changes: 5 additions & 0 deletions 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 );
14 changes: 14 additions & 0 deletions 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 };

0 comments on commit 9bf49e1

Please sign in to comment.