Skip to content

Commit 8ae163a

Browse files
committed
Merge branch 'master' of https://github.com/Microsoft/TypeScript into bug/25667-getmodifiedtime-has-wrong-return-type
2 parents 37add88 + 9891569 commit 8ae163a

File tree

102 files changed

+1450
-245
lines changed

Some content is hidden

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

102 files changed

+1450
-245
lines changed

.github/ISSUE_TEMPLATE/Bug_report.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ Please fill in the *entire* template below.
1616
-->
1717

1818
<!-- Please try to reproduce the issue with `typescript@next`. It may have already been fixed. -->
19-
**TypeScript Version:** 3.0.0-dev.201xxxxx
19+
**TypeScript Version:** 3.1.0-dev.201xxxxx
2020

2121
<!-- Search terms you tried before logging this (so others can find this issue more easily) -->
22-
**Search Terms:**
22+
**Search Terms:**
2323

2424
**Code**
2525

@@ -32,6 +32,6 @@ Please fill in the *entire* template below.
3232

3333
**Actual behavior:**
3434

35-
**Playground Link:** <!-- A link to a TypeScript Playground "Share" link which demonstrates this behavior -->
35+
**Playground Link:** <!-- A link to a TypeScript Playground "Share" link which demonstrates this behavior -->
3636

3737
**Related Issues:** <!-- Did you find other bugs that looked similar? -->

