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
2 changes: 1 addition & 1 deletion packages/scope-manager/src/analyze.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ const DEFAULT_OPTIONS: Required<AnalyzeOptions> = {
* Takes an AST and returns the analyzed scopes.
*/
export function analyze(
tree: TSESTree.Node,
tree: TSESTree.Program,
providedOptions?: AnalyzeOptions,
): ScopeManager {
const options: Required<AnalyzeOptions> = {
Expand Down
5 changes: 4 additions & 1 deletion packages/scope-manager/src/referencer/Referencer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,10 @@ export class Referencer extends Visitor {
public currentScope(throwOnNull: true): Scope | null;
public currentScope(dontThrowOnNull?: true): Scope | null {
if (!dontThrowOnNull) {
assert(this.scopeManager.currentScope, 'aaa');
assert(
this.scopeManager.currentScope,
'Expected currentScope to exist. This usually happens when analyze() is called with an incomplete AST node instead of a complete Program node.',
);
}
return this.scopeManager.currentScope;
}
Expand Down
16 changes: 16 additions & 0 deletions packages/scope-manager/tests/analyze.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { analyze } from '../src';
import { parse } from './test-utils';

describe('analyze()', () => {
it('should throw error when passed a partial AST node', () => {
const ast = parse(`const hello: string = 'world';`, {
range: true,
});
const partialNode = ast.body[0];

expect(() => {
// @ts-expect-error -- to reproduce https://github.com/typescript-eslint/typescript-eslint/issues/11727
analyze(partialNode);
}).toThrow();
});
});
Loading