mirror of
https://github.com/oxc-project/oxc.git
synced 2026-11-04 10:29:58 +00:00
refactor(ast_tools): simplify CloneIn derive (#9938)
Simplify implementation of code generator for `CloneIn`. Instead of complicated code to avoid unused vars, just add `#![allow(unused_variables)]` to silence the lint rules. And always use same name for the lifetime. These changes make the logic of the code generator simpler. Also add line breaks to generated code for readability.
This commit is contained in:
1 parent
a09bbcfbbb
commit
28179cdf81
4 files changed
+505
-243
No files matched your search
File diff suppressed because it is too large.
Load diff
@@ -1,7 +1,7 @@
|
||||
// Auto-generated code, DO NOT EDIT DIRECTLY!
|
||||
// To edit this generated file you have to edit `tasks/ast_tools/src/derives/clone_in.rs`
|
||||
|
||||
#![allow(clippy::default_trait_access)]
|
||||
#![allow(unused_variables, clippy::default_trait_access)]
|
||||
|
||||
use oxc_allocator::{Allocator, CloneIn};
|
||||
|
||||
@@ -9,6 +9,7 @@ use crate::ast::*;
|
||||
|
||||
impl<'new_alloc> CloneIn<'new_alloc> for Pattern<'_> {
|
||||
type Cloned = Pattern<'new_alloc>;
|
||||
|
||||
fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
|
||||
Pattern {
|
||||
span: CloneIn::clone_in(&self.span, allocator),
|
||||
@@ -26,6 +27,7 @@ impl<'new_alloc> CloneIn<'new_alloc> for Pattern<'_> {
|
||||
|
||||
impl<'new_alloc> CloneIn<'new_alloc> for Disjunction<'_> {
|
||||
type Cloned = Disjunction<'new_alloc>;
|
||||
|
||||
fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
|
||||
Disjunction {
|
||||
span: CloneIn::clone_in(&self.span, allocator),
|
||||
@@ -43,6 +45,7 @@ impl<'new_alloc> CloneIn<'new_alloc> for Disjunction<'_> {
|
||||
|
||||
impl<'new_alloc> CloneIn<'new_alloc> for Alternative<'_> {
|
||||
type Cloned = Alternative<'new_alloc>;
|
||||
|
||||
fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
|
||||
Alternative {
|
||||
span: CloneIn::clone_in(&self.span, allocator),
|
||||
@@ -60,6 +63,7 @@ impl<'new_alloc> CloneIn<'new_alloc> for Alternative<'_> {
|
||||
|
||||
impl<'new_alloc> CloneIn<'new_alloc> for Term<'_> {
|
||||
type Cloned = Term<'new_alloc>;
|
||||
|
||||
fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
|
||||
match self {
|
||||
Self::BoundaryAssertion(it) => {
|
||||
@@ -125,16 +129,17 @@ impl<'new_alloc> CloneIn<'new_alloc> for Term<'_> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'alloc> CloneIn<'alloc> for BoundaryAssertion {
|
||||
impl<'new_alloc> CloneIn<'new_alloc> for BoundaryAssertion {
|
||||
type Cloned = BoundaryAssertion;
|
||||
fn clone_in(&self, allocator: &'alloc Allocator) -> Self::Cloned {
|
||||
|
||||
fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
|
||||
BoundaryAssertion {
|
||||
span: CloneIn::clone_in(&self.span, allocator),
|
||||
kind: CloneIn::clone_in(&self.kind, allocator),
|
||||
}
|
||||
}
|
||||
|
||||
fn clone_in_with_semantic_ids(&self, allocator: &'alloc Allocator) -> Self::Cloned {
|
||||
fn clone_in_with_semantic_ids(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
|
||||
BoundaryAssertion {
|
||||
span: CloneIn::clone_in_with_semantic_ids(&self.span, allocator),
|
||||
kind: CloneIn::clone_in_with_semantic_ids(&self.kind, allocator),
|
||||
@@ -142,9 +147,10 @@ impl<'alloc> CloneIn<'alloc> for BoundaryAssertion {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'alloc> CloneIn<'alloc> for BoundaryAssertionKind {
|
||||
impl<'new_alloc> CloneIn<'new_alloc> for BoundaryAssertionKind {
|
||||
type Cloned = BoundaryAssertionKind;
|
||||
fn clone_in(&self, _: &'alloc Allocator) -> Self::Cloned {
|
||||
|
||||
fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
|
||||
match self {
|
||||
Self::Start => BoundaryAssertionKind::Start,
|
||||
Self::End => BoundaryAssertionKind::End,
|
||||
@@ -153,7 +159,7 @@ impl<'alloc> CloneIn<'alloc> for BoundaryAssertionKind {
|
||||
}
|
||||
}
|
||||
|
||||
fn clone_in_with_semantic_ids(&self, _: &'alloc Allocator) -> Self::Cloned {
|
||||
fn clone_in_with_semantic_ids(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
|
||||
match self {
|
||||
Self::Start => BoundaryAssertionKind::Start,
|
||||
Self::End => BoundaryAssertionKind::End,
|
||||
@@ -165,6 +171,7 @@ impl<'alloc> CloneIn<'alloc> for BoundaryAssertionKind {
|
||||
|
||||
impl<'new_alloc> CloneIn<'new_alloc> for LookAroundAssertion<'_> {
|
||||
type Cloned = LookAroundAssertion<'new_alloc>;
|
||||
|
||||
fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
|
||||
LookAroundAssertion {
|
||||
span: CloneIn::clone_in(&self.span, allocator),
|
||||
@@ -182,9 +189,10 @@ impl<'new_alloc> CloneIn<'new_alloc> for LookAroundAssertion<'_> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'alloc> CloneIn<'alloc> for LookAroundAssertionKind {
|
||||
impl<'new_alloc> CloneIn<'new_alloc> for LookAroundAssertionKind {
|
||||
type Cloned = LookAroundAssertionKind;
|
||||
fn clone_in(&self, _: &'alloc Allocator) -> Self::Cloned {
|
||||
|
||||
fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
|
||||
match self {
|
||||
Self::Lookahead => LookAroundAssertionKind::Lookahead,
|
||||
Self::NegativeLookahead => LookAroundAssertionKind::NegativeLookahead,
|
||||
@@ -193,7 +201,7 @@ impl<'alloc> CloneIn<'alloc> for LookAroundAssertionKind {
|
||||
}
|
||||
}
|
||||
|
||||
fn clone_in_with_semantic_ids(&self, _: &'alloc Allocator) -> Self::Cloned {
|
||||
fn clone_in_with_semantic_ids(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
|
||||
match self {
|
||||
Self::Lookahead => LookAroundAssertionKind::Lookahead,
|
||||
Self::NegativeLookahead => LookAroundAssertionKind::NegativeLookahead,
|
||||
@@ -205,6 +213,7 @@ impl<'alloc> CloneIn<'alloc> for LookAroundAssertionKind {
|
||||
|
||||
impl<'new_alloc> CloneIn<'new_alloc> for Quantifier<'_> {
|
||||
type Cloned = Quantifier<'new_alloc>;
|
||||
|
||||
fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
|
||||
Quantifier {
|
||||
span: CloneIn::clone_in(&self.span, allocator),
|
||||
@@ -226,9 +235,10 @@ impl<'new_alloc> CloneIn<'new_alloc> for Quantifier<'_> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'alloc> CloneIn<'alloc> for Character {
|
||||
impl<'new_alloc> CloneIn<'new_alloc> for Character {
|
||||
type Cloned = Character;
|
||||
fn clone_in(&self, allocator: &'alloc Allocator) -> Self::Cloned {
|
||||
|
||||
fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
|
||||
Character {
|
||||
span: CloneIn::clone_in(&self.span, allocator),
|
||||
kind: CloneIn::clone_in(&self.kind, allocator),
|
||||
@@ -236,7 +246,7 @@ impl<'alloc> CloneIn<'alloc> for Character {
|
||||
}
|
||||
}
|
||||
|
||||
fn clone_in_with_semantic_ids(&self, allocator: &'alloc Allocator) -> Self::Cloned {
|
||||
fn clone_in_with_semantic_ids(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
|
||||
Character {
|
||||
span: CloneIn::clone_in_with_semantic_ids(&self.span, allocator),
|
||||
kind: CloneIn::clone_in_with_semantic_ids(&self.kind, allocator),
|
||||
@@ -245,9 +255,10 @@ impl<'alloc> CloneIn<'alloc> for Character {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'alloc> CloneIn<'alloc> for CharacterKind {
|
||||
impl<'new_alloc> CloneIn<'new_alloc> for CharacterKind {
|
||||
type Cloned = CharacterKind;
|
||||
fn clone_in(&self, _: &'alloc Allocator) -> Self::Cloned {
|
||||
|
||||
fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
|
||||
match self {
|
||||
Self::ControlLetter => CharacterKind::ControlLetter,
|
||||
Self::HexadecimalEscape => CharacterKind::HexadecimalEscape,
|
||||
@@ -262,7 +273,7 @@ impl<'alloc> CloneIn<'alloc> for CharacterKind {
|
||||
}
|
||||
}
|
||||
|
||||
fn clone_in_with_semantic_ids(&self, _: &'alloc Allocator) -> Self::Cloned {
|
||||
fn clone_in_with_semantic_ids(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
|
||||
match self {
|
||||
Self::ControlLetter => CharacterKind::ControlLetter,
|
||||
Self::HexadecimalEscape => CharacterKind::HexadecimalEscape,
|
||||
@@ -278,16 +289,17 @@ impl<'alloc> CloneIn<'alloc> for CharacterKind {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'alloc> CloneIn<'alloc> for CharacterClassEscape {
|
||||
impl<'new_alloc> CloneIn<'new_alloc> for CharacterClassEscape {
|
||||
type Cloned = CharacterClassEscape;
|
||||
fn clone_in(&self, allocator: &'alloc Allocator) -> Self::Cloned {
|
||||
|
||||
fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
|
||||
CharacterClassEscape {
|
||||
span: CloneIn::clone_in(&self.span, allocator),
|
||||
kind: CloneIn::clone_in(&self.kind, allocator),
|
||||
}
|
||||
}
|
||||
|
||||
fn clone_in_with_semantic_ids(&self, allocator: &'alloc Allocator) -> Self::Cloned {
|
||||
fn clone_in_with_semantic_ids(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
|
||||
CharacterClassEscape {
|
||||
span: CloneIn::clone_in_with_semantic_ids(&self.span, allocator),
|
||||
kind: CloneIn::clone_in_with_semantic_ids(&self.kind, allocator),
|
||||
@@ -295,9 +307,10 @@ impl<'alloc> CloneIn<'alloc> for CharacterClassEscape {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'alloc> CloneIn<'alloc> for CharacterClassEscapeKind {
|
||||
impl<'new_alloc> CloneIn<'new_alloc> for CharacterClassEscapeKind {
|
||||
type Cloned = CharacterClassEscapeKind;
|
||||
fn clone_in(&self, _: &'alloc Allocator) -> Self::Cloned {
|
||||
|
||||
fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
|
||||
match self {
|
||||
Self::D => CharacterClassEscapeKind::D,
|
||||
Self::NegativeD => CharacterClassEscapeKind::NegativeD,
|
||||
@@ -308,7 +321,7 @@ impl<'alloc> CloneIn<'alloc> for CharacterClassEscapeKind {
|
||||
}
|
||||
}
|
||||
|
||||
fn clone_in_with_semantic_ids(&self, _: &'alloc Allocator) -> Self::Cloned {
|
||||
fn clone_in_with_semantic_ids(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
|
||||
match self {
|
||||
Self::D => CharacterClassEscapeKind::D,
|
||||
Self::NegativeD => CharacterClassEscapeKind::NegativeD,
|
||||
@@ -322,6 +335,7 @@ impl<'alloc> CloneIn<'alloc> for CharacterClassEscapeKind {
|
||||
|
||||
impl<'new_alloc> CloneIn<'new_alloc> for UnicodePropertyEscape<'_> {
|
||||
type Cloned = UnicodePropertyEscape<'new_alloc>;
|
||||
|
||||
fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
|
||||
UnicodePropertyEscape {
|
||||
span: CloneIn::clone_in(&self.span, allocator),
|
||||
@@ -343,19 +357,21 @@ impl<'new_alloc> CloneIn<'new_alloc> for UnicodePropertyEscape<'_> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'alloc> CloneIn<'alloc> for Dot {
|
||||
impl<'new_alloc> CloneIn<'new_alloc> for Dot {
|
||||
type Cloned = Dot;
|
||||
fn clone_in(&self, allocator: &'alloc Allocator) -> Self::Cloned {
|
||||
|
||||
fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
|
||||
Dot { span: CloneIn::clone_in(&self.span, allocator) }
|
||||
}
|
||||
|
||||
fn clone_in_with_semantic_ids(&self, allocator: &'alloc Allocator) -> Self::Cloned {
|
||||
fn clone_in_with_semantic_ids(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
|
||||
Dot { span: CloneIn::clone_in_with_semantic_ids(&self.span, allocator) }
|
||||
}
|
||||
}
|
||||
|
||||
impl<'new_alloc> CloneIn<'new_alloc> for CharacterClass<'_> {
|
||||
type Cloned = CharacterClass<'new_alloc>;
|
||||
|
||||
fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
|
||||
CharacterClass {
|
||||
span: CloneIn::clone_in(&self.span, allocator),
|
||||
@@ -377,9 +393,10 @@ impl<'new_alloc> CloneIn<'new_alloc> for CharacterClass<'_> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'alloc> CloneIn<'alloc> for CharacterClassContentsKind {
|
||||
impl<'new_alloc> CloneIn<'new_alloc> for CharacterClassContentsKind {
|
||||
type Cloned = CharacterClassContentsKind;
|
||||
fn clone_in(&self, _: &'alloc Allocator) -> Self::Cloned {
|
||||
|
||||
fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
|
||||
match self {
|
||||
Self::Union => CharacterClassContentsKind::Union,
|
||||
Self::Intersection => CharacterClassContentsKind::Intersection,
|
||||
@@ -387,7 +404,7 @@ impl<'alloc> CloneIn<'alloc> for CharacterClassContentsKind {
|
||||
}
|
||||
}
|
||||
|
||||
fn clone_in_with_semantic_ids(&self, _: &'alloc Allocator) -> Self::Cloned {
|
||||
fn clone_in_with_semantic_ids(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
|
||||
match self {
|
||||
Self::Union => CharacterClassContentsKind::Union,
|
||||
Self::Intersection => CharacterClassContentsKind::Intersection,
|
||||
@@ -398,6 +415,7 @@ impl<'alloc> CloneIn<'alloc> for CharacterClassContentsKind {
|
||||
|
||||
impl<'new_alloc> CloneIn<'new_alloc> for CharacterClassContents<'_> {
|
||||
type Cloned = CharacterClassContents<'new_alloc>;
|
||||
|
||||
fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
|
||||
match self {
|
||||
Self::CharacterClassRange(it) => {
|
||||
@@ -445,9 +463,10 @@ impl<'new_alloc> CloneIn<'new_alloc> for CharacterClassContents<'_> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'alloc> CloneIn<'alloc> for CharacterClassRange {
|
||||
impl<'new_alloc> CloneIn<'new_alloc> for CharacterClassRange {
|
||||
type Cloned = CharacterClassRange;
|
||||
fn clone_in(&self, allocator: &'alloc Allocator) -> Self::Cloned {
|
||||
|
||||
fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
|
||||
CharacterClassRange {
|
||||
span: CloneIn::clone_in(&self.span, allocator),
|
||||
min: CloneIn::clone_in(&self.min, allocator),
|
||||
@@ -455,7 +474,7 @@ impl<'alloc> CloneIn<'alloc> for CharacterClassRange {
|
||||
}
|
||||
}
|
||||
|
||||
fn clone_in_with_semantic_ids(&self, allocator: &'alloc Allocator) -> Self::Cloned {
|
||||
fn clone_in_with_semantic_ids(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
|
||||
CharacterClassRange {
|
||||
span: CloneIn::clone_in_with_semantic_ids(&self.span, allocator),
|
||||
min: CloneIn::clone_in_with_semantic_ids(&self.min, allocator),
|
||||
@@ -466,6 +485,7 @@ impl<'alloc> CloneIn<'alloc> for CharacterClassRange {
|
||||
|
||||
impl<'new_alloc> CloneIn<'new_alloc> for ClassStringDisjunction<'_> {
|
||||
type Cloned = ClassStringDisjunction<'new_alloc>;
|
||||
|
||||
fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
|
||||
ClassStringDisjunction {
|
||||
span: CloneIn::clone_in(&self.span, allocator),
|
||||
@@ -485,6 +505,7 @@ impl<'new_alloc> CloneIn<'new_alloc> for ClassStringDisjunction<'_> {
|
||||
|
||||
impl<'new_alloc> CloneIn<'new_alloc> for ClassString<'_> {
|
||||
type Cloned = ClassString<'new_alloc>;
|
||||
|
||||
fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
|
||||
ClassString {
|
||||
span: CloneIn::clone_in(&self.span, allocator),
|
||||
@@ -504,6 +525,7 @@ impl<'new_alloc> CloneIn<'new_alloc> for ClassString<'_> {
|
||||
|
||||
impl<'new_alloc> CloneIn<'new_alloc> for CapturingGroup<'_> {
|
||||
type Cloned = CapturingGroup<'new_alloc>;
|
||||
|
||||
fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
|
||||
CapturingGroup {
|
||||
span: CloneIn::clone_in(&self.span, allocator),
|
||||
@@ -523,6 +545,7 @@ impl<'new_alloc> CloneIn<'new_alloc> for CapturingGroup<'_> {
|
||||
|
||||
impl<'new_alloc> CloneIn<'new_alloc> for IgnoreGroup<'_> {
|
||||
type Cloned = IgnoreGroup<'new_alloc>;
|
||||
|
||||
fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
|
||||
IgnoreGroup {
|
||||
span: CloneIn::clone_in(&self.span, allocator),
|
||||
@@ -540,9 +563,10 @@ impl<'new_alloc> CloneIn<'new_alloc> for IgnoreGroup<'_> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'alloc> CloneIn<'alloc> for Modifiers {
|
||||
impl<'new_alloc> CloneIn<'new_alloc> for Modifiers {
|
||||
type Cloned = Modifiers;
|
||||
fn clone_in(&self, allocator: &'alloc Allocator) -> Self::Cloned {
|
||||
|
||||
fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
|
||||
Modifiers {
|
||||
span: CloneIn::clone_in(&self.span, allocator),
|
||||
enabling: CloneIn::clone_in(&self.enabling, allocator),
|
||||
@@ -550,7 +574,7 @@ impl<'alloc> CloneIn<'alloc> for Modifiers {
|
||||
}
|
||||
}
|
||||
|
||||
fn clone_in_with_semantic_ids(&self, allocator: &'alloc Allocator) -> Self::Cloned {
|
||||
fn clone_in_with_semantic_ids(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
|
||||
Modifiers {
|
||||
span: CloneIn::clone_in_with_semantic_ids(&self.span, allocator),
|
||||
enabling: CloneIn::clone_in_with_semantic_ids(&self.enabling, allocator),
|
||||
@@ -559,9 +583,10 @@ impl<'alloc> CloneIn<'alloc> for Modifiers {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'alloc> CloneIn<'alloc> for Modifier {
|
||||
impl<'new_alloc> CloneIn<'new_alloc> for Modifier {
|
||||
type Cloned = Modifier;
|
||||
fn clone_in(&self, allocator: &'alloc Allocator) -> Self::Cloned {
|
||||
|
||||
fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
|
||||
Modifier {
|
||||
ignore_case: CloneIn::clone_in(&self.ignore_case, allocator),
|
||||
multiline: CloneIn::clone_in(&self.multiline, allocator),
|
||||
@@ -569,7 +594,7 @@ impl<'alloc> CloneIn<'alloc> for Modifier {
|
||||
}
|
||||
}
|
||||
|
||||
fn clone_in_with_semantic_ids(&self, allocator: &'alloc Allocator) -> Self::Cloned {
|
||||
fn clone_in_with_semantic_ids(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
|
||||
Modifier {
|
||||
ignore_case: CloneIn::clone_in_with_semantic_ids(&self.ignore_case, allocator),
|
||||
multiline: CloneIn::clone_in_with_semantic_ids(&self.multiline, allocator),
|
||||
@@ -578,16 +603,17 @@ impl<'alloc> CloneIn<'alloc> for Modifier {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'alloc> CloneIn<'alloc> for IndexedReference {
|
||||
impl<'new_alloc> CloneIn<'new_alloc> for IndexedReference {
|
||||
type Cloned = IndexedReference;
|
||||
fn clone_in(&self, allocator: &'alloc Allocator) -> Self::Cloned {
|
||||
|
||||
fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
|
||||
IndexedReference {
|
||||
span: CloneIn::clone_in(&self.span, allocator),
|
||||
index: CloneIn::clone_in(&self.index, allocator),
|
||||
}
|
||||
}
|
||||
|
||||
fn clone_in_with_semantic_ids(&self, allocator: &'alloc Allocator) -> Self::Cloned {
|
||||
fn clone_in_with_semantic_ids(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
|
||||
IndexedReference {
|
||||
span: CloneIn::clone_in_with_semantic_ids(&self.span, allocator),
|
||||
index: CloneIn::clone_in_with_semantic_ids(&self.index, allocator),
|
||||
@@ -597,6 +623,7 @@ impl<'alloc> CloneIn<'alloc> for IndexedReference {
|
||||
|
||||
impl<'new_alloc> CloneIn<'new_alloc> for NamedReference<'_> {
|
||||
type Cloned = NamedReference<'new_alloc>;
|
||||
|
||||
fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
|
||||
NamedReference {
|
||||
span: CloneIn::clone_in(&self.span, allocator),
|
||||
|
||||
@@ -1,16 +1,17 @@
|
||||
// Auto-generated code, DO NOT EDIT DIRECTLY!
|
||||
// To edit this generated file you have to edit `tasks/ast_tools/src/derives/clone_in.rs`
|
||||
|
||||
#![allow(clippy::default_trait_access)]
|
||||
#![allow(unused_variables, clippy::default_trait_access)]
|
||||
|
||||
use oxc_allocator::{Allocator, CloneIn};
|
||||
|
||||
use crate::number::*;
|
||||
use crate::operator::*;
|
||||
|
||||
impl<'alloc> CloneIn<'alloc> for NumberBase {
|
||||
impl<'new_alloc> CloneIn<'new_alloc> for NumberBase {
|
||||
type Cloned = NumberBase;
|
||||
fn clone_in(&self, _: &'alloc Allocator) -> Self::Cloned {
|
||||
|
||||
fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
|
||||
match self {
|
||||
Self::Float => NumberBase::Float,
|
||||
Self::Decimal => NumberBase::Decimal,
|
||||
@@ -20,7 +21,7 @@ impl<'alloc> CloneIn<'alloc> for NumberBase {
|
||||
}
|
||||
}
|
||||
|
||||
fn clone_in_with_semantic_ids(&self, _: &'alloc Allocator) -> Self::Cloned {
|
||||
fn clone_in_with_semantic_ids(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
|
||||
match self {
|
||||
Self::Float => NumberBase::Float,
|
||||
Self::Decimal => NumberBase::Decimal,
|
||||
@@ -31,9 +32,10 @@ impl<'alloc> CloneIn<'alloc> for NumberBase {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'alloc> CloneIn<'alloc> for BigintBase {
|
||||
impl<'new_alloc> CloneIn<'new_alloc> for BigintBase {
|
||||
type Cloned = BigintBase;
|
||||
fn clone_in(&self, _: &'alloc Allocator) -> Self::Cloned {
|
||||
|
||||
fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
|
||||
match self {
|
||||
Self::Decimal => BigintBase::Decimal,
|
||||
Self::Binary => BigintBase::Binary,
|
||||
@@ -42,7 +44,7 @@ impl<'alloc> CloneIn<'alloc> for BigintBase {
|
||||
}
|
||||
}
|
||||
|
||||
fn clone_in_with_semantic_ids(&self, _: &'alloc Allocator) -> Self::Cloned {
|
||||
fn clone_in_with_semantic_ids(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
|
||||
match self {
|
||||
Self::Decimal => BigintBase::Decimal,
|
||||
Self::Binary => BigintBase::Binary,
|
||||
@@ -52,9 +54,10 @@ impl<'alloc> CloneIn<'alloc> for BigintBase {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'alloc> CloneIn<'alloc> for AssignmentOperator {
|
||||
impl<'new_alloc> CloneIn<'new_alloc> for AssignmentOperator {
|
||||
type Cloned = AssignmentOperator;
|
||||
fn clone_in(&self, _: &'alloc Allocator) -> Self::Cloned {
|
||||
|
||||
fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
|
||||
match self {
|
||||
Self::Assign => AssignmentOperator::Assign,
|
||||
Self::Addition => AssignmentOperator::Addition,
|
||||
@@ -75,7 +78,7 @@ impl<'alloc> CloneIn<'alloc> for AssignmentOperator {
|
||||
}
|
||||
}
|
||||
|
||||
fn clone_in_with_semantic_ids(&self, _: &'alloc Allocator) -> Self::Cloned {
|
||||
fn clone_in_with_semantic_ids(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
|
||||
match self {
|
||||
Self::Assign => AssignmentOperator::Assign,
|
||||
Self::Addition => AssignmentOperator::Addition,
|
||||
@@ -97,9 +100,10 @@ impl<'alloc> CloneIn<'alloc> for AssignmentOperator {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'alloc> CloneIn<'alloc> for BinaryOperator {
|
||||
impl<'new_alloc> CloneIn<'new_alloc> for BinaryOperator {
|
||||
type Cloned = BinaryOperator;
|
||||
fn clone_in(&self, _: &'alloc Allocator) -> Self::Cloned {
|
||||
|
||||
fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
|
||||
match self {
|
||||
Self::Equality => BinaryOperator::Equality,
|
||||
Self::Inequality => BinaryOperator::Inequality,
|
||||
@@ -126,7 +130,7 @@ impl<'alloc> CloneIn<'alloc> for BinaryOperator {
|
||||
}
|
||||
}
|
||||
|
||||
fn clone_in_with_semantic_ids(&self, _: &'alloc Allocator) -> Self::Cloned {
|
||||
fn clone_in_with_semantic_ids(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
|
||||
match self {
|
||||
Self::Equality => BinaryOperator::Equality,
|
||||
Self::Inequality => BinaryOperator::Inequality,
|
||||
@@ -154,9 +158,10 @@ impl<'alloc> CloneIn<'alloc> for BinaryOperator {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'alloc> CloneIn<'alloc> for LogicalOperator {
|
||||
impl<'new_alloc> CloneIn<'new_alloc> for LogicalOperator {
|
||||
type Cloned = LogicalOperator;
|
||||
fn clone_in(&self, _: &'alloc Allocator) -> Self::Cloned {
|
||||
|
||||
fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
|
||||
match self {
|
||||
Self::Or => LogicalOperator::Or,
|
||||
Self::And => LogicalOperator::And,
|
||||
@@ -164,7 +169,7 @@ impl<'alloc> CloneIn<'alloc> for LogicalOperator {
|
||||
}
|
||||
}
|
||||
|
||||
fn clone_in_with_semantic_ids(&self, _: &'alloc Allocator) -> Self::Cloned {
|
||||
fn clone_in_with_semantic_ids(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
|
||||
match self {
|
||||
Self::Or => LogicalOperator::Or,
|
||||
Self::And => LogicalOperator::And,
|
||||
@@ -173,9 +178,10 @@ impl<'alloc> CloneIn<'alloc> for LogicalOperator {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'alloc> CloneIn<'alloc> for UnaryOperator {
|
||||
impl<'new_alloc> CloneIn<'new_alloc> for UnaryOperator {
|
||||
type Cloned = UnaryOperator;
|
||||
fn clone_in(&self, _: &'alloc Allocator) -> Self::Cloned {
|
||||
|
||||
fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
|
||||
match self {
|
||||
Self::UnaryPlus => UnaryOperator::UnaryPlus,
|
||||
Self::UnaryNegation => UnaryOperator::UnaryNegation,
|
||||
@@ -187,7 +193,7 @@ impl<'alloc> CloneIn<'alloc> for UnaryOperator {
|
||||
}
|
||||
}
|
||||
|
||||
fn clone_in_with_semantic_ids(&self, _: &'alloc Allocator) -> Self::Cloned {
|
||||
fn clone_in_with_semantic_ids(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
|
||||
match self {
|
||||
Self::UnaryPlus => UnaryOperator::UnaryPlus,
|
||||
Self::UnaryNegation => UnaryOperator::UnaryNegation,
|
||||
@@ -200,16 +206,17 @@ impl<'alloc> CloneIn<'alloc> for UnaryOperator {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'alloc> CloneIn<'alloc> for UpdateOperator {
|
||||
impl<'new_alloc> CloneIn<'new_alloc> for UpdateOperator {
|
||||
type Cloned = UpdateOperator;
|
||||
fn clone_in(&self, _: &'alloc Allocator) -> Self::Cloned {
|
||||
|
||||
fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
|
||||
match self {
|
||||
Self::Increment => UpdateOperator::Increment,
|
||||
Self::Decrement => UpdateOperator::Decrement,
|
||||
}
|
||||
}
|
||||
|
||||
fn clone_in_with_semantic_ids(&self, _: &'alloc Allocator) -> Self::Cloned {
|
||||
fn clone_in_with_semantic_ids(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
|
||||
match self {
|
||||
Self::Increment => UpdateOperator::Increment,
|
||||
Self::Decrement => UpdateOperator::Decrement,
|
||||
|
||||
@@ -7,7 +7,6 @@ use syn::Ident;
|
||||
use crate::{
|
||||
Result,
|
||||
schema::{Def, EnumDef, FieldDef, Schema, StructDef, TypeDef},
|
||||
utils::create_safe_ident,
|
||||
};
|
||||
|
||||
use super::{
|
||||
@@ -59,7 +58,7 @@ impl Derive for DeriveCloneIn {
|
||||
|
||||
fn prelude(&self) -> TokenStream {
|
||||
quote! {
|
||||
#![allow(clippy::default_trait_access)]
|
||||
#![allow(unused_variables, clippy::default_trait_access)]
|
||||
|
||||
///@@line_break
|
||||
use oxc_allocator::{Allocator, CloneIn};
|
||||
@@ -83,7 +82,7 @@ fn derive_struct(struct_def: &StructDef, schema: &Schema) -> TokenStream {
|
||||
|
||||
let type_ident = struct_def.ident();
|
||||
let has_fields = !struct_def.fields.is_empty();
|
||||
let body = if has_fields {
|
||||
let clone_in_body = if has_fields {
|
||||
let fields = struct_def.fields.iter().map(|field| {
|
||||
let field_ident = field.ident();
|
||||
if struct_field_is_default(field, schema) {
|
||||
@@ -109,10 +108,9 @@ fn derive_struct(struct_def: &StructDef, schema: &Schema) -> TokenStream {
|
||||
|
||||
generate_impl(
|
||||
&type_ident,
|
||||
&body,
|
||||
&clone_in_body,
|
||||
&clone_in_with_semantic_ids_body,
|
||||
struct_def.has_lifetime,
|
||||
has_fields,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -142,36 +140,31 @@ fn derive_enum(enum_def: &EnumDef, schema: &Schema) -> TokenStream {
|
||||
);
|
||||
|
||||
let type_ident = enum_def.ident();
|
||||
let mut uses_allocator = false;
|
||||
let match_arms = enum_def.all_variants(schema).map(|variant| {
|
||||
let ident = variant.ident();
|
||||
if variant.is_fieldless() {
|
||||
quote!( Self::#ident => #type_ident::#ident )
|
||||
} else {
|
||||
uses_allocator = true;
|
||||
quote!( Self::#ident(it) => #type_ident::#ident(CloneIn::clone_in(it, allocator)) )
|
||||
}
|
||||
});
|
||||
|
||||
let clone_in_with_semantic_ids_match_arms = enum_def.all_variants(schema).map(|variant| {
|
||||
let ident = variant.ident();
|
||||
if variant.is_fieldless() {
|
||||
quote!( Self::#ident => #type_ident::#ident )
|
||||
} else {
|
||||
// does not needs mutate `uses_allocator` since it should be the same as `clone_in`
|
||||
quote!( Self::#ident(it) => #type_ident::#ident(CloneIn::clone_in_with_semantic_ids(it, allocator)) )
|
||||
}
|
||||
});
|
||||
|
||||
let clone_in_body = quote! {
|
||||
match self {
|
||||
#(#match_arms),*
|
||||
}
|
||||
};
|
||||
|
||||
let match_arms = enum_def.all_variants(schema).map(|variant| {
|
||||
let ident = variant.ident();
|
||||
if variant.is_fieldless() {
|
||||
quote!( Self::#ident => #type_ident::#ident )
|
||||
} else {
|
||||
quote!( Self::#ident(it) => #type_ident::#ident(CloneIn::clone_in_with_semantic_ids(it, allocator)) )
|
||||
}
|
||||
});
|
||||
let clone_in_with_semantic_ids_body = quote! {
|
||||
match self {
|
||||
#(#clone_in_with_semantic_ids_match_arms),*
|
||||
#(#match_arms),*
|
||||
}
|
||||
};
|
||||
|
||||
@@ -180,7 +173,6 @@ fn derive_enum(enum_def: &EnumDef, schema: &Schema) -> TokenStream {
|
||||
&clone_in_body,
|
||||
&clone_in_with_semantic_ids_body,
|
||||
enum_def.has_lifetime,
|
||||
uses_allocator,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -189,35 +181,22 @@ fn generate_impl(
|
||||
clone_in_body: &TokenStream,
|
||||
clone_in_with_semantic_ids_body: &TokenStream,
|
||||
has_lifetime: bool,
|
||||
uses_allocator: bool,
|
||||
) -> TokenStream {
|
||||
let alloc_ident = create_safe_ident(if uses_allocator { "allocator" } else { "_" });
|
||||
let (from_lifetime, to_lifetime) =
|
||||
if has_lifetime { (quote!( <'_> ), quote!( <'new_alloc> )) } else { (quote!(), quote!()) };
|
||||
|
||||
if has_lifetime {
|
||||
quote! {
|
||||
impl<'new_alloc> CloneIn<'new_alloc> for #type_ident<'_> {
|
||||
type Cloned = #type_ident<'new_alloc>;
|
||||
fn clone_in(&self, #alloc_ident: &'new_alloc Allocator) -> Self::Cloned {
|
||||
#clone_in_body
|
||||
}
|
||||
///@@line_break
|
||||
fn clone_in_with_semantic_ids(&self, #alloc_ident: &'new_alloc Allocator) -> Self::Cloned {
|
||||
#clone_in_with_semantic_ids_body
|
||||
}
|
||||
quote! {
|
||||
impl<'new_alloc> CloneIn<'new_alloc> for #type_ident #from_lifetime {
|
||||
type Cloned = #type_ident #to_lifetime;
|
||||
|
||||
///@@line_break
|
||||
fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
|
||||
#clone_in_body
|
||||
}
|
||||
}
|
||||
} else {
|
||||
quote! {
|
||||
impl<'alloc> CloneIn<'alloc> for #type_ident {
|
||||
type Cloned = #type_ident;
|
||||
fn clone_in(&self, #alloc_ident: &'alloc Allocator) -> Self::Cloned {
|
||||
#clone_in_body
|
||||
}
|
||||
|
||||
///@@line_break
|
||||
fn clone_in_with_semantic_ids(&self, #alloc_ident: &'alloc Allocator) -> Self::Cloned {
|
||||
#clone_in_with_semantic_ids_body
|
||||
}
|
||||
///@@line_break
|
||||
fn clone_in_with_semantic_ids(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
|
||||
#clone_in_with_semantic_ids_body
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user