Skip to content

babel pure annotation output with leading comments not supported #5324

@twk3

Description

@twk3

Rollup Version

4.5.0

Operating System (or Browser)

REPL

Node Version (if applicable)

No response

Link To Reproduction

https://rollupjs.org/repl/?version=4.5.0&shareable=JTdCJTIyZXhhbXBsZSUyMiUzQSUyMiUyMiUyQyUyMm1vZHVsZXMlMjIlM0ElNUIlN0IlMjJjb2RlJTIyJTNBJTIyY29uc3QlMjBmb3VyJTIwJTNEJTIwJTJGKiUyMCUyM19fUFVSRV9fJTIwKiUyRiUyMCUyRiolMjBmb28lMjAqJTJGJTIwYWRkKDIlMkMlMjAyKSUzQiUyMiUyQyUyMmlzRW50cnklMjIlM0F0cnVlJTJDJTIybmFtZSUyMiUzQSUyMm1haW4uanMlMjIlN0QlNUQlMkMlMjJvcHRpb25zJTIyJTNBJTdCJTdEJTdE

Expected Behaviour

The PURE annotation is not stripped. Instead all comments are considered combined or whitespace. Matching behaviour of UglifyJS starting in v3.1.0 and properly handling the output from @babel/helper-annotate-as-pure as documented here: https://babeljs.io/docs/babel-helper-annotate-as-pure

Actual Behaviour

The following warning is thrown, and the PURE annotation is stripped.

Rollup completed with warnings:
A comment "/* #__PURE__ */" in "main.js" contains an annotation that Rollup cannot interpret due to the position of the comment. The comment will be removed to avoid issues. [(link)](https://rollupjs.org/configuration-options/#pure)
/main.js (1:13)
1: const four = /* #__PURE__ */ /* foo */ add(2, 2);

Libraries like https://github.com/FormidableLabs/victory are currently triggering these warnings and having their annotations stripped when included in rollup projects due to this issue.

../../node_modules/victory-core/es/victory-primitives/rect.js (16:2) A comment

"/*#__PURE__*/"

in "../../node_modules/victory-core/es/victory-primitives/rect.js" contains an annotation that Rollup cannot interpret due to the position of the comment. The comment will be removed to avoid issues.
../../node_modules/victory-core/es/victory-primitives/rect.js (21:2) A comment

"/*#__PURE__*/"

in "../../node_modules/victory-core/es/victory-primitives/rect.js" contains an annotation that Rollup cannot interpret due to the position of the comment. The comment will be removed to avoid issues.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions