Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 22 additions & 18 deletions src/harness/harnessIO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,7 @@ export namespace Compiler {
compilerOptions: ts.CompilerOptions | undefined,
// Current directory is needed for rwcRunner to be able to use currentDirectory defined in json file
currentDirectory: string | undefined,
rootDir?: string,
symlinks?: vfs.FileSet
): compiler.CompilationResult {
const options: ts.CompilerOptions & HarnessOptions = compilerOptions ? ts.cloneCompilerOptions(compilerOptions) : { noResolve: false };
Expand All @@ -424,12 +425,12 @@ export namespace Compiler {
typeScriptVersion = harnessSettings.typeScriptVersion;
}
}
if (options.rootDirs) {
options.rootDirs = ts.map(options.rootDirs, d => ts.getNormalizedAbsolutePath(d, currentDirectory));
}

const useCaseSensitiveFileNames = options.useCaseSensitiveFileNames !== undefined ? options.useCaseSensitiveFileNames : true;
const programFileNames = inputFiles.map(file => file.unitName).filter(fileName => !ts.fileExtensionIs(fileName, ts.Extension.Json));
// When a tsconfig is present, root names passed to createProgram should already be absolute
const programFileNames = inputFiles
.map(file => options.configFile ? ts.getNormalizedAbsolutePath(file.unitName, currentDirectory) : file.unitName)
.filter(fileName => !ts.fileExtensionIs(fileName, ts.Extension.Json));

// Files from built\local that are requested by test "@includeBuiltFiles" to be in the context.
// Treat them as library files, so include them in build, but not in baselines.
Expand All @@ -449,6 +450,8 @@ export namespace Compiler {
if (symlinks) {
fs.apply(symlinks);
}

ts.assign(options, ts.convertToOptionsWithAbsolutePaths(options, path => ts.getNormalizedAbsolutePath(ts.getNormalizedAbsolutePath(path, rootDir), currentDirectory)));
const host = new fakes.CompilerHost(fs, options);
const result = compiler.compileFiles(host, programFileNames, options, typeScriptVersion);
result.symlinks = symlinks;
Expand Down Expand Up @@ -499,7 +502,10 @@ export namespace Compiler {
else if (vpath.isTypeScript(file.unitName) || (vpath.isJavaScript(file.unitName) && ts.getAllowJSCompilerOption(options))) {
const declFile = findResultCodeFile(file.unitName);
if (declFile && !findUnit(declFile.file, declInputFiles) && !findUnit(declFile.file, declOtherFiles)) {
dtsFiles.push({ unitName: declFile.file, content: Utils.removeByteOrderMark(declFile.text) });
dtsFiles.push({
unitName: declFile.file,
content: Utils.removeByteOrderMark(declFile.text)
});
}
}
}
Expand Down Expand Up @@ -539,7 +545,7 @@ export namespace Compiler {
return;
}
const { declInputFiles, declOtherFiles, harnessSettings, options, currentDirectory } = context;
const output = compileFiles(declInputFiles, declOtherFiles, harnessSettings, options, currentDirectory, symlinks);
const output = compileFiles(declInputFiles, declOtherFiles, harnessSettings, options, currentDirectory, /*rootDir*/ undefined, symlinks);
return { declInputFiles, declOtherFiles, declResult: output };
}