Jakefile.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -817,7 +817,7 @@ function diagnosticsToString(diagnostics, pretty) {
817817
* Concatenate a list of sourceFiles to a destinationFile
818818
* @param {string} destinationFile
819819
* @param {string[]} sourceFiles
820-
* @param {string} extraContent
820+
* @param {string=} extraContent
821821
*/
822822
function concatenateFiles(destinationFile, sourceFiles, extraContent) {
823823
var temp = "temptemp";

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "typescript",
33
"author": "Microsoft Corp.",
44
"homepage": "http://typescriptlang.org/",
5-
"version": "3.0.0",
5+
"version": "3.1.0",
66
"license": "Apache-2.0",
77
"description": "TypeScript is a language for application scale JavaScript development",
88
"keywords": [

src/compiler/binder.ts

+21-5
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ namespace ts {
306306
}
307307

308308
function getDisplayName(node: Declaration): string {
309-
return isNamedDeclaration(node) ? declarationNameToString(node.name) : unescapeLeadingUnderscores(getDeclarationName(node)!); // TODO: GH#18217
309+
return isNamedDeclaration(node) ? declarationNameToString(node.name) : unescapeLeadingUnderscores(Debug.assertDefined(getDeclarationName(node)));
310310
}
311311

312312
/**
@@ -383,9 +383,11 @@ namespace ts {
383383
let message = symbol.flags & SymbolFlags.BlockScopedVariable
384384
? Diagnostics.Cannot_redeclare_block_scoped_variable_0
385385
: Diagnostics.Duplicate_identifier_0;
386+
let messageNeedsName = true;
386387

387388
if (symbol.flags & SymbolFlags.Enum || includes & SymbolFlags.Enum) {
388389
message = Diagnostics.Enum_declarations_can_only_merge_with_namespace_or_other_enum_declarations;
390+
messageNeedsName = false;
389391
}
390392

391393
if (symbol.declarations && symbol.declarations.length) {
@@ -394,6 +396,7 @@ namespace ts {
394396
// We'll know whether we have other default exports depending on if `symbol` already has a declaration list set.
395397
if (isDefaultExport) {
396398
message = Diagnostics.A_module_cannot_have_multiple_default_exports;
399+
messageNeedsName = false;
397400
}
398401
else {
399402
// This is to properly report an error in the case "export default { }" is after export default of class declaration or function declaration.
@@ -403,14 +406,16 @@ namespace ts {
403406
if (symbol.declarations && symbol.declarations.length &&
404407
(node.kind === SyntaxKind.ExportAssignment && !(<ExportAssignment>node).isExportEquals)) {
405408
message = Diagnostics.A_module_cannot_have_multiple_default_exports;
409+
messageNeedsName = false;
406410
}
407411
}
408412
}
409413

410-
forEach(symbol.declarations, declaration => {
411-
file.bindDiagnostics.push(createDiagnosticForNode(getNameOfDeclaration(declaration) || declaration, message, getDisplayName(declaration)));
412-
});
413-
file.bindDiagnostics.push(createDiagnosticForNode(getNameOfDeclaration(node) || node, message, getDisplayName(node)));
414+
const addError = (decl: Declaration): void => {
415+
file.bindDiagnostics.push(createDiagnosticForNode(getNameOfDeclaration(decl) || decl, message, messageNeedsName ? getDisplayName(decl) : undefined));
416+
};
417+
forEach(symbol.declarations, addError);
418+
addError(node);
414419

415420
symbol = createSymbol(SymbolFlags.None, name);
416421
}
@@ -1913,6 +1918,15 @@ namespace ts {
19131918
}
19141919
}
19151920

1921+
function checkStrictModeLabeledStatement(node: LabeledStatement) {
1922+
// Grammar checking for labeledStatement
1923+
if (inStrictMode && options.target! >= ScriptTarget.ES2015) {
1924+
if (isDeclarationStatement(node.statement) || isVariableStatement(node.statement)) {
1925+
errorOnFirstToken(node.label, Diagnostics.A_label_is_not_allowed_here);
1926+
}
1927+
}
1928+
}
1929+
19161930
function errorOnFirstToken(node: Node, message: DiagnosticMessage, arg0?: any, arg1?: any, arg2?: any) {
19171931
const span = getSpanOfTokenAtPosition(file, node.pos);
19181932
file.bindDiagnostics.push(createFileDiagnostic(file, span.start, span.length, message, arg0, arg1, arg2));
@@ -2099,6 +2113,8 @@ namespace ts {
20992113
return checkStrictModePrefixUnaryExpression(<PrefixUnaryExpression>node);
21002114
case SyntaxKind.WithStatement:
21012115
return checkStrictModeWithStatement(<WithStatement>node);
2116+
case SyntaxKind.LabeledStatement:
2117+
return checkStrictModeLabeledStatement(<LabeledStatement>node);
21022118
case SyntaxKind.ThisType:
21032119
seenThisKeyword = true;
21042120
return;

src/compiler/checker.ts

+13-3
Original file line numberDiff line numberDiff line change
@@ -4714,6 +4714,10 @@ namespace ts {
47144714
// function/class/{} assignments are fresh declarations, not property assignments, so only add prototype assignments
47154715
const specialDeclaration = getAssignedJavascriptInitializer(symbol.valueDeclaration);
47164716
if (specialDeclaration) {
4717+
const tag = getJSDocTypeTag(specialDeclaration);
4718+
if (tag && tag.typeExpression) {
4719+
return getTypeFromTypeNode(tag.typeExpression);
4720+
}
47174721
return getWidenedLiteralType(checkExpressionCached(specialDeclaration));
47184722
}
47194723
const types: Type[] = [];
@@ -5081,7 +5085,7 @@ namespace ts {
50815085
}
50825086

50835087
function getJSInitializerType(decl: Node, symbol: Symbol, init: Expression | undefined): Type | undefined {
5084-
if (init && isInJavaScriptFile(init) && isObjectLiteralExpression(init)) {
5088+
if (init && isInJavaScriptFile(init) && isObjectLiteralExpression(init) && init.properties.length === 0) {
50855089
const exports = createSymbolTable();
50865090
while (isBinaryExpression(decl) || isPropertyAccessExpression(decl)) {
50875091
const s = getSymbolOfNode(decl);
@@ -11182,7 +11186,8 @@ namespace ts {
1118211186
if (reportErrors) {
1118311187
const bestMatchingType =
1118411188
findMatchingDiscriminantType(source, target) ||
11185-
findMatchingTypeReferenceOrTypeAliasReference(source, target);
11189+
findMatchingTypeReferenceOrTypeAliasReference(source, target) ||
11190+
findBestTypeForObjectLiteral(source, target);
1118611191

1118711192
isRelatedTo(source, bestMatchingType || targetTypes[targetTypes.length - 1], /*reportErrors*/ true);
1118811193
}
@@ -11207,6 +11212,11 @@ namespace ts {
1120711212
}
1120811213
}
1120911214

