use commandlineParser's optionDeclarations to parse compiler options instead of doing it explicitlly

This commit is contained in:
Mohamed Hegazy
2015-08-21 19:17:09 -07:00
parent b911dc3faf
commit 60e25a7e1d
57 changed files with 127 additions and 264 deletions

View File

@@ -838,9 +838,9 @@ module Harness {
}
export function createSourceFileAndAssertInvariants(
fileName: string,
sourceText: string,
languageVersion: ts.ScriptTarget) {
fileName: string,
sourceText: string,
languageVersion: ts.ScriptTarget) {
// We'll only assert inletiants outside of light mode.
const shouldAssertInvariants = !Harness.lightMode;
@@ -870,13 +870,13 @@ module Harness {
}
export function createCompilerHost(
inputFiles: { unitName: string; content: string; }[],
writeFile: (fn: string, contents: string, writeByteOrderMark: boolean) => void,
scriptTarget: ts.ScriptTarget,
useCaseSensitiveFileNames: boolean,
// the currentDirectory is needed for rwcRunner to passed in specified current directory to compiler host
currentDirectory?: string,
newLineKind?: ts.NewLineKind): ts.CompilerHost {
inputFiles: { unitName: string; content: string; }[],
writeFile: (fn: string, contents: string, writeByteOrderMark: boolean) => void,
scriptTarget: ts.ScriptTarget,
useCaseSensitiveFileNames: boolean,
// the currentDirectory is needed for rwcRunner to passed in specified current directory to compiler host
currentDirectory?: string,
newLineKind?: ts.NewLineKind): ts.CompilerHost {
// Local get canonical file name function, that depends on passed in parameter for useCaseSensitiveFileNames
function getCanonicalFileName(fileName: string): string {
@@ -894,7 +894,7 @@ module Harness {
}
};
inputFiles.forEach(register);
function getSourceFile(fn: string, languageVersion: ts.ScriptTarget) {
fn = ts.normalizePath(fn);
if (Object.prototype.hasOwnProperty.call(filemap, getCanonicalFileName(fn))) {
@@ -938,200 +938,64 @@ module Harness {
interface HarnesOptions {
useCaseSensitiveFileNames?: boolean;
includeBuiltFileNames?: string[];
includeBuiltFile?: string;
baselineFile?: string;
}
// Additional options not already in ts.optionDeclarations
const harnessOptionDeclarations: ts.CommandLineOption[] = [
{ name: "allowNonTsExtensions", type: "boolean" },
{ name: "useCaseSensitiveFileNames", type: "boolean" },
{ name: "baselineFile", type: "string" },
{ name: "includeBuiltFile", type: "string" },
{ name: "fileName", type: "string" },
{ name: "noErrorTruncation", type: "boolean" }
];
let optionsIndex: ts.Map<ts.CommandLineOption>;
function getCommandLineOption(name: string): ts.CommandLineOption {
if (!optionsIndex) {
optionsIndex = {};
let optionDeclarations = harnessOptionDeclarations.concat(ts.optionDeclarations);
for (let option of optionDeclarations) {
optionsIndex[option.name.toLowerCase()] = option;
}
}
return ts.lookUp(optionsIndex, name.toLowerCase());
}
export function setCompilerOptionsFromHarnessSetting(settings: Harness.TestCaseParser.CompilerSettings, options: ts.CompilerOptions & HarnesOptions): void {
for (let name in settings) {
if (settings.hasOwnProperty(name)) {
let value = settings[name] ? settings[name].toLowerCase() : settings[name];
switch (name.toLowerCase()) {
case "module":
if (value === "amd") {
options.module = ts.ModuleKind.AMD;
} else if (value === "umd") {
options.module = ts.ModuleKind.UMD;
} else if (value === "commonjs") {
options.module = ts.ModuleKind.CommonJS;
} else if (value === "system") {
options.module = ts.ModuleKind.System;
} else if (value === "unspecified") {
options.module = ts.ModuleKind.None;
} else {
throw new Error("Unknown module type " + value);
}
break;
case "target":
if (value === "es3") {
options.target = ts.ScriptTarget.ES3;
} else if (value === "es5") {
options.target = ts.ScriptTarget.ES5;
} else if (value === "es6") {
options.target = ts.ScriptTarget.ES6;
} else {
throw new Error("Unknown compile target " + value);
}
break;
case "experimentaldecorators":
options.experimentalDecorators = value === "true";
break;
case "emitdecoratormetadata":
options.emitDecoratorMetadata = value === "true";
break;
case "experimentalasyncfunctions":
options.experimentalAsyncFunctions = value === "true";
break;
case "noemithelpers":
options.noEmitHelpers = value === "true";
break;
case "noemitonerror":
options.noEmitOnError = value === "true";
break;
case "noresolve":
options.noResolve = value === "true";
break;
case "noimplicitany":
options.noImplicitAny = value === "true";
break;
case "nolib":
options.noLib = value === "true";
break;
case "out":
options.out = settings[name];
break;
case "outfile":
options.outFile = settings[name];
break;
case "outdir":
options.outDir = settings[name];
break;
case "skipdefaultlibcheck":
options.skipDefaultLibCheck = value === "true";
break;
case "sourceroot":
options.sourceRoot = settings[name];
break;
case "maproot":
options.mapRoot = settings[name];
break;
case "sourcemap":
options.sourceMap = value === "true";
break;
case "declaration":
options.declaration = value === "true";
break;
case "newline":
if (value === "crlf") {
options.newLine = ts.NewLineKind.CarriageReturnLineFeed;
}
else if (value === "lf") {
options.newLine = ts.NewLineKind.LineFeed;
}
else {
throw new Error("Unknown option for newLine: " + value);
}
break;
case "comments":
options.removeComments = value === "false";
break;
case "stripinternal":
options.stripInternal = value === "true";
break;
case "usecasesensitivefilenames":
options.useCaseSensitiveFileNames = value === "true";
break;
case "filename":
// Not supported yet
break;
case "emitbom":
options.emitBOM = value === "true";
break;
case "errortruncation":
options.noErrorTruncation = value === "false";
break;
case "preserveconstenums":
options.preserveConstEnums = value === "true";
break;
case "isolatedmodules":
options.isolatedModules = value === "true";
break;
case "suppressimplicitanyindexerrors":
options.suppressImplicitAnyIndexErrors = value === "true";
break;
case "includebuiltfile":
if (!options.includeBuiltFileNames) {
options.includeBuiltFileNames = [];
}
options.includeBuiltFileNames.push(settings[name]);
break;
case "inlinesourcemap":
options.inlineSourceMap = value === "true";
break;
case "inlinesources":
options.inlineSources = value === "true";
break;
case "jsx":
if (value === "react") {
options.jsx = ts.JsxEmit.React;
}
else if (value === "preserve") {
options.jsx = ts.JsxEmit.Preserve;
}
else if (value === "none") {
options.jsx = ts.JsxEmit.None;
}
else {
throw new Error("Unknown option for jsx: " + value);
}
break;
case "allownontsextensions":
options.allowNonTsExtensions = value === "true";
break;
case "baselinefile":
options.baselineFile = settings[name];
break;
default:
throw new Error("Unsupported compiler setting " + value);
let value = settings[name];
let option = getCommandLineOption(name);
if (option) {
switch (option.type) {
case "boolean":
options[option.name] = value.toLowerCase() === "true";
break;
case "string":
options[option.name] = value;
break;
// If not a primitive, the possible types are specified in what is effectively a map of options.
default:
let map = <ts.Map<number>>option.type;
let key = (value).toLowerCase();
if (ts.hasProperty(map, key)) {
options[option.name] = map[key];
}
else {
throw new Error(`Unkown value '${value}' for compiler option '${name}'.`);
}
}
}
else {
throw new Error(`Unkown compiler option '${name}'.`);
}
}
}
}
export class HarnessCompiler {
private inputFiles: { unitName: string; content: string }[] = [];
private compileOptions: ts.CompilerOptions;
@@ -1194,13 +1058,13 @@ module Harness {
options.module = options.module || ts.ModuleKind.None;
options.newLine = options.newLine || ts.NewLineKind.CarriageReturnLineFeed;
options.noErrorTruncation = true;
options.skipDefaultLibCheck = true;
if (settingsCallback) {
settingsCallback(null);
}
let newLine = "\r\n";
options.skipDefaultLibCheck = true;
// Parse settings
setCompilerOptionsFromHarnessSetting(this.settings, options);
@@ -1208,10 +1072,10 @@ module Harness {
// 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.
let includeBuiltFiles: { unitName: string; content: string }[] = [];
ts.forEach(options.includeBuiltFileNames, fileName => {
let builtFileName = libFolder + fileName;
if (options.includeBuiltFile) {
let builtFileName = libFolder + options.includeBuiltFile;
includeBuiltFiles.push({ unitName: builtFileName, content: normalizeLineEndings(IO.readFile(builtFileName), newLine) });
});
}
let useCaseSensitiveFileNames = options.useCaseSensitiveFileNames !== undefined ? options.useCaseSensitiveFileNames : Harness.IO.useCaseSensitiveFileNames();

View File

@@ -1,3 +1,3 @@
// @comments:true
// @removeComments: false
function foo(/** nothing */) {
}

View File

@@ -1,4 +1,4 @@
// @comments:true
// @removeComments: false
class WebControls {
/**
* Render a control

View File

@@ -1,3 +1,3 @@
// @comments: true
// @removeComments: false
1 + 1; // Comment.

View File

@@ -1,4 +1,4 @@
// @comments: true
// @removeComments: false
// Test
if (true) {

View File

@@ -1,5 +1,5 @@
//@module: amd
// @comments: true
// @module: amd
// @removeComments: false
/* Copyright */
import foo = require('./foo');

View File

@@ -1,4 +1,4 @@
//@module: commonjs
// @comments: true
// @module: commonjs
// @removeComments: false
/* not copyright */
import foo = require('./foo');

View File

@@ -1,5 +1,5 @@
//@module: commonjs
// @comments: true
// @module: commonjs
// @removeComments: false
/* copyright */
/* not copyright */

View File

@@ -1,4 +1,4 @@
// @comments: true
// @removeComments: false
function Foo(x: any)
{
}

View File

@@ -1,4 +1,4 @@
// @comments:true
// @removeComments: false
var v = {
f: /**own f*/ (a) => 0
}

View File

@@ -1,4 +1,4 @@
//@module: amd
// @comments: true
// @module: amd
// @removeComments: false
/** b's comment*/
export var b: number;

View File

@@ -1,6 +1,6 @@
// @target: ES5
// @declaration: true
// @comments: true
// @removeComments: false
/** This is class c2 without constuctor*/
class c2 {

View File

@@ -1,6 +1,6 @@
// @target: ES5
// @declaration: true
// @comments: true
// @removeComments: false
/** This is comment for c1*/
class c1 {

View File

@@ -1,6 +1,6 @@
// @target: ES5
// @declaration: true
// @comments: true
// @removeComments: false
/// This is simple /// comments
function simple() {

View File

@@ -1,7 +1,7 @@
//@module: amd
// @module: amd
// @target: ES5
// @declaration: true
// @comments: true
// @removeComments: false
/** this is multi declare module*/
export module outerModule.InnerModule {

View File

@@ -1,6 +1,6 @@
// @target: ES5
// @declaration: true
// @comments: true
// @removeComments: false
/** Enum of colors*/
enum Colors {

View File

@@ -1,7 +1,7 @@
//@module: amd
// @module: amd
// @target: ES5
// @declaration: true
// @comments: true
// @removeComments: false
// @Filename: commentsExternalModules_0.ts
/** Module comment*/

View File

@@ -1,7 +1,7 @@
//@module: amd
// @module: amd
// @target: ES5
// @declaration: true
// @comments: true
// @removeComments: false
// @Filename: commentsExternalModules2_0.ts
/** Module comment*/

View File

@@ -1,7 +1,7 @@
//@module: commonjs
// @module: commonjs
// @target: ES5
// @declaration: true
// @comments: true
// @removeComments: false
// @Filename: commentsExternalModules2_0.ts
/** Module comment*/

View File

@@ -1,6 +1,6 @@
// @target: ES5
// @declaration: true
// @comments: true
// @removeComments: false
module m {
/** this is first line - aligned to class declaration

View File

@@ -1,6 +1,6 @@
// @target: ES5
// @declaration: true
// @comments: true
// @removeComments: false
/** This comment should appear for foo*/
function foo() {

View File

@@ -1,6 +1,6 @@
// @target: ES5
// @declaration: true
// @comments: true
// @removeComments: false
/** i1 is interface with properties*/
interface i1 {

View File

@@ -1,6 +1,6 @@
// @target: ES5
// @declaration: true
// @comments: true
// @removeComments: false
/** this is interface 1*/
interface i1 {
}

View File

@@ -1,6 +1,6 @@
// @target: ES5
// @declaration: true
// @comments: true
// @removeComments: false
/** Module comment*/
module m1 {
/** b's comment*/

View File

@@ -1,7 +1,7 @@
//@module: amd
// @module: amd
// @target: ES5
// @declaration: true
// @comments: true
// @removeComments: false
// @Filename: commentsMultiModuleMultiFile_0.ts
/** this is multi declare module*/

View File

@@ -1,6 +1,6 @@
// @target: ES5
// @declaration: true
// @comments: true
// @removeComments: false
/** this is multi declare module*/
module multiM {

View File

@@ -1,4 +1,4 @@
// @comments: true
// @removeComments: false
var Person = makeClass(
/**
@scope Person

View File

@@ -1,4 +1,4 @@
// @comments: true
// @removeComments: false
var Person = makeClass(
{
/**

View File

@@ -1,4 +1,4 @@
// @comments: true
// @removeComments: false
// @target: ES5
var v = {

View File

@@ -1,4 +1,4 @@
// @comments: true
// @removeComments: false
// @target: ES5
var v = {

View File

@@ -1,4 +1,4 @@
// @comments: true
// @removeComments: false
class DebugClass {
public static debugFunc() {
// Start Debugger Test Code

View File

@@ -1,4 +1,4 @@
// @comments: true
// @removeComments: false
class test {
/**

View File

@@ -1,6 +1,6 @@
// @target: ES5
// @declaration: true
// @comments: true
// @removeComments: false
/** this is signature 1*/
function f1(/**param a*/a: number): number;
function f1(b: string): number;

View File

@@ -1,4 +1,4 @@
// @comments: true
// @removeComments: false
var a = {
/** own x*/
x: 0

View File

@@ -1,5 +1,5 @@
// @declaration: true
// @comments: true
// @removeComments: false
class C</**docComment for type parameter*/ T> {
method</**docComment of method type parameter */ U extends T>(a: U) {
}

View File

@@ -1,6 +1,6 @@
// @target: ES5
// @declaration: true
// @comments: true
// @removeComments: false
/** Variable comments*/
var myVariable = 10; // This trailing Comment1

View File

@@ -1,5 +1,5 @@
// @declaration: true
// @comments: true
// @removeComments: false
/** Comment */
var v = 1;

View File

@@ -1,6 +1,6 @@
// @target: ES5
// @declaration: true
// @comments: false
// @removeComments: true
/** Variable comments*/
var myVariable = 10;

View File

@@ -1,6 +1,6 @@
// @target: ES5
// @declaration: true
// @comments: true
// @removeComments: false
/** Variable comments*/
var myVariable = 10;

View File

@@ -1,4 +1,4 @@
// @comments: false
// @removeComments: true
const enum Foo {
X = 100,
Y = 0.5,

View File

@@ -1,4 +1,4 @@
// @comments: true
// @removeComments: false
const enum Foo {
X = 100,
Y = 0.5,

View File

@@ -1,6 +1,6 @@
// @target: ES5
// @declaration: true
// @comments: true
// @removeComments: false
// @module: commonjs
// @Filename: declFileAccessors_0.ts

View File

@@ -1,6 +1,6 @@
// @target: ES5
// @declaration: true
// @comments: true
// @removeComments: false
// @module: commonjs
// @Filename: declFileCallSignatures_0.ts

View File

@@ -1,6 +1,6 @@
// @target: ES5
// @declaration: true
// @comments: true
// @removeComments: false
// @module: commonjs
// @Filename: declFileConstructSignatures_0.ts

View File

@@ -1,6 +1,6 @@
// @target: ES5
// @declaration: true
// @comments: true
// @removeComments: false
// @module: commonjs
// @Filename: declFileConstructors_0.ts

View File

@@ -1,6 +1,6 @@
// @target: ES5
// @declaration: true
// @comments: true
// @removeComments: false
// @module: commonjs
// @Filename: declFileFunctions_0.ts

View File

@@ -1,6 +1,6 @@
// @target: ES5
// @declaration: true
// @comments: true
// @removeComments: false
// @module: commonjs
// @Filename: declFileIndexSignatures_0.ts

View File

@@ -1,6 +1,6 @@
// @target: ES5
// @declaration: true
// @comments: true
// @removeComments: false
// @module: commonjs
// @Filename: declFileMethods_0.ts

View File

@@ -1,4 +1,4 @@
// @comments: true
// @removeComments: false
/**
* @name Foo

View File

@@ -1,4 +1,4 @@
// @comments: true
// @removeComments: false
var y = 10;
/**

View File

@@ -1,4 +1,4 @@
// @comments: true
// @removeComments: false
// This is pre comment
var y = 10;

View File

@@ -1,4 +1,4 @@
// @errortruncation: true
// @noErrorTruncation: false
var x: {
propertyWithAnExceedinglyLongName1: string;

View File

@@ -1,4 +1,3 @@
// @module: unspecified
// Not on line 0 because we want to verify the error is placed in the appropriate location.
export module M {

View File

@@ -1,4 +1,4 @@
// @comments: true
// @removeComments: false
function Foo(x: any)
{

View File

@@ -3,7 +3,7 @@
// @declaration: true
// @module: commonjs
//// @out: bin\
// @comments: true
// @removeComments: false
// my class comments
class MyClass

View File

@@ -1,4 +1,4 @@
// @comments: false
// @removeComments: true
/* unpinned comment */
/*! pinned comment */

View File

@@ -1,5 +1,5 @@
// @sourcemap: true
// @comments: true
// @removeComments: false
// Interface
interface IPoint {