diff --git a/crates/swc_ecma_transforms_base/src/helpers/_apply_decs_2203_r.js b/crates/swc_ecma_transforms_base/src/helpers/_apply_decs_2203_r.js
index 8662d6ff4fd..718c02a0680 100644
--- a/crates/swc_ecma_transforms_base/src/helpers/_apply_decs_2203_r.js
+++ b/crates/swc_ecma_transforms_base/src/helpers/_apply_decs_2203_r.js
@@ -35,6 +35,7 @@ function applyDecs2203RFactory() {
kind,
isStatic,
isPrivate,
+ metadata,
value
) {
var kindStr;
@@ -61,6 +62,7 @@ function applyDecs2203RFactory() {
name: isPrivate ? "#" + name : name,
static: isStatic,
private: isPrivate,
+ metadata: metadata,
};
var decoratorFinishedRef = { v: false };
@@ -168,7 +170,8 @@ function applyDecs2203RFactory() {
kind,
isStatic,
isPrivate,
- initializers
+ initializers,
+ metadata
) {
var decs = decInfo[0];
@@ -221,6 +224,7 @@ function applyDecs2203RFactory() {
kind,
isStatic,
isPrivate,
+ metadata,
value
);
@@ -251,6 +255,7 @@ function applyDecs2203RFactory() {
kind,
isStatic,
isPrivate,
+ metadata,
value
);
@@ -345,7 +350,7 @@ function applyDecs2203RFactory() {
}
}
- function applyMemberDecs(Class, decInfos) {
+ function applyMemberDecs(Class, decInfos, metadata) {
var ret = [];
var protoInitializers;
var staticInitializers;
@@ -415,7 +420,8 @@ function applyDecs2203RFactory() {
kind,
isStatic,
isPrivate,
- initializers
+ initializers,
+ metadata
);
}
@@ -435,7 +441,7 @@ function applyDecs2203RFactory() {
}
}
- function applyClassDecs(targetClass, classDecs) {
+ function applyClassDecs(targetClass, classDecs, metadata) {
if (classDecs.length > 0) {
var initializers = [];
var newClass = targetClass;
@@ -452,6 +458,7 @@ function applyDecs2203RFactory() {
initializers,
decoratorFinishedRef
),
+ metadata,
});
} finally {
decoratorFinishedRef.v = true;
@@ -464,7 +471,7 @@ function applyDecs2203RFactory() {
}
return [
- newClass,
+ defineMetadata(newClass, metadata),
function () {
for (var i = 0; i < initializers.length; i++) {
initializers[i].call(newClass);
@@ -476,6 +483,14 @@ function applyDecs2203RFactory() {
// so we don't have to return an empty array here.
}
+ function defineMetadata(Class, metadata) {
+ return Object.defineProperty(
+ Class,
+ Symbol.metadata || Symbol.for("Symbol.metadata"),
+ { configurable: true, enumerable: true, value: metadata }
+ );
+ }
+
/**
Basic usage:
@@ -622,21 +637,31 @@ function applyDecs2203RFactory() {
initializeClass(Class);
*/
- return function applyDecs2203R(targetClass, memberDecs, classDecs) {
+ return function applyDecs2203R(targetClass, memberDecs, classDecs, parentClass) {
+ if (parentClass !== void 0) {
+ var parentMetadata =
+ parentClass[Symbol.metadata || Symbol.for("Symbol.metadata")];
+ }
+ var metadata = Object.create(
+ parentMetadata === void 0 ? null : parentMetadata
+ );
+ var e = applyMemberDecs(targetClass, memberDecs, metadata);
+ if (!classDecs.length) defineMetadata(targetClass, metadata);
return {
- e: applyMemberDecs(targetClass, memberDecs),
+ e: e,
// Lazily apply class decorations so that member init locals can be properly bound.
get c() {
- return applyClassDecs(targetClass, classDecs);
+ return applyClassDecs(targetClass, classDecs, metadata);
},
};
};
}
-function _apply_decs_2203_r(targetClass, memberDecs, classDecs) {
+function _apply_decs_2203_r(targetClass, memberDecs, classDecs, parentClass) {
return (_apply_decs_2203_r = applyDecs2203RFactory())(
targetClass,
memberDecs,
- classDecs
+ classDecs,
+ parentClass
);
-}
\ No newline at end of file
+}
diff --git a/crates/swc_ecma_transforms_proposal/src/decorator_2022_03.rs b/crates/swc_ecma_transforms_proposal/src/decorator_2022_03.rs
index 987d85aed10..5368144b84c 100644
--- a/crates/swc_ecma_transforms_proposal/src/decorator_2022_03.rs
+++ b/crates/swc_ecma_transforms_proposal/src/decorator_2022_03.rs
@@ -9,8 +9,9 @@ use swc_common::{util::take::Take, Spanned, SyntaxContext, DUMMY_SP};
use swc_ecma_ast::*;
use swc_ecma_transforms_base::{helper, helper_expr};
use swc_ecma_utils::{
- constructor::inject_after_super, default_constructor, prepend_stmt, private_ident,
- prop_name_to_expr_value, quote_ident, replace_ident, ExprFactory, IdentExt, IdentRenamer,
+ alias_ident_for, constructor::inject_after_super, default_constructor, prepend_stmt,
+ private_ident, prop_name_to_expr_value, quote_ident, replace_ident, ExprFactory, IdentExt,
+ IdentRenamer,
};
use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWith};
@@ -53,6 +54,8 @@ struct ClassState {
class_lhs: Vec