You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit cdd1d8c
Browse filesBrowse the repository at this point in the historyBrowse files
feat(javascript): call RegExp without new on a string pattern in the minifier (#22547)
`new RegExp("^" + s + "$")` becomes `RegExp("^" + s + "$")`, and so does a
`RegExp` given flags sure to be a string, as `new RegExp(s, g ? "g" : "i")`.
Called, `RegExp` hands back a regular expression passed without flags as it
is; a string pattern, or flags that are a string, make it construct as `new`
does. Only a constant pattern or literal flags qualified before.
Claude-Session: https://claude.ai/code/session_01ViD41i2KdwwGxrDk7yrjeD
Copy file name to clipboardExpand all lines: test/unitCases/syntax-printer.unittest.js
+7Lines changed: 7 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -534,6 +534,12 @@ const IMPROVED_CASES = [
534
534
'var y = Math.random() < 2 ? "a" : ""; console.log(new RegExp(y, "g").global, new Array(typeof y)[0], new Array(!0).length, new Array(7).length, typeof Object(y));',
535
535
{compress: {},mangle: false}
536
536
],
537
+
[
538
+
"`RegExp` given a pattern or flags sure to be a string",
539
+
'var s = Math.random() < 2 ? "a" : "b", g = Math.random() < 2; console.log(new RegExp("^" + s + "$").test("a"), new RegExp(`${s}+`).source, new RegExp(s, g ? "g" : "i").flags, new RegExp(typeof s).source);',
["a `RegExp` constructed from a regular expression","var r = /a/g; console.log(new RegExp(r) === r, RegExp(r) === r);"],
976
+
["a `RegExp` constructed from what may be a regular expression, with flags that may be missing","function f(a, b, g) { return [new RegExp(a + b).source, new RegExp(a, g) === a]; } var r = /a/; console.log(f(1, 2), f(r, void 0, void 0));"],
970
977
["a spread `Array` call","var a = [3]; console.log(Array(...a).length);"],
971
978
["a shadowed `Array`","function f(Array) { return new Array(1, 2); } console.log(f(function (a, b) { this.s = a + b; }).s, f(function () { this.s = 0; }).s);"],
972
979
["a call of a function returning a short constant or none, called once, marked `@__INLINE__`, or read by a test or an operator",'!function () { function f() { return "a string long enough that a copy costs more than a call"; } function g() { return "ab"; } function k() { return "a string long enough that a copy costs more than a call"; } function n() {} function r() { return; } var id = (x) => x; f(); console.log(/* @__INLINE__ */ f(), f() ? 1 : 2, typeof f(), f().length, f() || 1, !f(), g(), g(), k(), n(), n(), r(), r(), id(), id(void 0)); }();'],
0 commit comments