Browse Source

Fix panic in optional expressions with private identifiers (#2995)

pull/2997/head
raskad 1 year ago committed by GitHub
parent
commit
940529ac8a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 26
      boa_ast/src/operations.rs
  2. 8
      boa_parser/src/parser/expression/left_hand_side/optional/tests.rs

26
boa_ast/src/operations.rs

@ -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,
@ -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.

8
boa_parser/src/parser/expression/left_hand_side/optional/tests.rs

@ -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");
}

Loading…
Cancel
Save