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

Incorrect inlining of function with destructuring in initializer of for..of loop #1238

Closed
ajafff opened this issue Aug 8, 2022 · 0 comments

Comments

@ajafff
Copy link

ajafff commented Aug 8, 2022

Bug report or Feature request?

Bug

Version (complete output of terser -V or specific git commit)

What the online REPL currently uses

Complete CLI command or minify() options used

REPL defaults:

{
  module: true,
  compress: {},
  mangle: {},
  output: {},
  parse: {},
  rename: {},
}

terser input

export function caller(data, key) {
    return callee(data, key);
}

function callee(arr, key) {
    for (const { [key]: v } of arr) {
        return v;
    }
}

terser output or error

export function caller(n,r){return function(n,r){for(const{[r]:o}of n)return o}(n)}

Expected result

It should either pass r as second argument to the IIFE or it should not declare r as parameter of the inner function so that it references the variable in the outer scope. Currently r is always undefined at the destructuring

// either
export function caller(n,r){return function(n,r){for(const{[r]:o}of n)return o}(n, r)}

// or
export function caller(n,r){return function(){for(const{[r]:o}of n)return o}()}

Note that this only seems to happen with object destructuring in for..of loops


There's a similar case where the reference to the default value of a destructured property is not correctly tracked.

Input:

export function caller(data, fallback) {
    return callee(data, fallback);
}

function callee(arr, fallback) {
    for (const { v = fallback} of arr) {
        return v;
    }
}

Output:

export function caller(n,r){return function(n,r){for(const{v:o=r}of n)return o}(n)}

Same issue: r is always undefined

@ajafff ajafff changed the title Incorrect inlining of function with destructuring of computed key in for..of loop Incorrect inlining of function with destructuring in initializer of for..of loop Aug 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant