Skip to content

Commit df1162e

Browse files
author
Andy Hanson
committed
Merge branch 'master' into navigateToWithProjects
2 parents 0e62fdc + 5c57e14 commit df1162e

File tree

234 files changed

+6042
-2588
lines changed

Some content is hidden

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

234 files changed

+6042
-2588
lines changed

src/compiler/binder.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ namespace ts {
2626
return ModuleInstanceState.NonInstantiated;
2727
// 2. const enum declarations
2828
case SyntaxKind.EnumDeclaration:
29-
if (isConst(node)) {
29+
if (isEnumConst(node as EnumDeclaration)) {
3030
return ModuleInstanceState.ConstEnumOnly;
3131
}
3232
break;
@@ -2611,7 +2611,7 @@ namespace ts {
26112611
}
26122612

26132613
function bindEnumDeclaration(node: EnumDeclaration) {
2614-
return isConst(node)
2614+
return isEnumConst(node)
26152615
? bindBlockScopedDeclaration(node, SymbolFlags.ConstEnum, SymbolFlags.ConstEnumExcludes)
26162616
: bindBlockScopedDeclaration(node, SymbolFlags.RegularEnum, SymbolFlags.RegularEnumExcludes);
26172617
}
@@ -2768,7 +2768,7 @@ namespace ts {
27682768
// report error on instantiated modules or const-enums only modules if preserveConstEnums is set
27692769
(node.kind === SyntaxKind.ModuleDeclaration && shouldReportErrorOnModuleDeclaration(<ModuleDeclaration>node)) ||
27702770
// report error on regular enums and const enums if preserveConstEnums is set
2771-
(node.kind === SyntaxKind.EnumDeclaration && (!isConstEnumDeclaration(node) || options.preserveConstEnums));
2771+
(isEnumDeclaration(node) && (!isEnumConst(node) || options.preserveConstEnums));
27722772

27732773
if (reportError) {
27742774
currentFlow = reportedUnreachableFlow;

src/compiler/checker.ts

Lines changed: 213 additions & 201 deletions
Large diffs are not rendered by default.

src/compiler/diagnosticMessages.json

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1252,7 +1252,7 @@
12521252
"category": "Error",
12531253
"code": 2366
12541254
},
1255-
"The types of these values indicate that this condition will always be '{0}'.": {
1255+
"This condition will always return '{0}' since the types '{1}' and '{2}' have no overlap.": {
12561256
"category": "Error",
12571257
"code": 2367
12581258
},
@@ -2397,6 +2397,10 @@
23972397
"category": "Error",
23982398
"code": 2727
23992399
},
2400+
"'{0}' was declared here.": {
2401+
"category": "Error",
2402+
"code": 2728
2403+
},
24002404

24012405
"Import declaration '{0}' is using private name '{1}'.": {
24022406
"category": "Error",
@@ -3603,6 +3607,22 @@
36033607
"code": 6199,
36043608
"reportsUnnecessary": true
36053609
},
3610+
"Definitions of the following identifiers conflict with those in another file: {0}": {
3611+
"category": "Error",
3612+
"code": 6200
3613+
},
3614+
"Conflicts are in this file.": {
3615+
"category": "Message",
3616+
"code": 6201
3617+
},
3618+
"'{0}' was also declared here.": {
3619+
"category": "Message",
3620+
"code": 6203
3621+
},
3622+
"and here.": {
3623+
"category": "Message",
3624+
"code": 6204
3625+
},
36063626

36073627
"Projects to reference": {
36083628
"category": "Message",
@@ -4446,5 +4466,9 @@
44464466
"Convert named export to default export": {
44474467
"category": "Message",
44484468
"code": 95062
4469+
},
4470+
"Add missing enum member '{0}'": {
4471+
"category": "Message",
4472+
"code": 95063
44494473
}
44504474
}

src/compiler/emitter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1983,7 +1983,7 @@ namespace ts {
19831983
}
19841984

19851985
function emitVariableDeclarationList(node: VariableDeclarationList) {
1986-
writeKeyword(isLet(node) ? "let" : isConst(node) ? "const" : "var");
1986+
writeKeyword(isLet(node) ? "let" : isVarConst(node) ? "const" : "var");
19871987
writeSpace();
19881988
emitList(node, node.declarations, ListFormat.VariableDeclarationList);
19891989
}
@@ -2451,7 +2451,7 @@ namespace ts {
24512451

24522452
function emitJsxTagName(node: JsxTagNameExpression) {
24532453
if (node.kind === SyntaxKind.Identifier) {
2454-
emitExpression(<Identifier>node);
2454+
emitExpression(node);
24552455
}
24562456
else {
24572457
emit(node);

src/compiler/factory.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -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;

src/compiler/moduleSpecifiers.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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

@@ -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
}
@@ -150,10 +149,11 @@ namespace ts.moduleSpecifiers {
150149
const result = createMap<string>();
151150
if (symlinks) {
152151
const currentDirectory = host.getCurrentDirectory ? host.getCurrentDirectory() : "";
152+
const compareStrings = (!host.useCaseSensitiveFileNames || host.useCaseSensitiveFileNames()) ? compareStringsCaseSensitive : compareStringsCaseInsensitive;
153153
for (const [resolvedPath, originalPath] of symlinks) {
154154
const resolvedParts = getPathComponents(toPath(resolvedPath, currentDirectory, getCanonicalFileName));
155155
const originalParts = getPathComponents(toPath(originalPath, currentDirectory, getCanonicalFileName));
156-
while (resolvedParts[resolvedParts.length - 1] === originalParts[originalParts.length - 1]) {
156+
while (compareStrings(resolvedParts[resolvedParts.length - 1], originalParts[originalParts.length - 1]) === Comparison.EqualTo) {
157157
resolvedParts.pop();
158158
originalParts.pop();
159159
}

src/compiler/parser.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4314,9 +4314,9 @@ namespace ts {
43144314
// We can't just simply use parseLeftHandSideExpressionOrHigher because then we will start consider class,function etc as a keyword
43154315
// We only want to consider "this" as a primaryExpression
43164316
let expression: JsxTagNameExpression = token() === SyntaxKind.ThisKeyword ?
4317-
parseTokenNode<PrimaryExpression>() : parseIdentifierName();
4317+
parseTokenNode<ThisExpression>() : parseIdentifierName();
43184318
while (parseOptional(SyntaxKind.DotToken)) {
4319-
const propertyAccess: PropertyAccessExpression = <PropertyAccessExpression>createNode(SyntaxKind.PropertyAccessExpression, expression.pos);
4319+
const propertyAccess: JsxTagNamePropertyAccess = <JsxTagNamePropertyAccess>createNode(SyntaxKind.PropertyAccessExpression, expression.pos);
43204320
propertyAccess.expression = expression;
43214321
propertyAccess.name = parseRightSideOfDot(/*allowIdentifierNames*/ true);
43224322
expression = finishNode(propertyAccess);
@@ -7887,7 +7887,7 @@ namespace ts {
78877887
}
78887888

78897889
if (lhs.kind === SyntaxKind.Identifier) {
7890-
return (<Identifier>lhs).escapedText === (<Identifier>rhs).escapedText;
7890+
return lhs.escapedText === (<Identifier>rhs).escapedText;
78917891
}
78927892

78937893
if (lhs.kind === SyntaxKind.ThisKeyword) {

src/compiler/program.ts

Lines changed: 6 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

@@ -1248,6 +1249,7 @@ namespace ts {
12481249
return host.fileExists(f);
12491250
},
12501251
...(host.directoryExists ? { directoryExists: f => host.directoryExists!(f) } : {}),
1252+
useCaseSensitiveFileNames: () => host.useCaseSensitiveFileNames(),
12511253
};
12521254
}
12531255

src/compiler/transformers/es2015.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -855,7 +855,7 @@ namespace ts {
855855
if (extendsClauseElement) {
856856
statements.push(
857857
setTextRange(
858-
createStatement(
858+
createExpressionStatement(
859859
createExtendsHelper(context, getInternalName(node))
860860
),
861861
/*location*/ extendsClauseElement
@@ -1280,7 +1280,7 @@ namespace ts {
12801280
else if (initializer) {
12811281
statements.push(
12821282
setEmitFlags(
1283-
createStatement(
1283+
createExpressionStatement(
12841284
createAssignment(
12851285
temp,
12861286
visitNode(initializer, visitor, isExpression)
@@ -1307,7 +1307,7 @@ namespace ts {
13071307
setEmitFlags(
13081308
setTextRange(
13091309
createBlock([
1310-
createStatement(
1310+
createExpressionStatement(
13111311
setEmitFlags(
13121312
setTextRange(
13131313
createAssignment(
@@ -1409,7 +1409,7 @@ namespace ts {
14091409
createBlock([
14101410
startOnNewLine(
14111411
setTextRange(
1412-
createStatement(
1412+
createExpressionStatement(
14131413
createAssignment(
14141414
createElementAccess(
14151415
expressionName,
@@ -1594,7 +1594,7 @@ namespace ts {
15941594
setSourceMapRange(memberFunction, sourceMapRange);
15951595

15961596
const statement = setTextRange(
1597-
createStatement(
1597+
createExpressionStatement(
15981598
createAssignment(memberName, memberFunction)
15991599
),
16001600
/*location*/ member
@@ -1619,7 +1619,7 @@ namespace ts {
16191619
* @param accessors The set of related get/set accessors.
16201620
*/
16211621
function transformAccessorsToStatement(receiver: LeftHandSideExpression, accessors: AllAccessorDeclarations, container: Node): Statement {
1622-
const statement = createStatement(transformAccessorsToExpression(receiver, accessors, container, /*startsOnNewLine*/ false));
1622+
const statement = createExpressionStatement(transformAccessorsToExpression(receiver, accessors, container, /*startsOnNewLine*/ false));
16231623
// The location for the statement is used to emit source maps only.
16241624
// No comments should be emitted for this statement to align with the
16251625
// old emitter.
@@ -1949,9 +1949,9 @@ namespace ts {
19491949
// If we are here it is most likely because our expression is a destructuring assignment.
19501950
switch (node.expression.kind) {
19511951
case SyntaxKind.ParenthesizedExpression:
1952-
return updateStatement(node, visitParenthesizedExpression(<ParenthesizedExpression>node.expression, /*needsDestructuringValue*/ false));
1952+
return updateExpressionStatement(node, visitParenthesizedExpression(<ParenthesizedExpression>node.expression, /*needsDestructuringValue*/ false));
19531953
case SyntaxKind.BinaryExpression:
1954-
return updateStatement(node, visitBinaryExpression(<BinaryExpression>node.expression, /*needsDestructuringValue*/ false));
1954+
return updateExpressionStatement(node, visitBinaryExpression(<BinaryExpression>node.expression, /*needsDestructuringValue*/ false));
19551955
}
19561956
return visitEachChild(node, visitor, context);
19571957
}
@@ -2026,7 +2026,7 @@ namespace ts {
20262026
}
20272027
}
20282028
if (assignments) {
2029-
updated = setTextRange(createStatement(inlineExpressions(assignments)), node);
2029+
updated = setTextRange(createExpressionStatement(inlineExpressions(assignments)), node);
20302030
}
20312031
else {
20322032
// none of declarations has initializer - the entire variable statement can be deleted
@@ -2330,11 +2330,11 @@ namespace ts {
23302330
const assignment = createAssignment(initializer, boundValue);
23312331
if (isDestructuringAssignment(assignment)) {
23322332
aggregateTransformFlags(assignment);
2333-
statements.push(createStatement(visitBinaryExpression(assignment, /*needsDestructuringValue*/ false)));
2333+
statements.push(createExpressionStatement(visitBinaryExpression(assignment, /*needsDestructuringValue*/ false)));
23342334
}
23352335
else {
23362336
assignment.end = initializer.end;
2337-
statements.push(setTextRange(createStatement(visitNode(assignment, visitor, isExpression)), moveRangeEnd(initializer, -1)));
2337+
statements.push(setTextRange(createExpressionStatement(visitNode(assignment, visitor, isExpression)), moveRangeEnd(initializer, -1)));
23382338
}
23392339
}
23402340

@@ -2483,7 +2483,7 @@ namespace ts {
24832483
createCatchClause(createVariableDeclaration(catchVariable),
24842484
setEmitFlags(
24852485
createBlock([
2486-
createStatement(
2486+
createExpressionStatement(
24872487
createAssignment(
24882488
errorRecord,
24892489
createObjectLiteral([
@@ -2512,7 +2512,7 @@ namespace ts {
25122512
createPropertyAccess(iterator, "return")
25132513
)
25142514
),
2515-
createStatement(
2515+
createExpressionStatement(
25162516
createFunctionCall(returnMethod, iterator, [])
25172517
)
25182518
),
@@ -2868,7 +2868,7 @@ namespace ts {
28682868

28692869
function copyOutParameters(outParams: LoopOutParameter[], copyDirection: CopyDirection, statements: Statement[]): void {
28702870
for (const outParam of outParams) {
2871-
statements.push(createStatement(copyOutParameter(outParam, copyDirection)));
2871+
statements.push(createExpressionStatement(copyOutParameter(outParam, copyDirection)));
28722872
}
28732873
}
28742874

@@ -2892,7 +2892,7 @@ namespace ts {
28922892
)
28932893
: call;
28942894
if (isSimpleLoop) {
2895-
statements.push(createStatement(callResult));
2895+
statements.push(createExpressionStatement(callResult));
28962896
copyOutParameters(state.loopOutParameters!, CopyDirection.ToOriginal, statements);
28972897
}
28982898
else {
@@ -3358,7 +3358,7 @@ namespace ts {
33583358

33593359
// Add the class alias following the declaration.
33603360
statements.push(
3361-
createStatement(
3361+
createExpressionStatement(
33623362
createAssignment(
33633363
aliasAssignment.left,
33643364
cast(variable.name, isIdentifier)

src/compiler/transformers/es2017.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ namespace ts {
144144
function visitVariableStatementInAsyncBody(node: VariableStatement) {
145145
if (isVariableDeclarationListWithCollidingName(node.declarationList)) {
146146
const expression = visitVariableDeclarationListWithCollidingNames(node.declarationList, /*hasReceiver*/ false);
147-
return expression ? createStatement(expression) : undefined;
147+
return expression ? createExpressionStatement(expression) : undefined;
148148
}
149149
return visitEachChild(node, visitor, context);
150150
}

0 commit comments

Comments
 (0)