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

Inlining function with rest arguments leads to invalid code being generated #1226

Closed
jpdutoit opened this issue Jul 19, 2022 · 1 comment
Closed
Labels

Comments

@jpdutoit
Copy link
Contributor

Bug report

When inlining functions using rest arguments Terser sometimes tries to spread a rest argument into a variable, which is invalid Javascript. In the example below, it seems that Terser has missed that identity is only using its first argument.

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

https://try.terser.org

Complete CLI command or minify() options used

{
  module: true,
  compress: {
    passes: 3
  }
}

terser input

function identity(x) {
  return x
}

function outer(keyFn) {
  return function inner(...args) {
    const key = keyFn(...args)
    console.log(key)
  }
}

outer(identity)(1)

terser output or error

!function(...o){const n=...o;console.log(n)}(1);

Expected result

!function(...o){const n=o[0];console.log(n)}(1);

or

!function(o){const n=o;console.log(n)}(1);
@jpdutoit jpdutoit changed the title Inlining function with rest argumentsleads to invalid code being generated Inlining function with rest arguments leads to invalid code being generated Jul 19, 2022
@fabiosantoscode
Copy link
Collaborator

Thanks for reporting! I think I know why this happened

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants