Add meta-data flag name to modify compilationSettings
This commit is contained in:
parent
6ef41a74c7
commit
be4133a162
|
@ -122,9 +122,47 @@ module FourSlash {
|
|||
return s.replace(/[&<>"'\/]/g, ch => entityMap[ch]);
|
||||
}
|
||||
|
||||
// Name of ts.CompilerOptions properties that will be used by globalOptions
|
||||
// To add additional option, add property into the compilerOptMetadataNames, refer the property in either globalMetadataNames or fileMetadataNames
|
||||
// Add cases into convertGlobalOptionsToCompilationsSettings function for the compiler to acknowledge such option from meta data
|
||||
var compilerOptMetadataNames = {
|
||||
out: 'out',
|
||||
outDir: 'outDir',
|
||||
declaration: 'declaration',
|
||||
sourceMap: 'sourceMap',
|
||||
sourceRoot: 'sourceRoot'
|
||||
};
|
||||
|
||||
// List of allowed metadata names
|
||||
var fileMetadataNames = ['Filename'];
|
||||
var globalMetadataNames = ['Module', 'Target', 'BaselineFile']; // Note: Only BaselineFile is actually supported at the moment
|
||||
var globalMetadataNames = ['BaselineFile', compilerOptMetadataNames.out, compilerOptMetadataNames.outDir, compilerOptMetadataNames.declaration, compilerOptMetadataNames.outDir,
|
||||
compilerOptMetadataNames.declaration, compilerOptMetadataNames.sourceMap, compilerOptMetadataNames.sourceRoot]
|
||||
|
||||
function convertGlobalOptionsToCompilationSettings(globalOptions: { [idx: string]: string }): ts.CompilationSettings {
|
||||
var settings: ts.CompilationSettings = {};
|
||||
// Convert all property in globalOptions into ts.CompilationSettings
|
||||
for (var prop in globalOptions) {
|
||||
if (globalOptions.hasOwnProperty(prop)) {
|
||||
switch (prop) {
|
||||
case compilerOptMetadataNames.out:
|
||||
settings.outFileOption = globalOptions[prop];
|
||||
break;
|
||||
case compilerOptMetadataNames.outDir:
|
||||
settings.outDirOption = globalOptions[prop];
|
||||
break;
|
||||
case compilerOptMetadataNames.declaration:
|
||||
settings.generateDeclarationFiles = true;
|
||||
break;
|
||||
case compilerOptMetadataNames.sourceMap:
|
||||
settings.mapSourceFiles = true;
|
||||
break;
|
||||
case compilerOptMetadataNames.sourceRoot:
|
||||
settings.sourceRoot = globalOptions[prop]
|
||||
}
|
||||
}
|
||||
}
|
||||
return settings;
|
||||
}
|
||||
|
||||
export var currentTestState: TestState = null;
|
||||
|
||||
|
@ -189,12 +227,6 @@ module FourSlash {
|
|||
// Whether or not we should format on keystrokes
|
||||
public enableFormatting = true;
|
||||
|
||||
// Whether or not to generate .d.ts file
|
||||
public enableDeclaration = false;
|
||||
|
||||
// Output filename for single-output-file option
|
||||
public singleOutputFilename: string = undefined;
|
||||
|
||||
public formatCodeOptions: ts.FormatCodeOptions;
|
||||
|
||||
public cancellationToken: TestCancellationToken;
|
||||
|
@ -205,11 +237,15 @@ module FourSlash {
|
|||
private scenarioActions: string[] = [];
|
||||
private taoInvalidReason: string = null;
|
||||
|
||||
|
||||
constructor(public testData: FourSlashData) {
|
||||
// Initialize the language service with all the scripts
|
||||
this.cancellationToken = new TestCancellationToken();
|
||||
this.languageServiceShimHost = new Harness.LanguageService.TypeScriptLS(this.cancellationToken);
|
||||
|
||||
var compilationSettings = convertGlobalOptionsToCompilationSettings(this.testData.globalOptions);
|
||||
this.languageServiceShimHost.setCompilationSettings(compilationSettings);
|
||||
|
||||
var inputFiles: { unitName: string; content: string }[] = [];
|
||||
|
||||
testData.files.forEach(file => {
|
||||
|
@ -226,9 +262,9 @@ module FourSlash {
|
|||
//if (/require\(/.test(lastFile.content) || /reference\spath/.test(lastFile.content)) {
|
||||
// inputFiles.push({ unitName: lastFile.fileName, content: lastFile.content });
|
||||
//} else {
|
||||
inputFiles = testData.files.map(file => {
|
||||
return { unitName: file.fileName, content: file.content };
|
||||
});
|
||||
inputFiles = testData.files.map(file => {
|
||||
return { unitName: file.fileName, content: file.content };
|
||||
});
|
||||
//}
|
||||
|
||||
|
||||
|
@ -459,14 +495,6 @@ module FourSlash {
|
|||
}
|
||||
|
||||
public verifyEmitOutput(state: ts.EmitReturnStatus, filename?: string) {
|
||||
if (this.enableDeclaration) {
|
||||
this.languageServiceShimHost.setCompilationSettings({ generateDeclarationFiles: true });
|
||||
}
|
||||
|
||||
if (this.singleOutputFilename !== undefined) {
|
||||
this.languageServiceShimHost.setCompilationSettings({ outFileOption: this.singleOutputFilename });
|
||||
}
|
||||
|
||||
var expectedFilenames:string[] = [];
|
||||
if (filename !== undefined) {
|
||||
expectedFilenames = filename.split(" ");
|
||||
|
|
|
@ -134,8 +134,7 @@ module Harness.LanguageService {
|
|||
private ls: ts.LanguageServiceShim = null;
|
||||
|
||||
private fileNameToScript: ts.Map<ScriptInfo> = {};
|
||||
|
||||
private settings: any = {};
|
||||
private settings: ts.CompilationSettings = {};
|
||||
|
||||
constructor(private cancellationToken: ts.CancellationToken = CancellationToken.None) {
|
||||
}
|
||||
|
@ -246,7 +245,7 @@ module Harness.LanguageService {
|
|||
return this.ls;
|
||||
}
|
||||
|
||||
public setCompilationSettings(settings: any) {
|
||||
public setCompilationSettings(settings: ts.CompilationSettings) {
|
||||
for (var key in settings) {
|
||||
if (settings.hasOwnProperty(key)) {
|
||||
this.settings[key] = settings[key];
|
||||
|
|
|
@ -159,7 +159,7 @@ module ts {
|
|||
Asynchronous = 2,
|
||||
}
|
||||
|
||||
interface CompilationSettings {
|
||||
export interface CompilationSettings {
|
||||
propagateEnumConstants?: boolean;
|
||||
removeComments?: boolean;
|
||||
watch?: boolean;
|
||||
|
@ -179,6 +179,9 @@ module ts {
|
|||
gatherDiagnostics?: boolean;
|
||||
codepage?: number;
|
||||
emitBOM?: boolean;
|
||||
|
||||
// Declare indexer signature
|
||||
[index: string]: any;
|
||||
}
|
||||
|
||||
function languageVersionToScriptTarget(languageVersion: LanguageVersion): ScriptTarget {
|
||||
|
|
|
@ -446,23 +446,6 @@ module FourSlashInterface {
|
|||
public disableFormatting() {
|
||||
FourSlash.currentTestState.enableFormatting = false;
|
||||
}
|
||||
|
||||
public enableDeclaration() {
|
||||
FourSlash.currentTestState.enableDeclaration = true;
|
||||
}
|
||||
|
||||
public disableDeclaration() {
|
||||
FourSlash.currentTestState.enableDeclaration = false;
|
||||
}
|
||||
|
||||
public enableSingleOutputFile(outputFilename: string) {
|
||||
FourSlash.currentTestState.enableSingleOutputFile = true;
|
||||
FourSlash.currentTestState.singleOutputFilename = outputFilename;
|
||||
}
|
||||
|
||||
public disableSingleOutputFile() {
|
||||
FourSlash.currentTestState.enableSingleOutputFile = false;
|
||||
}
|
||||
}
|
||||
|
||||
export class debug {
|
||||
|
|
Loading…
Reference in a new issue