Discussion: Module Reflection - import.reflect
work at randybuchholz.com
Fri Jan 25 13:27:24 UTC 2019
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, );
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the es-discuss