This repository was archived by the owner on Dec 22, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +16
-2
lines changed Expand file tree Collapse file tree 2 files changed +16
-2
lines changed Original file line number Diff line number Diff line change 22 MIT License http://www.opensource.org/licenses/mit-license.php
33 Author Tobias Koppers @sokra
44*/
5+
6+ import util from 'util' ;
57import JSON5 from 'json5' ;
68
79function Json5Loader ( source ) {
@@ -13,7 +15,7 @@ function Json5Loader(source) {
1315 throw new Error ( 'Error parsing JSON5' , ( e ) ) ;
1416 }
1517
16- return `module.exports = ${ JSON . stringify ( value , null , '\t' ) } ` ;
18+ return `module.exports = ${ util . inspect ( value , { depth : null } ) } ` ;
1719}
1820
1921export default Json5Loader ;
Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ describe(PROJECT_NAME, () => {
1111
1212 test ( 'should convert to requires' , ( done ) => {
1313 const content = Json5Loader . call ( { } , staticJson5 ) ;
14- expect ( content ) . toBe ( 'module.exports = {\n\t" name": " test"\n }' ) ;
14+ expect ( content ) . toBe ( 'module.exports = { name: \' test\' }' ) ;
1515 done ( ) ;
1616 } ) ;
1717
@@ -22,4 +22,16 @@ describe(PROJECT_NAME, () => {
2222 } ) . toThrow ( 'Error parsing JSON5' ) ;
2323 done ( ) ;
2424 } ) ;
25+
26+ test ( 'should preserve Infinity' , ( done ) => {
27+ const content = Json5Loader . call ( { } , '{to : Infinity}' ) ;
28+ expect ( content ) . toBe ( 'module.exports = { to: Infinity }' ) ;
29+ done ( ) ;
30+ } ) ;
31+
32+ test ( 'should preserve NaN' , ( done ) => {
33+ const content = Json5Loader . call ( { } , '{nan : NaN}' ) ;
34+ expect ( content ) . toBe ( 'module.exports = { nan: NaN }' ) ;
35+ done ( ) ;
36+ } ) ;
2537} ) ;
You can’t perform that action at this time.
0 commit comments