Skip to content

Commit

Permalink
Improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
hydroper committed May 10, 2024
1 parent 292622c commit f3ce075
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/parser/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "as3_parser"
version = "1.0.19"
version = "1.0.21"
edition = "2021"
authors = ["hydroper <[email protected]>"]
repository = "https://github.com/hydroper/as3parser"
Expand Down
3 changes: 3 additions & 0 deletions crates/parser/parser/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down
3 changes: 2 additions & 1 deletion crates/parser/tree/assignment_expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ pub struct AssignmentExpression {
pub compound: Option<Operator>,
/// 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<Expression>,
pub right: Rc<Expression>,
Expand Down
24 changes: 24 additions & 0 deletions crates/parser/tree/directive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(_)
)
}
}
6 changes: 5 additions & 1 deletion crates/parser/tree/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down

0 comments on commit f3ce075

Please sign in to comment.