diff --git a/Cargo.lock b/Cargo.lock index be011a6..395027e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -67,7 +67,7 @@ checksum = "f538837af36e6f6a9be0faa67f9a314f8119e4e4b5867c6ab40ed60360142519" [[package]] name = "as3_parser" -version = "1.0.19" +version = "1.0.21" dependencies = [ "bitflags", "by_address", diff --git a/crates/parser/Cargo.toml b/crates/parser/Cargo.toml index 3341523..cc82f5e 100644 --- a/crates/parser/Cargo.toml +++ b/crates/parser/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "as3_parser" -version = "1.0.19" +version = "1.0.21" edition = "2021" authors = ["hydroper "] repository = "https://github.com/hydroper/as3parser" diff --git a/crates/parser/parser/parser.rs b/crates/parser/parser/parser.rs index b71d433..b62874a 100644 --- a/crates/parser/parser/parser.rs +++ b/crates/parser/parser/parser.rs @@ -3619,6 +3619,9 @@ impl<'input> Parser<'input> { // the super compilation unit. nested_compilation_unit.set_included_from(Some(self.tokenizer.compilation_unit().clone())); + // Inherit compiler options + nested_compilation_unit.set_compiler_options(self.tokenizer.compilation_unit().compiler_options()); + // Add sub compilation unit to super compilation unit self.tokenizer.compilation_unit().add_nested_compilation_unit(nested_compilation_unit.clone()); diff --git a/crates/parser/tree/assignment_expression.rs b/crates/parser/tree/assignment_expression.rs index fbcfe64..52db6f3 100644 --- a/crates/parser/tree/assignment_expression.rs +++ b/crates/parser/tree/assignment_expression.rs @@ -7,7 +7,8 @@ pub struct AssignmentExpression { pub compound: Option, /// Assignment left-hand side. /// - /// If the left-hand side is an `ObjectInitializer` or an `ArrayLiteral` + /// If the left-hand side is an `ObjectInitializer` or an `ArrayLiteral`, + /// possibly followed by a non-null operator, /// and there is no compound assignment, it is a destructuring pattern. pub left: Rc, pub right: Rc, diff --git a/crates/parser/tree/directive.rs b/crates/parser/tree/directive.rs index 2f0af6d..3bc0a5f 100644 --- a/crates/parser/tree/directive.rs +++ b/crates/parser/tree/directive.rs @@ -79,4 +79,28 @@ impl Directive { Self::NamespaceDefinition(d) => d.location.clone(), } } + + #[inline(always)] + pub fn is_statement(&self) -> bool { + !self.is_directive() + } + + pub fn is_directive(&self) -> bool { + matches!( + self, + Self::ConfigurationDirective(_) | + Self::ImportDirective(_) | + Self::UseNamespaceDirective(_) | + Self::IncludeDirective(_) | + Self::NormalConfigurationDirective(_) | + Self::PackageConcatDirective(_) | + Self::VariableDefinition(_) | + Self::FunctionDefinition(_) | + Self::ClassDefinition(_) | + Self::EnumDefinition(_) | + Self::InterfaceDefinition(_) | + Self::TypeDefinition(_) | + Self::NamespaceDefinition(_) + ) + } } \ No newline at end of file diff --git a/crates/parser/tree/expression.rs b/crates/parser/tree/expression.rs index b32fd33..edb8c5a 100644 --- a/crates/parser/tree/expression.rs +++ b/crates/parser/tree/expression.rs @@ -173,7 +173,11 @@ impl Expression { pub fn is_valid_assignment_left_hand_side(&self) -> bool { match self { Self::Invalidated(_) => true, - Self::Unary(e) => e.expression.is_valid_assignment_left_hand_side(), + Self::Unary(e) => if e.operator == Operator::NonNull { + e.expression.is_valid_assignment_left_hand_side() + } else { + true + }, Self::ArrayLiteral(_) | Self::ObjectInitializer(_) => self.is_valid_destructuring(), _ => true, }