archives

« Bugzilla Issues Index

#3299 — Function to determine if an object is an exotic namespace object


As mentioned on es-discuss, it is useful to have a function to determine whether a given object is an exotic module namespace object.

This arises in interop scenarios when loading ES6 through CommonJS, as we want to know and treat ES6 modules differently in compiled ES6 to CommonJS.

It may also arise in other scenarios as well.

The alternative becomes adding a flag to module namespace objects, which isn't ideal.


Reading further, it seems that something like:

function isModule(module) {
return typeof module === 'object' && module.toString() === 'Module';
}

will effectively be able to handle this. Do let me know if there's a better pattern though.