@@ -1024,62 +1024,94 @@ module ts {
1024
1024
// If we are emitting property it isn't moduleElement and hence we already know it needs to be emitted
1025
1025
// so there is no check needed to see if declaration is visible
1026
1026
if ( node . kind !== SyntaxKind . VariableDeclaration || resolver . isDeclarationVisible ( node ) ) {
1027
- // If this node is a computed name, it can only be a symbol, because we've already skipped
1028
- // it if it's not a well known symbol. In that case, the text of the name will be exactly
1029
- // what we want, namely the name expression enclosed in brackets.
1030
- writeTextOfNode ( currentSourceFile , node . name ) ;
1031
- // If optional property emit ?
1032
- if ( ( node . kind === SyntaxKind . PropertyDeclaration || node . kind === SyntaxKind . PropertySignature ) && hasQuestionToken ( node ) ) {
1033
- write ( "?" ) ;
1034
- }
1035
- if ( ( node . kind === SyntaxKind . PropertyDeclaration || node . kind === SyntaxKind . PropertySignature ) && node . parent . kind === SyntaxKind . TypeLiteral ) {
1036
- emitTypeOfVariableDeclarationFromTypeLiteral ( node ) ;
1027
+ if ( isBindingPattern ( node . name ) ) {
1028
+ emitBindingPattern ( < BindingPattern > node . name ) ;
1037
1029
}
1038
- else if ( ! ( node . flags & NodeFlags . Private ) ) {
1039
- writeTypeOfDeclaration ( node , node . type , getVariableDeclarationTypeVisibilityError ) ;
1030
+ else {
1031
+ // If this node is a computed name, it can only be a symbol, because we've already skipped
1032
+ // it if it's not a well known symbol. In that case, the text of the name will be exactly
1033
+ // what we want, namely the name expression enclosed in brackets.
1034
+ writeTextOfNode ( currentSourceFile , node . name ) ;
1035
+ // If optional property emit ?
1036
+ if ( ( node . kind === SyntaxKind . PropertyDeclaration || node . kind === SyntaxKind . PropertySignature ) && hasQuestionToken ( node ) ) {
1037
+ write ( "?" ) ;
1038
+ }
1039
+ if ( ( node . kind === SyntaxKind . PropertyDeclaration || node . kind === SyntaxKind . PropertySignature ) && node . parent . kind === SyntaxKind . TypeLiteral ) {
1040
+ emitTypeOfVariableDeclarationFromTypeLiteral ( node ) ;
1041
+ }
1042
+ else if ( ! ( node . flags & NodeFlags . Private ) ) {
1043
+ writeTypeOfDeclaration ( node , node . type , getVariableDeclarationTypeVisibilityError ) ;
1044
+ }
1040
1045
}
1041
1046
}
1042
1047
1043
- function getVariableDeclarationTypeVisibilityError ( symbolAccesibilityResult : SymbolAccessiblityResult ) : SymbolAccessibilityDiagnostic {
1044
- var diagnosticMessage : DiagnosticMessage ;
1048
+ function getVariableDeclarationTypeVisibilityDiagnosticMessage ( symbolAccesibilityResult : SymbolAccessiblityResult ) {
1045
1049
if ( node . kind === SyntaxKind . VariableDeclaration ) {
1046
- diagnosticMessage = symbolAccesibilityResult . errorModuleName ?
1047
- symbolAccesibilityResult . accessibility === SymbolAccessibility . CannotBeNamed ?
1048
- Diagnostics . Exported_variable_0_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named :
1049
- Diagnostics . Exported_variable_0_has_or_is_using_name_1_from_private_module_2 :
1050
- Diagnostics . Exported_variable_0_has_or_is_using_private_name_1 ;
1050
+ return symbolAccesibilityResult . errorModuleName ?
1051
+ symbolAccesibilityResult . accessibility === SymbolAccessibility . CannotBeNamed ?
1052
+ Diagnostics . Exported_variable_0_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named :
1053
+ Diagnostics . Exported_variable_0_has_or_is_using_name_1_from_private_module_2 :
1054
+ Diagnostics . Exported_variable_0_has_or_is_using_private_name_1 ;
1051
1055
}
1052
1056
// This check is to ensure we don't report error on constructor parameter property as that error would be reported during parameter emit
1053
1057
else if ( node . kind === SyntaxKind . PropertyDeclaration || node . kind === SyntaxKind . PropertySignature ) {
1054
1058
// TODO(jfreeman): Deal with computed properties in error reporting.
1055
1059
if ( node . flags & NodeFlags . Static ) {
1056
- diagnosticMessage = symbolAccesibilityResult . errorModuleName ?
1057
- symbolAccesibilityResult . accessibility === SymbolAccessibility . CannotBeNamed ?
1058
- Diagnostics . Public_static_property_0_of_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named :
1059
- Diagnostics . Public_static_property_0_of_exported_class_has_or_is_using_name_1_from_private_module_2 :
1060
- Diagnostics . Public_static_property_0_of_exported_class_has_or_is_using_private_name_1 ;
1060
+ return symbolAccesibilityResult . errorModuleName ?
1061
+ symbolAccesibilityResult . accessibility === SymbolAccessibility . CannotBeNamed ?
1062
+ Diagnostics . Public_static_property_0_of_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named :
1063
+ Diagnostics . Public_static_property_0_of_exported_class_has_or_is_using_name_1_from_private_module_2 :
1064
+ Diagnostics . Public_static_property_0_of_exported_class_has_or_is_using_private_name_1 ;
1061
1065
}
1062
1066
else if ( node . parent . kind === SyntaxKind . ClassDeclaration ) {
1063
- diagnosticMessage = symbolAccesibilityResult . errorModuleName ?
1064
- symbolAccesibilityResult . accessibility === SymbolAccessibility . CannotBeNamed ?
1065
- Diagnostics . Public_property_0_of_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named :
1066
- Diagnostics . Public_property_0_of_exported_class_has_or_is_using_name_1_from_private_module_2 :
1067
- Diagnostics . Public_property_0_of_exported_class_has_or_is_using_private_name_1 ;
1067
+ return symbolAccesibilityResult . errorModuleName ?
1068
+ symbolAccesibilityResult . accessibility === SymbolAccessibility . CannotBeNamed ?
1069
+ Diagnostics . Public_property_0_of_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named :
1070
+ Diagnostics . Public_property_0_of_exported_class_has_or_is_using_name_1_from_private_module_2 :
1071
+ Diagnostics . Public_property_0_of_exported_class_has_or_is_using_private_name_1 ;
1068
1072
}
1069
1073
else {
1070
1074
// Interfaces cannot have types that cannot be named
1071
- diagnosticMessage = symbolAccesibilityResult . errorModuleName ?
1072
- Diagnostics . Property_0_of_exported_interface_has_or_is_using_name_1_from_private_module_2 :
1073
- Diagnostics . Property_0_of_exported_interface_has_or_is_using_private_name_1 ;
1075
+ return symbolAccesibilityResult . errorModuleName ?
1076
+ Diagnostics . Property_0_of_exported_interface_has_or_is_using_name_1_from_private_module_2 :
1077
+ Diagnostics . Property_0_of_exported_interface_has_or_is_using_private_name_1 ;
1074
1078
}
1075
1079
}
1080
+ }
1076
1081
1082
+ function getVariableDeclarationTypeVisibilityError ( symbolAccesibilityResult : SymbolAccessiblityResult ) : SymbolAccessibilityDiagnostic {
1083
+ var diagnosticMessage = getVariableDeclarationTypeVisibilityDiagnosticMessage ( symbolAccesibilityResult ) ;
1077
1084
return diagnosticMessage !== undefined ? {
1078
1085
diagnosticMessage,
1079
1086
errorNode : node ,
1080
1087
typeName : node . name
1081
1088
} : undefined ;
1082
1089
}
1090
+
1091
+ function emitBindingPattern ( bindingPattern : BindingPattern ) {
1092
+ emitCommaList ( bindingPattern . elements , emitBindingElement ) ;
1093
+ }
1094
+
1095
+ function emitBindingElement ( bindingElement : BindingElement ) {
1096
+ function getBindingElementTypeVisibilityError ( symbolAccesibilityResult : SymbolAccessiblityResult ) : SymbolAccessibilityDiagnostic {
1097
+ var diagnosticMessage = getVariableDeclarationTypeVisibilityDiagnosticMessage ( symbolAccesibilityResult ) ;
1098
+ return diagnosticMessage !== undefined ? {
1099
+ diagnosticMessage,
1100
+ errorNode : bindingElement ,
1101
+ typeName : bindingElement . name
1102
+ } : undefined ;
1103
+ }
1104
+
1105
+ if ( bindingElement . name ) {
1106
+ if ( isBindingPattern ( bindingElement . name ) ) {
1107
+ emitBindingPattern ( < BindingPattern > bindingElement . name ) ;
1108
+ }
1109
+ else {
1110
+ writeTextOfNode ( currentSourceFile , bindingElement . name ) ;
1111
+ writeTypeOfDeclaration ( bindingElement , /*type*/ undefined , getBindingElementTypeVisibilityError ) ;
1112
+ }
1113
+ }
1114
+ }
1083
1115
}
1084
1116
1085
1117
function emitTypeOfVariableDeclarationFromTypeLiteral ( node : VariableLikeDeclaration ) {
0 commit comments