From 3f0c62bf02887237132907da739a76b21fe440d5 Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Wed, 13 Sep 2023 10:15:14 -0700 Subject: [PATCH] Fix test harness bugs hidden by method behavior (#55723) --- src/harness/fakesHosts.ts | 6 +++--- src/harness/harnessIO.ts | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/harness/fakesHosts.ts b/src/harness/fakesHosts.ts index 770b092ec5b..9d30f002189 100644 --- a/src/harness/fakesHosts.ts +++ b/src/harness/fakesHosts.ts @@ -350,7 +350,7 @@ export class CompilerHost implements ts.CompilerHost { return vpath.resolve(this.getDefaultLibLocation(), ts.getDefaultLibFileName(options)); } - public getSourceFile(fileName: string, languageVersion: number): ts.SourceFile | undefined { + public getSourceFile(fileName: string, languageVersionOrOptions: ts.ScriptTarget | ts.CreateSourceFileOptions): ts.SourceFile | undefined { const canonicalFileName = this.getCanonicalFileName(vpath.resolve(this.getCurrentDirectory(), fileName)); const existing = this._sourceFiles.get(canonicalFileName); if (existing) return existing; @@ -364,7 +364,7 @@ export class CompilerHost implements ts.CompilerHost { // reused across multiple tests. In that case, we cache the SourceFile we parse // so that it can be reused across multiple tests to avoid the cost of // repeatedly parsing the same file over and over (such as lib.d.ts). - const cacheKey = this.vfs.shadowRoot && `SourceFile[languageVersion=${languageVersion},setParentNodes=${this._setParentNodes}]`; + const cacheKey = this.vfs.shadowRoot && `SourceFile[languageVersionOrOptions=${languageVersionOrOptions !== undefined ? JSON.stringify(languageVersionOrOptions) : undefined},setParentNodes=${this._setParentNodes}]`; if (cacheKey) { const meta = this.vfs.filemeta(canonicalFileName); const sourceFileFromMetadata = meta.get(cacheKey) as ts.SourceFile | undefined; @@ -374,7 +374,7 @@ export class CompilerHost implements ts.CompilerHost { } } - const parsed = ts.createSourceFile(fileName, content, languageVersion, this._setParentNodes || this.shouldAssertInvariants); + const parsed = ts.createSourceFile(fileName, content, languageVersionOrOptions, this._setParentNodes || this.shouldAssertInvariants); if (this.shouldAssertInvariants) { Utils.assertInvariants(parsed, /*parent*/ undefined); } diff --git a/src/harness/harnessIO.ts b/src/harness/harnessIO.ts index 27c7436800b..3ef0e2d0bea 100644 --- a/src/harness/harnessIO.ts +++ b/src/harness/harnessIO.ts @@ -243,13 +243,13 @@ export namespace Compiler { export function createSourceFileAndAssertInvariants( fileName: string, sourceText: string, - languageVersion: ts.ScriptTarget, + languageVersionOrOptions: ts.ScriptTarget | ts.CreateSourceFileOptions, ) { // We'll only assert invariants outside of light mode. const shouldAssertInvariants = !lightMode; // Only set the parent nodes if we're asserting invariants. We don't need them otherwise. - const result = ts.createSourceFile(fileName, sourceText, languageVersion, /*setParentNodes:*/ shouldAssertInvariants); + const result = ts.createSourceFile(fileName, sourceText, languageVersionOrOptions, /*setParentNodes:*/ shouldAssertInvariants); if (shouldAssertInvariants) { Utils.assertInvariants(result, /*parent:*/ undefined);