babel-plugin-transform-line
Version:
Replaces the identifier __line with the source line number
24 lines (20 loc) • 609 B
JavaScript
;
module.exports = ({
types
}) => {
const void0Expression = types.unaryExpression('void', types.numericLiteral(0), true);
return {
visitor: {
ReferencedIdentifier (path) {
if (path.node.name === '__line') {
const location = path.node.loc;
path.replaceWith(
location && location.start.line ?
types.numericLiteral(location.start.line) :
void0Expression
);
}
}
}
};
};