Skip to content

[Bug]: Legal comments above import statements are not preserved #5482

@IronGeek

Description

@IronGeek

Reproduction link or steps

index.ts

/*! 
 * INDEX.TS (ABOVE IMPORT)
 * THIS COMMENT IS NOT PRESERVED
 */

import { foo } from './foo.ts';

/*! 
 * INDEX.TS (ABOVE IMPORT)
 * THIS COMMENT IS NOT PRESERVED
 */

import { bar } from './bar.ts';

/*! 
 * INDEX.TS (BELOW IMPORT)
 */

/*! 
 * INDEX.TS (ABOVE EXPORT)
 */

export default foo + bar;

/*! 
 * INDEX.TS (BELOW EXPORT)
 */

rolldown.config.ts

import type { RolldownOptions } from 'rolldown';

const config: RolldownOptions = {   
   experimental : {
      attachDebugInfo: 'none'
   },
   output: {
    legalComments: 'inline',    
    format: 'esm'    
   }
}

export default config

Rolldown REPL: https://repl.rolldown.rs/#eNq1Uk1vgkAQ/SvTvdBag3caD1VpSlLFILEeuKAulmTZJbC0NoT/3lkWLFVr0yYlJLuz8/HevJmSRMQqScy3dG/KXN05sT7tPtmgOehdQcChB85sYq9MfwHX9yN3aYMznbuef1P7/EdnAWN3OrVnPuB15vow9+yF7S3tiYoYBDzgcZKKTEIJkRBQQZSJBAxzgBbCGXcq5D/Q1mHWQUPrEtrIfnKfu2h1rW9p2auvgXRfg25pFBZM1o3eKgKX4bpVUHZKLJkVtOqTTDC2FW/c3AgexbvOlM549LyatuV7SrF3rwlzUxkLnh90aNO1Dlgjl6ArWSc5Q6wDijgAtkezOKFchgwsKOtH/EIpw83LhK6LncMjYYHBBadG7a769SEKmRbykMPoLmRjkahaOcbHnMWY0Vc+HRGJLAkxwaB5Yhyeq4DjfyK05k5QMr1NrUyNdbTKD6778wy1KGqCQzDwOFqZtsaZCSILvWUti8b6Owu1wsgCj1+wQBqviMdCSXNJqg/cYzCS

What is expected?

The legal comments above import statements should be preserved

index.js

/*! 
 * INDEX.TS (ABOVE IMPORT)
 * THIS COMMENT IS NOT PRESERVED
 */
/*! 
* FOO.TS (ABOVE EXPORT)
*/
const foo = "foo";
/*! 
* FOO.TS (BELOW EXPORT)
*/
/*! 
 * INDEX.TS (ABOVE IMPORT)
 * THIS COMMENT IS NOT PRESERVED
 */
/*! 
* FOO.TS (ABOVE EXPORT)
*/
const bar = "bar";
/*! 
* FOO.TS (BELOW EXPORT)
*/
/*! 
* INDEX.TS (BELOW IMPORT)
*/
/*! 
* INDEX.TS (ABOVE EXPORT)
*/
var index_default = foo + bar;
/*! 
* INDEX.TS (BELOW EXPORT)
*/
export { index_default as default };

What is actually happening?

The legal comments above import statements (which are very common as license file header) is not preserved with the options legalComments: 'inline'

index.js

/*! 
* FOO.TS (ABOVE EXPORT)
*/
const foo = "foo";
/*! 
* FOO.TS (BELOW EXPORT)
*/
/*! 
* FOO.TS (ABOVE EXPORT)
*/
const bar = "bar";
/*! 
* FOO.TS (BELOW EXPORT)
*/
/*! 
* INDEX.TS (BELOW IMPORT)
*/
/*! 
* INDEX.TS (ABOVE EXPORT)
*/
var index_default = foo + bar;
/*! 
* INDEX.TS (BELOW EXPORT)
*/
export { index_default as default };

System Info

System:
    OS: Linux 6.15 Arch Linux
    CPU: (8) x64 Intel(R) Core(TM) i7-3610QM CPU @ 2.30GHz
    Memory: 4.85 GB / 15.07 GB
    Container: Yes
    Shell: 5.9 - /usr/bin/zsh
  Binaries:
    Node: 24.4.1 - /usr/bin/node
    npm: 11.4.2 - /usr/bin/npm
    pnpm: 10.13.1 - /usr/bin/pnpm
    bun: 1.2.18 - ~/.bun/bin/bun
  npmPackages:
    rolldown: 1.0.0-beta.29 => 1.0.0-beta.29

Any additional comments?

I found the bug while trying to preserve license information on the final bundled file.

Metadata

Metadata

Assignees

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions