Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions packages/agent-bundle/tests/check-test-remove-tree.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,36 @@ it('does not let a parameter shadow a computed method key or decorator', () => {
` @hook(rm(root, { ${recursiveTrue} })) run(rm) {}`,
'}',
]))).toEqual([expect.objectContaining({ hasRetries: false, line: 3 })]);

expect(recursiveRmCalls(sample([
"import { rm } from 'node:fs/promises';",
'class Suite {',
` run(@hook(rm(root, { ${recursiveTrue} })) rm) {}`,
` constructor(@hook(rm(root, { ${recursiveTrue} })) rm) {}`,
'}',
]))).toEqual([
expect.objectContaining({ hasRetries: false, line: 3 }),
expect.objectContaining({ hasRetries: false, line: 4 }),
]);

expect(recursiveRmCalls(sample([
"import * as fs from 'node:fs/promises';",
`class Suite { run(@hook(fs.rm(root, { ${recursiveTrue} })) fs) {} }`,
]))).toEqual([expect.objectContaining({ hasRetries: false, line: 2 })]);
});

it('does not let a nested-block var hide a call outside its function', () => {
expect(recursiveRmCalls(sample([
"import { rm } from 'node:fs/promises';",
'function setup() { if (ready) { var rm = mockRm; } }',
`function cleanup() { rm(root, { ${recursiveTrue} }); }`,
`function reset(done = () => rm(root, { ${recursiveTrue} })) { { var rm = mockRm; } }`,
`class Suite { static { { var rm = mockRm; } } run() { rm(root, { ${recursiveTrue} }); } }`,
]))).toEqual([
expect.objectContaining({ hasRetries: false, line: 3 }),
expect.objectContaining({ hasRetries: false, line: 4 }),
expect.objectContaining({ hasRetries: false, line: 5 }),
]);
});

it('parses TSX and JS test files with their own script kind', () => {
Expand Down
10 changes: 9 additions & 1 deletion scripts/check-test-remove-tree.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,10 @@ const statementDeclares = (statement, name) => {
return false;
};

/** `from` is the child the walk came up through; names, computed keys, and decorators sit outside the function scope. */
/**
* `from` is the child the walk came up through; names, computed keys, and decorators
* (including parameter decorators) sit outside the function scope.
*/
const functionLikeDeclares = (node, from, name) => {
if (
!(
Expand Down Expand Up @@ -189,6 +192,11 @@ const identifierIsLocallyShadowed = (identifier) => {
let from = identifier;
let current = identifier.parent;
while (current !== undefined) {
if (ts.isDecorator(current) && ts.isParameter(current.parent)) {
from = current.parent.parent;
current = from.parent;
continue;
}
if (
ts.isSourceFile(current)
|| ts.isBlock(current)
Expand Down
Loading