Enumerating import of wildcards in ES2015

So in ES2015 you can:

// Module A
export const FOO = 0;
export const BAR = 1;

// Module B
import * as AExports from 'ModuleA';
console.log(AExports.FOO); // Prints 0

What is the official way to list ModuleA exports at runtime?

import * as AExports from 'ModuleA';
// Are these values guaranteed to be something?
Object.keys(AExports); // If so, should I look at enumerable values?
[...AExports]; // Iterable values?
Object.getOwnPropertyNames(AExports); // Here?

As far as I can tell, spec describes this as ImportedBinding, but I cannot extract any of this.

NameSpaceImport : * as ImportedBinding
Let localName be the StringValue of ImportedBinding.
Let entry be the Record {[[ModuleRequest]]: module, [[ImportName]]: "*", [[LocalName]]: localName }.
Return a new List containing entry.
+4
source share
1 answer

The important part of the specification in this case is that when you do

import * as foo from 'foo';

foo 15.2.1.16.4, 12.b, Module Namespace Exotic Object, - , Object.keys(foo) . , , , , . Object.getOwnPropertyNames .

+5

Source: https://habr.com/ru/post/1649661/


All Articles