Expand Down Expand Up @@ -1172,13 +1178,13 @@ export namespace TestCaseParser {
const optionRegex = /^[\/]{2}\s*@(\w+)\s*:\s*([^\r\n]*)/gm; // multiple matches on multiple lines
const linkRegex = /^[\/]{2}\s*@link\s*:\s*([^\r\n]*)\s*->\s*([^\r\n]*)/gm; // multiple matches on multiple lines

export function parseSymlinkFromTest(line: string, symlinks: vfs.FileSet | undefined) {
export function parseSymlinkFromTest(line: string, symlinks: vfs.FileSet | undefined, absoluteRootDir?: string) {
const linkMetaData = linkRegex.exec(line);
linkRegex.lastIndex = 0;
if (!linkMetaData) return undefined;

if (!symlinks) symlinks = {};
symlinks[linkMetaData[2].trim()] = new vfs.Symlink(linkMetaData[1].trim());
symlinks[ts.getNormalizedAbsolutePath(linkMetaData[2].trim(), absoluteRootDir)] = new vfs.Symlink(ts.getNormalizedAbsolutePath(linkMetaData[1].trim(), absoluteRootDir));
return symlinks;
}

Expand All @@ -1202,7 +1208,7 @@ export namespace TestCaseParser {
}

/** Given a test file containing // @FileName directives, return an array of named units of code to be added to an existing compiler instance */
export function makeUnitsFromTest(code: string, fileName: string, rootDir?: string, settings = extractCompilerSettings(code)): TestCaseContent {
export function makeUnitsFromTest(code: string, fileName: string, rootDir: string, settings = extractCompilerSettings(code)): TestCaseContent {
// List of all the subfiles we've parsed out
const testUnitData: TestUnitData[] = [];

Expand All @@ -1217,7 +1223,7 @@ export namespace TestCaseParser {

for (const line of lines) {
let testMetaData: RegExpExecArray | null;
const possiblySymlinks = parseSymlinkFromTest(line, symlinks);
const possiblySymlinks = parseSymlinkFromTest(line, symlinks, ts.getNormalizedAbsolutePath(rootDir, vfs.srcFolder));
if (possiblySymlinks) {
symlinks = possiblySymlinks;
}
Expand Down Expand Up @@ -1288,9 +1294,9 @@ export namespace TestCaseParser {
const files: string[] = [];
const directories = new Set<string>();
for (const unit of testUnitData) {
const unitName = ts.getNormalizedAbsolutePath(unit.name, rootDir);
if (unitName.toLowerCase().startsWith(dir.toLowerCase())) {
let path = unitName.substring(dir.length);
const fileName = ts.getNormalizedAbsolutePath(ts.getNormalizedAbsolutePath(unit.name, rootDir), vfs.srcFolder);
if (fileName.toLowerCase().startsWith(dir.toLowerCase())) {
let path = fileName.substring(dir.length);
if (path.startsWith("/")) {
path = path.substring(1);
}
Expand Down Expand Up @@ -1319,11 +1325,9 @@ export namespace TestCaseParser {
if (getConfigNameFromFileName(data.name)) {
const configJson = ts.parseJsonText(data.name, data.content);
assert.isTrue(configJson.endOfFileToken !== undefined);
let baseDir = ts.normalizePath(ts.getDirectoryPath(data.name));
if (rootDir) {
baseDir = ts.getNormalizedAbsolutePath(baseDir, rootDir);
}
tsConfig = ts.parseJsonSourceFileConfigFileContent(configJson, parseConfigHost, baseDir, /*existingOptions*/ undefined, ts.getNormalizedAbsolutePath(data.name, rootDir));
const configFileName = ts.getNormalizedAbsolutePath(ts.getNormalizedAbsolutePath(data.name, rootDir), vfs.srcFolder);
const configDir = ts.getDirectoryPath(configFileName);
tsConfig = ts.parseJsonSourceFileConfigFileContent(configJson, parseConfigHost, configDir, /*existingOptions*/ undefined, configFileName);
tsConfigFileUnitData = data;

// delete entry from the list
Expand Down
39 changes: 19 additions & 20 deletions src/testRunner/compilerRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ export class CompilerBaselineRunner extends RunnerBase {
let compilerTest!: CompilerTest;
before(() => {
let payload;
let rootDir = ts.combinePaths(vfs.srcFolder, fileName.indexOf("conformance") === -1 ? "tests/cases/compiler/" : ts.getDirectoryPath(fileName) + "/");
let rootDir = fileName.indexOf("conformance") === -1 ? "tests/cases/compiler/" : ts.getDirectoryPath(fileName) + "/";
if (test && test.content) {
rootDir = ts.combinePaths(vfs.srcFolder, test.file.indexOf("conformance") === -1 ? "tests/cases/compiler/" : ts.getDirectoryPath(test.file) + "/");
rootDir = test.file.indexOf("conformance") === -1 ? "tests/cases/compiler/" : ts.getDirectoryPath(test.file) + "/";
payload = TestCaseParser.makeUnitsFromTest(test.content, test.file, rootDir);
}
compilerTest = new CompilerTest(fileName, rootDir, payload, configuration);
Expand Down Expand Up @@ -179,7 +179,8 @@ class CompilerTest {
// equivalent to other files on the file system not directly passed to the compiler (ie things that are referenced by other files)
private otherFiles: Compiler.TestFile[];

constructor(fileName: string, rootDir: string, testCaseContent?: TestCaseParser.TestCaseContent, configurationOverrides?: TestCaseParser.CompilerSettings) {
constructor(fileName: string, private rootDir: string, testCaseContent?: TestCaseParser.TestCaseContent, configurationOverrides?: TestCaseParser.CompilerSettings) {
const absoluteRootDir = ts.getNormalizedAbsolutePath(rootDir, vfs.srcFolder);
this.fileName = fileName;
this.justName = vpath.basename(fileName);
this.configuredName = this.justName;
Expand Down Expand Up @@ -218,20 +219,20 @@ class CompilerTest {
this.tsConfigFiles = [];
if (testCaseContent.tsConfig) {
tsConfigOptions = ts.cloneCompilerOptions(testCaseContent.tsConfig.options);
this.tsConfigFiles.push(this.createHarnessTestFile(testCaseContent.tsConfigFileUnitData!, rootDir, tsConfigOptions.configFilePath));
this.tsConfigFiles.push(this.createHarnessTestFile(testCaseContent.tsConfigFileUnitData!));
for (const unit of units) {
if (testCaseContent.tsConfig.fileNames.includes(ts.getNormalizedAbsolutePath(unit.name, rootDir))) {
this.toBeCompiled.push(this.createHarnessTestFile(unit, rootDir));
if (testCaseContent.tsConfig.fileNames.includes(ts.getNormalizedAbsolutePath(unit.name, absoluteRootDir))) {
this.toBeCompiled.push(this.createHarnessTestFile(unit));
}
else {
this.otherFiles.push(this.createHarnessTestFile(unit, rootDir));
this.otherFiles.push(this.createHarnessTestFile(unit));
}
}
}
else {
const baseUrl = this.harnessSettings.baseUrl;
if (baseUrl !== undefined && !ts.isRootedDiskPath(baseUrl)) {
this.harnessSettings.baseUrl = ts.getNormalizedAbsolutePath(baseUrl, rootDir);
this.harnessSettings.baseUrl = ts.getNormalizedAbsolutePath(baseUrl, absoluteRootDir);
}

const lastUnit = units[units.length - 1];
Expand All @@ -240,22 +241,21 @@ class CompilerTest {
// otherwise, assume all files are just meant to be in the same compilation session without explicit references to one another.

if (testCaseContent.settings.noImplicitReferences || /require\(/.test(lastUnit.content) || /reference\spath/.test(lastUnit.content)) {
this.toBeCompiled.push(this.createHarnessTestFile(lastUnit, rootDir));
this.toBeCompiled.push(this.createHarnessTestFile(lastUnit));
units.forEach(unit => {
if (unit.name !== lastUnit.name) {
this.otherFiles.push(this.createHarnessTestFile(unit, rootDir));
this.otherFiles.push(this.createHarnessTestFile(unit));
}
});
}
else {
this.toBeCompiled = units.map(unit => {
return this.createHarnessTestFile(unit, rootDir);
return this.createHarnessTestFile(unit);
});
}
}

if (tsConfigOptions && tsConfigOptions.configFilePath !== undefined) {
tsConfigOptions.configFilePath = ts.combinePaths(rootDir, tsConfigOptions.configFilePath);
tsConfigOptions.configFile!.fileName = tsConfigOptions.configFilePath;
}

Expand All @@ -265,6 +265,7 @@ class CompilerTest {
this.harnessSettings,
/*options*/ tsConfigOptions,
/*currentDirectory*/ this.harnessSettings.currentDirectory,
this.rootDir,
testCaseContent.symlinks
);

Expand Down Expand Up @@ -352,13 +353,11 @@ class CompilerTest {
);
}

private makeUnitName(name: string, root: string) {
const path = ts.toPath(name, root, ts.identity);
const pathStart = ts.toPath(IO.getCurrentDirectory(), "", ts.identity);
return pathStart ? path.replace(pathStart, "/") : path;
}

private createHarnessTestFile(lastUnit: TestCaseParser.TestUnitData, rootDir: string, unitName?: string): Compiler.TestFile {
return { unitName: unitName || this.makeUnitName(lastUnit.name, rootDir), content: lastUnit.content, fileOptions: lastUnit.fileOptions };
private createHarnessTestFile(unit: TestCaseParser.TestUnitData): Compiler.TestFile {
return {
unitName: ts.getNormalizedAbsolutePath(unit.name, this.rootDir),
content: unit.content,
fileOptions: unit.fileOptions
};
}
}
2 changes: 1 addition & 1 deletion tests/baselines/reference/amdLikeInputDeclarationEmit.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ define("lib/ExtendedClass", ["deps/BaseClass"],


//// [ExtendedClass.d.ts]
/// <reference path="../tests/cases/compiler/deps/BaseClass.d.ts" />
/// <reference path="../deps/BaseClass.d.ts" />
export = ExtendedClass;
declare const ExtendedClass: new () => {
f: () => "something";
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/bundledDtsLateExportRenaming.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ declare module "index" {
//// [DtsFileErrors]


dist/out.d.ts(10,33): error TS2307: Cannot find module 'nested' or its corresponding type declarations.
tests/cases/compiler/dist/out.d.ts(10,33): error TS2307: Cannot find module 'nested' or its corresponding type declarations.


==== ./dist/out.d.ts (1 errors) ====
==== tests/cases/compiler/dist/out.d.ts (1 errors) ====
declare module "nested/shared" {
export class B {
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error TS5056: Cannot write file 'out/b.js' because it would be overwritten by multiple input files.
error TS5056: Cannot write file 'out/c.js' because it would be overwritten by multiple input files.
error TS5056: Cannot write file 'tests/cases/conformance/moduleResolution/bundler/out/b.js' because it would be overwritten by multiple input files.
error TS5056: Cannot write file 'tests/cases/conformance/moduleResolution/bundler/out/c.js' because it would be overwritten by multiple input files.
error TS6054: File '/project/e.txt' has an unsupported extension. The only supported extensions are '.ts', '.tsx', '.d.ts', '.js', '.jsx', '.cts', '.d.cts', '.cjs', '.mts', '.d.mts', '.mjs'.
The file is in the program because:
Root file specified for compilation
Expand All @@ -13,8 +13,8 @@ error TS6054: File '/project/e.txt' has an unsupported extension. The only suppo
/project/types.d.ts(2,16): error TS2846: A declaration file cannot be imported without 'import type'. Did you mean to import an implementation file './a.js' instead?


!!! error TS5056: Cannot write file 'out/b.js' because it would be overwritten by multiple input files.
!!! error TS5056: Cannot write file 'out/c.js' because it would be overwritten by multiple input files.
!!! error TS5056: Cannot write file 'tests/cases/conformance/moduleResolution/bundler/out/b.js' because it would be overwritten by multiple input files.
!!! error TS5056: Cannot write file 'tests/cases/conformance/moduleResolution/bundler/out/c.js' because it would be overwritten by multiple input files.
!!! error TS6054: File '/project/e.txt' has an unsupported extension. The only supported extensions are '.ts', '.tsx', '.d.ts', '.js', '.jsx', '.cts', '.d.cts', '.cjs', '.mts', '.d.mts', '.mjs'.
!!! error TS6054: The file is in the program because:
!!! error TS6054: Root file specified for compilation
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error TS5056: Cannot write file 'out/b.js' because it would be overwritten by multiple input files.
error TS5056: Cannot write file 'out/c.js' because it would be overwritten by multiple input files.
error TS5056: Cannot write file 'tests/cases/conformance/moduleResolution/bundler/out/b.js' because it would be overwritten by multiple input files.
error TS5056: Cannot write file 'tests/cases/conformance/moduleResolution/bundler/out/c.js' because it would be overwritten by multiple input files.
error TS5096: Option 'allowImportingTsExtensions' can only be used when either 'noEmit' or 'emitDeclarationOnly' is set.
error TS6054: File '/project/e.txt' has an unsupported extension. The only supported extensions are '.ts', '.tsx', '.d.ts', '.js', '.jsx', '.cts', '.d.cts', '.cjs', '.mts', '.d.mts', '.mjs'.
The file is in the program because:
Expand All @@ -9,8 +9,8 @@ error TS6054: File '/project/e.txt' has an unsupported extension. The only suppo
/project/types.d.ts(2,16): error TS2846: A declaration file cannot be imported without 'import type'. Did you mean to import an implementation file './a.ts' instead?


!!! error TS5056: Cannot write file 'out/b.js' because it would be overwritten by multiple input files.
!!! error TS5056: Cannot write file 'out/c.js' because it would be overwritten by multiple input files.
!!! error TS5056: Cannot write file 'tests/cases/conformance/moduleResolution/bundler/out/b.js' because it would be overwritten by multiple input files.
!!! error TS5056: Cannot write file 'tests/cases/conformance/moduleResolution/bundler/out/c.js' because it would be overwritten by multiple input files.
!!! error TS5096: Option 'allowImportingTsExtensions' can only be used when either 'noEmit' or 'emitDeclarationOnly' is set.
!!! error TS6054: File '/project/e.txt' has an unsupported extension. The only supported extensions are '.ts', '.tsx', '.d.ts', '.js', '.jsx', '.cts', '.d.cts', '.cjs', '.mts', '.d.mts', '.mjs'.
!!! error TS6054: The file is in the program because:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ declare module "index" {
//// [DtsFileErrors]


dist/index.d.ts(2,23): error TS2307: Cannot find module 'b' or its corresponding type declarations.
/a/tests/cases/compiler/dist/index.d.ts(2,23): error TS2307: Cannot find module 'b' or its corresponding type declarations.


==== dist/index.d.ts (1 errors) ====
==== /a/tests/cases/compiler/dist/index.d.ts (1 errors) ====
declare module "src/index" {
import { B } from "b";
~~~
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
error TS5055: Cannot write file 'tests/cases/compiler/out.d.ts' because it would overwrite input file.
error TS5055: Cannot write file '/out.d.ts' because it would overwrite input file.
Adding a tsconfig.json file will help organize projects that contain both TypeScript and JavaScript files. Learn more at https://aka.ms/tsconfig.
error TS5101: Option 'out' is deprecated and will stop functioning in TypeScript 5.5. Specify compilerOption '"ignoreDeprecations": "5.0"' to silence this error.
Use 'outFile' instead.


!!! error TS5055: Cannot write file 'tests/cases/compiler/out.d.ts' because it would overwrite input file.
!!! error TS5055: Cannot write file '/out.d.ts' because it would overwrite input file.
!!! error TS5055: Adding a tsconfig.json file will help organize projects that contain both TypeScript and JavaScript files. Learn more at https://aka.ms/tsconfig.
!!! error TS5101: Option 'out' is deprecated and will stop functioning in TypeScript 5.5. Specify compilerOption '"ignoreDeprecations": "5.0"' to silence this error.
!!! error TS5101: Use 'outFile' instead.
==== tests/cases/compiler/out.d.ts (0 errors) ====
==== /out.d.ts (0 errors) ====
declare class c {
}

==== tests/cases/compiler/a.ts (0 errors) ====
==== /a.ts (0 errors) ====
class d {
}

Loading