From f3c992391a5842639994ddfd3d4d4f5078598ba2 Mon Sep 17 00:00:00 2001 From: archmoj Date: Thu, 21 Jan 2021 10:49:57 -0500 Subject: [PATCH 1/2] refactor add const for optional comma --- tasks/compress_attributes.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tasks/compress_attributes.js b/tasks/compress_attributes.js index 139086e8900..fd6ec0e741b 100644 --- a/tasks/compress_attributes.js +++ b/tasks/compress_attributes.js @@ -5,25 +5,26 @@ var through = require('through2'); * of the plotly.js bundles */ +var OPTIONAL_COMMA = ',?'; // one line string with or without trailing comma function makeStringRegex(attr) { return makeRegex( - attr + ': \'.*\'' + ',?' + attr + ': \'.*\'' + OPTIONAL_COMMA ); } // joined array of strings with or without trailing comma function makeJoinedArrayRegex(attr) { return makeRegex( - attr + ': \\[[\\s\\S]*?\\]' + '\\.join\\(.*' + ',?' + attr + ': \\[[\\s\\S]*?\\]' + '\\.join\\(.*' + OPTIONAL_COMMA ); } // array with or without trailing comma function makeArrayRegex(attr) { return makeRegex( - attr + ': \\[[\\s\\S]*?\\]' + ',?' + attr + ': \\[[\\s\\S]*?\\]' + OPTIONAL_COMMA ); } From 1436b9c6c4f1ddcd80506af54dc61272def62632 Mon Sep 17 00:00:00 2001 From: archmoj Date: Thu, 21 Jan 2021 10:56:35 -0500 Subject: [PATCH 2/2] select and replace the whitespace before attribute to remove --- tasks/compress_attributes.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tasks/compress_attributes.js b/tasks/compress_attributes.js index fd6ec0e741b..b2f43e7e5d4 100644 --- a/tasks/compress_attributes.js +++ b/tasks/compress_attributes.js @@ -5,26 +5,27 @@ var through = require('through2'); * of the plotly.js bundles */ +var WHITESPACE_BEFORE = '\\s*'; var OPTIONAL_COMMA = ',?'; // one line string with or without trailing comma function makeStringRegex(attr) { return makeRegex( - attr + ': \'.*\'' + OPTIONAL_COMMA + WHITESPACE_BEFORE + attr + ': \'.*\'' + OPTIONAL_COMMA ); } // joined array of strings with or without trailing comma function makeJoinedArrayRegex(attr) { return makeRegex( - attr + ': \\[[\\s\\S]*?\\]' + '\\.join\\(.*' + OPTIONAL_COMMA + WHITESPACE_BEFORE + attr + ': \\[[\\s\\S]*?\\]' + '\\.join\\(.*' + OPTIONAL_COMMA ); } // array with or without trailing comma function makeArrayRegex(attr) { return makeRegex( - attr + ': \\[[\\s\\S]*?\\]' + OPTIONAL_COMMA + WHITESPACE_BEFORE + attr + ': \\[[\\s\\S]*?\\]' + OPTIONAL_COMMA ); }