Skip to content

Commit fb282fb

Browse files
author
Andy Hanson
committed
Merge branch 'master' into convertToEsModule
2 parents c02ddfc + 8f1cdc9 commit fb282fb

File tree

658 files changed

+39543
-6877
lines changed

Some content is hidden

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

658 files changed

+39543
-6877
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,4 @@ tests/cases/user/*/**/*.d.ts
6767
!tests/cases/user/zone.js/
6868
!tests/cases/user/bignumber.js/
6969
!tests/cases/user/discord.js/
70+
tests/baselines/reference/dt

.gitmodules

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
[submodule "tests/cases/user/TypeScript-React-Starter/TypeScript-React-Starter"]
2+
path = tests/cases/user/TypeScript-React-Starter/TypeScript-React-Starter
3+
url = https://github.com/Microsoft/TypeScript-React-Starter
4+
ignore = all
5+
shallow = true
6+
[submodule "tests/cases/user/TypeScript-Node-Starter/TypeScript-Node-Starter"]
7+
path = tests/cases/user/TypeScript-Node-Starter/TypeScript-Node-Starter
8+
url = https://github.com/Microsoft/TypeScript-Node-Starter.git
9+
ignore = all
10+
shallow = true
11+
[submodule "tests/cases/user/TypeScript-React-Native-Starter/TypeScript-React-Native-Starter"]
12+
path = tests/cases/user/TypeScript-React-Native-Starter/TypeScript-React-Native-Starter
13+
url = https://github.com/Microsoft/TypeScript-React-Native-Starter.git
14+
ignore = all
15+
shallow = true
16+
[submodule "tests/cases/user/TypeScript-Vue-Starter/TypeScript-Vue-Starter"]
17+
path = tests/cases/user/TypeScript-Vue-Starter/TypeScript-Vue-Starter
18+
url = https://github.com/Microsoft/TypeScript-Vue-Starter.git
19+
ignore = all
20+
shallow = true
21+
[submodule "tests/cases/user/TypeScript-WeChat-Starter/TypeScript-WeChat-Starter"]
22+
path = tests/cases/user/TypeScript-WeChat-Starter/TypeScript-WeChat-Starter
23+
url = https://github.com/Microsoft/TypeScript-WeChat-Starter.git
24+
ignore = all
25+
shallow = true

Jakefile.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,10 @@ compileFile(word2mdJs,
731731
[word2mdTs],
732732
[word2mdTs],
733733
[],
734-
/*useBuiltCompiler*/ false);
734+
/*useBuiltCompiler*/ false,
735+
{
736+
lib: "scripthost,es5"
737+
});
735738

