Skip to content

Commit 36d493e

Browse files
Merge remote-tracking branch 'tsupstream/master'
2 parents 898a70d + 95c3ecc commit 36d493e

19 files changed

+382
-46
lines changed

src/compiler/checker.ts

Lines changed: 51 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ namespace ts {
132132
const esSymbolType = createIntrinsicType(TypeFlags.ESSymbol, "symbol");
133133
const voidType = createIntrinsicType(TypeFlags.Void, "void");
134134
const neverType = createIntrinsicType(TypeFlags.Never, "never");
135+
const silentNeverType = createIntrinsicType(TypeFlags.Never, "never");
135136

136137
const emptyObjectType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined);
137138
const emptyGenericType = <GenericType><ObjectType>createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined);
@@ -147,6 +148,7 @@ namespace ts {
147148
const anySignature = createSignature(undefined, undefined, undefined, emptyArray, anyType, /*typePredicate*/ undefined, 0, /*hasRestParameter*/ false, /*hasLiteralTypes*/ false);
148149
const unknownSignature = createSignature(undefined, undefined, undefined, emptyArray, unknownType, /*typePredicate*/ undefined, 0, /*hasRestParameter*/ false, /*hasLiteralTypes*/ false);
149150
const resolvingSignature = createSignature(undefined, undefined, undefined, emptyArray, anyType, /*typePredicate*/ undefined, 0, /*hasRestParameter*/ false, /*hasLiteralTypes*/ false);
151+
const silentNeverSignature = createSignature(undefined, undefined, undefined, emptyArray, silentNeverType, /*typePredicate*/ undefined, 0, /*hasRestParameter*/ false, /*hasLiteralTypes*/ false);
150152

151153
const enumNumberIndexInfo = createIndexInfo(stringType, /*isReadonly*/ true);
152154

@@ -6504,6 +6506,9 @@ namespace ts {
65046506
} else if (source.symbol && source.flags & TypeFlags.ObjectType && globalObjectType === source) {
65056507
reportError(Diagnostics.The_Object_type_is_assignable_to_very_few_other_types_Did_you_mean_to_use_the_any_type_instead);
65066508
}
6509+
else if (source.symbol && source.flags & TypeFlags.ObjectType && globalObjectType === source) {
6510+
reportError(Diagnostics.The_Object_type_is_assignable_to_very_few_other_types_Did_you_mean_to_use_the_any_type_instead);
6511+
}
65076512
reportRelationError(headMessage, source, target);
65086513
}
65096514
return Ternary.False;
@@ -8072,8 +8077,11 @@ namespace ts {
80728077
// we remove type string.
80738078
function getAssignmentReducedType(declaredType: UnionType, assignedType: Type) {
80748079
if (declaredType !== assignedType) {
8080+
if (assignedType.flags & TypeFlags.Never) {
8081+
return assignedType;
8082+
}
80758083
const reducedType = filterType(declaredType, t => typeMaybeAssignableTo(assignedType, t));
8076-
if (reducedType !== neverType) {
8084+
if (!(reducedType.flags & TypeFlags.Never)) {
80778085
return reducedType;
80788086
}
80798087
}
@@ -8353,7 +8361,7 @@ namespace ts {
83538361
const visitedFlowStart = visitedFlowCount;
83548362
const result = getTypeFromFlowType(getTypeAtFlowNode(reference.flowNode));
83558363
visitedFlowCount = visitedFlowStart;
8356-
if (reference.parent.kind === SyntaxKind.NonNullExpression && getTypeWithFacts(result, TypeFacts.NEUndefinedOrNull) === neverType) {
8364+
if (reference.parent.kind === SyntaxKind.NonNullExpression && getTypeWithFacts(result, TypeFacts.NEUndefinedOrNull).flags & TypeFlags.Never) {
83578365
return declaredType;
83588366
}
83598367
return result;
@@ -8442,17 +8450,18 @@ namespace ts {
84428450
function getTypeAtFlowCondition(flow: FlowCondition): FlowType {
84438451
const flowType = getTypeAtFlowNode(flow.antecedent);
84448452
let type = getTypeFromFlowType(flowType);
8445-
if (type !== neverType) {
8453+
if (!(type.flags & TypeFlags.Never)) {
84468454
// If we have an antecedent type (meaning we're reachable in some way), we first
84478455
// attempt to narrow the antecedent type. If that produces the never type, and if
84488456
// the antecedent type is incomplete (i.e. a transient type in a loop), then we
84498457
// take the type guard as an indication that control *could* reach here once we
8450-
// have the complete type. We proceed by reverting to the declared type and then
8451-
// narrow that.
8458+
// have the complete type. We proceed by switching to the silent never type which
8459+
// doesn't report errors when operators are applied to it. Note that this is the
8460+
// *only* place a silent never type is ever generated.
84528461
const assumeTrue = (flow.flags & FlowFlags.TrueCondition) !== 0;
84538462
type = narrowType(type, flow.expression, assumeTrue);
8454-
if (type === neverType && isIncomplete(flowType)) {
8455-
type = narrowType(declaredType, flow.expression, assumeTrue);
8463+
if (type.flags & TypeFlags.Never && isIncomplete(flowType)) {
8464+
type = silentNeverType;
84568465
}
84578466
}
84588467
return createFlowType(type, isIncomplete(flowType));
@@ -8661,7 +8670,7 @@ namespace ts {
86618670
}
86628671
if (assumeTrue) {
86638672
const narrowedType = filterType(type, t => areTypesComparable(t, valueType));
8664-
return narrowedType !== neverType ? narrowedType : type;
8673+
return narrowedType.flags & TypeFlags.Never ? type : narrowedType;
86658674
}
86668675
return isUnitType(valueType) ? filterType(type, t => t !== valueType) : type;
86678676
}
@@ -8704,12 +8713,12 @@ namespace ts {
87048713
const clauseTypes = switchTypes.slice(clauseStart, clauseEnd);
87058714
const hasDefaultClause = clauseStart === clauseEnd || contains(clauseTypes, neverType);
87068715
const discriminantType = getUnionType(clauseTypes);
8707-
const caseType = discriminantType === neverType ? neverType : filterType(type, t => isTypeComparableTo(discriminantType, t));
8716+
const caseType = discriminantType.flags & TypeFlags.Never ? neverType : filterType(type, t => isTypeComparableTo(discriminantType, t));
87088717
if (!hasDefaultClause) {
87098718
return caseType;
87108719
}
87118720
const defaultType = filterType(type, t => !(isUnitType(t) && contains(switchTypes, t)));
8712-
return caseType === neverType ? defaultType : getUnionType([caseType, defaultType]);
8721+
return caseType.flags & TypeFlags.Never ? defaultType : getUnionType([caseType, defaultType]);
87138722
}
87148723

87158724
function narrowTypeByInstanceof(type: Type, expr: BinaryExpression, assumeTrue: boolean): Type {
@@ -8773,7 +8782,7 @@ namespace ts {
87738782
// the candidate type. If one or more constituents remain, return a union of those.
87748783
if (type.flags & TypeFlags.Union) {
87758784
const assignableType = filterType(type, t => isTypeInstanceOf(t, candidate));
8776-
if (assignableType !== neverType) {
8785+
if (!(assignableType.flags & TypeFlags.Never)) {
87778786
return assignableType;
87788787
}
87798788
}
@@ -10891,7 +10900,7 @@ namespace ts {
1089110900

1089210901
function checkPropertyAccessExpressionOrQualifiedName(node: PropertyAccessExpression | QualifiedName, left: Expression | QualifiedName, right: Identifier) {
1089310902
const type = checkNonNullExpression(left);
10894-
if (isTypeAny(type)) {
10903+
if (isTypeAny(type) || type === silentNeverType) {
1089510904
return type;
1089610905
}
1089710906

@@ -11038,8 +11047,8 @@ namespace ts {
1103811047
const objectType = getApparentType(checkNonNullExpression(node.expression));
1103911048
const indexType = node.argumentExpression ? checkExpression(node.argumentExpression) : unknownType;
1104011049

11041-
if (objectType === unknownType) {
11042-
return unknownType;
11050+
if (objectType === unknownType || objectType === silentNeverType) {
11051+
return objectType;
1104311052
}
1104411053

1104511054
const isConstEnum = isConstEnumObjectType(objectType);
@@ -12089,6 +12098,9 @@ namespace ts {
1208912098
}
1209012099

1209112100
const funcType = checkNonNullExpression(node.expression);
12101+
if (funcType === silentNeverType) {
12102+
return silentNeverSignature;
12103+
}
1209212104
const apparentType = getApparentType(funcType);
1209312105

1209412106
if (apparentType === unknownType) {
@@ -12161,6 +12173,9 @@ namespace ts {
1216112173
}
1216212174

1216312175
let expressionType = checkNonNullExpression(node.expression);
12176+
if (expressionType === silentNeverType) {
12177+
return silentNeverSignature;
12178+
}
1216412179

1216512180
// If expressionType's apparent type(section 3.8.1) is an object type with one or
1216612181
// more construct signatures, the expression is processed in the same manner as a
@@ -12720,7 +12735,7 @@ namespace ts {
1272012735
// the native Promise<T> type by the caller.
1272112736
type = checkAwaitedType(type, func, Diagnostics.Return_expression_in_async_function_does_not_have_a_valid_callable_then_member);
1272212737
}
12723-
if (type === neverType) {
12738+
if (type.flags & TypeFlags.Never) {
1272412739
hasReturnOfTypeNever = true;
1272512740
}
1272612741
else if (!contains(aggregatedTypes, type)) {
@@ -12770,7 +12785,7 @@ namespace ts {
1277012785

1277112786
const hasExplicitReturn = func.flags & NodeFlags.HasExplicitReturn;
1277212787

12773-
if (returnType === neverType) {
12788+
if (returnType && returnType.flags & TypeFlags.Never) {
1277412789
error(func.type, Diagnostics.A_function_returning_never_cannot_have_a_reachable_end_point);
1277512790
}
1277612791
else if (returnType && !hasExplicitReturn) {
@@ -13026,6 +13041,9 @@ namespace ts {
1302613041

1302713042
function checkPrefixUnaryExpression(node: PrefixUnaryExpression): Type {
1302813043
const operandType = checkExpression(node.operand);
13044+
if (operandType === silentNeverType) {
13045+
return silentNeverType;
13046+
}
1302913047
if (node.operator === SyntaxKind.MinusToken && node.operand.kind === SyntaxKind.NumericLiteral) {
1303013048
return getLiteralTypeForText(TypeFlags.NumberLiteral, "" + -(<LiteralExpression>node.operand).text);
1303113049
}
@@ -13059,6 +13077,9 @@ namespace ts {
1305913077

1306013078
function checkPostfixUnaryExpression(node: PostfixUnaryExpression): Type {
1306113079
const operandType = checkExpression(node.operand);
13080+
if (operandType === silentNeverType) {
13081+
return silentNeverType;
13082+
}
1306213083
const ok = checkArithmeticOperandType(node.operand, getNonNullableType(operandType),
1306313084
Diagnostics.An_arithmetic_operand_must_be_of_type_any_number_or_an_enum_type);
1306413085
if (ok) {
@@ -13123,6 +13144,9 @@ namespace ts {
1312313144
}
1312413145

1312513146
function checkInstanceOfExpression(left: Expression, right: Expression, leftType: Type, rightType: Type): Type {
13147+
if (leftType === silentNeverType || rightType === silentNeverType) {
13148+
return silentNeverType;
13149+
}
1312613150
// TypeScript 1.0 spec (April 2014): 4.15.4
1312713151
// The instanceof operator requires the left operand to be of type Any, an object type, or a type parameter type,
1312813152
// and the right operand to be of type Any or a subtype of the 'Function' interface type.
@@ -13139,6 +13163,9 @@ namespace ts {
1313913163
}
1314013164

1314113165
function checkInExpression(left: Expression, right: Expression, leftType: Type, rightType: Type): Type {
13166+
if (leftType === silentNeverType || rightType === silentNeverType) {
13167+
return silentNeverType;
13168+
}
1314213169
// TypeScript 1.0 spec (April 2014): 4.15.5
1314313170
// The in operator requires the left operand to be of type Any, the String primitive type, or the Number primitive type,
1314413171
// and the right operand to be of type Any, an object type, or a type parameter type.
@@ -13403,6 +13430,9 @@ namespace ts {
1340313430
case SyntaxKind.CaretEqualsToken:
1340413431
case SyntaxKind.AmpersandToken:
1340513432
case SyntaxKind.AmpersandEqualsToken:
13433+
if (leftType === silentNeverType || rightType === silentNeverType) {
13434+
return silentNeverType;
13435+
}
1340613436
// TypeScript 1.0 spec (April 2014): 4.19.1
1340713437
// These operators require their operands to be of type Any, the Number primitive type,
1340813438
// or an enum type. Operands of an enum type are treated
@@ -13435,6 +13465,9 @@ namespace ts {
1343513465
return numberType;
1343613466
case SyntaxKind.PlusToken:
1343713467
case SyntaxKind.PlusEqualsToken:
13468+
if (leftType === silentNeverType || rightType === silentNeverType) {
13469+
return silentNeverType;
13470+
}
1343813471
// TypeScript 1.0 spec (April 2014): 4.19.2
1343913472
// The binary + operator requires both operands to be of the Number primitive type or an enum type,
1344013473
// or at least one of the operands to be of type Any or the String primitive type.
@@ -16267,7 +16300,7 @@ namespace ts {
1626716300

1626816301
// Now that we've removed all the StringLike types, if no constituents remain, then the entire
1626916302
// arrayOrStringType was a string.
16270-
if (arrayType === neverType) {
16303+
if (arrayType.flags & TypeFlags.Never) {
1627116304
return stringType;
1627216305
}
1627316306
}
@@ -16328,7 +16361,7 @@ namespace ts {
1632816361
if (func) {
1632916362
const signature = getSignatureFromDeclaration(func);
1633016363
const returnType = getReturnTypeOfSignature(signature);
16331-
if (strictNullChecks || node.expression || returnType === neverType) {
16364+
if (strictNullChecks || node.expression || returnType.flags & TypeFlags.Never) {
1633216365
const exprType = node.expression ? checkExpressionCached(node.expression) : undefinedType;
1633316366

1633416367
if (func.asteriskToken) {

src/compiler/tsc.ts

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@ namespace ts {
667667
}
668668

669669
function printHelp() {
670-
let output = "";
670+
const output: string[] = [];
671671

672672
// We want to align our "syntax" and "examples" commands to a certain margin.
673673
const syntaxLength = getDiagnosticText(Diagnostics.Syntax_Colon_0, "").length;
@@ -678,17 +678,17 @@ namespace ts {
678678
let syntax = makePadding(marginLength - syntaxLength);
679679
syntax += "tsc [" + getDiagnosticText(Diagnostics.options) + "] [" + getDiagnosticText(Diagnostics.file) + " ...]";
680680

681-
output += getDiagnosticText(Diagnostics.Syntax_Colon_0, syntax);
682-
output += sys.newLine + sys.newLine;
681+
output.push(getDiagnosticText(Diagnostics.Syntax_Colon_0, syntax));
682+
output.push(sys.newLine + sys.newLine);
683683

684684
// Build up the list of examples.
685685
const padding = makePadding(marginLength);
686-
output += getDiagnosticText(Diagnostics.Examples_Colon_0, makePadding(marginLength - examplesLength) + "tsc hello.ts") + sys.newLine;
687-
output += padding + "tsc --outFile file.js file.ts" + sys.newLine;
688-
output += padding + "tsc @args.txt" + sys.newLine;
689-
output += sys.newLine;
686+
output.push(getDiagnosticText(Diagnostics.Examples_Colon_0, makePadding(marginLength - examplesLength) + "tsc hello.ts") + sys.newLine);
687+
output.push(padding + "tsc --outFile file.js file.ts" + sys.newLine);
688+
output.push(padding + "tsc @args.txt" + sys.newLine);
689+
output.push(sys.newLine);
690690

691-
output += getDiagnosticText(Diagnostics.Options_Colon) + sys.newLine;
691+
output.push(getDiagnosticText(Diagnostics.Options_Colon) + sys.newLine);
692692

693693
// Sort our options by their names, (e.g. "--noImplicitAny" comes before "--watch")
694694
const optsList = filter(optionDeclarations.slice(), v => !v.experimental);
@@ -755,18 +755,20 @@ namespace ts {
755755
const usage = usageColumn[i];
756756
const description = descriptionColumn[i];
757757
const kindsList = optionsDescriptionMap[description];
758-
output += usage + makePadding(marginLength - usage.length + 2) + description + sys.newLine;
758+
output.push(usage + makePadding(marginLength - usage.length + 2) + description + sys.newLine);
759759

760760
if (kindsList) {
761-
output += makePadding(marginLength + 4);
761+
output.push(makePadding(marginLength + 4));
762762
for (const kind of kindsList) {
763-
output += kind + " ";
763+
output.push(kind + " ");
764764
}
765-
output += sys.newLine;
765+
output.push(sys.newLine);
766766
}
767767
}
768768

769-
sys.write(output);
769+
for (const line of output) {
770+
sys.write(line);
771+
}
770772
return;
771773

772774
function getParamType(option: CommandLineOption) {

src/compiler/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1604,7 +1604,7 @@ namespace ts {
16041604

16051605
// @kind(SyntaxKind.JSDocComment)
16061606
export interface JSDoc extends Node {
1607-
tags: NodeArray<JSDocTag>;
1607+
tags: NodeArray<JSDocTag> | undefined;
16081608
comment: string | undefined;
16091609
}
16101610

src/harness/compilerRunner.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,7 @@ class CompilerBaselineRunner extends RunnerBase {
136136

137137
// check errors
138138
it("Correct errors for " + fileName, () => {
139-
if (this.errors) {
140-
Harness.Compiler.doErrorBaseline(justName, toBeCompiled.concat(otherFiles), result.errors);
141-
}
139+
Harness.Compiler.doErrorBaseline(justName, toBeCompiled.concat(otherFiles), result.errors);
142140
});
143141

144142
it (`Correct module resolution tracing for ${fileName}`, () => {

src/harness/harness.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1407,7 +1407,7 @@ namespace Harness {
14071407

14081408
export function doErrorBaseline(baselinePath: string, inputFiles: TestFile[], errors: ts.Diagnostic[]) {
14091409
Harness.Baseline.runBaseline(baselinePath.replace(/\.tsx?$/, ".errors.txt"), (): string => {
1410-
if (errors.length === 0) {
1410+
if (!errors || (errors.length === 0)) {
14111411
/* tslint:disable:no-null-keyword */
14121412
return null;
14131413
/* tslint:enable:no-null-keyword */

src/harness/harnessLanguageService.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,9 @@ namespace Harness.LanguageService {
492492
getNonBoundSourceFile(fileName: string): ts.SourceFile {
493493
throw new Error("SourceFile can not be marshaled across the shim layer.");
494494
}
495+
getSourceFile(fileName: string): ts.SourceFile {
496+
throw new Error("SourceFile can not be marshaled across the shim layer.");
497+
}
495498
dispose(): void { this.shim.dispose({}); }
496499
}
497500

src/lib/es2015.reflect.d.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ declare namespace Reflect {
66
function get(target: any, propertyKey: PropertyKey, receiver?: any): any;
77
function getOwnPropertyDescriptor(target: any, propertyKey: PropertyKey): PropertyDescriptor;
88
function getPrototypeOf(target: any): any;
9-
function has(target: any, propertyKey: string): boolean;
10-
function has(target: any, propertyKey: symbol): boolean;
9+
function has(target: any, propertyKey: PropertyKey): boolean;
1110
function isExtensible(target: any): boolean;
1211
function ownKeys(target: any): Array<PropertyKey>;
1312
function preventExtensions(target: any): boolean;

0 commit comments

Comments
 (0)