diff --git a/src/shell_parser/parse.rs b/src/shell_parser/parse.rs index 8ae38c01f92..0961042fb71 100644 --- a/src/shell_parser/parse.rs +++ b/src/shell_parser/parse.rs @@ -1915,10 +1915,7 @@ impl<'bump> Parser<'bump> { Ok(match atoms.len() { 0 => None, - 1 => { - debug_assert!(atoms.capacity() == 1); - Some(ast::Atom::new_simple(atoms.into_iter().next().unwrap())) - } + 1 => Some(ast::Atom::new_simple(atoms.into_iter().next().unwrap())), _ => Some(ast::Atom::Compound(ast::CompoundAtom { atoms: atoms.into_bump_slice(), brace_expansion_hint: has_brace_open && has_brace_close && has_comma, diff --git a/test/js/bun/shell/parse.test.ts b/test/js/bun/shell/parse.test.ts index a091858e9dc..2da7a674bc1 100644 --- a/test/js/bun/shell/parse.test.ts +++ b/test/js/bun/shell/parse.test.ts @@ -59,6 +59,42 @@ describe("parse shell", () => { expect(result).toEqual(expected); }); + test("single atom", () => { + expect(JSON.parse(parse`ls`)).toEqual({ + stmts: [ + { + exprs: [ + { + cmd: { + assigns: [], + name_and_args: [{ simple: { Text: "ls" } }], + redirect: redirect({}), + redirect_file: null, + }, + }, + ], + }, + ], + }); + + expect(JSON.parse(parse`echo ~`)).toEqual({ + stmts: [ + { + exprs: [ + { + cmd: { + assigns: [], + name_and_args: [{ simple: { Text: "echo" } }, { simple: { tilde: {} } }], + redirect: redirect({}), + redirect_file: null, + }, + }, + ], + }, + ], + }); + }); + test("compound atom", () => { const expected = { stmts: [