-
Notifications
You must be signed in to change notification settings - Fork 47
Error Asymmetry with declaration form #44
Comments
This isn't an asymmetry, so much as a deliberate omission. This imperative form only corresponds to namespace imports (i.e. const { parseJS } = await validate(import("./validators.js"), "parseJS"); (where So this is out of scope of this proposal, and IMO not something we need to add to the language. Going to close as this isn't going to lead to actionable change to this proposal, but happy to continue discussing in the closed thread. |
Fair enough, I was mainly interested because there's no way to get what the host's error message would've been e.g. Chrome does: Something I wish was the case but is probably too late to change now is that Module Namespace objects had getters that throw errors for those weird "ambiguous" exports instead of silently vanishing them. At current I feel like the vanishing of ambiguous imports is just going to be a weird source of bugs, especially for people dealing with dynamic import because you can only get the Module Namespace object. Do you have any idea what the original reasoning behind vanishing "ambiguous" imports was? Because I haven't managed to find anything on the matter. |
I don't really know, sorry. Maybe someone on the es-discuss mailing list does. |
Something that the declarative
import
form is able to do but theimport()
form is not able to do is throw errors on missing or ambiguous imports, e.g. these can throw errors with the declaration form:Now you definitely can create functions that do these behaviours e.g.:
However this suffers the same issue as #37 (comment) in that you can't share it around different modules so you wind up having to reimplement it everywhere.
I'm not sure what the solution would be, it might even be a part of the loader API instead but I could imagine something like on the loader issue of having
import.names
where you can specify names you want.e.g.
An alternative could be that the
import()
form doesn't return a normalModule
object but rather another object that hassomeModule.someNonexistentName
be a getter that throws the error that would've happened e.g.(await import('./foo.js')).nonExistentName
would throw the same error asimport { nonExistentName } from "./foo.js"
.The text was updated successfully, but these errors were encountered: