Skip to content

Commit

Permalink
[flow][refactor] Pull out string_of_variable_kind function for re-use
Browse files Browse the repository at this point in the history
Summary:
Pull out `string_of_variable_kind` function for re-use.

Changelog: [internal]

Reviewed By: SamChou19815

Differential Revision:
D67502320

------------------------------------------------------------------------
(from d93582fdb364287bf1bfcf6bcd8b915285ffb6db)

fbshipit-source-id: f5a07275123ef62f13e17804ac188d4e702fc0e7
  • Loading branch information
gkz authored and facebook-github-bot committed Dec 20, 2024
1 parent b4faf47 commit 9138251
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 13 deletions.
11 changes: 3 additions & 8 deletions src/parser/estree_translator.ml
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,7 @@ with type t = Impl.t = struct
let (loc, _) = id in
node "MatchIdentifierPattern" loc [("id", identifier id)]
and match_binding_pattern (loc, { MatchPattern.BindingPattern.kind; id; comments }) =
let kind = variable_kind kind in
let kind = Flow_ast_utils.string_of_variable_kind kind in
node ?comments "MatchBindingPattern" loc [("id", identifier id); ("kind", string kind)]
and match_rest_pattern (loc, { MatchPattern.RestPattern.argument; comments }) =
node ?comments "MatchRestPattern" loc [("argument", option match_binding_pattern argument)]
Expand Down Expand Up @@ -915,7 +915,7 @@ with type t = Impl.t = struct
[("body", statement_list body)]
and declare_variable (loc, { Statement.DeclareVariable.id; annot; kind; comments }) =
let id_loc = Loc.btwn (fst id) (fst annot) in
let kind = variable_kind kind in
let kind = Flow_ast_utils.string_of_variable_kind kind in
node
?comments
"DeclareVariable"
Expand Down Expand Up @@ -1687,13 +1687,8 @@ with type t = Impl.t = struct
"TaggedTemplateExpression"
loc
[("tag", expression tag); ("quasi", template_literal quasi)]
and variable_kind kind =
match kind with
| Variable.Var -> "var"
| Variable.Let -> "let"
| Variable.Const -> "const"
and variable_declaration (loc, { Statement.VariableDeclaration.kind; declarations; comments }) =
let kind = variable_kind kind in
let kind = Flow_ast_utils.string_of_variable_kind kind in
node
?comments
"VariableDeclaration"
Expand Down
5 changes: 5 additions & 0 deletions src/parser/flow_ast_utils.ml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ let rec match_pattern_has_binding =
| (_, OrPattern { OrPattern.patterns; _ }) -> List.exists match_pattern_has_binding patterns
| (_, AsPattern _) -> true

let string_of_variable_kind = function
| Variable.Var -> "var"
| Variable.Let -> "let"
| Variable.Const -> "const"

let partition_directives statements =
let open Statement in
let rec helper directives = function
Expand Down
2 changes: 2 additions & 0 deletions src/parser/flow_ast_utils.mli
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ val pattern_has_binding : ('m, 't) Flow_ast.Pattern.t -> bool

val match_pattern_has_binding : ('m, 't) Flow_ast.MatchPattern.t -> bool

val string_of_variable_kind : Flow_ast.Variable.kind -> string

val partition_directives :
(Loc.t, Loc.t) Flow_ast.Statement.t list ->
(Loc.t, Loc.t) Flow_ast.Statement.t list * (Loc.t, Loc.t) Flow_ast.Statement.t list
Expand Down
6 changes: 1 addition & 5 deletions src/parser_utils/output/js_layout_generator.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1735,11 +1735,7 @@ and template_literal ~opts { Ast.Expression.TemplateLiteral.quasis; expressions;
in
fuse [Atom "`"; fuse (List.mapi template_element quasis); Atom "`"]

and variable_kind kind =
match kind with
| Ast.Variable.Var -> Atom "var"
| Ast.Variable.Let -> Atom "let"
| Ast.Variable.Const -> Atom "const"
and variable_kind kind = Atom (Flow_ast_utils.string_of_variable_kind kind)

and variable_declaration
?(ctxt = normal_context)
Expand Down

0 comments on commit 9138251

Please sign in to comment.