Skip to content

Commit

Permalink
Restore class fields transform compat with old @babel/types (#14231)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed Feb 3, 2022
1 parent 18f938c commit 963da89
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
Expand Up @@ -82,7 +82,8 @@ function extractElementDescriptor(
prop("decorators", takeDecorators(node as Decorable)),
prop(
"static",
!t.isStaticBlock(node) && node.static && t.booleanLiteral(true),
// @ts-expect-error: TS doesn't infer that node is not a StaticBlock
!t.isStaticBlock?.(node) && node.static && t.booleanLiteral(true),
),
prop("key", getKey(node)),
].filter(Boolean);
Expand Down
Expand Up @@ -911,7 +911,8 @@ function replaceThisContext(
getSuperRef,
getObjectRef() {
state.needsClassRef = true;
return t.isStaticBlock(path.node) || path.node.static
// @ts-expect-error: TS doesn't infer that path.node is not a StaticBlock
return t.isStaticBlock?.(path.node) || path.node.static
? ref
: t.memberExpression(ref, t.identifier("prototype"));
},
Expand Down Expand Up @@ -964,7 +965,8 @@ export function buildFieldsInitNodes(
for (const prop of props) {
prop.isClassProperty() && ts.assertFieldTransformed(prop);

const isStatic = !t.isStaticBlock(prop.node) && prop.node.static;
// @ts-expect-error: TS doesn't infer that prop.node is not a StaticBlock
const isStatic = !t.isStaticBlock?.(prop.node) && prop.node.static;
const isInstance = !isStatic;
const isPrivate = prop.isPrivate();
const isPublic = !isPrivate;
Expand Down
Expand Up @@ -242,7 +242,8 @@ export function createClassFeaturePlugin({
(referenceVisitor, state) => {
if (isDecorated) return;
for (const prop of props) {
if (t.isStaticBlock(prop.node) || prop.node.static) continue;
// @ts-expect-error: TS doesn't infer that prop.node is not a StaticBlock
if (t.isStaticBlock?.(prop.node) || prop.node.static) continue;
prop.traverse(referenceVisitor, state);
}
},
Expand Down

0 comments on commit 963da89

Please sign in to comment.