Skip to content

Commit 28a3745

Browse files
committed
Merge pull request #987 from Microsoft/es6Typings
ES6 typings
2 parents 203e46c + d390f67 commit 28a3745

File tree

71 files changed

+5780
-423
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+5780
-423
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ tests/cases/*/*/*.js.map
1111
tests/cases/*/*/*/*.js.map
1212
tests/cases/*/*/*/*/*.js.map
1313
tests/cases/rwc/*
14+
tests/cases/test262/*
1415
tests/cases/perf/*
1516
!tests/cases/webharness/compilerToString.js
1617
test-args.txt
@@ -19,6 +20,7 @@ tests/baselines/local/*
1920
tests/services/baselines/local/*
2021
tests/baselines/prototyping/local/*
2122
tests/baselines/rwc/*
23+
tests/baselines/test262/*
2224
tests/services/baselines/prototyping/local/*
2325
tests/services/browser/typescriptServices.js
2426
scripts/processDiagnosticMessages.d.ts

Jakefile

+15-3
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ var harnessSources = [
7878
"projectsRunner.ts",
7979
"loggedIO.ts",
8080
"rwcRunner.ts",
81+
"test262Runner.ts",
8182
"runner.ts"
8283
].map(function (f) {
8384
return path.join(harnessDirectory, f);
@@ -91,10 +92,12 @@ var harnessSources = [
9192

9293
var librarySourceMap = [
9394
{ target: "lib.core.d.ts", sources: ["core.d.ts"] },
94-
{ target: "lib.dom.d.ts", sources: ["importcore.d.ts", "extensions.d.ts", "dom.generated.d.ts"], },
95-
{ target: "lib.webworker.d.ts", sources: ["importcore.d.ts", "extensions.d.ts", "webworker.generated.d.ts"], },
95+
{ target: "lib.dom.d.ts", sources: ["importcore.d.ts", "extensions.d.ts", "intl.d.ts", "dom.generated.d.ts"], },
96+
{ target: "lib.webworker.d.ts", sources: ["importcore.d.ts", "extensions.d.ts", "intl.d.ts", "webworker.generated.d.ts"], },
9697
{ target: "lib.scriptHost.d.ts", sources: ["importcore.d.ts", "scriptHost.d.ts"], },
97-
{ target: "lib.d.ts", sources: ["core.d.ts", "extensions.d.ts", "dom.generated.d.ts", "webworker.importscripts.d.ts", "scriptHost.d.ts"], },
98+
{ target: "lib.d.ts", sources: ["core.d.ts", "extensions.d.ts", "intl.d.ts", "dom.generated.d.ts", "webworker.importscripts.d.ts", "scriptHost.d.ts"], },
99+
{ target: "lib.core.es6.d.ts", sources: ["core.d.ts", "es6.d.ts"]},
100+
{ target: "lib.es6.d.ts", sources: ["core.d.ts", "es6.d.ts", "intl.d.ts", "dom.generated.d.ts", "webworker.importscripts.d.ts", "scriptHost.d.ts"]},
98101
];
99102

100103
var libraryTargets = librarySourceMap.map(function (f) {
@@ -341,6 +344,9 @@ var refBaseline = "tests/baselines/reference/";
341344
var localRwcBaseline = "tests/baselines/rwc/local/";
342345
var refRwcBaseline = "tests/baselines/rwc/reference/";
343346

347+
var localTest262Baseline = "tests/baselines/test262/local/";
348+
var refTest262Baseline = "tests/baselines/test262/reference/";
349+
344350
desc("Builds the test infrastructure using the built compiler");
345351
task("tests", ["local", run].concat(libraryTargets));
346352

@@ -509,6 +515,12 @@ task("baseline-accept-rwc", function() {
509515
fs.renameSync(localRwcBaseline, refRwcBaseline);
510516
});
511517

518+
desc("Makes the most recent test262 test results the new baseline, overwriting the old baseline");
519+
task("baseline-accept-test262", function() {
520+
jake.rmRf(refTest262Baseline);
521+
fs.renameSync(localTest262Baseline, refTest262Baseline);
522+
});
523+
512524

513525
// Webhost
514526
var webhostPath = "tests/webhost/webtsc.ts";

src/compiler/parser.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -5452,7 +5452,7 @@ module ts {
54525452

54535453
forEach(rootNames, name => processRootFile(name, false));
54545454
if (!seenNoDefaultLib) {
5455-
processRootFile(host.getDefaultLibFilename(), true);
5455+
processRootFile(host.getDefaultLibFilename(options), true);
54565456
}
54575457
verifyCompilerOptions();
54585458
errors.sort(compareDiagnostics);
@@ -5496,7 +5496,7 @@ module ts {
54965496
}
54975497
var diagnostic: DiagnosticMessage;
54985498
if (hasExtension(filename)) {
5499-
if (!fileExtensionIs(filename, ".ts")) {
5499+
if (!options.allowNonTsExtensions && !fileExtensionIs(filename, ".ts")) {
55005500
diagnostic = Diagnostics.File_0_must_have_extension_ts_or_d_ts;
55015501
}
55025502
else if (!findSourceFile(filename, isDefaultLib, refFile, refPos, refEnd)) {

src/compiler/tsc.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ module ts {
193193

194194
return {
195195
getSourceFile,
196-
getDefaultLibFilename: () => combinePaths(getDirectoryPath(normalizePath(sys.getExecutingFilePath())), "lib.d.ts"),
196+
getDefaultLibFilename: options => combinePaths(getDirectoryPath(normalizePath(sys.getExecutingFilePath())), options.target === ScriptTarget.ES6 ? "lib.es6.d.ts" : "lib.d.ts"),
197197
writeFile,
198198
getCurrentDirectory: () => currentDirectory || (currentDirectory = sys.getCurrentDirectory()),
199199
useCaseSensitiveFileNames: () => sys.useCaseSensitiveFileNames,

src/compiler/types.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1306,6 +1306,7 @@ module ts {
13061306
version?: boolean;
13071307
watch?: boolean;
13081308
preserveConstEnums?: boolean;
1309+
allowNonTsExtensions?: boolean;
13091310
[option: string]: string | number | boolean;
13101311
}
13111312

@@ -1487,7 +1488,7 @@ module ts {
14871488

14881489
export interface CompilerHost {
14891490
getSourceFile(filename: string, languageVersion: ScriptTarget, onError?: (message: string) => void): SourceFile;
1490-
getDefaultLibFilename(): string;
1491+
getDefaultLibFilename(options: CompilerOptions): string;
14911492
getCancellationToken? (): CancellationToken;
14921493
writeFile(filename: string, data: string, writeByteOrderMark: boolean, onError?: (message: string) => void): void;
14931494
getCurrentDirectory(): string;

src/harness/compilerRunner.ts

+4-16
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,7 @@ class CompilerBaselineRunner extends RunnerBase {
113113
for (var i = 0; i < tcSettings.length; ++i) {
114114
// noImplicitAny is passed to getCompiler, but target is just passed in the settings blob to setCompilerSettings
115115
if (!createNewInstance && (tcSettings[i].flag == "noimplicitany" || tcSettings[i].flag === 'target')) {
116-
harnessCompiler = Harness.Compiler.getCompiler({
117-
useExistingInstance: false,
118-
optionsForFreshInstance: { useMinimalDefaultLib: true, noImplicitAny: tcSettings[i].flag === "noimplicitany" }
119-
});
116+
harnessCompiler = Harness.Compiler.getCompiler();
120117
harnessCompiler.setCompilerSettings(tcSettings);
121118
createNewInstance = true;
122119
}
@@ -125,10 +122,7 @@ class CompilerBaselineRunner extends RunnerBase {
125122

126123
afterEach(() => {
127124
if (createNewInstance) {
128-
harnessCompiler = Harness.Compiler.getCompiler({
129-
useExistingInstance: false,
130-
optionsForFreshInstance: { useMinimalDefaultLib: true, noImplicitAny: false }
131-
});
125+
harnessCompiler = Harness.Compiler.getCompiler();
132126
createNewInstance = false;
133127
}
134128
});
@@ -323,10 +317,7 @@ class CompilerBaselineRunner extends RunnerBase {
323317

324318
public initializeTests() {
325319
describe("Setup compiler for compiler baselines", () => {
326-
var harnessCompiler = Harness.Compiler.getCompiler({
327-
useExistingInstance: false,
328-
optionsForFreshInstance: { useMinimalDefaultLib: true, noImplicitAny: false }
329-
});
320+
var harnessCompiler = Harness.Compiler.getCompiler();
330321
this.parseOptions();
331322
});
332323

@@ -343,10 +334,7 @@ class CompilerBaselineRunner extends RunnerBase {
343334
}
344335

345336
describe("Cleanup after compiler baselines", () => {
346-
var harnessCompiler = Harness.Compiler.getCompiler({
347-
useExistingInstance: false,
348-
optionsForFreshInstance: { useMinimalDefaultLib: true, noImplicitAny: false }
349-
});
337+
var harnessCompiler = Harness.Compiler.getCompiler();
350338
});
351339
}
352340

src/harness/fourslashRunner.ts

-8
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@ class FourslashRunner extends RunnerBase {
1515
}
1616

1717
describe("fourslash tests", () => {
18-
before(() => {
19-
Harness.Compiler.getCompiler({ useExistingInstance: false });
20-
});
21-
2218
this.tests.forEach((fn: string) => {
2319
fn = ts.normalizeSlashes(fn);
2420
var justName = fn.replace(/^.*[\\\/]/, '');
@@ -33,10 +29,6 @@ class FourslashRunner extends RunnerBase {
3329
});
3430
}
3531
});
36-
37-
after(() => {
38-
Harness.Compiler.getCompiler({ useExistingInstance: false });
39-
});
4032
});
4133

4234
describe('Generate Tao XML', () => {

src/harness/harness.ts

+29-16
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
//
23
// Copyright (c) Microsoft Corporation. All rights reserved.
34
//
@@ -538,6 +539,8 @@ module Harness {
538539

539540
export var defaultLibFileName = 'lib.d.ts';
540541
export var defaultLibSourceFile = ts.createSourceFile(defaultLibFileName, IO.readFile(libFolder + 'lib.core.d.ts'), /*languageVersion*/ ts.ScriptTarget.Latest, /*version:*/ "0");
542+
export var defaultES6LibSourceFile = ts.createSourceFile(defaultLibFileName, IO.readFile(libFolder + 'lib.core.es6.d.ts'), /*languageVersion*/ ts.ScriptTarget.Latest, /*version:*/ "0");
543+
541544

