mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-05 08:11:30 -06:00
fix(13503): fix crash on calling getTypeAtLocation with the SourceFile nodes (#39994)
This commit is contained in:
parent
d371ae770d
commit
1f5caf554c
@ -36620,6 +36620,10 @@ namespace ts {
|
||||
}
|
||||
|
||||
function getTypeOfNode(node: Node): Type {
|
||||
if (isSourceFile(node) && !isExternalModule(node)) {
|
||||
return errorType;
|
||||
}
|
||||
|
||||
if (node.flags & NodeFlags.InWithStatement) {
|
||||
// We cannot answer semantic questions within a with block, do not proceed any further
|
||||
return errorType;
|
||||
|
||||
@ -104,4 +104,23 @@ describe("unittests:: Public APIs:: getTypeAtLocation", () => {
|
||||
assert.ok(!(type.flags & ts.TypeFlags.Any));
|
||||
assert.equal(type, checker.getTypeAtLocation(propertyAccess.name));
|
||||
});
|
||||
|
||||
it("works on SourceFile", () => {
|
||||
const content = `const foo = 1;`;
|
||||
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 type = checker.getTypeAtLocation(file);
|
||||
assert.equal(type.flags, ts.TypeFlags.Any);
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user