From b8dbf7412c1a7243e785ac06ab75d34275331800 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20T=C3=A9treault-Pinard?= Date: Thu, 28 Jan 2016 11:54:18 -0500 Subject: [PATCH 1/3] fix regular exp to compress joined array attributes --- tasks/util/compress_attributes.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tasks/util/compress_attributes.js b/tasks/util/compress_attributes.js index 488c6a9594a..b5693d342ef 100644 --- a/tasks/util/compress_attributes.js +++ b/tasks/util/compress_attributes.js @@ -9,15 +9,14 @@ var attributeNamesToRemove = [ 'description', 'requiredOpts', 'otherOpts', 'hrName', 'role' ]; -// ref: http://www.regexr.com/3bj6p +// ref: http://www.regexr.com/3cmac var regexStr = ''; attributeNamesToRemove.forEach(function(attr, i) { // one line string with or without trailing comma regexStr += attr + ': \'.*\'' + ',?' + '|'; - // array of strings with or without trailing comma - regexStr += attr + ':.*\\n*.*\\.join\\(\\\'\\s\\\'\\)'; - // attr:.*\n.*\.join\(\'\s\'\) + // joined array of strings with or without trailing comma + regexStr += attr + ': \\[[\\s\\S]*?\\]\\.join\\(.*' + ',?'; if(i !== attributeNamesToRemove.length-1) regexStr += '|'; }); From 29a6865dbf3e0dce955209c24e34124c569817ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20T=C3=A9treault-Pinard?= Date: Thu, 28 Jan 2016 11:54:41 -0500 Subject: [PATCH 2/3] rm jshint mark --- build/ploticon.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/build/ploticon.js b/build/ploticon.js index 2577efbb557..84b86fb0aa6 100644 --- a/build/ploticon.js +++ b/build/ploticon.js @@ -1,5 +1,3 @@ -/* jshint quotmark:true */ - 'use strict'; module.exports = { From 10188d1b6d84cd383e38e127907134e7cebd71fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20T=C3=A9treault-Pinard?= Date: Thu, 28 Jan 2016 13:57:02 -0500 Subject: [PATCH 3/3] robustify compress reg exp --- tasks/util/compress_attributes.js | 34 ++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/tasks/util/compress_attributes.js b/tasks/util/compress_attributes.js index b5693d342ef..e417312c410 100644 --- a/tasks/util/compress_attributes.js +++ b/tasks/util/compress_attributes.js @@ -5,21 +5,31 @@ var through = require('through2'); * of the plotly.js bundles */ -var attributeNamesToRemove = [ - 'description', 'requiredOpts', 'otherOpts', 'hrName', 'role' -]; -// ref: http://www.regexr.com/3cmac -var regexStr = ''; -attributeNamesToRemove.forEach(function(attr, i) { - // one line string with or without trailing comma - regexStr += attr + ': \'.*\'' + ',?' + '|'; +// one line string with or without trailing comma +function makeStringRegex(attr) { + return attr + ': \'.*\'' + ',?'; +} + +// joined array of strings with or without trailing comma +function makeJoinedArrayRegex(attr) { + return attr + ': \\[[\\s\\S]*?\\]' + '\\.join\\(.*' + ',?'; +} - // joined array of strings with or without trailing comma - regexStr += attr + ': \\[[\\s\\S]*?\\]\\.join\\(.*' + ',?'; +// array with or without trailing comma +function makeArrayRegex(attr) { + return attr + ': \\[[\\s\\S]*?\\]' + ',?'; +} - if(i !== attributeNamesToRemove.length-1) regexStr += '|'; -}); +// ref: http://www.regexr.com/3cmac +var regexStr = [ + makeStringRegex('description'), + makeJoinedArrayRegex('description'), + makeArrayRegex('requiredOpts'), + makeArrayRegex('otherOpts'), + makeStringRegex('hrName'), + makeStringRegex('role') +].join('|'); var regex = new RegExp(regexStr, 'g');