Files
old-slucajna-televizija/web/node_modules/jsx-ast-utils/__tests__/helper.js
2017-10-16 11:19:46 +02:00

20 lines
427 B
JavaScript

import getProp from '../src/getProp';
const acorn = require('acorn-jsx');
function parse(code) {
return acorn.parse(code, {
plugins: { jsx: true },
});
}
export function getOpeningElement(code) {
return parse(code).body[0].expression.openingElement;
}
export function extractProp(code, prop = 'foo') {
const node = getOpeningElement(code);
const { attributes: props } = node;
return getProp(props, prop);
}