Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the purpose of these comments in Babel output?

Tags:

javascript

Babel transpilation output follows. What is the purpose of generated comments like /*#__PURE__*/?

function foo() {
    return (<div>
        <p></p>
        <p></p>
    </div>)
}

transpiles to:

"use strict";

function foo() {
  return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("p", null), /*#__PURE__*/React.createElement("p", null));
}
like image 245
Ben Aston Avatar asked Mar 02 '23 10:03

Ben Aston


1 Answers

This was introduced in Babel 7:

...transpiled ES6 classes are annotated with a /*#__PURE__*/ comment that allows gives a hint to minifiers like Uglify and babel-minify for dead code elimination. These annotations are added to other helper functions as well.

like image 135
jonrsharpe Avatar answered Mar 05 '23 18:03

jonrsharpe