Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core(minification-estimator): add else to punctuation #15624

Merged
merged 3 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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', () => {
let script = '} else/^hello!/.test(n)?(d=element.parseFromString("Hi/Hello there!")';
let minified = '}else/^hello!/.test(n)?(d=element.parseFromString("Hi/Hello there!")';
adamraine marked this conversation as resolved.
Show resolved Hide resolved
expect(computeJSTokenLength(script)).toEqual(minified.length);
});
});
});
Loading