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

Commit

Permalink
support a namedExports false option
Browse files Browse the repository at this point in the history
  • Loading branch information
guybedford authored and lukastaegert committed May 21, 2018
1 parent 28983e0 commit 796bb63
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion README.md
Expand Up @@ -117,7 +117,8 @@ const esModuleSource = dataToEsm({
compact: false,
indent: '\t',
preferConst: false,
objectShorthand: false
objectShorthand: false,
namedExports: true
});
/*
Outputs the string ES module source:
Expand Down
3 changes: 3 additions & 0 deletions src/dataToEsm.js
Expand Up @@ -46,6 +46,9 @@ export default function dataToNamedExports (data, options = {}) {
const _ = options.compact ? '' : ' ';
const n = options.compact ? '' : '\n';
const declarationType = options.preferConst ? 'const' : 'var';

if (options.namedExports === false)
return `export default${ _ }${ serialize( data, options.compact ? null : t, '' ) };`;

let namedExportCode = '';
const defaultExportRows = [];
Expand Down
5 changes: 5 additions & 0 deletions test/test.js
Expand Up @@ -512,5 +512,10 @@ describe( 'rollup-pluginutils', function () {
it ( 'supports null serialize', function () {
assert.equal( dataToEsm( { null: null } ), 'export default {\n\t"null": null\n};\n' );
});

it ( 'supports default only', function () {
var arr = ['a', 'b'];
assert.equal( dataToEsm( { arr: arr }, { namedExports: false } ), 'export default {\n\tarr: [\n\t\t"a",\n\t\t"b"\n\t]\n};' );
});
});
});

0 comments on commit 796bb63

Please sign in to comment.