From bce09504987b2facb92c0aa517c1a00cc686506e Mon Sep 17 00:00:00 2001 From: Hannah Ward Date: Thu, 6 Apr 2017 12:43:37 +0100 Subject: [PATCH] chg: Removed redundant code = code.replace --- src/core/operations/Code.js | 41 ++++++++++++++++--------------------- 1 file changed, 18 insertions(+), 23 deletions(-) diff --git a/src/core/operations/Code.js b/src/core/operations/Code.js index 9ee74d21..ba596f23 100755 --- a/src/core/operations/Code.js +++ b/src/core/operations/Code.js @@ -257,29 +257,24 @@ const Code = { } // Add strategic spaces - code = code.replace(/\s*([!<>=+-/*]?)=\s*/g, " $1= "); - code = code.replace(/\s*<([=]?)\s*/g, " <$1 "); - code = code.replace(/\s*>([=]?)\s*/g, " >$1 "); - code = code.replace(/([^+])\+([^+=])/g, "$1 + $2"); - code = code.replace(/([^-])-([^-=])/g, "$1 - $2"); - code = code.replace(/([^*])\*([^*=])/g, "$1 * $2"); - code = code.replace(/([^/])\/([^/=])/g, "$1 / $2"); - code = code.replace(/\s*,\s*/g, ", "); - code = code.replace(/\s*{/g, " {"); - code = code.replace(/}\n/g, "}\n\n"); - - // Just... don't look at this - code = code.replace(/(if|for|while|with|elif|elseif)\s*\(([^\n]*)\)\s*\n([^{])/gim, "$1 ($2)\n $3"); - code = code.replace(/(if|for|while|with|elif|elseif)\s*\(([^\n]*)\)([^{])/gim, "$1 ($2) $3"); - code = code.replace(/else\s*\n([^{])/gim, "else\n $1"); - code = code.replace(/else\s+([^{])/gim, "else $1"); - - // Remove strategic spaces - code = code.replace(/\s+;/g, ";"); - code = code.replace(/\{\s+\}/g, "{}"); - code = code.replace(/\[\s+\]/g, "[]"); - code = code.replace(/}\s*(else|catch|except|finally|elif|elseif|else if)/gi, "} $1"); - + code = code.replace(/\s*([!<>=+-/*]?)=\s*/g, " $1= ") + .replace(/\s*<([=]?)\s*/g, " <$1 ") + .replace(/\s*>([=]?)\s*/g, " >$1 ") + .replace(/([^+])\+([^+=])/g, "$1 + $2") + .replace(/([^-])-([^-=])/g, "$1 - $2") + .replace(/([^*])\*([^*=])/g, "$1 * $2") + .replace(/([^/])\/([^/=])/g, "$1 / $2") + .replace(/\s*,\s*/g, ", ") + .replace(/\s*{/g, " {") + .replace(/}\n/g, "}\n\n") + .replace(/(if|for|while|with|elif|elseif)\s*\(([^\n]*)\)\s*\n([^{])/gim, "$1 ($2)\n $3") + .replace(/(if|for|while|with|elif|elseif)\s*\(([^\n]*)\)([^{])/gim, "$1 ($2) $3") + .replace(/else\s*\n([^{])/gim, "else\n $1") + .replace(/else\s+([^{])/gim, "else $1") + .replace(/\s+;/g, ";") + .replace(/\{\s+\}/g, "{}") + .replace(/\[\s+\]/g, "[]") + .replace(/}\s*(else|catch|except|finally|elif|elseif|else if)/gi, "} $1"); // Replace preserved tokens var ptokens = /###preservedToken(\d+)###/g;