Merge branch 'v3nom-master'

This commit is contained in:
Mohamed Hegazy 2015-02-12 09:43:39 -08:00
commit d9058fbda0
14 changed files with 119 additions and 6 deletions

1
.gitignore vendored
View file

@ -44,3 +44,4 @@ scripts/ior.js
scripts/*.js.map scripts/*.js.map
coverage/ coverage/
internal/ internal/
**/.DS_Store

View file

@ -4057,11 +4057,25 @@ module ts {
} }
}); });
} }
function sortAMDModules(amdModules: {name: string; path: string}[]) {
// AMD modules with declared variable names go first
return amdModules.sort((moduleA, moduleB) => {
if (moduleA.name === moduleB.name) {
return 0;
} else if (!moduleA.name) {
return 1;
} else {
return -1;
}
});
}
function emitAMDModule(node: SourceFile, startIndex: number) { function emitAMDModule(node: SourceFile, startIndex: number) {
var imports = getExternalImportDeclarations(node); var imports = getExternalImportDeclarations(node);
writeLine(); writeLine();
write("define("); write("define(");
sortAMDModules(node.amdDependencies);
if (node.amdModuleName) { if (node.amdModuleName) {
write("\"" + node.amdModuleName + "\", "); write("\"" + node.amdModuleName + "\", ");
} }
@ -4071,7 +4085,7 @@ module ts {
emitLiteral(<LiteralExpression>getExternalModuleImportDeclarationExpression(imp)); emitLiteral(<LiteralExpression>getExternalModuleImportDeclarationExpression(imp));
}); });
forEach(node.amdDependencies, amdDependency => { forEach(node.amdDependencies, amdDependency => {
var text = "\"" + amdDependency + "\""; var text = "\"" + amdDependency.path + "\"";
write(", "); write(", ");
write(text); write(text);
}); });
@ -4080,6 +4094,12 @@ module ts {
write(", "); write(", ");
emit(imp.name); emit(imp.name);
}); });
forEach(node.amdDependencies, amdDependency => {
if (amdDependency.name) {
write(", ");
write(amdDependency.name);
}
});
write(") {"); write(") {");
increaseIndent(); increaseIndent();
emitCaptureThisForNodeIfNecessary(node); emitCaptureThisForNodeIfNecessary(node);

View file

