Skip to content

Commit

Permalink
Fix panic in optional expressions with private identifiers (#2995)
Browse files Browse the repository at this point in the history
  • Loading branch information
raskad authored Jun 4, 2023
1 parent ee97198 commit 940529a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
26 changes: 25 additions & 1 deletion boa_ast/src/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::{
expression::{
access::{PrivatePropertyAccess, SuperPropertyAccess},
operator::BinaryInPrivate,
Await, Identifier, SuperCall, Yield,
Await, Identifier, OptionalOperationKind, SuperCall, Yield,
},
function::{
ArrowFunction, AsyncArrowFunction, AsyncFunction, AsyncGenerator, Class, ClassElement,
Expand Down Expand Up @@ -976,6 +976,30 @@ impl<'ast> Visitor<'ast> for AllPrivateIdentifiersValidVisitor {
ControlFlow::Break(())
}
}

fn visit_optional_operation_kind(
&mut self,
node: &'ast OptionalOperationKind,
) -> ControlFlow<Self::BreakTy> {
match node {
OptionalOperationKind::SimplePropertyAccess { field } => {
self.visit_property_access_field(field)
}
OptionalOperationKind::PrivatePropertyAccess { field } => {
if self.0.contains(&field.description()) {
ControlFlow::Continue(())
} else {
ControlFlow::Break(())
}
}
OptionalOperationKind::Call { args } => {
for arg in args.iter() {
try_break!(self.visit_expression(arg));
}
ControlFlow::Continue(())
}
}
}
}

/// Errors that can occur when checking labels.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,11 @@ const a = console?.log
`Hello`"#,
);
}

#[test]
fn private_identifier_early_error() {
check_invalid_script("this?.#a");
check_invalid_script("this.#a");
check_invalid_script("this?.a?.#a");
check_invalid_script("this.a.#a");
}

0 comments on commit 940529a

Please sign in to comment.