diff --git a/tools/hermes-parser/js/babel-plugin-syntax-hermes-parser/__tests__/babel-plugin-syntax-hermes-parser-test.js b/tools/hermes-parser/js/babel-plugin-syntax-hermes-parser/__tests__/babel-plugin-syntax-hermes-parser-test.js index a03108c2b20..3bcf530c55c 100644 --- a/tools/hermes-parser/js/babel-plugin-syntax-hermes-parser/__tests__/babel-plugin-syntax-hermes-parser-test.js +++ b/tools/hermes-parser/js/babel-plugin-syntax-hermes-parser/__tests__/babel-plugin-syntax-hermes-parser-test.js @@ -16,7 +16,7 @@ import {transformSync} from '@babel/core'; import hermesParserPlugin from '../src'; import * as HermesParser from 'hermes-parser'; -const MODULE_PREAMBLE = '"use strict";\n\n'; +const MODULE_PREAMBLE = '// @flow\n\n"use strict";\n\n'; describe('babel-plugin-syntax-hermes-parser', () => { test('test basic parsing', () => { diff --git a/tools/hermes-parser/js/babel-plugin-syntax-hermes-parser/src/index.js b/tools/hermes-parser/js/babel-plugin-syntax-hermes-parser/src/index.js index a04237fb031..ac4730cfd13 100644 --- a/tools/hermes-parser/js/babel-plugin-syntax-hermes-parser/src/index.js +++ b/tools/hermes-parser/js/babel-plugin-syntax-hermes-parser/src/index.js @@ -37,8 +37,9 @@ export default function BabelPluginSyntaxHermesParser( parserOverride(code: string) { const filename = curFilename; if ( - filename != null && - (filename.endsWith('.ts') || filename.endsWith('.tsx')) + !/@flow/.test(code) || + (filename != null && + (filename.endsWith('.ts') || filename.endsWith('.tsx'))) ) { return; }