Skip to content

Commit 91fbe92

Browse files
committed
[core][rewriter] handle update_expression properly
1 parent 3d92639 commit 91fbe92

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

rewriter/js/src/visitor.rs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::error::Error;
33
use oxc::{
44
allocator::{Allocator, StringBuilder},
55
ast::ast::{
6-
AssignmentExpression, AssignmentTarget, CallExpression, ComputedMemberExpression, DebuggerStatement, ExportAllDeclaration, ExportNamedDeclaration, Expression, FunctionBody, IdentifierReference, ImportDeclaration, ImportExpression, MemberExpression, MetaProperty, NewExpression, ObjectExpression, ObjectPropertyKind, ReturnStatement, StringLiteral, ThisExpression, UnaryExpression, UnaryOperator, UpdateExpression
6+
AssignmentExpression, AssignmentTarget, BindingPattern, CallExpression, ComputedMemberExpression, DebuggerStatement, ExportAllDeclaration, ExportNamedDeclaration, Expression, FunctionBody, IdentifierReference, ImportDeclaration, ImportExpression, MemberExpression, MetaProperty, NewExpression, ObjectExpression, ObjectPattern, ObjectPropertyKind, ReturnStatement, SimpleAssignmentTarget, StringLiteral, ThisExpression, UnaryExpression, UnaryOperator, UpdateExpression
77
},
88
ast_visit::{walk, Visit},
99
span::{Atom, GetSpan, Span},
@@ -291,9 +291,24 @@ where
291291
walk::walk_unary_expression(self, it);
292292
}
293293

294-
// fn visit_update_expression(&mut self, _it: &UpdateExpression<'data>) {
295-
// // this is like a ++ or -- operator
296-
// }
294+
fn visit_update_expression(&mut self, it: &UpdateExpression<'data>) {
295+
// this is like a ++ or -- operator
296+
match it.argument {
297+
SimpleAssignmentTarget::AssignmentTargetIdentifier(_) => {
298+
// if it's an identifier we cannot rewrite it
299+
// $wrap(location)++ is invalid syntax
300+
301+
// so it's safer to assume that this "location" is a local
302+
// even if it's real location you can't escape with it anyway
303+
// unless you consider navigating to "https://proxy.com/NaN" escaping
304+
return;
305+
}
306+
_=>{}
307+
}
308+
309+
// if it's not a simple identifier it's probably a member expression which is safe
310+
walk::walk_update_expression(self, it);
311+
}
297312

298313
fn visit_meta_property(&mut self, it: &MetaProperty<'data>) {
299314
if it.meta.name == "import" {

0 commit comments

Comments
 (0)