mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-29 16:29:19 -05:00
Fix Identifiers: NaN diagnostic when having JSON SourceFiles
This makes sure that the `identifierCount` and `nodeCount` properties are always initialized for `SourceFile` objects.
This commit is contained in:
@@ -160,4 +160,22 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
describe("unittests:: Program.getNodeCount / Program.getIdentifierCount", () => {
|
||||
it("works on projects that have .json files", () => {
|
||||
const main = new documents.TextDocument("/main.ts", 'export { version } from "./package.json";');
|
||||
const pkg = new documents.TextDocument("/package.json", '{"version": "1.0.0"}');
|
||||
|
||||
const fs = vfs.createFromFileSystem(Harness.IO, /*ignoreCase*/ false, { documents: [main, pkg], cwd: "/" });
|
||||
const program = createProgram(["/main.ts"], { resolveJsonModule: true }, new fakes.CompilerHost(fs, { newLine: NewLineKind.LineFeed }));
|
||||
|
||||
const json = program.getSourceFile("/package.json")!;
|
||||
assert.equal(json.scriptKind, ScriptKind.JSON);
|
||||
assert.isNumber(json.nodeCount);
|
||||
assert.isNumber(json.identifierCount);
|
||||
|
||||
assert.isNotNaN(program.getNodeCount());
|
||||
assert.isNotNaN(program.getIdentifierCount());
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user