Skip to content

Commit

Permalink
DevTools named hooks: Support FLow syntax
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 committed Jul 7, 2021
1 parent 9c7f29e commit 7d0292e
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 @@ -560,10 +560,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 7d0292e

Please sign in to comment.