@@ -28,12 +28,14 @@ import {
2828} from './runtime-binding.ts'
2929import {
3030 collectReferenceDirectives ,
31+ findDefaultExportRef ,
3132 getIdentifierIndex ,
3233 getIdFromTSEntityName ,
3334 inheritNodeComments ,
3435 isCjsDtsInputSyntax ,
3536 isHelperImport ,
3637 isInfer ,
38+ isLineMapped ,
3739 overwriteNode ,
3840 pragmaComments ,
3941} from './utils.ts'
@@ -214,6 +216,22 @@ export function createFakeJsPlugin({
214216 const appendStmts : t . ProgramStatement [ ] = [ ]
215217 const namespaceStmts : NamespaceMap = new Map ( )
216218
219+ // Generators map different statements of `export default <expr>`: tsc and
220+ // tsgo only map `export default _default`, oxc only maps the declaration.
221+ // The former is dropped below, so a binding on a line without mappings
222+ // takes the position of its default export reference.
223+ const defaultExportRef = sourcemap
224+ ? findDefaultExportRef ( program . body )
225+ : undefined
226+ const inputMappings = defaultExportRef
227+ ? this . getCombinedSourcemap ( ) . mappings
228+ : ''
229+ const getBindingRange = ( binding : t . Identifier ) =>
230+ binding . name === defaultExportRef ?. name &&
231+ ! isLineMapped ( inputMappings , code , binding . start )
232+ ? { start : defaultExportRef . start , end : defaultExportRef . end }
233+ : undefined
234+
217235 for ( const [ i , stmt ] of program . body . entries ( ) ) {
218236 const setStmt = ( stmt : t . ProgramStatement ) => ( program . body [ i ] = stmt )
219237 if ( rewriteImportExport ( stmt , setStmt , appendStmts ) ) {
@@ -378,6 +396,7 @@ export function createFakeJsPlugin({
378396 id : b . ArrayPattern ( {
379397 elements : bindings . map ( ( binding ) => ( {
380398 ...binding ,
399+ ...getBindingRange ( binding ) ,
381400 typeAnnotation : null ,
382401 } ) ) ,
383402 } ) ,
0 commit comments