@@ -309,6 +309,39 @@ class BinderImp implements Binder {
309309 }
310310 }
311311
312+ // Ensure platform-specific variants (e.g. *-browser.*, *-react-native.*)
313+ // are preserved whenever their base helper is referenced.
314+ const platformSuffixes = [ "-browser" , "-react-native" ] ;
315+ const helpersWithReferences = Array . from ( usedHelperFiles ) ;
316+ for ( const helperFile of helpersWithReferences ) {
317+ const directory = helperFile . getDirectory ( ) ;
318+ const filePath = helperFile . getFilePath ( ) ;
319+ const fileName = path . basename ( filePath ) ;
320+ const dotIndex = fileName . indexOf ( "." ) ;
321+ const baseName =
322+ dotIndex === - 1 ? fileName : fileName . substring ( 0 , dotIndex ) ;
323+ const variantPrefix = `${ baseName } -` ;
324+
325+ for ( const sibling of directory . getSourceFiles ( ) ) {
326+ if ( usedHelperFiles . has ( sibling ) ) {
327+ continue ;
328+ }
329+ const siblingPath = sibling . getFilePath ( ) ;
330+ const siblingName = path . basename ( siblingPath ) ;
331+ const siblingDotIndex = siblingName . indexOf ( "." ) ;
332+ const siblingBaseName =
333+ siblingDotIndex === - 1
334+ ? siblingName
335+ : siblingName . substring ( 0 , siblingDotIndex ) ;
336+
337+ if (
338+ siblingBaseName . startsWith ( variantPrefix ) &&
339+ platformSuffixes . some ( ( suffix ) => siblingBaseName . endsWith ( suffix ) )
340+ ) {
341+ usedHelperFiles . add ( sibling ) ;
342+ }
343+ }
344+ }
312345 function isFileUnused ( file : SourceFile ) {
313346 return ! usedHelperFiles . has ( file ) ;
314347 }
0 commit comments