Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Symbol compatibility detection under Terser #1242

Merged
merged 2 commits into from
May 4, 2023

Commits on May 1, 2023

  1. 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.
    laverdet committed May 1, 2023
    Configuration menu
    Copy the full SHA
    9439c1d View commit details
    Browse the repository at this point in the history

Commits on May 2, 2023

  1. Lint and "future-proof"

    laverdet committed May 2, 2023
    Configuration menu
    Copy the full SHA
    1a0dfd4 View commit details
    Browse the repository at this point in the history