Skip to content

codegen: preserve coverage comments inside TemplateLiteral expression interpolations #22049

Description

@simleb

Companion to #21301, #21302, #20549. Coverage pragmas placed inside a TemplateLiteral expression (${ /* … */ expr }) are dropped by codegen even when the expression itself is preserved. Common in styled-components / CSS-in-JS code where each interpolation is a function and the developer wants to ignore branches inside it.

Input

const HeaderTitle = styled(Text)`
  color: ${
    /* v8 ignore next -- @preserve */
    ({ theme }) => theme.header?.mobile?.textColor || theme.global?.colors?.text
  };
`

Expected output

const HeaderTitle = styled(Text)`
  color: ${
    /* v8 ignore next -- @preserve */
    ({ theme }) => theme.header?.mobile?.textColor || theme.global?.colors?.text
  };
`

Actual output

const HeaderTitle = styled(Text)`
  color: ${({ theme }) => theme.header?.mobile?.textColor || theme.global?.colors?.text};
`

The pragma is silently dropped.

Reproduction

import { transformSync } from 'rolldown/experimental'

const code = `const x = styled\`color: \${
  /* v8 ignore next -- @preserve */ ({ theme }) => theme.color || 'black'
};\``

const r = transformSync('x.ts', code, { sourcemap: false, lang: 'ts' })
console.log(r.code.includes('v8 ignore'))   // false (expected: true)

Reproduces with rolldown 1.0.0-rc.17 / oxc 0.127.0.

Metadata

Metadata

Assignees

Labels

A-codegenArea - Code Generation

Type

Fields

Priority

None yet

Effort

None yet

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions