@@ -1043,7 +1043,7 @@ namespace ts {
10431043 const moduleSymbol = resolveExternalModuleName(node, (<ImportDeclaration>node.parent).moduleSpecifier);
10441044
10451045 if (moduleSymbol) {
1046- const exportDefaultSymbol = isShorthandAmbientModule (moduleSymbol.valueDeclaration ) ?
1046+ const exportDefaultSymbol = isShorthandAmbientModuleSymbol (moduleSymbol) ?
10471047 moduleSymbol :
10481048 moduleSymbol.exports["export="] ?
10491049 getPropertyOfType(getTypeOfSymbol(moduleSymbol.exports["export="]), "default") :
@@ -1119,7 +1119,7 @@ namespace ts {
11191119 if (targetSymbol) {
11201120 const name = specifier.propertyName || specifier.name;
11211121 if (name.text) {
1122- if (isShorthandAmbientModule (moduleSymbol.valueDeclaration )) {
1122+ if (isShorthandAmbientModuleSymbol (moduleSymbol)) {
11231123 return moduleSymbol;
11241124 }
11251125
@@ -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);
@@ -3129,7 +3129,7 @@ namespace ts {
31293129 }
31303130
31313131 // Return the type implied by an object binding pattern
3132- function getTypeFromObjectBindingPattern(pattern: BindingPattern , includePatternInType: boolean, reportErrors: boolean): Type {
3132+ function getTypeFromObjectBindingPattern(pattern: ObjectBindingPattern , includePatternInType: boolean, reportErrors: boolean): Type {
31333133 const members = createMap<Symbol>();
31343134 let hasComputedProperties = false;
31353135 forEach(pattern.elements, e => {
@@ -3160,11 +3160,12 @@ namespace ts {
31603160 // Return the type implied by an array binding pattern
31613161 function getTypeFromArrayBindingPattern(pattern: BindingPattern, includePatternInType: boolean, reportErrors: boolean): Type {
31623162 const elements = pattern.elements;
3163- if (elements.length === 0 || elements[elements.length - 1].dotDotDotToken) {
3163+ const lastElement = lastOrUndefined(elements);
3164+ if (elements.length === 0 || (!isOmittedExpression(lastElement) && lastElement.dotDotDotToken)) {
31643165 return languageVersion >= ScriptTarget.ES6 ? createIterableType(anyType) : anyArrayType;
31653166 }
31663167 // If the pattern has at least one element, and no rest element, then it should imply a tuple type.
3167- const elementTypes = map(elements, e => e.kind === SyntaxKind.OmittedExpression ? anyType : getTypeFromBindingElement(e, includePatternInType, reportErrors));
3168+ const elementTypes = map(elements, e => isOmittedExpression(e) ? anyType : getTypeFromBindingElement(e, includePatternInType, reportErrors));
31683169 let result = createTupleType(elementTypes);
31693170 if (includePatternInType) {
31703171 result = cloneTypeReference(result);
@@ -3182,8 +3183,8 @@ namespace ts {
31823183 // the parameter.
31833184 function getTypeFromBindingPattern(pattern: BindingPattern, includePatternInType?: boolean, reportErrors?: boolean): Type {
31843185 return pattern.kind === SyntaxKind.ObjectBindingPattern
3185- ? getTypeFromObjectBindingPattern(pattern, includePatternInType, reportErrors)
3186- : getTypeFromArrayBindingPattern(pattern, includePatternInType, reportErrors);
3186+ ? getTypeFromObjectBindingPattern(<ObjectBindingPattern> pattern, includePatternInType, reportErrors)
3187+ : getTypeFromArrayBindingPattern(<ArrayBindingPattern> pattern, includePatternInType, reportErrors);
31873188 }
31883189
31893190 // Return the type associated with a variable, parameter, or property declaration. In the simple case this is the type
@@ -3385,7 +3386,7 @@ namespace ts {
33853386 function getTypeOfFuncClassEnumModule(symbol: Symbol): Type {
33863387 const links = getSymbolLinks(symbol);
33873388 if (!links.type) {
3388- if (symbol.valueDeclaration.kind === SyntaxKind.ModuleDeclaration && isShorthandAmbientModule(<ModuleDeclaration> symbol.valueDeclaration )) {
3389+ if (symbol.valueDeclaration.kind === SyntaxKind.ModuleDeclaration && isShorthandAmbientModuleSymbol( symbol)) {
33893390 links.type = anyType;
33903391 }
33913392 else {
@@ -8970,6 +8971,7 @@ namespace ts {
89708971 const isParameter = getRootDeclaration(declaration).kind === SyntaxKind.Parameter;
89718972 const declarationContainer = getControlFlowContainer(declaration);
89728973 let flowContainer = getControlFlowContainer(node);
8974+ const isOuterVariable = flowContainer !== declarationContainer;
89738975 // When the control flow originates in a function expression or arrow function and we are referencing
89748976 // a const variable or parameter from an outer function, we extend the origin of the control flow
89758977 // analysis to include the immediately enclosing function.
@@ -8982,7 +8984,7 @@ namespace ts {
89828984 // the entire control flow graph from the variable's declaration (i.e. when the flow container and
89838985 // declaration container are the same).
89848986 const assumeInitialized = !strictNullChecks || (type.flags & TypeFlags.Any) !== 0 || isParameter ||
8985- flowContainer !== declarationContainer || isInAmbientContext(declaration);
8987+ isOuterVariable || isInAmbientContext(declaration);
89868988 const flowType = getFlowTypeOfReference(node, type, assumeInitialized, flowContainer);
89878989 // A variable is considered uninitialized when it is possible to analyze the entire control flow graph
89888990 // from declaration to use, and when the variable's declared type doesn't include undefined but the
@@ -12437,7 +12439,7 @@ namespace ts {
1243712439 function assignBindingElementTypes(node: VariableLikeDeclaration) {
1243812440 if (isBindingPattern(node.name)) {
1243912441 for (const element of (<BindingPattern>node.name).elements) {
12440- if (element.kind !== SyntaxKind.OmittedExpression ) {
12442+ if (!isOmittedExpression(element) ) {
1244112443 if (element.name.kind === SyntaxKind.Identifier) {
1244212444 getSymbolLinks(getSymbolOfNode(element)).type = getTypeForBindingElement(element);
1244312445 }
@@ -13880,7 +13882,12 @@ namespace ts {
1388013882 pattern: BindingPattern,
1388113883 predicateVariableNode: Node,
1388213884 predicateVariableName: string) {
13883- for (const { name } of pattern.elements) {
13885+ for (const element of pattern.elements) {
13886+ if (isOmittedExpression(element)) {
13887+ continue;
13888+ }
13889+
13890+ const name = element.name;
1388413891 if (name.kind === SyntaxKind.Identifier &&
1388513892 (<Identifier>name).text === predicateVariableName) {
1388613893 error(predicateVariableNode,
@@ -18356,8 +18363,8 @@ namespace ts {
1835618363
1835718364 function moduleExportsSomeValue(moduleReferenceExpression: Expression): boolean {
1835818365 let moduleSymbol = resolveExternalModuleName(moduleReferenceExpression.parent, moduleReferenceExpression);
18359- if (!moduleSymbol) {
18360- // module not found - be conservative
18366+ if (!moduleSymbol || isShorthandAmbientModuleSymbol(moduleSymbol) ) {
18367+ // If the module is not found or is shorthand, assume that it may export a value.
1836118368 return true;
1836218369 }
1836318370
@@ -19990,7 +19997,7 @@ namespace ts {
1999019997 else {
1999119998 const elements = (<BindingPattern>name).elements;
1999219999 for (const element of elements) {
19993- if (element.kind !== SyntaxKind.OmittedExpression ) {
20000+ if (!isOmittedExpression(element) ) {
1999420001 checkGrammarNameInLetOrConstDeclarations(element.name);
1999520002 }
1999620003 }
0 commit comments