Vendor things
This commit is contained in:
parent
5deceec006
commit
977e3c17e5
19434 changed files with 10682014 additions and 0 deletions
1
third-party/vendor/swc_config_macro/.cargo-checksum.json
vendored
Normal file
1
third-party/vendor/swc_config_macro/.cargo-checksum.json
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
{"files":{"Cargo.toml":"09a9806e3df8e8534d8de0fd4e5490b530dfdfc72ac8f4f2a697a1cc4c96d579","src/lib.rs":"dd5b0a5e639c6e0529e57dffc7f81e25ba2dd8cc515840af38466d9dce3c6357","src/merge.rs":"ea0ff0d432a0f804569b4640b73466aef8f2c44959b9ba97f841060f22b683e3"},"package":"e5b5aaca9a0082be4515f0fbbecc191bf5829cd25b5b9c0a2810f6a2bb0d6829"}
|
||||
40
third-party/vendor/swc_config_macro/Cargo.toml
vendored
Normal file
40
third-party/vendor/swc_config_macro/Cargo.toml
vendored
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO
|
||||
#
|
||||
# When uploading crates to the registry Cargo will automatically
|
||||
# "normalize" Cargo.toml files for maximal compatibility
|
||||
# with all versions of Cargo and also rewrite `path` dependencies
|
||||
# to registry (e.g., crates.io) dependencies.
|
||||
#
|
||||
# If you are reading this file be aware that the original Cargo.toml
|
||||
# will likely look very different (and much more reasonable).
|
||||
# See Cargo.toml.orig for the original contents.
|
||||
|
||||
[package]
|
||||
edition = "2021"
|
||||
name = "swc_config_macro"
|
||||
version = "0.1.2"
|
||||
authors = ["강동윤 <kdy1997.dev@gmail.com>"]
|
||||
description = "Macros to prevent mistakes"
|
||||
documentation = "https://rustdoc.swc.rs/swc_config_macro/"
|
||||
license = "Apache-2.0"
|
||||
repository = "https://github.com/swc-project/swc.git"
|
||||
resolver = "1"
|
||||
|
||||
[lib]
|
||||
bench = false
|
||||
proc-macro = true
|
||||
|
||||
[dependencies.pmutil]
|
||||
version = "0.6.1"
|
||||
|
||||
[dependencies.proc-macro2]
|
||||
version = "1"
|
||||
|
||||
[dependencies.quote]
|
||||
version = "1"
|
||||
|
||||
[dependencies.swc_macros_common]
|
||||
version = "0.3.8"
|
||||
|
||||
[dependencies.syn]
|
||||
version = "2"
|
||||
10
third-party/vendor/swc_config_macro/src/lib.rs
vendored
Normal file
10
third-party/vendor/swc_config_macro/src/lib.rs
vendored
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
extern crate proc_macro;
|
||||
|
||||
mod merge;
|
||||
|
||||
#[proc_macro_derive(Merge)]
|
||||
pub fn derive_merge(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
|
||||
let input = syn::parse(input).expect("failed to parse input as DeriveInput");
|
||||
|
||||
self::merge::expand(input).into()
|
||||
}
|
||||
64
third-party/vendor/swc_config_macro/src/merge.rs
vendored
Normal file
64
third-party/vendor/swc_config_macro/src/merge.rs
vendored
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
use pmutil::{q, SpanExt};
|
||||
use proc_macro2::TokenStream;
|
||||
use quote::ToTokens;
|
||||
use swc_macros_common::{access_field, join_stmts};
|
||||
use syn::{DeriveInput, Expr, Field, Fields, Stmt};
|
||||
|
||||
pub fn expand(input: DeriveInput) -> TokenStream {
|
||||
match &input.data {
|
||||
syn::Data::Struct(s) => {
|
||||
let body = call_merge_for_fields(&q!({ self }), &s.fields);
|
||||
let body = join_stmts(&body);
|
||||
|
||||
q!(
|
||||
Vars {
|
||||
Type: &input.ident,
|
||||
body
|
||||
},
|
||||
{
|
||||
#[automatically_derived]
|
||||
impl swc_config::merge::Merge for Type {
|
||||
fn merge(&mut self, _other: Self) {
|
||||
body
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
.into()
|
||||
}
|
||||
syn::Data::Enum(_) => unimplemented!("derive(Merge) does not support an enum"),
|
||||
syn::Data::Union(_) => unimplemented!("derive(Merge) does not support a union"),
|
||||
}
|
||||
}
|
||||
|
||||
fn call_merge_for_fields(obj: &dyn ToTokens, fields: &Fields) -> Vec<Stmt> {
|
||||
fn call_merge(obj: &dyn ToTokens, idx: usize, f: &Field) -> Expr {
|
||||
let r = q!({ _other });
|
||||
q!(
|
||||
Vars {
|
||||
l: access_field(obj, idx, f),
|
||||
r: access_field(&r, idx, f),
|
||||
},
|
||||
{ swc_config::merge::Merge::merge(&mut l, r) }
|
||||
)
|
||||
.parse()
|
||||
}
|
||||
|
||||
match fields {
|
||||
Fields::Named(fs) => fs
|
||||
.named
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(idx, f)| call_merge(obj, idx, f))
|
||||
.map(|expr| Stmt::Expr(expr, Some(fs.brace_token.span.join().as_token())))
|
||||
.collect(),
|
||||
Fields::Unnamed(fs) => fs
|
||||
.unnamed
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(idx, f)| call_merge(obj, idx, f))
|
||||
.map(|expr| Stmt::Expr(expr, Some(fs.paren_token.span.join().as_token())))
|
||||
.collect(),
|
||||
Fields::Unit => unimplemented!("derive(Merge) does not support a unit struct"),
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue