Skip to content

Commit

Permalink
fix(tofu): ClassProperty nodes are not globals
Browse files Browse the repository at this point in the history
Adds an exception to `findGlobals()` for AST nodes of type `ClassProperty`.

Closes #1098
  • Loading branch information
boneskull committed Mar 12, 2024
1 parent 7d89d0c commit ca63a99
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/tofu/src/findGlobals.js
Expand Up @@ -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)
},
Expand Down
15 changes: 15 additions & 0 deletions packages/tofu/test/inspectGlobals.spec.js
Expand Up @@ -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)
Expand Down

0 comments on commit ca63a99

Please sign in to comment.