736739
// The generated spec.md; built for the 'generate-spec' task
737740
file(specMd, [word2mdJs, specWord], function () {

lib/typescript.d.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -4487,9 +4487,9 @@ declare namespace ts {
44874487
* @param compilationSettings Some compilation settings like target affects the
44884488
* shape of a the resulting SourceFile. This allows the DocumentRegistry to store
44894489
* multiple copies of the same file for different compilation settings.
4490-
* @parm scriptSnapshot Text of the file. Only used if the file was not found
4490+
* @param scriptSnapshot Text of the file. Only used if the file was not found
44914491
* in the registry and a new one was created.
4492-
* @parm version Current version of the file. Only used if the file was not found
4492+
* @param version Current version of the file. Only used if the file was not found
44934493
* in the registry and a new one was created.
44944494
*/
44954495
acquireDocument(fileName: string, compilationSettings: CompilerOptions, scriptSnapshot: IScriptSnapshot, version: string, scriptKind?: ScriptKind): SourceFile;

lib/typescriptServices.d.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -4487,9 +4487,9 @@ declare namespace ts {
44874487
* @param compilationSettings Some compilation settings like target affects the
44884488
* shape of a the resulting SourceFile. This allows the DocumentRegistry to store
44894489
* multiple copies of the same file for different compilation settings.
4490-
* @parm scriptSnapshot Text of the file. Only used if the file was not found
4490+
* @param scriptSnapshot Text of the file. Only used if the file was not found
44914491
* in the registry and a new one was created.
4492-
* @parm version Current version of the file. Only used if the file was not found
4492+
* @param version Current version of the file. Only used if the file was not found
44934493
* in the registry and a new one was created.
44944494
*/
44954495
acquireDocument(fileName: string, compilationSettings: CompilerOptions, scriptSnapshot: IScriptSnapshot, version: string, scriptKind?: ScriptKind): SourceFile;

src/compiler/binder.ts

+126-72
Large diffs are not rendered by default.

src/compiler/builder.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ namespace ts {
7777
}
7878

7979
export interface BuilderOptions {
80-
getCanonicalFileName: (fileName: string) => string;
80+
getCanonicalFileName: GetCanonicalFileName;
8181
computeHash: (data: string) => string;
8282
}
8383

src/compiler/checker.ts

+1,105-441
Large diffs are not rendered by default.

src/compiler/commandLineParser.ts

+12-5
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,13 @@ namespace ts {
277277
category: Diagnostics.Strict_Type_Checking_Options,
278278
description: Diagnostics.Enable_strict_checking_of_function_types
279279
},
280+
{
281+
name: "strictPropertyInitialization",
282+
type: "boolean",
283+
showInSimplifiedHelpView: true,
284+
category: Diagnostics.Strict_Type_Checking_Options,
285+
description: Diagnostics.Enable_strict_checking_of_property_initialization_in_classes
286+
},
280287
{
281288
name: "noImplicitThis",
282289
type: "boolean",
@@ -1540,7 +1547,7 @@ namespace ts {
15401547
host: ParseConfigHost,
15411548
basePath: string,
15421549
configFileName: string,
1543-
getCanonicalFileName: (fileName: string) => string,
1550+
getCanonicalFileName: GetCanonicalFileName,
15441551
resolutionStack: Path[],
15451552
errors: Push<Diagnostic>,
15461553
): ParsedTsconfig {
@@ -1588,7 +1595,7 @@ namespace ts {
15881595
json: any,
15891596
host: ParseConfigHost,
15901597
basePath: string,
1591-
getCanonicalFileName: (fileName: string) => string,
1598+
getCanonicalFileName: GetCanonicalFileName,
15921599
configFileName: string | undefined,
15931600
errors: Push<Diagnostic>
15941601
): ParsedTsconfig {
@@ -1619,7 +1626,7 @@ namespace ts {
16191626
sourceFile: JsonSourceFile,
16201627
host: ParseConfigHost,
16211628
basePath: string,
1622-
getCanonicalFileName: (fileName: string) => string,
1629+
getCanonicalFileName: GetCanonicalFileName,
16231630
configFileName: string | undefined,
16241631
errors: Push<Diagnostic>
16251632
): ParsedTsconfig {
@@ -1688,7 +1695,7 @@ namespace ts {
16881695
extendedConfig: string,
16891696
host: ParseConfigHost,
16901697
basePath: string,
1691-
getCanonicalFileName: (fileName: string) => string,
1698+
getCanonicalFileName: GetCanonicalFileName,
16921699
errors: Push<Diagnostic>,
16931700
createDiagnostic: (message: DiagnosticMessage, arg1?: string) => Diagnostic) {
16941701
extendedConfig = normalizeSlashes(extendedConfig);
@@ -1713,7 +1720,7 @@ namespace ts {
17131720
extendedConfigPath: Path,
17141721
host: ts.ParseConfigHost,
17151722
basePath: string,
1716-
getCanonicalFileName: (fileName: string) => string,
1723+
getCanonicalFileName: GetCanonicalFileName,
17171724
resolutionStack: Path[],
17181725
errors: Push<Diagnostic>,
17191726
): ParsedTsconfig | undefined {

src/compiler/core.ts

+82-20
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,13 @@ namespace ts {
6868
}
6969

7070
// The global Map object. This may not be available, so we must test for it.
71-
declare const Map: { new<T>(): Map<T> } | undefined;
71+
declare const Map: { new <T>(): Map<T> } | undefined;
7272
// Internet Explorer's Map doesn't support iteration, so don't use it.
7373
// tslint:disable-next-line no-in-operator variable-name
7474
const MapCtr = typeof Map !== "undefined" && "entries" in Map.prototype ? Map : shimMap();
7575

7676
// Keep the class inside a function so it doesn't get compiled if it's not used.
77-
function shimMap(): { new<T>(): Map<T> } {
77+
function shimMap(): { new <T>(): Map<T> } {
7878

7979
class MapIterator<T, U extends (string | T | [string, T])> {
8080
private data: MapLike<T>;
@@ -97,7 +97,7 @@ namespace ts {
9797
}
9898
}
9999

100-
return class<T> implements Map<T> {
100+
return class <T> implements Map<T> {
101101
private data = createDictionaryObject<T>();
102102
public size = 0;
103103

@@ -394,11 +394,13 @@ namespace ts {
394394
return result;
395395
}
396396

397-
export function mapIter<T, U>(iter: Iterator<T>, mapFn: (x: T) => U): Iterator<U> {
398-
return { next };
399-
function next(): { value: U, done: false } | { value: never, done: true } {
400-
const iterRes = iter.next();
401-
return iterRes.done ? iterRes : { value: mapFn(iterRes.value), done: false };
397+
398+
export function mapIterator<T, U>(iter: Iterator<T>, mapFn: (x: T) => U): Iterator<U> {
399+
return {
400+
next() {
401+
const iterRes = iter.next();
402+
return iterRes.done ? iterRes : { value: mapFn(iterRes.value), done: false };
403+
}
402404
}
403405
}
404406

@@ -936,6 +938,36 @@ namespace ts {
936938
return array.slice().sort(comparer);
937939
}
938940

941+
export function best<T>(iter: Iterator<T>, isBetter: (a: T, b: T) => boolean): T | undefined {
942+
const x = iter.next();
943+
if (x.done) {
944+
return undefined;
945+
}
946+
let best = x.value;
947+
while (true) {
948+
const { value, done } = iter.next();
949+
if (done) {
950+
return best;
951+
}
952+
if (isBetter(value, best)) {
953+
best = value;
954+
}
955+
}
956+
}
957+
958+
export function arrayIterator<T>(array: ReadonlyArray<T>): Iterator<T> {
959+
let i = 0;
960+
return { next: () => {
961+
if (i === array.length) {
962+
return { value: undefined as never, done: true };
963+
}
964+
else {
965+
i++;
966+
return { value: array[i - 1], done: false };
967+
}
968+
}};
969+
}
970+
939971
/**
940972
* Stable sort of an array. Elements equal to each other maintain their relative position in the array.
941973
*/
@@ -1241,10 +1273,12 @@ namespace ts {
12411273
return result;
12421274
}
12431275

1244-
export function arrayToNumericMap<T>(array: ReadonlyArray<T>, makeKey: (value: T) => number): T[] {
1245-
const result: T[] = [];
1276+
export function arrayToNumericMap<T>(array: ReadonlyArray<T>, makeKey: (value: T) => number): T[];
1277+
export function arrayToNumericMap<T, V>(array: ReadonlyArray<T>, makeKey: (value: T) => number, makeValue: (value: T) => V): V[];
1278+
export function arrayToNumericMap<T, V>(array: ReadonlyArray<T>, makeKey: (value: T) => number, makeValue?: (value: T) => V): V[] {
1279+
const result: V[] = [];
12461280
for (const value of array) {
1247-
result[makeKey(value)] = value;
1281+
result[makeKey(value)] = makeValue ? makeValue(value) : value as any as V;
12481282
}
12491283
return result;
12501284
}
@@ -1343,6 +1377,12 @@ namespace ts {
13431377
return Array.isArray ? Array.isArray(value) : value instanceof Array;
13441378
}
13451379

1380+
export function toArray<T>(value: T | ReadonlyArray<T>): ReadonlyArray<T>;
1381+
export function toArray<T>(value: T | T[]): T[];
1382+
export function toArray<T>(value: T | T[]): T[] {
1383+
return isArray(value) ? value : [value];
1384+
}
1385+
13461386
/**
13471387
* Tests whether a value is string
13481388
*/
@@ -1942,7 +1982,7 @@ namespace ts {
19421982
: moduleKind === ModuleKind.System;
19431983
}
19441984

1945-
export type StrictOptionName = "noImplicitAny" | "noImplicitThis" | "strictNullChecks" | "strictFunctionTypes" | "alwaysStrict";
1985+
export type StrictOptionName = "noImplicitAny" | "noImplicitThis" | "strictNullChecks" | "strictFunctionTypes" | "strictPropertyInitialization" | "alwaysStrict";
19461986

19471987
export function getStrictOptionValue(compilerOptions: CompilerOptions, flag: StrictOptionName): boolean {
19481988
return compilerOptions[flag] === undefined ? compilerOptions.strict : compilerOptions[flag];
@@ -2052,7 +2092,7 @@ namespace ts {
20522092
}
20532093
}
20542094

2055-
export function getRelativePathToDirectoryOrUrl(directoryPathOrUrl: string, relativeOrAbsolutePath: string, currentDirectory: string, getCanonicalFileName: (fileName: string) => string, isAbsolutePathAnUrl: boolean) {
2095+
export function getRelativePathToDirectoryOrUrl(directoryPathOrUrl: string, relativeOrAbsolutePath: string, currentDirectory: string, getCanonicalFileName: GetCanonicalFileName, isAbsolutePathAnUrl: boolean) {
20562096
const pathComponents = getNormalizedPathOrUrlComponents(relativeOrAbsolutePath, currentDirectory);
20572097
const directoryComponents = getNormalizedPathOrUrlComponents(directoryPathOrUrl, currentDirectory);
20582098
if (directoryComponents.length > 1 && lastOrUndefined(directoryComponents) === "") {
@@ -2188,6 +2228,10 @@ namespace ts {
21882228
return expectedPos >= 0 && str.indexOf(suffix, expectedPos) === expectedPos;
21892229
}
21902230

2231+
export function removeSuffix(str: string, suffix: string): string {
2232+
return endsWith(str, suffix) ? str.slice(0, str.length - suffix.length) : str;
2233+
}
2234+
21912235
export function stringContains(str: string, substring: string): boolean {
21922236
return str.indexOf(substring) !== -1;
21932237
}
@@ -2654,6 +2698,17 @@ namespace ts {
26542698
return <T>(removeFileExtension(path) + newExtension);
26552699
}
26562700

2701+
/**
2702+
* Takes a string like "jquery-min.4.2.3" and returns "jquery"
2703+
*/
2704+
export function removeMinAndVersionNumbers(fileName: string) {
2705+
// Match a "." or "-" followed by a version number or 'min' at the end of the name
2706+
const trailingMinOrVersion = /[.-]((min)|(\d+(\.\d+)*))$/;
2707+
2708+
// The "min" or version may both be present, in either order, so try applying the above twice.
2709+
return fileName.replace(trailingMinOrVersion, "").replace(trailingMinOrVersion, "");
2710+
}
2711+
26572712
export interface ObjectAllocator {
26582713
getNodeConstructor(): new (kind: SyntaxKind, pos?: number, end?: number) => Node;
26592714
getTokenConstructor(): new <TKind extends SyntaxKind>(kind: TKind, pos?: number, end?: number) => Token<TKind>;
@@ -2716,6 +2771,12 @@ namespace ts {
27162771
VeryAggressive = 3,
27172772
}
27182773

2774+
/**
2775+
* Safer version of `Function` which should not be called.
2776+
* Every function should be assignable to this, but this should not be assignable to every function.
2777+
*/
2778+
export type AnyFunction = (...args: never[]) => void;
2779+
27192780
export namespace Debug {
27202781
export let currentAssertionLevel = AssertionLevel.None;
27212782
export let isDebugging = false;
@@ -2724,7 +2785,7 @@ namespace ts {
27242785
return currentAssertionLevel >= level;
27252786
}
27262787

2727-
export function assert(expression: boolean, message?: string, verboseDebugInfo?: string | (() => string), stackCrawlMark?: Function): void {
2788+
export function assert(expression: boolean, message?: string, verboseDebugInfo?: string | (() => string), stackCrawlMark?: AnyFunction): void {
27282789
if (!expression) {
27292790
if (verboseDebugInfo) {
27302791
message += "\r\nVerbose Debug Information: " + (typeof verboseDebugInfo === "string" ? verboseDebugInfo : verboseDebugInfo());
@@ -2758,7 +2819,7 @@ namespace ts {
27582819
}
27592820
}
27602821

2761-
export function fail(message?: string, stackCrawlMark?: Function): never {
2822+
export function fail(message?: string, stackCrawlMark?: AnyFunction): never {
27622823
debugger;
27632824
const e = new Error(message ? `Debug Failure. ${message}` : "Debug Failure.");
27642825
if ((<any>Error).captureStackTrace) {
@@ -2767,11 +2828,11 @@ namespace ts {
27672828
throw e;
27682829
}
27692830

2770-
export function assertNever(member: never, message?: string, stackCrawlMark?: Function): never {
2831+
export function assertNever(member: never, message?: string, stackCrawlMark?: AnyFunction): never {
27712832
return fail(message || `Illegal value: ${member}`, stackCrawlMark || assertNever);
27722833
}
27732834

2774-
export function getFunctionName(func: Function) {
2835+
export function getFunctionName(func: AnyFunction) {
27752836
if (typeof func !== "function") {
27762837
return "";
27772838
}
@@ -2827,7 +2888,8 @@ namespace ts {
28272888
}
28282889
}
28292890

2830-
export function createGetCanonicalFileName(useCaseSensitiveFileNames: boolean): (fileName: string) => string {
2891+
export type GetCanonicalFileName = (fileName: string) => string;
2892+
export function createGetCanonicalFileName(useCaseSensitiveFileNames: boolean): GetCanonicalFileName {
28312893
return useCaseSensitiveFileNames
28322894
? ((fileName) => fileName)
28332895
: ((fileName) => fileName.toLowerCase());
@@ -2854,7 +2916,7 @@ namespace ts {
28542916
return findBestPatternMatch(patterns, _ => _, candidate);
28552917
}
28562918

2857-
export function patternText({prefix, suffix}: Pattern): string {
2919+
export function patternText({ prefix, suffix }: Pattern): string {
28582920
return `${prefix}*${suffix}`;
28592921
}
28602922

@@ -2884,7 +2946,7 @@ namespace ts {
28842946
return matchedValue;
28852947
}
28862948

2887-
function isPatternMatch({prefix, suffix}: Pattern, candidate: string) {
2949+
function isPatternMatch({ prefix, suffix }: Pattern, candidate: string) {
28882950
return candidate.length >= prefix.length + suffix.length &&
28892951
startsWith(candidate, prefix) &&
28902952
endsWith(candidate, suffix);

0 commit comments

Comments
 (0)