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
Unify logic for pure and non-pure enums #5
Unify logic for pure and non-pure enums #5
Conversation
@@ -3,7 +3,7 @@ var E = /*#__PURE__*/function (E) { | |||
E[E["y"] = 2] = "y"; | |||
return E; | |||
}(E || {}); | |||
E = /*#__PURE__*/function (E) { | |||
E = function (E) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was not needed, terser doesn't remove used variables (E) anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm inclined to keep it, maybe in the future terser can be implemented or other compressors can be used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
(function (E) {})(E || (E = {})); | ||
let E = /*#__PURE__*/function (E) { | ||
return E; | ||
}({}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now terser can remove this :)
Thanks! It's all really good! |
Fixes #1, Fixes #2
This is similar to what I suggested in babel#15467 (comment): it unifies the code path for the "pure" and "non pure" versions, so that we avoid having two different but very similar cases.
Instead of always generating the variable declaration followed by the IIFE, which as you pointed out doesn't work, I took the opposite approach and always generate the declaration with the IIFE as the initializer. It has the unfortunate side effect that
let X = (function () {})(X || {})
is not valid (becauseX
is in TDZ), so we must instead generatelet X = (function () {})({})
in this case.