@@ -1339,23 +1339,7 @@ module Make
13391339 case
13401340 in
13411341 let pattern =
1342- Match_pattern. pattern
1343- cx
1344- ( case_match_root_loc,
1345- Flow_ast.Expression. Identifier
1346- (Flow_ast_utils. match_root_ident case_match_root_loc)
1347- )
1348- pattern
1349- ~on_identifier: (fun ~encl_ctx cx ->
1350- identifier cx { empty_syntactic_flags with Natural_inference. encl_ctx })
1351- ~on_expression: expression
1352- ~on_binding: (fun ~use_op ~name_loc ~kind name t ->
1353- init_var kind cx ~use_op t name_loc;
1354- Type_env. constraining_type
1355- ~default: (Type_env. get_var_declared_type cx (OrdinaryName name) name_loc)
1356- cx
1357- name
1358- name_loc)
1342+ match_pattern cx case_match_root_loc ~has_guard: (Option. is_some guard) pattern
13591343 in
13601344 let guard = Base.Option. map ~f: (expression cx) guard in
13611345 (match body with
@@ -3129,22 +3113,7 @@ module Make
31293113 case
31303114 in
31313115 let pattern =
3132- Match_pattern. pattern
3133- cx
3134- ( case_match_root_loc,
3135- Identifier (Flow_ast_utils. match_root_ident case_match_root_loc)
3136- )
3137- pattern
3138- ~on_identifier: (fun ~encl_ctx cx ->
3139- identifier cx { empty_syntactic_flags with Natural_inference. encl_ctx })
3140- ~on_expression: expression
3141- ~on_binding: (fun ~use_op ~name_loc ~kind name t ->
3142- init_var kind cx ~use_op t name_loc;
3143- Type_env. constraining_type
3144- ~default: (Type_env. get_var_declared_type cx (OrdinaryName name) name_loc)
3145- cx
3146- name
3147- name_loc)
3116+ match_pattern cx case_match_root_loc ~has_guard: (Option. is_some guard) pattern
31483117 in
31493118 let (guard, guard_throws) =
31503119 match guard with
@@ -9014,6 +8983,32 @@ module Make
90148983 in
90158984 { enum_name; enum_id; members; representation_t; has_unknown_members }
90168985
8986+ and match_pattern cx case_match_root_loc ~has_guard pattern =
8987+ let node_cache = Context. node_cache cx in
8988+ match Node_cache. get_match_pattern node_cache (fst pattern) with
8989+ | Some (p , _has_guard ) -> p
8990+ | None ->
8991+ let p =
8992+ Match_pattern. pattern
8993+ cx
8994+ ( case_match_root_loc,
8995+ Flow_ast.Expression. Identifier (Flow_ast_utils. match_root_ident case_match_root_loc)
8996+ )
8997+ pattern
8998+ ~on_identifier: (fun ~encl_ctx cx ->
8999+ identifier cx { empty_syntactic_flags with Natural_inference. encl_ctx })
9000+ ~on_expression: expression
9001+ ~on_binding: (fun ~use_op ~name_loc ~kind name t ->
9002+ init_var kind cx ~use_op t name_loc;
9003+ Type_env. constraining_type
9004+ ~default: (Type_env. get_var_declared_type cx (OrdinaryName name) name_loc)
9005+ cx
9006+ name
9007+ name_loc)
9008+ in
9009+ Node_cache. set_match_pattern node_cache (fst pattern) (p, has_guard);
9010+ p
9011+
90179012 and error_on_match_case_invalid_syntax
90189013 cx ~match_keyword_loc (invalid_syntax_list : ALoc.t Flow_ast.Match.Case.InvalidSyntax.t list )
90199014 : unit =
0 commit comments