Skip to content

Commit 9e5410a

Browse files
panagosg7facebook-github-bot
authored andcommitted
[flow] tidy up syntactic flags in statement.ml
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
1 parent b7a02fa commit 9e5410a

File tree

7 files changed

+138
-59
lines changed

7 files changed

+138
-59
lines changed

src/services/autocomplete/autocomplete_js.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ module Inference = struct
162162
let type_of_match_member_pattern cx loc mem =
163163
Match_pattern.type_of_member_pattern
164164
cx
165-
~on_identifier:Statement.identifier
165+
~on_identifier:(Statement.identifier ~cond:None)
166166
~on_expression:Statement.expression
167167
(loc, mem)
168168
end
@@ -966,7 +966,7 @@ class process_request_searcher cx ~from_trigger_character ~cursor =
966966
let member_loc = Some (compute_member_loc ~expr_loc:loc ~obj_loc:base_loc) in
967967
let obj_type () =
968968
match base with
969-
| BaseIdentifier (loc, id) -> Inference.type_of_identifier cx loc id
969+
| BaseIdentifier (loc, id) -> Inference.type_of_identifier ~cond:None cx loc id
970970
| BaseMember (loc, mem) -> Inference.type_of_match_member_pattern cx loc mem
971971
in
972972
(match property with

src/typing/env_resolution.ml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,12 @@ let resolve_annotation cx tparams_map ?(react_deep_read_only = None) anno =
105105
let rec synthesizable_expression cx ?cond exp =
106106
let open Ast.Expression in
107107
match exp with
108-
| (loc, Identifier (_, name)) -> Statement.identifier cx name loc
109-
| (loc, StringLiteral lit) -> Statement.string_literal cx ~singleton:false loc lit
110-
| (loc, BooleanLiteral lit) -> Statement.boolean_literal ~singleton:false loc lit
108+
| (loc, Identifier (_, name)) -> Statement.identifier cx ~cond name loc
109+
| (loc, StringLiteral lit) -> Statement.string_literal cx ~cond loc lit
110+
| (loc, BooleanLiteral lit) -> Statement.boolean_literal cx ~cond loc lit
111111
| (loc, NullLiteral _) -> Statement.null_literal loc
112-
| (loc, NumberLiteral lit) -> Statement.number_literal ~singleton:false loc lit
113-
| (loc, BigIntLiteral lit) -> Statement.bigint_literal ~singleton:false loc lit
112+
| (loc, NumberLiteral lit) -> Statement.number_literal cx ~cond loc lit
113+
| (loc, BigIntLiteral lit) -> Statement.bigint_literal cx ~cond loc lit
114114
| (loc, RegExpLiteral _) -> Statement.regexp_literal cx loc
115115
| (loc, ModuleRefLiteral lit) ->
116116
let (t, _lit) = Statement.module_ref_literal cx loc lit in

src/typing/primitive_literal.ml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
(*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*)
7+
8+
module Ast = Flow_ast
9+
10+
type syntactic_flags = {
11+
cond: Type.cond_context option;
12+
decl: Ast.Variable.kind option;
13+
as_const: bool;
14+
frozen: Type.frozen_kind;
15+
}
16+
17+
let empty_syntactic_flags = { cond = None; decl = None; as_const = false; frozen = Type.NotFrozen }
18+
19+
let mk_syntactic_flags ?cond ?decl ?(as_const = false) ?(frozen = Type.NotFrozen) () =
20+
{ cond; decl; as_const; frozen }

src/typing/primitive_literal.mli

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
(*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*)
7+
8+
module Ast = Flow_ast
9+
10+
type syntactic_flags = {
11+
cond: Type.cond_context option;
12+
decl: Ast.Variable.kind option;
13+
as_const: bool;
14+
frozen: Type.frozen_kind;
15+
}
16+
17+
val empty_syntactic_flags : syntactic_flags
18+
19+
val mk_syntactic_flags :
20+
?cond:Type.cond_context ->
21+
?decl:Ast.Variable.kind ->
22+
?as_const:bool ->
23+
?frozen:Type.frozen_kind ->
24+
unit ->
25+
syntactic_flags

0 commit comments

Comments
 (0)