Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
test('simple facts about two props', () => {
const file2 = `
const MyComponent = (props: { simpleProp: string, secondProp?: number }) => null;
export default MyComponent;
`;
const wrapper = mount(
);
const prop = wrapper.find('Prop');
expect(prop.length).toBe(2);
});
test('should visualise props from extract-types-loader', () => {
const wrapper = mount(
);
const prop = wrapper.find('Prop');
expect(prop.length).toBe(1);
expect(prop.prop('name')).toBe('simpleProp');
expect(prop.prop('required')).toBe(true);
expect(prop.prop('type')).toBe('string');
});
export default (content, typeSystem, filename) => {
const resolveOpts = {
pathFilter: (pkg, location, dist) => {
if (pkg['atlaskit:src'] && location.includes('node_modules') && location.includes(pkg.main)) {
return location.replace(dist, pkg['atlaskit:src']);
}
return null;
}
};
const ertAst = extractReactTypes(content, target[typeSystem], filename, resolveOpts);
if (typeSystem === 'typescript') {
return convertToTs(ertAst);
}
return ertAst;
};
pathFilter: (pkg, location, dist) => {
if (
!pkg.types &&
pkg['atlaskit:src'] &&
location.includes('node_modules') &&
location.includes(pkg.main)
) {
return location.replace(dist, pkg['atlaskit:src']);
}
return null;
},
/*This is here for instances where there are paths which are not packages */
moduleDirectory: ['node_modules', 'src']
};
const types = extractReactTypes(content, typeSystem, filename, resolveOpts);
return `module.exports = ${JSON.stringify(types)}`;
};
const assembleERTAST = (propTypes, defaultProps, type = 'flow') => {
let file = `
class Component extends React.Component<${propTypes}> {
defaultProps = ${defaultProps}
}`;
let res = extractReactTypes(file, type);
return res.component.members;
};