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

compress: Fix unsound optimization of new RegExp(…) #7091

Merged
merged 2 commits into from
Mar 17, 2023

Commits on Mar 16, 2023

  1. compress: Fix unsound optimization of new RegExp(…)

    In swc-project#4932, an optimization was added that transforms `new RegExp(…)` to
    `RegExp(…)`.  It seems to have been motivated by this sentence in the
    ECMAScript specification:
    
    “Thus the function call RegExp(…) is equivalent to the object creation
    expression new RegExp(…) with the same arguments.”
    
    But that sentence turns out to be wrong.  It contradicts the detailed
    steps in the following section of the specification, as well as the
    empirical behavior of JavaScriptCore, SpiderMonkey, and V8:
    
        > r = /a/;
        /a/
        > RegExp(r) === r
        true
        > new RegExp(r) === r
        false
    
    Restrict this optimization to the case where we can prove one of the
    first two arguments is a string.
    
    Fixes swc-project#6941.
    
    Signed-off-by: Anders Kaseorg <andersk@mit.edu>
    andersk committed Mar 16, 2023
    Configuration menu
    Copy the full SHA
    6079a06 View commit details
    Browse the repository at this point in the history

Commits on Mar 17, 2023

  1. Configuration menu
    Copy the full SHA
    bcb463a View commit details
    Browse the repository at this point in the history