@@ -1092,6 +1092,15 @@ export function generateDtsBundle(entries: readonly EntryPointConfig[], options:
1092
1092
// by default this option should be enabled
1093
1093
const exportReferencedTypes = outputOptions . exportReferencedTypes !== false ;
1094
1094
1095
+ function isExportedWithLocalName ( namedDeclaration : ts . NamedDeclaration , exportedName : string ) : boolean {
1096
+ const nodeName = getNodeName ( namedDeclaration ) ;
1097
+ if ( nodeName === undefined ) {
1098
+ throw new Error ( `Cannot find node name ${ namedDeclaration . getText ( ) } ` ) ;
1099
+ }
1100
+
1101
+ return collisionsResolver . resolveReferencedIdentifier ( nodeName as ts . Identifier ) === exportedName ;
1102
+ }
1103
+
1095
1104
return generateOutput (
1096
1105
{
1097
1106
...collectionResult ,
@@ -1102,14 +1111,18 @@ export function generateDtsBundle(entries: readonly EntryPointConfig[], options:
1102
1111
return collisionsResolver . resolveReferencedQualifiedName ( identifier ) ;
1103
1112
}
1104
1113
} ,
1114
+ // eslint-disable-next-line complexity
1105
1115
shouldStatementHasExportKeyword : ( statement : ts . Statement ) => {
1116
+ if ( isAmbientModule ( statement ) || ts . isExportDeclaration ( statement ) ) {
1117
+ return false ;
1118
+ }
1119
+
1106
1120
const statementExports = getExportsForStatement ( rootFileExports , typeChecker , statement ) ;
1107
1121
1108
1122
// If true, then no direct export was found. That means that node might have
1109
1123
// an export keyword (like interface, type, etc) otherwise, if there are
1110
1124
// only re-exports with renaming (like export { foo as bar }) we don't need
1111
1125
// to put export keyword for this statement because we'll re-export it in the way
1112
- // const hasStatementDefaultKeyword = hasNodeModifier(statement, ts.SyntaxKind.DefaultKeyword);
1113
1126
let result = statementExports . length === 0 || statementExports . find ( ( exp : SourceFileExport ) => {
1114
1127
if ( ts . isVariableStatement ( statement ) ) {
1115
1128
for ( const variableDeclaration of statement . declarationList . declarations ) {
@@ -1128,17 +1141,7 @@ export function generateDtsBundle(entries: readonly EntryPointConfig[], options:
1128
1141
return false ;
1129
1142
}
1130
1143
1131
- if ( isNodeNamedDeclaration ( statement ) ) {
1132
- const nodeName = getNodeName ( statement ) ;
1133
- if ( nodeName === undefined ) {
1134
- throw new Error ( `Cannot find node name ${ statement . getText ( ) } ` ) ;
1135
- }
1136
-
1137
- const resolvedName = collisionsResolver . resolveReferencedIdentifier ( nodeName as ts . Identifier ) ;
1138
- return exp . exportedName === resolvedName ;
1139
- }
1140
-
1141
- return false ;
1144
+ return isNodeNamedDeclaration ( statement ) && isExportedWithLocalName ( statement , exp . exportedName ) ;
1142
1145
} ) !== undefined ;
1143
1146
1144
1147
// "direct export" means export from the root source file
@@ -1156,8 +1159,8 @@ export function generateDtsBundle(entries: readonly EntryPointConfig[], options:
1156
1159
// "valuable" statements must be re-exported from root source file
1157
1160
// to having export keyword in declaration file
1158
1161
result = result && statementExports . length !== 0 ;
1159
- } else if ( isAmbientModule ( statement ) || ts . isExportDeclaration ( statement ) ) {
1160
- result = false ;
1162
+ } else if ( isNodeNamedDeclaration ( statement ) && ! isExportedWithLocalName ( statement , getNodeName ( statement ) ! . getText ( ) ) ) { // eslint-disable-line @typescript-eslint/no-non-null-assertion
1163
+ return false ;
1161
1164
}
1162
1165
1163
1166
return result ;
0 commit comments