Skip to content

Commit 755dc83

Browse files
committed
Merge branch 'master' of github.com:Microsoft/TypeScript into factory-export-default
2 parents c39da7b + 84f5aa5 commit 755dc83

File tree

361 files changed

+7361
-2477
lines changed

Some content is hidden

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

361 files changed

+7361
-2477
lines changed

src/compiler/checker.ts

Lines changed: 442 additions & 158 deletions
Large diffs are not rendered by default.

src/compiler/core.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ namespace ts {
531531
return result;
532532
}
533533

534-
export function flatMapIterator<T, U>(iter: Iterator<T>, mapfn: (x: T) => U[] | Iterator<U> | undefined): Iterator<U> {
534+
export function flatMapIterator<T, U>(iter: Iterator<T>, mapfn: (x: T) => ReadonlyArray<U> | Iterator<U> | undefined): Iterator<U> {
535535
const first = iter.next();
536536
if (first.done) {
537537
return emptyIterator;
@@ -1418,7 +1418,9 @@ namespace ts {
14181418
return typeof text === "string";
14191419
}
14201420

1421-
export function tryCast<TOut extends TIn, TIn = any>(value: TIn | undefined, test: (value: TIn) => value is TOut): TOut | undefined {
1421+
export function tryCast<TOut extends TIn, TIn = any>(value: TIn | undefined, test: (value: TIn) => value is TOut): TOut | undefined;
1422+
export function tryCast<T>(value: T, test: (value: T) => boolean): T | undefined;
1423+
export function tryCast<T>(value: T, test: (value: T) => boolean): T | undefined {
14221424
return value !== undefined && test(value) ? value : undefined;
14231425
}
14241426

src/compiler/diagnosticMessages.json

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1452,6 +1452,10 @@
14521452
"category": "Error",
14531453
"code": 2417
14541454
},
1455+
"Type of computed property's value is '{0}', which is not assignable to type '{1}'.": {
1456+
"category": "Error",
1457+
"code": 2418
1458+
},
14551459
"Class '{0}' incorrectly implements interface '{1}'.": {
14561460
"category": "Error",
14571461
"code": 2420
@@ -2397,6 +2401,14 @@
23972401
"category": "Error",
23982402
"code": 2727
23992403
},
2404+
"'{0}' was declared here.": {
2405+
"category": "Error",
2406+
"code": 2728
2407+
},
2408+
"Property '{0}' is used before its initialization.": {
2409+
"category": "Error",
2410+
"code": 2729
2411+
},
24002412

24012413
"Import declaration '{0}' is using private name '{1}'.": {
24022414
"category": "Error",
@@ -3603,6 +3615,22 @@
36033615
"code": 6199,
36043616
"reportsUnnecessary": true
36053617
},
3618+
"Definitions of the following identifiers conflict with those in another file: {0}": {
3619+
"category": "Error",
3620+
"code": 6200
3621+
},
3622+
"Conflicts are in this file.": {
3623+
"category": "Message",
3624+
"code": 6201
3625+
},
3626+
"'{0}' was also declared here.": {
3627+
"category": "Message",
3628+
"code": 6203
3629+
},
3630+
"and here.": {
3631+
"category": "Message",
3632+
"code": 6204
3633+
},
36063634

36073635
"Projects to reference": {
36083636
"category": "Message",
@@ -3730,6 +3758,15 @@
37303758
"code": 6371
37313759
},
37323760

3761+
"The expected type comes from property '{0}' which is declared here on type '{1}'": {
3762+
"category": "Message",
3763+
"code": 6500
3764+
},
3765+
"The expected type comes from this index signature.": {
3766+
"category": "Message",
3767+
"code": 6501
3768+
},
3769+
37333770
"Variable '{0}' implicitly has an '{1}' type.": {
37343771
"category": "Error",
37353772
"code": 7005
@@ -4451,7 +4488,7 @@
44514488
"category": "Message",
44524489
"code": 95063
44534490
},
4454-
"Add all missing enum members": {
4491+
"Add all missing imports": {
44554492
"category": "Message",
44564493
"code": 95064
44574494
}

src/compiler/factory.ts

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1170,7 +1170,7 @@ namespace ts {
11701170
return node;
11711171
}
11721172

1173-
/* @deprecated */ export function updateArrowFunction(
1173+
/** @deprecated */ export function updateArrowFunction(
11741174
node: ArrowFunction,
11751175
modifiers: ReadonlyArray<Modifier> | undefined,
11761176
typeParameters: ReadonlyArray<TypeParameterDeclaration> | undefined,
@@ -1319,7 +1319,7 @@ namespace ts {
13191319
return node;
13201320
}
13211321

1322-
/* @deprecated */ export function updateConditional(
1322+
/** @deprecated */ export function updateConditional(
13231323
node: ConditionalExpression,
13241324
condition: Expression,
13251325
whenTrue: Expression,
@@ -1531,13 +1531,6 @@ namespace ts {
15311531
return block;
15321532
}
15331533

1534-
/* @internal */
1535-
export function createExpressionStatement(expression: Expression): ExpressionStatement {
1536-
const node = <ExpressionStatement>createSynthesizedNode(SyntaxKind.ExpressionStatement);
1537-
node.expression = expression;
1538-
return node;
1539-
}
1540-
15411534
export function updateBlock(node: Block, statements: ReadonlyArray<Statement>) {
15421535
return node.statements !== statements
15431536
? updateNode(createBlock(statements, node.multiLine), node)
@@ -1563,16 +1556,23 @@ namespace ts {
15631556
return <EmptyStatement>createSynthesizedNode(SyntaxKind.EmptyStatement);
15641557
}
15651558

1566-
export function createStatement(expression: Expression) {
1567-
return createExpressionStatement(parenthesizeExpressionForExpressionStatement(expression));
1559+
export function createExpressionStatement(expression: Expression): ExpressionStatement {
1560+
const node = <ExpressionStatement>createSynthesizedNode(SyntaxKind.ExpressionStatement);
1561+
node.expression = parenthesizeExpressionForExpressionStatement(expression);
1562+
return node;
15681563
}
15691564

1570-
export function updateStatement(node: ExpressionStatement, expression: Expression) {
1565+
export function updateExpressionStatement(node: ExpressionStatement, expression: Expression) {
15711566
return node.expression !== expression
1572-
? updateNode(createStatement(expression), node)
1567+
? updateNode(createExpressionStatement(expression), node)
15731568
: node;
15741569
}
15751570

1571+
/** @deprecated Use `createExpressionStatement` instead. */
1572+
export const createStatement = createExpressionStatement;
1573+
/** @deprecated Use `updateExpressionStatement` instead. */
1574+
export const updateStatement = updateExpressionStatement;
1575+
15761576
export function createIf(expression: Expression, thenStatement: Statement, elseStatement?: Statement) {
15771577
const node = <IfStatement>createSynthesizedNode(SyntaxKind.IfStatement);
15781578
node.expression = expression;
@@ -4358,19 +4358,17 @@ namespace ts {
43584358
case SyntaxKind.ConditionalExpression:
43594359
node = (<ConditionalExpression>node).condition;
43604360
continue;
4361-
43624361
case SyntaxKind.CallExpression:
43634362
if (stopAtCallExpressions) {
43644363
return node;
43654364
}
43664365
// falls through
4366+
case SyntaxKind.AsExpression:
43674367
case SyntaxKind.ElementAccessExpression:
43684368
case SyntaxKind.PropertyAccessExpression:
4369-
node = (<CallExpression | PropertyAccessExpression | ElementAccessExpression>node).expression;
4370-
continue;
4371-
4369+
case SyntaxKind.NonNullExpression:
43724370
case SyntaxKind.PartiallyEmittedExpression:
4373-
node = (<PartiallyEmittedExpression>node).expression;
4371+
node = (<CallExpression | PropertyAccessExpression | ElementAccessExpression | AsExpression | NonNullExpression | PartiallyEmittedExpression>node).expression;
43744372
continue;
43754373
}
43764374

src/compiler/moduleSpecifiers.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace ts.moduleSpecifiers {
99
export function getModuleSpecifier(
1010
compilerOptions: CompilerOptions,
1111
importingSourceFile: SourceFile,
12-
importingSourceFileName: string,
12+
importingSourceFileName: Path,
1313
toFileName: string,
1414
host: ModuleSpecifierResolutionHost,
1515
files: ReadonlyArray<SourceFile>,
@@ -18,7 +18,6 @@ namespace ts.moduleSpecifiers {
1818
const info = getInfo(compilerOptions, importingSourceFile, importingSourceFileName, host);
1919
const modulePaths = getAllModulePaths(files, toFileName, info.getCanonicalFileName, host);
2020
return firstDefined(modulePaths, moduleFileName => getGlobalModuleSpecifier(moduleFileName, info, host, compilerOptions)) ||
21-
getGlobalModuleSpecifier(toFileName, info, host, compilerOptions) ||
2221
first(getLocalModuleSpecifiers(toFileName, info, compilerOptions, preferences));
2322
}
2423

@@ -49,10 +48,10 @@ namespace ts.moduleSpecifiers {
4948
readonly moduleResolutionKind: ModuleResolutionKind;
5049
readonly addJsExtension: boolean;
5150
readonly getCanonicalFileName: GetCanonicalFileName;
52-
readonly sourceDirectory: string;
51+
readonly sourceDirectory: Path;
5352
}
5453
// importingSourceFileName is separate because getEditsForFileRename may need to specify an updated path
55-
function getInfo(compilerOptions: CompilerOptions, importingSourceFile: SourceFile, importingSourceFileName: string, host: ModuleSpecifierResolutionHost): Info {
54+
function getInfo(compilerOptions: CompilerOptions, importingSourceFile: SourceFile, importingSourceFileName: Path, host: ModuleSpecifierResolutionHost): Info {
5655
const moduleResolutionKind = getEmitModuleResolutionKind(compilerOptions);
5756
const addJsExtension = usesJsExtensionOnImports(importingSourceFile);
5857
const getCanonicalFileName = createGetCanonicalFileName(host.useCaseSensitiveFileNames ? host.useCaseSensitiveFileNames() : true);
@@ -67,19 +66,19 @@ namespace ts.moduleSpecifiers {
6766
compilerOptions: CompilerOptions,
6867
) {
6968
return tryGetModuleNameFromTypeRoots(compilerOptions, host, getCanonicalFileName, moduleFileName, addJsExtension)
70-
|| tryGetModuleNameAsNodeModule(compilerOptions, moduleFileName, host, getCanonicalFileName, sourceDirectory)
71-
|| compilerOptions.rootDirs && tryGetModuleNameFromRootDirs(compilerOptions.rootDirs, moduleFileName, sourceDirectory, getCanonicalFileName);
69+
|| tryGetModuleNameAsNodeModule(compilerOptions, moduleFileName, host, getCanonicalFileName, sourceDirectory);
7270
}
7371

7472
function getLocalModuleSpecifiers(
7573
moduleFileName: string,
7674
{ moduleResolutionKind, addJsExtension, getCanonicalFileName, sourceDirectory }: Info,
7775
compilerOptions: CompilerOptions,
7876
preferences: ModuleSpecifierPreferences,
79-
) {
80-
const { baseUrl, paths } = compilerOptions;
77+
): ReadonlyArray<string> {
78+
const { baseUrl, paths, rootDirs } = compilerOptions;
8179

82-
const relativePath = removeExtensionAndIndexPostFix(ensurePathIsNonModuleName(getRelativePathFromDirectory(sourceDirectory, moduleFileName, getCanonicalFileName)), moduleResolutionKind, addJsExtension);
80+
const relativePath = rootDirs && tryGetModuleNameFromRootDirs(rootDirs, moduleFileName, sourceDirectory, getCanonicalFileName) ||
81+
removeExtensionAndIndexPostFix(ensurePathIsNonModuleName(getRelativePathFromDirectory(sourceDirectory, moduleFileName, getCanonicalFileName)), moduleResolutionKind, addJsExtension);
8382
if (!baseUrl || preferences.importModuleSpecifierPreference === "relative") {
8483
return [relativePath];
8584
}
@@ -272,7 +271,7 @@ namespace ts.moduleSpecifiers {
272271
moduleFileName: string,
273272
host: ModuleSpecifierResolutionHost,
274273
getCanonicalFileName: (file: string) => string,
275-
sourceDirectory: string,
274+
sourceDirectory: Path,
276275
): string | undefined {
277276
if (getEmitModuleResolutionKind(options) !== ModuleResolutionKind.NodeJs) {
278277
// nothing to do here
@@ -291,7 +290,7 @@ namespace ts.moduleSpecifiers {
291290
const moduleSpecifier = getDirectoryOrExtensionlessFileName(moduleFileName);
292291
// Get a path that's relative to node_modules or the importing file's path
293292
// if node_modules folder is in this folder or any of its parent folders, no need to keep it.
294-
if (!startsWith(sourceDirectory, moduleSpecifier.substring(0, parts.topLevelNodeModulesIndex))) return undefined;
293+
if (!startsWith(sourceDirectory, getCanonicalFileName(moduleSpecifier.substring(0, parts.topLevelNodeModulesIndex)))) return undefined;
295294
// If the module was found in @types, get the actual Node package name
296295
return getPackageNameFromAtTypesDirectory(moduleSpecifier.substring(parts.topLevelPackageNameIndex + 1));
297296

src/compiler/parser.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2090,8 +2090,18 @@ namespace ts {
20902090
return result;
20912091
}
20922092

2093-
function createMissingList<T extends Node>(): NodeArray<T> {
2094-
return createNodeArray<T>([], getNodePos());
2093+
interface MissingList<T extends Node> extends NodeArray<T> {
2094+
isMissingList: true;
2095+
}
2096+
2097+
function createMissingList<T extends Node>(): MissingList<T> {
2098+
const list = createNodeArray<T>([], getNodePos()) as MissingList<T>;
2099+
list.isMissingList = true;
2100+
return list;
2101+
}
2102+
2103+
function isMissingList(arr: NodeArray<Node>): boolean {
2104+
return !!(arr as MissingList<Node>).isMissingList;
20952105
}
20962106

20972107
function parseBracketedList<T extends Node>(kind: ParsingContext, parseElement: () => T, open: SyntaxKind, close: SyntaxKind): NodeArray<T> {
@@ -2260,8 +2270,7 @@ namespace ts {
22602270
case SyntaxKind.FunctionType:
22612271
case SyntaxKind.ConstructorType: {
22622272
const { parameters, type } = node as FunctionOrConstructorTypeNode;
2263-
// parameters.pos === parameters.end only if we used parseMissingList, else should contain at least `()`
2264-
return parameters.pos === parameters.end || typeHasArrowFunctionBlockingParseError(type);
2273+
return isMissingList(parameters) || typeHasArrowFunctionBlockingParseError(type);
22652274
}
22662275
case SyntaxKind.ParenthesizedType:
22672276
return typeHasArrowFunctionBlockingParseError((node as ParenthesizedTypeNode).type);

src/compiler/program.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -329,16 +329,17 @@ namespace ts {
329329
return context;
330330
}
331331

332-
function formatLocation(file: SourceFile, start: number, host: FormatDiagnosticsHost) {
332+
/* @internal */
333+
export function formatLocation(file: SourceFile, start: number, host: FormatDiagnosticsHost, color = formatColorAndReset) {
333334
const { line: firstLine, character: firstLineChar } = getLineAndCharacterOfPosition(file, start); // TODO: GH#18217
334335
const relativeFileName = host ? convertToRelativePath(file.fileName, host.getCurrentDirectory(), fileName => host.getCanonicalFileName(fileName)) : file.fileName;
335336

336337
let output = "";
337-
output += formatColorAndReset(relativeFileName, ForegroundColorEscapeSequences.Cyan);
338+
output += color(relativeFileName, ForegroundColorEscapeSequences.Cyan);
338339
output += ":";
339-
output += formatColorAndReset(`${firstLine + 1}`, ForegroundColorEscapeSequences.Yellow);
340+
output += color(`${firstLine + 1}`, ForegroundColorEscapeSequences.Yellow);
340341
output += ":";
341-
output += formatColorAndReset(`${firstLineChar + 1}`, ForegroundColorEscapeSequences.Yellow);
342+
output += color(`${firstLineChar + 1}`, ForegroundColorEscapeSequences.Yellow);
342343
return output;
343344
}
344345

src/compiler/transformers/declarations.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,13 @@ namespace ts {
6666
}
6767
}
6868

69-
function trackReferencedAmbientModule(node: ModuleDeclaration) {
69+
function trackReferencedAmbientModule(node: ModuleDeclaration, symbol: Symbol) {
70+
// If it is visible via `// <reference types="..."/>`, then we should just use that
71+
const directives = resolver.getTypeReferenceDirectivesForSymbol(symbol, SymbolFlags.All);
72+
if (length(directives)) {
73+
return recordTypeReferenceDirectivesIfNecessary(directives);
74+
}
75+
// Otherwise we should emit a path-based reference
7076
const container = getSourceFileOfNode(node);
7177
refs.set("" + getOriginalNodeId(container), container);
7278
}

0 commit comments

Comments
 (0)