From 464cf296a915b3fa7d6ff395b94300aecf27adff Mon Sep 17 00:00:00 2001 From: Jon Wong Date: Fri, 24 Feb 2017 10:49:30 -0800 Subject: [PATCH] Pulling `stripLoc` changes from #46 --- index.js | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/index.js b/index.js index e3afe88a..2c266674 100644 --- a/index.js +++ b/index.js @@ -1,4 +1,6 @@ -var parse = require('./parser').parse; +var parser = require('graphql/language/parser'); + +var parse = parser.parse; // Strip insignificant whitespace // Note that this could do a lot more, such as reorder fields etc. @@ -38,8 +40,7 @@ function processFragments(ast) { var sourceKey = cacheKeyFromLoc(fragmentDefinition.loc); // We know something about this fragment - if (fragmentSourceMap.hasOwnProperty(fragmentName) && - !fragmentSourceMap[fragmentName][sourceKey]) { + if (fragmentSourceMap.hasOwnProperty(fragmentName) && !fragmentSourceMap[fragmentName][sourceKey]) { // this is a problem because the app developer is trying to register another fragment with // the same name as one previously registered. So, we tell them about it. @@ -73,11 +74,13 @@ function disableFragmentWarnings() { printFragmentWarnings = false; } -function stripLoc (doc, removeLocAtThisLevel) { +function stripLoc(doc, removeLocAtThisLevel) { var docType = Object.prototype.toString.call(doc); if (docType === '[object Array]') { - return doc.map(function(d) { return stripLoc(d, removeLocAtThisLevel); }); + return doc.map(function (d) { + return stripLoc(d, removeLocAtThisLevel); + }); } if (docType !== '[object Object]') { @@ -90,6 +93,11 @@ function stripLoc (doc, removeLocAtThisLevel) { delete doc.loc; } + if (doc.loc) { + delete doc.loc.startToken; + delete doc.loc.endToken; + } + var keys = Object.keys(doc); var key; var value; @@ -140,13 +148,13 @@ function gql(/* arguments */) { var result = literals[0]; for (var i = 1; i < args.length; i++) { - if (args[i] && args[i].kind && args[i].kind === 'Document') { - result += args[i].loc.source.body; - } else { - result += args[i]; - } + if (args[i] && args[i].kind && args[i].kind === 'Document') { + result += args[i].loc.source.body; + } else { + result += args[i]; + } - result += literals[i]; + result += literals[i]; } return parseDocument(result);