Skip to content

Instantly share code, notes, and snippets.

@ifandelse
Last active August 29, 2015 14:05
Show Gist options
  • Save ifandelse/54c264a9eb262c5be0ea to your computer and use it in GitHub Desktop.
Save ifandelse/54c264a9eb262c5be0ea to your computer and use it in GitHub Desktop.
Trying to understand traceur's module transpilation output

The AMD output of traceur has me a bit confused. The return value looks a lot like an ES6 class - shouldn't this be converting all the way to ES5? FWIW, my options (to traceur) are:

{
  modules: "amd",
	outputLanguage: 'es5'
}
define([], function() {
"use strict";
var myVar = {};
var $__default = myVar;
return {
get default() {
return $__default;
},
__esModule: true
};
});
var myVar = {};
export default myVar;
@michaelficarra
Copy link

Agreed with @eventualbuddha, that example would work because of partially loaded modules.

Modules are cached after the first time they are loaded. This means (among other things) that every call to require('foo') will get exactly the same object returned, if it would resolve to the same file. Multiple calls to require('foo') may not cause the module code to be executed multiple times. This is an important feature. With it, "partially done" objects can be returned, thus allowing transitive dependencies to be loaded even when they would cause cycles.

edit: This was posted way after composing it, and a few comments were posted before it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment