Skip to content

Commit 530a5c0

Browse files
author
Yui T
committed
Merge branch 'master' into getEmitOutputExternalModule
2 parents 7d72503 + 0625cc4 commit 530a5c0

File tree

38 files changed

+1050
-89
lines changed

38 files changed

+1050
-89
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "typescript",
33
"author": "Microsoft Corp.",
44
"homepage": "http://typescriptlang.org/",
5-
"version": "1.1.0",
5+
"version": "1.3.0",
66
"licenses": [
77
{
88
"type": "Apache License 2.0",

src/compiler/core.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ module ts {
476476
}
477477
}
478478

479-
export function getRelativePathToDirectoryOrUrl(directoryPathOrUrl: string, relativeOrAbsolutePath: string, currentDirectory: string, isAbsolutePathAnUrl: boolean) {
479+
export function getRelativePathToDirectoryOrUrl(directoryPathOrUrl: string, relativeOrAbsolutePath: string, currentDirectory: string, getCanonicalFileName: (fileName: string) => string, isAbsolutePathAnUrl: boolean) {
480480
var pathComponents = getNormalizedPathOrUrlComponents(relativeOrAbsolutePath, currentDirectory);
481481
var directoryComponents = getNormalizedPathOrUrlComponents(directoryPathOrUrl, currentDirectory);
482482
if (directoryComponents.length > 1 && directoryComponents[directoryComponents.length - 1] === "") {
@@ -487,7 +487,7 @@ module ts {
487487

488488
// Find the component that differs
489489
for (var joinStartIndex = 0; joinStartIndex < pathComponents.length && joinStartIndex < directoryComponents.length; joinStartIndex++) {
490-
if (directoryComponents[joinStartIndex] !== pathComponents[joinStartIndex]) {
490+
if (getCanonicalFileName(directoryComponents[joinStartIndex]) !== getCanonicalFileName(pathComponents[joinStartIndex])) {
491491
break;
492492
}
493493
}

src/compiler/emitter.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,8 @@ module ts {
527527
sourceMapData.sourceMapSources.push(getRelativePathToDirectoryOrUrl(sourcesDirectoryPath,
528528
node.filename,
529529
compilerHost.getCurrentDirectory(),
530-
/*isAbsolutePathAnUrl*/ true));
530+
compilerHost.getCanonicalFileName,
531+
/*isAbsolutePathAnUrl*/ true));
531532
sourceMapSourceIndex = sourceMapData.sourceMapSources.length - 1;
532533

533534
// The one that can be used from program to get the actual source file
@@ -669,7 +670,8 @@ module ts {
669670
getDirectoryPath(normalizePath(jsFilePath)), // get the relative sourceMapDir path based on jsFilePath
670671
combinePaths(sourceMapDir, sourceMapData.jsSourceMappingURL), // this is where user expects to see sourceMap
671672
compilerHost.getCurrentDirectory(),
672-
/*isAbsolutePathAnUrl*/ true);
673+
compilerHost.getCanonicalFileName,
674+
/*isAbsolutePathAnUrl*/ true);
673675
}
674676
else {
675677
sourceMapData.jsSourceMappingURL = combinePaths(sourceMapDir, sourceMapData.jsSourceMappingURL);
@@ -3147,7 +3149,8 @@ module ts {
31473149
getDirectoryPath(normalizeSlashes(jsFilePath)),
31483150
declFileName,
31493151
compilerHost.getCurrentDirectory(),
3150-
/*isAbsolutePathAnUrl*/ false);
3152+
compilerHost.getCanonicalFileName,
3153+
/*isAbsolutePathAnUrl*/ false);
31513154

31523155
referencePathsOutput += "/// <reference path=\"" + declFileName + "\" />" + newLine;
31533156
}

src/compiler/parser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3639,7 +3639,7 @@ module ts {
36393639
}
36403640
return finishNode(node);
36413641
}
3642-
3642+
36433643
function parseAndCheckEnumDeclaration(pos: number, flags: NodeFlags): EnumDeclaration {
36443644
function isIntegerLiteral(expression: Expression): boolean {
36453645
function isInteger(literalExpression: LiteralExpression): boolean {

src/compiler/tsc.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
/// <reference path="commandLineParser.ts"/>
1010

1111
module ts {
12-
var version = "1.1.0.0";
12+
var version = "1.3.0.0";
1313

1414
/**
1515
* Checks to see if the locale is in the appropriate format,

src/harness/fourslash.ts

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -413,10 +413,14 @@ module FourSlash {
413413
}
414414

415415
private raiseError(message: string) {
416-
message = "Marker: " + currentTestState.lastKnownMarker + "\n" + message;
416+
message = this.messageAtLastKnownMarker(message);
417417
throw new Error(message);
418418
}
419419

420+
private messageAtLastKnownMarker(message: string) {
421+
return "Marker: " + currentTestState.lastKnownMarker + "\n" + message;
422+
}
423+
420424
private getDiagnostics(fileName: string): ts.Diagnostic[] {
421425
var syntacticErrors = this.languageService.getSyntacticDiagnostics(fileName);
422426
var semanticErrors = this.languageService.getSemanticDiagnostics(fileName);
@@ -778,29 +782,29 @@ module FourSlash {
778782

779783
if (negative) {
780784
if (expectedTypeName !== undefined) {
781-
assert.notEqual(actualQuickInfoMemberName, expectedTypeName, this.assertionMessage("quick info member name", actualQuickInfoMemberName, expectedTypeName));
785+
assert.notEqual(actualQuickInfoMemberName, expectedTypeName, this.messageAtLastKnownMarker("quick info member name"));
782786
}
783787
if (docComment != undefined) {
784-
assert.notEqual(actualQuickInfoDocComment, docComment, this.assertionMessage("quick info doc comment", actualQuickInfoDocComment, docComment));
788+
assert.notEqual(actualQuickInfoDocComment, docComment, this.messageAtLastKnownMarker("quick info doc comment"));
785789
}
786790
if (symbolName !== undefined) {
787-
assert.notEqual(actualQuickInfoSymbolName, symbolName, this.assertionMessage("quick info symbol name", actualQuickInfoSymbolName, symbolName));
791+
assert.notEqual(actualQuickInfoSymbolName, symbolName, this.messageAtLastKnownMarker("quick info symbol name"));
788792
}
789793
if (kind !== undefined) {
790-
assert.notEqual(actualQuickInfoKind, kind, this.assertionMessage("quick info kind", actualQuickInfoKind, kind));
794+
assert.notEqual(actualQuickInfoKind, kind, this.messageAtLastKnownMarker("quick info kind"));
791795
}
792796
} else {
793797
if (expectedTypeName !== undefined) {
794-
assert.equal(actualQuickInfoMemberName, expectedTypeName, this.assertionMessage("quick info member", actualQuickInfoMemberName, expectedTypeName));
798+
assert.equal(actualQuickInfoMemberName, expectedTypeName, this.messageAtLastKnownMarker("quick info member"));
795799
}
796800
if (docComment != undefined) {
797-
assert.equal(actualQuickInfoDocComment, docComment, this.assertionMessage("quick info doc", actualQuickInfoDocComment, docComment));
801+
assert.equal(actualQuickInfoDocComment, docComment, this.messageAtLastKnownMarker("quick info doc"));
798802
}
799803
if (symbolName !== undefined) {
800-
assert.equal(actualQuickInfoSymbolName, symbolName, this.assertionMessage("quick info symbol name", actualQuickInfoSymbolName, symbolName));
804+
assert.equal(actualQuickInfoSymbolName, symbolName, this.messageAtLastKnownMarker("quick info symbol name"));
801805
}
802806
if (kind !== undefined) {
803-
assert.equal(actualQuickInfoKind, kind, this.assertionMessage("quick info kind", actualQuickInfoKind, kind));
807+
assert.equal(actualQuickInfoKind, kind, this.messageAtLastKnownMarker("quick info kind"));
804808
}
805809
}
806810
}
@@ -1480,6 +1484,21 @@ module FourSlash {
14801484
}
14811485
}
14821486

1487+
public verifyDefinitionsName(negative: boolean, expectedName: string, expectedContainerName: string) {
1488+
this.taoInvalidReason = 'verifyDefinititionsInfo NYI';
1489+
1490+
var definitions = this.languageService.getDefinitionAtPosition(this.activeFile.fileName, this.currentCaretPosition);
1491+
var actualDefinitionName = definitions && definitions.length ? definitions[0].name : "";
1492+
var actualDefinitionContainerName = definitions && definitions.length ? definitions[0].containerName : "";
1493+
if (negative) {
1494+
assert.notEqual(actualDefinitionName, expectedName, this.messageAtLastKnownMarker("Definition Info Name"));
1495+
assert.notEqual(actualDefinitionName, expectedName, this.messageAtLastKnownMarker("Definition Info Container Name"));
1496+
} else {
1497+
assert.equal(actualDefinitionName, expectedName, this.messageAtLastKnownMarker("Definition Info Name"));
1498+
assert.equal(actualDefinitionName, expectedName, this.messageAtLastKnownMarker("Definition Info Container Name"));
1499+
}
1500+
}
1501+
14831502
public getMarkers(): Marker[] {
14841503
// Return a copy of the list
14851504
return this.testData.markers.slice(0);
@@ -2128,31 +2147,23 @@ module FourSlash {
21282147
xmlData.push(xml);
21292148
}
21302149

2131-
// Cache these between executions so we don't have to re-parse them for every test
2132-
var fourslashSourceFile: ts.SourceFile = undefined;
2133-
21342150
export function runFourSlashTestContent(content: string, fileName: string): TestXmlData {
21352151
// Parse out the files and their metadata
21362152
var testData = parseTestData(content, fileName);
21372153

21382154
currentTestState = new TestState(testData);
21392155

21402156
var result = '';
2141-
var fourslashFilename = 'fourslash.ts';
2142-
var tsFn = 'tests/cases/fourslash/' + fourslashFilename;
2143-
fourslashSourceFile = fourslashSourceFile || ts.createSourceFile(tsFn, Harness.IO.readFile(tsFn), ts.ScriptTarget.ES5, /*version*/ "0", /*isOpen*/ false);
2144-
2145-
var files: { [filename: string]: ts.SourceFile; } = {};
2146-
files[Harness.Compiler.getCanonicalFileName(fourslashFilename)] = fourslashSourceFile;
2147-
files[Harness.Compiler.getCanonicalFileName(fileName)] = ts.createSourceFile(fileName, content, ts.ScriptTarget.ES5, /*version*/ "0", /*isOpen*/ false);
2148-
files[Harness.Compiler.getCanonicalFileName(Harness.Compiler.defaultLibFileName)] = Harness.Compiler.defaultLibSourceFile;
2149-
2150-
var host = Harness.Compiler.createCompilerHost(files, (fn, contents) => result = contents);
2151-
var program = ts.createProgram([fourslashFilename, fileName], { out: "fourslashTestOutput.js" }, host);
2157+
var host = Harness.Compiler.createCompilerHost([{ unitName: Harness.Compiler.fourslashFilename, content: undefined },
2158+
{ unitName: fileName, content: content }],
2159+
(fn, contents) => result = contents,
2160+
ts.ScriptTarget.ES5,
2161+
sys.useCaseSensitiveFileNames);
2162+
var program = ts.createProgram([Harness.Compiler.fourslashFilename, fileName], { out: "fourslashTestOutput.js" }, host);
21522163
var checker = ts.createTypeChecker(program, /*fullTypeCheckMode*/ true);
21532164
checker.checkProgram();
21542165

2155-
var errs = checker.getDiagnostics(files[fileName]);
2166+
var errs = checker.getDiagnostics(program.getSourceFile(fileName));
21562167
if (errs.length > 0) {
21572168
throw new Error('Error compiling ' + fileName + ': ' + errs.map(e => e.messageText).join('\r\n'));
21582169
}

src/harness/harness.ts

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -534,18 +534,47 @@ module Harness {
534534
export var defaultLibFileName = 'lib.d.ts';
535535
export var defaultLibSourceFile = ts.createSourceFile(defaultLibFileName, IO.readFile(libFolder + 'lib.core.d.ts'), /*languageVersion*/ ts.ScriptTarget.ES5, /*version:*/ "0");
536536

537+
// Cache these between executions so we don't have to re-parse them for every test
538+
export var fourslashFilename = 'fourslash.ts';
539+
export var fourslashSourceFile: ts.SourceFile;
540+
537541
export function getCanonicalFileName(fileName: string): string {
538542
return sys.useCaseSensitiveFileNames ? fileName : fileName.toLowerCase();
539543
}
540544

541-
export function createCompilerHost(filemap: { [filename: string]: ts.SourceFile; }, writeFile: (fn: string, contents: string, writeByteOrderMark:boolean) => void): ts.CompilerHost {
545+
export function createCompilerHost(inputFiles: { unitName: string; content: string; }[],
546+
writeFile: (fn: string, contents: string, writeByteOrderMark: boolean) => void,
547+
scriptTarget: ts.ScriptTarget,
548+
useCaseSensitiveFileNames: boolean): ts.CompilerHost {
549+
550+
// Local get canonical file name function, that depends on passed in parameter for useCaseSensitiveFileNames
551+
function getCanonicalFileName(fileName: string): string {
552+
return useCaseSensitiveFileNames ? fileName : fileName.toLowerCase();
553+
}
554+
555+
var filemap: { [filename: string]: ts.SourceFile; } = {};
556+
// Register input files
557+
function register(file: { unitName: string; content: string; }) {
558+
if (file.content !== undefined) {
559+
var filename = Path.switchToForwardSlashes(file.unitName);
560+
filemap[getCanonicalFileName(filename)] = ts.createSourceFile(filename, file.content, scriptTarget, /*version:*/ "0");
561+
}
562+
};
563+
inputFiles.forEach(register);
564+
542565
return {
543566
getCurrentDirectory: sys.getCurrentDirectory,
544567
getCancellationToken: (): any => undefined,
545568
getSourceFile: (fn, languageVersion) => {
546569
if (Object.prototype.hasOwnProperty.call(filemap, getCanonicalFileName(fn))) {
547570
return filemap[getCanonicalFileName(fn)];
548-
} else {
571+
}
572+
else if (fn === fourslashFilename) {
573+
var tsFn = 'tests/cases/fourslash/' + fourslashFilename;
574+
fourslashSourceFile = fourslashSourceFile || ts.createSourceFile(tsFn, Harness.IO.readFile(tsFn), scriptTarget, /*version*/ "0", /*isOpen*/ false);
575+
return fourslashSourceFile;
576+
}
577+
else {
549578
var lib = defaultLibFileName;
550579
if (fn === defaultLibFileName) {
551580
return defaultLibSourceFile;
@@ -557,7 +586,7 @@ module Harness {
557586
getDefaultLibFilename: () => defaultLibFileName,
558587
writeFile: writeFile,
559588
getCanonicalFileName: getCanonicalFileName,
560-
useCaseSensitiveFileNames: () => sys.useCaseSensitiveFileNames,
589+
useCaseSensitiveFileNames: () => useCaseSensitiveFileNames,
561590
getNewLine: ()=> sys.newLine
562591
};
563592
}
@@ -614,7 +643,7 @@ module Harness {
614643
}
615644

616645
public compileFiles(inputFiles: { unitName: string; content: string }[],
617-
otherFiles: { unitName: string; content?: string }[],
646+
otherFiles: { unitName: string; content: string }[],
618647
onComplete: (result: CompilerResult, checker: ts.TypeChecker) => void,
619648
settingsCallback?: (settings: ts.CompilerOptions) => void,
620649
options?: ts.CompilerOptions) {
@@ -628,9 +657,10 @@ module Harness {
628657
settingsCallback(null);
629658
}
630659

660+
var useCaseSensitiveFileNames = sys.useCaseSensitiveFileNames;
631661
this.settings.forEach(setting => {
632662
switch (setting.flag.toLowerCase()) {
633-
// "filename", "comments", "declaration", "module", "nolib", "sourcemap", "target", "out", "outDir", "noimplicitany", "noresolve"
663+
// "filename", "comments", "declaration", "module", "nolib", "sourcemap", "target", "out", "outdir", "noimplicitany", "noresolve"
634664
case "module":
635665
case "modulegentarget":
636666
if (typeof setting.value === 'string') {
@@ -706,10 +736,13 @@ module Harness {
706736
options.removeComments = setting.value === 'false';
707737
break;
708738

739+
case 'usecasesensitivefilenames':
740+
useCaseSensitiveFileNames = setting.value === 'true';
741+
break;
742+
709743
case 'mapsourcefiles':
710744
case 'maproot':
711745
case 'generatedeclarationfiles':
712-
case 'usecasesensitivefileresolution':
713746
case 'gatherDiagnostics':
714747
case 'codepage':
715748
case 'createFileLog':
@@ -748,7 +781,10 @@ module Harness {
748781
var fileOutputs: GeneratedFile[] = [];
749782

750783
var programFiles = inputFiles.map(file => file.unitName);
751-
var program = ts.createProgram(programFiles, options, createCompilerHost(filemap, (fn, contents, writeByteOrderMark) => fileOutputs.push({ fileName: fn, code: contents, writeByteOrderMark: writeByteOrderMark })));
784+
var program = ts.createProgram(programFiles, options, createCompilerHost(inputFiles.concat(otherFiles),
785+
(fn, contents, writeByteOrderMark) => fileOutputs.push({ fileName: fn, code: contents, writeByteOrderMark: writeByteOrderMark }),
786+
options.target,
787+
useCaseSensitiveFileNames));
752788

753789
var hadParseErrors = program.getDiagnostics().length > 0;
754790

@@ -1034,7 +1070,7 @@ module Harness {
10341070
var optionRegex = /^[\/]{2}\s*@(\w+)\s*:\s*(\S*)/gm; // multiple matches on multiple lines
10351071

10361072
// List of allowed metadata names
1037-
var fileMetadataNames = ["filename", "comments", "declaration", "module", "nolib", "sourcemap", "target", "out", "outDir", "noimplicitany", "noresolve", "newline", "newlines", "emitbom", "errortruncation"];
1073+
var fileMetadataNames = ["filename", "comments", "declaration", "module", "nolib", "sourcemap", "target", "out", "outdir", "noimplicitany", "noresolve", "newline", "newlines", "emitbom", "errortruncation", "usecasesensitivefilenames"];
10381074

10391075
function extractCompilerSettings(content: string): CompilerSetting[] {
10401076

src/harness/projectsRunner.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,8 @@ class ProjectRunner extends RunnerBase {
226226
? filename
227227
: ts.normalizeSlashes(testCase.projectRoot) + "/" + ts.normalizeSlashes(filename);
228228

229-
var diskRelativeName = ts.getRelativePathToDirectoryOrUrl(testCase.projectRoot, diskFileName, getCurrentDirectory(), false);
229+
var diskRelativeName = ts.getRelativePathToDirectoryOrUrl(testCase.projectRoot, diskFileName,
230+
getCurrentDirectory(), Harness.Compiler.getCanonicalFileName, /*isAbsolutePathAnUrl*/ false);
230231
if (ts.isRootedDiskPath(diskRelativeName) || diskRelativeName.substr(0, 3) === "../") {
231232
// If the generated output file resides in the parent folder or is rooted path,
232233
// we need to instead create files that can live in the project reference folder

0 commit comments

Comments
 (0)