Skip to content

Commit 349367d

Browse files
committed
Consolidate logic to use the lib in one location in the tests
1 parent 851e335 commit 349367d

File tree

7 files changed

+108
-195
lines changed

7 files changed

+108
-195
lines changed

src/harness/fourslash.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ module FourSlash {
254254
}
255255
});
256256

257-
this.languageServiceShimHost.addScript('lib.d.ts', Harness.Compiler.libTextMinimal);
257+
this.languageServiceShimHost.addDefaultLibrary();
258258

259259

260260
// Sneak into the language service and get its compiler so we can examine the syntax trees
@@ -1467,7 +1467,7 @@ module FourSlash {
14671467
var referenceLanguageService = referenceLanguageServiceShim.languageService;
14681468

14691469
// Add lib.d.ts to the reference language service
1470-
referenceLanguageServiceShimHost.addScript('lib.d.ts', Harness.Compiler.libTextMinimal);
1470+
referenceLanguageServiceShimHost.addDefaultLibrary();
14711471

14721472
for (var i = 0; i < this.testData.files.length; i++) {
14731473
var file = this.testData.files[i];
@@ -1885,7 +1885,7 @@ module FourSlash {
18851885

18861886
// Cache these between executions so we don't have to re-parse them for every test
18871887
var fourslashSourceFile: ts.SourceFile = undefined;
1888-
var libdtsSourceFile: ts.SourceFile = undefined;
1888+
18891889
export function runFourSlashTestContent(content: string, fileName: string): TestXmlData {
18901890
// Parse out the files and their metadata
18911891
var testData = parseTestData(content, fileName);
@@ -1896,12 +1896,11 @@ module FourSlash {
18961896
var fourslashFilename = 'fourslash.ts';
18971897
var tsFn = 'tests/cases/fourslash/' + fourslashFilename;
18981898
fourslashSourceFile = fourslashSourceFile || ts.createSourceFile(tsFn, Harness.IO.readFile(tsFn), ts.ScriptTarget.ES5, /*version*/ 0, /*isOpen*/ false);
1899-
libdtsSourceFile = libdtsSourceFile || ts.createSourceFile('lib.d.ts', Harness.Compiler.libTextMinimal, ts.ScriptTarget.ES3, /*version*/ 0, /*isOpen*/ false);
19001899

19011900
var files: { [filename: string]: ts.SourceFile; } = {};
19021901
files[fourslashFilename] = fourslashSourceFile;
19031902
files[fileName] = ts.createSourceFile(fileName, content, ts.ScriptTarget.ES5, /*version*/ 0, /*isOpen*/ false);
1904-
files['lib.d.ts'] = libdtsSourceFile;
1903+
files[Harness.Compiler.defaultLibFileName] = Harness.Compiler.defaultLibSourceFile;
19051904

19061905
var host = Harness.Compiler.createCompilerHost(files, (fn, contents) => result = contents);
19071906
var program = ts.createProgram([fileName, fourslashFilename], {}, host);

src/harness/harness.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -434,15 +434,15 @@ module Harness {
434434
export var libFolder: string;
435435
switch (Utils.getExecutionEnvironment()) {
436436
case Utils.ExecutionEnvironment.CScript:
437-
libFolder = Path.filePath(global['WScript'].ScriptFullName);
437+
libFolder = "built/local/";
438438
tcServicesFilename = "built/local/typescriptServices.js";
439439
break;
440440
case Utils.ExecutionEnvironment.Node:
441-
libFolder = (__dirname + '/');
441+
libFolder = "built/local/";
442442
tcServicesFilename = "built/local/typescriptServices.js";
443443
break;
444444
case Utils.ExecutionEnvironment.Browser:
445-
libFolder = "bin/";
445+
libFolder = "built/local/";
446446
tcServicesFilename = "built/local/typescriptServices.js";
447447
break;
448448
default:
@@ -531,8 +531,8 @@ module Harness {
531531
}
532532
}
533533

534-
export var libText = IO.readFile(libFolder + "lib.d.ts");
535-
export var libTextMinimal = IO.readFile('bin/lib.core.d.ts');
534+
export var defaultLibFileName = 'lib.d.ts';
535+
export var defaultLibSourceFile = ts.createSourceFile(defaultLibFileName, IO.readFile(libFolder + 'lib.core.d.ts'), /*languageVersion*/ ts.ScriptTarget.ES5);
536536

537537
export function createCompilerHost(filemap: { [filename: string]: ts.SourceFile; }, writeFile: (fn: string, contents: string, writeByteOrderMark:boolean) => void): ts.CompilerHost {
538538
return {
@@ -542,15 +542,15 @@ module Harness {
542542
if (fn in filemap) {
543543
return filemap[fn];
544544
} else {
545-
var lib = 'lib.d.ts';
546-
if (fn.substr(fn.length - lib.length) === lib) {
547-
return filemap[fn] = ts.createSourceFile('lib.d.ts', libTextMinimal, languageVersion);
545+
var lib = defaultLibFileName;
546+
if (fn === defaultLibFileName) {
547+
return defaultLibSourceFile;
548548
}
549549
// Don't throw here -- the compiler might be looking for a test that actually doesn't exist as part of the TC
550550
return null;
551551
}
552552
},
553-
getDefaultLibFilename: () => 'lib.d.ts',
553+
getDefaultLibFilename: () => defaultLibFileName,
554554
writeFile: writeFile,
555555
getCanonicalFileName: ts.getCanonicalFileName,
556556
useCaseSensitiveFileNames: () => sys.useCaseSensitiveFileNames,

src/harness/harnessLanguageService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ module Harness.LanguageService {
175175
}
176176

177177
public addDefaultLibrary() {
178-
this.addScript("lib.d.ts", Harness.Compiler.libText);
178+
this.addScript(Harness.Compiler.defaultLibFileName, Harness.Compiler.defaultLibSourceFile.text);
179179
}
180180

181181
public getHostIdentifier(): string {

src/harness/projectsRunner.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,8 @@ class ProjectRunner extends RunnerBase {
136136

137137
function getSourceFile(filename: string, languageVersion: ts.ScriptTarget): ts.SourceFile {
138138
var sourceFile: ts.SourceFile = undefined;
139-
if (filename === 'lib.d.ts') {
140-
sourceFile = ts.createSourceFile('lib.d.ts', Harness.Compiler.libTextMinimal, languageVersion);
139+
if (filename === Harness.Compiler.defaultLibFileName) {
140+
sourceFile = Harness.Compiler.defaultLibSourceFile;
141141
}
142142
else {
143143
assert.isTrue(!ts.filter(readInputFiles, sourceFile => sourceFile.filename == filename).length, "Compiler trying to read same file again: " + filename);
@@ -217,7 +217,7 @@ class ProjectRunner extends RunnerBase {
217217
function createCompilerHost(): ts.CompilerHost {
218218
return {
219219
getSourceFile: getSourceFile,
220-
getDefaultLibFilename: () => "lib.d.ts",
220+
getDefaultLibFilename: () => Harness.Compiler.defaultLibFileName,
221221
writeFile: writeFile,
222222
getCurrentDirectory: getCurrentDirectory,
223223
getCanonicalFileName: ts.getCanonicalFileName,
Lines changed: 32 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -1,138 +1,47 @@
1-
==== tests/cases/conformance/types/members/duplicateStringIndexers.ts (52 errors) ====
1+
==== tests/cases/conformance/types/members/duplicateStringIndexers.ts (6 errors) ====
22
// it is an error to have duplicate index signatures of the same kind in a type
33

4-
interface Number {
5-
[x: string]: string;
6-
~~~~~~~~~~~~~~~~~~~~
7-
!!! Property 'toExponential' of type '(fractionDigits?: number) => string' is not assignable to string index type 'string'.
8-
~~~~~~~~~~~~~~~~~~~~
9-
!!! Property 'toFixed' of type '(fractionDigits?: number) => string' is not assignable to string index type 'string'.
10-
~~~~~~~~~~~~~~~~~~~~
11-
!!! Property 'toPrecision' of type '(precision?: number) => string' is not assignable to string index type 'string'.
12-
~~~~~~~~~~~~~~~~~~~~
13-
!!! Property 'toString' of type '(radix?: number) => string' is not assignable to string index type 'string'.
14-
[x: string]: string;
15-
~~~~~~~~~~~~~~~~~~~~
4+
module test {
5+
interface Number {
6+
[x: string]: string;
7+
[x: string]: string;
8+
~~~~~~~~~~~~~~~~~~~~
169
!!! Duplicate string index signature.
17-
}
10+
}
1811

19-
interface String {
20-
[x: string]: string;
21-
~~~~~~~~~~~~~~~~~~~~
22-
!!! Property 'charAt' of type '(pos: number) => string' is not assignable to string index type 'string'.
23-
~~~~~~~~~~~~~~~~~~~~
24-
!!! Property 'charCodeAt' of type '(index: number) => number' is not assignable to string index type 'string'.
25-
~~~~~~~~~~~~~~~~~~~~
26-
!!! Property 'concat' of type '(...strings: string[]) => string' is not assignable to string index type 'string'.
27-
~~~~~~~~~~~~~~~~~~~~
28-
!!! Property 'indexOf' of type '(searchString: string, position?: number) => number' is not assignable to string index type 'string'.
29-
~~~~~~~~~~~~~~~~~~~~
30-
!!! Property 'lastIndexOf' of type '(searchString: string, position?: number) => number' is not assignable to string index type 'string'.
31-
~~~~~~~~~~~~~~~~~~~~
32-
!!! Property 'length' of type 'number' is not assignable to string index type 'string'.
33-
~~~~~~~~~~~~~~~~~~~~
34-
!!! Property 'localeCompare' of type '(that: string) => number' is not assignable to string index type 'string'.
35-
~~~~~~~~~~~~~~~~~~~~
36-
!!! Property 'match' of type '{ (regexp: string): string[]; (regexp: RegExp): string[]; }' is not assignable to string index type 'string'.
37-
~~~~~~~~~~~~~~~~~~~~
38-
!!! Property 'replace' of type '{ (searchValue: string, replaceValue: string): string; (searchValue: string, replaceValue: (substring: string, ...args: any[]) => string): string; (searchValue: RegExp, replaceValue: string): string; (searchValue: RegExp, replaceValue: (substring: string, ...args: any[]) => string): string; }' is not assignable to string index type 'string'.
39-
~~~~~~~~~~~~~~~~~~~~
40-
!!! Property 'search' of type '{ (regexp: string): number; (regexp: RegExp): number; }' is not assignable to string index type 'string'.
41-
~~~~~~~~~~~~~~~~~~~~
42-
!!! Property 'slice' of type '(start?: number, end?: number) => string' is not assignable to string index type 'string'.
43-
~~~~~~~~~~~~~~~~~~~~
44-
!!! Property 'split' of type '{ (separator: string, limit?: number): string[]; (separator: RegExp, limit?: number): string[]; }' is not assignable to string index type 'string'.
45-
~~~~~~~~~~~~~~~~~~~~
46-
!!! Property 'substr' of type '(from: number, length?: number) => string' is not assignable to string index type 'string'.
47-
~~~~~~~~~~~~~~~~~~~~
48-
!!! Property 'substring' of type '(start: number, end?: number) => string' is not assignable to string index type 'string'.
49-
~~~~~~~~~~~~~~~~~~~~
50-
!!! Property 'toLocaleLowerCase' of type '() => string' is not assignable to string index type 'string'.
51-
~~~~~~~~~~~~~~~~~~~~
52-
!!! Property 'toLocaleUpperCase' of type '() => string' is not assignable to string index type 'string'.
53-
~~~~~~~~~~~~~~~~~~~~
54-
!!! Property 'toLowerCase' of type '() => string' is not assignable to string index type 'string'.
55-
~~~~~~~~~~~~~~~~~~~~
56-
!!! Property 'toString' of type '() => string' is not assignable to string index type 'string'.
57-
~~~~~~~~~~~~~~~~~~~~
58-
!!! Property 'toUpperCase' of type '() => string' is not assignable to string index type 'string'.
59-
~~~~~~~~~~~~~~~~~~~~
60-
!!! Property 'trim' of type '() => string' is not assignable to string index type 'string'.
61-
[x: string]: string;
62-
~~~~~~~~~~~~~~~~~~~~
12+
interface String {
13+
[x: string]: string;
14+
[x: string]: string;
15+
~~~~~~~~~~~~~~~~~~~~
6316
!!! Duplicate string index signature.
64-
}
17+
}
6518

66-
interface Array<T> {
67-
[x: string]: T;
68-
~~~~~~~~~~~~~~~
69-
!!! Property 'concat' of type '{ <U extends T[]>(...items: U[]): T[]; (...items: T[]): T[]; }' is not assignable to string index type 'T'.
70-
~~~~~~~~~~~~~~~
71-
!!! Property 'every' of type '(callbackfn: (value: T, index: number, array: T[]) => boolean, thisArg?: any) => boolean' is not assignable to string index type 'T'.
72-
~~~~~~~~~~~~~~~
73-
!!! Property 'filter' of type '(callbackfn: (value: T, index: number, array: T[]) => boolean, thisArg?: any) => T[]' is not assignable to string index type 'T'.
74-
~~~~~~~~~~~~~~~
75-
!!! Property 'forEach' of type '(callbackfn: (value: T, index: number, array: T[]) => void, thisArg?: any) => void' is not assignable to string index type 'T'.
76-
~~~~~~~~~~~~~~~
77-
!!! Property 'indexOf' of type '(searchElement: T, fromIndex?: number) => number' is not assignable to string index type 'T'.
78-
~~~~~~~~~~~~~~~
79-
!!! Property 'join' of type '(separator?: string) => string' is not assignable to string index type 'T'.
80-
~~~~~~~~~~~~~~~
81-
!!! Property 'lastIndexOf' of type '(searchElement: T, fromIndex?: number) => number' is not assignable to string index type 'T'.
82-
~~~~~~~~~~~~~~~
83-
!!! Property 'length' of type 'number' is not assignable to string index type 'T'.
84-
~~~~~~~~~~~~~~~
85-
!!! Property 'map' of type '<U>(callbackfn: (value: T, index: number, array: T[]) => U, thisArg?: any) => U[]' is not assignable to string index type 'T'.
86-
~~~~~~~~~~~~~~~
87-
!!! Property 'pop' of type '() => T' is not assignable to string index type 'T'.
88-
~~~~~~~~~~~~~~~
89-
!!! Property 'push' of type '(...items: T[]) => number' is not assignable to string index type 'T'.
90-
~~~~~~~~~~~~~~~
91-
!!! Property 'reduce' of type '{ (callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T, initialValue?: T): T; <U>(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: T[]) => U, initialValue: U): U; }' is not assignable to string index type 'T'.
92-
~~~~~~~~~~~~~~~
93-
!!! Property 'reduceRight' of type '{ (callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T, initialValue?: T): T; <U>(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: T[]) => U, initialValue: U): U; }' is not assignable to string index type 'T'.
94-
~~~~~~~~~~~~~~~
95-
!!! Property 'reverse' of type '() => T[]' is not assignable to string index type 'T'.
96-
~~~~~~~~~~~~~~~
97-
!!! Property 'shift' of type '() => T' is not assignable to string index type 'T'.
98-
~~~~~~~~~~~~~~~
99-
!!! Property 'slice' of type '(start?: number, end?: number) => T[]' is not assignable to string index type 'T'.
100-
~~~~~~~~~~~~~~~
101-
!!! Property 'some' of type '(callbackfn: (value: T, index: number, array: T[]) => boolean, thisArg?: any) => boolean' is not assignable to string index type 'T'.
102-
~~~~~~~~~~~~~~~
103-
!!! Property 'sort' of type '(compareFn?: (a: T, b: T) => number) => T[]' is not assignable to string index type 'T'.
104-
~~~~~~~~~~~~~~~
105-
!!! Property 'splice' of type '{ (start: number): T[]; (start: number, deleteCount: number, ...items: T[]): T[]; }' is not assignable to string index type 'T'.
106-
~~~~~~~~~~~~~~~
107-
!!! Property 'toLocaleString' of type '() => string' is not assignable to string index type 'T'.
108-
~~~~~~~~~~~~~~~
109-
!!! Property 'toString' of type '() => string' is not assignable to string index type 'T'.
110-
~~~~~~~~~~~~~~~
111-
!!! Property 'unshift' of type '(...items: T[]) => number' is not assignable to string index type 'T'.
112-
[x: string]: T;
113-
~~~~~~~~~~~~~~~
19+
interface Array<T> {
20+
[x: string]: T;
21+
[x: string]: T;
22+
~~~~~~~~~~~~~~~
11423
!!! Duplicate string index signature.
115-
}
24+
}
11625

117-
class C {
118-
[x: string]: string;
119-
[x: string]: string;
120-
~~~~~~~~~~~~~~~~~~~~
26+
class C {
27+
[x: string]: string;
28+
[x: string]: string;
29+
~~~~~~~~~~~~~~~~~~~~
12130
!!! Duplicate string index signature.
122-
}
31+
}
12332

124-
interface I {
125-
[x: string]: string;
126-
[x: string]: string;
127-
~~~~~~~~~~~~~~~~~~~~
33+
interface I {
34+
[x: string]: string;
35+
[x: string]: string;
36+
~~~~~~~~~~~~~~~~~~~~
12837
!!! Duplicate string index signature.
129-
}
38+
}
13039

131-
var a: {
132-
[x: string]: string;
133-
[x: string]: string;
134-
~~~~~~~~~~~~~~~~~~~~
40+
var a: {
41+
[x: string]: string;
42+
[x: string]: string;
43+
~~~~~~~~~~~~~~~~~~~~
13544
!!! Duplicate string index signature.
45+
}
13646
}
137-
13847

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,46 @@
11
//// [duplicateStringIndexers.ts]
22
// it is an error to have duplicate index signatures of the same kind in a type
33

4-
interface Number {
5-
[x: string]: string;
6-
[x: string]: string;
7-
}
4+
module test {
5+
interface Number {
6+
[x: string]: string;
7+
[x: string]: string;
8+
}
89

9-
interface String {
10-
[x: string]: string;
11-
[x: string]: string;
12-
}
10+
interface String {
11+
[x: string]: string;
12+
[x: string]: string;
13+
}
1314

14-
interface Array<T> {
15-
[x: string]: T;
16-
[x: string]: T;
17-
}
15+
interface Array<T> {
16+
[x: string]: T;
17+
[x: string]: T;
18+
}
1819

19-
class C {
20-
[x: string]: string;
21-
[x: string]: string;
22-
}
20+
class C {
21+
[x: string]: string;
22+
[x: string]: string;
23+
}
2324

24-
interface I {
25-
[x: string]: string;
26-
[x: string]: string;
27-
}
25+
interface I {
26+
[x: string]: string;
27+
[x: string]: string;
28+
}
2829

29-
var a: {
30-
[x: string]: string;
31-
[x: string]: string;
30+
var a: {
31+
[x: string]: string;
32+
[x: string]: string;
33+
}
3234
}
33-
3435

3536

3637
//// [duplicateStringIndexers.js]
37-
var C = (function () {
38-
function C() {
39-
}
40-
return C;
41-
})();
42-
var a;
38+
var test;
39+
(function (test) {
40+
var C = (function () {
41+
function C() {
42+
}
43+
return C;
44+
})();
45+
var a;
46+
})(test || (test = {}));

0 commit comments

Comments
 (0)