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

Support null serialization #34

Merged
merged 1 commit into from
May 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/dataToEsm.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ function serialize (obj, indent, baseIndent) {
return 'NaN';
if (Array.isArray(obj))
return serializeArray(obj, indent, baseIndent);
if (obj === null)
return 'null';
if (typeof obj === 'object')
return serializeObject(obj, indent, baseIndent);
return JSON.stringify(obj);
Expand Down
4 changes: 4 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -508,5 +508,9 @@ describe( 'rollup-pluginutils', function () {
var arr = ['a', 'b'];
assert.equal( dataToEsm( { arr: arr } ), 'export var arr = [\n\t"a",\n\t"b"\n];\nexport default {\n\tarr: arr\n};\n' );
});

it ( 'supports null serialize', function () {
assert.equal( dataToEsm( { null: null } ), 'export default {\n\t"null": null\n};\n' );
});
});
});