Skip to content

Commit

Permalink
[flow] tidy up syntactic flags in statement.ml
Browse files Browse the repository at this point in the history
Summary:
Groups together flags that capture properties of the syntactic context of an expression.

Changelog: [internal]

Reviewed By: SamChou19815

Differential Revision: D70676104

fbshipit-source-id: 4476f1849723ad9f5fd76a1872ff45c7fe85e3db
  • Loading branch information
panagosg7 authored and facebook-github-bot committed Mar 6, 2025
1 parent b7a02fa commit 9e5410a
Show file tree
Hide file tree
Showing 7 changed files with 138 additions and 59 deletions.
4 changes: 2 additions & 2 deletions src/services/autocomplete/autocomplete_js.ml
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ module Inference = struct
let type_of_match_member_pattern cx loc mem =
Match_pattern.type_of_member_pattern
cx
~on_identifier:Statement.identifier
~on_identifier:(Statement.identifier ~cond:None)
~on_expression:Statement.expression
(loc, mem)
end
Expand Down Expand Up @@ -966,7 +966,7 @@ class process_request_searcher cx ~from_trigger_character ~cursor =
let member_loc = Some (compute_member_loc ~expr_loc:loc ~obj_loc:base_loc) in
let obj_type () =
match base with
| BaseIdentifier (loc, id) -> Inference.type_of_identifier cx loc id
| BaseIdentifier (loc, id) -> Inference.type_of_identifier ~cond:None cx loc id
| BaseMember (loc, mem) -> Inference.type_of_match_member_pattern cx loc mem
in
(match property with
Expand Down
10 changes: 5 additions & 5 deletions src/typing/env_resolution.ml
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,12 @@ let resolve_annotation cx tparams_map ?(react_deep_read_only = None) anno =
let rec synthesizable_expression cx ?cond exp =
let open Ast.Expression in
match exp with
| (loc, Identifier (_, name)) -> Statement.identifier cx name loc
| (loc, StringLiteral lit) -> Statement.string_literal cx ~singleton:false loc lit
| (loc, BooleanLiteral lit) -> Statement.boolean_literal ~singleton:false loc lit
| (loc, Identifier (_, name)) -> Statement.identifier cx ~cond name loc
| (loc, StringLiteral lit) -> Statement.string_literal cx ~cond loc lit
| (loc, BooleanLiteral lit) -> Statement.boolean_literal cx ~cond loc lit
| (loc, NullLiteral _) -> Statement.null_literal loc
| (loc, NumberLiteral lit) -> Statement.number_literal ~singleton:false loc lit
| (loc, BigIntLiteral lit) -> Statement.bigint_literal ~singleton:false loc lit
| (loc, NumberLiteral lit) -> Statement.number_literal cx ~cond loc lit
| (loc, BigIntLiteral lit) -> Statement.bigint_literal cx ~cond loc lit
| (loc, RegExpLiteral _) -> Statement.regexp_literal cx loc
| (loc, ModuleRefLiteral lit) ->
let (t, _lit) = Statement.module_ref_literal cx loc lit in
Expand Down
20 changes: 20 additions & 0 deletions src/typing/primitive_literal.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
(*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*)

module Ast = Flow_ast

type syntactic_flags = {
cond: Type.cond_context option;
decl: Ast.Variable.kind option;
as_const: bool;
frozen: Type.frozen_kind;
}

let empty_syntactic_flags = { cond = None; decl = None; as_const = false; frozen = Type.NotFrozen }

let mk_syntactic_flags ?cond ?decl ?(as_const = false) ?(frozen = Type.NotFrozen) () =
{ cond; decl; as_const; frozen }
25 changes: 25 additions & 0 deletions src/typing/primitive_literal.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
(*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*)

module Ast = Flow_ast

type syntactic_flags = {
cond: Type.cond_context option;
decl: Ast.Variable.kind option;
as_const: bool;
frozen: Type.frozen_kind;
}

val empty_syntactic_flags : syntactic_flags

val mk_syntactic_flags :
?cond:Type.cond_context ->
?decl:Ast.Variable.kind ->
?as_const:bool ->
?frozen:Type.frozen_kind ->
unit ->
syntactic_flags
Loading

0 comments on commit 9e5410a

Please sign in to comment.