Skip to content

Commit

Permalink
Theoretically protect against getProjectReferences changes in typescr…
Browse files Browse the repository at this point in the history
…ipt@master
  • Loading branch information
andrewbranch committed Sep 20, 2018
1 parent fe888e2 commit ddc5cc7
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ export function supportsProjectReferences(instance: TSInstance) {
export function isUsingProjectReferences(instance: TSInstance) {
if (supportsProjectReferences(instance)) {
const program = ensureProgram(instance);
return program && program.getProjectReferences();
return Boolean(program && program.getProjectReferences());
}
return false;
}
Expand All @@ -285,21 +285,31 @@ export function getAndCacheProjectReference(
return projectReference;
}

function getResolvedProjectReferences(
program: typescript.Program
): typescript.ResolvedProjectReference[] | undefined {
const getProjectReferences =
(program as any).getResolvedProjectReferences ||
program.getProjectReferences;
if (getProjectReferences) {
return getProjectReferences();
}
return;
}

function getProjectReferenceForFile(filePath: string, instance: TSInstance) {
if (isUsingProjectReferences(instance)) {
const program = ensureProgram(instance);
return (
program &&
program
.getProjectReferences()!
.find(
ref =>
(ref &&
ref.commandLine.fileNames.some(
file => path.normalize(file) === filePath
)) ||
false
)
getResolvedProjectReferences(program)!.find(
ref =>
(ref &&
ref.commandLine.fileNames.some(
file => path.normalize(file) === filePath
)) ||
false
)
);
}

Expand Down

0 comments on commit ddc5cc7

Please sign in to comment.