Skip to content

Commit a400816

Browse files
committed
Add way to handle different script kind for the source file to determine if program is upto date
1 parent 6cb1237 commit a400816

File tree

5 files changed

+14
-4
lines changed

5 files changed

+14
-4
lines changed

src/compiler/program.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,7 @@ namespace ts {
653653
rootFileNames: string[],
654654
newOptions: CompilerOptions,
655655
getSourceVersion: (path: Path, fileName: string) => string | undefined,
656+
getScriptKind: ((path: Path, fileName: string) => ScriptKind) | undefined,
656657
fileExists: (fileName: string) => boolean,
657658
hasInvalidatedResolution: HasInvalidatedResolution,
658659
hasChangedAutomaticTypeDirectiveNames: HasChangedAutomaticTypeDirectiveNames | undefined,
@@ -688,13 +689,19 @@ namespace ts {
688689

689690
function sourceFileNotUptoDate(sourceFile: SourceFile) {
690691
return !sourceFileVersionUptoDate(sourceFile) ||
692+
!sourceFileScriptKindUptoDate(sourceFile) ||
691693
hasInvalidatedResolution(sourceFile.path);
692694
}
693695

694696
function sourceFileVersionUptoDate(sourceFile: SourceFile) {
695697
return sourceFile.version === getSourceVersion(sourceFile.resolvedPath, sourceFile.fileName);
696698
}
697699

700+
function sourceFileScriptKindUptoDate(sourceFile: SourceFile) {
701+
return !getScriptKind ||
702+
sourceFile.scriptKind === ensureScriptKind(sourceFile.fileName, getScriptKind(sourceFile.resolvedPath, sourceFile.fileName));
703+
}
704+
698705
function projectReferenceUptoDate(oldRef: ProjectReference, newRef: ProjectReference, index: number) {
699706
return projectReferenceIsEqualTo(oldRef, newRef) &&
700707
resolvedProjectReferenceUptoDate(program!.getResolvedProjectReferences()![index], oldRef);

src/compiler/watchPublic.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ namespace ts {
426426

427427
// All resolutions are invalid if user provided resolutions
428428
const hasInvalidatedResolution = resolutionCache.createHasInvalidatedResolution(userProvidedResolution);
429-
if (isProgramUptoDate(getCurrentProgram(), rootFileNames, compilerOptions, getSourceVersion, fileExists, hasInvalidatedResolution, hasChangedAutomaticTypeDirectiveNames, getParsedCommandLine, projectReferences)) {
429+
if (isProgramUptoDate(getCurrentProgram(), rootFileNames, compilerOptions, getSourceVersion, /*getScriptKind*/ undefined, fileExists, hasInvalidatedResolution, hasChangedAutomaticTypeDirectiveNames, getParsedCommandLine, projectReferences)) {
430430
if (hasChangedConfigFileParsingErrors) {
431431
builderProgram = createProgram(/*rootNames*/ undefined, /*options*/ undefined, compilerHost, builderProgram, configFileParsingDiagnostics, projectReferences);
432432
hasChangedConfigFileParsingErrors = false;

src/server/project.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,8 @@ namespace ts.server {
412412
}
413413

414414
getScriptKind(fileName: string) {
415-
const info = this.getOrCreateScriptInfoAndAttachToProject(fileName);
415+
// Don't attach to the project if script kind is asked
416+
const info = this.projectService.getOrCreateScriptInfoNotOpenedByClient(fileName, this.currentDirectory, this.directoryStructureHost);
416417
return (info && info.scriptKind)!; // TODO: GH#18217
417418
}
418419

src/services/services.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1312,7 +1312,7 @@ namespace ts {
13121312
};
13131313

13141314
// If the program is already up-to-date, we can reuse it
1315-
if (isProgramUptoDate(program, rootFileNames, newSettings, (_path, fileName) => host.getScriptVersion(fileName), fileExists, hasInvalidatedResolution, hasChangedAutomaticTypeDirectiveNames, getParsedCommandLine, projectReferences)) {
1315+
if (isProgramUptoDate(program, rootFileNames, newSettings, (_path, fileName) => host.getScriptVersion(fileName), host.getScriptKind ? (_path, fileName) => host.getScriptKind!(fileName) : undefined, fileExists, hasInvalidatedResolution, hasChangedAutomaticTypeDirectiveNames, getParsedCommandLine, projectReferences)) {
13161316
return;
13171317
}
13181318

src/testRunner/unittests/reuseProgramStructure.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -913,7 +913,9 @@ namespace ts {
913913
) {
914914
return isProgramUptoDate(
915915
program, newRootFileNames, newOptions,
916-
path => program.getSourceFileByPath(path)!.version, /*fileExists*/ returnFalse,
916+
path => program.getSourceFileByPath(path)!.version,
917+
/*getScfriptKind*/ undefined,
918+
/*fileExists*/ returnFalse,
917919
/*hasInvalidatedResolution*/ returnFalse,
918920
/*hasChangedAutomaticTypeDirectiveNames*/ undefined,
919921
/*getParsedCommandLine*/ returnUndefined,

0 commit comments

Comments
 (0)