542545
// Cache these between executions so we don't have to re-parse them for every test
543546
export var fourslashFilename = 'fourslash.ts';
@@ -580,15 +583,14 @@ module Harness {
580583
return fourslashSourceFile;
581584
}
582585
else {
583-
var lib = defaultLibFileName;
584586
if (fn === defaultLibFileName) {
585-
return defaultLibSourceFile;
587+
return languageVersion === ts.ScriptTarget.ES6 ? defaultES6LibSourceFile : defaultLibSourceFile;
586588
}
587589
// Don't throw here -- the compiler might be looking for a test that actually doesn't exist as part of the TC
588590
return undefined;
589591
}
590592
},
591-
getDefaultLibFilename: () => defaultLibFileName,
593+
getDefaultLibFilename: options => defaultLibFileName,
592594
writeFile,
593595
getCanonicalFileName,
594596
useCaseSensitiveFileNames: () => useCaseSensitiveFileNames,
@@ -1016,27 +1018,38 @@ module Harness {
10161018
sys.newLine + sys.newLine + outputLines.join('\r\n');
10171019
}
10181020

1019-
/* TODO: Delete?
1020-
export function makeDefaultCompilerSettings(options?: { useMinimalDefaultLib: boolean; noImplicitAny: boolean; }) {
1021-
var useMinimalDefaultLib = options ? options.useMinimalDefaultLib : true;
1022-
var noImplicitAny = options ? options.noImplicitAny : false;
1023-
var settings = new TypeScript.CompilationSettings();
1024-
settings.codeGenTarget = TypeScript.LanguageVersion.EcmaScript5;
1025-
settings.moduleGenTarget = TypeScript.ModuleGenTarget.Synchronous;
1026-
settings.noLib = useMinimalDefaultLib;
1027-
settings.noResolve = false;
1028-
settings.noImplicitAny = noImplicitAny;
1029-
return settings;
1021+
export function collateOutputs(outputFiles: Harness.Compiler.GeneratedFile[], clean?: (s: string) => string) {
1022+
// Collect, test, and sort the filenames
1023+
function cleanName(fn: string) {
1024+
var lastSlash = ts.normalizeSlashes(fn).lastIndexOf('/');
1025+
return fn.substr(lastSlash + 1).toLowerCase();
1026+
}
1027+
outputFiles.sort((a, b) => cleanName(a.fileName).localeCompare(cleanName(b.fileName)));
1028+
1029+
// Emit them
1030+
var result = '';
1031+
ts.forEach(outputFiles, outputFile => {
1032+
// Some extra spacing if this isn't the first file
1033+
if (result.length) result = result + '\r\n\r\n';
1034+
1035+
// Filename header + content
1036+
result = result + '/*====== ' + outputFile.fileName + ' ======*/\r\n';
1037+
if (clean) {
1038+
result = result + clean(outputFile.code);
1039+
} else {
1040+
result = result + outputFile.code;
1041+
}
1042+
});
1043+
return result;
10301044
}
1031-
*/
10321045

