Skip to content

Commit

Permalink
Adds a simple AST printer
Browse files Browse the repository at this point in the history
  • Loading branch information
ManasJayanth committed Aug 18, 2024
1 parent 57aeae2 commit d587f50
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/bin/dune
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(executable
(public_name js_bundler)
(name main)
(libraries js_bundler flow_parser))
(libraries JSBundler flow_parser))
32 changes: 19 additions & 13 deletions src/bin/main.re
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@


let parse_source = source => {
let parse = source => {
let parse_options =
Some(
Flow_parser.Parser_env.{
esproposal_nullish_coalescing: false,
esproposal_optional_chaining: false,
esproposal_class_instance_fields: true,
esproposal_class_static_fields: true,
esproposal_decorators: true,
esproposal_export_star_as: true,
types: true,
types_in_comments: false,
Parser_env.{
components: false,
enums: false,
esproposal_decorators: false,
types: false,
use_strict: false,
module_ref_prefix: None,
module_ref_prefix_LEGACY_INTEROP: None,
},
);
Parser_flow.program(source, ~parse_options);
};

Flow_parser.Parser_flow.program(source, ~parse_options);
let source = {|
console.log("Hello, World.");
|};

let print = ast => {
Flow_ast.(Program.show(Loc.pp, Loc.pp, ast));
};

let (ast, _errors) = parse(source);
ast |> print |> print_endline;
1 change: 1 addition & 0 deletions src/lib/JSBundler.re
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
let hello = "hello"
2 changes: 1 addition & 1 deletion src/lib/dune
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
(library
(name js_bundler))
(name JSBundler))

0 comments on commit d587f50

Please sign in to comment.