Skip to content

Commit

Permalink
core(minification-estimator): add else to punctuation (#15624)
Browse files Browse the repository at this point in the history
  • Loading branch information
avinash-sd committed Nov 22, 2023
1 parent 0f77e58 commit ec66e19
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion core/lib/minification-estimator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)+$/;

/**
Expand Down
6 changes: 6 additions & 0 deletions core/test/lib/minification-estimator-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
});

0 comments on commit ec66e19

Please sign in to comment.