@@ -2505,8 +2505,8 @@ namespace ts {
25052505 }
25062506 }
25072507
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) ) {
25102510 return;
25112511 }
25122512 Debug.assert(bindingElement.kind === SyntaxKind.BindingElement);
@@ -3125,7 +3125,7 @@ namespace ts {
31253125 }
31263126
31273127 // 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 {
31293129 const members = createMap<Symbol>();
31303130 let hasComputedProperties = false;
31313131 forEach(pattern.elements, e => {
@@ -3156,11 +3156,12 @@ namespace ts {
31563156 // Return the type implied by an array binding pattern
31573157 function getTypeFromArrayBindingPattern(pattern: BindingPattern, includePatternInType: boolean, reportErrors: boolean): Type {
31583158 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)) {
31603161 return languageVersion >= ScriptTarget.ES6 ? createIterableType(anyType) : anyArrayType;
31613162 }
31623163 // 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));
31643165 let result = createTupleType(elementTypes);
31653166 if (includePatternInType) {
31663167 result = cloneTypeReference(result);
@@ -3178,8 +3179,8 @@ namespace ts {
31783179 // the parameter.
31793180 function getTypeFromBindingPattern(pattern: BindingPattern, includePatternInType?: boolean, reportErrors?: boolean): Type {
31803181 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);
31833184 }
31843185
31853186 // 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 {
1241312414 function assignBindingElementTypes(node: VariableLikeDeclaration) {
1241412415 if (isBindingPattern(node.name)) {
1241512416 for (const element of (<BindingPattern>node.name).elements) {
12416- if (element.kind !== SyntaxKind.OmittedExpression ) {
12417+ if (!isOmittedExpression(element) ) {
1241712418 if (element.name.kind === SyntaxKind.Identifier) {
1241812419 getSymbolLinks(getSymbolOfNode(element)).type = getTypeForBindingElement(element);
1241912420 }
@@ -13889,7 +13890,12 @@ namespace ts {
1388913890 pattern: BindingPattern,
1389013891 predicateVariableNode: Node,
1389113892 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;
1389313899 if (name.kind === SyntaxKind.Identifier &&
1389413900 (<Identifier>name).text === predicateVariableName) {
1389513901 error(predicateVariableNode,
@@ -19999,7 +20005,7 @@ namespace ts {
1999920005 else {
2000020006 const elements = (<BindingPattern>name).elements;
2000120007 for (const element of elements) {
20002- if (element.kind !== SyntaxKind.OmittedExpression ) {
20008+ if (!isOmittedExpression(element) ) {
2000320009 checkGrammarNameInLetOrConstDeclarations(element.name);
2000420010 }
2000520011 }
0 commit comments