DevTools named hooks: Support FLow syntax (#21815)

Detect Flow pragma (@flow) and use Flow plug-in instead of TypeScript (default)
This commit is contained in:
Brian Vaughn
2021-07-07 14:29:41 -04:00
committed by GitHub
parent 91e90d06a1
commit 359bd67ea2
+6 -1
View File
@@ -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__) {