This repository has been archived on 2026-03-31. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
react-iconpack/lib/BabelSVGTracker.js

30 lines
1 KiB
JavaScript

/**
* A Babel "plugin/transformer" that just tracks unique <Icon.../>
* JSX tags in your source code. Note that this does absolutely no
* modifications - just accumulates the unique SVG uris for the mapping.
*
* @param {Object} babel This will be auto-passed, most likely, by Babel.
* @returns {Object} babel.Transformer used for the babel'ing. You know the one.
*/
module.exports = function(babel) {
var _packer = this;
return {
visitor: {
JSXElement: function JSXElement(node, parent, scope, file) {
if(_packer.opts.JSXTagNames.indexOf(node.node.openingElement.name.name) < 0)
return;
var attributes = node.node.openingElement.attributes,
l = attributes.length,
i = 0;
for(; i < l; i++) {
if(attributes[i].name.name !== 'uri')
continue;
_packer.SVGS[attributes[i].value.value] = 1;
}
}
}
};
};