Skip to content

Commit db0e376

Browse files
committed
Merge remote-tracking branch 'origin/master' into functionAndClassProperties
2 parents 90eef89 + f673f48 commit db0e376

File tree

1,708 files changed

+6092
-1752
lines changed

Some content is hidden

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

1,708 files changed

+6092
-1752
lines changed

src/compiler/binder.ts

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,7 +1046,35 @@ namespace ts {
10461046
if (node.finallyBlock) {
10471047
// in finally flow is combined from pre-try/flow from try/flow from catch
10481048
// pre-flow is necessary to make sure that finally is reachable even if finally flows in both try and finally blocks are unreachable
1049-
addAntecedent(preFinallyLabel, preTryFlow);
1049+
1050+
// also for finally blocks we inject two extra edges into the flow graph.
1051+
// first -> edge that connects pre-try flow with the label at the beginning of the finally block, it has lock associated with it
1052+
// second -> edge that represents post-finally flow.
1053+
// these edges are used in following scenario:
1054+
// let a; (1)
1055+
// try { a = someOperation(); (2)}
1056+
// finally { (3) console.log(a) } (4)
1057+
// (5) a
1058+
1059+
// flow graph for this case looks roughly like this (arrows show ):
1060+
// (1-pre-try-flow) <--.. <-- (2-post-try-flow)
1061+
// ^ ^
1062+
// |*****(3-pre-finally-label) -----|
1063+
// ^
1064+
// |-- ... <-- (4-post-finally-label) <--- (5)
1065+
// In case when we walk the flow starting from inside the finally block we want to take edge '*****' into account
1066+
// since it ensures that finally is always reachable. However when we start outside the finally block and go through label (5)
1067+
// then edge '*****' should be discarded because label 4 is only reachable if post-finally label-4 is reachable
1068+
// Simply speaking code inside finally block is treated as reachable as pre-try-flow
1069+
// since we conservatively assume that any line in try block can throw or return in which case we'll enter finally.
1070+
// However code after finally is reachable only if control flow was not abrupted in try/catch or finally blocks - it should be composed from
1071+
// final flows of these blocks without taking pre-try flow into account.
1072+
//
1073+
// extra edges that we inject allows to control this behavior
1074+
// if when walking the flow we step on post-finally edge - we can mark matching pre-finally edge as locked so it will be skipped.
1075+
const preFinallyFlow: PreFinallyFlow = { flags: FlowFlags.PreFinally, antecedent: preTryFlow, lock: {} };
1076+
addAntecedent(preFinallyLabel, preFinallyFlow);
1077+
10501078
currentFlow = finishFlowLabel(preFinallyLabel);
10511079
bind(node.finallyBlock);
10521080
// if flow after finally is unreachable - keep it
@@ -1062,6 +1090,11 @@ namespace ts {
10621090
: unreachableFlow;
10631091
}
10641092
}
1093+
if (!(currentFlow.flags & FlowFlags.Unreachable)) {
1094+
const afterFinallyFlow: AfterFinallyFlow = { flags: FlowFlags.AfterFinally, antecedent: currentFlow };
1095+
preFinallyFlow.lock = afterFinallyFlow;
1096+
currentFlow = afterFinallyFlow;
1097+
}
10651098
}
10661099
else {
10671100
currentFlow = finishFlowLabel(preFinallyLabel);
@@ -2250,7 +2283,7 @@ namespace ts {
22502283

22512284
// Set up the members collection if it doesn't exist already
22522285
const symbolTable = isPrototypeProperty ?
2253-
(targetSymbol.members || (targetSymbol.members = createMap<Symbol>())):
2286+
(targetSymbol.members || (targetSymbol.members = createMap<Symbol>())) :
22542287
(targetSymbol.exports || (targetSymbol.exports = createMap<Symbol>()));
22552288

22562289
// Declare the method/property

src/compiler/checker.ts

Lines changed: 294 additions & 141 deletions
Large diffs are not rendered by default.

src/compiler/commandLineParser.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -840,7 +840,7 @@ namespace ts {
840840
* @param basePath A root directory to resolve relative path entries in the config
841841
* file to. e.g. outDir
842842
*/
843-
export function parseJsonConfigFileContent(json: any, host: ParseConfigHost, basePath: string, existingOptions: CompilerOptions = {}, configFileName?: string, resolutionStack: Path[] = [], extraFileExtensions: FileExtensionInfo[] = []): ParsedCommandLine {
843+
export function parseJsonConfigFileContent(json: any, host: ParseConfigHost, basePath: string, existingOptions: CompilerOptions = {}, configFileName?: string, resolutionStack: Path[] = [], extraFileExtensions: JsFileExtensionInfo[] = []): ParsedCommandLine {
844844
const errors: Diagnostic[] = [];
845845
basePath = normalizeSlashes(basePath);
846846
const getCanonicalFileName = createGetCanonicalFileName(host.useCaseSensitiveFileNames);
@@ -1186,7 +1186,7 @@ namespace ts {
11861186
* @param host The host used to resolve files and directories.
11871187
* @param errors An array for diagnostic reporting.
11881188
*/
1189-
function matchFileNames(fileNames: string[], include: string[], exclude: string[], basePath: string, options: CompilerOptions, host: ParseConfigHost, errors: Diagnostic[], extraFileExtensions: FileExtensionInfo[]): ExpandResult {
1189+
function matchFileNames(fileNames: string[], include: string[], exclude: string[], basePath: string, options: CompilerOptions, host: ParseConfigHost, errors: Diagnostic[], extraFileExtensions: JsFileExtensionInfo[]): ExpandResult {
11901190
basePath = normalizePath(basePath);
11911191

11921192
// The exclude spec list is converted into a regular expression, which allows us to quickly
@@ -1361,7 +1361,7 @@ namespace ts {
13611361
*/
13621362
function hasFileWithHigherPriorityExtension(file: string, literalFiles: Map<string>, wildcardFiles: Map<string>, extensions: string[], keyMapper: (value: string) => string) {
13631363
const extensionPriority = getExtensionPriority(file, extensions);
1364-
const adjustedExtensionPriority = adjustExtensionPriority(extensionPriority);
1364+
const adjustedExtensionPriority = adjustExtensionPriority(extensionPriority, extensions);
13651365
for (let i = ExtensionPriority.Highest; i < adjustedExtensionPriority; i++) {
13661366
const higherPriorityExtension = extensions[i];
13671367
const higherPriorityPath = keyMapper(changeExtension(file, higherPriorityExtension));
@@ -1383,7 +1383,7 @@ namespace ts {
13831383
*/
13841384
function removeWildcardFilesWithLowerPriorityExtension(file: string, wildcardFiles: Map<string>, extensions: string[], keyMapper: (value: string) => string) {
13851385
const extensionPriority = getExtensionPriority(file, extensions);
1386-
const nextExtensionPriority = getNextLowestExtensionPriority(extensionPriority);
1386+
const nextExtensionPriority = getNextLowestExtensionPriority(extensionPriority, extensions);
13871387
for (let i = nextExtensionPriority; i < extensions.length; i++) {
13881388
const lowerPriorityExtension = extensions[i];
13891389
const lowerPriorityPath = keyMapper(changeExtension(file, lowerPriorityExtension));

src/compiler/core.ts

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2020,14 +2020,14 @@ namespace ts {
20202020
export const supportedJavascriptExtensions = [".js", ".jsx"];
20212021
const allSupportedExtensions = supportedTypeScriptExtensions.concat(supportedJavascriptExtensions);
20222022

2023-
export function getSupportedExtensions(options?: CompilerOptions, extraFileExtensions?: FileExtensionInfo[]): string[] {
2023+
export function getSupportedExtensions(options?: CompilerOptions, extraFileExtensions?: JsFileExtensionInfo[]): string[] {
20242024
const needAllExtensions = options && options.allowJs;
2025-
if (!extraFileExtensions || extraFileExtensions.length === 0) {
2025+
if (!extraFileExtensions || extraFileExtensions.length === 0 || !needAllExtensions) {
20262026
return needAllExtensions ? allSupportedExtensions : supportedTypeScriptExtensions;
20272027
}
2028-
const extensions = (needAllExtensions ? allSupportedExtensions : supportedTypeScriptExtensions).slice(0);
2028+
const extensions = allSupportedExtensions.slice(0);
20292029
for (const extInfo of extraFileExtensions) {
2030-
if (needAllExtensions || extInfo.scriptKind === ScriptKind.TS) {
2030+
if (extensions.indexOf(extInfo.extension) === -1) {
20312031
extensions.push(extInfo.extension);
20322032
}
20332033
}
@@ -2042,7 +2042,7 @@ namespace ts {
20422042
return forEach(supportedTypeScriptExtensions, extension => fileExtensionIs(fileName, extension));
20432043
}
20442044

2045-
export function isSupportedSourceFileName(fileName: string, compilerOptions?: CompilerOptions, extraFileExtensions?: FileExtensionInfo[]) {
2045+
export function isSupportedSourceFileName(fileName: string, compilerOptions?: CompilerOptions, extraFileExtensions?: JsFileExtensionInfo[]) {
20462046
if (!fileName) { return false; }
20472047

20482048
for (const extension of getSupportedExtensions(compilerOptions, extraFileExtensions)) {
@@ -2061,7 +2061,6 @@ namespace ts {
20612061
export const enum ExtensionPriority {
20622062
TypeScriptFiles = 0,
20632063
DeclarationAndJavaScriptFiles = 2,
2064-
Limit = 5,
20652064

20662065
Highest = TypeScriptFiles,
20672066
Lowest = DeclarationAndJavaScriptFiles,
@@ -2070,7 +2069,7 @@ namespace ts {
20702069
export function getExtensionPriority(path: string, supportedExtensions: string[]): ExtensionPriority {
20712070
for (let i = supportedExtensions.length - 1; i >= 0; i--) {
20722071
if (fileExtensionIs(path, supportedExtensions[i])) {
2073-
return adjustExtensionPriority(<ExtensionPriority>i);
2072+
return adjustExtensionPriority(<ExtensionPriority>i, supportedExtensions);
20742073
}
20752074
}
20762075

@@ -2082,27 +2081,26 @@ namespace ts {
20822081
/**
20832082
* Adjusts an extension priority to be the highest priority within the same range.
20842083
*/
2085-
export function adjustExtensionPriority(extensionPriority: ExtensionPriority): ExtensionPriority {
2084+
export function adjustExtensionPriority(extensionPriority: ExtensionPriority, supportedExtensions: string[]): ExtensionPriority {
20862085
if (extensionPriority < ExtensionPriority.DeclarationAndJavaScriptFiles) {
20872086
return ExtensionPriority.TypeScriptFiles;
20882087
}
2089-
else if (extensionPriority < ExtensionPriority.Limit) {
2088+
else if (extensionPriority < supportedExtensions.length) {
20902089
return ExtensionPriority.DeclarationAndJavaScriptFiles;
20912090
}
20922091
else {
2093-
return ExtensionPriority.Limit;
2094-
}
2095-
}
2092+
return supportedExtensions.length;
2093+
} }
20962094

20972095
/**
20982096
* Gets the next lowest extension priority for a given priority.
20992097
*/
2100-
export function getNextLowestExtensionPriority(extensionPriority: ExtensionPriority): ExtensionPriority {
2098+
export function getNextLowestExtensionPriority(extensionPriority: ExtensionPriority, supportedExtensions: string[]): ExtensionPriority {
21012099
if (extensionPriority < ExtensionPriority.DeclarationAndJavaScriptFiles) {
21022100
return ExtensionPriority.DeclarationAndJavaScriptFiles;
21032101
}
21042102
else {
2105-
return ExtensionPriority.Limit;
2103+
return supportedExtensions.length;
21062104
}
21072105
}
21082106

src/compiler/declarationEmitter.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,13 +324,20 @@ namespace ts {
324324
function writeTypeOfDeclaration(declaration: AccessorDeclaration | VariableLikeDeclaration, type: TypeNode, getSymbolAccessibilityDiagnostic: GetSymbolAccessibilityDiagnostic) {
325325
writer.getSymbolAccessibilityDiagnostic = getSymbolAccessibilityDiagnostic;
326326
write(": ");
327-
if (type) {
327+
328+
// use the checker's type, not the declared type,
329+
// for non-optional initialized parameters that aren't a parameter property
330+
const shouldUseResolverType = declaration.kind === SyntaxKind.Parameter &&
331+
resolver.isRequiredInitializedParameter(declaration as ParameterDeclaration);
332+
if (type && !shouldUseResolverType) {
328333
// Write the type
329334
emitType(type);
330335
}
331336
else {
332337
errorNameNode = declaration.name;
333-
resolver.writeTypeOfDeclaration(declaration, enclosingDeclaration, TypeFormatFlags.UseTypeOfFunction | TypeFormatFlags.UseTypeAliasValue, writer);
338+
const format = TypeFormatFlags.UseTypeOfFunction | TypeFormatFlags.UseTypeAliasValue |
339+
(shouldUseResolverType ? TypeFormatFlags.AddUndefined : 0);
340+
resolver.writeTypeOfDeclaration(declaration, enclosingDeclaration, format, writer);
334341
errorNameNode = undefined;
335342
}
336343
}

src/compiler/diagnosticMessages.json

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,10 @@
671671
"category": "Error",
672672
"code": 1215
673673
},
674+
"Identifier expected. '__esModule' is reserved as an exported marker when transforming ECMAScript modules.": {
675+
"category": "Error",
676+
"code": 1216
677+
},
674678
"Export assignment is not supported when '--module' flag is 'system'.": {
675679
"category": "Error",
676680
"code": 1218
@@ -1787,6 +1791,10 @@
17871791
"category": "Error",
17881792
"code": 2545
17891793
},
1794+
"Property '{0}' has conflicting declarations and is inaccessible in type '{1}'.": {
1795+
"category": "Error",
1796+
"code": 2546
1797+
},
17901798
"JSX element attributes type '{0}' may not be a union type.": {
17911799
"category": "Error",
17921800
"code": 2600
@@ -2801,7 +2809,7 @@
28012809
"category": "Message",
28022810
"code": 6099
28032811
},
2804-
"'package.json' does not have a 'types' or 'main' field.": {
2812+
"'package.json' does not have a '{0}' field.": {
28052813
"category": "Message",
28062814
"code": 6100
28072815
},
@@ -2949,10 +2957,6 @@
29492957
"category": "Message",
29502958
"code": 6136
29512959
},
2952-
"No types specified in 'package.json', so returning 'main' value of '{0}'": {
2953-
"category": "Message",
2954-
"code": 6137
2955-
},
29562960
"Property '{0}' is declared but never used.": {
29572961
"category": "Error",
29582962
"code": 6138

0 commit comments

Comments
 (0)