Skip to content

Commit df0df1a

Browse files
committed
fix #4343, regex syntax checking
1 parent b3f7daf commit df0df1a

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

jscomp/syntax/ast_payload.ml

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,15 @@ let raw_as_string_exp_exn
112112
pexp_loc = loc} as e ,_);
113113
_}] ->
114114
check_flow_errors ~loc deli (match kind with
115-
| Raw_re ->
116-
let l s =
117-
Flow_lexer.regexp (Lex_env.new_lex_env None (Sedlexing.Utf8.from_string s) ~enable_types_in_comments:false)
118-
in
119-
(snd (l str)).lex_errors
115+
| Raw_re
120116
| Raw_exp ->
121-
snd (Parser_flow.parse_expression (Parser_env.init_env None str) false)
117+
let (_loc,e),errors = (Parser_flow.parse_expression (Parser_env.init_env None str) false) in
118+
if kind = Raw_re then
119+
(match e with
120+
| Literal {value = RegExp _} -> ()
121+
| _ -> Location.raise_errorf ~loc "Syntax error: a valid JS regex literal expected"
122+
);
123+
errors
122124
| Raw_program ->
123125
snd (Parser_flow.parse_program false None str)
124126
);
@@ -173,8 +175,8 @@ let ident_or_record_as_config
173175
begin match with_obj with
174176
| None ->
175177
Ext_list.map label_exprs
176-
(fun ((x,y) : (Longident.t Asttypes.loc * _) ) ->
177-
match (x,y) with
178+
(fun u ->
179+
match u with
178180
| ({txt = Lident name; loc} ) ,
179181
({Parsetree.pexp_desc = Pexp_ident{txt = Lident name2}} )
180182
when name2 = name ->

0 commit comments

Comments
 (0)