Vendor things

This commit is contained in:
John Doty 2024-03-08 11:03:01 -08:00
parent 5deceec006
commit 977e3c17e5
19434 changed files with 10682014 additions and 0 deletions

View file

@ -0,0 +1,24 @@
use serde_json::from_str;
use swc_common::ast_serde;
#[ast_serde]
#[derive(Debug, PartialEq, Eq)]
pub enum Ambiguous {
#[tag("A")]
A(A),
#[tag("B")]
B(B),
}
#[ast_serde("B")]
#[derive(Debug, PartialEq, Eq)]
pub struct A {}
#[ast_serde("B")]
#[derive(Debug, PartialEq, Eq)]
pub struct B {}
#[test]
fn deserialize() {
assert_eq!(A {}, from_str(r#"{"type": "A"}"#).unwrap());
assert_eq!(B {}, from_str(r#"{"type": "B"}"#).unwrap());
}

View file

@ -0,0 +1,38 @@
//! Test that `#[span]` and `#[fold]` can be used at same time.
use serde::{self, Deserialize, Serialize};
use swc_common::{self, ast_node, Span, Spanned};
#[ast_node("Class")]
// See https://github.com/rust-lang/rust/issues/44925
pub struct Class {
#[span]
pub has_span: HasSpan,
pub s: String,
}
#[ast_node("Tuple")]
pub struct Tuple(#[span] HasSpan, usize, usize);
#[derive(Debug, Clone, PartialEq, Eq, Spanned, Serialize, Deserialize)]
#[cfg_attr(
any(feature = "rkyv-impl"),
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
)]
#[cfg_attr(
any(feature = "rkyv-impl"),
archive(bound(serialize = "__S: rkyv::ser::Serializer + rkyv::ser::ScratchSpace"))
)]
#[cfg_attr(feature = "rkyv-impl", archive(check_bytes))]
#[cfg_attr(feature = "rkyv-impl", archive_attr(repr(C)))]
pub struct HasSpan {
#[cfg_attr(feature = "__rkyv", omit_bounds)]
pub span: Span,
}
#[ast_node]
pub enum Node {
#[tag("Class")]
Class(Class),
#[tag("Tuple")]
Tuple(Tuple),
}

View file

@ -0,0 +1 @@
const foo = 1;

View file

@ -0,0 +1,41 @@
#![cfg(feature = "concurrent")]
use std::{env, path::PathBuf, sync::Arc};
use rayon::prelude::*;
use swc_common::{sync::Lrc, FilePathMapping, SourceFile, SourceMap};
#[test]
fn no_overlap() {
let cm = Lrc::new(SourceMap::new(FilePathMapping::empty()));
let files: Vec<Lrc<SourceFile>> = (0..100000)
.into_par_iter()
.map(|_| {
cm.load_file(
&PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap())
.join("tests")
.join("concurrent.js"),
)
.unwrap()
})
.collect::<Vec<_>>();
// This actually tests if there is overlap
let mut start = files.clone();
start.sort_by_key(|f| f.start_pos);
let mut end = files;
end.sort_by_key(|f| f.end_pos);
start
.into_par_iter()
.zip(end)
.for_each(|(start, end): (Arc<SourceFile>, Arc<SourceFile>)| {
assert_eq!(start.start_pos, end.start_pos);
assert_eq!(start.end_pos, end.end_pos);
assert!(start.start_pos < start.end_pos);
cm.lookup_char_pos(start.start_pos);
});
}

View file

@ -0,0 +1,6 @@
use swc_common::*;
pub struct Struct {}
#[derive(FromVariant)]
pub enum Enum {}

View file

@ -0,0 +1,9 @@
use swc_common::ast_serde;
#[ast_serde]
pub enum Message {
#[tag("Request")]
Request(String),
#[tag("Response")]
Response(u8),
}

View file

@ -0,0 +1,38 @@
#![cfg(feature = "concurrent")]
use rayon::{prelude::*, ThreadPoolBuilder};
use swc_common::{FileName, FilePathMapping, SourceMap};
#[test]
fn stress() {
let _ = ThreadPoolBuilder::new().num_threads(100).build_global();
let fm = SourceMap::new(FilePathMapping::empty());
(0..10000).into_par_iter().for_each(|_| {
fm.new_source_file(
FileName::Anon,
"@Entity()
export class Product extends TimestampedEntity {
@PrimaryGeneratedColumn('uuid')
public id!: string;
@Column()
public price!: number;
@Column({ enum: ProductType })
public type!: ProductType;
@Column()
public productEntityId!: string;
/* ANCHOR: Relations ------------------------------------------------------ */
@OneToMany(() => Order, (order) => order.product)
public orders!: Order[];
@OneToMany(() => Discount, (discount) => discount.product)
public discounts!: Discount[];
}"
.into(),
);
})
}

View file

@ -0,0 +1,19 @@
use swc_common::{BytePos, Span, Spanned};
#[test]
fn lo_hi() {
#[derive(Spanned)]
struct LoHi {
#[span(lo)]
pub lo: BytePos,
#[span(hi)]
pub hi: BytePos,
}
let lo = BytePos(0);
let hi = BytePos(5);
assert_eq!(
LoHi { lo, hi }.span(),
Span::new(lo, hi, Default::default())
);
}