UNPKG

427 BJavaScriptView Raw
1import getProp from '../src/getProp';
2
3const acorn = require('acorn-jsx');
4
5function parse(code) {
6 return acorn.parse(code, {
7 plugins: { jsx: true },
8 });
9}
10
11export function getOpeningElement(code) {
12 return parse(code).body[0].expression.openingElement;
13}
14
15export function extractProp(code, prop = 'foo') {
16 const node = getOpeningElement(code);
17 const { attributes: props } = node;
18 return getProp(props, prop);
19}