Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions compiler/src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1217,11 +1217,16 @@ pub fn parse_block(c: &mut Cursor) -> R<Vec<Stmt>> {
c.ws(true);
let mut out = vec![];
while !c.starts_with("}") {
let at = c.i;
out.push(parse_stmt(c)?);
out.append(&mut c.pending);
c.ws(true);
c.eat(";");
c.ws(true);
// an editor's parse reads a missing statement as an empty one, so at the end of input nothing moves
if c.i == at {
break;
}
}
c.expect("}")?;
Ok(out)
Expand Down Expand Up @@ -2257,6 +2262,13 @@ mod recovering {
assert!(parse_program(src).is_err());
}

#[test]
fn an_unclosed_block_at_the_end_of_input_stops() {
let src = "export default component App() {\n <button onClick={() => { c";
let (_, errs) = parse_program_recovering(src);
assert!(!errs.is_empty());
}

#[test]
fn function_types_in_props_and_type_aliases() {
let src = "type Pick = (id: number) => void\ncomponent Row(props: { id: number; onPick: (id: number) => void; onDrop: Pick }) {\n source n: number := peek(props.id)\n <li onClick={() => { props.onPick(n) }}>{n}</li>\n}\nfn twice(x: number): number => x * 2\nexport default component App() {\n <Row id={twice(1)} onPick={id => { log(id) }} onDrop={id => { log(id) }} />\n}\n";
Expand Down
Loading