Skip to content

Commit 0c99955

Browse files
panagosg7facebook-github-bot
authored andcommitted
[flow] add "decl_kind" field in Name_def.Value
Summary: We will use this to determine if this value corresponds to a const-variable. Changelog: [internal] Reviewed By: SamChou19815 Differential Revision: D70763512 fbshipit-source-id: 565c2f17318f8946d2a85d17ad79729aaa697381
1 parent f7579ce commit 0c99955

File tree

4 files changed

+13
-12
lines changed

4 files changed

+13
-12
lines changed

src/analysis/env_builder/name_def.ml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,10 +1061,10 @@ class def_finder ~autocomplete_hooks ~react_jsx env_info toplevel_scope =
10611061
let this_write_locs = obj_this_write_locs obj in
10621062
begin
10631063
match obj_properties_synthesizable ~this_write_locs obj with
1064-
| Unsynthesizable -> Some (Value { hints = []; expr = init })
1064+
| Unsynthesizable -> Some (Value { hints = []; expr = init; decl_kind = None })
10651065
| synthesizable -> Some (ObjectValue { obj_loc = loc; obj; synthesizable })
10661066
end
1067-
| (Some init, _) -> Some (Value { hints = []; expr = init })
1067+
| (Some init, _) -> Some (Value { hints = []; expr = init; decl_kind = Some kind })
10681068
| (None, _) -> None
10691069
in
10701070
let (source, hints) =
@@ -2051,11 +2051,11 @@ class def_finder ~autocomplete_hooks ~react_jsx env_info toplevel_scope =
20512051
this#visit_expression ~hints:(expression_pattern_hints e) ~cond:NonConditionalContext right
20522052
| (None, Ast.Pattern.Expression e) ->
20532053
let (_ : (_, _) Ast.Pattern.t) = this#assignment_pattern (lhs_loc, lhs_node) in
2054-
this#add_destructure_bindings (Value { hints = []; expr = right }) left;
2054+
this#add_destructure_bindings (Value { hints = []; expr = right; decl_kind = None }) left;
20552055
this#visit_expression ~hints:(expression_pattern_hints e) ~cond:NonConditionalContext right
20562056
| (None, _) ->
20572057
let (_ : (_, _) Ast.Pattern.t) = this#assignment_pattern (lhs_loc, lhs_node) in
2058-
this#add_destructure_bindings (Value { hints = []; expr = right }) left;
2058+
this#add_destructure_bindings (Value { hints = []; expr = right; decl_kind = None }) left;
20592059
this#visit_expression ~hints:(other_pattern_hints left) ~cond:NonConditionalContext right
20602060
| ( Some operator,
20612061
Ast.Pattern.Identifier
@@ -3203,7 +3203,7 @@ class def_finder ~autocomplete_hooks ~react_jsx env_info toplevel_scope =
32033203
this#add_ordinary_binding
32043204
match_keyword_loc
32053205
(mk_reason RMatch match_keyword_loc)
3206-
(Binding (Root (Value { hints = []; expr = arg })));
3206+
(Binding (Root (Value { hints = []; expr = arg; decl_kind = None })));
32073207
let value_hints =
32083208
Base.List.foldi cases ~init:IMap.empty ~f:(fun i acc (_, { Case.body; _ }) ->
32093209
if expression_is_definitely_synthesizable ~autocomplete_hooks body then
@@ -3218,7 +3218,7 @@ class def_finder ~autocomplete_hooks ~react_jsx env_info toplevel_scope =
32183218
(case_loc, Ast.Expression.Identifier (Flow_ast_utils.match_root_ident case_loc))
32193219
in
32203220
ignore @@ this#expression match_root;
3221-
let acc = Value { hints = []; expr = match_root } in
3221+
let acc = Value { hints = []; expr = match_root; decl_kind = None } in
32223222
this#add_match_destructure_bindings acc pattern;
32233223
ignore @@ super#match_pattern pattern;
32243224
run_opt this#expression guard;
@@ -3235,13 +3235,13 @@ class def_finder ~autocomplete_hooks ~react_jsx env_info toplevel_scope =
32353235
this#add_ordinary_binding
32363236
match_keyword_loc
32373237
(mk_reason RMatch match_keyword_loc)
3238-
(Binding (Root (Value { hints = []; expr = arg })));
3238+
(Binding (Root (Value { hints = []; expr = arg; decl_kind = None })));
32393239
Base.List.iter cases ~f:(fun (case_loc, { Case.pattern; body; guard; comments = _ }) ->
32403240
let match_root =
32413241
(case_loc, Ast.Expression.Identifier (Flow_ast_utils.match_root_ident case_loc))
32423242
in
32433243
ignore @@ this#expression match_root;
3244-
let acc = Value { hints = []; expr = match_root } in
3244+
let acc = Value { hints = []; expr = match_root; decl_kind = None } in
32453245
this#add_match_destructure_bindings acc pattern;
32463246
ignore @@ super#match_pattern pattern;
32473247
run_opt this#expression guard;

src/analysis/env_builder/name_def_ordering.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -962,7 +962,7 @@ struct
962962
in
963963
let depends_of_root state = function
964964
| Annotation { annot; tparams_map; _ } -> depends_of_annotation tparams_map annot state
965-
| Value { hints; expr } ->
965+
| Value { hints; expr; decl_kind = _ } ->
966966
let state = depends_of_hints state hints in
967967
depends_of_expression expr state
968968
| ObjectValue { obj; synthesizable = ObjectSynthesizable _; _ } ->

src/analysis/env_builder/name_def_types.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ type dro_annot =
8888
type value = {
8989
hints: ast_hints;
9090
expr: (ALoc.t, ALoc.t) Ast.Expression.t;
91+
decl_kind: Ast.Variable.kind option;
9192
}
9293

9394
type root =

src/typing/env_resolution.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@ let try_cache : 'l. check:(unit -> 'l) -> cache:('l -> unit) -> Context.t -> 'l
4545
cache e;
4646
e
4747

48-
let expression cx ?cond exp =
48+
let expression cx ?cond ?decl exp =
4949
let cache = Context.node_cache cx in
5050
let ((_, t), _) =
5151
try_cache
5252
cx
53-
~check:(fun () -> Statement.expression ?cond cx exp)
53+
~check:(fun () -> Statement.expression ?cond ?decl cx exp)
5454
~cache:(Node_cache.set_expression cache)
5555
in
5656
t
@@ -466,7 +466,7 @@ let rec resolve_binding cx reason loc b =
466466
TypeUtil.optional t
467467
else
468468
t
469-
| Root (Value { hints = _; expr }) -> expression cx expr
469+
| Root (Value { hints = _; expr; decl_kind }) -> expression cx ?decl:decl_kind expr
470470
| Root (ObjectValue { obj_loc = loc; obj; synthesizable = ObjectSynthesizable _ }) ->
471471
let open Ast.Expression.Object in
472472
let resolve_prop ~bind_this ~prop_loc ~fn_loc fn =

0 commit comments

Comments
 (0)