Skip to content

Use hermes parser for flow#225

Merged
prabhu merged 3 commits intomainfrom
feature/hermes-parser
Dec 15, 2025
Merged

Use hermes parser for flow#225
prabhu merged 3 commits intomainfrom
feature/hermes-parser

Conversation

@prabhu
Copy link
Contributor

@prabhu prabhu commented Dec 15, 2025

Better flow support with hermes-parser.

Signed-off-by: Prabhu Subramanian <prabhu@appthreat.com>
Signed-off-by: Prabhu Subramanian <prabhu@appthreat.com>
Signed-off-by: Prabhu Subramanian <prabhu@appthreat.com>
if x <= 0 then failure("`max-num-def` must be an integer larger than 0")
else success
)
arg[String]("input")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Improved command line parsing when both full form and aliases are used. For example, before this change you cannot run atom with full arguments at the end as shown below.

Won't work.

atom -o ... --language java

Would work.

atom --language java -o ... 

.withInputPath(config.inputPath.pathAsString)
.withOutputPath(outputAtomFile)
.withFlow(config.language.equalsIgnoreCase("FLOW"))
val finalConfig = sys.env.get("CHEN_ASTGEN_OUT") match
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Support for new environment variable CHEN_ASTGEN_OUT to reuse an existing astgen output directory.

projectType === "flow" ? babelFlowParserOptions : babelParserOptions;
const codeToJsAst = (file, code, projectType) => {
const isJs = /\.(js|jsx|cjs|mjs)$/.test(file);
if (isJs && projectType === "flow") {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even when the user specifies flow, we can use hermes only for certain file types.

try {
return parse(code, optionsToUse);
} catch {
return parse(code, primaryBabelOptions);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How many parsers do you need to support javascript? The true answer could be infinity, but currently we use three parsers.

/**
* Convert a single EJS file to AST.
*/
const toEjsAst = (file) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic was ported from chen's EjsPreprocessor. Why? So that we can cache and reuse astgen output 💡

const typeObj = typeChecker.getTypeAtLocation(node);
let typeObj = typeChecker.getTypeAtLocation(node);
if (
typeObj.isLiteral() ||
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For string literals and booleans, we need to widen the type name.

const projectFiles = srcFiles.filter(
(file) => !file.includes("node_modules")
);
const projectFiles = !shouldIncludeNodeModulesBundles
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can create types for even dependencies inside node_modules. It will increase the time and memory quite a lot, but worth it.

@prabhu prabhu merged commit 299c497 into main Dec 15, 2025
44 checks passed
@prabhu prabhu deleted the feature/hermes-parser branch December 15, 2025 22:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant