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

Added Array.from unsafe optimization #747

Merged
merged 1 commit into from
Aug 24, 2021
Merged

Added Array.from unsafe optimization #747

merged 1 commit into from
Aug 24, 2021

Conversation

L2jLiga
Copy link
Contributor

@L2jLiga L2jLiga commented Jul 4, 2020

Only simple case Array.from(array) -> array

Closes #746

Copy link

@aminya aminya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems safe to me. Could you provide a situation that this does not work?

@L2jLiga
Copy link
Contributor Author

L2jLiga commented Aug 26, 2020

Sure, I can:

Array.from = function(...elements) {
  return elements;
}

console.log(Array.from([1]));

expected: [[1]]
actual: [1]

@aminya
Copy link

aminya commented Aug 26, 2020

Array.from = function(...elements) {
  return elements;
}

Here you are assigning Array.from! We can do this for all of the JavaScript functions and break everything. I don't think this the responsibility of the minifier to prevent these cases. But I understand that tagging this as unsafe will prevent this 0.01% chance of breakage.

@L2jLiga
Copy link
Contributor Author

L2jLiga commented Aug 26, 2020

Yes, Terser has several optimizations marked as unsafe because of this

@L2jLiga
Copy link
Contributor Author

L2jLiga commented Aug 26, 2020

@fabiosantoscode
Copy link
Collaborator

Uh, why have I missed this?

Thanks!

@fabiosantoscode fabiosantoscode merged commit d3fb5b0 into terser:master Aug 24, 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 this pull request may close these issues.

Simplify Array.from calls with a static array
3 participants