@ -4749,7 +4749,7 @@ module ts {
function processReferenceComments(sourceFile: SourceFile): void { function processReferenceComments(sourceFile: SourceFile): void {
var triviaScanner = createScanner(sourceFile.languageVersion, /*skipTrivia*/false, sourceText); var triviaScanner = createScanner(sourceFile.languageVersion, /*skipTrivia*/false, sourceText);
var referencedFiles: FileReference[] = []; var referencedFiles: FileReference[] = [];
var amdDependencies: string[] = []; var amdDependencies: {path: string; name: string}[] = [];
var amdModuleName: string; var amdModuleName: string;
// Keep scanning all the leading trivia in the file until we get to something that // Keep scanning all the leading trivia in the file until we get to something that
@ -4789,10 +4789,17 @@ module ts {
amdModuleName = amdModuleNameMatchResult[2]; amdModuleName = amdModuleNameMatchResult[2];
} }
var amdDependencyRegEx = /^\/\/\/\s*<amd-dependency\s+path\s*=\s*('|")(.+?)\1/gim; var amdDependencyRegEx = /^\/\/\/\s*<amd-dependency\s/gim;
var pathRegex = /\spath\s*=\s*('|")(.+?)\1/gim;
var nameRegex = /\sname\s*=\s*('|")(.+?)\1/gim;
var amdDependencyMatchResult = amdDependencyRegEx.exec(comment); var amdDependencyMatchResult = amdDependencyRegEx.exec(comment);
if (amdDependencyMatchResult) { if (amdDependencyMatchResult) {
amdDependencies.push(amdDependencyMatchResult[2]); var pathMatchResult = pathRegex.exec(comment);
var nameMatchResult = nameRegex.exec(comment);
if (pathMatchResult) {
var amdDependency = {path: pathMatchResult[2], name: nameMatchResult ? nameMatchResult[2] : undefined };
amdDependencies.push(amdDependency);
}
} }
} }
} }

View file

@ -887,7 +887,7 @@ module ts {
fileName: string; fileName: string;
text: string; text: string;
amdDependencies: string[]; amdDependencies: {path: string; name: string}[];
amdModuleName: string; amdModuleName: string;
referencedFiles: FileReference[]; referencedFiles: FileReference[];

View file

@ -725,7 +725,7 @@ module ts {
public statements: NodeArray<Statement>; public statements: NodeArray<Statement>;
public endOfFileToken: Node; public endOfFileToken: Node;
public amdDependencies: string[]; public amdDependencies: {name: string; path: string}[];
public amdModuleName: string; public amdModuleName: string;
public referencedFiles: FileReference[]; public referencedFiles: FileReference[];

View file

@ -0,0 +1,10 @@
tests/cases/compiler/amdDependencyCommentName1.ts(3,21): error TS2307: Cannot find external module 'm2'.
==== tests/cases/compiler/amdDependencyCommentName1.ts (1 errors) ====
///<amd-dependency path='bar' name='b'/>
import m1 = require("m2")
~~~~
!!! error TS2307: Cannot find external module 'm2'.
m1.f();

View file

@ -0,0 +1,10 @@
//// [amdDependencyCommentName1.ts]
///<amd-dependency path='bar' name='b'/>
import m1 = require("m2")
m1.f();
//// [amdDependencyCommentName1.js]
///<amd-dependency path='bar' name='b'/>
var m1 = require("m2");
m1.f();

View file

@ -0,0 +1,10 @@
tests/cases/compiler/amdDependencyCommentName2.ts(3,21): error TS2307: Cannot find external module 'm2'.
==== tests/cases/compiler/amdDependencyCommentName2.ts (1 errors) ====
///<amd-dependency path='bar' name='b'/>
import m1 = require("m2")
~~~~
!!! error TS2307: Cannot find external module 'm2'.
m1.f();

View file

@ -0,0 +1,11 @@
//// [amdDependencyCommentName2.ts]
///<amd-dependency path='bar' name='b'/>
import m1 = require("m2")
m1.f();
//// [amdDependencyCommentName2.js]
///<amd-dependency path='bar' name='b'/>
define(["require", "exports", "m2", "bar"], function (require, exports, m1, b) {
m1.f();
});

View file

@ -0,0 +1,12 @@
tests/cases/compiler/amdDependencyCommentName3.ts(5,21): error TS2307: Cannot find external module 'm2'.
==== tests/cases/compiler/amdDependencyCommentName3.ts (1 errors) ====
///<amd-dependency path='bar' name='b'/>
///<amd-dependency path='foo'/>
///<amd-dependency path='goo' name='c'/>
import m1 = require("m2")
~~~~
!!! error TS2307: Cannot find external module 'm2'.
m1.f();

View file

@ -0,0 +1,15 @@
//// [amdDependencyCommentName3.ts]
///<amd-dependency path='bar' name='b'/>
///<amd-dependency path='foo'/>
///<amd-dependency path='goo' name='c'/>
import m1 = require("m2")
m1.f();
//// [amdDependencyCommentName3.js]
///<amd-dependency path='bar' name='b'/>
///<amd-dependency path='foo'/>
///<amd-dependency path='goo' name='c'/>
define(["require", "exports", "m2", "bar", "goo", "foo"], function (require, exports, m1, b, c) {
m1.f();
});

View file

@ -0,0 +1,5 @@
//@module: commonjs
///<amd-dependency path='bar' name='b'/>
import m1 = require("m2")
m1.f();

View file

@ -0,0 +1,5 @@
//@module: amd
///<amd-dependency path='bar' name='b'/>
import m1 = require("m2")
m1.f();

View file

@ -0,0 +1,7 @@
//@module: amd
///<amd-dependency path='bar' name='b'/>
///<amd-dependency path='foo'/>
///<amd-dependency path='goo' name='c'/>
import m1 = require("m2")
m1.f();