Skip to content

Commit 528d82a

Browse files
committed
Merge branch 'master' of https://github.com/microsoft/TypeScript into bug/38463
2 parents 1c72da6 + 5f597e6 commit 528d82a

File tree

275 files changed

+6205
-1596
lines changed

Some content is hidden

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

275 files changed

+6205
-1596
lines changed

CONTRIBUTING.md

Lines changed: 203 additions & 216 deletions
Large diffs are not rendered by default.

src/compiler/binder.ts

Lines changed: 39 additions & 34 deletions
Large diffs are not rendered by default.

src/compiler/checker.ts

Lines changed: 369 additions & 194 deletions
Large diffs are not rendered by default.

src/compiler/core.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,28 @@ namespace ts {
129129
return map;
130130
}
131131

132+
/**
133+
* Creates a new array with `element` interspersed in between each element of `input`
134+
* if there is more than 1 value in `input`. Otherwise, returns the existing array.
135+
*/
136+
export function intersperse<T>(input: T[], element: T): T[] {
137+
if (input.length <= 1) {
138+
return input;
139+
}
140+
const result: T[] = [];
141+
for (let i = 0, n = input.length; i < n; i++) {
142+
if (i) result.push(element);
143+
result.push(input[i]);
144+
}
145+
return result;
146+
}
147+
132148
/**
133149
* Iterates through `array` by index and performs the callback on each element of array until the callback
134150
* returns a falsey value, then returns false.
135151
* If no such value is found, the callback is applied to each element of array and `true` is returned.
136152
*/
137-
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 {
138154
if (array) {
139155
for (let i = 0; i < array.length; i++) {
140156
if (!callback(array[i], i)) {

src/compiler/debug.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ namespace ts {
376376
Object.defineProperties(ctor.prototype, {
377377
__debugKind: { get(this: Node) { return formatSyntaxKind(this.kind); } },
378378
__debugNodeFlags: { get(this: Node) { return formatNodeFlags(this.flags); } },
379-
__debugModifierFlags: { get(this: Node) { return formatModifierFlags(getModifierFlagsNoCache(this)); } },
379+
__debugModifierFlags: { get(this: Node) { return formatModifierFlags(getEffectiveModifierFlagsNoCache(this)); } },
380380
__debugTransformFlags: { get(this: Node) { return formatTransformFlags(this.transformFlags); } },
381381
__debugIsParseTreeNode: { get(this: Node) { return isParseTreeNode(this); } },
382382
__debugEmitFlags: { get(this: Node) { return formatEmitFlags(getEmitFlags(this)); } },

src/compiler/diagnosticMessages.json

Lines changed: 35 additions & 3 deletions
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",
@@ -4911,6 +4927,14 @@
49114927
"category": "Error",
49124928
"code": 8032
49134929
},
4930+
"A JSDoc '@typedef' comment may not contain multiple '@type' tags.": {
4931+
"category": "Error",
4932+
"code": 8033
4933+
},
4934+
"The tag was first specified here.": {
4935+
"category": "Error",
4936+
"code": 8034
4937+
},
49144938
"Only identifiers/qualified-names with optional type arguments are currently supported in a class 'extends' clause.": {
49154939
"category": "Error",
49164940
"code": 9002
@@ -5649,7 +5673,7 @@
56495673
"category": "Message",
56505674
"code": 95111
56515675
},
5652-
"Remove block body braces": {
5676+
"Remove braces from arrow function body": {
56535677
"category": "Message",
56545678
"code": 95112
56555679
},
@@ -5661,15 +5685,23 @@
56615685
"category": "Message",
56625686
"code": 95114
56635687
},
5664-
"Remove all incorrect body block braces": {
5688+
"Remove braces from all arrow function bodies with relevant issues": {
56655689
"category": "Message",
56665690
"code": 95115
56675691
},
56685692
"Wrap all object literal with parentheses": {
56695693
"category": "Message",
56705694
"code": 95116
56715695
},
5672-
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+
},
5704+
56735705
"No value exists in scope for the shorthand property '{0}'. Either declare one or provide an initializer.": {
56745706
"category": "Error",
56755707
"code": 18004

src/compiler/emitter.ts

Lines changed: 16 additions & 4 deletions
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/factory.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -751,7 +751,7 @@ namespace ts {
751751
* @param allowSourceMaps A value indicating whether source maps may be emitted for the name.
752752
*/
753753
export function getExternalModuleOrNamespaceExportName(ns: Identifier | undefined, node: Declaration, allowComments?: boolean, allowSourceMaps?: boolean): Identifier | PropertyAccessExpression {
754-
if (ns && hasModifier(node, ModifierFlags.Export)) {
754+
if (ns && hasSyntacticModifier(node, ModifierFlags.Export)) {
755755
return getNamespaceMemberName(ns, getName(node), allowComments, allowSourceMaps);
756756
}
757757
return getExportName(node, allowComments, allowSourceMaps);

src/compiler/factoryPublic.ts

Lines changed: 38 additions & 5 deletions
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

Lines changed: 39 additions & 2 deletions
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

@@ -7483,6 +7512,14 @@ namespace ts {
74837512
}
74847513
if (child.kind === SyntaxKind.JSDocTypeTag) {
74857514
if (childTypeTag) {
7515+
parseErrorAtCurrentToken(Diagnostics.A_JSDoc_typedef_comment_may_not_contain_multiple_type_tags);
7516+
const lastError = lastOrUndefined(parseDiagnostics);
7517+
if (lastError) {
7518+
addRelatedInfo(
7519+
lastError,
7520+
createDiagnosticForNode(sourceFile, Diagnostics.The_tag_was_first_specified_here)
7521+
);
7522+
}
74867523
break;
74877524
}
74887525
else {

0 commit comments

Comments
 (0)