From c1beb0f56d81855d8b7e679c1c4d893463ebc20f Mon Sep 17 00:00:00 2001 From: Steven Cole Date: Wed, 15 Jul 2026 12:24:04 -0700 Subject: [PATCH] Fix up the optional chain template code Moving from a to-do panic to a not-actually-allowed internal error --- src/compiler/mod.rs | 8 ++++---- src/compiler/tests.rs | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/compiler/mod.rs b/src/compiler/mod.rs index 5ec91e87..e333b6c3 100644 --- a/src/compiler/mod.rs +++ b/src/compiler/mod.rs @@ -1,6 +1,6 @@ use super::*; use ahash::AHashSet; -use anyhow::{Context, anyhow}; +use anyhow::{Context, anyhow, bail}; use counter::Counter; #[cfg(test)] use num::BigInt; @@ -1046,7 +1046,7 @@ fn compile_debug_lit(chunk: &mut Chunk, ch: &DebugKind, line: usize) -> anyhow:: } DebugKind::Char('~') => { // Be a compiler error - anyhow::bail!("@@~ token detected. aborting compilation.") + bail!("@@~ token detected. aborting compilation.") } DebugKind::Char(_) => (), } @@ -3032,7 +3032,7 @@ impl OptionalChain { chunk.op_plus_arg(Insn::Unwind, 1, line); evaluate_property_access_with_identifier_key(chunk, id, strict, line).map(CompilerStatusFlags::from) } - OptionalChain::Template(_, _) => todo!(), + OptionalChain::Template(_, _) => bail!("Template literals are not allowed in optional chains"), OptionalChain::PrivateId(id, _) => { // OptionalChain : ?. PrivateIdentifier // 1. Let fieldNameString be the StringValue of PrivateIdentifier. @@ -3709,7 +3709,7 @@ impl RelationalExpression { RelationalExpression::GreaterEqual(_, _) => Insn::GreaterEqual, RelationalExpression::InstanceOf(_, _) => Insn::InstanceOf, RelationalExpression::In(_, _) => Insn::In, - _ => anyhow::bail!("RelationalExpression has no binary instruction"), + _ => bail!("RelationalExpression has no binary instruction"), }) } diff --git a/src/compiler/tests.rs b/src/compiler/tests.rs index 5575df0f..efec30a7 100644 --- a/src/compiler/tests.rs +++ b/src/compiler/tests.rs @@ -12793,7 +12793,7 @@ mod optional_chain { => Ok((svec(&["00001: ?.a", "UNWIND 1", "STRING 0 (a)", "STRICT_REF"]), false, true)); "oc: id; success" )] - #[test_case("?.``", true, &[] => panics "not yet implemented"; "oc: template")] + #[test_case("?.``", true, &[] => serr("Template literals are not allowed in optional chains"); "oc: template")] #[test_case( "?.#a", true, &[] => Ok((svec(&["00001: ?.#a", "UNWIND 1", "PRIVATE_REF 0 (#a)"]), false, true));