Discussion: Module Reflection - import.reflect

Jordan Harband ljharb at gmail.com
Sat Jan 26 00:37:15 UTC 2019


In `import * as m from myModule`, `m.default` is already the default
export; `Object.keys(m)` is already the list of export names, and
`Object.entries(m).filter(([k, v]) => typeof v === 'function'))` is the
list of functions.

On Fri, Jan 25, 2019 at 5:27 AM Randy Buchholz <work at randybuchholz.com>
wrote:

> Would it be worthwhile to add reflection to modules as a distinct feature?
>
>
>
> `import.meta.url` is a basic form of reflection, but it seems (?) `meta`
> is trying to be a fairly loose specification. Being able query a module can
> be helpful. For example, if I can see the static imports, I can
> conditionally do dynamic imports. Or (thinking out loud here), can
> “generic” modules be built where `default` is the generic?
>
>
>
> Some of the possibilities are
>
> `import.reflect.default` - returns `default` in its native form (function,
> class, value)
>
> `import.reflect.imports` - provides a list of static imports. Not sure
> what this should be (value or key-value (e.g., [importName, module]), but
> should be enumerable.
>
> `import.reflect.functions` - provides a list of exported functions. Can be
> use, for instance, to validate the shape of a module.
>
>
>
> This can be exposed to an importing module.
>
>
>
> ```
>
> // myModule has default export of `class xxx`
>
>
>
> Import * as m from myModule
>
> const instance = Reflect.construct(m.import.reflect.default, []);
>
>
>
> ```
>
>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20190125/8971a75d/attachment.html>


More information about the es-discuss mailing list