Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix
Symbol
compatibility detection under Terser
The `String` constructor has a special case for `Symbol` conversions: https://tc39.es/ecma262/#sec-string-constructor-string-value a. If NewTarget is undefined and value is a Symbol, return SymbolDescriptiveString(value). b. Let s be ? ToString(value). Therefore, the only difference between `String(value)` and `value + ''` is that the latter will throw for symbols. Terser uses this to advantage by replacing invocations of `String(...)` with `... + ''`. Terser, to its credit, has this behavior gated behind the `unsafe` flag with the following documentation: "It enables some transformations that might break code logic in certain contrived cases, but should be fine for most code." For this particular code it is *not* fine though. Under WebPack, Terser is typically run per chunk rather than per file. It is difficult or impossible to disable these optimizations for only core-js, only for the entire bundle. This optimization causes the Symbol constructor detection pathway to fail and fallback to string keys. After everything is said and done we end up with a confusing error message of "[object Generator] is not iterable". The fix is simple, we simply bailout of this optimization in this critical path.
- Loading branch information