Skip to content

Commit 8ec74f8

Browse files
committed
mass-replace the JSON.parse(JSON.stringify(data)) pattern with our new helper
we will error handle json during load after #634 solidifies part of #637
1 parent 27adbd1 commit 8ec74f8

File tree

6 files changed

+21
-21
lines changed

6 files changed

+21
-21
lines changed

core/lib/annotation_exporter.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
var path = require('path'),
44
glob = require('glob'),
55
fs = require('fs-extra'),
6-
JSON5 = require('json5'),
76
_ = require('lodash'),
87
mp = require('./markdown_parser');
98

@@ -30,7 +29,7 @@ var annotations_exporter = function (pl) {
3029
oldAnnotations = oldAnnotations.replace('};', '}');
3130

3231
try {
33-
var oldAnnotationsJSON = JSON5.parse(oldAnnotations);
32+
var oldAnnotationsJSON = JSON.parse(oldAnnotations);
3433
} catch (ex) {
3534
console.log('There was an error parsing JSON for ' + paths.source.annotations + 'annotations.js');
3635
console.log(ex);

core/lib/list_item_hunter.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
var list_item_hunter = function () {
44

55
var extend = require('util')._extend,
6-
JSON5 = require('json5'),
76
pa = require('./pattern_assembler'),
87
smh = require('./style_modifier_hunter'),
98
plutils = require('./utilities'),
9+
jsonCopy = require('./json_copy'),
1010
Pattern = require('./object_factory').Pattern;
1111

1212
var pattern_assembler = new pa(),
@@ -42,7 +42,7 @@ var list_item_hunter = function () {
4242
//check for a local listitems.json file
4343
var listData;
4444
try {
45-
listData = JSON5.parse(JSON5.stringify(patternlab.listitems));
45+
listData = jsonCopy(patternlab.listitems, 'config.paths.source.data listitems');
4646
} catch (err) {
4747
console.log('There was an error parsing JSON for ' + pattern.relPath);
4848
console.log(err);
@@ -62,8 +62,8 @@ var list_item_hunter = function () {
6262
var globalData;
6363
var localData;
6464
try {
65-
globalData = JSON5.parse(JSON5.stringify(patternlab.data));
66-
localData = JSON5.parse(JSON5.stringify(pattern.jsonFileData));
65+
globalData = jsonCopy(patternlab.data, 'config.paths.source.data global data');
66+
localData = jsonCopy(pattern.jsonFileData, `${pattern.patternPartial} data`);
6767
} catch (err) {
6868
console.log('There was an error parsing JSON for ' + pattern.relPath);
6969
console.log(err);
@@ -87,7 +87,8 @@ var list_item_hunter = function () {
8787
//create a copy of the partial so as to not pollute it after the get_pattern_by_key call.
8888
var cleanPartialPattern;
8989
try {
90-
cleanPartialPattern = JSON5.parse(JSON5.stringify(partialPattern));
90+
cleanPartialPattern = JSON.parse(JSON.stringify(partialPattern));
91+
cleanPartialPattern = jsonCopy(partialPattern, `partial pattern ${partialName}`);
9192
} catch (err) {
9293
console.log('There was an error parsing JSON for ' + pattern.relPath);
9394
console.log(err);

core/lib/parameter_hunter.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
var parameter_hunter = function () {
44

55
var extend = require('util')._extend,
6-
JSON5 = require('json5'),
76
pa = require('./pattern_assembler'),
87
smh = require('./style_modifier_hunter'),
98
plutils = require('./utilities'),
109
style_modifier_hunter = new smh(),
10+
jsonCopy = require('./json_copy'),
1111
pattern_assembler = new pa();
1212

1313
/**
@@ -19,7 +19,7 @@ var parameter_hunter = function () {
1919
* The steps on a high-level are as follows:
2020
* * Further escape all escaped quotes and colons. Use the string
2121
* representation of their unicodes for this. This has the added bonus
22-
* of being interpreted correctly by JSON5.parse() without further
22+
* of being interpreted correctly by JSON.parse() without further
2323
* modification. This will be useful later in the function.
2424
* * Once escaped quotes are out of the way, we know the remaining quotes
2525
* are either key/value wrappers or wrapped within those wrappers. We know
@@ -260,9 +260,9 @@ var parameter_hunter = function () {
260260
var localData = {};
261261

262262
try {
263-
paramData = JSON5.parse(paramStringWellFormed);
264-
globalData = JSON5.parse(JSON5.stringify(patternlab.data));
265-
localData = JSON5.parse(JSON5.stringify(pattern.jsonFileData || {}));
263+
paramData = JSON.parse(paramStringWellFormed);
264+
globalData = jsonCopy(patternlab.data, 'config.paths.source.data global data');
265+
localData = jsonCopy(pattern.jsonFileData || {}, `pattern ${pattern.patternPartial} data`);
266266
} catch (err) {
267267
console.log('There was an error parsing JSON for ' + pattern.relPath);
268268
console.log(err);

core/lib/pattern_assembler.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ var path = require('path'),
1313
lih = require('./list_item_hunter'),
1414
smh = require('./style_modifier_hunter'),
1515
ph = require('./parameter_hunter'),
16-
ch = require('./changes_hunter'),
17-
JSON5 = require('json5');
16+
jsonCopy = require('./json_copy'),
17+
ch = require('./changes_hunter');
1818

1919
const markdown_parser = new mp();
2020
const changes_hunter = new ch();
@@ -476,7 +476,7 @@ var pattern_assembler = function () {
476476
//complete assembly of extended template
477477
//create a copy of the partial so as to not pollute it after the getPartial call.
478478
var partialPattern = getPartial(partial, patternlab);
479-
var cleanPartialPattern = JSON5.parse(JSON5.stringify(partialPattern));
479+
var cleanPartialPattern = jsonCopy(partialPattern, `partial pattern ${partial}`);
480480

481481
//if partial has style modifier data, replace the styleModifier value
482482
if (currentPattern.stylePartials && currentPattern.stylePartials.length > 0) {
@@ -494,7 +494,7 @@ var pattern_assembler = function () {
494494
linkRE = /(?:'|")(link\.[A-z0-9-_]+)(?:'|")/g;
495495

496496
//stringify the passed in object
497-
dataObjAsString = JSON5.stringify(obj);
497+
dataObjAsString = JSON.stringify(obj);
498498
if (!dataObjAsString) { return obj; }
499499

500500
//find matches
@@ -533,7 +533,7 @@ var pattern_assembler = function () {
533533

534534
var dataObj;
535535
try {
536-
dataObj = JSON5.parse(dataObjAsString);
536+
dataObj = JSON.parse(dataObjAsString);
537537
} catch (err) {
538538
console.log('There was an error parsing JSON for ' + key);
539539
console.log(err);

core/lib/patternlab.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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 = jsonCopy(patternlab.data, 'config.paths.source.data');
373+
allData = jsonCopy(patternlab.data, 'config.paths.source.data global 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 = jsonCopy(patternlab.data, 'config.paths.source.data');
424+
allFooterData = jsonCopy(patternlab.data, 'config.paths.source.data global data');
425425
} catch (err) {
426426
console.log('There was an error parsing JSON for ' + pattern.relPath);
427427
console.log(err);

core/lib/ui_builder.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"use strict";
22

33
var path = require('path');
4-
var JSON5 = require('json5');
54
var fs = require('fs-extra');
65
var ae = require('./annotation_exporter');
76
var of = require('./object_factory');
@@ -10,6 +9,7 @@ var pattern_assembler = require('./pattern_assembler')();
109
var plutils = require('./utilities');
1110
var eol = require('os').EOL;
1211
var _ = require('lodash');
12+
var jsonCopy = require('./json_copy');
1313

1414
var ui_builder = function () {
1515

@@ -435,7 +435,7 @@ var ui_builder = function () {
435435

436436
var allFooterData;
437437
try {
438-
allFooterData = JSON5.parse(JSON5.stringify(patternlab.data));
438+
allFooterData = jsonCopy(patternlab.data, 'config.paths.source.data plus patterns data');
439439
} catch (err) {
440440
console.log('There was an error parsing JSON for patternlab.data');
441441
console.log(err);

0 commit comments

Comments
 (0)