diff --git a/core/lib/minification-estimator.js b/core/lib/minification-estimator.js index 0ad46cd83526..5cd18f1e71e8 100644 --- a/core/lib/minification-estimator.js +++ b/core/lib/minification-estimator.js @@ -6,7 +6,7 @@ // https://www.ecma-international.org/ecma-262/9.0/index.html#sec-punctuators // eslint-disable-next-line max-len -const PUNCTUATOR_REGEX = /(return|case|{|\(|\[|\.\.\.|;|,|<|>|<=|>=|==|!=|===|!==|\+|-|\*|%|\*\*|\+\+|--|<<|>>|>>>|&|\||\^|!|~|&&|\|\||\?|:|=|\+=|-=|\*=|%=|\*\*=|<<=|>>=|>>>=|&=|\|=|\^=|=>|\/|\/=|\})$/; +const PUNCTUATOR_REGEX = /(return|case|else|{|\(|\[|\.\.\.|;|,|<|>|<=|>=|==|!=|===|!==|\+|-|\*|%|\*\*|\+\+|--|<<|>>|>>>|&|\||\^|!|~|&&|\|\||\?|:|=|\+=|-=|\*=|%=|\*\*=|<<=|>>=|>>>=|&=|\|=|\^=|=>|\/|\/=|\})$/; const WHITESPACE_REGEX = /( |\n|\t)+$/; /** diff --git a/core/test/lib/minification-estimator-test.js b/core/test/lib/minification-estimator-test.js index eff3feaf2fc1..0c4134259201 100644 --- a/core/test/lib/minification-estimator-test.js +++ b/core/test/lib/minification-estimator-test.js @@ -262,5 +262,11 @@ describe('minification estimator', () => { const outerBraces = '{ foo:{bar:`baz ${bam.get({} )}`}}'; expect(computeJSTokenLength(outerBraces)).toEqual(outerBraces.length - 6); }); + + it('should handle else keyword followed by a regex pattern in scripts', () => { + const script = '} else/^hello!/.test(n)?(d=element.parseFromString("Hi/Hello there!")'; + const minified = '}else/^hello!/.test(n)?(d=element.parseFromString("Hi/Hello there!")'; + expect(computeJSTokenLength(script)).toEqual(minified.length); + }); }); });