fbredius/storybook

View on GitHub
lib/source-loader/src/abstract-syntax-tree/parsers/index.js

Summary

Maintainability
A
0 mins
Test Coverage
import jsParser from './parser-js';
import tsParser from './parser-ts';
import flowParser from './parser-flow';

function getParser(type) {
  if (type === 'javascript' || /\.jsx?/.test(type) || !type) {
    return jsParser;
  }

  if (type === 'typescript' || /\.tsx?/.test(type)) {
    return tsParser;
  }

  if (type === 'flow') {
    return flowParser;
  }

  throw new Error(`Parser of type "${type}" is not supported`);
}

export default getParser;