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
fix(compiler): Force rollup to use named exports #1752
Conversation
Although I'm fine with this change, and I think it does make sense, there are other issues to consider. Locker being one of them, e.g.: locker has to sign and loop through the exports if needed (with default export only, everything is quicker. |
We (me and @jdalton) were looking at the changes in rollup and it seems there is quite a bit of history behind rollup's interop code but we don't think it's controversial to fix this in rollup code. In this case this could be a path worth exploring rather than making changes in 2 of our stacks (LWC & Locker). Have we considered this option? History of changes possibly related the current issue Possible fix could be to use |
I don't think the performance hit is a concern, in most of the case only a small amount of properties are exported outside a module. Also, the locker signature should only happen once at evaluation time.
This option has been considered. @jodarove proposed himself to do that fix, but I saw that @jdalton just opened a PR for this: rollup/rollup#3420. While I think it's import to fix rollup, forcing the named export out of the compiler, would allow us to remove unnecessary code that we had to introduce into Aura. I am fine postponing this change to the next release, but it would be great to tackle this as soon as possible next release. |
Next release sounds fine, we can coordinate between the two teams. |
@pmdartus can you please rebase and merge |
This would also prevent recursive/circular dependency issue for default only exports: rollup/rollup#3384 |
fd92fd2
to
b2cc7de
Compare
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.
looks good! @pmdartus pls remember to update lwc-platform and cut a release
Details
This PR forces rollup bundle generation to use
named
exports.Background
Currently, rollup attempts to detect how exports should be generated based on the exported values from the LWC module entry.
named
), rollup returns an object with thenamed
property.named
), rollup returns an object with thedefault
and thenamed
property. It's important to note that if nooutput.exports
property is set, rollup warns in this case.On the other hand, when importing the default value from an external module, rollup injects some interop code extract the code right default value. This interop checks the presence of the
default
property on the exported object usingmodule.hasOwnProperty('default')
.We recently ran into a case where the interop code throws an error when the interop code throws an error because
hasOwnProperty
is not defined on the external module. This issue happens only if a module (module/a
) has a single default export and the default export value has no prototype. In this case, if another module (module/b
) imports the default export the interop code will throw becausehasOwnProperty
is not defined on the object.By forcing the rollup
options.exports
flag to benamed
, modules with a single default export (case 1.) to return an object with thedefault
property. The generated output for cases 2. and 3. remain identical.Using this approach we can guarantee that the exported returned object inherits from Object and will not throw when invoking
hasOwnProperty
.Does this PR introduce breaking changes?
No, it does not introduce breaking changes.
The PR fulfills these requirements:
GUS work item
W-7272006, W-7352554