diff --git a/src/harness/compilerRunner.ts b/src/harness/compilerRunner.ts index 21e88b9e41..1b399e1b70 100644 --- a/src/harness/compilerRunner.ts +++ b/src/harness/compilerRunner.ts @@ -149,7 +149,7 @@ class CompilerBaselineRunner extends RunnerBase { // check errors it('Correct errors for ' + fileName, () => { if (this.errors) { - Harness.Baseline.runBaseline('Correct errors for ' + fileName, justName.replace(/\.ts$/, '.errors.txt'), (): string => { + Harness.Baseline.runBaseline('Correct errors for ' + fileName, justName.replace(/\.tsx?$/, '.errors.txt'), (): string => { if (result.errors.length === 0) return null; return getErrorBaseline(toBeCompiled, otherFiles, result); }); @@ -159,7 +159,7 @@ class CompilerBaselineRunner extends RunnerBase { // Source maps? it('Correct sourcemap content for ' + fileName, () => { if (options.sourceMap || options.inlineSourceMap) { - Harness.Baseline.runBaseline('Correct sourcemap content for ' + fileName, justName.replace(/\.ts$/, '.sourcemap.txt'), () => { + Harness.Baseline.runBaseline('Correct sourcemap content for ' + fileName, justName.replace(/\.tsx?$/, '.sourcemap.txt'), () => { var record = result.getSourceMapRecord(); if (options.noEmitOnError && result.errors.length !== 0 && record === undefined) { // Because of the noEmitOnError option no files are created. We need to return null because baselining isn't required. @@ -177,7 +177,7 @@ class CompilerBaselineRunner extends RunnerBase { } // check js output - Harness.Baseline.runBaseline('Correct JS output for ' + fileName, justName.replace(/\.ts/, '.js'), () => { + Harness.Baseline.runBaseline('Correct JS output for ' + fileName, justName.replace(/\.tsx?/, '.js'), () => { var tsCode = ''; var tsSources = otherFiles.concat(toBeCompiled); if (tsSources.length > 1) { @@ -235,7 +235,7 @@ class CompilerBaselineRunner extends RunnerBase { throw new Error('Number of sourcemap files should be same as js files.'); } - Harness.Baseline.runBaseline('Correct Sourcemap output for ' + fileName, justName.replace(/\.ts/, '.js.map'), () => { + Harness.Baseline.runBaseline('Correct Sourcemap output for ' + fileName, justName.replace(/\.tsx?/, '.js.map'), () => { if (options.noEmitOnError && result.errors.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. @@ -320,11 +320,11 @@ class CompilerBaselineRunner extends RunnerBase { let pullExtension = isSymbolBaseLine ? '.symbols.pull' : '.types.pull'; if (fullBaseLine !== pullBaseLine) { - Harness.Baseline.runBaseline('Correct full information for ' + fileName, justName.replace(/\.ts/, fullExtension), () => fullBaseLine); - Harness.Baseline.runBaseline('Correct pull information for ' + fileName, justName.replace(/\.ts/, pullExtension), () => pullBaseLine); + Harness.Baseline.runBaseline('Correct full information for ' + fileName, justName.replace(/\.tsx?/, fullExtension), () => fullBaseLine); + Harness.Baseline.runBaseline('Correct pull information for ' + fileName, justName.replace(/\.tsx?/, pullExtension), () => pullBaseLine); } else { - Harness.Baseline.runBaseline('Correct information for ' + fileName, justName.replace(/\.ts/, fullExtension), () => fullBaseLine); + Harness.Baseline.runBaseline('Correct information for ' + fileName, justName.replace(/\.tsx?/, fullExtension), () => fullBaseLine); } } @@ -391,7 +391,7 @@ class CompilerBaselineRunner extends RunnerBase { // this will set up a series of describe/it blocks to run between the setup and cleanup phases if (this.tests.length === 0) { - var testFiles = this.enumerateFiles(this.basePath, /\.ts$/, { recursive: true }); + var testFiles = this.enumerateFiles(this.basePath, /\.tsx?$/, { recursive: true }); testFiles.forEach(fn => { fn = fn.replace(/\\/g, "/"); this.checkTestCodeOutput(fn); diff --git a/src/harness/harness.ts b/src/harness/harness.ts index 6a55948815..0ea7db33fe 100644 --- a/src/harness/harness.ts +++ b/src/harness/harness.ts @@ -212,7 +212,7 @@ module Utils { } var result = ""; - ts.forEach(Object.getOwnPropertyNames(flags),(v: any) => { + ts.forEach(Object.getOwnPropertyNames(flags), (v: any) => { if (isFinite(v)) { v = +v; if (f === +v) { @@ -410,7 +410,7 @@ module Harness { deleteFile(fileName: string): void; listFiles(path: string, filter: RegExp, options?: { recursive?: boolean }): string[]; log(text: string): void; - getMemoryUsage? (): number; + getMemoryUsage?(): number; } module IOImpl { @@ -794,7 +794,7 @@ module Harness { public reset() { this.fileCollection = {}; } - public toArray(): { fileName: string; file: WriterAggregator; }[]{ + public toArray(): { fileName: string; file: WriterAggregator; }[] { var result: { fileName: string; file: WriterAggregator; }[] = []; for (var p in this.fileCollection) { if (this.fileCollection.hasOwnProperty(p)) { @@ -1166,6 +1166,12 @@ module Harness { options.inlineSources = setting.value === 'true'; break; + case 'jsx': + options.jsx = setting.value.toLowerCase() === 'react' ? ts.JsxEmit.React : + setting.value.toLowerCase() === 'preserve' ? ts.JsxEmit.Preserve : + ts.JsxEmit.None; + break; + default: throw new Error('Unsupported compiler setting ' + setting.flag); } @@ -1229,7 +1235,7 @@ module Harness { } var dTsFileName = ts.removeFileExtension(sourceFileName) + ".d.ts"; - + return ts.forEach(result.declFilesCode, declFile => declFile.fileName === dTsFileName ? declFile : undefined); } @@ -1428,6 +1434,10 @@ module Harness { return stringEndsWith(fileName, '.ts'); } + export function isTSX(fileName: string) { + return stringEndsWith(fileName, '.tsx'); + } + export function isDTS(fileName: string) { return stringEndsWith(fileName, '.d.ts'); } @@ -1435,6 +1445,9 @@ module Harness { export function isJS(fileName: string) { return stringEndsWith(fileName, '.js'); } + export function isJSX(fileName: string) { + return stringEndsWith(fileName, '.jsx'); + } export function isJSMap(fileName: string) { return stringEndsWith(fileName, '.js.map'); @@ -1455,7 +1468,7 @@ module Harness { if (isDTS(emittedFile.fileName)) { // .d.ts file, add to declFiles emit this.declFilesCode.push(emittedFile); - } else if (isJS(emittedFile.fileName)) { + } else if (isJS(emittedFile.fileName) || isJSX(emittedFile.fileName)) { // .js file, add to files this.files.push(emittedFile); } else if (isJSMap(emittedFile.fileName)) { @@ -1495,6 +1508,16 @@ module Harness { // Regex for parsing options in the format "@Alpha: Value of any sort" var optionRegex = /^[\/]{2}\s*@(\w+)\s*:\s*(\S*)/gm; // multiple matches on multiple lines + // List of allowed metadata names + var fileMetadataNames = ["filename", "comments", "declaration", "module", + "nolib", "sourcemap", "target", "out", "outdir", "noemithelpers", "noemitonerror", + "noimplicitany", "noresolve", "newline", "normalizenewline", "emitbom", + "errortruncation", "usecasesensitivefilenames", "preserveconstenums", + "includebuiltfile", "suppressimplicitanyindexerrors", "stripinternal", + "isolatedmodules", "inlinesourcemap", "maproot", "sourceroot", + "inlinesources", "emitdecoratormetadata", "experimentaldecorators", + "skipdefaultlibcheck", "jsx"]; + function extractCompilerSettings(content: string): CompilerSetting[] { var opts: CompilerSetting[] = []; diff --git a/src/harness/runnerbase.ts b/src/harness/runnerbase.ts index 269e889704..fa8d9d2c59 100644 --- a/src/harness/runnerbase.ts +++ b/src/harness/runnerbase.ts @@ -27,7 +27,7 @@ class RunnerBase { var fixedPath = path; // full paths either start with a drive letter or / for *nix, shouldn't have \ in the path at this point - var fullPath = /(\w+:|\/)?([\w+\-\.]|\/)*\.ts/g; + var fullPath = /(\w+:|\/)?([\w+\-\.]|\/)*\.tsx?/g; var fullPathList = fixedPath.match(fullPath); if (fullPathList) { fullPathList.forEach((match: string) => fixedPath = fixedPath.replace(match, Harness.Path.getFileName(match)));