Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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: 0 additions & 2 deletions crates/oxc_ecmascript/src/side_effects/expressions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -547,8 +547,6 @@ fn property_access_may_have_side_effects<'a>(
!(matches!(object, Expression::ArrayExpression(_))
|| object.value_type(ctx).is_string())
}
// `import.meta.url` is spec-defined and side-effect free.
"url" if matches!(object.without_parentheses(), Expression::MetaProperty(_)) => false,
_ => true,
}
}
Expand Down
7 changes: 4 additions & 3 deletions crates/oxc_minifier/tests/ecmascript/may_have_side_effects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -783,9 +783,10 @@ fn test_property_access() {
test("[...'a'][0]", false);
test("[...'a'][1]", true);

test("import.meta.url", false);
test("import.meta['url']", false);
test("import.meta[`url`]", false);
test("import.meta.url", true);
test("import.meta['url']", true);
test("import.meta[`url`]", true);
test_in_function("function f() { new.target.url }", true);
test("[...'😀'][0]", false);
test("[...'😀'][1]", true);
test("[...a, 1][0]", true); // "...a" may have a sideeffect
Expand Down
13 changes: 12 additions & 1 deletion crates/oxc_minifier/tests/peephole/obscure_edge_cases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ fn test_esm_minification_edge_cases() {
);

// Import.meta (should be preserved mostly)
test("import.meta.url", "");
test_same("import.meta.url");
test_same("import.meta.resolve('./module.js')");
test_same("import.meta.hot");
test_same("import.meta.env");
Expand Down Expand Up @@ -592,6 +592,17 @@ fn test_esm_module_patterns() {
test("import('module-' + (2 + 3))", "import('module-5')");
}

#[test]
fn test_meta_property_url_getter_side_effects() {
test(
"Object.defineProperty(import.meta, 'url', { get() { console.log('import.meta.url'); return 'virtual:' } }); import.meta.url;",
"Object.defineProperty(import.meta, 'url', { get() { return console.log('import.meta.url'), 'virtual:'; } }), import.meta.url;",
);
test_same(
"class A { constructor() { new.target.url; } } class B extends A { static get url() { console.log('url!'); } constructor() { super(); } } new B();",
);
}

#[test]
fn test_bigint_edge_cases() {
// Test BigInt operations - these ARE optimized by oxc
Expand Down
Loading