mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-11 10:00:13 -06: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:
parent
fd6fbdf7fe
commit
a8d04b2db9
@ -770,7 +770,11 @@ namespace ts {
|
||||
fixupParentReferences(sourceFile);
|
||||
}
|
||||
|
||||
sourceFile.nodeCount = nodeCount;
|
||||
sourceFile.identifierCount = identifierCount;
|
||||
sourceFile.identifiers = identifiers;
|
||||
sourceFile.parseDiagnostics = parseDiagnostics;
|
||||
|
||||
const result = sourceFile as JsonSourceFile;
|
||||
clearState();
|
||||
return result;
|
||||
|
||||
@ -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());
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user