Skip to content

Commit d9058fb

Browse files
committed
Merge branch 'v3nom-master'
2 parents f2c98ba + d94cbed commit d9058fb

14 files changed

Lines changed: 119 additions & 6 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,4 @@ scripts/ior.js
4444
scripts/*.js.map
4545
coverage/
4646
internal/
47+
**/.DS_Store

src/compiler/emitter.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4057,11 +4057,25 @@ module ts {
40574057
}
40584058
});
40594059
}
4060+
4061+
function sortAMDModules(amdModules: {name: string; path: string}[]) {
4062+
// AMD modules with declared variable names go first
4063+
return amdModules.sort((moduleA, moduleB) => {
4064+
if (moduleA.name === moduleB.name) {
4065+
return 0;
4066+
} else if (!moduleA.name) {
4067+
return 1;
4068+
} else {
4069+
return -1;
4070+
}
4071+
});
4072+
}
40604073

40614074
function emitAMDModule(node: SourceFile, startIndex: number) {
40624075
var imports = getExternalImportDeclarations(node);
40634076
writeLine();
40644077
write("define(");
4078+
sortAMDModules(node.amdDependencies);
40654079
if (node.amdModuleName) {
40664080
write("\"" + node.amdModuleName + "\", ");
40674081
}
@@ -4071,7 +4085,7 @@ module ts {
40714085
emitLiteral(<LiteralExpression>getExternalModuleImportDeclarationExpression(imp));
40724086
});
40734087
forEach(node.amdDependencies, amdDependency => {
4074-
var text = "\"" + amdDependency + "\"";
4088+
var text = "\"" + amdDependency.path + "\"";
40754089
write(", ");
40764090
write(text);
40774091
});
@@ -4080,6 +4094,12 @@ module ts {
40804094
write(", ");
40814095
emit(imp.name);
40824096
});
4097+
forEach(node.amdDependencies, amdDependency => {
4098+
if (amdDependency.name) {
4099+
write(", ");
4100+
write(amdDependency.name);
4101+
}
4102+
});
40834103
write(") {");
40844104
increaseIndent();
40854105
emitCaptureThisForNodeIfNecessary(node);

src/compiler/parser.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4749,7 +4749,7 @@ module ts {
47494749
function processReferenceComments(sourceFile: SourceFile): void {
47504750
var triviaScanner = createScanner(sourceFile.languageVersion, /*skipTrivia*/false, sourceText);
47514751
var referencedFiles: FileReference[] = [];
4752-
var amdDependencies: string[] = [];
4752+
var amdDependencies: {path: string; name: string}[] = [];
47534753
var amdModuleName: string;
47544754

47554755
// Keep scanning all the leading trivia in the file until we get to something that
@@ -4789,10 +4789,17 @@ module ts {
47894789
amdModuleName = amdModuleNameMatchResult[2];
47904790
}
47914791

4792-
var amdDependencyRegEx = /^\/\/\/\s*<amd-dependency\s+path\s*=\s*('|")(.+?)\1/gim;
4792+
var amdDependencyRegEx = /^\/\/\/\s*<amd-dependency\s/gim;
4793+
var pathRegex = /\spath\s*=\s*('|")(.+?)\1/gim;
4794+
var nameRegex = /\sname\s*=\s*('|")(.+?)\1/gim;
47934795
var amdDependencyMatchResult = amdDependencyRegEx.exec(comment);
47944796
if (amdDependencyMatchResult) {
4795-
amdDependencies.push(amdDependencyMatchResult[2]);
4797+
var pathMatchResult = pathRegex.exec(comment);
4798+
var nameMatchResult = nameRegex.exec(comment);
4799+
if (pathMatchResult) {
4800+
var amdDependency = {path: pathMatchResult[2], name: nameMatchResult ? nameMatchResult[2] : undefined };
4801+
amdDependencies.push(amdDependency);
4802+
}
47964803
}
47974804
}
47984805
}

src/compiler/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -887,7 +887,7 @@ module ts {
887887
fileName: string;
888888
text: string;
889889

890-
amdDependencies: string[];
890+
amdDependencies: {path: string; name: string}[];
891891
amdModuleName: string;
892892
referencedFiles: FileReference[];
893893

src/services/services.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -725,7 +725,7 @@ module ts {
725725
public statements: NodeArray<Statement>;
726726
public endOfFileToken: Node;
727727

728-
public amdDependencies: string[];
728+
public amdDependencies: {name: string; path: string}[];
729729
public amdModuleName: string;
730730
public referencedFiles: FileReference[];
731731

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
tests/cases/compiler/amdDependencyCommentName1.ts(3,21): error TS2307: Cannot find external module 'm2'.
2+
3+
4+
==== tests/cases/compiler/amdDependencyCommentName1.ts (1 errors) ====
5+
///<amd-dependency path='bar' name='b'/>
6+
7+
import m1 = require("m2")
8+
~~~~
9+
!!! error TS2307: Cannot find external module 'm2'.
10+
m1.f();
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
//// [amdDependencyCommentName1.ts]
2+
///<amd-dependency path='bar' name='b'/>
3+
4+
import m1 = require("m2")
5+
m1.f();
6+
7+
//// [amdDependencyCommentName1.js]
8+
///<amd-dependency path='bar' name='b'/>
9+
var m1 = require("m2");
10+
m1.f();
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
tests/cases/compiler/amdDependencyCommentName2.ts(3,21): error TS2307: Cannot find external module 'm2'.
2+
3+
4+
==== tests/cases/compiler/amdDependencyCommentName2.ts (1 errors) ====
5+
///<amd-dependency path='bar' name='b'/>
6+
7+
import m1 = require("m2")
8+
~~~~
9+
!!! error TS2307: Cannot find external module 'm2'.
10+
m1.f();
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//// [amdDependencyCommentName2.ts]
2+
///<amd-dependency path='bar' name='b'/>
3+
4+
import m1 = require("m2")
5+
m1.f();
6+
7+
//// [amdDependencyCommentName2.js]
8+
///<amd-dependency path='bar' name='b'/>
9+
define(["require", "exports", "m2", "bar"], function (require, exports, m1, b) {
10+
m1.f();
11+
});
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
tests/cases/compiler/amdDependencyCommentName3.ts(5,21): error TS2307: Cannot find external module 'm2'.
2+
3+
4+
==== tests/cases/compiler/amdDependencyCommentName3.ts (1 errors) ====
5+
///<amd-dependency path='bar' name='b'/>
6+
///<amd-dependency path='foo'/>
7+
///<amd-dependency path='goo' name='c'/>
8+
9+
import m1 = require("m2")
10+
~~~~
11+
!!! error TS2307: Cannot find external module 'm2'.
12+
m1.f();

0 commit comments

Comments
 (0)