mirror of
https://github.com/oxc-project/oxc.git
synced 2026-11-04 10:29:58 +00:00
test(ecmascript): add comments and tests for cases where ToPropertyKey throws an error (#9429)
This commit is contained in:
2 files changed
+7
No files matched your search
@@ -340,6 +340,8 @@ impl MayHaveSideEffects for PropertyKey<'_> {
|
||||
match self {
|
||||
PropertyKey::StaticIdentifier(_) | PropertyKey::PrivateIdentifier(_) => false,
|
||||
match_expression!(PropertyKey) => {
|
||||
// ToPropertyKey(key) throws an error when ToPrimitive(key) throws an Error
|
||||
// But we can ignore that by using the assumption.
|
||||
self.to_expression().may_have_side_effects(is_global_reference)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -560,6 +560,11 @@ fn test_object_expression() {
|
||||
test("({[1]: 1})", false);
|
||||
test("({[1n]: 1})", false);
|
||||
test("({['1']: 1})", false);
|
||||
// These actually have a side effect, but this treated as side-effect free.
|
||||
test("({[{ toString() { console.log('sideeffect') } }]: 1})", false);
|
||||
test("({[{ valueOf() { console.log('sideeffect') } }]: 1})", false);
|
||||
test("({[{ [s]() { console.log('sideeffect') } }]: 1})", false); // assuming s is Symbol.toPrimitive
|
||||
test("({[foo]: 1})", false);
|
||||
test("({[foo()]: 1 })", true);
|
||||
test("({a: foo()})", true);
|
||||
test("({...a})", true);
|
||||
|
||||
Reference in new issue
Block a user