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

Commit

Permalink
also provide default-only for non-objects
Browse files Browse the repository at this point in the history
  • Loading branch information
guybedford committed May 15, 2018
1 parent 04b472e commit 05089fc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/dataToEsm.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export default function dataToNamedExports (data, options = {}) {
const n = options.compact ? '' : '\n';
const declarationType = options.preferConst ? 'const' : 'var';

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

let namedExportCode = '';
Expand Down
5 changes: 5 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -513,5 +513,10 @@ describe( 'rollup-pluginutils', 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};' );
});

it ( 'default only for non-objects', function () {
var arr = ['a', 'b'];
assert.equal( dataToEsm( arr ), 'export default [\n\t"a",\n\t"b"\n];' );
});
});
});

0 comments on commit 05089fc

Please sign in to comment.