Skip to content

Commit 92f16c9

Browse files
fix(javascript): keep a newer RegExp and Symbol.for when dropping built-ins
Check a RegExp against ES2018 with the base parser, which always runs the spec's validator, so a pattern a newer build host accepts is still kept. Keep an unused Symbol.for, whose key would stay in the build's own registry, and drop an optional read of a built-in like the plain one. Claude-Session: https://claude.ai/code/session_01ViD41i2KdwwGxrDk7yrjeD
1 parent 7ee8afc commit 92f16c9

5 files changed

Lines changed: 13 additions & 3 deletions

File tree

‎lib/javascript/syntax-printer-data.js‎

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎lib/javascript/syntax-printer.js‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15510,7 +15510,6 @@ const installImprove = (modules) => {
1551015510
let property;
1551115511
let onPrototype = false;
1551215512
if (A.isDotNode(object)) {
15513-
if (object.optional) return false;
1551415513
property = object.property.name;
1551515514
object = object.object;
1551615515
if (
@@ -15551,8 +15550,10 @@ const installImprove = (modules) => {
1555115550
) {
1555215551
return false;
1555315552
}
15553+
// The base `Parser` always runs the spec's validator, where `parse` lets
15554+
// a pattern the host engine accepts through, newer syntax included.
1555415555
try {
15555-
require("./syntax-parser").parse(`/${pattern}/${flags || ""}`, {
15556+
require("./syntax-parser").Parser.parse(`/${pattern}/${flags || ""}`, {
1555615557
ecmaVersion: 2018
1555715558
});
1555815559
} catch (_err) {

‎test/helpers/oxcSmaller.js‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2023,6 +2023,10 @@ const OXC_SMALLER_BY_REASON = [
20232023
[
20242024
"oxc's output is wrong: it renames `LocalCtor` inside a `with` body, so a `LocalCtor` property on the `with` object is no longer used",
20252025
["swc minifier: fixture/issues/11684/with-scope/input.js"]
2026+
],
2027+
[
2028+
"oxc drops an unused `Symbol.for`, which webpack keeps: running it at build time would keep its key in the build's own symbol registry",
2029+
["oxc minifier: ecmascript/may_have_side_effects.rs:1259"]
20262030
]
20272031
];
20282032

‎test/unitCases/syntax-printer.unittest.js‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,8 +352,11 @@ const KEPT_CASES = [
352352
["an optional built-in call", "Math?.max(1); JSON.parse?.(\"1\"); console.log(1);"],
353353
["a static the generated tables leave out", "try { Math.nope(); } catch (e) { console.log(1); }"],
354354
["a call of something that is no built-in", "var o = { f: function () { console.log(1); } }; o.f(); (0, o.f)();"],
355+
["a `RegExp` newer than ES2018, which a newer host engine reads too", 'new RegExp("(?i:a)"); console.log(1);'],
356+
["a `Symbol.for`, which would register its key in the build's own registry", 'Symbol.for("k"); console.log(1);'],
355357
["a `typeof` guard of another name", 'try { typeof y != "undefined" && z; } catch (e) { console.log(1); }'],
356358
["a `typeof` guard the wrong way round", 'try { typeof y == "undefined" && y; } catch (e) { console.log(1); }'],
359+
["a `typeof` comparison guarding the wrong way round", 'try { typeof y < "u" || y; } catch (e) { console.log(1); }'],
357360
["a `typeof` guard of a declared name", 'var y = { valueOf: function () { console.log(1); } }; typeof y != "undefined" && +y;'],
358361
["a `typeof` guard of no reference", 'typeof 1 != "undefined" && console.log(1); typeof y != 1 && console.log(2); typeof y in {} || console.log(3);'],
359362
["a count past the call's own size", 'console.log("a".repeat(1e9), "a".padStart("99999"), "a".padEnd(1e9));'],

‎tooling/generate-js-data.js‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1131,6 +1131,9 @@ const IMPURE_BUILT_INS = {
11311131
"Atomics.wait",
11321132
"Atomics.notify",
11331133
"Atomics.waitAsync"
1134+
],
1135+
"running it at build time keeps its key in the build's own symbol registry": [
1136+
"Symbol.for"
11341137
]
11351138
};
11361139

0 commit comments

Comments
 (0)