UNPKG

babel-plugin-remove-nonjs

Version:

Babel plugin to remove dependencies of non JS files such as CSS and images

27 lines (24 loc) 890 B
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var _path = require('path'); exports.default = ({ types: t }) => { return { visitor: { CallExpression(path) { if (!t.isIdentifier(path.node.callee, { name: "require" })) return; const arg = path.node.arguments[0].value; const ext = (0, _path.extname)(arg).toLowerCase(); if (!ext || ext === '.js') return; // TODO: Replace with a commented out node instead. if (path.parentPath.type === 'VariableDeclarator') { console.warn(`babel-plugin-remove-nonjs does not assume variable assignment from "require("${ arg }")". Your program has been possibly broken since the variable "${ path.parentPath.node.id.name }" was erased by us.`); path.parentPath.remove(); } else { path.remove(); } } } }; };