@@ -14246,7 +14246,7 @@ namespace ts {
1424614246 if (checkBody) {
1424714247 // body of ambient external module is always a module block
1424814248 for (const statement of (<ModuleBlock>node.body).statements) {
14249- checkBodyOfModuleAugmentation (statement, isGlobalAugmentation);
14249+ checkModuleAugmentationElement (statement, isGlobalAugmentation);
1425014250 }
1425114251 }
1425214252 }
@@ -14273,20 +14273,12 @@ namespace ts {
1427314273 checkSourceElement(node.body);
1427414274 }
1427514275
14276- function checkBodyOfModuleAugmentation (node: Node, isGlobalAugmentation: boolean): void {
14276+ function checkModuleAugmentationElement (node: Node, isGlobalAugmentation: boolean): void {
1427714277 switch (node.kind) {
1427814278 case SyntaxKind.VariableStatement:
1427914279 // error each individual name in variable statement instead of marking the entire variable statement
1428014280 for (const decl of (<VariableStatement>node).declarationList.declarations) {
14281- if (isBindingPattern(decl.name)) {
14282- for (const el of (<BindingPattern>decl.name).elements) {
14283- // mark individual names in binding pattern
14284- checkBodyOfModuleAugmentation(el, isGlobalAugmentation);
14285- }
14286- }
14287- else {
14288- checkBodyOfModuleAugmentation(decl, isGlobalAugmentation);
14289- }
14281+ checkModuleAugmentationElement(decl, isGlobalAugmentation);
1429014282 }
1429114283 break;
1429214284 case SyntaxKind.ExportAssignment:
@@ -14302,7 +14294,23 @@ namespace ts {
1430214294 case SyntaxKind.ImportDeclaration:
1430314295 grammarErrorOnFirstToken(node, Diagnostics.Imports_are_not_permitted_in_module_augmentations_Consider_moving_them_to_the_enclosing_external_module);
1430414296 break;
14305- default:
14297+ case SyntaxKind.BindingElement:
14298+ case SyntaxKind.VariableDeclaration:
14299+ const name = (<VariableDeclaration | BindingElement>node).name;
14300+ if (isBindingPattern(name)) {
14301+ for (const el of name.elements) {
14302+ // mark individual names in binding pattern
14303+ checkModuleAugmentationElement(el, isGlobalAugmentation);
14304+ }
14305+ break;
14306+ }
14307+ // fallthrough
14308+ case SyntaxKind.ClassDeclaration:
14309+ case SyntaxKind.EnumDeclaration:
14310+ case SyntaxKind.FunctionDeclaration:
14311+ case SyntaxKind.InterfaceDeclaration:
14312+ case SyntaxKind.ModuleDeclaration:
14313+ case SyntaxKind.TypeAliasDeclaration:
1430614314 const symbol = getSymbolOfNode(node);
1430714315 if (symbol) {
1430814316 // module augmentations cannot introduce new names on the top level scope of the module
0 commit comments