Skip to content

Commit 78d1bad

Browse files
committed
Merge branch 'master' into fixGenericSignatureRelation
# Conflicts: # tests/baselines/reference/keyofAndIndexedAccess2.errors.txt # tests/baselines/reference/keyofAndIndexedAccess2.js # tests/baselines/reference/keyofAndIndexedAccess2.symbols # tests/baselines/reference/keyofAndIndexedAccess2.types # tests/cases/conformance/types/keyof/keyofAndIndexedAccess2.ts
2 parents 2f6203e + 6c4876a commit 78d1bad

File tree

340 files changed

+9084
-2508
lines changed

Some content is hidden

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

340 files changed

+9084
-2508
lines changed

.github/pull_request_template.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<!--
22
Thank you for submitting a pull request!
33
4-
Here's a checklist you might find useful.
5-
* [ ] There is an associated issue that is labeled 'Bug' or 'help wanted'
4+
Please verify that:
5+
* [ ] There is an associated issue in the `Backlog` milestone (**required**)
66
* [ ] Code is up-to-date with the `master` branch
77
* [ ] You've successfully run `gulp runtests` locally
88
* [ ] There are new or updated unit tests validating the change
@@ -12,4 +12,3 @@ Refer to CONTRIBUTING.MD for more details.
1212
-->
1313

