isFlowFileAnnotation.js.flow 529 B

1234567891011121314151617
  1. import _ from 'lodash';
  2. const FLOW_MATCHER = /^@(?:no)?flow$/u;
  3. export default (comment, strict) => (
  4. // The flow parser splits comments with the following regex to look for the @flow flag.
  5. // See https://github.com/facebook/flow/blob/a96249b93541f2f7bfebd8d62085bf7a75de02f2/src/parsing/docblock.ml#L39
  6. _.some(comment.split(/[\t\n\r */\\]+/u), (commentPart) => {
  7. const match = commentPart.match(FLOW_MATCHER);
  8. if (match === null) {
  9. return false;
  10. }
  11. return !strict || match[0] === '@flow';
  12. })
  13. );