diff --git a/.gitignore b/.gitignore index 57e8804d7c..c54c8018ea 100644 --- a/.gitignore +++ b/.gitignore @@ -44,3 +44,4 @@ scripts/ior.js scripts/*.js.map coverage/ internal/ +**/.DS_Store diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index a452197780..ebd9f3b25c 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -3916,7 +3916,7 @@ module ts { emitLiteral(getExternalModuleImportDeclarationExpression(imp)); }); forEach(node.amdDependencies, amdDependency => { - var text = "\"" + amdDependency + "\""; + var text = "\"" + amdDependency.path + "\""; write(", "); write(text); }); @@ -3925,6 +3925,12 @@ module ts { write(", "); emit(imp.name); }); + forEach(node.amdDependencies, amdDependency => { + if (amdDependency.name) { + write(", "); + write(amdDependency.name); + } + }); write(") {"); increaseIndent(); emitCaptureThisForNodeIfNecessary(node); diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 866d66d515..373c378241 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -4670,7 +4670,7 @@ module ts { function processReferenceComments(sourceFile: SourceFile): void { var triviaScanner = createScanner(sourceFile.languageVersion, /*skipTrivia*/false, sourceText); var referencedFiles: FileReference[] = []; - var amdDependencies: string[] = []; + var amdDependencies: {path: string; name: string}[] = []; var amdModuleName: string; // Keep scanning all the leading trivia in the file until we get to something that @@ -4710,10 +4710,16 @@ module ts { amdModuleName = amdModuleNameMatchResult[2]; } - var amdDependencyRegEx = /^\/\/\/\s*; public endOfFileToken: Node; - public amdDependencies: string[]; + public amdDependencies: {name: string; path: string}[]; public amdModuleName: string; public referencedFiles: FileReference[]; diff --git a/tests/baselines/reference/amdDependencyCommentName1.errors.txt b/tests/baselines/reference/amdDependencyCommentName1.errors.txt new file mode 100644 index 0000000000..081c86b25e --- /dev/null +++ b/tests/baselines/reference/amdDependencyCommentName1.errors.txt @@ -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) ==== + /// + + import m1 = require("m2") + ~~~~ +!!! error TS2307: Cannot find external module 'm2'. + m1.f(); \ No newline at end of file diff --git a/tests/baselines/reference/amdDependencyCommentName1.js b/tests/baselines/reference/amdDependencyCommentName1.js new file mode 100644 index 0000000000..0333653637 --- /dev/null +++ b/tests/baselines/reference/amdDependencyCommentName1.js @@ -0,0 +1,10 @@ +//// [amdDependencyCommentName1.ts] +/// + +import m1 = require("m2") +m1.f(); + +//// [amdDependencyCommentName1.js] +/// +var m1 = require("m2"); +m1.f(); diff --git a/tests/baselines/reference/amdDependencyCommentName2.errors.txt b/tests/baselines/reference/amdDependencyCommentName2.errors.txt new file mode 100644 index 0000000000..137f9335ff --- /dev/null +++ b/tests/baselines/reference/amdDependencyCommentName2.errors.txt @@ -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) ==== + /// + + import m1 = require("m2") + ~~~~ +!!! error TS2307: Cannot find external module 'm2'. + m1.f(); \ No newline at end of file diff --git a/tests/baselines/reference/amdDependencyCommentName2.js b/tests/baselines/reference/amdDependencyCommentName2.js new file mode 100644 index 0000000000..d923df8019 --- /dev/null +++ b/tests/baselines/reference/amdDependencyCommentName2.js @@ -0,0 +1,11 @@ +//// [amdDependencyCommentName2.ts] +/// + +import m1 = require("m2") +m1.f(); + +//// [amdDependencyCommentName2.js] +/// +define(["require", "exports", "m2", "bar"], function (require, exports, m1, b) { + m1.f(); +}); diff --git a/tests/cases/compiler/amdDependencyCommentName1.ts b/tests/cases/compiler/amdDependencyCommentName1.ts new file mode 100644 index 0000000000..958d7ff825 --- /dev/null +++ b/tests/cases/compiler/amdDependencyCommentName1.ts @@ -0,0 +1,5 @@ +//@module: commonjs +/// + +import m1 = require("m2") +m1.f(); \ No newline at end of file diff --git a/tests/cases/compiler/amdDependencyCommentName2.ts b/tests/cases/compiler/amdDependencyCommentName2.ts new file mode 100644 index 0000000000..6cd7d5531f --- /dev/null +++ b/tests/cases/compiler/amdDependencyCommentName2.ts @@ -0,0 +1,5 @@ +//@module: amd +/// + +import m1 = require("m2") +m1.f(); \ No newline at end of file