diff --git a/js/translator.js b/js/translator.js index 3a09fe0b..ee4e1051 100644 --- a/js/translator.js +++ b/js/translator.js @@ -19,92 +19,12 @@ var Translator = (function () { xhr.open("GET", file, true); xhr.onreadystatechange = function () { if (xhr.readyState === 4 && xhr.status === 200) { - callback(JSON.parse(stripComments(xhr.responseText))); + callback(JSON.parse(xhr.responseText)); } }; xhr.send(null); } - /* loadJSON(str, options) - * Remove any commenting from a json file so it can be parsed. - * - * argument str string - The string that contains json with comments. - * argument opts function - Strip options. - * - * return the stripped string. - */ - function stripComments(str, opts) { - // strip comments copied from: https://github.com/sindresorhus/strip-json-comments - - var singleComment = 1; - var multiComment = 2; - - function stripWithoutWhitespace() { - return ""; - } - - function stripWithWhitespace(str, start, end) { - return str.slice(start, end).replace(/\S/g, " "); - } - - opts = opts || {}; - - var currentChar; - var nextChar; - var insideString = false; - var insideComment = false; - var offset = 0; - var ret = ""; - var strip = opts.whitespace === false ? stripWithoutWhitespace : stripWithWhitespace; - - for (var i = 0; i < str.length; i++) { - currentChar = str[i]; - nextChar = str[i + 1]; - - if (!insideComment && currentChar === '"') { - var escaped = str[i - 1] === "\\" && str[i - 2] !== "\\"; - if (!escaped) { - insideString = !insideString; - } - } - - if (insideString) { - continue; - } - - if (!insideComment && currentChar + nextChar === "//") { - ret += str.slice(offset, i); - offset = i; - insideComment = singleComment; - i++; - } else if (insideComment === singleComment && currentChar + nextChar === "\r\n") { - i++; - insideComment = false; - ret += strip(str, offset, i); - offset = i; - continue; - } else if (insideComment === singleComment && currentChar === "\n") { - insideComment = false; - ret += strip(str, offset, i); - offset = i; - } else if (!insideComment && currentChar + nextChar === "/*") { - ret += str.slice(offset, i); - offset = i; - insideComment = multiComment; - i++; - continue; - } else if (insideComment === multiComment && currentChar + nextChar === "*/") { - i++; - insideComment = false; - ret += strip(str, offset, i + 1); - offset = i + 1; - continue; - } - } - - return ret + (insideComment ? strip(str.substr(offset)) : str.substr(offset)); - } - return { coreTranslations: {}, coreTranslationsFallback: {}, diff --git a/tests/unit/classes/translator_spec.js b/tests/unit/classes/translator_spec.js index b0ec084c..9d784cff 100644 --- a/tests/unit/classes/translator_spec.js +++ b/tests/unit/classes/translator_spec.js @@ -171,25 +171,6 @@ describe("Translator", function () { }; }); - it("should strip comments", function (done) { - const dom = new JSDOM(`