Skip to content

Commit

Permalink
fix(transformer): do not add __source for generated nodes (#3614)
Browse files Browse the repository at this point in the history
  • Loading branch information
overlookmotel committed Jun 11, 2024
1 parent f4c1389 commit 9e8f4d6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
15 changes: 15 additions & 0 deletions crates/oxc_span/src/span.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,21 @@ impl Span {
self.start == self.end
}

/// Returns `true` if `self` is not a real span.
/// i.e. `SPAN` which is used for generated nodes which are not in source code.
///
/// # Example
/// ```
/// use oxc_span::{Span, SPAN};
///
/// assert!(SPAN.is_unspanned());
/// assert!(!Span::new(0, 5).is_unspanned());
/// assert!(!Span::new(5, 5).is_unspanned());
/// ```
pub const fn is_unspanned(&self) -> bool {
self.start == SPAN.start && self.end == SPAN.end
}

/// Create a [`Span`] covering the maximum range of two [`Span`]s.
///
/// # Example
Expand Down
5 changes: 5 additions & 0 deletions crates/oxc_transformer/src/react/jsx_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ impl<'a> ReactJsxSource<'a> {
elem: &mut JSXOpeningElement<'a>,
ctx: &mut TraverseCtx<'a>,
) {
// Don't add `__source` if this node was generated
if elem.span.is_unspanned() {
return;
}

// Check if `__source` attribute already exists
for item in &elem.attributes {
if let JSXAttributeItem::Attribute(attribute) = item {
Expand Down

0 comments on commit 9e8f4d6

Please sign in to comment.