mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-06 20:14:01 -06:00
Deprecate GeneratedFile
This commit is contained in:
parent
cd0809e4d6
commit
791c01eb98
@ -236,12 +236,9 @@ namespace compiler {
|
||||
private _inputsAndOutputs: core.KeyedCollection<string, CompilationOutput>;
|
||||
|
||||
// from CompilerResult
|
||||
public readonly files: ReadonlyArray<Harness.Compiler.GeneratedFile>;
|
||||
public readonly declFilesCode: ReadonlyArray<Harness.Compiler.GeneratedFile>;
|
||||
public readonly sourceMaps: ReadonlyArray<Harness.Compiler.GeneratedFile>;
|
||||
public readonly errors: ReadonlyArray<ts.Diagnostic>;
|
||||
public readonly currentDirectoryForProgram: string;
|
||||
public readonly traceResults: ReadonlyArray<string>;
|
||||
public readonly files: ReadonlyArray<documents.TextDocument>;
|
||||
public readonly declFilesCode: ReadonlyArray<documents.TextDocument>;
|
||||
public readonly sourceMaps: ReadonlyArray<documents.TextDocument>;
|
||||
|
||||
constructor(host: CompilerHost, options: ts.CompilerOptions, program: ts.Program | undefined, result: ts.EmitResult | undefined, diagnostics: ts.Diagnostic[]) {
|
||||
this.host = host;
|
||||
@ -291,12 +288,10 @@ namespace compiler {
|
||||
}
|
||||
|
||||
// from CompilerResult
|
||||
this.files = Array.from(this.js.values(), file => file.asGeneratedFile());
|
||||
this.declFilesCode = Array.from(this.dts.values(), file => file.asGeneratedFile());
|
||||
this.sourceMaps = Array.from(this.maps.values(), file => file.asGeneratedFile());
|
||||
this.errors = diagnostics;
|
||||
this.currentDirectoryForProgram = host.vfs.currentDirectory;
|
||||
this.traceResults = host.traces;
|
||||
this.files = Array.from(this.js.values());
|
||||
this.declFilesCode = Array.from(this.dts.values());
|
||||
this.sourceMaps = Array.from(this.maps.values());
|
||||
this.diagnostics = diagnostics;
|
||||
}
|
||||
|
||||
public get vfs(): vfs.VirtualFileSystem {
|
||||
|
||||
@ -208,14 +208,14 @@ class CompilerTest {
|
||||
Harness.Compiler.doErrorBaseline(
|
||||
this.justName,
|
||||
this.tsConfigFiles.concat(this.toBeCompiled, this.otherFiles),
|
||||
this.result.errors,
|
||||
this.result.diagnostics,
|
||||
!!this.options.pretty);
|
||||
}
|
||||
|
||||
public verifyModuleResolution() {
|
||||
if (this.options.traceResolution) {
|
||||
Harness.Baseline.runBaseline(this.justName.replace(/\.tsx?$/, ".trace.json"), () => {
|
||||
return utils.removeTestPathPrefixes(JSON.stringify(this.result.traceResults || [], undefined, 4));
|
||||
return utils.removeTestPathPrefixes(JSON.stringify(this.result.traces, undefined, 4));
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -224,7 +224,7 @@ class CompilerTest {
|
||||
if (this.options.sourceMap || this.options.inlineSourceMap) {
|
||||
Harness.Baseline.runBaseline(this.justName.replace(/\.tsx?$/, ".sourcemap.txt"), () => {
|
||||
const record = utils.removeTestPathPrefixes(this.result.getSourceMapRecord());
|
||||
if ((this.options.noEmitOnError && this.result.errors.length !== 0) || record === undefined) {
|
||||
if ((this.options.noEmitOnError && this.result.diagnostics.length !== 0) || record === undefined) {
|
||||
// Because of the noEmitOnError option no files are created. We need to return null because baselining isn't required.
|
||||
/* tslint:disable:no-null-keyword */
|
||||
return null;
|
||||
|
||||
@ -357,6 +357,11 @@ namespace core {
|
||||
return text;
|
||||
}
|
||||
|
||||
export function getByteOrderMark(text: string): string {
|
||||
const length = getByteOrderMarkLength(text);
|
||||
return length > 0 ? text.slice(0, length) : "";
|
||||
}
|
||||
|
||||
export function getByteOrderMarkLength(text: string): number {
|
||||
if (text.length >= 2) {
|
||||
const ch0 = text.charCodeAt(0);
|
||||
|
||||
@ -11,7 +11,6 @@ namespace documents {
|
||||
|
||||
private _lineStarts: core.LineStarts | undefined;
|
||||
private _testFile: Harness.Compiler.TestFile | undefined;
|
||||
private _generatedFile: Harness.Compiler.GeneratedFile | undefined;
|
||||
|
||||
constructor(file: string, text: string, meta?: Map<string, string>) {
|
||||
this.file = file;
|
||||
@ -39,20 +38,6 @@ namespace documents {
|
||||
.reduce((obj, [key, value]) => (obj[key] = value, obj), {} as Record<string, string>)
|
||||
});
|
||||
}
|
||||
|
||||
public static fromGeneratedFile(file: Harness.Compiler.GeneratedFile) {
|
||||
return new TextDocument(
|
||||
file.fileName,
|
||||
file.writeByteOrderMark ? core.addUTF8ByteOrderMark(file.code) : file.code);
|
||||
}
|
||||
|
||||
public asGeneratedFile() {
|
||||
return this._generatedFile || (this._generatedFile = {
|
||||
fileName: this.file,
|
||||
code: core.removeByteOrderMark(this.text),
|
||||
writeByteOrderMark: core.getByteOrderMarkLength(this.text) > 0
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export interface RawSourceMap {
|
||||
|
||||
@ -1244,7 +1244,7 @@ namespace Harness {
|
||||
options: ts.CompilerOptions,
|
||||
// Current directory is needed for rwcRunner to be able to use currentDirectory defined in json file
|
||||
currentDirectory: string): DeclarationCompilationContext | undefined {
|
||||
if (options.declaration && result.errors.length === 0 && result.declFilesCode.length !== result.files.length) {
|
||||
if (options.declaration && result.diagnostics.length === 0 && result.declFilesCode.length !== result.files.length) {
|
||||
throw new Error("There were no errors and declFiles generated did not match number of js files generated");
|
||||
}
|
||||
|
||||
@ -1252,7 +1252,7 @@ namespace Harness {
|
||||
const declOtherFiles: TestFile[] = [];
|
||||
|
||||
// if the .d.ts is non-empty, confirm it compiles correctly as well
|
||||
if (options.declaration && result.errors.length === 0 && result.declFilesCode.length > 0) {
|
||||
if (options.declaration && result.diagnostics.length === 0 && result.declFilesCode.length > 0) {
|
||||
ts.forEach(inputFiles, file => addDtsFile(file, declInputFiles));
|
||||
ts.forEach(otherFiles, file => addDtsFile(file, declOtherFiles));
|
||||
return { declInputFiles, declOtherFiles, harnessSettings, options, currentDirectory: currentDirectory || harnessSettings.currentDirectory };
|
||||
@ -1264,8 +1264,8 @@ namespace Harness {
|
||||
}
|
||||
else if (vpath.isTypeScript(file.unitName)) {
|
||||
const declFile = findResultCodeFile(file.unitName);
|
||||
if (declFile && !findUnit(declFile.fileName, declInputFiles) && !findUnit(declFile.fileName, declOtherFiles)) {
|
||||
dtsFiles.push({ unitName: declFile.fileName, content: declFile.code });
|
||||
if (declFile && !findUnit(declFile.file, declInputFiles) && !findUnit(declFile.file, declOtherFiles)) {
|
||||
dtsFiles.push({ unitName: declFile.file, content: core.removeByteOrderMark(declFile.text) });
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1278,7 +1278,7 @@ namespace Harness {
|
||||
const outFile = options.outFile || options.out;
|
||||
if (!outFile) {
|
||||
if (options.outDir) {
|
||||
let sourceFilePath = ts.getNormalizedAbsolutePath(sourceFile.fileName, result.currentDirectoryForProgram);
|
||||
let sourceFilePath = ts.getNormalizedAbsolutePath(sourceFile.fileName, result.vfs.currentDirectory);
|
||||
sourceFilePath = sourceFilePath.replace(result.program.getCommonSourceDirectory(), "");
|
||||
sourceFileName = ts.combinePaths(options.outDir, sourceFilePath);
|
||||
}
|
||||
@ -1293,7 +1293,7 @@ namespace Harness {
|
||||
|
||||
const dTsFileName = ts.removeFileExtension(sourceFileName) + ts.Extension.Dts;
|
||||
|
||||
return ts.forEach(result.declFilesCode, declFile => declFile.fileName === dTsFileName ? declFile : undefined);
|
||||
return ts.forEach(result.declFilesCode, declFile => declFile.file === dTsFileName ? declFile : undefined);
|
||||
}
|
||||
|
||||
function findUnit(fileName: string, units: TestFile[]) {
|
||||
@ -1602,10 +1602,6 @@ namespace Harness {
|
||||
}
|
||||
}
|
||||
|
||||
function getByteOrderMarkText(file: Harness.Compiler.GeneratedFile): string {
|
||||
return file.writeByteOrderMark ? "\u00EF\u00BB\u00BF" : "";
|
||||
}
|
||||
|
||||
export function doSourcemapBaseline(baselinePath: string, options: ts.CompilerOptions, result: compiler.CompilationResult, harnessSettings: Harness.TestCaseParser.CompilerSettings) {
|
||||
if (options.inlineSourceMap) {
|
||||
if (result.sourceMaps.length > 0) {
|
||||
@ -1619,7 +1615,7 @@ namespace Harness {
|
||||
}
|
||||
|
||||
Harness.Baseline.runBaseline(baselinePath.replace(/\.tsx?/, ".js.map"), () => {
|
||||
if ((options.noEmitOnError && result.errors.length !== 0) || result.sourceMaps.length === 0) {
|
||||
if ((options.noEmitOnError && result.diagnostics.length !== 0) || result.sourceMaps.length === 0) {
|
||||
// We need to return null here or the runBaseLine will actually create a empty file.
|
||||
// Baselining isn't required here because there is no output.
|
||||
/* tslint:disable:no-null-keyword */
|
||||
@ -1638,7 +1634,7 @@ namespace Harness {
|
||||
}
|
||||
|
||||
export function doJsEmitBaseline(baselinePath: string, header: string, options: ts.CompilerOptions, result: compiler.CompilationResult, tsConfigFiles: ReadonlyArray<Harness.Compiler.TestFile>, toBeCompiled: ReadonlyArray<Harness.Compiler.TestFile>, otherFiles: ReadonlyArray<Harness.Compiler.TestFile>, harnessSettings: Harness.TestCaseParser.CompilerSettings) {
|
||||
if (!options.noEmit && result.files.length === 0 && result.errors.length === 0) {
|
||||
if (!options.noEmit && result.files.length === 0 && result.diagnostics.length === 0) {
|
||||
throw new Error("Expected at least one js file to be emitted or at least one error to be created.");
|
||||
}
|
||||
|
||||
@ -1671,10 +1667,10 @@ namespace Harness {
|
||||
);
|
||||
const declFileCompilationResult = Harness.Compiler.compileDeclarationFiles(declFileContext);
|
||||
|
||||
if (declFileCompilationResult && declFileCompilationResult.declResult.errors.length) {
|
||||
if (declFileCompilationResult && declFileCompilationResult.declResult.diagnostics.length) {
|
||||
jsCode += "\r\n\r\n//// [DtsFileErrors]\r\n";
|
||||
jsCode += "\r\n\r\n";
|
||||
jsCode += Harness.Compiler.getErrorBaseline(tsConfigFiles.concat(declFileCompilationResult.declInputFiles, declFileCompilationResult.declOtherFiles), declFileCompilationResult.declResult.errors);
|
||||
jsCode += Harness.Compiler.getErrorBaseline(tsConfigFiles.concat(declFileCompilationResult.declInputFiles, declFileCompilationResult.declOtherFiles), declFileCompilationResult.declResult.diagnostics);
|
||||
}
|
||||
|
||||
if (jsCode.length > 0) {
|
||||
@ -1688,12 +1684,12 @@ namespace Harness {
|
||||
});
|
||||
}
|
||||
|
||||
function fileOutput(file: GeneratedFile, harnessSettings: Harness.TestCaseParser.CompilerSettings): string {
|
||||
const fileName = harnessSettings.fullEmitPaths ? utils.removeTestPathPrefixes(file.fileName) : ts.getBaseFileName(file.fileName);
|
||||
return "//// [" + fileName + "]\r\n" + getByteOrderMarkText(file) + utils.removeTestPathPrefixes(file.code);
|
||||
function fileOutput(file: documents.TextDocument, harnessSettings: Harness.TestCaseParser.CompilerSettings): string {
|
||||
const fileName = harnessSettings.fullEmitPaths ? utils.removeTestPathPrefixes(file.file) : ts.getBaseFileName(file.file);
|
||||
return "//// [" + fileName + "]\r\n" + utils.removeTestPathPrefixes(file.text);
|
||||
}
|
||||
|
||||
export function collateOutputs(outputFiles: ReadonlyArray<Harness.Compiler.GeneratedFile>): string {
|
||||
export function collateOutputs(outputFiles: ReadonlyArray<documents.TextDocument>): string {
|
||||
const gen = iterateOutputs(outputFiles);
|
||||
// Emit them
|
||||
let result = "";
|
||||
@ -1709,13 +1705,13 @@ namespace Harness {
|
||||
return result;
|
||||
}
|
||||
|
||||
export function *iterateOutputs(outputFiles: ReadonlyArray<Harness.Compiler.GeneratedFile>): IterableIterator<[string, string]> {
|
||||
export function *iterateOutputs(outputFiles: ReadonlyArray<documents.TextDocument>): IterableIterator<[string, string]> {
|
||||
// Collect, test, and sort the fileNames
|
||||
outputFiles.slice().sort((a, b) => ts.compareStringsCaseSensitive(cleanName(a.fileName), cleanName(b.fileName)));
|
||||
outputFiles.slice().sort((a, b) => ts.compareStringsCaseSensitive(cleanName(a.file), cleanName(b.file)));
|
||||
const dupeCase = ts.createMap<number>();
|
||||
// Yield them
|
||||
for (const outputFile of outputFiles) {
|
||||
yield [checkDuplicatedFileName(outputFile.fileName, dupeCase), "/*====== " + outputFile.fileName + " ======*/\r\n" + outputFile.code];
|
||||
yield [checkDuplicatedFileName(outputFile.file, dupeCase), "/*====== " + outputFile.file + " ======*/\r\n" + core.removeByteOrderMark(outputFile.text)];
|
||||
}
|
||||
|
||||
function cleanName(fn: string) {
|
||||
@ -1745,12 +1741,6 @@ namespace Harness {
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
export interface GeneratedFile {
|
||||
fileName: string;
|
||||
code: string;
|
||||
writeByteOrderMark: boolean;
|
||||
}
|
||||
}
|
||||
|
||||
export namespace TestCaseParser {
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
/// <reference path="harness.ts" />
|
||||
/// <reference path="runnerbase.ts" />
|
||||
/// <reference path="./vpath.ts" />
|
||||
/// <reference path="./documents.ts" />
|
||||
|
||||
// Test case is json of below type in tests/cases/project/
|
||||
interface ProjectRunnerTestCase {
|
||||
@ -20,10 +21,6 @@ interface ProjectRunnerTestCaseResolutionInfo extends ProjectRunnerTestCase {
|
||||
emittedFiles: ReadonlyArray<string>; // List of files that were emitted by the compiler
|
||||
}
|
||||
|
||||
interface BatchCompileProjectTestCaseEmittedFile extends Harness.Compiler.GeneratedFile {
|
||||
emittedFileName: string;
|
||||
}
|
||||
|
||||
interface CompileProjectFilesResult {
|
||||
configFileSourceFiles: ReadonlyArray<ts.SourceFile>;
|
||||
moduleKind: ts.ModuleKind;
|
||||
@ -34,7 +31,7 @@ interface CompileProjectFilesResult {
|
||||
}
|
||||
|
||||
interface BatchCompileProjectTestCaseResult extends CompileProjectFilesResult {
|
||||
outputFiles?: BatchCompileProjectTestCaseEmittedFile[];
|
||||
outputFiles?: ReadonlyArray<documents.TextDocument>;
|
||||
}
|
||||
|
||||
class ProjectRunner extends RunnerBase {
|
||||
@ -197,7 +194,7 @@ class ProjectRunner extends RunnerBase {
|
||||
function batchCompilerProjectTestCase(moduleKind: ts.ModuleKind): BatchCompileProjectTestCaseResult {
|
||||
let nonSubfolderDiskFiles = 0;
|
||||
|
||||
const outputFiles: BatchCompileProjectTestCaseEmittedFile[] = [];
|
||||
const outputFiles: documents.TextDocument[] = [];
|
||||
let inputFiles = testCase.inputFiles;
|
||||
let compilerOptions = createCompilerOptions();
|
||||
const configFileSourceFiles: ts.SourceFile[] = [];
|
||||
@ -355,12 +352,15 @@ class ProjectRunner extends RunnerBase {
|
||||
ensureDirectoryStructure(ts.getDirectoryPath(ts.normalizePath(outputFilePath)));
|
||||
Harness.IO.writeFile(outputFilePath, data);
|
||||
|
||||
outputFiles.push({ emittedFileName: fileName, code: data, fileName: diskRelativeName, writeByteOrderMark });
|
||||
outputFiles.push(new documents.TextDocument(
|
||||
diskRelativeName,
|
||||
writeByteOrderMark ? core.addUTF8ByteOrderMark(data) : data,
|
||||
new Map([["emittedFileName", fileName]])));
|
||||
}
|
||||
}
|
||||
|
||||
function compileCompileDTsFiles(compilerResult: BatchCompileProjectTestCaseResult) {
|
||||
const allInputFiles: { emittedFileName: string; code: string; }[] = [];
|
||||
const allInputFiles: documents.TextDocument[] = [];
|
||||
if (!compilerResult.program) {
|
||||
return;
|
||||
}
|
||||
@ -368,7 +368,10 @@ class ProjectRunner extends RunnerBase {
|
||||
|
||||
ts.forEach(compilerResult.program.getSourceFiles(), sourceFile => {
|
||||
if (sourceFile.isDeclarationFile) {
|
||||
allInputFiles.unshift({ emittedFileName: sourceFile.fileName, code: sourceFile.text });
|
||||
allInputFiles.unshift(new documents.TextDocument(
|
||||
sourceFile.fileName,
|
||||
sourceFile.text,
|
||||
new Map([["emittedFileName", sourceFile.fileName]])));
|
||||
}
|
||||
else if (!(compilerOptions.outFile || compilerOptions.out)) {
|
||||
let emitOutputFilePathWithoutExtension: string = undefined;
|
||||
@ -400,19 +403,19 @@ class ProjectRunner extends RunnerBase {
|
||||
return compileProjectFiles(compilerResult.moduleKind, compilerResult.configFileSourceFiles, getInputFiles, getSourceFileText, /*writeFile*/ ts.noop, compilerResult.compilerOptions);
|
||||
|
||||
function findOutputDtsFile(fileName: string) {
|
||||
return ts.forEach(compilerResult.outputFiles, outputFile => outputFile.emittedFileName === fileName ? outputFile : undefined);
|
||||
return ts.forEach(compilerResult.outputFiles, outputFile => outputFile.meta.get("emittedFileName") === fileName ? outputFile : undefined);
|
||||
}
|
||||
function getInputFiles() {
|
||||
return ts.map(allInputFiles, outputFile => outputFile.emittedFileName);
|
||||
return ts.map(allInputFiles, outputFile => outputFile.meta.get("emittedFileName"));
|
||||
}
|
||||
function getSourceFileText(fileName: string): string {
|
||||
for (const inputFile of allInputFiles) {
|
||||
const isMatchingFile = ts.isRootedDiskPath(fileName)
|
||||
? ts.getNormalizedAbsolutePath(inputFile.emittedFileName, getCurrentDirectory()) === fileName
|
||||
: inputFile.emittedFileName === fileName;
|
||||
? ts.getNormalizedAbsolutePath(inputFile.meta.get("emittedFileName"), getCurrentDirectory()) === fileName
|
||||
: inputFile.meta.get("emittedFileName") === fileName;
|
||||
|
||||
if (isMatchingFile) {
|
||||
return inputFile.code;
|
||||
return core.removeByteOrderMark(inputFile.text);
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
@ -452,7 +455,7 @@ class ProjectRunner extends RunnerBase {
|
||||
return ts.convertToRelativePath(inputFile.fileName, getCurrentDirectory(), path => Harness.Compiler.getCanonicalFileName(path));
|
||||
});
|
||||
resolutionInfo.emittedFiles = ts.map(compilerResult.outputFiles, outputFile => {
|
||||
return ts.convertToRelativePath(outputFile.emittedFileName, getCurrentDirectory(), path => Harness.Compiler.getCanonicalFileName(path));
|
||||
return ts.convertToRelativePath(outputFile.meta.get("emittedFileName"), getCurrentDirectory(), path => Harness.Compiler.getCanonicalFileName(path));
|
||||
});
|
||||
return resolutionInfo;
|
||||
}
|
||||
@ -484,9 +487,9 @@ class ProjectRunner extends RunnerBase {
|
||||
// There may be multiple files with different baselines. Run all and report at the end, else
|
||||
// it stops copying the remaining emitted files from 'local/projectOutput' to 'local/project'.
|
||||
try {
|
||||
Harness.Baseline.runBaseline(getBaselineFolder(compilerResult.moduleKind) + outputFile.fileName, () => {
|
||||
Harness.Baseline.runBaseline(getBaselineFolder(compilerResult.moduleKind) + outputFile.file, () => {
|
||||
try {
|
||||
return Harness.IO.readFile(getProjectOutputFolder(outputFile.fileName, compilerResult.moduleKind));
|
||||
return Harness.IO.readFile(getProjectOutputFolder(outputFile.file, compilerResult.moduleKind));
|
||||
}
|
||||
catch (e) {
|
||||
return undefined;
|
||||
|
||||
@ -197,12 +197,12 @@ namespace RWC {
|
||||
|
||||
it("has the expected errors", () => {
|
||||
Harness.Baseline.runMultifileBaseline(baseName, ".errors.txt", () => {
|
||||
if (compilerResult.errors.length === 0) {
|
||||
if (compilerResult.diagnostics.length === 0) {
|
||||
return null;
|
||||
}
|
||||
// Do not include the library in the baselines to avoid noise
|
||||
const baselineFiles = tsconfigFiles.concat(inputFiles, otherFiles).filter(f => !Harness.isDefaultLibraryFile(f.unitName));
|
||||
const errors = compilerResult.errors.filter(e => !e.file || !Harness.isDefaultLibraryFile(e.file.fileName));
|
||||
const errors = compilerResult.diagnostics.filter(e => !e.file || !Harness.isDefaultLibraryFile(e.file.fileName));
|
||||
return Harness.Compiler.iterateErrorBaseline(baselineFiles, errors);
|
||||
}, baselineOpts);
|
||||
});
|
||||
@ -210,9 +210,9 @@ namespace RWC {
|
||||
// Ideally, a generated declaration file will have no errors. But we allow generated
|
||||
// declaration file errors as part of the baseline.
|
||||
it("has the expected errors in generated declaration files", () => {
|
||||
if (compilerOptions.declaration && !compilerResult.errors.length) {
|
||||
if (compilerOptions.declaration && !compilerResult.diagnostics.length) {
|
||||
Harness.Baseline.runMultifileBaseline(baseName, ".dts.errors.txt", () => {
|
||||
if (compilerResult.errors.length === 0) {
|
||||
if (compilerResult.diagnostics.length === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -223,7 +223,7 @@ namespace RWC {
|
||||
compilerResult = undefined;
|
||||
const declFileCompilationResult = Harness.Compiler.compileDeclarationFiles(declContext);
|
||||
|
||||
return Harness.Compiler.iterateErrorBaseline(tsconfigFiles.concat(declFileCompilationResult.declInputFiles, declFileCompilationResult.declOtherFiles), declFileCompilationResult.declResult.errors);
|
||||
return Harness.Compiler.iterateErrorBaseline(tsconfigFiles.concat(declFileCompilationResult.declInputFiles, declFileCompilationResult.declOtherFiles), declFileCompilationResult.declResult.diagnostics);
|
||||
}, baselineOpts);
|
||||
}
|
||||
});
|
||||
|
||||
@ -206,8 +206,8 @@ namespace Harness.SourceMapRecorder {
|
||||
let sourceMapSources: string[];
|
||||
let sourceMapNames: string[];
|
||||
|
||||
let jsFile: Compiler.GeneratedFile;
|
||||
let jsLineMap: number[];
|
||||
let jsFile: documents.TextDocument;
|
||||
let jsLineMap: ReadonlyArray<number>;
|
||||
let tsCode: string;
|
||||
let tsLineMap: number[];
|
||||
|
||||
@ -216,13 +216,13 @@ namespace Harness.SourceMapRecorder {
|
||||
let prevWrittenJsLine: number;
|
||||
let spanMarkerContinues: boolean;
|
||||
|
||||
export function initializeSourceMapSpanWriter(sourceMapRecordWriter: Compiler.WriterAggregator, sourceMapData: ts.SourceMapData, currentJsFile: Compiler.GeneratedFile) {
|
||||
export function initializeSourceMapSpanWriter(sourceMapRecordWriter: Compiler.WriterAggregator, sourceMapData: ts.SourceMapData, currentJsFile: documents.TextDocument) {
|
||||
sourceMapRecorder = sourceMapRecordWriter;
|
||||
sourceMapSources = sourceMapData.sourceMapSources;
|
||||
sourceMapNames = sourceMapData.sourceMapNames;
|
||||
|
||||
jsFile = currentJsFile;
|
||||
jsLineMap = ts.computeLineStarts(jsFile.code);
|
||||
jsLineMap = jsFile.lineStarts;
|
||||
|
||||
spansOnSingleLine = [];
|
||||
prevWrittenSourcePos = 0;
|
||||
@ -290,7 +290,7 @@ namespace Harness.SourceMapRecorder {
|
||||
|
||||
assert.isTrue(spansOnSingleLine.length === 1);
|
||||
sourceMapRecorder.WriteLine("-------------------------------------------------------------------");
|
||||
sourceMapRecorder.WriteLine("emittedFile:" + jsFile.fileName);
|
||||
sourceMapRecorder.WriteLine("emittedFile:" + jsFile.file);
|
||||
sourceMapRecorder.WriteLine("sourceFile:" + sourceMapSources[spansOnSingleLine[0].sourceMapSpan.sourceIndex]);
|
||||
sourceMapRecorder.WriteLine("-------------------------------------------------------------------");
|
||||
|
||||
@ -313,15 +313,16 @@ namespace Harness.SourceMapRecorder {
|
||||
writeJsFileLines(jsLineMap.length);
|
||||
}
|
||||
|
||||
function getTextOfLine(line: number, lineMap: number[], code: string) {
|
||||
function getTextOfLine(line: number, lineMap: ReadonlyArray<number>, code: string) {
|
||||
const startPos = lineMap[line];
|
||||
const endPos = lineMap[line + 1];
|
||||
return code.substring(startPos, endPos);
|
||||
const text = code.substring(startPos, endPos);
|
||||
return line === 0 ? core.removeByteOrderMark(text) : text;
|
||||
}
|
||||
|
||||
function writeJsFileLines(endJsLine: number) {
|
||||
for (; prevWrittenJsLine < endJsLine; prevWrittenJsLine++) {
|
||||
sourceMapRecorder.Write(">>>" + getTextOfLine(prevWrittenJsLine, jsLineMap, jsFile.code));
|
||||
sourceMapRecorder.Write(">>>" + getTextOfLine(prevWrittenJsLine, jsLineMap, jsFile.text));
|
||||
}
|
||||
}
|
||||
|
||||
@ -417,7 +418,7 @@ namespace Harness.SourceMapRecorder {
|
||||
// Emit markers
|
||||
iterateSpans(writeSourceMapMarker);
|
||||
|
||||
const jsFileText = getTextOfLine(currentJsLine, jsLineMap, jsFile.code);
|
||||
const jsFileText = getTextOfLine(currentJsLine, jsLineMap, jsFile.text);
|
||||
if (prevEmittedCol < jsFileText.length) {
|
||||
// There is remaining text on this line that will be part of next source span so write marker that continues
|
||||
writeSourceMapMarker(/*currentSpan*/ undefined, spansOnSingleLine.length, /*endColumn*/ jsFileText.length, /*endContinues*/ true);
|
||||
@ -434,7 +435,7 @@ namespace Harness.SourceMapRecorder {
|
||||
}
|
||||
}
|
||||
|
||||
export function getSourceMapRecord(sourceMapDataList: ReadonlyArray<ts.SourceMapData>, program: ts.Program, jsFiles: ReadonlyArray<Compiler.GeneratedFile>) {
|
||||
export function getSourceMapRecord(sourceMapDataList: ReadonlyArray<ts.SourceMapData>, program: ts.Program, jsFiles: ReadonlyArray<documents.TextDocument>) {
|
||||
const sourceMapRecorder = new Compiler.WriterAggregator();
|
||||
|
||||
for (let i = 0; i < sourceMapDataList.length; i++) {
|
||||
|
||||
@ -68,14 +68,14 @@ class Test262BaselineRunner extends RunnerBase {
|
||||
|
||||
it("has the expected emitted code", () => {
|
||||
Harness.Baseline.runBaseline(testState.filename + ".output.js", () => {
|
||||
const files = testState.compilerResult.files.filter(f => f.fileName !== Test262BaselineRunner.helpersFilePath);
|
||||
const files = testState.compilerResult.files.filter(f => f.file !== Test262BaselineRunner.helpersFilePath);
|
||||
return Harness.Compiler.collateOutputs(files);
|
||||
}, Test262BaselineRunner.baselineOptions);
|
||||
});
|
||||
|
||||
it("has the expected errors", () => {
|
||||
Harness.Baseline.runBaseline(testState.filename + ".errors.txt", () => {
|
||||
const errors = testState.compilerResult.errors;
|
||||
const errors = testState.compilerResult.diagnostics;
|
||||
if (errors.length === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -20,7 +20,7 @@ describe("Public APIs", () => {
|
||||
};
|
||||
const inputFiles = [testFile];
|
||||
const output = Harness.Compiler.compileFiles(inputFiles, [], /*harnessSettings*/ undefined, /*options*/ {}, /*currentDirectory*/ undefined);
|
||||
assert(!output.result.errors || !output.result.errors.length, Harness.Compiler.minimalDiagnosticsToString(output.result.errors, /*pretty*/ true));
|
||||
assert(!output.result.diagnostics || !output.result.diagnostics.length, Harness.Compiler.minimalDiagnosticsToString(output.result.diagnostics, /*pretty*/ true));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user