Skip to content

bug: comments are not entirely emitted when comments: 'all' is specified  #1440

Open

Description

@michaele-blend

Bug report

Version 5.19.4

Complete CLI command or minify() options used

/** @returns {terser.MinifyOptions} */
const getTerserOpts = () => ({
  ecma: 2020,
  toplevel: true,

  parse: {},
  mangle: true,
  compress: {
    keep_fargs: false,

    pure_getters: true,
    drop_console: false,
    pure_funcs: [],

    unsafe: true,
    unsafe_arrows: true,
    unsafe_comps: true,
    unsafe_Function: true,
    unsafe_math: true,
    unsafe_symbols: true,
    unsafe_methods: true,
    unsafe_proto: true,

    passes: 10,
  },
  format: {
    comments: 'all',
    wrap_func_args: false,
    wrap_iife: false,
  },
});

const file1 = `
// f1-before

const func = () => 'surprise!';

// f1-after
`
const file2 = `
// f2-before

console.log(func());

// f2-after
`



const terser = require('terser');
terser.minify({ 'file-1.js': file1, 'file-2.js': file2 }, getTerserOpts()).then(console.dir)

terser input

see above

terser output or error

Expected result

when comments: 'all' is specified, I expect to receive all comments: [f1-before, f1-after, f2-before, f2-after].

{
  code: '// f1-before\n// f1-after\n// f2-before\nconsole.log("surprise!");\n// f2-after'
}

(for my use case, I am not too particular about the ordering. but I do care that they are all present)

Actual result
even when comments: 'all' is specified, the f1-after comment is missing

{
  code: '// f1-before\n// f2-before\nconsole.log("surprise!");\n// f2-after'
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions