2525
2626let rec is_obj_literal ( x : _ Flow_ast.Expression.t ) : bool =
2727 match snd x with
28- | Literal _ -> true
28+ | Identifier (_, {name = " undefined" })
29+ | Literal _ -> true
2930 | Object {properties} ->
3031 Ext_list. for_all properties is_literal_kv
3132 | Array {elements} ->
@@ -42,27 +43,26 @@ and is_literal_kv (x : _ Flow_ast.Expression.Object.property) =
4243 | _ -> false
4344
4445
45- let classify (prog : string ) : Js_raw_info.exp =
46- match Parser_flow. parse_expression
47- (Parser_env. init_env None prog) false with
46+ let classify_exp (prog : _ Flow_ast.Expression.t ) : Js_raw_info.exp =
47+ match prog with
4848 | (_, Function {
4949 id = _;
5050 params = (_, {params});
5151 async = false ;
5252 generator = false ;
5353 predicate = None
54- }) , [] ->
54+ }) ->
5555 Js_function {arity = List. length params; arrow = false }
5656 | (_, ArrowFunction {
5757 id = None ;
5858 params = (_, {params});
5959 async = false ;
6060 generator = false ;
6161 predicate = None
62- }) , [] ->
62+ }) ->
6363 Js_function
6464 {arity = List. length params; arrow = true }
65- | (_, Literal {comments}), [] ->
65+ | (_, Literal {comments}) ->
6666 let comment =
6767 match comments with
6868 | None -> None
@@ -71,13 +71,23 @@ let classify (prog : string) : Js_raw_info.exp =
7171 | Some _ -> None
7272 in
7373 Js_literal {comment}
74- | (_ ,Object _ ) as exp , _ ->
75- if is_obj_literal exp then Js_literal {comment = None } else Js_exp_unknown
74+ | (_ , Identifier(_ ,{name = "undefined" } )) -> Js_literal {comment = None }
75+ | (_ ,Object _ ) ->
76+ if is_obj_literal prog then Js_literal {comment = None } else Js_exp_unknown
7677 | _ ->
7778 Js_exp_unknown
7879 | exception _ ->
7980 Js_exp_unknown
8081
82+ let classify (prog : string ) : Js_raw_info.exp =
83+ let prog, errors =
84+ Parser_flow. parse_expression
85+ (Parser_env. init_env None prog) false in
86+ if errors <> [] then
87+ assert false (* in the calling API, we already asked flow to raise*)
88+ else classify_exp prog
89+
90+
8191let classify_stmt (prog : string ) : Js_raw_info.stmt =
8292 let result = Parser_flow. parse_program false None prog in
8393 match fst result with
0 commit comments