How to use the extract-react-types.extractReactTypes function in extract-react-types

To help you get started, we’ve selected a few extract-react-types examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mitchellhamilton / magical-types / packages / pretty / src / pretty-proptypes / Props / Props.tst.js View on Github external
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);
});
github mitchellhamilton / magical-types / packages / pretty / src / pretty-proptypes / Props / Props.tst.js View on Github external
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');
});
github atlassian / extract-react-types / packages / generate-react-types / src / index.js View on Github external
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;
};
github atlassian / extract-react-types / packages / extract-react-types-loader / index.js View on Github external
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)}`;
};
github mitchellhamilton / magical-types / packages / pretty / src / pretty-proptypes / PrettyConvert / converters.tst.js View on Github external
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;
};

extract-react-types

Parse prop-types from react components using typescript or flow

MIT
Latest version published 2 years ago

Package Health Score

64 / 100
Full package analysis