@@ -2505,8 +2505,8 @@ namespace ts {
2505
2505
}
2506
2506
}
2507
2507
2508
- function buildBindingElementDisplay(bindingElement: BindingElement , writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, symbolStack?: Symbol[]) {
2509
- if (bindingElement.kind === SyntaxKind.OmittedExpression ) {
2508
+ function buildBindingElementDisplay(bindingElement: ArrayBindingElement , writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, symbolStack?: Symbol[]) {
2509
+ if (isOmittedExpression( bindingElement) ) {
2510
2510
return;
2511
2511
}
2512
2512
Debug.assert(bindingElement.kind === SyntaxKind.BindingElement);
@@ -3125,7 +3125,7 @@ namespace ts {
3125
3125
}
3126
3126
3127
3127
// Return the type implied by an object binding pattern
3128
- function getTypeFromObjectBindingPattern(pattern: BindingPattern , includePatternInType: boolean, reportErrors: boolean): Type {
3128
+ function getTypeFromObjectBindingPattern(pattern: ObjectBindingPattern , includePatternInType: boolean, reportErrors: boolean): Type {
3129
3129
const members = createMap<Symbol>();
3130
3130
let hasComputedProperties = false;
3131
3131
forEach(pattern.elements, e => {
@@ -3156,11 +3156,12 @@ namespace ts {
3156
3156
// Return the type implied by an array binding pattern
3157
3157
function getTypeFromArrayBindingPattern(pattern: BindingPattern, includePatternInType: boolean, reportErrors: boolean): Type {
3158
3158
const elements = pattern.elements;
3159
- if (elements.length === 0 || elements[elements.length - 1].dotDotDotToken) {
3159
+ const lastElement = lastOrUndefined(elements);
3160
+ if (elements.length === 0 || (!isOmittedExpression(lastElement) && lastElement.dotDotDotToken)) {
3160
3161
return languageVersion >= ScriptTarget.ES6 ? createIterableType(anyType) : anyArrayType;
3161
3162
}
3162
3163
// If the pattern has at least one element, and no rest element, then it should imply a tuple type.
3163
- const elementTypes = map(elements, e => e.kind === SyntaxKind.OmittedExpression ? anyType : getTypeFromBindingElement(e, includePatternInType, reportErrors));
3164
+ const elementTypes = map(elements, e => isOmittedExpression(e) ? anyType : getTypeFromBindingElement(e, includePatternInType, reportErrors));
3164
3165
let result = createTupleType(elementTypes);
3165
3166
if (includePatternInType) {
3166
3167
result = cloneTypeReference(result);
@@ -3178,8 +3179,8 @@ namespace ts {
3178
3179
// the parameter.
3179
3180
function getTypeFromBindingPattern(pattern: BindingPattern, includePatternInType?: boolean, reportErrors?: boolean): Type {
3180
3181
return pattern.kind === SyntaxKind.ObjectBindingPattern
3181
- ? getTypeFromObjectBindingPattern(pattern, includePatternInType, reportErrors)
3182
- : getTypeFromArrayBindingPattern(pattern, includePatternInType, reportErrors);
3182
+ ? getTypeFromObjectBindingPattern(<ObjectBindingPattern> pattern, includePatternInType, reportErrors)
3183
+ : getTypeFromArrayBindingPattern(<ArrayBindingPattern> pattern, includePatternInType, reportErrors);
3183
3184
}
3184
3185
3185
3186
// Return the type associated with a variable, parameter, or property declaration. In the simple case this is the type
@@ -12413,7 +12414,7 @@ namespace ts {
12413
12414
function assignBindingElementTypes(node: VariableLikeDeclaration) {
12414
12415
if (isBindingPattern(node.name)) {
12415
12416
for (const element of (<BindingPattern>node.name).elements) {
12416
- if (element.kind !== SyntaxKind.OmittedExpression ) {
12417
+ if (!isOmittedExpression(element) ) {
12417
12418
if (element.name.kind === SyntaxKind.Identifier) {
12418
12419
getSymbolLinks(getSymbolOfNode(element)).type = getTypeForBindingElement(element);
12419
12420
}
@@ -13889,7 +13890,12 @@ namespace ts {
13889
13890
pattern: BindingPattern,
13890
13891
predicateVariableNode: Node,
13891
13892
predicateVariableName: string) {
13892
- for (const { name } of pattern.elements) {
13893
+ for (const element of pattern.elements) {
13894
+ if (isOmittedExpression(element)) {
13895
+ continue;
13896
+ }
13897
+
13898
+ const name = element.name;
13893
13899
if (name.kind === SyntaxKind.Identifier &&
13894
13900
(<Identifier>name).text === predicateVariableName) {
13895
13901
error(predicateVariableNode,
@@ -19999,7 +20005,7 @@ namespace ts {
19999
20005
else {
20000
20006
const elements = (<BindingPattern>name).elements;
20001
20007
for (const element of elements) {
20002
- if (element.kind !== SyntaxKind.OmittedExpression ) {
20008
+ if (!isOmittedExpression(element) ) {
20003
20009
checkGrammarNameInLetOrConstDeclarations(element.name);
20004
20010
}
20005
20011
}
0 commit comments