-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
[Bug] Re-exported binding doesn't track the original binding #12522
Comments
This is really interesting. Note that is works differently in different module formats. Specifically if you compile into foo
bar
bar
baz as you expect it to be because the vars are declared outside of the closure which sets up the module and are hoisted. Also, using any module format except
the behavior under the |
That is interesting. I should have mentioned in the OP that I was using |
This seems to have slipped through the cracks. @mhegazy would you mind triaging this issue? |
The current state of the node-eps for es modules makes this very pertinent. It definitely needs to be revisited. |
Any update on this? Still happening and wildly indeterministic. Also, when I add a simple Doesn't work ( export * from "./foo"
export * from "./bar" Works: //
export * from "./foo"
export * from "./bar" Also works: console.log("")
export * from "./foo"
export * from "./bar" I'm also using EDIT: Following this comment – it seems to vanish when removing |
Is this issue still being worked on? This can be a serious problem in some cases (such as this), and is definitely out of the ESM spec. Also, the tricks mentioned by @squidfunk are invalid currently. |
@t532 - removing |
Unfortunately @t532 is right - I've just encountered a case where setting |
What's the state of this issue? Is it considered being investigated? The issue was triaged as "needs investigation" by @RyanCavanaugh nearly two years ago, and shortly after that labeled as a "bug", but a year ago it was not considered being a bug anymore? Its effects are wildly indeterministic and thus really annoying. We're in need of deterministic builds and re-exports are a very common thing. This problem may live in a lot of codebases. I'm currently working around it by adding an empty comment after the |
@squidfunk Well I don't think this is being actually investigated anymore - the solution is clear: make the imported values getters, just as what Babel and Rollup did; but for some reason they are not getting this done. @weswigham Would you mind paying some attention to this?
|
I started a PR in #31715 using the technique described in #13245 (comment). Heavily WIP. Happy to collaborate! |
TypeScript Version: nightly (2.2.0-dev.20161127)
EDIT: The issue described below is with
--module commonjs
, but as @aluanhaddad points out in a comment below, there are other behaviours with different module emits.I looked for an existing issue about this but didn't find one. Apologies if this is a duplicate.
I ran into a problem with TypeScript's emit for re-exported bindings, in particular when the original exported value changes over time.
Importing a binding directly from a source module gets a 'live view' that changes when the export value changes, as it should. But importing from a re-exported binding gets a snapshot that is no longer a live view of the original export. This seems not to be spec compliant and leads to my code not working as intended.
Code
Expected behavior
Emitted code should preserve the live binding to
liveView
when re-exporting fromb.ts
.Last line of
c.ts
should output'baz'
.Actual behavior
Emitted code exports a 'snapshot' of the
liveView
binding fromb.ts
, so that the import ofliveView
intoc.ts
is no longer a live binding.Last line of
c.ts
incorrectly outputs'bar'
.What should be the Correct Behaviour?
I found it hard to locate a clear description of correct ES6 behaviour for this situation, but from what I did find I think TypeScript's current emit is not compliant with ES6.
E.g. from the Exploring ES6 sections about imports as views and about re-exports
Babel emits code that preserves the 'live-ness' of re-exports
So for
export { liveView } from 'some-module';
TypeScript emits something like:Whereas babel emits something like:
The text was updated successfully, but these errors were encountered: