Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert JSON parsing to stock implementation #639

Merged
merged 6 commits into from
Mar 21, 2017
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
3 changes: 1 addition & 2 deletions core/lib/annotation_exporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
var path = require('path'),
glob = require('glob'),
fs = require('fs-extra'),
JSON5 = require('json5'),
_ = require('lodash'),
mp = require('./markdown_parser');

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

try {
var oldAnnotationsJSON = JSON5.parse(oldAnnotations);
var oldAnnotationsJSON = JSON.parse(oldAnnotations);
} catch (ex) {
console.log('There was an error parsing JSON for ' + paths.source.annotations + 'annotations.js');
console.log(ex);
Expand Down
14 changes: 14 additions & 0 deletions core/lib/json_copy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"use strict";

const plutils = require('./utilities');
const json_copy = (data, callee) => {
try {
return JSON.parse(JSON.stringify(data));
} catch (e) {
//this is unlikely to be hit due to the passed in data already being loaded using JSON parsers
plutils.error(`JSON provided by ${callee} is invalid and cannot be copied`);
return {};
}
};

module.exports = json_copy;
11 changes: 6 additions & 5 deletions core/lib/list_item_hunter.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
var list_item_hunter = function () {

var extend = require('util')._extend,
JSON5 = require('json5'),
pa = require('./pattern_assembler'),
smh = require('./style_modifier_hunter'),
plutils = require('./utilities'),
jsonCopy = require('./json_copy'),
Pattern = require('./object_factory').Pattern;

var pattern_assembler = new pa(),
Expand Down Expand Up @@ -42,7 +42,7 @@ var list_item_hunter = function () {
//check for a local listitems.json file
var listData;
try {
listData = JSON5.parse(JSON5.stringify(patternlab.listitems));
listData = jsonCopy(patternlab.listitems, 'config.paths.source.data listitems');
} catch (err) {
console.log('There was an error parsing JSON for ' + pattern.relPath);
console.log(err);
Expand All @@ -62,8 +62,8 @@ var list_item_hunter = function () {
var globalData;
var localData;
try {
globalData = JSON5.parse(JSON5.stringify(patternlab.data));
localData = JSON5.parse(JSON5.stringify(pattern.jsonFileData));
globalData = jsonCopy(patternlab.data, 'config.paths.source.data global data');
localData = jsonCopy(pattern.jsonFileData, `${pattern.patternPartial} data`);
} catch (err) {
console.log('There was an error parsing JSON for ' + pattern.relPath);
console.log(err);
Expand All @@ -87,7 +87,8 @@ var list_item_hunter = function () {
//create a copy of the partial so as to not pollute it after the get_pattern_by_key call.
var cleanPartialPattern;
try {
cleanPartialPattern = JSON5.parse(JSON5.stringify(partialPattern));
cleanPartialPattern = JSON.parse(JSON.stringify(partialPattern));
cleanPartialPattern = jsonCopy(partialPattern, `partial pattern ${partialName}`);
} catch (err) {
console.log('There was an error parsing JSON for ' + pattern.relPath);
console.log(err);
Expand Down
10 changes: 5 additions & 5 deletions core/lib/parameter_hunter.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
var parameter_hunter = function () {

var extend = require('util')._extend,
JSON5 = require('json5'),
pa = require('./pattern_assembler'),
smh = require('./style_modifier_hunter'),
plutils = require('./utilities'),
style_modifier_hunter = new smh(),
jsonCopy = require('./json_copy'),
pattern_assembler = new pa();

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

try {
paramData = JSON5.parse(paramStringWellFormed);
globalData = JSON5.parse(JSON5.stringify(patternlab.data));
localData = JSON5.parse(JSON5.stringify(pattern.jsonFileData || {}));
paramData = JSON.parse(paramStringWellFormed);
globalData = jsonCopy(patternlab.data, 'config.paths.source.data global data');
localData = jsonCopy(pattern.jsonFileData || {}, `pattern ${pattern.patternPartial} data`);
} catch (err) {
console.log('There was an error parsing JSON for ' + pattern.relPath);
console.log(err);
Expand Down
10 changes: 5 additions & 5 deletions core/lib/pattern_assembler.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ var path = require('path'),
lih = require('./list_item_hunter'),
smh = require('./style_modifier_hunter'),
ph = require('./parameter_hunter'),
ch = require('./changes_hunter'),
JSON5 = require('json5');
jsonCopy = require('./json_copy'),
ch = require('./changes_hunter');

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

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

//stringify the passed in object
dataObjAsString = JSON5.stringify(obj);
dataObjAsString = JSON.stringify(obj);
if (!dataObjAsString) { return obj; }

//find matches
Expand Down Expand Up @@ -533,7 +533,7 @@ var pattern_assembler = function () {

var dataObj;
try {
dataObj = JSON5.parse(dataObjAsString);
dataObj = JSON.parse(dataObjAsString);
} catch (err) {
console.log('There was an error parsing JSON for ' + key);
console.log(err);
Expand Down
10 changes: 5 additions & 5 deletions core/lib/patternlab.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ var diveSync = require('diveSync'),
fs = require('fs-extra'),
packageInfo = require('../../package.json'),
plutils = require('./utilities'),
jsonCopy = require('./json_copy'),
PatternGraph = require('./pattern_graph').PatternGraph;

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

var JSON5 = require('json5'),
pa = require('./pattern_assembler'),
var pa = require('./pattern_assembler'),
pe = require('./pattern_exporter'),
lh = require('./lineage_hunter'),
ui = require('./ui_builder'),
Expand Down Expand Up @@ -180,7 +180,7 @@ var patternlab_engine = function (config) {
console.log(patternlab.package.version);
}

function getSupportedTemplateExtensions(){
function getSupportedTemplateExtensions() {
return patternlab.engines.getSupportedFileExtensions();
}

Expand Down Expand Up @@ -370,7 +370,7 @@ var patternlab_engine = function (config) {
//render the pattern, but first consolidate any data we may have
var allData;
try {
allData = JSON5.parse(JSON5.stringify(patternlab.data));
allData = jsonCopy(patternlab.data, 'config.paths.source.data global data');
} catch (err) {
console.log('There was an error parsing JSON for ' + pattern.relPath);
console.log(err);
Expand Down Expand Up @@ -421,7 +421,7 @@ var patternlab_engine = function (config) {

var allFooterData;
try {
allFooterData = JSON5.parse(JSON5.stringify(patternlab.data));
allFooterData = jsonCopy(patternlab.data, 'config.paths.source.data global data');
} catch (err) {
console.log('There was an error parsing JSON for ' + pattern.relPath);
console.log(err);
Expand Down
4 changes: 2 additions & 2 deletions core/lib/ui_builder.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"use strict";

var path = require('path');
var JSON5 = require('json5');
var fs = require('fs-extra');
var ae = require('./annotation_exporter');
var of = require('./object_factory');
Expand All @@ -10,6 +9,7 @@ var pattern_assembler = require('./pattern_assembler')();
var plutils = require('./utilities');
var eol = require('os').EOL;
var _ = require('lodash');
var jsonCopy = require('./json_copy');

var ui_builder = function () {

Expand Down Expand Up @@ -435,7 +435,7 @@ var ui_builder = function () {

var allFooterData;
try {
allFooterData = JSON5.parse(JSON5.stringify(patternlab.data));
allFooterData = jsonCopy(patternlab.data, 'config.paths.source.data plus patterns data');
} catch (err) {
console.log('There was an error parsing JSON for patternlab.data');
console.log(err);
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"glob": "^7.0.0",
"js-beautify": "^1.6.3",
"js-yaml": "^3.6.1",
"json5": "^0.5.0",
"lodash": "~4.13.1",
"markdown-it": "^6.0.1",
"node-fetch": "^1.6.0",
Expand Down