ensure we still throw on multiple anonymous defines (#1116)

This commit is contained in:
guybedford 2016-02-23 18:01:22 +02:00
parent bd8b0d0618
commit 9bcd118d8f
3 changed files with 28 additions and 2 deletions

View File

@ -193,9 +193,11 @@ hookConstructor(function(constructor) {
if (!entry.name) {
if (!curMeta)
throw new TypeError('Unexpected anonymous AMD define.');
if (curMeta.entry && !curMeta.entry.name)
throw new Error('Multiple anonymous defines in module ' + load.name);
if (!curMeta.entry || curMeta.entry.name)
curMeta.entry = entry;
curMeta.entry = entry;
}
// named define
else {

View File

@ -301,6 +301,16 @@ asyncTest('Loading an AMD bundle with an anonymous define', function() {
}, err);
});
asyncTest('Loading an AMD bundle with multiple anonymous defines', function() {
System['import']('tests/multiple-anonymous.js').then(function(m) {
ok(false);
start();
}, function(e) {
ok(e.toString().indexOf('Multiple anonymous') != -1)
start();
});
})
asyncTest('Loading AMD CommonJS form', function() {
System['import']('tests/amd-cjs-module.js').then(function(m) {
ok(m.test == 'hi', 'Not defined');

View File

@ -0,0 +1,14 @@
define('named-in-anon', function() {
return 'named';
});
define(['named-in-anon'], function(named) {
return {
anon: true,
named: named
};
});
define([], function() {
});