@@ -571,7 +571,7 @@ export function createFakeJsPlugin({
571571 return { code : EMPTY_STUB , map : null }
572572 }
573573
574- if ( ! program . body . some ( isModuleStatement ) ) {
574+ if ( needsScopeMarker ( program . body ) ) {
575575 program . body . push (
576576 b . ExportNamedDeclaration ( {
577577 declaration : null ,
@@ -641,16 +641,38 @@ export function createFakeJsPlugin({
641641 }
642642}
643643
644- function isModuleStatement ( node : t . ProgramStatement ) : boolean {
645- return (
646- is . oneOf ( node , [
647- 'ImportDeclaration' ,
648- 'ExportAllDeclaration' ,
649- 'ExportDefaultDeclaration' ,
650- 'ExportNamedDeclaration' ,
651- 'TSExportAssignment' ,
652- ] ) ||
653- ( node . type === 'TSImportEqualsDeclaration' &&
654- node . moduleReference . type === 'TSExternalModuleReference' )
655- )
644+ function needsScopeMarker ( body : t . ProgramStatement [ ] ) : boolean {
645+ let hasModuleStatement = false
646+ let hasPrivateDeclaration = false
647+
648+ for ( const node of body ) {
649+ switch ( node . type ) {
650+ case 'ExportAllDeclaration' :
651+ case 'TSExportAssignment' :
652+ return false
653+ case 'ExportNamedDeclaration' :
654+ if ( ! node . declaration ) return false
655+ hasModuleStatement = true
656+ break
657+ case 'ExportDefaultDeclaration' :
658+ if ( ! is . Declaration ( node . declaration ) ) return false
659+ hasModuleStatement = true
660+ break
661+ case 'ImportDeclaration' :
662+ hasModuleStatement = true
663+ break
664+ case 'TSImportEqualsDeclaration' :
665+ hasModuleStatement ||=
666+ node . moduleReference . type === 'TSExternalModuleReference'
667+ break
668+ default :
669+ hasPrivateDeclaration ||=
670+ is . Declaration ( node ) &&
671+ ( node . type !== 'TSModuleDeclaration' ||
672+ ( node . kind !== 'global' && ! is . StringLiteral ( node . id ) ) )
673+ }
674+ }
675+
676+ // Inline exports alone do not prevent private declarations from being exported.
677+ return ! hasModuleStatement || hasPrivateDeclaration
656678}
0 commit comments