10331046
/** The harness' compiler instance used when tests are actually run. Reseting or changing settings of this compiler instance must be done within a test case (i.e., describe/it) */
10341047
var harnessCompiler: HarnessCompiler;
10351048

10361049
/** Returns the singleton harness compiler instance for generating and running tests.
10371050
If required a fresh compiler instance will be created, otherwise the existing singleton will be re-used.
10381051
*/
1039-
export function getCompiler(opts?: { useExistingInstance: boolean; optionsForFreshInstance?: { useMinimalDefaultLib: boolean; noImplicitAny: boolean; } }) {
1052+
export function getCompiler() {
10401053
return harnessCompiler = harnessCompiler || new HarnessCompiler();
10411054
}
10421055

src/harness/projectsRunner.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ class ProjectRunner extends RunnerBase {
171171
function getSourceFile(filename: string, languageVersion: ts.ScriptTarget): ts.SourceFile {
172172
var sourceFile: ts.SourceFile = undefined;
173173
if (filename === Harness.Compiler.defaultLibFileName) {
174-
sourceFile = Harness.Compiler.defaultLibSourceFile;
174+
sourceFile = languageVersion === ts.ScriptTarget.ES6 ? Harness.Compiler.defaultES6LibSourceFile : Harness.Compiler.defaultLibSourceFile;
175175
}
176176
else {
177177
var text = getSourceFileText(filename);
@@ -186,7 +186,7 @@ class ProjectRunner extends RunnerBase {
186186
function createCompilerHost(): ts.CompilerHost {
187187
return {
188188
getSourceFile,
189-
getDefaultLibFilename: () => "lib.d.ts",
189+
getDefaultLibFilename: options => options.target === ts.ScriptTarget.ES6 ? "lib.es6.d.ts" : "lib.d.ts",
190190
writeFile,
191191
getCurrentDirectory,
192192
getCanonicalFileName: Harness.Compiler.getCanonicalFileName,

src/harness/runner.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
// limitations under the License.
1414
//
1515

16+
/// <reference path='test262Runner.ts' />
1617
/// <reference path='compilerRunner.ts' />
17-
// TODO: re-enable
18-
// ///<reference path='fourslashRunner.ts' />
18+
/// <reference path='fourslashRunner.ts' />
1919
/// <reference path='projectsRunner.ts' />
2020
/// <reference path='rwcRunner.ts' />
2121

@@ -69,6 +69,9 @@ if (testConfigFile !== '') {
6969
case 'rwc':
7070
runners.push(new RWCRunner());
7171
break;
72+
case 'test262':
73+
runners.push(new Test262BaselineRunner());
74+
break;
7275
case 'reverse':
7376
reverse = true;
7477
break;

src/harness/rwcRunner.ts

+3-28
Original file line numberDiff line numberDiff line change
@@ -20,31 +20,6 @@ module RWC {
2020
}
2121
}
2222

23-
function collateOutputs(outputFiles: Harness.Compiler.GeneratedFile[], clean?: (s: string) => string) {
24-
// Collect, test, and sort the filenames
25-
function cleanName(fn: string) {
26-
var lastSlash = ts.normalizeSlashes(fn).lastIndexOf('/');
27-
return fn.substr(lastSlash + 1).toLowerCase();
28-
}
29-
outputFiles.sort((a, b) => cleanName(a.fileName).localeCompare(cleanName(b.fileName)));
30-
31-
// Emit them
32-
var result = '';
33-
ts.forEach(outputFiles, outputFile => {
34-
// Some extra spacing if this isn't the first file
35-
if (result.length) result = result + '\r\n\r\n';
36-
37-
// Filename header + content
38-
result = result + '/*====== ' + outputFile.fileName + ' ======*/\r\n';
39-
if (clean) {
40-
result = result + clean(outputFile.code);
41-
} else {
42-
result = result + outputFile.code;
43-
}
44-
});
45-
return result;
46-
}
47-
4823
export function runRWCTest(jsonPath: string) {
4924
describe("Testing a RWC project: " + jsonPath, () => {
5025
var inputFiles: { unitName: string; content: string; }[] = [];
@@ -136,7 +111,7 @@ module RWC {
136111

137112
it('has the expected emitted code', () => {
138113
Harness.Baseline.runBaseline('has the expected emitted code', baseName + '.output.js', () => {
139-
return collateOutputs(compilerResult.files, s => SyntacticCleaner.clean(s));
114+
return Harness.Compiler.collateOutputs(compilerResult.files, s => SyntacticCleaner.clean(s));
140115
}, false, baselineOpts);
141116
});
142117

@@ -145,7 +120,7 @@ module RWC {
145120
if (compilerResult.errors.length || !compilerResult.declFilesCode.length) {
146121
return null;
147122
}
148-
return collateOutputs(compilerResult.declFilesCode);
123+
return Harness.Compiler.collateOutputs(compilerResult.declFilesCode);
149124
}, false, baselineOpts);
150125
});
151126

@@ -155,7 +130,7 @@ module RWC {
155130
return null;
156131
}
157132

158-
return collateOutputs(compilerResult.sourceMaps);
133+
return Harness.Compiler.collateOutputs(compilerResult.sourceMaps);
159134
}, false, baselineOpts);
160135
});
161136

0 commit comments

Comments
 (0)