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
244 changes: 126 additions & 118 deletions src/harness/compilerRunner.ts

Large diffs are not rendered by default.

20 changes: 16 additions & 4 deletions src/harness/harness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -806,10 +806,22 @@ module Harness {
code: string;
}

export function stringEndsWith(str: string, end: string) {
function stringEndsWith(str: string, end: string) {
return str.substr(str.length - end.length) === end;
}

export function isDTS(fileName: string) {
return stringEndsWith(fileName, '.d.ts');
}

export function isJS(fileName: string) {
return stringEndsWith(fileName, '.js');
}

export function isJSMap(fileName: string) {
return stringEndsWith(fileName, '.js.map');
}

/** Contains the code and errors of a compilation and some helper methods to check its status. */
export class CompilerResult {
public files: GeneratedFile[] = [];
Expand All @@ -824,13 +836,13 @@ module Harness {

fileResults.forEach(emittedFile => {
var fileObj = { fileName: emittedFile.fileName, code: emittedFile.file };
if (stringEndsWith(emittedFile.fileName, '.d.ts')) {
if (isDTS(emittedFile.fileName)) {
// .d.ts file, add to declFiles emit
this.declFilesCode.push(fileObj);
} else if (stringEndsWith(emittedFile.fileName, '.js')) {
} else if (isJS(emittedFile.fileName)) {
// .js file, add to files
this.files.push(fileObj);
} else if (stringEndsWith(emittedFile.fileName, '.js.map')) {
} else if (isJSMap(emittedFile.fileName)) {
this.sourceMaps.push(fileObj);
} else {
throw new Error('Unrecognized file extension for file ' + emittedFile.fileName);
Expand Down
10 changes: 5 additions & 5 deletions src/harness/projectsRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,18 +175,18 @@ class ProjectRunner extends RunnerBase {
// we need to instead create files that can live in the project reference folder
// but make sure extension of these files matches with the filename the compiler asked to write
diskRelativeName = "diskFile" + nonSubfolderDiskFiles++ +
(Harness.Compiler.stringEndsWith(filename, ".d.ts") ? ".d.ts" :
Harness.Compiler.stringEndsWith(filename, ".js") ? ".js" : ".js.map");
(Harness.Compiler.isDTS(filename) ? ".d.ts" :
Harness.Compiler.isJS(filename) ? ".js" : ".js.map");
}

if (Harness.Compiler.stringEndsWith(filename, ".js")) {
if (Harness.Compiler.isJS(filename)) {
// Make sure if there is URl we have it cleaned up
var indexOfSourceMapUrl = data.lastIndexOf("//# sourceMappingURL=");
if (indexOfSourceMapUrl != -1) {
data = data.substring(0, indexOfSourceMapUrl + 21) + cleanProjectUrl(data.substring(indexOfSourceMapUrl + 21));
}
}
else if (Harness.Compiler.stringEndsWith(filename, ".js.map")) {
else if (Harness.Compiler.isJSMap(filename)) {
// Make sure sources list is cleaned
var sourceMapData = JSON.parse(data);
for (var i = 0; i < sourceMapData.sources.length; i++) {
Expand Down Expand Up @@ -332,7 +332,7 @@ class ProjectRunner extends RunnerBase {
it('SourceMapRecord for (' + moduleNameToString(compilerResult.moduleKind) + '): ' + testCaseFileName, () => {
Harness.Baseline.runBaseline('SourceMapRecord for (' + moduleNameToString(compilerResult.moduleKind) + '): ' + testCaseFileName, getBaselineFolder(compilerResult.moduleKind) + testCaseJustName + '.sourcemap.txt', () => {
return Harness.SourceMapRecoder.getSourceMapRecord(compilerResult.sourceMapData, compilerResult.program,
ts.filter(compilerResult.outputFiles, outputFile => Harness.Compiler.stringEndsWith(outputFile.emittedFileName, ".js")));
ts.filter(compilerResult.outputFiles, outputFile => Harness.Compiler.isJS(outputFile.emittedFileName)));
});
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,22 @@ declare module "SubModule" {
//// [declFileAmbientExternalModuleWithSingleExportedModule_1.d.ts]
/// <reference path='declFileAmbientExternalModuleWithSingleExportedModule_0.d.ts' />
export declare var x: SubModule.m.m3.c;


//// [DtsFileErrors]


==== tests/cases/compiler/declFileAmbientExternalModuleWithSingleExportedModule_1.d.ts (1 errors) ====
/// <reference path='declFileAmbientExternalModuleWithSingleExportedModule_0.d.ts' />
export declare var x: SubModule.m.m3.c;
~~~~~~~~~~~~~~~~
!!! Cannot find name 'SubModule'.

==== tests/cases/compiler/declFileAmbientExternalModuleWithSingleExportedModule_0.d.ts (0 errors) ====
declare module "SubModule" {
module m {
module m3 {
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,19 @@ interface Foo<T> {
export = Foo;
//// [declFileExportAssignmentOfGenericInterface_1.d.ts]
export declare var x: a<a<string>>;


//// [DtsFileErrors]


==== tests/cases/compiler/declFileExportAssignmentOfGenericInterface_1.d.ts (1 errors) ====
export declare var x: a<a<string>>;
~~~~~~~~~~~~
!!! Cannot find name 'a'.

==== tests/cases/compiler/declFileExportAssignmentOfGenericInterface_0.d.ts (0 errors) ====
interface Foo<T> {
a: string;
}
export = Foo;

29 changes: 29 additions & 0 deletions tests/baselines/reference/declFileExportImportChain.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,32 @@ export = b;
export import b1 = require("declFileExportImportChain_b1");
//// [declFileExportImportChain_d.d.ts]
export declare var x: m1.m2.c1;


//// [DtsFileErrors]


==== tests/cases/compiler/declFileExportImportChain_d.d.ts (1 errors) ====
export declare var x: m1.m2.c1;
~~~~~~~~
!!! Cannot find name 'm1'.

==== tests/cases/compiler/declFileExportImportChain_a.d.ts (0 errors) ====
declare module m1 {
module m2 {
class c1 {
}
}
}
export = m1;

==== tests/cases/compiler/declFileExportImportChain_b.d.ts (0 errors) ====
export import a = require("declFileExportImportChain_a");

==== tests/cases/compiler/declFileExportImportChain_b1.d.ts (0 errors) ====
import b = require("declFileExportImportChain_b");
export = b;

==== tests/cases/compiler/declFileExportImportChain_c.d.ts (0 errors) ====
export import b1 = require("declFileExportImportChain_b1");

26 changes: 26 additions & 0 deletions tests/baselines/reference/declFileExportImportChain2.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,29 @@ export = a;
export import b = require("declFileExportImportChain2_b");
//// [declFileExportImportChain2_d.d.ts]
export declare var x: m1.m2.c1;


//// [DtsFileErrors]


==== tests/cases/compiler/declFileExportImportChain2_d.d.ts (1 errors) ====
export declare var x: m1.m2.c1;
~~~~~~~~
!!! Cannot find name 'm1'.

==== tests/cases/compiler/declFileExportImportChain2_a.d.ts (0 errors) ====
declare module m1 {
module m2 {
class c1 {
}
}
}
export = m1;

==== tests/cases/compiler/declFileExportImportChain2_b.d.ts (0 errors) ====
import a = require("declFileExportImportChain2_a");
export = a;

==== tests/cases/compiler/declFileExportImportChain2_c.d.ts (0 errors) ====
export import b = require("declFileExportImportChain2_b");

42 changes: 42 additions & 0 deletions tests/baselines/reference/declFileGenericType2.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,45 @@ declare module templa.dom.mvc.composite {
constructor();
}
}


//// [DtsFileErrors]


==== tests/cases/compiler/declFileGenericType2.d.ts (6 errors) ====
declare module templa.mvc {
}
declare module templa.mvc {
}
declare module templa.mvc {
}
declare module templa.mvc.composite {
}
declare module templa.dom.mvc {
interface IElementController<ModelType extends templa.mvc.IModel> extends templa.mvc.IController<ModelType> {
~~~~~~~~~~~~~~~~~
!!! Module 'templa.mvc' has no exported member 'IModel'.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! Module 'templa.mvc' has no exported member 'IController'.
}
}
declare module templa.dom.mvc {
class AbstractElementController<ModelType extends templa.mvc.IModel> extends templa.mvc.AbstractController<ModelType> implements IElementController<ModelType> {
~~~~~~~~~~~~~~~~~
!!! Module 'templa.mvc' has no exported member 'IModel'.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! Module 'templa.mvc' has no exported member 'AbstractController'.
constructor();
}
}
declare module templa.dom.mvc.composite {
class AbstractCompositeElementController<ModelType extends templa.mvc.composite.ICompositeControllerModel> extends AbstractElementController<ModelType> {
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! Module 'templa.mvc.composite' has no exported member 'ICompositeControllerModel'.
_controllers: templa.mvc.IController<templa.mvc.IModel>[];
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! Module 'templa.mvc' has no exported member 'IController'.
constructor();
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,38 @@ export declare var a: {
test1: a1.connectModule;
test2(): a1.connectModule;
};


//// [DtsFileErrors]


==== tests/cases/compiler/declFileImportModuleWithExportAssignment_1.d.ts (3 errors) ====
export declare var a: {
(): a1.connectExport;
~~~~~~~~~~~~~~~~
!!! Cannot find name 'a1'.
test1: a1.connectModule;
~~~~~~~~~~~~~~~~
!!! Cannot find name 'a1'.
test2(): a1.connectModule;
~~~~~~~~~~~~~~~~
!!! Cannot find name 'a1'.
};

==== tests/cases/compiler/declFileImportModuleWithExportAssignment_0.d.ts (0 errors) ====
declare module m2 {
interface connectModule {
(res: any, req: any, next: any): void;
}
interface connectExport {
use: (mod: connectModule) => connectExport;
listen: (port: number) => void;
}
}
declare var m2: {
(): m2.connectExport;
test1: m2.connectModule;
test2(): m2.connectModule;
};
export = m2;

Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,19 @@ declare module 'mod1' {
declare module 'moo' {
var p: List<x.Foo>;
}


//// [DtsFileErrors]


==== tests/cases/compiler/declFileImportedTypeUseInTypeArgPosition.d.ts (1 errors) ====
declare class List<T> {
}
declare module 'mod1' {
}
declare module 'moo' {
var p: List<x.Foo>;
~~~~~
!!! Cannot find name 'x'.
}

20 changes: 20 additions & 0 deletions tests/baselines/reference/declFileInternalAliases.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,23 @@ declare module m2 {
export import x = m.c;
var d: x;
}


//// [DtsFileErrors]


==== tests/cases/compiler/declFileInternalAliases.d.ts (1 errors) ====
declare module m {
class c {
}
}
declare module m1 {
var d: x;
~
!!! Cannot find name 'x'.
}
declare module m2 {
export import x = m.c;
var d: x;
}

38 changes: 38 additions & 0 deletions tests/baselines/reference/declInput-2.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,41 @@ declare module M {
m3(): C;
}
}


//// [DtsFileErrors]


==== tests/cases/compiler/declInput-2.d.ts (5 errors) ====
declare module M {
class E {
}
interface I1 {
}
class D {
private c;
m1: number;
m2: string;
m22: C;
~
!!! Cannot find name 'C'.
m23: E;
m24: I1;
m25: I2;
~~
!!! Cannot find name 'I2'.
m232(): E;
m242(): I1;
m252(): I2;
~~
!!! Cannot find name 'I2'.
m26(i: I1): void;
m262(i: I2): void;
~~
!!! Cannot find name 'I2'.
m3(): C;
~
!!! Cannot find name 'C'.
}
}

Loading