mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 04:08:41 +00:00
feat(ast): allow passing span to void_0 method (#6065)
unblock #6021 Keep the original expression's `span` to insert comments correctly. Have tested in #6021 and it worked
This commit is contained in:
parent
77647931e4
commit
60c52ba2b9
5 changed files with 8 additions and 7 deletions
|
|
@ -127,10 +127,10 @@ impl<'a> AstBuilder<'a> {
|
|||
|
||||
/// `void 0`
|
||||
#[inline]
|
||||
pub fn void_0(self) -> Expression<'a> {
|
||||
pub fn void_0(self, span: Span) -> Expression<'a> {
|
||||
let num = self.number_0();
|
||||
Expression::UnaryExpression(self.alloc(self.unary_expression(
|
||||
Span::default(),
|
||||
span,
|
||||
UnaryOperator::Void,
|
||||
num,
|
||||
)))
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use oxc_ast::ast::*;
|
||||
use oxc_span::SPAN;
|
||||
use oxc_span::{GetSpan, SPAN};
|
||||
use oxc_syntax::{
|
||||
number::NumberBase,
|
||||
operator::{BinaryOperator, UnaryOperator},
|
||||
|
|
@ -101,7 +101,7 @@ impl<'a> PeepholeSubstituteAlternateSyntax {
|
|||
/// Transforms `undefined` => `void 0`
|
||||
fn compress_undefined(&self, expr: &mut Expression<'a>, ctx: &mut TraverseCtx<'a>) -> bool {
|
||||
if ctx.is_expression_undefined(expr) {
|
||||
*expr = ctx.ast.void_0();
|
||||
*expr = ctx.ast.void_0(expr.span());
|
||||
return true;
|
||||
};
|
||||
false
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
use oxc_allocator::Vec;
|
||||
use oxc_ast::ast::*;
|
||||
use oxc_span::GetSpan;
|
||||
use oxc_traverse::{Traverse, TraverseCtx};
|
||||
|
||||
use crate::{CompressOptions, CompressorPass};
|
||||
|
|
@ -77,7 +78,7 @@ impl<'a> RemoveSyntax {
|
|||
|
||||
fn compress_console(&mut self, expr: &mut Expression<'a>, ctx: &mut TraverseCtx<'a>) {
|
||||
if self.options.drop_console && Self::is_console(expr) {
|
||||
*expr = ctx.ast.void_0();
|
||||
*expr = ctx.ast.void_0(expr.span());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -224,7 +224,7 @@ impl<'a> NullishCoalescingOperator<'a> {
|
|||
SPAN,
|
||||
Self::clone_expression(&reference, ctx),
|
||||
op,
|
||||
ctx.ast.void_0(),
|
||||
ctx.ast.void_0(SPAN),
|
||||
);
|
||||
let test = ctx.ast.expression_logical(SPAN, left, LogicalOperator::And, right);
|
||||
|
||||
|
|
|
|||
|
|
@ -676,7 +676,7 @@ impl<'a> ReactJsx<'a> {
|
|||
if key_prop.is_some() {
|
||||
arguments.push(Argument::from(self.transform_jsx_attribute_value(key_prop, ctx)));
|
||||
} else if is_development {
|
||||
arguments.push(Argument::from(self.ctx.ast.void_0()));
|
||||
arguments.push(Argument::from(self.ctx.ast.void_0(SPAN)));
|
||||
}
|
||||
|
||||
// isStaticChildren
|
||||
|
|
|
|||
Loading…
Reference in a new issue