From 05089fcb77fce35ee7585de75cfe627d21a69a3d Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Tue, 15 May 2018 13:18:30 +0200 Subject: [PATCH] also provide default-only for non-objects --- src/dataToEsm.js | 2 +- test/test.js | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/dataToEsm.js b/src/dataToEsm.js index 5603527..7f4823d 100644 --- a/src/dataToEsm.js +++ b/src/dataToEsm.js @@ -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 = ''; diff --git a/test/test.js b/test/test.js index f11c009..0479fb9 100644 --- a/test/test.js +++ b/test/test.js @@ -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];' ); + }); }); });