Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import * as parser from 'svg-parser';
// $ExpectType RootNode
parser.parse('<svg></svg>');
export function SvgFromXml({ xml, ...props }) {
try {
const hast = parse(xml.replace(/xlink:href/g, 'href'));
return ;
} catch (e) {
console.log(e);
return null;
}
}
export default function jsxPlugin(code, config, state) {
const filePath = state.filePath || 'unknown'
const hastTree = parse(code)
const babelTree = hastToBabelAst(hastTree)
const { code: generatedCode } = transformFromAstSync(babelTree, code, {
caller: {
name: 'svgr',
},
presets: [
createConfigItem([svgrBabelPreset, { ...config, state }], {
type: 'preset',
}),
],
filename: filePath,
babelrc: false,
configFile: false,
code: true,
constructor ( source ) {
this.source = parseSvg( source );
this.target = {
name: this.source.name,
attributes: Object.assign( {}, this.source.attributes ),
children: []
};
walk( this.source, this.target.children, [], {}, {} );
}