Skip to content

Commit 157b525

Browse files
committed
replace JSON5 with v8 implementation
1 parent 01e72a5 commit 157b525

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

core/lib/json_copy.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
"use strict";
2+
3+
const plutils = require('./utilities');
4+
const json_copy = (data, callee) => {
5+
try {
6+
return JSON.parse(JSON.stringify(data));
7+
} catch (e) {
8+
//this is unlikely to be hit due to the passed in data already being loaded using JSON parsers
9+
plutils.error(`JSON provided by ${callee} is invalid and cannot be copied`);
10+
return {};
11+
}
12+
};
13+
14+
module.exports = json_copy;

core/lib/patternlab.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ var diveSync = require('diveSync'),
2121
fs = require('fs-extra'),
2222
packageInfo = require('../../package.json'),
2323
plutils = require('./utilities'),
24+
jsonCopy = require('./json_copy'),
2425
PatternGraph = require('./pattern_graph').PatternGraph;
2526

2627
//register our log events
@@ -146,8 +147,7 @@ inherits(PatternLabEventEmitter, EventEmitter);
146147
var patternlab_engine = function (config) {
147148
'use strict';
148149

149-
var JSON5 = require('json5'),
150-
pa = require('./pattern_assembler'),
150+
var pa = require('./pattern_assembler'),
151151
pe = require('./pattern_exporter'),
152152
lh = require('./lineage_hunter'),
153153
ui = require('./ui_builder'),
@@ -370,7 +370,7 @@ var patternlab_engine = function (config) {
370370
//render the pattern, but first consolidate any data we may have
371371
var allData;
372372
try {
373-
allData = JSON5.parse(JSON5.stringify(patternlab.data));
373+
allData = jsonCopy(patternlab.data, 'config.paths.source.data');
374374
} catch (err) {
375375
console.log('There was an error parsing JSON for ' + pattern.relPath);
376376
console.log(err);
@@ -421,7 +421,7 @@ var patternlab_engine = function (config) {
421421

422422
var allFooterData;
423423
try {
424-
allFooterData = JSON5.parse(JSON5.stringify(patternlab.data));
424+
allFooterData = jsonCopy(patternlab.data, 'config.paths.source.data');
425425
} catch (err) {
426426
console.log('There was an error parsing JSON for ' + pattern.relPath);
427427
console.log(err);

0 commit comments

Comments
 (0)