Skip to content

Commit d09c6f1

Browse files
Brian Vaughnzhengjitf
authored andcommitted
DevTools named hooks: Support FLow syntax (facebook#21815)
Detect Flow pragma (@flow) and use Flow plug-in instead of TypeScript (default)
1 parent 482da12 commit d09c6f1

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

packages/react-devtools-extensions/src/parseHookNames.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -542,10 +542,15 @@ async function parseSourceAST(
542542
hookSourceData.originalSourceAST = sourceMetadata.originalSourceAST;
543543
hookSourceData.originalSourceCode = sourceMetadata.originalSourceCode;
544544
} else {
545+
// TypeScript is the most commonly used typed JS variant so let's default to it
546+
// unless we detect explicit Flow usage via the "@flow" pragma.
547+
const plugin =
548+
originalSourceCode.indexOf('@flow') > 0 ? 'flow' : 'typescript';
549+
545550
// TODO (named hooks) Parsing should ideally be done off of the main thread.
546551
const originalSourceAST = parse(originalSourceCode, {
547552
sourceType: 'unambiguous',
548-
plugins: ['jsx', 'typescript'],
553+
plugins: ['jsx', plugin],
549554
});
550555
hookSourceData.originalSourceAST = originalSourceAST;
551556
if (__DEBUG__) {

0 commit comments

Comments
 (0)