Adds the 2021-12 transform for decorators
Implements the 2021-12 transform for the decorators proposal, with support for the `accessor` keyword.
This commit is contained in:
committed by
Nicolò Ribaudo
parent
579ab3fc81
commit
1f63f94718
@@ -80,7 +80,10 @@ function extractElementDescriptor(
|
||||
const properties: t.ObjectExpression["properties"] = [
|
||||
prop("kind", t.stringLiteral(t.isClassMethod(node) ? node.kind : "field")),
|
||||
prop("decorators", takeDecorators(node as Decorable)),
|
||||
prop("static", node.static && t.booleanLiteral(true)),
|
||||
prop(
|
||||
"static",
|
||||
!t.isStaticBlock(node) && node.static && t.booleanLiteral(true),
|
||||
),
|
||||
prop("key", getKey(node)),
|
||||
].filter(Boolean);
|
||||
|
||||
|
||||
@@ -911,7 +911,7 @@ function replaceThisContext(
|
||||
getSuperRef,
|
||||
getObjectRef() {
|
||||
state.needsClassRef = true;
|
||||
return isStaticBlock || path.node.static
|
||||
return t.isStaticBlock(path.node) || path.node.static
|
||||
? ref
|
||||
: t.memberExpression(ref, t.identifier("prototype"));
|
||||
},
|
||||
@@ -931,7 +931,8 @@ function replaceThisContext(
|
||||
export type PropNode =
|
||||
| t.ClassProperty
|
||||
| t.ClassPrivateMethod
|
||||
| t.ClassPrivateProperty;
|
||||
| t.ClassPrivateProperty
|
||||
| t.StaticBlock;
|
||||
export type PropPath = NodePath<PropNode>;
|
||||
|
||||
export function buildFieldsInitNodes(
|
||||
@@ -963,7 +964,7 @@ export function buildFieldsInitNodes(
|
||||
for (const prop of props) {
|
||||
prop.isClassProperty() && ts.assertFieldTransformed(prop);
|
||||
|
||||
const isStatic = prop.node.static;
|
||||
const isStatic = !t.isStaticBlock(prop.node) && prop.node.static;
|
||||
const isInstance = !isStatic;
|
||||
const isPrivate = prop.isPrivate();
|
||||
const isPublic = !isPrivate;
|
||||
|
||||
@@ -170,7 +170,7 @@ export function createClassFeaturePlugin({
|
||||
path.isPrivate() ||
|
||||
path.isStaticBlock?.()
|
||||
) {
|
||||
props.push(path);
|
||||
props.push(path as PropPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -246,7 +246,7 @@ export function createClassFeaturePlugin({
|
||||
(referenceVisitor, state) => {
|
||||
if (isDecorated) return;
|
||||
for (const prop of props) {
|
||||
if (prop.node.static) continue;
|
||||
if (t.isStaticBlock(prop.node) || prop.node.static) continue;
|
||||
prop.traverse(referenceVisitor, state);
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user