-
Notifications
You must be signed in to change notification settings - Fork 147
Circular dependency doesn't work with anonymous function declaration #183
Comments
Hi @nicolo-ribaudo! Looks like I can fix this with a little import/export order juggling or name generating for the anon-function. I'll kick something around and report back. For a temp workaround you can move the import g from "./g";
import f from "./f"; |
Thank you! |
Would you expect this to work for arbitrary import "./module/that/imports/and/immediately/uses/default.js";
export default fnThatReturnsFn(); The In some sense, import "./module/that/imports/and/immediately/uses/default.js";
export default function () {...} is just another You can still import the export let f;
import "./module/that/imports/and/immediately/uses/f.js";
// Too late!
f = function () {...}; Since the expression in question isn't evaluated until after the circular import, there may not be anything the JS runtime can safely do to make this work for you. |
It's less about what I or @nicolo-ribaudo expects to work and more about what does work in the native runtime. In this case, @nicolo-ribaudo's example does work with I'll tackle it by generating a safe name, transforming the anonymous function into a safe named declaration. |
@benjamn I'd only expect declarations to be hoisted, like it has always been in JavaScript. export default (function () {}); While this should be hoisted, so I'd expect it to work with dependnecy cycles: export default function () {}
rollup/rollup#1787: In rollup I fixed this issue by transforming anonymous function declarations to named function declarations. EDIT: @jdalton If you haven't started working on this yet, I'd like to contribute! |
I agree we should reconcile what However, I understand export default function () {} to be exporting a function expression, which is not a declaration (function declarations can't be anonymous, right?), so I'm not following the argument for hoisting it. |
It is an anonymous function declaration:
Btw, I just realized that this issue needs to be fixed also or async functions and generators. |
Ok, I didn't realize anonymous declarations were a thing! By the way, I think you can get this to work in |
@benjamn The name is needed because anynimous declarations are only allowed after |
Moved to #187. |
* Hoist anonymous function declarations. Fixes #183
https://github.com/nicolo-ribaudo/std-esm-bug-anonymous-fn-decl
It works with node, but not with
@std/esm
:If I give a name to the function defined in
f.js
or I remove the first import frommain.js
, it works as I'd expect.I'm not 100% sure that this is a bug, since I don't understand well the part of the spec related to modules and rollup behaves exactly like
@std/esm
.The text was updated successfully, but these errors were encountered: