Skip to content

Commit ab59f10

Browse files
committed
merge dev into dev-3.0 after
part of #639
2 parents 50a4660 + 2e86e27 commit ab59f10

File tree

8 files changed

+35
-23
lines changed

8 files changed

+35
-23
lines changed

core/lib/annotation_exporter.js

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

@@ -30,7 +29,7 @@ const 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/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/list_item_hunter.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
const list_item_hunter = function () {
44
const extend = require('util')._extend;
5-
const JSON5 = require('json5');
65
const pa = require('./pattern_assembler');
76
const smh = require('./style_modifier_hunter');
87
const plutils = require('./utilities');
@@ -41,7 +40,7 @@ const list_item_hunter = function () {
4140
//check for a local listitems.json file
4241
let listData;
4342
try {
44-
listData = JSON5.parse(JSON5.stringify(patternlab.listitems));
43+
listData = jsonCopy(patternlab.listitems, 'config.paths.source.data listitems');
4544
} catch (err) {
4645
console.log('There was an error parsing JSON for ' + pattern.relPath);
4746
console.log(err);
@@ -61,8 +60,8 @@ const list_item_hunter = function () {
6160
let globalData;
6261
let localData;
6362
try {
64-
globalData = JSON5.parse(JSON5.stringify(patternlab.data));
65-
localData = JSON5.parse(JSON5.stringify(pattern.jsonFileData));
63+
globalData = jsonCopy(patternlab.data, 'config.paths.source.data global data');
64+
localData = jsonCopy(pattern.jsonFileData, `${pattern.patternPartial} data`);
6665
} catch (err) {
6766
console.log('There was an error parsing JSON for ' + pattern.relPath);
6867
console.log(err);
@@ -86,7 +85,8 @@ const list_item_hunter = function () {
8685
//create a copy of the partial so as to not pollute it after the get_pattern_by_key call.
8786
let cleanPartialPattern;
8887
try {
89-
cleanPartialPattern = JSON5.parse(JSON5.stringify(partialPattern));
88+
cleanPartialPattern = JSON.parse(JSON.stringify(partialPattern));
89+
cleanPartialPattern = jsonCopy(partialPattern, `partial pattern ${partialName}`);
9090
} catch (err) {
9191
console.log('There was an error parsing JSON for ' + pattern.relPath);
9292
console.log(err);

core/lib/parameter_hunter.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
const parameter_hunter = function () {
44
const extend = require('util')._extend;
5-
const JSON5 = require('json5');
5+
const jsonCopy = require('./json_copy');
66
const pa = require('./pattern_assembler');
77
const smh = require('./style_modifier_hunter');
88
const plutils = require('./utilities');
@@ -18,7 +18,7 @@ const parameter_hunter = function () {
1818
* The steps on a high-level are as follows:
1919
* * Further escape all escaped quotes and colons. Use the string
2020
* representation of their unicodes for this. This has the added bonus
21-
* of being interpreted correctly by JSON5.parse() without further
21+
* of being interpreted correctly by JSON.parse() without further
2222
* modification. This will be useful later in the function.
2323
* * Once escaped quotes are out of the way, we know the remaining quotes
2424
* are either key/value wrappers or wrapped within those wrappers. We know
@@ -259,9 +259,9 @@ const parameter_hunter = function () {
259259
let localData = {};
260260

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

core/lib/pattern_assembler.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const lih = require('./list_item_hunter');
1313
const smh = require('./style_modifier_hunter');
1414
const ph = require('./parameter_hunter');
1515
const ch = require('./changes_hunter');
16-
const JSON5 = require('json5');
16+
const jsonCopy = require('./json_copy');
1717
const markdown_parser = new mp();
1818
const changes_hunter = new ch();
1919

@@ -473,7 +473,7 @@ const pattern_assembler = function () {
473473
//complete assembly of extended template
474474
//create a copy of the partial so as to not pollute it after the getPartial call.
475475
var partialPattern = getPartial(partial, patternlab);
476-
var cleanPartialPattern = JSON5.parse(JSON5.stringify(partialPattern));
476+
var cleanPartialPattern = jsonCopy(partialPattern, `partial pattern ${partial}`);
477477

478478
//if partial has style modifier data, replace the styleModifier value
479479
if (currentPattern.stylePartials && currentPattern.stylePartials.length > 0) {
@@ -491,7 +491,7 @@ const pattern_assembler = function () {
491491
linkRE = /(?:'|")(link\.[A-z0-9-_]+)(?:'|")/g;
492492

493493
//stringify the passed in object
494-
dataObjAsString = JSON5.stringify(obj);
494+
dataObjAsString = JSON.stringify(obj);
495495
if (!dataObjAsString) { return obj; }
496496

497497
//find matches
@@ -530,7 +530,7 @@ const pattern_assembler = function () {
530530

531531
var dataObj;
532532
try {
533-
dataObj = JSON5.parse(dataObjAsString);
533+
dataObj = JSON.parse(dataObjAsString);
534534
} catch (err) {
535535
console.log('There was an error parsing JSON for ' + key);
536536
console.log(err);

core/lib/patternlab.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const pm = require('./plugin_manager');
2222
const fs = require('fs-extra');
2323
const packageInfo = require('../../package.json');
2424
const plutils = require('./utilities');
25+
const jsonCopy = require('./json_copy');
2526
const PatternGraph = require('./pattern_graph').PatternGraph;
2627

2728
//register our log events
@@ -171,7 +172,6 @@ inherits(PatternLabEventEmitter, EventEmitter);
171172
const patternlab_engine = function (config) {
172173
'use strict';
173174

174-
const JSON5 = require('json5');
175175
const pa = require('./pattern_assembler');
176176
const pe = require('./pattern_exporter');
177177
const lh = require('./lineage_hunter');
@@ -206,7 +206,7 @@ const patternlab_engine = function (config) {
206206
console.log(patternlab.package.version);
207207
}
208208

209-
function getSupportedTemplateExtensions(){
209+
function getSupportedTemplateExtensions() {
210210
return patternlab.engines.getSupportedFileExtensions();
211211
}
212212

@@ -396,7 +396,7 @@ const patternlab_engine = function (config) {
396396
//render the pattern, but first consolidate any data we may have
397397
let allData;
398398
try {
399-
allData = JSON5.parse(JSON5.stringify(patternlab.data));
399+
allData = jsonCopy(patternlab.data, 'config.paths.source.data global data');
400400
} catch (err) {
401401
console.log('There was an error parsing JSON for ' + pattern.relPath);
402402
console.log(err);
@@ -447,7 +447,7 @@ const patternlab_engine = function (config) {
447447

448448
let allFooterData;
449449
try {
450-
allFooterData = JSON5.parse(JSON5.stringify(patternlab.data));
450+
allFooterData = jsonCopy(patternlab.data, 'config.paths.source.data global data');
451451
} catch (err) {
452452
console.log('There was an error parsing JSON for ' + pattern.relPath);
453453
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,7 @@
11
"use strict";
22

33
const path = require('path');
4-
const JSON5 = require('json5');
4+
const jsonCopy = require('./json_copy');
55
const ae = require('./annotation_exporter');
66
const of = require('./object_factory');
77
const Pattern = of.Pattern;
@@ -437,7 +437,7 @@ const ui_builder = function () {
437437

438438
let allFooterData;
439439
try {
440-
allFooterData = JSON5.parse(JSON5.stringify(patternlab.data));
440+
allFooterData = jsonCopy(patternlab.data, 'config.paths.source.data plus patterns data');
441441
} catch (err) {
442442
console.log('There was an error parsing JSON for patternlab.data');
443443
console.log(err);

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
"glob": "^7.0.0",
1414
"js-beautify": "^1.6.3",
1515
"js-yaml": "^3.6.1",
16-
"json5": "^0.5.0",
1716
"lodash": "~4.13.1",
1817
"markdown-it": "^6.0.1",
1918
"node-fetch": "^1.6.0",

0 commit comments

Comments
 (0)