11215+
function findBestTypeForObjectLiteral(source: Type, unionTarget: UnionOrIntersectionType) {
11216+
if (getObjectFlags(source) & ObjectFlags.ObjectLiteral && forEachType(unionTarget, isArrayLikeType)) {
11217+
return find(unionTarget.types, t => !isArrayLikeType(t));
11218+
}
11219+
}
1121011220

1121111221
// Keep this up-to-date with the same logic within `getApparentTypeOfContextualType`, since they should behave similarly
1121211222
function findMatchingDiscriminantType(source: Type, target: UnionOrIntersectionType) {
@@ -19083,7 +19093,7 @@ namespace ts {
1908319093
else if (candidateForTypeArgumentError) {
1908419094
checkTypeArguments(candidateForTypeArgumentError, (node as CallExpression | TaggedTemplateExpression).typeArguments!, /*reportErrors*/ true, fallbackError);
1908519095
}
19086-
else if (typeArguments && every(signatures, sig => length(sig.typeParameters) !== typeArguments!.length)) {
19096+
else if (typeArguments && every(signatures, sig => typeArguments!.length < getMinTypeArgumentCount(sig.typeParameters) || typeArguments!.length > length(sig.typeParameters))) {
1908719097
diagnostics.add(getTypeArgumentArityError(node, signatures, typeArguments));
1908819098
}
1908919099
else if (args) {

src/compiler/core.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
namespace ts {
22
// WARNING: The script `configureNightly.ts` uses a regexp to parse out these values.
33
// If changing the text in this section, be sure to test `configureNightly` too.
4-
export const versionMajorMinor = "3.0";
4+
export const versionMajorMinor = "3.1";
55
/** The version of the TypeScript compiler release */
66
export const version = `${versionMajorMinor}.0-dev`;
77
}

src/compiler/diagnosticMessages.json

+4
Original file line numberDiff line numberDiff line change
@@ -983,6 +983,10 @@
983983
"category": "Error",
984984
"code": 1343
985985
},
986+
"'A label is not allowed here.": {
987+
"category": "Error",
988+
"code": 1344
989+
},
986990

987991
"Duplicate identifier '{0}'.": {
988992
"category": "Error",

src/compiler/parser.ts

+18-8
Original file line numberDiff line numberDiff line change
@@ -494,9 +494,9 @@ namespace ts {
494494
case SyntaxKind.JSDocSignature:
495495
return visitNodes(cbNode, cbNodes, node.decorators) ||
496496
visitNodes(cbNode, cbNodes, node.modifiers) ||
497-
visitNodes(cbNode, cbNodes, (<SignatureDeclaration>node).typeParameters) ||
498-
visitNodes(cbNode, cbNodes, (<SignatureDeclaration>node).parameters) ||
499-
visitNode(cbNode, (<SignatureDeclaration>node).type);
497+
forEach((<JSDocSignature>node).typeParameters, cbNode) ||
498+
forEach((<JSDocSignature>node).parameters, cbNode) ||
499+
visitNode(cbNode, (<JSDocSignature>node).type);
500500
case SyntaxKind.JSDocTypeLiteral:
501501
if ((node as JSDocTypeLiteral).jsDocPropertyTags) {
502502
for (const tag of (node as JSDocTypeLiteral).jsDocPropertyTags!) {
@@ -1509,7 +1509,9 @@ namespace ts {
15091509
case ParsingContext.ArgumentExpressions:
15101510
return token() === SyntaxKind.DotDotDotToken || isStartOfExpression();
15111511
case ParsingContext.Parameters:
1512-
return isStartOfParameter();
1512+
return isStartOfParameter(/*isJSDocParameter*/ false);
1513+
case ParsingContext.JSDocParameters:
1514+
return isStartOfParameter(/*isJSDocParameter*/ true);
15131515
case ParsingContext.TypeArguments:
15141516
case ParsingContext.TupleElementTypes:
15151517
return token() === SyntaxKind.CommaToken || isStartOfType();
@@ -1612,6 +1614,7 @@ namespace ts {
16121614
case ParsingContext.TupleElementTypes:
16131615
case ParsingContext.ArrayBindingElements:
16141616
return token() === SyntaxKind.CloseBracketToken;
1617+
case ParsingContext.JSDocParameters:
16151618
case ParsingContext.Parameters:
16161619
case ParsingContext.RestProperties:
16171620
// Tokens other than ')' and ']' (the latter for index signatures) are here for better error recovery
@@ -1795,6 +1798,7 @@ namespace ts {
17951798
case ParsingContext.VariableDeclarations:
17961799
return isReusableVariableDeclaration(node);
17971800

1801+
case ParsingContext.JSDocParameters:
17981802
case ParsingContext.Parameters:
17991803
return isReusableParameter(node);
18001804

@@ -2009,6 +2013,7 @@ namespace ts {
20092013
case ParsingContext.ArgumentExpressions: return Diagnostics.Argument_expression_expected;
20102014
case ParsingContext.ObjectLiteralMembers: return Diagnostics.Property_assignment_expected;
20112015
case ParsingContext.ArrayLiteralMembers: return Diagnostics.Expression_or_comma_expected;
2016+
case ParsingContext.JSDocParameters: return Diagnostics.Parameter_declaration_expected;
20122017
case ParsingContext.Parameters: return Diagnostics.Parameter_declaration_expected;
20132018
case ParsingContext.TypeParameters: return Diagnostics.Type_parameter_declaration_expected;
20142019
case ParsingContext.TypeArguments: return Diagnostics.Type_argument_expected;
@@ -2430,12 +2435,12 @@ namespace ts {
24302435
return undefined;
24312436
}
24322437

2433-
function isStartOfParameter(): boolean {
2438+
function isStartOfParameter(isJSDocParameter: boolean): boolean {
24342439
return token() === SyntaxKind.DotDotDotToken ||
24352440
isIdentifierOrPattern() ||
24362441
isModifierKind(token()) ||
24372442
token() === SyntaxKind.AtToken ||
2438-
isStartOfType(/*inStartOfParameter*/ true);
2443+
isStartOfType(/*inStartOfParameter*/ !isJSDocParameter);
24392444
}
24402445

24412446
function parseParameter(): ParameterDeclaration {
@@ -2534,7 +2539,9 @@ namespace ts {
25342539
setYieldContext(!!(flags & SignatureFlags.Yield));
25352540
setAwaitContext(!!(flags & SignatureFlags.Await));
25362541

2537-
signature.parameters = parseDelimitedList(ParsingContext.Parameters, flags & SignatureFlags.JSDoc ? parseJSDocParameter : parseParameter);
2542+
signature.parameters = flags & SignatureFlags.JSDoc ?
2543+
parseDelimitedList(ParsingContext.JSDocParameters, parseJSDocParameter) :
2544+
parseDelimitedList(ParsingContext.Parameters, parseParameter);
25382545

25392546
setYieldContext(savedYieldContext);
25402547
setAwaitContext(savedAwaitContext);
@@ -2960,6 +2967,8 @@ namespace ts {
29602967
case SyntaxKind.InferKeyword:
29612968
case SyntaxKind.ImportKeyword:
29622969
return true;
2970+
case SyntaxKind.FunctionKeyword:
2971+
return !inStartOfParameter;
29632972
case SyntaxKind.MinusToken:
29642973
return !inStartOfParameter && lookAhead(nextTokenIsNumericLiteral);
29652974
case SyntaxKind.OpenParenToken:
@@ -2973,7 +2982,7 @@ namespace ts {
29732982

29742983
function isStartOfParenthesizedOrFunctionType() {
29752984
nextToken();
2976-
return token() === SyntaxKind.CloseParenToken || isStartOfParameter() || isStartOfType();
2985+
return token() === SyntaxKind.CloseParenToken || isStartOfParameter(/*isJSDocParameter*/ false) || isStartOfType();
29772986
}
29782987

29792988
function parsePostfixTypeOrHigher(): TypeNode {
@@ -6255,6 +6264,7 @@ namespace ts {
62556264
JsxChildren, // Things between opening and closing JSX tags
62566265
ArrayLiteralMembers, // Members in array literal
62576266
Parameters, // Parameters in parameter list
6267+
JSDocParameters, // JSDoc parameters in parameter list of JSDoc function type
62586268
RestProperties, // Property names in a rest type list
62596269
TypeParameters, // Type parameters in type parameter list
62606270
TypeArguments, // Type arguments in type argument list

src/compiler/program.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2366,7 +2366,7 @@ namespace ts {
23662366
}
23672367

23682368
function verifyCompilerOptions() {
2369-
if (options.strictPropertyInitialization && !options.strictNullChecks) {
2369+
if (options.strictPropertyInitialization && !getStrictOptionValue(options, "strictNullChecks")) {
23702370
createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "strictPropertyInitialization", "strictNullChecks");
23712371
}
23722372

src/compiler/transformers/es2015.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2207,7 +2207,7 @@ namespace ts {
22072207
const statement = unwrapInnermostStatementOfLabel(node, convertedLoopState && recordLabel);
22082208
return isIterationStatement(statement, /*lookInLabeledStatements*/ false)
22092209
? visitIterationStatement(statement, /*outermostLabeledStatement*/ node)
2210-
: restoreEnclosingLabel(visitNode(statement, visitor, isStatement), node, convertedLoopState && resetLabel);
2210+
: restoreEnclosingLabel(visitNode(statement, visitor, isStatement, liftToBlock), node, convertedLoopState && resetLabel);
22112211
}
22122212

22132213
function visitIterationStatement(node: IterationStatement, outermostLabeledStatement: LabeledStatement) {

src/compiler/types.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,7 @@ namespace ts {
755755

756756
export interface TypeParameterDeclaration extends NamedDeclaration {
757757
kind: SyntaxKind.TypeParameter;
758-
parent: DeclarationWithTypeParameters | InferTypeNode;
758+
parent: DeclarationWithTypeParameterChildren | InferTypeNode;
759759
name: Identifier;
760760
constraint?: TypeNode;
761761
default?: TypeNode;
@@ -2036,7 +2036,8 @@ namespace ts {
20362036

20372037
export type ObjectTypeDeclaration = ClassLikeDeclaration | InterfaceDeclaration | TypeLiteralNode;
20382038

2039-
export type DeclarationWithTypeParameters = SignatureDeclaration | ClassLikeDeclaration | InterfaceDeclaration | TypeAliasDeclaration | JSDocTemplateTag | JSDocTypedefTag | JSDocCallbackTag | JSDocSignature;
2039+
export type DeclarationWithTypeParameters = DeclarationWithTypeParameterChildren | JSDocTypedefTag | JSDocCallbackTag | JSDocSignature;
2040+
export type DeclarationWithTypeParameterChildren = SignatureDeclaration | ClassLikeDeclaration | InterfaceDeclaration | TypeAliasDeclaration | JSDocTemplateTag;
20402041

20412042
export interface ClassLikeDeclarationBase extends NamedDeclaration, JSDocContainer {
20422043
kind: SyntaxKind.ClassDeclaration | SyntaxKind.ClassExpression;
@@ -4361,7 +4362,7 @@ namespace ts {
43614362
strictFunctionTypes?: boolean; // Always combine with strict property
43624363
strictNullChecks?: boolean; // Always combine with strict property
43634364
strictPropertyInitialization?: boolean; // Always combine with strict property
4364-
/* @internal */ stripInternal?: boolean;
4365+
stripInternal?: boolean;
43654366
suppressExcessPropertyErrors?: boolean;
43664367
suppressImplicitAnyIndexErrors?: boolean;
43674368
/* @internal */ suppressOutputPathCheck?: boolean;

0 commit comments

Comments
 (0)