From dcac64fb9aae5e61d89827e46cbcd13c2b1f59a1 Mon Sep 17 00:00:00 2001 From: Hannah Ward Date: Thu, 6 Apr 2017 12:31:44 +0100 Subject: [PATCH] chg: Compress repeated replaces --- src/core/operations/Code.js | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/src/core/operations/Code.js b/src/core/operations/Code.js index 32c147e..9ee74d2 100755 --- a/src/core/operations/Code.js +++ b/src/core/operations/Code.js @@ -226,24 +226,14 @@ const Code = { } // Create newlines after ; - code = code.replace(/;/g, ";\n"); - - // Create newlines after { and around } - code = code.replace(/{/g, "{\n"); - code = code.replace(/}/g, "\n}\n"); - - // Remove carriage returns - code = code.replace(/\r/g, ""); - - // Remove all indentation - code = code.replace(/^\s+/g, ""); - code = code.replace(/\n\s+/g, "\n"); - - // Remove trailing spaces - code = code.replace(/\s*$/g, ""); - - // Remove newlines before { - code = code.replace(/\n{/g, "{"); + code = code.replace(/;/g, ";\n") + .replace(/{/g, "{\n") + .replace(/}/g, "\n}\n") + .replace(/\r/g, "") + .replace(/^\s+/g, "") + .replace(/\n\s+/g, "\n") + .replace(/\s*$/g, "") + .replace(/\n{/g, "{"); // Indent var i = 0,