Skip to content

Commit 6bed1ba

Browse files
committed
merge with master
2 parents d2fd643 + 883b8d9 commit 6bed1ba

1,023 files changed

Lines changed: 7897 additions & 2781 deletions

File tree

Some content is hidden

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

.gitignore

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,5 @@
11
node_modules/
22
built/*
3-
tests/cases/*.js
4-
tests/cases/*/*.js
5-
tests/cases/*/*/*.js
6-
tests/cases/*/*/*/*.js
7-
tests/cases/*/*/*/*/*.js
8-
tests/cases/*.js.map
9-
tests/cases/*/*.js.map
10-
tests/cases/*/*/*.js.map
11-
tests/cases/*/*/*/*.js.map
12-
tests/cases/*/*/*/*/*.js.map
133
tests/cases/rwc/*
144
tests/cases/test262/*
155
tests/cases/perf/*

src/compiler/binder.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ namespace ts {
196196
}
197197
if (node.name.kind === SyntaxKind.ComputedPropertyName) {
198198
const nameExpression = (<ComputedPropertyName>node.name).expression;
199-
// treat computed property names where expression is string/numeric literal as just string/numeric literal
199+
// treat computed property names where expression is string/numeric literal as just string/numeric literal
200200
if (isStringOrNumericLiteral(nameExpression.kind)) {
201201
return (<LiteralExpression>nameExpression).text;
202202
}
@@ -457,7 +457,7 @@ namespace ts {
457457

458458
/**
459459
* Returns true if node and its subnodes were successfully traversed.
460-
* Returning false means that node was not examined and caller needs to dive into the node himself.
460+
* Returning false means that node was not examined and caller needs to dive into the node himself.
461461
*/
462462
function bindReachableStatement(node: Node): void {
463463
if (checkUnreachable(node)) {
@@ -567,7 +567,7 @@ namespace ts {
567567
}
568568

569569
function bindIfStatement(n: IfStatement): void {
570-
// denotes reachability state when entering 'thenStatement' part of the if statement:
570+
// denotes reachability state when entering 'thenStatement' part of the if statement:
571571
// i.e. if condition is false then thenStatement is unreachable
572572
const ifTrueState = n.expression.kind === SyntaxKind.FalseKeyword ? Reachability.Unreachable : currentReachabilityState;
573573
// denotes reachability state when entering 'elseStatement':
@@ -1186,7 +1186,7 @@ namespace ts {
11861186
return checkStrictModePrefixUnaryExpression(<PrefixUnaryExpression>node);
11871187
case SyntaxKind.WithStatement:
11881188
return checkStrictModeWithStatement(<WithStatement>node);
1189-
case SyntaxKind.ThisKeyword:
1189+
case SyntaxKind.ThisType:
11901190
seenThisKeyword = true;
11911191
return;
11921192

@@ -1535,7 +1535,7 @@ namespace ts {
15351535

15361536
// unreachable code is reported if
15371537
// - user has explicitly asked about it AND
1538-
// - statement is in not ambient context (statements in ambient context is already an error
1538+
// - statement is in not ambient context (statements in ambient context is already an error
15391539
// so we should not report extras) AND
15401540
// - node is not variable statement OR
15411541
// - node is block scoped variable statement OR

src/compiler/checker.ts

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4585,7 +4585,7 @@ namespace ts {
45854585
return esSymbolType;
45864586
case SyntaxKind.VoidKeyword:
45874587
return voidType;
4588-
case SyntaxKind.ThisKeyword:
4588+
case SyntaxKind.ThisType:
45894589
return getTypeFromThisTypeNode(node);
45904590
case SyntaxKind.StringLiteral:
45914591
return getTypeFromStringLiteral(<StringLiteral>node);
@@ -6427,6 +6427,8 @@ namespace ts {
64276427
// Only narrow when symbol is variable of type any or an object, union, or type parameter type
64286428
if (node && symbol.flags & SymbolFlags.Variable) {
64296429
if (isTypeAny(type) || type.flags & (TypeFlags.ObjectType | TypeFlags.Union | TypeFlags.TypeParameter)) {
6430+
const declaration = getDeclarationOfKind(symbol, SyntaxKind.VariableDeclaration);
6431+
const top = declaration && getDeclarationContainer(declaration);
64306432
const originalType = type;
64316433
const nodeStack: {node: Node, child: Node}[] = [];
64326434
loop: while (node.parent) {
@@ -6440,15 +6442,12 @@ namespace ts {
64406442
break;
64416443
case SyntaxKind.SourceFile:
64426444
case SyntaxKind.ModuleDeclaration:
6443-
case SyntaxKind.FunctionDeclaration:
6444-
case SyntaxKind.MethodDeclaration:
6445-
case SyntaxKind.MethodSignature:
6446-
case SyntaxKind.GetAccessor:
6447-
case SyntaxKind.SetAccessor:
6448-
case SyntaxKind.Constructor:
6449-
// Stop at the first containing function or module declaration
6445+
// Stop at the first containing file or module declaration
64506446
break loop;
64516447
}
6448+
if (node === top) {
6449+
break;
6450+
}
64526451
}
64536452

64546453
let nodes: {node: Node, child: Node};
@@ -10209,7 +10208,7 @@ namespace ts {
1020910208
checkDestructuringAssignment(<ShorthandPropertyAssignment>p, type);
1021010209
}
1021110210
else {
10212-
// non-shorthand property assignments should always have initializers
10211+
// non-shorthand property assignments should always have initializers
1021310212
checkDestructuringAssignment((<PropertyAssignment>p).initializer, type);
1021410213
}
1021510214
}
@@ -11035,6 +11034,7 @@ namespace ts {
1103511034

1103611035
const symbol = getSymbolOfNode(node);
1103711036
const firstDeclaration = getDeclarationOfKind(symbol, node.kind);
11037+
1103811038
// Only type check the symbol once
1103911039
if (node === firstDeclaration) {
1104011040
checkFunctionOrConstructorSymbol(symbol);
@@ -12065,7 +12065,14 @@ namespace ts {
1206512065
const symbol = getSymbolOfNode(node);
1206612066
const localSymbol = node.localSymbol || symbol;
1206712067

12068-
const firstDeclaration = getDeclarationOfKind(localSymbol, node.kind);
12068+
// Since the javascript won't do semantic analysis like typescript,
12069+
// if the javascript file comes before the typescript file and both contain same name functions,
12070+
// checkFunctionOrConstructorSymbol wouldn't be called if we didnt ignore javascript function.
12071+
const firstDeclaration = forEach(localSymbol.declarations,
12072+
// Get first non javascript function declaration
12073+
declaration => declaration.kind === node.kind && !isSourceFileJavaScript(getSourceFile(declaration)) ?
12074+
declaration : undefined);
12075+
1206912076
// Only type check the symbol once
1207012077
if (node === firstDeclaration) {
1207112078
checkFunctionOrConstructorSymbol(localSymbol);
@@ -14683,6 +14690,9 @@ namespace ts {
1468314690
const type = isExpression(node) ? checkExpression(<Expression>node) : getTypeFromTypeNode(<TypeNode>node);
1468414691
return type.symbol;
1468514692

14693+
case SyntaxKind.ThisType:
14694+
return getTypeFromTypeNode(<TypeNode>node).symbol;
14695+
1468614696
case SyntaxKind.ConstructorKeyword:
1468714697
// constructor keyword for an overload, should take us to the definition if it exist
1468814698
const constructorDeclaration = node.parent;

src/compiler/commandLineParser.ts

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,11 @@ namespace ts {
301301
name: "rootDirs",
302302
type: "object",
303303
isTSConfigOnly: true
304+
},
305+
{
306+
name: "allowJs",
307+
type: "boolean",
308+
description: Diagnostics.Allow_javascript_files_to_be_compiled,
304309
}
305310
];
306311

@@ -500,9 +505,10 @@ namespace ts {
500505
* @param basePath A root directory to resolve relative path entries in the config
501506
* file to. e.g. outDir
502507
*/
503-
export function parseJsonConfigFileContent(json: any, host: ParseConfigHost, basePath: string): ParsedCommandLine {
504-
const { options, errors } = convertCompilerOptionsFromJson(json["compilerOptions"], basePath);
508+
export function parseJsonConfigFileContent(json: any, host: ParseConfigHost, basePath: string, existingOptions: CompilerOptions = {}): ParsedCommandLine {
509+
const { options: optionsFromJsonConfigFile, errors } = convertCompilerOptionsFromJson(json["compilerOptions"], basePath);
505510

511+
const options = extend(existingOptions, optionsFromJsonConfigFile);
506512
// set basePath as inferredBaseUrl so baseUrl module resolution strategy can still work even if user have not specified baseUrl explicity
507513
options.inferredBaseUrl = basePath;
508514

@@ -523,23 +529,32 @@ namespace ts {
523529
}
524530
}
525531
else {
532+
const filesSeen: Map<boolean> = {};
526533
const exclude = json["exclude"] instanceof Array ? map(<string[]>json["exclude"], normalizeSlashes) : undefined;
527-
const sysFiles = host.readDirectory(basePath, ".ts", exclude).concat(host.readDirectory(basePath, ".tsx", exclude));
528-
for (let i = 0; i < sysFiles.length; i++) {
529-
const name = sysFiles[i];
530-
if (fileExtensionIs(name, ".d.ts")) {
531-
const baseName = name.substr(0, name.length - ".d.ts".length);
532-
if (!contains(sysFiles, baseName + ".tsx") && !contains(sysFiles, baseName + ".ts")) {
533-
fileNames.push(name);
534+
const supportedExtensions = getSupportedExtensions(options);
535+
Debug.assert(indexOf(supportedExtensions, ".ts") < indexOf(supportedExtensions, ".d.ts"), "Changed priority of extensions to pick");
536+
537+
// Get files of supported extensions in their order of resolution
538+
for (const extension of supportedExtensions) {
539+
const filesInDirWithExtension = host.readDirectory(basePath, extension, exclude);
540+
for (const fileName of filesInDirWithExtension) {
541+
// .ts extension would read the .d.ts extension files too but since .d.ts is lower priority extension,
542+
// lets pick them when its turn comes up
543+
if (extension === ".ts" && fileExtensionIs(fileName, ".d.ts")) {
544+
continue;
534545
}
535-
}
536-
else if (fileExtensionIs(name, ".ts")) {
537-
if (!contains(sysFiles, name + "x")) {
538-
fileNames.push(name);
546+
547+
// If this is one of the output extension (which would be .d.ts and .js if we are allowing compilation of js files)
548+
// do not include this file if we included .ts or .tsx file with same base name as it could be output of the earlier compilation
549+
if (extension === ".d.ts" || (options.allowJs && contains(supportedJavascriptExtensions, extension))) {
550+
const baseName = fileName.substr(0, fileName.length - extension.length);
551+
if (hasProperty(filesSeen, baseName + ".ts") || hasProperty(filesSeen, baseName + ".tsx")) {
552+
continue;
553+
}
539554
}
540-
}
541-
else {
542-
fileNames.push(name);
555+
556+
filesSeen[fileName] = true;
557+
fileNames.push(fileName);
543558
}
544559
}
545560
}

src/compiler/core.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -297,8 +297,8 @@ namespace ts {
297297
return <T>result;
298298
}
299299

300-
export function extend<T1, T2>(first: Map<T1>, second: Map<T2>): Map<T1 & T2> {
301-
const result: Map<T1 & T2> = {};
300+
export function extend<T1 extends Map<{}>, T2 extends Map<{}>>(first: T1 , second: T2): T1 & T2 {
301+
const result: T1 & T2 = <any>{};
302302
for (const id in first) {
303303
(result as any)[id] = first[id];
304304
}
@@ -714,7 +714,7 @@ namespace ts {
714714
}
715715

716716
export function getBaseFileName(path: string) {
717-
if (!path) {
717+
if (path === undefined) {
718718
return undefined;
719719
}
720720
const i = path.lastIndexOf(directorySeparator);
@@ -738,13 +738,18 @@ namespace ts {
738738
/**
739739
* List of supported extensions in order of file resolution precedence.
740740
*/
741-
export const supportedExtensions = [".ts", ".tsx", ".d.ts"];
742-
export const supportedJsExtensions = supportedExtensions.concat(".js", ".jsx");
741+
export const supportedTypeScriptExtensions = [".ts", ".tsx", ".d.ts"];
742+
export const supportedJavascriptExtensions = [".js", ".jsx"];
743+
const allSupportedExtensions = supportedTypeScriptExtensions.concat(supportedJavascriptExtensions);
743744

744-
export function isSupportedSourceFileName(fileName: string) {
745+
export function getSupportedExtensions(options?: CompilerOptions): string[] {
746+
return options && options.allowJs ? allSupportedExtensions : supportedTypeScriptExtensions;
747+
}
748+
749+
export function isSupportedSourceFileName(fileName: string, compilerOptions?: CompilerOptions) {
745750
if (!fileName) { return false; }
746751

747-
for (const extension of supportedExtensions) {
752+
for (const extension of getSupportedExtensions(compilerOptions)) {
748753
if (fileExtensionIs(fileName, extension)) {
749754
return true;
750755
}
@@ -855,4 +860,4 @@ namespace ts {
855860
}
856861
return copiedList;
857862
}
858-
}
863+
}

0 commit comments

Comments
 (0)