mirror of
https://github.com/swc-project/swc.git
synced 2024-12-25 22:56:11 +03:00
feat(es/decorators): Groundwork for stage 3 decorator (#9450)
**Description:** I decided to port the babel transform instead of recreating a new pass using inputs and outputs. Babel transform reuses many codes, and this is the basic API for decorator passes that share the implementation.
This commit is contained in:
parent
673655c169
commit
238ba8b1d2
7
.changeset/rare-plants-shout.md
Normal file
7
.changeset/rare-plants-shout.md
Normal file
@ -0,0 +1,7 @@
|
||||
---
|
||||
swc_core: patch
|
||||
swc_ecma_ast: patch
|
||||
swc_ecma_transforms_proposal: patch
|
||||
---
|
||||
|
||||
feat(es/decorators): Groundwork for stage 3 decorator
|
@ -687,6 +687,7 @@ impl Options {
|
||||
DecoratorVersion::V202203 => Box::new(
|
||||
swc_ecma_transforms::proposals::decorator_2022_03::decorator_2022_03(),
|
||||
),
|
||||
DecoratorVersion::V202311 => todo!("2023-11 decorator"),
|
||||
};
|
||||
|
||||
Box::new(chain!(
|
||||
|
@ -90,7 +90,7 @@ impl Take for ClassMember {
|
||||
}
|
||||
|
||||
#[ast_node("ClassProperty")]
|
||||
#[derive(Eq, Hash, EqIgnoreSpan)]
|
||||
#[derive(Eq, Hash, EqIgnoreSpan, Default)]
|
||||
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
|
||||
pub struct ClassProp {
|
||||
#[cfg_attr(feature = "serde-impl", serde(default))]
|
||||
@ -135,7 +135,7 @@ pub struct ClassProp {
|
||||
}
|
||||
|
||||
#[ast_node("PrivateProperty")]
|
||||
#[derive(Eq, Hash, EqIgnoreSpan)]
|
||||
#[derive(Eq, Hash, EqIgnoreSpan, Default)]
|
||||
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
|
||||
pub struct PrivateProp {
|
||||
#[cfg_attr(feature = "serde-impl", serde(default))]
|
||||
@ -176,7 +176,7 @@ pub struct PrivateProp {
|
||||
}
|
||||
|
||||
#[ast_node("ClassMethod")]
|
||||
#[derive(Eq, Hash, EqIgnoreSpan)]
|
||||
#[derive(Eq, Hash, EqIgnoreSpan, Default)]
|
||||
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
|
||||
pub struct ClassMethod {
|
||||
#[cfg_attr(feature = "serde-impl", serde(default))]
|
||||
@ -199,7 +199,7 @@ pub struct ClassMethod {
|
||||
}
|
||||
|
||||
#[ast_node("PrivateMethod")]
|
||||
#[derive(Eq, Hash, EqIgnoreSpan)]
|
||||
#[derive(Eq, Hash, EqIgnoreSpan, Default)]
|
||||
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
|
||||
pub struct PrivateMethod {
|
||||
#[cfg_attr(feature = "serde-impl", serde(default))]
|
||||
@ -244,7 +244,7 @@ pub struct Constructor {
|
||||
}
|
||||
|
||||
#[ast_node("Decorator")]
|
||||
#[derive(Eq, Hash, EqIgnoreSpan)]
|
||||
#[derive(Eq, Hash, EqIgnoreSpan, Default)]
|
||||
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
|
||||
pub struct Decorator {
|
||||
pub span: Span,
|
||||
@ -253,7 +253,7 @@ pub struct Decorator {
|
||||
pub expr: Box<Expr>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, EqIgnoreSpan)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, EqIgnoreSpan, Default)]
|
||||
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
|
||||
#[cfg_attr(
|
||||
any(feature = "rkyv-impl"),
|
||||
@ -263,6 +263,7 @@ pub struct Decorator {
|
||||
#[cfg_attr(feature = "rkyv-impl", archive_attr(repr(u32)))]
|
||||
#[cfg_attr(feature = "serde-impl", derive(serde::Serialize, serde::Deserialize))]
|
||||
pub enum MethodKind {
|
||||
#[default]
|
||||
#[cfg_attr(feature = "serde-impl", serde(rename = "method"))]
|
||||
Method,
|
||||
#[cfg_attr(feature = "serde-impl", serde(rename = "getter"))]
|
||||
@ -272,7 +273,7 @@ pub enum MethodKind {
|
||||
}
|
||||
|
||||
#[ast_node("StaticBlock")]
|
||||
#[derive(Eq, Hash, EqIgnoreSpan)]
|
||||
#[derive(Eq, Hash, EqIgnoreSpan, Default)]
|
||||
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
|
||||
pub struct StaticBlock {
|
||||
pub span: Span,
|
||||
@ -312,12 +313,18 @@ bridge_from!(Key, PropName, BigInt);
|
||||
|
||||
impl Take for Key {
|
||||
fn dummy() -> Self {
|
||||
Key::Public(Take::dummy())
|
||||
Default::default()
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Key {
|
||||
fn default() -> Self {
|
||||
Key::Public(Default::default())
|
||||
}
|
||||
}
|
||||
|
||||
#[ast_node("AutoAccessor")]
|
||||
#[derive(Eq, Hash, EqIgnoreSpan)]
|
||||
#[derive(Eq, Hash, EqIgnoreSpan, Default)]
|
||||
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
|
||||
pub struct AutoAccessor {
|
||||
#[cfg_attr(feature = "serde-impl", serde(default))]
|
||||
|
@ -504,7 +504,7 @@ impl<'a> arbitrary::Arbitrary<'a> for Ident {
|
||||
}
|
||||
|
||||
#[ast_node("PrivateName")]
|
||||
#[derive(Eq, Hash, EqIgnoreSpan)]
|
||||
#[derive(Eq, Hash, EqIgnoreSpan, Default)]
|
||||
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
|
||||
pub struct PrivateName {
|
||||
pub span: Span,
|
||||
@ -528,6 +528,11 @@ impl Ident {
|
||||
}
|
||||
}
|
||||
|
||||
#[inline(never)]
|
||||
pub fn new_private(sym: Atom, span: Span) -> Self {
|
||||
Self::new(sym, span, SyntaxContext::empty().apply_mark(Mark::new()))
|
||||
}
|
||||
|
||||
pub const fn new_no_ctxt(sym: Atom, span: Span) -> Self {
|
||||
Self::new(sym, span, SyntaxContext::empty())
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
1923
crates/swc_ecma_transforms_proposal/src/decorator_impl.rs
Normal file
1923
crates/swc_ecma_transforms_proposal/src/decorator_impl.rs
Normal file
File diff suppressed because it is too large
Load Diff
@ -17,9 +17,13 @@ pub enum DecoratorVersion {
|
||||
|
||||
#[serde(rename = "2022-03")]
|
||||
V202203,
|
||||
|
||||
#[serde(rename = "2023-11")]
|
||||
V202311,
|
||||
}
|
||||
|
||||
pub mod decorator_2022_03;
|
||||
mod decorator_impl;
|
||||
pub mod decorators;
|
||||
pub mod explicit_resource_management;
|
||||
mod export_default_from;
|
||||
|
@ -162,9 +162,9 @@ fn create_pass(comments: Rc<SingleThreadedComments>, input: &Path) -> Box<dyn Fo
|
||||
BabelPluginEntry::WithConfig(name, config) => match &**name {
|
||||
"proposal-decorators" => match config {
|
||||
BabelPluginOption::Decorator { version } => match version {
|
||||
// DecoratorVersion::V202311 => {
|
||||
// add!(decorator_2023_11());
|
||||
// }
|
||||
DecoratorVersion::V202311 => {
|
||||
todo!()
|
||||
}
|
||||
DecoratorVersion::V202112 => todo!(),
|
||||
DecoratorVersion::V202203 => {
|
||||
add!(decorator_2022_03());
|
||||
|
Loading…
Reference in New Issue
Block a user