Skip to content

Commit 963da89

Browse files
Restore class fields transform compat with old @babel/types (#14231)
1 parent 18f938c commit 963da89

3 files changed

Lines changed: 8 additions & 4 deletions

File tree

packages/babel-helper-create-class-features-plugin/src/decorators.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ function extractElementDescriptor(
8282
prop("decorators", takeDecorators(node as Decorable)),
8383
prop(
8484
"static",
85-
!t.isStaticBlock(node) && node.static && t.booleanLiteral(true),
85+
// @ts-expect-error: TS doesn't infer that node is not a StaticBlock
86+
!t.isStaticBlock?.(node) && node.static && t.booleanLiteral(true),
8687
),
8788
prop("key", getKey(node)),
8889
].filter(Boolean);

packages/babel-helper-create-class-features-plugin/src/fields.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -911,7 +911,8 @@ function replaceThisContext(
911911
getSuperRef,
912912
getObjectRef() {
913913
state.needsClassRef = true;
914-
return t.isStaticBlock(path.node) || path.node.static
914+
// @ts-expect-error: TS doesn't infer that path.node is not a StaticBlock
915+
return t.isStaticBlock?.(path.node) || path.node.static
915916
? ref
916917
: t.memberExpression(ref, t.identifier("prototype"));
917918
},
@@ -964,7 +965,8 @@ export function buildFieldsInitNodes(
964965
for (const prop of props) {
965966
prop.isClassProperty() && ts.assertFieldTransformed(prop);
966967

967-
const isStatic = !t.isStaticBlock(prop.node) && prop.node.static;
968+
// @ts-expect-error: TS doesn't infer that prop.node is not a StaticBlock
969+
const isStatic = !t.isStaticBlock?.(prop.node) && prop.node.static;
968970
const isInstance = !isStatic;
969971
const isPrivate = prop.isPrivate();
970972
const isPublic = !isPrivate;

packages/babel-helper-create-class-features-plugin/src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,8 @@ export function createClassFeaturePlugin({
242242
(referenceVisitor, state) => {
243243
if (isDecorated) return;
244244
for (const prop of props) {
245-
if (t.isStaticBlock(prop.node) || prop.node.static) continue;
245+
// @ts-expect-error: TS doesn't infer that prop.node is not a StaticBlock
246+
if (t.isStaticBlock?.(prop.node) || prop.node.static) continue;
246247
prop.traverse(referenceVisitor, state);
247248
}
248249
},

0 commit comments

Comments
 (0)