1414
Fixes #
15-

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
[![Join the chat at https://gitter.im/Microsoft/TypeScript](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/Microsoft/TypeScript?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
99

10-
[TypeScript](https://www.typescriptlang.org/) is a language for application-scale JavaScript. TypeScript adds optional types to JavaScript that support tools for large-scale JavaScript applications for any browser, for any host, on any OS. TypeScript compiles to readable, standards-based JavaScript. Try it out at the [playground](https://www.typescriptlang.org/play/), and stay up to date via [our blog](https://blogs.msdn.microsoft.com/typescript) and [Twitter account](https://twitter.com/typescriptlang).
10+
[TypeScript](https://www.typescriptlang.org/) is a language for application-scale JavaScript. TypeScript adds optional types to JavaScript that support tools for large-scale JavaScript applications for any browser, for any host, on any OS. TypeScript compiles to readable, standards-based JavaScript. Try it out at the [playground](https://www.typescriptlang.org/play/), and stay up to date via [our blog](https://blogs.msdn.microsoft.com/typescript) and [Twitter account](https://twitter.com/typescript).
1111

1212
## Installing
1313

src/compiler/binder.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1625,15 +1625,8 @@ namespace ts {
16251625
}
16261626

16271627
function hasExportDeclarations(node: ModuleDeclaration | SourceFile): boolean {
1628-
const body = node.kind === SyntaxKind.SourceFile ? node : node.body;
1629-
if (body && (body.kind === SyntaxKind.SourceFile || body.kind === SyntaxKind.ModuleBlock)) {
1630-
for (const stat of (<BlockLike>body).statements) {
1631-
if (stat.kind === SyntaxKind.ExportDeclaration || stat.kind === SyntaxKind.ExportAssignment) {
1632-
return true;
1633-
}
1634-
}
1635-
}
1636-
return false;
1628+
const body = isSourceFile(node) ? node : tryCast(node.body, isModuleBlock);
1629+
return !!body && body.statements.some(s => isExportDeclaration(s) || isExportAssignment(s));
16371630
}
16381631

16391632
function setExportContextFlag(node: ModuleDeclaration | SourceFile) {

src/compiler/checker.ts

Lines changed: 529 additions & 169 deletions
Large diffs are not rendered by default.

src/compiler/commandLineParser.ts

Lines changed: 82 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ namespace ts {
1616
["es2017", "lib.es2017.d.ts"],
1717
["es2018", "lib.es2018.d.ts"],
1818
["es2019", "lib.es2019.d.ts"],
19+
["es2020", "lib.es2020.d.ts"],
1920
["esnext", "lib.esnext.d.ts"],
2021
// Host only
2122
["dom", "lib.dom.d.ts"],
@@ -44,8 +45,11 @@ namespace ts {
4445
["es2018.promise", "lib.es2018.promise.d.ts"],
4546
["es2018.regexp", "lib.es2018.regexp.d.ts"],
4647
["es2019.array", "lib.es2019.array.d.ts"],
48+
["es2019.object", "lib.es2019.object.d.ts"],
4749
["es2019.string", "lib.es2019.string.d.ts"],
4850
["es2019.symbol", "lib.es2019.symbol.d.ts"],
51+
["es2020.string", "lib.es2020.string.d.ts"],
52+
["es2020.symbol.wellknown", "lib.es2020.symbol.wellknown.d.ts"],
4953
["esnext.array", "lib.es2019.array.d.ts"],
5054
["esnext.symbol", "lib.es2019.symbol.d.ts"],
5155
["esnext.asynciterable", "lib.es2018.asynciterable.d.ts"],
@@ -210,10 +214,12 @@ namespace ts {
210214
es2017: ScriptTarget.ES2017,
211215
es2018: ScriptTarget.ES2018,
212216
es2019: ScriptTarget.ES2019,
217+
es2020: ScriptTarget.ES2020,
213218
esnext: ScriptTarget.ESNext,
214219
}),
215220
affectsSourceFile: true,
216221
affectsModuleResolution: true,
222+
affectsEmit: true,
217223
paramType: Diagnostics.VERSION,
218224
showInSimplifiedHelpView: true,
219225
category: Diagnostics.Basic_Options,
@@ -1341,7 +1347,12 @@ namespace ts {
13411347
/**
13421348
* Reads the config file, reports errors if any and exits if the config file cannot be found
13431349
*/
1344-
export function getParsedCommandLineOfConfigFile(configFileName: string, optionsToExtend: CompilerOptions, host: ParseConfigFileHost): ParsedCommandLine | undefined {
1350+
export function getParsedCommandLineOfConfigFile(
1351+
configFileName: string,
1352+
optionsToExtend: CompilerOptions,
1353+
host: ParseConfigFileHost,
1354+
extendedConfigCache?: Map<ExtendedConfigCacheEntry>
1355+
): ParsedCommandLine | undefined {
13451356
let configFileText: string | undefined;
13461357
try {
13471358
configFileText = host.readFile(configFileName);
@@ -1362,7 +1373,16 @@ namespace ts {
13621373
result.path = toPath(configFileName, cwd, createGetCanonicalFileName(host.useCaseSensitiveFileNames));
13631374
result.resolvedPath = result.path;
13641375
result.originalFileName = result.fileName;
1365-
return parseJsonSourceFileConfigFileContent(result, host, getNormalizedAbsolutePath(getDirectoryPath(configFileName), cwd), optionsToExtend, getNormalizedAbsolutePath(configFileName, cwd));
1376+
return parseJsonSourceFileConfigFileContent(
1377+
result,
1378+
host,
1379+
getNormalizedAbsolutePath(getDirectoryPath(configFileName), cwd),
1380+
optionsToExtend,
1381+
getNormalizedAbsolutePath(configFileName, cwd),
1382+
/*resolutionStack*/ undefined,
1383+
/*extraFileExtension*/ undefined,
1384+
extendedConfigCache
1385+
);
13661386
}
13671387

13681388
/**
@@ -1965,8 +1985,8 @@ namespace ts {
19651985
* @param basePath A root directory to resolve relative path entries in the config
19661986
* file to. e.g. outDir
19671987
*/
1968-
export function parseJsonConfigFileContent(json: any, host: ParseConfigHost, basePath: string, existingOptions?: CompilerOptions, configFileName?: string, resolutionStack?: Path[], extraFileExtensions?: ReadonlyArray<FileExtensionInfo>): ParsedCommandLine {
1969-
return parseJsonConfigFileContentWorker(json, /*sourceFile*/ undefined, host, basePath, existingOptions, configFileName, resolutionStack, extraFileExtensions);
1988+
export function parseJsonConfigFileContent(json: any, host: ParseConfigHost, basePath: string, existingOptions?: CompilerOptions, configFileName?: string, resolutionStack?: Path[], extraFileExtensions?: ReadonlyArray<FileExtensionInfo>, extendedConfigCache?: Map<ExtendedConfigCacheEntry>): ParsedCommandLine {
1989+
return parseJsonConfigFileContentWorker(json, /*sourceFile*/ undefined, host, basePath, existingOptions, configFileName, resolutionStack, extraFileExtensions, extendedConfigCache);
19701990
}
19711991

19721992
/**
@@ -1976,8 +1996,8 @@ namespace ts {
19761996
* @param basePath A root directory to resolve relative path entries in the config
19771997
* file to. e.g. outDir
19781998
*/
1979-
export function parseJsonSourceFileConfigFileContent(sourceFile: TsConfigSourceFile, host: ParseConfigHost, basePath: string, existingOptions?: CompilerOptions, configFileName?: string, resolutionStack?: Path[], extraFileExtensions?: ReadonlyArray<FileExtensionInfo>): ParsedCommandLine {
1980-
return parseJsonConfigFileContentWorker(/*json*/ undefined, sourceFile, host, basePath, existingOptions, configFileName, resolutionStack, extraFileExtensions);
1999+
export function parseJsonSourceFileConfigFileContent(sourceFile: TsConfigSourceFile, host: ParseConfigHost, basePath: string, existingOptions?: CompilerOptions, configFileName?: string, resolutionStack?: Path[], extraFileExtensions?: ReadonlyArray<FileExtensionInfo>, extendedConfigCache?: Map<ExtendedConfigCacheEntry>): ParsedCommandLine {
2000+
return parseJsonConfigFileContentWorker(/*json*/ undefined, sourceFile, host, basePath, existingOptions, configFileName, resolutionStack, extraFileExtensions, extendedConfigCache);
19812001
}
19822002

19832003
/*@internal*/
@@ -2016,11 +2036,12 @@ namespace ts {
20162036
configFileName?: string,
20172037
resolutionStack: Path[] = [],
20182038
extraFileExtensions: ReadonlyArray<FileExtensionInfo> = [],
2039+
extendedConfigCache?: Map<ExtendedConfigCacheEntry>
20192040
): ParsedCommandLine {
20202041
Debug.assert((json === undefined && sourceFile !== undefined) || (json !== undefined && sourceFile === undefined));
20212042
const errors: Diagnostic[] = [];
20222043

2023-
const parsedConfig = parseConfig(json, sourceFile, host, basePath, configFileName, resolutionStack, errors);
2044+
const parsedConfig = parseConfig(json, sourceFile, host, basePath, configFileName, resolutionStack, errors, extendedConfigCache);
20242045
const { raw } = parsedConfig;
20252046
const options = extend(existingOptions, parsedConfig.options || {});
20262047
options.configFilePath = configFileName && normalizeSlashes(configFileName);
@@ -2168,7 +2189,7 @@ namespace ts {
21682189
return existingErrors !== configParseDiagnostics.length;
21692190
}
21702191

2171-
interface ParsedTsconfig {
2192+
export interface ParsedTsconfig {
21722193
raw: any;
21732194
options?: CompilerOptions;
21742195
typeAcquisition?: TypeAcquisition;
@@ -2187,13 +2208,14 @@ namespace ts {
21872208
* It does *not* resolve the included files.
21882209
*/
21892210
function parseConfig(
2190-
json: any,
2191-
sourceFile: TsConfigSourceFile | undefined,
2192-
host: ParseConfigHost,
2193-
basePath: string,
2194-
configFileName: string | undefined,
2195-
resolutionStack: string[],
2196-
errors: Push<Diagnostic>,
2211+
json: any,
2212+
sourceFile: TsConfigSourceFile | undefined,
2213+
host: ParseConfigHost,
2214+
basePath: string,
2215+
configFileName: string | undefined,
2216+
resolutionStack: string[],
2217+
errors: Push<Diagnostic>,
2218+
extendedConfigCache?: Map<ExtendedConfigCacheEntry>
21972219
): ParsedTsconfig {
21982220
basePath = normalizeSlashes(basePath);
21992221
const resolvedPath = getNormalizedAbsolutePath(configFileName || "", basePath);
@@ -2210,7 +2232,7 @@ namespace ts {
22102232
if (ownConfig.extendedConfigPath) {
22112233
// copy the resolution stack so it is never reused between branches in potential diamond-problem scenarios.
22122234
resolutionStack = resolutionStack.concat([resolvedPath]);
2213-
const extendedConfig = getExtendedConfig(sourceFile, ownConfig.extendedConfigPath, host, basePath, resolutionStack, errors);
2235+
const extendedConfig = getExtendedConfig(sourceFile, ownConfig.extendedConfigPath, host, basePath, resolutionStack, errors, extendedConfigCache);
22142236
if (extendedConfig && isSuccessfulParsedTsconfig(extendedConfig)) {
22152237
const baseRaw = extendedConfig.raw;
22162238
const raw = ownConfig.raw;
@@ -2354,47 +2376,65 @@ namespace ts {
23542376
return undefined;
23552377
}
23562378

2379+
export interface ExtendedConfigCacheEntry {
2380+
extendedResult: TsConfigSourceFile;
2381+
extendedConfig: ParsedTsconfig | undefined;
2382+
}
2383+
23572384
function getExtendedConfig(
23582385
sourceFile: TsConfigSourceFile | undefined,
23592386
extendedConfigPath: string,
23602387
host: ParseConfigHost,
23612388
basePath: string,
23622389
resolutionStack: string[],
23632390
errors: Push<Diagnostic>,
2391+
extendedConfigCache?: Map<ExtendedConfigCacheEntry>
23642392
): ParsedTsconfig | undefined {
2365-
const extendedResult = readJsonConfigFile(extendedConfigPath, path => host.readFile(path));
2393+
const path = host.useCaseSensitiveFileNames ? extendedConfigPath : toLowerCase(extendedConfigPath);
2394+
let value: ExtendedConfigCacheEntry | undefined;
2395+
let extendedResult: TsConfigSourceFile;
2396+
let extendedConfig: ParsedTsconfig | undefined;
2397+
if (extendedConfigCache && (value = extendedConfigCache.get(path))) {
2398+
({ extendedResult, extendedConfig } = value);
2399+
}
2400+
else {
2401+
extendedResult = readJsonConfigFile(extendedConfigPath, path => host.readFile(path));
2402+
if (!extendedResult.parseDiagnostics.length) {
2403+
const extendedDirname = getDirectoryPath(extendedConfigPath);
2404+
extendedConfig = parseConfig(/*json*/ undefined, extendedResult, host, extendedDirname,
2405+
getBaseFileName(extendedConfigPath), resolutionStack, errors, extendedConfigCache);
2406+
2407+
if (isSuccessfulParsedTsconfig(extendedConfig)) {
2408+
// Update the paths to reflect base path
2409+
const relativeDifference = convertToRelativePath(extendedDirname, basePath, identity);
2410+
const updatePath = (path: string) => isRootedDiskPath(path) ? path : combinePaths(relativeDifference, path);
2411+
const mapPropertiesInRawIfNotUndefined = (propertyName: string) => {
2412+
if (raw[propertyName]) {
2413+
raw[propertyName] = map(raw[propertyName], updatePath);
2414+
}
2415+
};
2416+
2417+
const { raw } = extendedConfig;
2418+
mapPropertiesInRawIfNotUndefined("include");
2419+
mapPropertiesInRawIfNotUndefined("exclude");
2420+
mapPropertiesInRawIfNotUndefined("files");
2421+
}
2422+
}
2423+
if (extendedConfigCache) {
2424+
extendedConfigCache.set(path, { extendedResult, extendedConfig });
2425+
}
2426+
}
23662427
if (sourceFile) {
23672428
sourceFile.extendedSourceFiles = [extendedResult.fileName];
2429+
if (extendedResult.extendedSourceFiles) {
2430+
sourceFile.extendedSourceFiles.push(...extendedResult.extendedSourceFiles);
2431+
}
23682432
}
23692433
if (extendedResult.parseDiagnostics.length) {
23702434
errors.push(...extendedResult.parseDiagnostics);
23712435
return undefined;
23722436
}
2373-
2374-
const extendedDirname = getDirectoryPath(extendedConfigPath);
2375-
const extendedConfig = parseConfig(/*json*/ undefined, extendedResult, host, extendedDirname,
2376-
getBaseFileName(extendedConfigPath), resolutionStack, errors);
2377-
if (sourceFile && extendedResult.extendedSourceFiles) {
2378-
sourceFile.extendedSourceFiles!.push(...extendedResult.extendedSourceFiles);
2379-
}
2380-
2381-
if (isSuccessfulParsedTsconfig(extendedConfig)) {
2382-
// Update the paths to reflect base path
2383-
const relativeDifference = convertToRelativePath(extendedDirname, basePath, identity);
2384-
const updatePath = (path: string) => isRootedDiskPath(path) ? path : combinePaths(relativeDifference, path);
2385-
const mapPropertiesInRawIfNotUndefined = (propertyName: string) => {
2386-
if (raw[propertyName]) {
2387-
raw[propertyName] = map(raw[propertyName], updatePath);
2388-
}
2389-
};
2390-
2391-
const { raw } = extendedConfig;
2392-
mapPropertiesInRawIfNotUndefined("include");
2393-
mapPropertiesInRawIfNotUndefined("exclude");
2394-
mapPropertiesInRawIfNotUndefined("files");
2395-
}
2396-
2397-
return extendedConfig;
2437+
return extendedConfig!;
23982438
}
23992439

24002440
function convertCompileOnSaveOptionFromJson(jsonOption: any, basePath: string, errors: Push<Diagnostic>): boolean {

src/compiler/core.ts

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1400,8 +1400,8 @@ namespace ts {
14001400
/** Shims `Array.from`. */
14011401
export function arrayFrom<T, U>(iterator: Iterator<T> | IterableIterator<T>, map: (t: T) => U): U[];
14021402
export function arrayFrom<T>(iterator: Iterator<T> | IterableIterator<T>): T[];
1403-
export function arrayFrom(iterator: Iterator<any> | IterableIterator<any>, map?: (t: any) => any): any[] {
1404-
const result: any[] = [];
1403+
export function arrayFrom<T, U>(iterator: Iterator<T> | IterableIterator<T>, map?: (t: T) => U): (T | U)[] {
1404+
const result: (T | U)[] = [];
14051405
for (let { value, done } = iterator.next(); !done; { value, done } = iterator.next()) {
14061406
result.push(map ? map(value) : value);
14071407
}
@@ -2284,4 +2284,29 @@ namespace ts {
22842284
}
22852285
return result;
22862286
}
2287+
2288+
export function cartesianProduct<T>(arrays: readonly T[][]) {
2289+
const result: T[][] = [];
2290+
cartesianProductWorker(arrays, result, /*outer*/ undefined, 0);
2291+
return result;
2292+
}
2293+
2294+
function cartesianProductWorker<T>(arrays: readonly (readonly T[])[], result: (readonly T[])[], outer: readonly T[] | undefined, index: number) {
2295+
for (const element of arrays[index]) {
2296+
let inner: T[];
2297+
if (outer) {
2298+
inner = outer.slice();
2299+
inner.push(element);
2300+
}
2301+
else {
2302+
inner = [element];
2303+
}
2304+
if (index === arrays.length - 1) {
2305+
result.push(inner);
2306+
}
2307+
else {
2308+
cartesianProductWorker(arrays, result, inner, index + 1);
2309+
}
2310+
}
2311+
}
22872312
}

src/compiler/diagnosticMessages.json

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@
139139
"category": "Error",
140140
"code": 1045
141141
},
142-
"A 'declare' modifier is required for a top level declaration in a .d.ts file.": {
142+
"Top-level declarations in .d.ts files must start with either a 'declare' or 'export' modifier.": {
143143
"category": "Error",
144144
"code": 1046
145145
},
@@ -691,7 +691,7 @@
691691
"category": "Error",
692692
"code": 1218
693693
},
694-
"Experimental support for decorators is a feature that is subject to change in a future release. Set the 'experimentalDecorators' option to remove this warning.": {
694+
"Experimental support for decorators is a feature that is subject to change in a future release. Set the 'experimentalDecorators' option in your 'tsconfig' or 'jsconfig' to remove this warning.": {
695695
"category": "Error",
696696
"code": 1219
697697
},
@@ -1035,6 +1035,10 @@
10351035
"category": "Error",
10361036
"code": 1355
10371037
},
1038+
"Did you mean to mark this function as 'async'?": {
1039+
"category": "Error",
1040+
"code": 1356
1041+
},
10381042

10391043
"Duplicate identifier '{0}'.": {
10401044
"category": "Error",
@@ -2959,7 +2963,7 @@
29592963
"category": "Error",
29602964
"code": 4104
29612965
},
2962-
2966+
29632967
"The current host does not support the '{0}' option.": {
29642968
"category": "Error",
29652969
"code": 5001
@@ -3096,6 +3100,10 @@
30963100
"category": "Error",
30973101
"code": 5074
30983102
},
3103+
"'{0}' is assignable to the constraint of type '{1}', but '{1}' could be instantiated with a different subtype of constraint '{2}'.": {
3104+
"category": "Error",
3105+
"code": 5075
3106+
},
30993107

31003108
"Generates a sourcemap for each corresponding '.d.ts' file.": {
31013109
"category": "Message",
@@ -4272,7 +4280,10 @@
42724280
"category": "Error",
42734281
"code": 7051
42744282
},
4275-
4283+
"Element implicitly has an 'any' type because type '{0}' has no index signature. Did you mean to call '{1}' ?": {
4284+
"category": "Error",
4285+
"code": 7052
4286+
},
42764287
"You cannot rename this element.": {
42774288
"category": "Error",
42784289
"code": 8000
@@ -4954,5 +4965,13 @@
49544965
"No value exists in scope for the shorthand property '{0}'. Either declare one or provide an initializer." :{
49554966
"category": "Error",
49564967
"code": 18004
4968+
},
4969+
"Quoted constructors have previously been interpreted as methods, which is incorrect. In TypeScript 3.6, they will be correctly parsed as constructors. In the meantime, consider using 'constructor()' to write a constructor, or '[\"constructor\"]()' to write a method.": {
4970+
"category": "Error",
4971+
"code": 18005
4972+
},
4973+
"Classes may not have a field named 'constructor'.": {
4974+
"category": "Error",
4975+
"code": 18006
49574976
}
49584977
}

0 commit comments

Comments
 (0)