fix(ecmascript): fix false negative for may_have_side_effects on dynamic property access (#24709)

``[][`length${foo()}`]`` was treated as side effect free. But `foo()` can have side effects.
This commit is contained in:
sapphi-red committed 2026-07-20 09:13:59 +00:00
1 parent f145d73b6a
commit e750a8243a
2 files changed
+2 -1

No files matched your search

@@ -428,7 +428,7 @@ impl<'a> MayHaveSideEffects<'a> for ComputedMemberExpression<'a> {
Expression::StringLiteral(s) => {
property_access_may_have_side_effects(&self.object, &s.value, ctx)
}
Expression::TemplateLiteral(t) => t.single_quasi().is_some_and(|quasi| {
Expression::TemplateLiteral(t) => t.single_quasi().is_none_or(|quasi| {
property_access_may_have_side_effects(&self.object, &quasi, ctx)
}),
Expression::NumericLiteral(n) => !n.value.to_integer_index().is_some_and(|n| {
@@ -800,6 +800,7 @@ fn test_property_access() {
test("[].length", false);
test("[]['length']", false);
test("[][`length`]", false);
test("[][`length${foo()}`]", true);
test("(foo() + '').length", true);
test("a[0]", true);