From 14c19c8dc34f9bd8e9e66700a0280f11d1a750ab Mon Sep 17 00:00:00 2001 From: John Pignata Date: Tue, 27 Oct 2015 16:54:56 -0400 Subject: [PATCH] Ensure value is always defined before access In parsing some JSX from relax/relax, we noticed the parser was choking on trying to access attributes of the loc attribute of a given node. It looks like we were checking for the presence of value in every other branch so this change hoists that check up around the processing. --- lib/cc/engine/analyzers/javascript/parser.js | 24 +++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/lib/cc/engine/analyzers/javascript/parser.js b/lib/cc/engine/analyzers/javascript/parser.js index 4e50aefd..d39f4418 100644 --- a/lib/cc/engine/analyzers/javascript/parser.js +++ b/lib/cc/engine/analyzers/javascript/parser.js @@ -32,17 +32,19 @@ var format = function(node) { if (node.hasOwnProperty(prop) && !prop.startsWith("_") && toScrub.indexOf(prop) === -1) { var value = node[prop]; - if (value && value.constructor === Array) { - result[prop] = value.map(function(p) { - return format(p) - }); - } else if (prop === "loc") { - result["start"] = value.start.line; - result["end"] = value.end.line; - } else if (value && typeof(value) === "object") { - result[prop] = format(value); - } else if (value) { - result[prop] = node[prop]; + if (value) { + if (value.constructor === Array) { + result[prop] = value.map(function(p) { + return format(p) + }); + } else if (prop === "loc") { + result["start"] = value.start.line; + result["end"] = value.end.line; + } else if (typeof(value) === "object") { + result[prop] = format(value); + } else { + result[prop] = node[prop]; + } } } }