From d9be5d628631eb90ee867fc3849f6b32c5214660 Mon Sep 17 00:00:00 2001 From: Mike Bostock Date: Thu, 28 May 2015 21:56:32 -0700 Subject: [PATCH 1/3] Fix for malformed output. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Without this change, you can get malformed stuff like this: var foo = function() { return "foo"; }var bar = function() { return "bar"; } By introducing a newline, a semicolon is implicitly inserted between statements when necessary: var foo = function() { return "foo"; } var bar = function() { return "bar"; } The indentation as a result of this commit is off, but I’m not sure how to fix it because the build fails for me. (I tested this by editing dist directly.) --- src/Module.js | 2 +- src/Statement.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Module.js b/src/Module.js index b27830d..90592f4 100644 --- a/src/Module.js +++ b/src/Module.js @@ -44,7 +44,7 @@ export default class Module { }); this.statements = ast.body.map( node => { - const magicString = this.magicString.snip( node.start, node.end ); + const magicString = this.magicString.snip( node.start, node.end ).append( '\n' ); return new Statement( node, magicString, this ); }); } catch ( err ) { diff --git a/src/Statement.js b/src/Statement.js index 042d939..5d8fd24 100644 --- a/src/Statement.js +++ b/src/Statement.js @@ -248,7 +248,7 @@ export default class Statement { } replaceIdentifiers ( names ) { - const magicString = this.magicString.clone().trim(); + const magicString = this.magicString.clone(); const replacementStack = [ names ]; const nameList = keys( names ); From f3c8eeee0ab3f4e0f2956be1184713a33f8e184c Mon Sep 17 00:00:00 2001 From: Mike Bostock Date: Thu, 28 May 2015 22:25:54 -0700 Subject: [PATCH 2/3] You get a newline! YOU get a newline! Everyone gets a newline! --- src/Module.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Module.js b/src/Module.js index 90592f4..f078324 100644 --- a/src/Module.js +++ b/src/Module.js @@ -44,7 +44,7 @@ export default class Module { }); this.statements = ast.body.map( node => { - const magicString = this.magicString.snip( node.start, node.end ).append( '\n' ); + const magicString = this.magicString.snip( node.start, node.end ).prepend( '\n' ).append( '\n' ); return new Statement( node, magicString, this ); }); } catch ( err ) { From acecb7f8627c007c659ac5736ffe276d3d2db74a Mon Sep 17 00:00:00 2001 From: Mike Bostock Date: Thu, 28 May 2015 22:28:33 -0700 Subject: [PATCH 3/3] Fix UMD exports. Use function(exports), not function('exports'). --- src/finalisers/umd.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/finalisers/umd.js b/src/finalisers/umd.js index 09164f7..490b60c 100644 --- a/src/finalisers/umd.js +++ b/src/finalisers/umd.js @@ -16,7 +16,7 @@ export default function umd ( bundle, magicString, exportMode, options ) { if ( exportMode === 'named' ) { amdDeps.unshift( `'exports'` ); - cjsDeps.unshift( `'exports'` ); + cjsDeps.unshift( `exports` ); globalDeps.unshift( `(global.${options.moduleName} = {})` ); args.unshift( 'exports' );