From 7ea058d84fa3d581b9cbf4916dd8a714c971232b Mon Sep 17 00:00:00 2001 From: overlookmotel <557937+overlookmotel@users.noreply.github.com> Date: Thu, 8 Aug 2024 17:28:58 +0000 Subject: [PATCH] refactor(ast_codegen): replace Windows-style line breaks with Unix-style (#4769) 2 files in AST codegen had Windows-style CRLF line breaks. Change them to Unix-style LF. Does not alter contents of the files aside from the line breaks. --- crates/oxc_ast_macros/src/lib.rs | 168 +++++++++++++++---------------- crates/oxc_macros/src/lib.rs | 116 ++++++++++----------- 2 files changed, 142 insertions(+), 142 deletions(-) diff --git a/crates/oxc_ast_macros/src/lib.rs b/crates/oxc_ast_macros/src/lib.rs index eff30de0943b9..c74cb402dba36 100644 --- a/crates/oxc_ast_macros/src/lib.rs +++ b/crates/oxc_ast_macros/src/lib.rs @@ -1,84 +1,84 @@ -use proc_macro::TokenStream; -use proc_macro2::TokenStream as TokenStream2; -use quote::quote; - -/// returns `#[repr(C, u8)]` if `enum_` has any non-unit variant, -/// Otherwise it would return `#[repr(u8)]`. -fn enum_repr(enum_: &syn::ItemEnum) -> TokenStream2 { - if enum_.variants.iter().any(|var| !matches!(var.fields, syn::Fields::Unit)) { - quote!(#[repr(C, u8)]) - } else { - quote!(#[repr(u8)]) - } -} - -/// This attribute serves two purposes, -/// First, it is a marker for our codegen to detect AST types. Furthermore. -/// It is also a lightweight macro; All of its computation is cached and -/// it only applies the following changes without any complex operation: -/// -/// * Prepend `#[repr(C)]` to structs -/// * Prepend `#[repr(C, u8)]` to fieldful enums e.g. `enum E { X: u32, Y: u8 }` -/// * Prepend `#[repr(u8)]` to unit (fieldless) enums e.g. `enum E { X, Y, Z, }` -/// * Prepend `#[derive(oxc_ast_macros::Ast)]` to all structs and enums -/// -#[proc_macro_attribute] -#[allow(clippy::missing_panics_doc)] -pub fn ast(_args: TokenStream, input: TokenStream) -> TokenStream { - let input = syn::parse_macro_input!(input as syn::Item); - - let repr = match input { - syn::Item::Enum(ref enum_) => enum_repr(enum_), - syn::Item::Struct(_) => quote!(#[repr(C)]), - - _ => { - unreachable!() - } - }; - - let expanded = quote! { - #[derive(::oxc_ast_macros::Ast)] - #repr - #input - }; - TokenStream::from(expanded) -} - -/// Dummy derive macro for a non-existent trait `Ast`. -/// -/// Does not generate any code. -/// Only purpose is to allow using `#[scope]`, `#[visit]`, and other attrs in the AST node type defs. -/// These "marker" attributes are used in codegen. -#[proc_macro_derive(Ast, attributes(scope, visit, span, serde, tsify, generate_derive))] -pub fn ast_derive(_item: TokenStream) -> TokenStream { - TokenStream::new() -} - -/// Derive macro generating an impl of the trait `CloneIn`. -/// -/// NOTE: This is an internal macro! -/// # Panics -/// -#[proc_macro_derive(CloneIn)] -pub fn derive_clone_in(item: TokenStream) -> TokenStream { - let item = syn::parse_macro_input!(item as syn::Item); - match &item { - syn::Item::Struct(syn::ItemStruct { ident, generics, .. }) - | syn::Item::Enum(syn::ItemEnum { ident, generics, .. }) - if generics.params.is_empty() => - { - quote! { - #[automatically_derived] - impl<'alloc> ::oxc_allocator::CloneIn<'alloc> for #ident { - type Cloned = #ident; - - fn clone_in(&self, _: &'alloc ::oxc_allocator::Allocator) -> Self::Cloned { - std::clone::Clone::clone(self) - } - } - } - .into() - } - _ => panic!("At the moment `CloneIn` derive macro only works for types without lifetimes and/or generic params"), - } -} +use proc_macro::TokenStream; +use proc_macro2::TokenStream as TokenStream2; +use quote::quote; + +/// returns `#[repr(C, u8)]` if `enum_` has any non-unit variant, +/// Otherwise it would return `#[repr(u8)]`. +fn enum_repr(enum_: &syn::ItemEnum) -> TokenStream2 { + if enum_.variants.iter().any(|var| !matches!(var.fields, syn::Fields::Unit)) { + quote!(#[repr(C, u8)]) + } else { + quote!(#[repr(u8)]) + } +} + +/// This attribute serves two purposes, +/// First, it is a marker for our codegen to detect AST types. Furthermore. +/// It is also a lightweight macro; All of its computation is cached and +/// it only applies the following changes without any complex operation: +/// +/// * Prepend `#[repr(C)]` to structs +/// * Prepend `#[repr(C, u8)]` to fieldful enums e.g. `enum E { X: u32, Y: u8 }` +/// * Prepend `#[repr(u8)]` to unit (fieldless) enums e.g. `enum E { X, Y, Z, }` +/// * Prepend `#[derive(oxc_ast_macros::Ast)]` to all structs and enums +/// +#[proc_macro_attribute] +#[allow(clippy::missing_panics_doc)] +pub fn ast(_args: TokenStream, input: TokenStream) -> TokenStream { + let input = syn::parse_macro_input!(input as syn::Item); + + let repr = match input { + syn::Item::Enum(ref enum_) => enum_repr(enum_), + syn::Item::Struct(_) => quote!(#[repr(C)]), + + _ => { + unreachable!() + } + }; + + let expanded = quote! { + #[derive(::oxc_ast_macros::Ast)] + #repr + #input + }; + TokenStream::from(expanded) +} + +/// Dummy derive macro for a non-existent trait `Ast`. +/// +/// Does not generate any code. +/// Only purpose is to allow using `#[scope]`, `#[visit]`, and other attrs in the AST node type defs. +/// These "marker" attributes are used in codegen. +#[proc_macro_derive(Ast, attributes(scope, visit, span, serde, tsify, generate_derive))] +pub fn ast_derive(_item: TokenStream) -> TokenStream { + TokenStream::new() +} + +/// Derive macro generating an impl of the trait `CloneIn`. +/// +/// NOTE: This is an internal macro! +/// # Panics +/// +#[proc_macro_derive(CloneIn)] +pub fn derive_clone_in(item: TokenStream) -> TokenStream { + let item = syn::parse_macro_input!(item as syn::Item); + match &item { + syn::Item::Struct(syn::ItemStruct { ident, generics, .. }) + | syn::Item::Enum(syn::ItemEnum { ident, generics, .. }) + if generics.params.is_empty() => + { + quote! { + #[automatically_derived] + impl<'alloc> ::oxc_allocator::CloneIn<'alloc> for #ident { + type Cloned = #ident; + + fn clone_in(&self, _: &'alloc ::oxc_allocator::Allocator) -> Self::Cloned { + std::clone::Clone::clone(self) + } + } + } + .into() + } + _ => panic!("At the moment `CloneIn` derive macro only works for types without lifetimes and/or generic params"), + } +} diff --git a/crates/oxc_macros/src/lib.rs b/crates/oxc_macros/src/lib.rs index 9f3a1a1179517..d26473968f70e 100644 --- a/crates/oxc_macros/src/lib.rs +++ b/crates/oxc_macros/src/lib.rs @@ -1,58 +1,58 @@ -use proc_macro::TokenStream; -use syn::parse_macro_input; - -mod declare_all_lint_rules; -mod declare_oxc_lint; - -/// Macro used to declare an oxc lint rule -/// -/// Every lint declaration consists of 2 parts: -/// -/// 1. The documentation -/// 2. The lint's struct -/// -/// # Example -/// -/// ``` -/// use oxc_macros::declare_oxc_lint; -/// -/// declare_oxc_lint! { -/// /// ### What it does -/// /// Checks for usage of the `debugger` statement -/// /// -/// /// ### Why is this bad? -/// /// `debugger` statements do not affect functionality when a debugger isn't attached. -/// /// They're most commonly an accidental debugging leftover. -/// /// -/// /// -/// /// ### Example -/// /// ```javascript -/// /// const data = await getData(); -/// /// const result = complexCalculation(data); -/// /// debugger; -/// /// ``` -/// /// -/// /// ``` -/// pub struct NoDebugger -/// } -/// ``` -#[proc_macro] -pub fn declare_oxc_lint(input: TokenStream) -> TokenStream { - let metadata = parse_macro_input!(input as declare_oxc_lint::LintRuleMeta); - declare_oxc_lint::declare_oxc_lint(metadata) -} - -/// Same as `declare_oxc_lint`, but doesn't do imports. -/// Enables multiple usages in a single file. -#[proc_macro] -pub fn declare_oxc_lint_test(input: TokenStream) -> TokenStream { - let mut metadata = parse_macro_input!(input as declare_oxc_lint::LintRuleMeta); - metadata.used_in_test = true; - declare_oxc_lint::declare_oxc_lint(metadata) -} - -#[proc_macro] -pub fn declare_all_lint_rules(input: TokenStream) -> TokenStream { - let metadata = parse_macro_input!(input as declare_all_lint_rules::AllLintRulesMeta); - declare_all_lint_rules::declare_all_lint_rules(metadata) -} +use proc_macro::TokenStream; +use syn::parse_macro_input; + +mod declare_all_lint_rules; +mod declare_oxc_lint; + +/// Macro used to declare an oxc lint rule +/// +/// Every lint declaration consists of 2 parts: +/// +/// 1. The documentation +/// 2. The lint's struct +/// +/// # Example +/// +/// ``` +/// use oxc_macros::declare_oxc_lint; +/// +/// declare_oxc_lint! { +/// /// ### What it does +/// /// Checks for usage of the `debugger` statement +/// /// +/// /// ### Why is this bad? +/// /// `debugger` statements do not affect functionality when a debugger isn't attached. +/// /// They're most commonly an accidental debugging leftover. +/// /// +/// /// +/// /// ### Example +/// /// ```javascript +/// /// const data = await getData(); +/// /// const result = complexCalculation(data); +/// /// debugger; +/// /// ``` +/// /// +/// /// ``` +/// pub struct NoDebugger +/// } +/// ``` +#[proc_macro] +pub fn declare_oxc_lint(input: TokenStream) -> TokenStream { + let metadata = parse_macro_input!(input as declare_oxc_lint::LintRuleMeta); + declare_oxc_lint::declare_oxc_lint(metadata) +} + +/// Same as `declare_oxc_lint`, but doesn't do imports. +/// Enables multiple usages in a single file. +#[proc_macro] +pub fn declare_oxc_lint_test(input: TokenStream) -> TokenStream { + let mut metadata = parse_macro_input!(input as declare_oxc_lint::LintRuleMeta); + metadata.used_in_test = true; + declare_oxc_lint::declare_oxc_lint(metadata) +} + +#[proc_macro] +pub fn declare_all_lint_rules(input: TokenStream) -> TokenStream { + let metadata = parse_macro_input!(input as declare_all_lint_rules::AllLintRulesMeta); + declare_all_lint_rules::declare_all_lint_rules(metadata) +}