Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(48878): TypeChecker.getTypeAtLocation throws runtime errors when passed valid nodes #48967

Merged
merged 1 commit into from
May 5, 2022
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 src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42198,7 +42198,7 @@ namespace ts {
if (isDeclaration(node)) {
// In this case, we call getSymbolOfNode instead of getSymbolAtLocation because it is a declaration
const symbol = getSymbolOfNode(node);
return getTypeOfSymbol(symbol);
return symbol ? getTypeOfSymbol(symbol) : errorType;
}

if (isDeclarationNameOrImportPropertyName(node)) {
Expand Down
20 changes: 20 additions & 0 deletions src/testRunner/unittests/publicApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,26 @@ describe("unittests:: Public APIs:: getTypeAtLocation", () => {
const type = checker.getTypeAtLocation(file);
assert.equal(type.flags, ts.TypeFlags.Any);
});

it("returns an errorType for VariableDeclaration with BindingPattern name", () => {
const content = "const foo = [1];\n" + "const [a] = foo;";

const host = new fakes.CompilerHost(vfs.createFromFileSystem(
Harness.IO,
/*ignoreCase*/ true,
{ documents: [new documents.TextDocument("/file.ts", content)], cwd: "/" }));

const program = ts.createProgram({
host,
rootNames: ["/file.ts"],
options: { noLib: true }
});

const checker = program.getTypeChecker();
const file = program.getSourceFile("/file.ts")!;
const [declaration] = (ts.findLast(file.statements, ts.isVariableStatement) as ts.VariableStatement).declarationList.declarations;
assert.equal(checker.getTypeAtLocation(declaration).flags, ts.TypeFlags.Any);
});
});

describe("unittests:: Public APIs:: validateLocaleAndSetLanguage", () => {
Expand Down