mirror of
https://github.com/hanzoai/react.git
synced 2026-09-24 17:02:27 +00:00
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:
@@ -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__) {
|
||||
|
||||
Reference in New Issue
Block a user