From 53f9b90715962374cf2fc65ece134dc82d0d880e Mon Sep 17 00:00:00 2001 From: Christopher Hiller Date: Tue, 12 Mar 2024 13:40:04 -0700 Subject: [PATCH 1/2] 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) From dde2761fc08d1939e50f306c5c79d619d42484ac Mon Sep 17 00:00:00 2001 From: Christopher Hiller Date: Tue, 12 Mar 2024 14:08:05 -0700 Subject: [PATCH 2/2] chore(browserify): update test fixture policy --- .../fixtures/secureBundling/lavamoat/node/policy.json | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/packages/browserify/test/fixtures/secureBundling/lavamoat/node/policy.json b/packages/browserify/test/fixtures/secureBundling/lavamoat/node/policy.json index 71eacd7b99..00aba004bd 100644 --- a/packages/browserify/test/fixtures/secureBundling/lavamoat/node/policy.json +++ b/packages/browserify/test/fixtures/secureBundling/lavamoat/node/policy.json @@ -1040,17 +1040,9 @@ }, "globals": { "__dirname": true, - "ast": true, "console.error": true, "console.warn": true, - "content": true, - "define": true, - "file": true, - "importMap": true, - "moduleInitializer": true, - "packageName": true, - "specifier": true, - "type": true + "define": true }, "packages": { "json-stable-stringify": true,