@samitouri / QOS-React-2 / commits / b6258b05f4

DevTools named hooks: Support FLow syntax (#21815)

Detect Flow pragma (@flow) and use Flow plug-in instead of TypeScript (default)

Brian Vaughn committed Jul 7, 2021 at 14:29 UTC b6258b05f4ea16776557bc370ee0892604504d8f
1 file changed +6 -1
packages/react-devtools-extensions/src/parseHookNames.js
+6 -1
@@ -542,10 +542,15 @@ async function parseSourceAST(
542 hookSourceData.originalSourceAST = sourceMetadata.originalSourceAST;
543 hookSourceData.originalSourceCode = sourceMetadata.originalSourceCode;
544 } 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 +
550 // TODO (named hooks) Parsing should ideally be done off of the main thread.
551 const originalSourceAST = parse(originalSourceCode, {
552 sourceType: 'unambiguous',
548 - plugins: ['jsx', 'typescript'],
553 + plugins: ['jsx', plugin],
554 });
555 hookSourceData.originalSourceAST = originalSourceAST;
556 if (__DEBUG__) {