How to use the recast/lib/parser.parse function in recast

To help you get started, we’ve selected a few recast 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 material-components / material-components-web / scripts / lint-mdc.ts View on Github external
function getAstFromCodeString(inputCode: string): babelTypes.Node {
  // DO NOT INLINE this variable. It provides stronger typing than recast's type declarations..
  const customParser: RecastCustomParser = {
    parse: (code) => babelParser.parse(code, {
      sourceType: 'module',
      plugins: ['typescript', 'classProperties'],
    }),
  };
  return recastParser.parse(inputCode, {parser: customParser});
}