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 a function 3 times may break if passes=2 #1046

Closed
gdh1995 opened this issue Aug 23, 2021 · 0 comments · Fixed by #1047
Closed

inlining a function 3 times may break if passes=2 #1046

gdh1995 opened this issue Aug 23, 2021 · 0 comments · Fixed by #1047

Comments

@gdh1995
Copy link
Contributor

gdh1995 commented Aug 23, 2021

Bug report or Feature request? Bug

Version (complete output of terser -V or specific git commit) 5.7.1, and 5.7.1 with PR #1036

Complete CLI command or minify() options used

npx terser -f beautify -c passes=2 a.js

terser input

// a.js
const endsWith = (s, t) => s.endsWith(t)
export const test = (a) => {
  return /*#__INLINE__*/ endsWith(a, "foo") ? a.replace("foo", "foo")
    : /*#__INLINE__*/ endsWith(a, "bar") ? a.replace("bar", "bar")
    : /*#__INLINE__*/ endsWith(a, "123") ? a.replace("123", "123")
    : a
}

terser output or error

const endsWith = (s, t) => s.endsWith("123");

export const test = a => {
    return "foo", a.endsWith("foo") ? a.replace("foo", "foo")
    : (s = a).endsWith("123") ? a.replace("bar", "bar")
    : ((s, t) => s.endsWith("123"))(a) ? a.replace("123", "123") : a;
    var s;
};

(I add some \n before :)

Expected result

const endsWith = (s, t) => s.endsWith("123");

export const test = a => {
    return "foo", a.endsWith("foo") ? a.replace("foo", "foo")
    : (s = a).endsWith("bar") ? a.replace("bar", "bar")
    : ((s, t) => s.endsWith("123"))(a) ? a.replace("123", "123") : a;
    var s;
};

The difference is the 2nd branch: "bar" in endsWith(...) should be not "123" but "bar"

Some notes

I think this has a same root cause just like #1022 .

@gdh1995 gdh1995 changed the title inlining function 3 times may break if passes=2 inlining a function 3 times may break if passes=2 Aug 26, 2021
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

Successfully merging a pull request may close this issue.

1 participant