Skip to content

Commit

Permalink
traceur.compile moduleName fix
Browse files Browse the repository at this point in the history
Allows `moduleName` option as a string for `traceur.compile` into AMD and instantiate
to output correctly named define statement
  • Loading branch information
guybedford committed May 12, 2014
1 parent 5dbc660 commit cbc7e8c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/node/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ function compile(content, options) {
if (moduleName === true || options.modules == 'register' || options.modules == 'inline') {
moduleName = options.filename.replace(/\.js$/, '');
moduleName = path.relative(options.cwd, moduleName).replace(/\\/g,'/');
}
if (moduleName) {
transformer = new AttachModuleNameTransformer(moduleName);
tree = transformer.transformAny(tree);
}
Expand Down
25 changes: 25 additions & 0 deletions test/node-api-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,29 @@ suite('node public api', function() {
'module defines its path'
);
});

test('named amd', function() {
var compiled = traceur.compile(contents, {
// absolute path is important
filename: path,

// build ES6 style modules rather then cjs
modules: 'amd',

// enforce a module name in the AMD define
moduleName: 'test-module'
});

assert.deepEqual(compiled.errors, []);
assert.ok(compiled.js, 'can compile');

var gotName;
var define = function(name) {
gotName = name;
}

eval(compiled.js);

assert.ok(gotName == 'test-module', 'module defines into named AMD');
});
});

0 comments on commit cbc7e8c

Please sign in to comment.