Skip to content

Commit 3f0c62b

Browse files
authored
Fix test harness bugs hidden by method behavior (#55723)
1 parent e7bb0eb commit 3f0c62b

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/harness/fakesHosts.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ export class CompilerHost implements ts.CompilerHost {
350350
return vpath.resolve(this.getDefaultLibLocation(), ts.getDefaultLibFileName(options));
351351
}
352352

353-
public getSourceFile(fileName: string, languageVersion: number): ts.SourceFile | undefined {
353+
public getSourceFile(fileName: string, languageVersionOrOptions: ts.ScriptTarget | ts.CreateSourceFileOptions): ts.SourceFile | undefined {
354354
const canonicalFileName = this.getCanonicalFileName(vpath.resolve(this.getCurrentDirectory(), fileName));
355355
const existing = this._sourceFiles.get(canonicalFileName);
356356
if (existing) return existing;
@@ -364,7 +364,7 @@ export class CompilerHost implements ts.CompilerHost {
364364
// reused across multiple tests. In that case, we cache the SourceFile we parse
365365
// so that it can be reused across multiple tests to avoid the cost of
366366
// repeatedly parsing the same file over and over (such as lib.d.ts).
367-
const cacheKey = this.vfs.shadowRoot && `SourceFile[languageVersion=${languageVersion},setParentNodes=${this._setParentNodes}]`;
367+
const cacheKey = this.vfs.shadowRoot && `SourceFile[languageVersionOrOptions=${languageVersionOrOptions !== undefined ? JSON.stringify(languageVersionOrOptions) : undefined},setParentNodes=${this._setParentNodes}]`;
368368
if (cacheKey) {
369369
const meta = this.vfs.filemeta(canonicalFileName);
370370
const sourceFileFromMetadata = meta.get(cacheKey) as ts.SourceFile | undefined;
@@ -374,7 +374,7 @@ export class CompilerHost implements ts.CompilerHost {
374374
}
375375
}
376376

377-
const parsed = ts.createSourceFile(fileName, content, languageVersion, this._setParentNodes || this.shouldAssertInvariants);
377+
const parsed = ts.createSourceFile(fileName, content, languageVersionOrOptions, this._setParentNodes || this.shouldAssertInvariants);
378378
if (this.shouldAssertInvariants) {
379379
Utils.assertInvariants(parsed, /*parent*/ undefined);
380380
}

src/harness/harnessIO.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,13 +243,13 @@ export namespace Compiler {
243243
export function createSourceFileAndAssertInvariants(
244244
fileName: string,
245245
sourceText: string,
246-
languageVersion: ts.ScriptTarget,
246+
languageVersionOrOptions: ts.ScriptTarget | ts.CreateSourceFileOptions,
247247
) {
248248
// We'll only assert invariants outside of light mode.
249249
const shouldAssertInvariants = !lightMode;
250250

251251
// Only set the parent nodes if we're asserting invariants. We don't need them otherwise.
252-
const result = ts.createSourceFile(fileName, sourceText, languageVersion, /*setParentNodes:*/ shouldAssertInvariants);
252+
const result = ts.createSourceFile(fileName, sourceText, languageVersionOrOptions, /*setParentNodes:*/ shouldAssertInvariants);
253253

254254
if (shouldAssertInvariants) {
255255
Utils.assertInvariants(result, /*parent:*/ undefined);

0 commit comments

Comments
 (0)