diff --git a/src/res_core.ml b/src/res_core.ml index 31258253..f6747806 100644 --- a/src/res_core.ml +++ b/src/res_core.ml @@ -5408,11 +5408,15 @@ and parseJsImport ~startPos ~attrs p = let importSpec = match p.Parser.token with | Token.Lident _ | Token.At -> + Parser.leaveBreadcrumb p Grammar.JsFfiImport; let decl = match parseJsFfiDeclaration p with | Some decl -> decl - | None -> assert false + | None -> + Parser.err p (Diagnostics.unexpected p.Parser.token p.breadcrumbs); + JsFfi.emptyDecl p.startPos in + Parser.eatBreadcrumb p; JsFfi.Default decl | _ -> JsFfi.Spec (parseJsFfiDeclarations p) in diff --git a/src/res_js_ffi.ml b/src/res_js_ffi.ml index 3d02fb10..12a4ae2a 100644 --- a/src/res_js_ffi.ml +++ b/src/res_js_ffi.ml @@ -32,6 +32,19 @@ let decl ~attrs ~loc ~name ~alias ~typ = jld_type = typ; } +let emptyDecl loc = + let loc = Location.{loc_start = loc; loc_end = loc; loc_ghost = false} in + let emptyCoreType : Parsetree.core_type = + {ptyp_desc = Parsetree.Ptyp_any; ptyp_loc = loc; ptyp_attributes = []} + in + { + jld_loc = loc; + jld_attributes = []; + jld_name = ""; + jld_alias = ""; + jld_type = emptyCoreType; + } + let importDescr ~attrs ~scope ~importSpec ~loc = { jid_loc = loc; diff --git a/tests/parsing/errors/other/expected/import.res.txt b/tests/parsing/errors/other/expected/import.res.txt new file mode 100644 index 00000000..6af348b9 --- /dev/null +++ b/tests/parsing/errors/other/expected/import.res.txt @@ -0,0 +1,10 @@ + + Syntax error! + tests/parsing/errors/other/import.res:2:1 + + 1 │ import@ + 2 │ + + I'm not sure what to parse here when looking at "eof". + +include struct external Fatal error: exception Invalid_argument("index out of bounds") diff --git a/tests/parsing/errors/other/import.res b/tests/parsing/errors/other/import.res new file mode 100644 index 00000000..74d56807 --- /dev/null +++ b/tests/parsing/errors/other/import.res @@ -0,0 +1 @@ +import@