From ca63a99a023d625dd89b3b11f4ff7d3af73f7dde Mon Sep 17 00:00:00 2001 From: Christopher Hiller Date: Tue, 12 Mar 2024 13:40:04 -0700 Subject: [PATCH] fix(tofu): ClassProperty nodes are not globals Adds an exception to `findGlobals()` for AST nodes of type `ClassProperty`. Closes #1098 --- packages/tofu/src/findGlobals.js | 5 +++++ packages/tofu/test/inspectGlobals.spec.js | 15 +++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/packages/tofu/src/findGlobals.js b/packages/tofu/src/findGlobals.js index 56d502a592..56d09cebac 100644 --- a/packages/tofu/src/findGlobals.js +++ b/packages/tofu/src/findGlobals.js @@ -84,6 +84,11 @@ function findGlobals(ast) { return } + // class props are not globals + if (parentType === 'ClassProperty' && path.parent.key === path.node) { + return + } + // save global saveGlobal(path) }, diff --git a/packages/tofu/test/inspectGlobals.spec.js b/packages/tofu/test/inspectGlobals.spec.js index 4f47a91296..e3422b456d 100644 --- a/packages/tofu/test/inspectGlobals.spec.js +++ b/packages/tofu/test/inspectGlobals.spec.js @@ -430,6 +430,21 @@ testInspect( } ) +testInspect( + 'class properties', + {}, + () => { + class X { + y = 123 + z + why() { + return this.y + } + } + }, + {} +) + function testInspect(label, opts, fn, expectedResultObj) { test(label, (t) => { const src = fnToCodeBlock(fn)