mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +00:00
fix(transformer): do not add __source for generated nodes (#3614)
JSX transform don't add `__source` to nodes which were generated (not present in source).
Following:
8e39f35eb9/packages/babel-plugin-transform-react-jsx-source/src/index.ts (L57-L64)
This commit is contained in:
parent
f4c1389e99
commit
9e8f4d60b5
2 changed files with 20 additions and 0 deletions
|
|
@ -118,6 +118,21 @@ impl Span {
|
||||||
self.start == self.end
|
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.
|
/// Create a [`Span`] covering the maximum range of two [`Span`]s.
|
||||||
///
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
|
|
|
||||||
|
|
@ -65,6 +65,11 @@ impl<'a> ReactJsxSource<'a> {
|
||||||
elem: &mut JSXOpeningElement<'a>,
|
elem: &mut JSXOpeningElement<'a>,
|
||||||
ctx: &mut TraverseCtx<'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
|
// Check if `__source` attribute already exists
|
||||||
for item in &elem.attributes {
|
for item in &elem.attributes {
|
||||||
if let JSXAttributeItem::Attribute(attribute) = item {
|
if let JSXAttributeItem::Attribute(attribute) = item {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue