-
-
Notifications
You must be signed in to change notification settings - Fork 485
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(transformer): add utils to make logical_assignment_operators pass (
- Loading branch information
Showing
12 changed files
with
340 additions
and
95 deletions.
There are no files selected for viewing
82 changes: 82 additions & 0 deletions
82
crates/oxc_ast/src/syntax_directed_operations/gather_node_parts.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
use crate::ast::*; | ||
use oxc_span::Atom; | ||
|
||
// TODO: <https://github.com/babel/babel/blob/419644f27c5c59deb19e71aaabd417a3bc5483ca/packages/babel-traverse/src/scope/index.ts#L61> | ||
pub trait GatherNodeParts { | ||
fn gather<F: FnMut(Atom)>(&self, f: &mut F); | ||
} | ||
|
||
impl<'a> GatherNodeParts for Expression<'a> { | ||
fn gather<F: FnMut(Atom)>(&self, f: &mut F) { | ||
match self { | ||
Self::Identifier(ident) => f(ident.name.clone()), | ||
Self::MemberExpression(expr) => expr.gather(f), | ||
Self::AssignmentExpression(expr) => expr.left.gather(f), | ||
Self::UpdateExpression(expr) => expr.argument.gather(f), | ||
Self::StringLiteral(lit) => lit.gather(f), | ||
_ => f(Atom::from("ref")), | ||
} | ||
} | ||
} | ||
|
||
impl<'a> GatherNodeParts for MemberExpression<'a> { | ||
fn gather<F: FnMut(Atom)>(&self, f: &mut F) { | ||
match self { | ||
MemberExpression::ComputedMemberExpression(expr) => { | ||
expr.object.gather(f); | ||
expr.expression.gather(f); | ||
} | ||
MemberExpression::StaticMemberExpression(expr) => { | ||
expr.object.gather(f); | ||
expr.property.gather(f); | ||
} | ||
MemberExpression::PrivateFieldExpression(expr) => { | ||
expr.object.gather(f); | ||
expr.field.gather(f); | ||
} | ||
} | ||
} | ||
} | ||
|
||
impl<'a> GatherNodeParts for AssignmentTarget<'a> { | ||
fn gather<F: FnMut(Atom)>(&self, f: &mut F) { | ||
match self { | ||
AssignmentTarget::SimpleAssignmentTarget(t) => t.gather(f), | ||
AssignmentTarget::AssignmentTargetPattern(_) => {} | ||
} | ||
} | ||
} | ||
|
||
impl<'a> GatherNodeParts for SimpleAssignmentTarget<'a> { | ||
fn gather<F: FnMut(Atom)>(&self, f: &mut F) { | ||
match self { | ||
Self::AssignmentTargetIdentifier(ident) => ident.gather(f), | ||
Self::MemberAssignmentTarget(expr) => expr.gather(f), | ||
_ => {} | ||
} | ||
} | ||
} | ||
|
||
impl GatherNodeParts for IdentifierReference { | ||
fn gather<F: FnMut(Atom)>(&self, f: &mut F) { | ||
f(self.name.clone()); | ||
} | ||
} | ||
|
||
impl GatherNodeParts for IdentifierName { | ||
fn gather<F: FnMut(Atom)>(&self, f: &mut F) { | ||
f(self.name.clone()); | ||
} | ||
} | ||
|
||
impl GatherNodeParts for PrivateIdentifier { | ||
fn gather<F: FnMut(Atom)>(&self, f: &mut F) { | ||
f(self.name.clone()); | ||
} | ||
} | ||
|
||
impl GatherNodeParts for StringLiteral { | ||
fn gather<F: FnMut(Atom)>(&self, f: &mut F) { | ||
f(self.value.clone()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
//! [ECMA262 Syntax-Directed Operations](https://tc39.es/ecma262/#sec-syntax-directed-operations) | ||
mod bound_names; | ||
mod gather_node_parts; | ||
mod is_simple_parameter_list; | ||
mod private_bound_identifiers; | ||
mod prop_name; | ||
|
||
pub use self::{ | ||
bound_names::BoundNames, is_simple_parameter_list::IsSimpleParameterList, | ||
bound_names::BoundNames, gather_node_parts::GatherNodeParts, | ||
is_simple_parameter_list::IsSimpleParameterList, | ||
private_bound_identifiers::PrivateBoundIdentifiers, prop_name::PropName, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,30 @@ | ||
use std::{cell::RefCell, rc::Rc}; | ||
use std::{ | ||
cell::{Ref, RefCell}, | ||
rc::Rc, | ||
}; | ||
|
||
use oxc_ast::AstBuilder; | ||
use oxc_semantic::{ScopeTree, SymbolTable}; | ||
use oxc_semantic::{ScopeId, ScopeTree, SymbolId, SymbolTable}; | ||
use oxc_span::Atom; | ||
|
||
#[derive(Clone)] | ||
pub struct TransformerCtx<'a> { | ||
pub ast: Rc<AstBuilder<'a>>, | ||
pub symbols: Rc<RefCell<SymbolTable>>, | ||
pub scopes: Rc<RefCell<ScopeTree>>, | ||
} | ||
|
||
impl<'a> TransformerCtx<'a> { | ||
pub fn symbols(&self) -> Ref<SymbolTable> { | ||
self.symbols.borrow() | ||
} | ||
|
||
pub fn scopes(&self) -> Ref<ScopeTree> { | ||
self.scopes.borrow() | ||
} | ||
|
||
pub fn add_binding(&self, name: Atom) { | ||
// TODO: use the correct scope and symbol id | ||
self.scopes.borrow_mut().add_binding(ScopeId::new(0), name, SymbolId::new(0)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.