moved AMD module sorting to emitter, updated test case

This commit is contained in:
togru 2015-02-10 10:28:09 +01:00
parent a27a893eeb
commit 8492dfdffd
3 changed files with 16 additions and 7 deletions

View File

@ -3902,11 +3902,25 @@ module ts {
}
});
}
function sortAMDModules(amdModules: {name: string; path: string}[]) {
// AMD modules with declared variable names goes first
return amdModules.sort((moduleA, moduleB) => {
if (moduleA.name == moduleB.name) {
return 0;
} else if (moduleA.name == undefined) {
return 1;
} else {
return -1;
}
});
}
function emitAMDModule(node: SourceFile, startIndex: number) {
var imports = getExternalImportDeclarations(node);
writeLine();
write("define(");
sortAMDModules(node.amdDependencies);
if (node.amdModuleName) {
write("\"" + node.amdModuleName + "\", ");
}

View File

@ -4719,12 +4719,7 @@ module ts {
var nameMatchResult = nameRegex.exec(comment);
if (pathMatchResult) {
var amdDependency = {path: pathMatchResult[2], name: nameMatchResult ? nameMatchResult[2] : undefined };
// AMD dependencies with names have to go first in define header
if (nameMatchResult) {
amdDependencies.unshift(amdDependency);
} else {
amdDependencies.push(amdDependency);
}
amdDependencies.push(amdDependency);
}
}
}

View File

@ -10,6 +10,6 @@ m1.f();
///<amd-dependency path='bar' name='b'/>
///<amd-dependency path='foo'/>
///<amd-dependency path='goo' name='c'/>
define(["require", "exports", "m2", "goo", "bar", "foo"], function (require, exports, m1, c, b) {
define(["require", "exports", "m2", "bar", "goo", "foo"], function (require, exports, m1, b, c) {
m1.f();
});