-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Annotate frozen namespaces with #__PURE__ comment #2044
Conversation
ebaaece
to
97017cb
Compare
I'm trying to envision a real life use case. Will any of these tests produce a pure annotated |
This particular annotation is targeting consumers' of splitted libraries. // library/index.js
import * as selectors from './chunk1.js'
console.log('selectors', selectors) // library/selectors.js
export { selectorA, selectorB } from './chunk1.js' // library/chunk1.js
export const selectorA = () => {}
export const selectorB = () => {}
export const selectors = /*#__PURE__*/Object.freeze({
selectorA,
selectorB,
}) // ./consumer.js
import { selectorA } from 'library/selectors'
selectorA() |
I see the use case now - deep linked named imports from chunked libraries. |
@Andarist thanks for clarifying the use case. It sounds like if we could get treeshaking to work for this use case - https://rollupjs.org/repl?version=0.56.3&shareable=JTdCJTIybW9kdWxlcyUyMiUzQSU1QiU3QiUyMm5hbWUlMjIlM0ElMjJtYWluLmpzJTIyJTJDJTIyY29kZSUyMiUzQSUyMmNvbnN0JTIweCUyMCUzRCUyME9iamVjdC5mcmVlemUoJTdCJTIwYXNkZiUzQSUyMCdhc2RmJyUyMCU3RCklMjIlN0QlMkMlN0IlMjJuYW1lJTIyJTNBJTIybWF0aHMuanMlMjIlMkMlMjJjb2RlJTIyJTNBJTIyJTIyJTdEJTVEJTJDJTIyb3B0aW9ucyUyMiUzQSU3QiUyMmZvcm1hdCUyMiUzQSUyMmNqcyUyMiUyQyUyMm5hbWUlMjIlM0ElMjJteUJ1bmRsZSUyMiUyQyUyMmdsb2JhbHMlMjIlM0ElN0IlN0QlMkMlMjJhbWQlMjIlM0ElN0IlMjJpZCUyMiUzQSUyMiUyMiU3RCU3RCUyQyUyMmV4YW1wbGUlMjIlM0FudWxsJTdE then that would also solve the issue right? //cc @lukastaegert any ideas? |
As long as side effects are taken into consideration in a freeze of an object literal, sure: const unused = Object.freeze({a: side_effect()}); |
Adding the pure annotation comment has one advantage - the rolled up chunked library will allow for webpack with scope hoisting to drop the unnecessary call. The ultimate consumer of the library may not be using Rollup. |
Exactly what I'm after with this PR :) |
@guybedford Yes, I already have plans how to get this to tree-shake, just didn't get to it yet. Doesn't make sense IMO doing this without refactoring all of the global handling to create a general solution for globals the only side-effect of which would be to modify (or call) one of their arguments. In this specific situation, the proper logic would include the statement if the argument is an included variable (or of course if the variable it is assigned to is used). Otherwise, code-splitting is not even necessary for this to be useful. You could also export a namespace import from an external dependency as an object. All users of uglify would then benefit from this change. |
86e65a9
to
f191014
Compare
f191014
to
e721e1c
Compare
I've rebased my branch against latest master, this could be shipped with @guybedford's namespace improvements PR (if you decide this one is ready) |
fixes #2042