fix(ecmascript): fix may_have_side_effects for ${a() === b} (#9478)

`${a() === b}` has a sideeffect, but was not detected.
This commit is contained in:
sapphi-red committed 2025-03-02 12:37:02 +00:00
1 parent 0b96ebe3ad
commit d2cd97565a
2 files changed
+2

No files matched your search

@@ -89,6 +89,7 @@ impl MayHaveSideEffects for TemplateLiteral<'_> {
// If the expression is a Symbol or ToPrimitive returns a Symbol, an error is thrown.
// ToPrimitive returns the value as-is for non-Object values, so we can use it instead of ToString here.
e.to_primitive(is_global_reference).is_symbol() != Some(false)
|| e.may_have_side_effects(is_global_reference)
})
}
}
@@ -354,6 +354,7 @@ fn test_template_literal() {
test("`${{ [s]() { console.log('sideeffect') } }}`", true); // assuming s is Symbol.toPrimitive
test("`${a}`", true); // a maybe a symbol
test("`${a()}`", true);
test("`${a() === b}`", true);
}
#[test]