Browse Source

Merge pull request #857 from rollup/gh-852

put outro after export block, not before
rewrite
Rich Harris 8 years ago
committed by GitHub
parent
commit
573d517e3b
  1. 1
      src/Bundle.js
  2. 6
      src/finalisers/amd.js
  3. 1
      src/finalisers/cjs.js
  4. 7
      src/finalisers/es.js
  5. 1
      src/finalisers/iife.js
  6. 6
      src/finalisers/umd.js
  7. 3
      test/form/intro-and-outro/_config.js
  8. 4
      test/form/intro-and-outro/_expected/amd.js
  9. 4
      test/form/intro-and-outro/_expected/cjs.js
  10. 4
      test/form/intro-and-outro/_expected/es.js
  11. 6
      test/form/intro-and-outro/_expected/iife.js
  12. 10
      test/form/intro-and-outro/_expected/umd.js
  13. 2
      test/form/intro-and-outro/main.js

1
src/Bundle.js

@ -320,7 +320,6 @@ export default class Bundle {
.join( '\n\n' );
if ( intro ) magicString.prepend( intro + '\n' );
if ( options.outro ) magicString.append( '\n' + options.outro );
const indentString = getIndentString( magicString, options );

6
src/finalisers/amd.js

@ -25,10 +25,8 @@ export default function amd ( bundle, magicString, { exportMode, indentString },
const exportBlock = getExportBlock( bundle.entryModule, exportMode );
if ( exportBlock ) magicString.append( '\n\n' + exportBlock );
if ( exportMode === 'named' ) {
magicString.append( `\n\n${esModuleExport}` );
}
if ( exportMode === 'named' ) magicString.append( `\n\n${esModuleExport}` );
if ( options.outro ) magicString.append( `\n${options.outro}` );
return magicString
.indent( indentString )

1
src/finalisers/cjs.js

@ -44,6 +44,7 @@ export default function cjs ( bundle, magicString, { exportMode }, options ) {
const exportBlock = getExportBlock( bundle.entryModule, exportMode, 'module.exports =' );
if ( exportBlock ) magicString.append( '\n\n' + exportBlock );
if ( options.outro ) magicString.append( `\n${options.outro}` );
return magicString;
}

7
src/finalisers/es.js

@ -4,7 +4,7 @@ function notDefault ( name ) {
return name !== 'default';
}
export default function es ( bundle, magicString ) {
export default function es ( bundle, magicString, config, options ) {
const importBlock = bundle.externalModules
.map( module => {
const specifiers = [];
@ -71,9 +71,8 @@ export default function es ( bundle, magicString ) {
exportBlock += `export default ${module.traceExport( 'default' ).render( true )};`;
}
if ( exportBlock ) {
magicString.append( '\n\n' + exportBlock.trim() );
}
if ( exportBlock ) magicString.append( '\n\n' + exportBlock.trim() );
if ( options.outro ) magicString.append( `\n${options.outro}` );
return magicString.trim();
}

1
src/finalisers/iife.js

@ -54,6 +54,7 @@ export default function iife ( bundle, magicString, { exportMode, indentString }
if ( useStrict ) magicString.prepend( useStrict + '\n\n' );
const exportBlock = getExportBlock( bundle.entryModule, exportMode );
if ( exportBlock ) magicString.append( '\n\n' + exportBlock );
if ( options.outro ) magicString.append( `\n${options.outro}` );
return magicString
.indent( indentString )

6
src/finalisers/umd.js

@ -69,10 +69,8 @@ export default function umd ( bundle, magicString, { exportMode, indentString },
const exportBlock = getExportBlock( bundle.entryModule, exportMode );
if ( exportBlock ) magicString.append( '\n\n' + exportBlock );
if (exportMode === 'named') {
magicString.append( `\n\n${esModuleExport}` );
}
if ( exportMode === 'named' ) magicString.append( `\n\n${esModuleExport}` );
if ( options.outro ) magicString.append( `\n${options.outro}` );
return magicString
.trim()

3
test/form/intro-and-outro/_config.js

@ -2,6 +2,7 @@ module.exports = {
description: 'adds an intro/outro',
options: {
intro: '/* this is an intro */',
outro: '/* this is an outro */'
outro: '/* this is an outro */',
moduleName: 'foo'
}
};

4
test/form/intro-and-outro/_expected/amd.js

@ -2,6 +2,10 @@ define(function () { 'use strict';
/* this is an intro */
console.log( 'hello world' );
var main = 42;
return main;
/* this is an outro */
});

4
test/form/intro-and-outro/_expected/cjs.js

@ -2,4 +2,8 @@
/* this is an intro */
console.log( 'hello world' );
var main = 42;
module.exports = main;
/* this is an outro */

4
test/form/intro-and-outro/_expected/es.js

@ -1,3 +1,7 @@
/* this is an intro */
console.log( 'hello world' );
var main = 42;
export default main;
/* this is an outro */

6
test/form/intro-and-outro/_expected/iife.js

@ -1,8 +1,12 @@
(function () {
var foo = (function () {
'use strict';
/* this is an intro */
console.log( 'hello world' );
var main = 42;
return main;
/* this is an outro */
}());

10
test/form/intro-and-outro/_expected/umd.js

@ -1,11 +1,15 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory() :
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(factory());
(global.foo = factory());
}(this, (function () { 'use strict';
/* this is an intro */
console.log( 'hello world' );
var main = 42;
return main;
/* this is an outro */
})));
})));

2
test/form/intro-and-outro/main.js

@ -1 +1,3 @@
console.log( 'hello world' );
export default 42;

Loading…
Cancel
Save