Skip to content

Commit

Permalink
DevTools named hooks: Support FLow syntax (facebook#21815)
Browse files Browse the repository at this point in the history
Detect Flow pragma (@flow) and use Flow plug-in instead of TypeScript (default)
  • Loading branch information
Brian Vaughn authored and zhengjitf committed Apr 15, 2022
1 parent 482da12 commit d09c6f1
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion packages/react-devtools-extensions/src/parseHookNames.js
Original file line number Diff line number Diff line change
Expand Up @@ -542,10 +542,15 @@ async function parseSourceAST(
hookSourceData.originalSourceAST = sourceMetadata.originalSourceAST;
hookSourceData.originalSourceCode = sourceMetadata.originalSourceCode;
} else {
// TypeScript is the most commonly used typed JS variant so let's default to it
// unless we detect explicit Flow usage via the "@flow" pragma.
const plugin =
originalSourceCode.indexOf('@flow') > 0 ? 'flow' : 'typescript';

// TODO (named hooks) Parsing should ideally be done off of the main thread.
const originalSourceAST = parse(originalSourceCode, {
sourceType: 'unambiguous',
plugins: ['jsx', 'typescript'],
plugins: ['jsx', plugin],
});
hookSourceData.originalSourceAST = originalSourceAST;
if (__DEBUG__) {
Expand Down

0 comments on commit d09c6f1

Please sign in to comment.