Skip to content

Commit bbf56b0

Browse files
committed
Merge branch 'master' of https://github.com/microsoft/TypeScript into bug/38295
2 parents e04ab69 + 2cea9d9 commit bbf56b0

File tree

135 files changed

+4677
-1037
lines changed

Some content is hidden

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

135 files changed

+4677
-1037
lines changed

CONTRIBUTING.md

+203-216
Large diffs are not rendered by default.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696
"source-map-support": "latest",
9797
"through2": "latest",
9898
"travis-fold": "latest",
99-
"typescript": "next",
99+
"typescript": "^3.9.3",
100100
"vinyl": "latest",
101101
"vinyl-sourcemaps-apply": "latest",
102102
"xml2js": "^0.4.19"

src/compiler/binder.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -985,7 +985,7 @@ namespace ts {
985985
return initFlowNode({ flags: FlowFlags.SwitchClause, antecedent, switchStatement, clauseStart, clauseEnd });
986986
}
987987

988-
function createFlowMutation(flags: FlowFlags, antecedent: FlowNode, node: Node): FlowNode {
988+
function createFlowMutation(flags: FlowFlags, antecedent: FlowNode, node: Expression | VariableDeclaration | ArrayBindingElement): FlowNode {
989989
setFlowNodeReferenced(antecedent);
990990
const result = initFlowNode({ flags, antecedent, node });
991991
if (currentExceptionTarget) {
@@ -1341,7 +1341,7 @@ namespace ts {
13411341
// is potentially an assertion and is therefore included in the control flow.
13421342
if (node.expression.kind === SyntaxKind.CallExpression) {
13431343
const call = <CallExpression>node.expression;
1344-
if (isDottedName(call.expression)) {
1344+
if (isDottedName(call.expression) && call.expression.kind !== SyntaxKind.SuperKeyword) {
13451345
currentFlow = createFlowCall(currentFlow, call);
13461346
}
13471347
}
@@ -1747,6 +1747,9 @@ namespace ts {
17471747
}
17481748
else {
17491749
bindEachChild(node);
1750+
if (node.expression.kind === SyntaxKind.SuperKeyword) {
1751+
currentFlow = createFlowCall(currentFlow, node);
1752+
}
17501753
}
17511754
}
17521755
if (node.expression.kind === SyntaxKind.PropertyAccessExpression) {
@@ -2464,6 +2467,9 @@ namespace ts {
24642467
node.flowNode = currentFlow;
24652468
}
24662469
return checkStrictModeIdentifier(<Identifier>node);
2470+
case SyntaxKind.SuperKeyword:
2471+
node.flowNode = currentFlow;
2472+
break;
24672473
case SyntaxKind.PrivateIdentifier:
24682474
return checkPrivateIdentifier(node as PrivateIdentifier);
24692475
case SyntaxKind.PropertyAccessExpression:

src/compiler/checker.ts

+267-107
Large diffs are not rendered by default.

src/compiler/commandLineParser.ts

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ namespace ts {
5353
["es2020.promise", "lib.es2020.promise.d.ts"],
5454
["es2020.string", "lib.es2020.string.d.ts"],
5555
["es2020.symbol.wellknown", "lib.es2020.symbol.wellknown.d.ts"],
56+
["es2020.intl", "lib.es2020.intl.d.ts"],
5657
["esnext.array", "lib.es2019.array.d.ts"],
5758
["esnext.symbol", "lib.es2019.symbol.d.ts"],
5859
["esnext.asynciterable", "lib.es2018.asynciterable.d.ts"],

src/compiler/core.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ namespace ts {
150150
* returns a falsey value, then returns false.
151151
* If no such value is found, the callback is applied to each element of array and `true` is returned.
152152
*/
153-
export function every<T>(array: readonly T[], callback: (element: T, index: number) => boolean): boolean {
153+
export function every<T>(array: readonly T[] | undefined, callback: (element: T, index: number) => boolean): boolean {
154154
if (array) {
155155
for (let i = 0; i < array.length; i++) {
156156
if (!callback(array[i], i)) {

src/compiler/diagnosticMessages.json

+24
Original file line numberDiff line numberDiff line change
@@ -3517,6 +3517,22 @@
35173517
"category": "Error",
35183518
"code": 5083
35193519
},
3520+
"Tuple members must all have names or all not have names.": {
3521+
"category": "Error",
3522+
"code": 5084
3523+
},
3524+
"A tuple member cannot be both optional and rest.": {
3525+
"category": "Error",
3526+
"code": 5085
3527+
},
3528+
"A labeled tuple element is declared as optional with a question mark after the name and before the colon, rather than after the type.": {
3529+
"category": "Error",
3530+
"code": 5086
3531+
},
3532+
"A labeled tuple element is declared as rest with a `...` before the name, rather than before the type.": {
3533+
"category": "Error",
3534+
"code": 5087
3535+
},
35203536

35213537
"Generates a sourcemap for each corresponding '.d.ts' file.": {
35223538
"category": "Message",
@@ -5677,6 +5693,14 @@
56775693
"category": "Message",
56785694
"code": 95116
56795695
},
5696+
"Move labeled tuple element modifiers to labels": {
5697+
"category": "Message",
5698+
"code": 95117
5699+
},
5700+
"Convert overload list to single signature": {
5701+
"category": "Message",
5702+
"code": 95118
5703+
},
56805704

56815705
"No value exists in scope for the shorthand property '{0}'. Either declare one or provide an initializer.": {
56825706
"category": "Error",

src/compiler/emitter.ts

+16-4
Original file line numberDiff line numberDiff line change
@@ -1370,6 +1370,8 @@ namespace ts {
13701370
case SyntaxKind.RestType:
13711371
case SyntaxKind.JSDocVariadicType:
13721372
return emitRestOrJSDocVariadicType(node as RestTypeNode | JSDocVariadicType);
1373+
case SyntaxKind.NamedTupleMember:
1374+
return emitNamedTupleMember(node as NamedTupleMember);
13731375

13741376
// Binding patterns
13751377
case SyntaxKind.ObjectBindingPattern:
@@ -2099,9 +2101,19 @@ namespace ts {
20992101
}
21002102

21012103
function emitTupleType(node: TupleTypeNode) {
2102-
writePunctuation("[");
2103-
emitList(node, node.elementTypes, ListFormat.TupleTypeElements);
2104-
writePunctuation("]");
2104+
emitTokenWithComment(SyntaxKind.OpenBracketToken, node.pos, writePunctuation, node);
2105+
const flags = getEmitFlags(node) & EmitFlags.SingleLine ? ListFormat.SingleLineTupleTypeElements : ListFormat.MultiLineTupleTypeElements;
2106+
emitList(node, node.elements, flags | ListFormat.NoSpaceIfEmpty);
2107+
emitTokenWithComment(SyntaxKind.CloseBracketToken, node.elements.end, writePunctuation, node);
2108+
}
2109+
2110+
function emitNamedTupleMember(node: NamedTupleMember) {
2111+
emit(node.dotDotDotToken);
2112+
emit(node.name);
2113+
emit(node.questionToken);
2114+
emitTokenWithComment(SyntaxKind.ColonToken, node.name.end, writePunctuation, node);
2115+
writeSpace();
2116+
emit(node.type);
21052117
}
21062118

21072119
function emitOptionalType(node: OptionalTypeNode) {
@@ -4968,7 +4980,7 @@ namespace ts {
49684980
}
49694981

49704982
function emitLeadingSynthesizedComment(comment: SynthesizedComment) {
4971-
if (comment.kind === SyntaxKind.SingleLineCommentTrivia) {
4983+
if (comment.hasLeadingNewline || comment.kind === SyntaxKind.SingleLineCommentTrivia) {
49724984
writer.writeLine();
49734985
}
49744986
writeSynthesizedComment(comment);

src/compiler/factoryPublic.ts

+38-5
Original file line numberDiff line numberDiff line change
@@ -810,15 +810,15 @@ namespace ts {
810810
: node;
811811
}
812812

813-
export function createTupleTypeNode(elementTypes: readonly TypeNode[]) {
813+
export function createTupleTypeNode(elements: readonly (TypeNode | NamedTupleMember)[]) {
814814
const node = createSynthesizedNode(SyntaxKind.TupleType) as TupleTypeNode;
815-
node.elementTypes = createNodeArray(elementTypes);
815+
node.elements = createNodeArray(elements);
816816
return node;
817817
}
818818

819-
export function updateTupleTypeNode(node: TupleTypeNode, elementTypes: readonly TypeNode[]) {
820-
return node.elementTypes !== elementTypes
821-
? updateNode(createTupleTypeNode(elementTypes), node)
819+
export function updateTupleTypeNode(node: TupleTypeNode, elements: readonly (TypeNode | NamedTupleMember)[]) {
820+
return node.elements !== elements
821+
? updateNode(createTupleTypeNode(elements), node)
822822
: node;
823823
}
824824

@@ -934,6 +934,24 @@ namespace ts {
934934
: node;
935935
}
936936

937+
export function createNamedTupleMember(dotDotDotToken: Token<SyntaxKind.DotDotDotToken> | undefined, name: Identifier, questionToken: Token<SyntaxKind.QuestionToken> | undefined, type: TypeNode) {
938+
const node = <NamedTupleMember>createSynthesizedNode(SyntaxKind.NamedTupleMember);
939+
node.dotDotDotToken = dotDotDotToken;
940+
node.name = name;
941+
node.questionToken = questionToken;
942+
node.type = type;
943+
return node;
944+
}
945+
946+
export function updateNamedTupleMember(node: NamedTupleMember, dotDotDotToken: Token<SyntaxKind.DotDotDotToken> | undefined, name: Identifier, questionToken: Token<SyntaxKind.QuestionToken> | undefined, type: TypeNode) {
947+
return node.dotDotDotToken !== dotDotDotToken
948+
|| node.name !== name
949+
|| node.questionToken !== questionToken
950+
|| node.type !== type
951+
? updateNode(createNamedTupleMember(dotDotDotToken, name, questionToken, type), node)
952+
: node;
953+
}
954+
937955
export function createThisTypeNode() {
938956
return <ThisTypeNode>createSynthesizedNode(SyntaxKind.ThisType);
939957
}
@@ -2616,6 +2634,21 @@ namespace ts {
26162634
return node;
26172635
}
26182636

2637+
2638+
/* @internal */
2639+
export function createJSDocVariadicType(type: TypeNode): JSDocVariadicType {
2640+
const node = createSynthesizedNode(SyntaxKind.JSDocVariadicType) as JSDocVariadicType;
2641+
node.type = type;
2642+
return node;
2643+
}
2644+
2645+
/* @internal */
2646+
export function updateJSDocVariadicType(node: JSDocVariadicType, type: TypeNode): JSDocVariadicType {
2647+
return node.type !== type
2648+
? updateNode(createJSDocVariadicType(type), node)
2649+
: node;
2650+
}
2651+
26192652
// JSX
26202653

26212654
export function createJsxElement(openingElement: JsxOpeningElement, children: readonly JsxChild[], closingElement: JsxClosingElement) {

src/compiler/parser.ts

+31-2
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ namespace ts {
179179
case SyntaxKind.ArrayType:
180180
return visitNode(cbNode, (<ArrayTypeNode>node).elementType);
181181
case SyntaxKind.TupleType:
182-
return visitNodes(cbNode, cbNodes, (<TupleTypeNode>node).elementTypes);
182+
return visitNodes(cbNode, cbNodes, (<TupleTypeNode>node).elements);
183183
case SyntaxKind.UnionType:
184184
case SyntaxKind.IntersectionType:
185185
return visitNodes(cbNode, cbNodes, (<UnionOrIntersectionTypeNode>node).types);
@@ -207,6 +207,11 @@ namespace ts {
207207
visitNode(cbNode, (<MappedTypeNode>node).type);
208208
case SyntaxKind.LiteralType:
209209
return visitNode(cbNode, (<LiteralTypeNode>node).literal);
210+
case SyntaxKind.NamedTupleMember:
211+
return visitNode(cbNode, (<NamedTupleMember>node).dotDotDotToken) ||
212+
visitNode(cbNode, (<NamedTupleMember>node).name) ||
213+
visitNode(cbNode, (<NamedTupleMember>node).questionToken) ||
214+
visitNode(cbNode, (<NamedTupleMember>node).type);
210215
case SyntaxKind.ObjectBindingPattern:
211216
case SyntaxKind.ArrayBindingPattern:
212217
return visitNodes(cbNode, cbNodes, (<BindingPattern>node).elements);
@@ -3056,9 +3061,33 @@ namespace ts {
30563061
return type;
30573062
}
30583063

3064+
function isNextTokenColonOrQuestionColon() {
3065+
return nextToken() === SyntaxKind.ColonToken || (token() === SyntaxKind.QuestionToken && nextToken() === SyntaxKind.ColonToken);
3066+
}
3067+
3068+
function isTupleElementName() {
3069+
if (token() === SyntaxKind.DotDotDotToken) {
3070+
return tokenIsIdentifierOrKeyword(nextToken()) && isNextTokenColonOrQuestionColon();
3071+
}
3072+
return tokenIsIdentifierOrKeyword(token()) && isNextTokenColonOrQuestionColon();
3073+
}
3074+
3075+
function parseTupleElementNameOrTupleElementType() {
3076+
if (lookAhead(isTupleElementName)) {
3077+
const node = <NamedTupleMember>createNode(SyntaxKind.NamedTupleMember);
3078+
node.dotDotDotToken = parseOptionalToken(SyntaxKind.DotDotDotToken);
3079+
node.name = parseIdentifierName();
3080+
node.questionToken = parseOptionalToken(SyntaxKind.QuestionToken);
3081+
parseExpected(SyntaxKind.ColonToken);
3082+
node.type = parseTupleElementType();
3083+
return addJSDocComment(finishNode(node));
3084+
}
3085+
return parseTupleElementType();
3086+
}
3087+
30593088
function parseTupleType(): TupleTypeNode {
30603089
const node = <TupleTypeNode>createNode(SyntaxKind.TupleType);
3061-
node.elementTypes = parseBracketedList(ParsingContext.TupleElementTypes, parseTupleElementType, SyntaxKind.OpenBracketToken, SyntaxKind.CloseBracketToken);
3090+
node.elements = parseBracketedList(ParsingContext.TupleElementTypes, parseTupleElementNameOrTupleElementType, SyntaxKind.OpenBracketToken, SyntaxKind.CloseBracketToken);
30623091
return finishNode(node);
30633092
}
30643093

src/compiler/transformers/declarations.ts

+4
Original file line numberDiff line numberDiff line change
@@ -1018,6 +1018,10 @@ namespace ts {
10181018
}
10191019
}
10201020

1021+
if (isTupleTypeNode(input) && (getLineAndCharacterOfPosition(currentSourceFile, input.pos).line === getLineAndCharacterOfPosition(currentSourceFile, input.end).line)) {
1022+
setEmitFlags(input, EmitFlags.SingleLine);
1023+
}
1024+
10211025
return cleanup(visitEachChild(input, visitDeclarationSubtree, context));
10221026

10231027
function cleanup<T extends Node>(returnValue: T | undefined): T | undefined {

src/compiler/transformers/es2015.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2583,7 +2583,7 @@ namespace ts {
25832583
&& i < numInitialPropertiesWithoutYield) {
25842584
numInitialPropertiesWithoutYield = i;
25852585
}
2586-
if (property.name!.kind === SyntaxKind.ComputedPropertyName) {
2586+
if (Debug.checkDefined(property.name).kind === SyntaxKind.ComputedPropertyName) {
25872587
numInitialProperties = i;
25882588
break;
25892589
}

src/compiler/transformers/taggedTemplate.ts

+15-10
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace ts {
88
export function processTaggedTemplateExpression(
99
context: TransformationContext,
1010
node: TaggedTemplateExpression,
11-
visitor: ((node: Node) => VisitResult<Node>) | undefined,
11+
visitor: Visitor,
1212
currentSourceFile: SourceFile,
1313
recordTaggedTemplateString: (temp: Identifier) => void,
1414
level: ProcessLevel) {
@@ -24,7 +24,9 @@ namespace ts {
2424
const rawStrings: Expression[] = [];
2525
const template = node.template;
2626

27-
if (level === ProcessLevel.LiftRestriction && !hasInvalidEscape(template)) return node;
27+
if (level === ProcessLevel.LiftRestriction && !hasInvalidEscape(template)) {
28+
return visitEachChild(node, visitor, context);
29+
}
2830

2931
if (isNoSubstitutionTemplateLiteral(template)) {
3032
cookedStrings.push(createTemplateCooked(template));
@@ -71,18 +73,21 @@ namespace ts {
7173
*
7274
* @param node The ES6 template literal.
7375
*/
74-
function getRawLiteral(node: LiteralLikeNode, currentSourceFile: SourceFile) {
76+
function getRawLiteral(node: TemplateLiteralLikeNode, currentSourceFile: SourceFile) {
7577
// Find original source text, since we need to emit the raw strings of the tagged template.
7678
// The raw strings contain the (escaped) strings of what the user wrote.
7779
// Examples: `\n` is converted to "\\n", a template string with a newline to "\n".
78-
let text = getSourceTextOfNodeFromSourceFile(currentSourceFile, node);
80+
let text = node.rawText;
81+
if (text === undefined) {
82+
text = getSourceTextOfNodeFromSourceFile(currentSourceFile, node);
7983

80-
// text contains the original source, it will also contain quotes ("`"), dolar signs and braces ("${" and "}"),
81-
// thus we need to remove those characters.
82-
// First template piece starts with "`", others with "}"
83-
// Last template piece ends with "`", others with "${"
84-
const isLast = node.kind === SyntaxKind.NoSubstitutionTemplateLiteral || node.kind === SyntaxKind.TemplateTail;
85-
text = text.substring(1, text.length - (isLast ? 1 : 2));
84+
// text contains the original source, it will also contain quotes ("`"), dolar signs and braces ("${" and "}"),
85+
// thus we need to remove those characters.
86+
// First template piece starts with "`", others with "}"
87+
// Last template piece ends with "`", others with "${"
88+
const isLast = node.kind === SyntaxKind.NoSubstitutionTemplateLiteral || node.kind === SyntaxKind.TemplateTail;
89+
text = text.substring(1, text.length - (isLast ? 1 : 2));
90+
}
8691

8792
// Newline normalization:
8893
// ES6 Spec 11.8.6.1 - Static Semantics of TV's and TRV's

0 commit comments

Comments
 (0)