mirror of
https://github.com/oxc-project/oxc.git
synced 2026-11-04 10:29:58 +00:00
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:
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);
|
||||
|
||||
Reference in new issue
Block a user