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
[core] incorrect output of exporting of reference #4049
Comments
related: angular/angular#40959 |
@lukastaegert Hi, is there any news, it's a really serious problem... |
I will have a look into this the next days. Sorry there was no news as I was busy on another front. |
Ok, this is not as simple as it looks. The code Rollup produces is not correct, but it is not immediately clear how to really hand this correctly. The core of the problem is that in Why is that? The core of the problem is that Note that the reason that HOWEVER, if there is no export named The problem is, I have no clue how to fix this well except by creating an additional chunk, because as exports in ESM are static, we cannot determine them at runtime. And dynamically creating a chunk here is quite difficult as well. |
It seems it worked previously, at least on |
ESM is static, so of course And also, I don't know if it's valid to override export * from 'ts-essentials' // it contains `noop`
export const noop = {
console.log('my nopp')
} If it is valid, If it is invalid, |
According to tc39/proposal-export-default-from#11, rollup should not care whether |
Yes, the problem is really the competing namespace reexports in |
Fix at #4064 |
@lukastaegert I think it should prefer the |
Not sure I fully understand. What would you expect to happen in your example? |
const noop = () => {
console.log('my loop');
};
export { noop };
export * from 'ts-essentials'; // it contains `noop`, maybe should override above `noop`, not sure But it should leave it as-is IMO. |
Here is a small example that you can run in your browser if you put // index.js
import * as ns from './reexport.js';
console.log(ns.foo, ns.bar, ns.baz);
// reexport.js
export * from './first.js';
export * from './second.js';
// first.js
export const foo = 1;
export const bar = 1;
// second.js
export const foo = 2;
export const baz = 2; If you run this, the system will log import { foo, bar, baz } from './reexport.js';
console.log(foo, bar, baz); then the code will immediately throw So no, it should not prefer any one of them. |
So the logic that is implemented in the PR is a heuristic that assumes that there will be no conflicts, which means if you explicitly export a name in one of the modules the namespace of which is reexported, then we assume this name does not exist in any of the other namespaces, especially not in external namespaces. |
But it will not replicate real browser errors like the one listed above. |
I mean we should keep the exporting order, so that the JavaScript engine will emit the error. Or, we should provide an option to:
|
I do not think it is possible to emit any error at runtime when bundling a single file as the error only exists when there are actually several conflicting namespace reexports from different files, so you need at least two local chunks to simulate it. Beyond that, I do not think this error is really useful to many, so I would prefer to only add such an option if there is actual demand. |
Note that explicit named exports or reexports will always override the same names in namespace reexports and will not throw even in case of conflict. |
This actually seems to me to be an implementation bug as |
Posted tc39/ecma262#2399 it turns out this is a spec thing, and will likely be just an editorial change to codify the behaviour at this point as a dynamic error is likely not web compatible. |
Expected Behavior
Actual Behavior
The text was updated successfully, but these errors were encountered: