-
-
Notifications
You must be signed in to change notification settings - Fork 518
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
transformer: a helper for inserting new statements above or below the current statement. #6641
Comments
Good idea. As #6644 is problematic, I suggest using oxc/crates/oxc_allocator/src/boxed.rs Lines 173 to 181 in 9281234
Currently we only support getting an pub trait GetAddress {
fn address(&self) -> Address;
}
impl<'a> GetAddress for Statement<'a> {
#[inline]
fn address(&self) -> Address {
match self {
Statement::BlockStatement(s) => s.address(),
Statement::BreakStatement(s) => s.address(),
Statement::ContinueStatement(s) => s.address(),
// ... all the rest
}
}
} The We could generate this with I know everyone but me sees |
I have no preference for either way. But this way I have a concern, we have many places where mutate directly the |
Therefore, you can also move a So, how does this apply to
let mut stmts = Vec::new_in(allocator);
stmts.push(Statement::EmptyStatement(Box::new_in(
EmptyStatement { span: Span::new(0, 0) },
allocator,
)));
// Get address of the statement at index 0
let address = stmts[0].address();
// Insert another statement before it
stmts.insert(
0,
Statement::EmptyStatement(Box::new_in(EmptyStatement { span: Span::new(1, 1) }, allocator)),
);
// The original statement is now at index 1, but its `Address` has not changed
assert_eq!(stmts[1].address(), address); Mutating a The only thing that will affect If you take ownership of a The one tricky situation is if you replace a statement e.g. convert So... TLDR... I think |
@overlookmotel I got your point, I am trying it |
Here a case can be replaced with oxc/crates/oxc_transformer/src/react/refresh.rs Lines 269 to 304 in ca8c578
The above logic handles the following code, and determines whether the parent of the current node is const statement = function b() {} I want to use Do you think it is possible? |
I think it should be possible to add support for getting |
Unified usage like #4767 (comment) does
The text was updated successfully, but these errors were encountered: