Skip to content

Commit 7aee43b

Browse files
committed
Merge branch 'master' into release-1.5
2 parents 17a8024 + 7f8e21b commit 7aee43b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+1143
-38
lines changed

src/compiler/checker.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3788,7 +3788,7 @@ module ts {
37883788
}
37893789

37903790
function combineTypeMappers(mapper1: TypeMapper, mapper2: TypeMapper): TypeMapper {
3791-
return t => mapper2(mapper1(t));
3791+
return t => instantiateType(mapper1(t), mapper2);
37923792
}
37933793

37943794
function instantiateTypeParameter(typeParameter: TypeParameter, mapper: TypeMapper): TypeParameter {
@@ -3859,7 +3859,7 @@ module ts {
38593859
function instantiateType(type: Type, mapper: TypeMapper): Type {
38603860
if (mapper !== identityMapper) {
38613861
if (type.flags & TypeFlags.TypeParameter) {
3862-
return mapper(type);
3862+
return mapper(<TypeParameter>type);
38633863
}
38643864
if (type.flags & TypeFlags.Anonymous) {
38653865
return type.symbol && type.symbol.flags & (SymbolFlags.Function | SymbolFlags.Method | SymbolFlags.TypeLiteral | SymbolFlags.ObjectLiteral) ?

src/compiler/commandLineParser.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,13 @@ module ts {
110110
type: "boolean",
111111
description: Diagnostics.Do_not_emit_comments_to_output,
112112
},
113+
{
114+
name: "rootDir",
115+
type: "string",
116+
isFilePath: true,
117+
description: Diagnostics.Specifies_the_root_directory_of_input_files_Use_to_control_the_output_directory_structure_with_outDir,
118+
paramType: Diagnostics.LOCATION,
119+
},
113120
{
114121
name: "separateCompilation",
115122
type: "boolean",

src/compiler/diagnosticInformationMap.generated.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,8 @@ module ts {
496496
Suppress_noImplicitAny_errors_for_indexing_objects_lacking_index_signatures: { code: 6055, category: DiagnosticCategory.Message, key: "Suppress noImplicitAny errors for indexing objects lacking index signatures." },
497497
Do_not_emit_declarations_for_code_that_has_an_internal_annotation: { code: 6056, category: DiagnosticCategory.Message, key: "Do not emit declarations for code that has an '@internal' annotation." },
498498
Preserve_new_lines_when_emitting_code: { code: 6057, category: DiagnosticCategory.Message, key: "Preserve new-lines when emitting code." },
499+
Specifies_the_root_directory_of_input_files_Use_to_control_the_output_directory_structure_with_outDir: { code: 6058, category: DiagnosticCategory.Message, key: "Specifies the root directory of input files. Use to control the output directory structure with --outDir." },
500+
File_0_is_not_under_rootDir_1_rootDir_is_expected_to_contain_all_source_files: { code: 6059, category: DiagnosticCategory.Error, key: "File '{0}' is not under 'rootDir' '{1}'. 'rootDir' is expected to contain all source files." },
499501
Variable_0_implicitly_has_an_1_type: { code: 7005, category: DiagnosticCategory.Error, key: "Variable '{0}' implicitly has an '{1}' type." },
500502
Parameter_0_implicitly_has_an_1_type: { code: 7006, category: DiagnosticCategory.Error, key: "Parameter '{0}' implicitly has an '{1}' type." },
501503
Member_0_implicitly_has_an_1_type: { code: 7008, category: DiagnosticCategory.Error, key: "Member '{0}' implicitly has an '{1}' type." },

src/compiler/diagnosticMessages.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1972,6 +1972,15 @@
19721972
"category": "Message",
19731973
"code": 6057
19741974
},
1975+
"Specifies the root directory of input files. Use to control the output directory structure with --outDir.": {
1976+
"category": "Message",
1977+
"code": 6058
1978+
},
1979+
"File '{0}' is not under 'rootDir' '{1}'. 'rootDir' is expected to contain all source files.": {
1980+
"category": "Error",
1981+
"code": 6059
1982+
},
1983+
19751984

19761985
"Variable '{0}' implicitly has an '{1}' type.": {
19771986
"category": "Error",

src/compiler/program.ts

Lines changed: 69 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,66 @@ module ts {
455455
}
456456
}
457457

458+
function computeCommonSourceDirectory(sourceFiles: SourceFile[]): string {
459+
let commonPathComponents: string[];
460+
let currentDirectory = host.getCurrentDirectory();
461+
forEach(files, sourceFile => {
462+
// Each file contributes into common source file path
463+
if (isDeclarationFile(sourceFile)) {
464+
return;
465+
}
466+
467+
let sourcePathComponents = getNormalizedPathComponents(sourceFile.fileName, currentDirectory);
468+
sourcePathComponents.pop(); // The base file name is not part of the common directory path
469+
470+
if (!commonPathComponents) {
471+
// first file
472+
commonPathComponents = sourcePathComponents;
473+
return;
474+
}
475+
476+
for (let i = 0, n = Math.min(commonPathComponents.length, sourcePathComponents.length); i < n; i++) {
477+
if (commonPathComponents[i] !== sourcePathComponents[i]) {
478+
if (i === 0) {
479+
diagnostics.add(createCompilerDiagnostic(Diagnostics.Cannot_find_the_common_subdirectory_path_for_the_input_files));
480+
return;
481+
}
482+
483+
// New common path found that is 0 -> i-1
484+
commonPathComponents.length = i;
485+
break;
486+
}
487+
}
488+
489+
// If the sourcePathComponents was shorter than the commonPathComponents, truncate to the sourcePathComponents
490+
if (sourcePathComponents.length < commonPathComponents.length) {
491+
commonPathComponents.length = sourcePathComponents.length;
492+
}
493+
});
494+
495+
return getNormalizedPathFromPathComponents(commonPathComponents);
496+
}
497+
498+
function checkSourceFilesBelongToPath(sourceFiles: SourceFile[], rootDirectory: string): boolean {
499+
let allFilesBelongToPath = true;
500+
if (sourceFiles) {
501+
let currentDirectory = host.getCurrentDirectory();
502+
let absoluteRootDirectoryPath = host.getCanonicalFileName(getNormalizedAbsolutePath(rootDirectory, currentDirectory));
503+
504+
for (var sourceFile of sourceFiles) {
505+
if (!isDeclarationFile(sourceFile)) {
506+
let absoluteSourceFilePath = host.getCanonicalFileName(getNormalizedAbsolutePath(sourceFile.fileName, currentDirectory));
507+
if (absoluteSourceFilePath.indexOf(absoluteRootDirectoryPath) !== 0) {
508+
diagnostics.add(createCompilerDiagnostic(Diagnostics.File_0_is_not_under_rootDir_1_rootDir_is_expected_to_contain_all_source_files, sourceFile.fileName, options.rootDir));
509+
allFilesBelongToPath = false;
510+
}
511+
}
512+
}
513+
}
514+
515+
return allFilesBelongToPath;
516+
}
517+
458518
function verifyCompilerOptions() {
459519
if (options.separateCompilation) {
460520
if (options.sourceMap) {
@@ -517,41 +577,16 @@ module ts {
517577
(options.mapRoot && // there is --mapRoot specified and there would be multiple js files generated
518578
(!options.out || firstExternalModuleSourceFile !== undefined))) {
519579

520-
let commonPathComponents: string[];
521-
forEach(files, sourceFile => {
522-
// Each file contributes into common source file path
523-
if (!(sourceFile.flags & NodeFlags.DeclarationFile)
524-
&& !fileExtensionIs(sourceFile.fileName, ".js")) {
525-
let sourcePathComponents = getNormalizedPathComponents(sourceFile.fileName, host.getCurrentDirectory());
526-
sourcePathComponents.pop(); // FileName is not part of directory
527-
if (commonPathComponents) {
528-
for (let i = 0; i < Math.min(commonPathComponents.length, sourcePathComponents.length); i++) {
529-
if (commonPathComponents[i] !== sourcePathComponents[i]) {
530-
if (i === 0) {
531-
diagnostics.add(createCompilerDiagnostic(Diagnostics.Cannot_find_the_common_subdirectory_path_for_the_input_files));
532-
return;
533-
}
534-
535-
// New common path found that is 0 -> i-1
536-
commonPathComponents.length = i;
537-
break;
538-
}
539-
}
540-
541-
// If the fileComponent path completely matched and less than already found update the length
542-
if (sourcePathComponents.length < commonPathComponents.length) {
543-
commonPathComponents.length = sourcePathComponents.length;
544-
}
545-
}
546-
else {
547-
// first file
548-
commonPathComponents = sourcePathComponents;
549-
}
550-
}
551-
});
580+
if (options.rootDir && checkSourceFilesBelongToPath(files, options.rootDir)) {
581+
// If a rootDir is specified and is valid use it as the commonSourceDirectory
582+
commonSourceDirectory = getNormalizedAbsolutePath(options.rootDir, host.getCurrentDirectory());
583+
}
584+
else {
585+
// Compute the commonSourceDirectory from the input files
586+
commonSourceDirectory = computeCommonSourceDirectory(files);
587+
}
552588

553-
commonSourceDirectory = getNormalizedPathFromPathComponents(commonPathComponents);
554-
if (commonSourceDirectory) {
589+
if (commonSourceDirectory && commonSourceDirectory[commonSourceDirectory.length - 1] !== directorySeparator) {
555590
// Make sure directory path ends with directory separator so this string can directly
556591
// used to replace with "" to get the relative path of the source file and the relative path doesn't
557592
// start with / making it rooted path

src/compiler/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1577,7 +1577,7 @@ module ts {
15771577

15781578
/* @internal */
15791579
export interface TypeMapper {
1580-
(t: Type): Type;
1580+
(t: TypeParameter): Type;
15811581
}
15821582

15831583
/* @internal */
@@ -1654,6 +1654,7 @@ module ts {
16541654
preserveConstEnums?: boolean;
16551655
project?: string;
16561656
removeComments?: boolean;
1657+
rootDir?: string;
16571658
sourceMap?: boolean;
16581659
sourceRoot?: string;
16591660
suppressImplicitAnyIndexErrors?: boolean;

src/harness/projectsRunner.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ interface ProjectRunnerTestCase {
1818
runTest?: boolean; // Run the resulting test
1919
bug?: string; // If there is any bug associated with this test case
2020
noResolve?: boolean;
21+
rootDir?: string; // --rootDir
2122
}
2223

2324
interface ProjectRunnerTestCaseResolutionInfo extends ProjectRunnerTestCase {
@@ -160,7 +161,8 @@ class ProjectRunner extends RunnerBase {
160161
mapRoot: testCase.resolveMapRoot && testCase.mapRoot ? ts.sys.resolvePath(testCase.mapRoot) : testCase.mapRoot,
161162
sourceRoot: testCase.resolveSourceRoot && testCase.sourceRoot ? ts.sys.resolvePath(testCase.sourceRoot) : testCase.sourceRoot,
162163
module: moduleKind,
163-
noResolve: testCase.noResolve
164+
noResolve: testCase.noResolve,
165+
rootDir: testCase.rootDir
164166
};
165167
}
166168

@@ -344,6 +346,7 @@ class ProjectRunner extends RunnerBase {
344346
baselineCheck: testCase.baselineCheck,
345347
runTest: testCase.runTest,
346348
bug: testCase.bug,
349+
rootDir: testCase.rootDir,
347350
resolvedInputFiles: ts.map(compilerResult.program.getSourceFiles(), inputFile => inputFile.fileName),
348351
emittedFiles: ts.map(compilerResult.outputFiles, outputFile => outputFile.emittedFileName)
349352
};

src/server/session.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,9 @@ module ts.server {
527527
if (lineText.charAt(i) == " ") {
528528
indentPosition--;
529529
}
530+
else if (lineText.charAt(i) == "\t") {
531+
indentPosition -= editorOptions.IndentSize;
532+
}
530533
else {
531534
break;
532535
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
//// [baseTypeWrappingInstantiationChain.ts]
2+
class C<T1> extends CBase<T1> {
3+
public works() {
4+
new CBaseBase<Wrapper<T1>>(this);
5+
}
6+
public alsoWorks() {
7+
new CBase<T1>(this); // Should not error, parameter is of type Parameter<Wrapper<T1>>
8+
}
9+
10+
public method(t: Wrapper<T1>) { }
11+
}
12+
13+
class CBase<T2> extends CBaseBase<Wrapper<T2>> {
14+
15+
}
16+
17+
class CBaseBase<T3> {
18+
constructor(x: Parameter<T3>) { }
19+
}
20+
21+
class Parameter<T4> {
22+
method(t: T4) { }
23+
}
24+
25+
class Wrapper<T5> {
26+
property: T5;
27+
}
28+
29+
//// [baseTypeWrappingInstantiationChain.js]
30+
var __extends = this.__extends || function (d, b) {
31+
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
32+
function __() { this.constructor = d; }
33+
__.prototype = b.prototype;
34+
d.prototype = new __();
35+
};
36+
var C = (function (_super) {
37+
__extends(C, _super);
38+
function C() {
39+
_super.apply(this, arguments);
40+
}
41+
C.prototype.works = function () {
42+
new CBaseBase(this);
43+
};
44+
C.prototype.alsoWorks = function () {
45+
new CBase(this); // Should not error, parameter is of type Parameter<Wrapper<T1>>
46+
};
47+
C.prototype.method = function (t) { };
48+
return C;
49+
})(CBase);
50+
var CBase = (function (_super) {
51+
__extends(CBase, _super);
52+
function CBase() {
53+
_super.apply(this, arguments);
54+
}
55+
return CBase;
56+
})(CBaseBase);
57+
var CBaseBase = (function () {
58+
function CBaseBase(x) {
59+
}
60+
return CBaseBase;
61+
})();
62+
var Parameter = (function () {
63+
function Parameter() {
64+
}
65+
Parameter.prototype.method = function (t) { };
66+
return Parameter;
67+
})();
68+
var Wrapper = (function () {
69+
function Wrapper() {
70+
}
71+
return Wrapper;
72+
})();
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
=== tests/cases/compiler/baseTypeWrappingInstantiationChain.ts ===
2+
class C<T1> extends CBase<T1> {
3+
>C : Symbol(C, Decl(baseTypeWrappingInstantiationChain.ts, 0, 0))
4+
>T1 : Symbol(T1, Decl(baseTypeWrappingInstantiationChain.ts, 0, 8))
5+
>CBase : Symbol(CBase, Decl(baseTypeWrappingInstantiationChain.ts, 9, 1))
6+
>T1 : Symbol(T1, Decl(baseTypeWrappingInstantiationChain.ts, 0, 8))
7+
8+
public works() {
9+
>works : Symbol(works, Decl(baseTypeWrappingInstantiationChain.ts, 0, 31))
10+
11+
new CBaseBase<Wrapper<T1>>(this);
12+
>CBaseBase : Symbol(CBaseBase, Decl(baseTypeWrappingInstantiationChain.ts, 13, 1))
13+
>Wrapper : Symbol(Wrapper, Decl(baseTypeWrappingInstantiationChain.ts, 21, 1))
14+
>T1 : Symbol(T1, Decl(baseTypeWrappingInstantiationChain.ts, 0, 8))
15+
>this : Symbol(C, Decl(baseTypeWrappingInstantiationChain.ts, 0, 0))
16+
}
17+
public alsoWorks() {
18+
>alsoWorks : Symbol(alsoWorks, Decl(baseTypeWrappingInstantiationChain.ts, 3, 5))
19+
20+
new CBase<T1>(this); // Should not error, parameter is of type Parameter<Wrapper<T1>>
21+
>CBase : Symbol(CBase, Decl(baseTypeWrappingInstantiationChain.ts, 9, 1))
22+
>T1 : Symbol(T1, Decl(baseTypeWrappingInstantiationChain.ts, 0, 8))
23+
>this : Symbol(C, Decl(baseTypeWrappingInstantiationChain.ts, 0, 0))
24+
}
25+
26+
public method(t: Wrapper<T1>) { }
27+
>method : Symbol(method, Decl(baseTypeWrappingInstantiationChain.ts, 6, 5))
28+
>t : Symbol(t, Decl(baseTypeWrappingInstantiationChain.ts, 8, 18))
29+
>Wrapper : Symbol(Wrapper, Decl(baseTypeWrappingInstantiationChain.ts, 21, 1))
30+
>T1 : Symbol(T1, Decl(baseTypeWrappingInstantiationChain.ts, 0, 8))
31+
}
32+
33+
class CBase<T2> extends CBaseBase<Wrapper<T2>> {
34+
>CBase : Symbol(CBase, Decl(baseTypeWrappingInstantiationChain.ts, 9, 1))
35+
>T2 : Symbol(T2, Decl(baseTypeWrappingInstantiationChain.ts, 11, 12))
36+
>CBaseBase : Symbol(CBaseBase, Decl(baseTypeWrappingInstantiationChain.ts, 13, 1))
37+
>Wrapper : Symbol(Wrapper, Decl(baseTypeWrappingInstantiationChain.ts, 21, 1))
38+
>T2 : Symbol(T2, Decl(baseTypeWrappingInstantiationChain.ts, 11, 12))
39+
40+
}
41+
42+
class CBaseBase<T3> {
43+
>CBaseBase : Symbol(CBaseBase, Decl(baseTypeWrappingInstantiationChain.ts, 13, 1))
44+
>T3 : Symbol(T3, Decl(baseTypeWrappingInstantiationChain.ts, 15, 16))
45+
46+
constructor(x: Parameter<T3>) { }
47+
>x : Symbol(x, Decl(baseTypeWrappingInstantiationChain.ts, 16, 16))
48+
>Parameter : Symbol(Parameter, Decl(baseTypeWrappingInstantiationChain.ts, 17, 1))
49+
>T3 : Symbol(T3, Decl(baseTypeWrappingInstantiationChain.ts, 15, 16))
50+
}
51+
52+
class Parameter<T4> {
53+
>Parameter : Symbol(Parameter, Decl(baseTypeWrappingInstantiationChain.ts, 17, 1))
54+
>T4 : Symbol(T4, Decl(baseTypeWrappingInstantiationChain.ts, 19, 16))
55+
56+
method(t: T4) { }
57+
>method : Symbol(method, Decl(baseTypeWrappingInstantiationChain.ts, 19, 21))
58+
>t : Symbol(t, Decl(baseTypeWrappingInstantiationChain.ts, 20, 11))
59+
>T4 : Symbol(T4, Decl(baseTypeWrappingInstantiationChain.ts, 19, 16))
60+
}
61+
62+
class Wrapper<T5> {
63+
>Wrapper : Symbol(Wrapper, Decl(baseTypeWrappingInstantiationChain.ts, 21, 1))
64+
>T5 : Symbol(T5, Decl(baseTypeWrappingInstantiationChain.ts, 23, 14))
65+
66+
property: T5;
67+
>property : Symbol(property, Decl(baseTypeWrappingInstantiationChain.ts, 23, 19))
68+
>T5 : Symbol(T5, Decl(baseTypeWrappingInstantiationChain.ts, 23, 14))
69+
}

0 commit comments

Comments
 (0)