Unverified Commit 82a04364 authored by Niklas Mischkulnig's avatar Niklas Mischkulnig Committed by GitHub

Turbopack: Symbol.for and keyFor are sideeffect-free (#89454)

```js
class X {
  [Symbol.for('nodejs.util.inspect.custom')] () {
    ...
  }
}
```
parent 0d15dd58
......@@ -94,6 +94,10 @@ static KNOWN_PURE_FUNCTIONS: phf::Map<&'static str, phf::Set<&'static str>> = ph
"Array" => phf_set! {
"isArray", "from", "of",
},
// Symbol static methods
"Symbol" => phf_set! {
"for", "keyFor"
},
};
/// Known pure global functions that can be called directly (not as methods).
......@@ -1364,6 +1368,15 @@ mod tests {
"const sym = Symbol('description');"
);
// Symbol.for() is pure
no_side_effects!(test_symbol_for, "const sym = Symbol.for('description');");
// Symbol.keyFor() is pure
no_side_effects!(
test_symbol_key_for,
"const description = Symbol.keyFor(sym);"
);
// Global pure function with impure argument is impure
side_effects!(
test_global_pure_with_impure_arg,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment