Skip to content
This repository was archived by the owner on Mar 29, 2018. It is now read-only.
This repository was archived by the owner on Mar 29, 2018. It is now read-only.

__esModule flag #86

@guybedford

Description

@guybedford

Update - calling this __esModule.

Working with module loaders based on https://github.com/ModuleLoader/es6-module-loader, in order to support the loading of AMD and CommonJS, it is necessary to add a flag to transpiled modules.

This flag is completely necessary to support AMD, ES6 and transpiled ES6 for module loaders. I have attempted to explain why below, but if it is unclear please do ask.

If we can agree on the name of a __transpiled flag, then we save much headache further down the line.

To explain how this occurs, consider loading an AMD module from an ES6 module loader:

  define(function() {
    return function() {
      console.log('exported value');
    }
  });

In the module table, we need to store the entire AMD module as the default value:

new Module({
  default: function() {
    console.log('exported value');
  }
});

Now when loading this AMD module from within another AMD module, we then need to automatically provide the default property to the module.

This is all great, but now if we load an ES6 module transpiled as AMD, from with an AMD module, we will try to do the same trick, and end up providing the default property of a transpiled es6 module instead of the entire es6 module to the AMD module.

A way to avoid this is to simply define a flag on the transpiled module so we know not to do this:

  // transpiled from ES6:
  define({
    __transpiled: true,
    someExport: 'value'
  });

This then allows AMD modules the full access to other AMD modules, ES6 modules as well as transpiled ES6 modules all in consistent ways.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions