Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ES6 typings #987

Merged
merged 38 commits into from
Dec 2, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
fe4a96e
Allow static side of native types to be extended
mhegazy Oct 29, 2014
c8db066
First draft of es6 typings
mhegazy Oct 29, 2014
63e1363
Load the es6 lib if target is es6
mhegazy Oct 29, 2014
4f8605b
Add reflect definition
mhegazy Oct 29, 2014
13a6487
Merge branch 'master' into es6Typings
mhegazy Nov 11, 2014
00bfc06
remove unused arguments for getCompiler
mhegazy Nov 11, 2014
ff32be7
Add additional property to mapfn for Array.from
mhegazy Nov 11, 2014
f5eef43
Use the correct name for interface Math
mhegazy Nov 11, 2014
6ae43f3
Fix paramters for Math.hypot function
mhegazy Nov 11, 2014
6b5d0b0
Use PropertyKey instead of string when appropriate
mhegazy Nov 11, 2014
20bbebc
Make WeakMap.prototype.set second parameter optional
mhegazy Nov 11, 2014
4257e1c
Make Map.prototype.set second paramter optional
mhegazy Nov 11, 2014
abed6e4
Cleanup Proxy definition
mhegazy Nov 11, 2014
ded34ef
Add support for typed arrays
mhegazy Nov 11, 2014
7d6f7ea
Fix symbol constructor and update Object properties
mhegazy Nov 14, 2014
2897612
Add Promise typing support
mhegazy Nov 15, 2014
1986fb1
Respond to code review comments
mhegazy Nov 17, 2014
0629bba
allow non ts files to be passed in to the compiler
mhegazy Nov 17, 2014
6c6d9bf
Add test262 test runner
mhegazy Nov 17, 2014
0dddfd9
respond to code review comment
mhegazy Nov 17, 2014
25ce5db
Merge branch 'master' into es6Typings
mhegazy Nov 17, 2014
19854a0
Add TypedArray tests
mhegazy Nov 17, 2014
4413dd5
Move the Internationalization API to its own file and include it in E…
mhegazy Nov 17, 2014
f33c1d5
Add ArrayBufferView definition to ES6 lib
mhegazy Nov 17, 2014
1abe1d7
Add dom to es6 lib
mhegazy Nov 17, 2014
bdee183
minor fixes
mhegazy Nov 17, 2014
4c2f5d1
Add some more jsdoc comments and ensure everything has a constructor …
mhegazy Nov 17, 2014
ff2e4fa
remove extra call to getSourceFile
mhegazy Nov 17, 2014
ebf4ed8
Respond to code review comments
mhegazy Nov 20, 2014
d3e70ec
Merge branch 'master' into es6typings
mhegazy Nov 27, 2014
507ec3d
Merge branch 'master' into es6Typings
mhegazy Nov 27, 2014
ef14da0
Add tree serializer to test262
mhegazy Nov 27, 2014
af38970
Move collateOutputs to harness
mhegazy Nov 27, 2014
cc270c7
Add the test262 helper file
mhegazy Nov 27, 2014
199b71c
Merge branch 'master' into es6Typings
mhegazy Dec 1, 2014
99d13f4
handel serializing diagnostics
mhegazy Dec 2, 2014
4e79458
Merge branch 'master' into es6typings
mhegazy Dec 2, 2014
d390f67
add missing prototype definitions
mhegazy Dec 2, 2014
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ tests/cases/*/*/*.js.map
tests/cases/*/*/*/*.js.map
tests/cases/*/*/*/*/*.js.map
tests/cases/rwc/*
tests/cases/test262/*
tests/cases/perf/*
!tests/cases/webharness/compilerToString.js
test-args.txt
Expand All @@ -19,6 +20,7 @@ tests/baselines/local/*
tests/services/baselines/local/*
tests/baselines/prototyping/local/*
tests/baselines/rwc/*
tests/baselines/test262/*
tests/services/baselines/prototyping/local/*
tests/services/browser/typescriptServices.js
scripts/processDiagnosticMessages.d.ts
Expand Down
18 changes: 15 additions & 3 deletions Jakefile
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ var harnessSources = [
"projectsRunner.ts",
"loggedIO.ts",
"rwcRunner.ts",
"test262Runner.ts",
"runner.ts"
].map(function (f) {
return path.join(harnessDirectory, f);
Expand All @@ -91,10 +92,12 @@ var harnessSources = [

var librarySourceMap = [
{ target: "lib.core.d.ts", sources: ["core.d.ts"] },
{ target: "lib.dom.d.ts", sources: ["importcore.d.ts", "extensions.d.ts", "dom.generated.d.ts"], },
{ target: "lib.webworker.d.ts", sources: ["importcore.d.ts", "extensions.d.ts", "webworker.generated.d.ts"], },
{ target: "lib.dom.d.ts", sources: ["importcore.d.ts", "extensions.d.ts", "intl.d.ts", "dom.generated.d.ts"], },
{ target: "lib.webworker.d.ts", sources: ["importcore.d.ts", "extensions.d.ts", "intl.d.ts", "webworker.generated.d.ts"], },
{ target: "lib.scriptHost.d.ts", sources: ["importcore.d.ts", "scriptHost.d.ts"], },
{ target: "lib.d.ts", sources: ["core.d.ts", "extensions.d.ts", "dom.generated.d.ts", "webworker.importscripts.d.ts", "scriptHost.d.ts"], },
{ 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"], },
{ target: "lib.core.es6.d.ts", sources: ["core.d.ts", "es6.d.ts"]},
{ 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"]},
];

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

var localTest262Baseline = "tests/baselines/test262/local/";
var refTest262Baseline = "tests/baselines/test262/reference/";

desc("Builds the test infrastructure using the built compiler");
task("tests", ["local", run].concat(libraryTargets));

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

desc("Makes the most recent test262 test results the new baseline, overwriting the old baseline");
task("baseline-accept-test262", function() {
jake.rmRf(refTest262Baseline);
fs.renameSync(localTest262Baseline, refTest262Baseline);
});


// Webhost
var webhostPath = "tests/webhost/webtsc.ts";
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5452,7 +5452,7 @@ module ts {

forEach(rootNames, name => processRootFile(name, false));
if (!seenNoDefaultLib) {
processRootFile(host.getDefaultLibFilename(), true);
processRootFile(host.getDefaultLibFilename(options), true);
}
verifyCompilerOptions();
errors.sort(compareDiagnostics);
Expand Down Expand Up @@ -5496,7 +5496,7 @@ module ts {
}
var diagnostic: DiagnosticMessage;
if (hasExtension(filename)) {
if (!fileExtensionIs(filename, ".ts")) {
if (!options.allowNonTsExtensions && !fileExtensionIs(filename, ".ts")) {
diagnostic = Diagnostics.File_0_must_have_extension_ts_or_d_ts;
}
else if (!findSourceFile(filename, isDefaultLib, refFile, refPos, refEnd)) {
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/tsc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ module ts {

return {
getSourceFile,
getDefaultLibFilename: () => combinePaths(getDirectoryPath(normalizePath(sys.getExecutingFilePath())), "lib.d.ts"),
getDefaultLibFilename: options => combinePaths(getDirectoryPath(normalizePath(sys.getExecutingFilePath())), options.target === ScriptTarget.ES6 ? "lib.es6.d.ts" : "lib.d.ts"),
writeFile,
getCurrentDirectory: () => currentDirectory || (currentDirectory = sys.getCurrentDirectory()),
useCaseSensitiveFileNames: () => sys.useCaseSensitiveFileNames,
Expand Down
3 changes: 2 additions & 1 deletion src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1306,6 +1306,7 @@ module ts {
version?: boolean;
watch?: boolean;
preserveConstEnums?: boolean;
allowNonTsExtensions?: boolean;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens on compile on save - So what happens with emit - what file name do we give.. Should it be emitted? Should it be considered ts file and not .d.ts file? What about declaration file generation - I think we should give error if emit is called with this option. (Emit time error)
We need tests with and without this option and .d.ts and .js file generation. Can be compiler baseline I guess.

[option: string]: string | number | boolean;
}

Expand Down Expand Up @@ -1487,7 +1488,7 @@ module ts {

export interface CompilerHost {
getSourceFile(filename: string, languageVersion: ScriptTarget, onError?: (message: string) => void): SourceFile;
getDefaultLibFilename(): string;
getDefaultLibFilename(options: CompilerOptions): string;
getCancellationToken? (): CancellationToken;
writeFile(filename: string, data: string, writeByteOrderMark: boolean, onError?: (message: string) => void): void;
getCurrentDirectory(): string;
Expand Down
20 changes: 4 additions & 16 deletions src/harness/compilerRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,7 @@ class CompilerBaselineRunner extends RunnerBase {
for (var i = 0; i < tcSettings.length; ++i) {
// noImplicitAny is passed to getCompiler, but target is just passed in the settings blob to setCompilerSettings
if (!createNewInstance && (tcSettings[i].flag == "noimplicitany" || tcSettings[i].flag === 'target')) {
harnessCompiler = Harness.Compiler.getCompiler({
useExistingInstance: false,
optionsForFreshInstance: { useMinimalDefaultLib: true, noImplicitAny: tcSettings[i].flag === "noimplicitany" }
});
harnessCompiler = Harness.Compiler.getCompiler();
harnessCompiler.setCompilerSettings(tcSettings);
createNewInstance = true;
}
Expand All @@ -125,10 +122,7 @@ class CompilerBaselineRunner extends RunnerBase {

afterEach(() => {
if (createNewInstance) {
harnessCompiler = Harness.Compiler.getCompiler({
useExistingInstance: false,
optionsForFreshInstance: { useMinimalDefaultLib: true, noImplicitAny: false }
});
harnessCompiler = Harness.Compiler.getCompiler();
createNewInstance = false;
}
});
Expand Down Expand Up @@ -323,10 +317,7 @@ class CompilerBaselineRunner extends RunnerBase {

public initializeTests() {
describe("Setup compiler for compiler baselines", () => {
var harnessCompiler = Harness.Compiler.getCompiler({
useExistingInstance: false,
optionsForFreshInstance: { useMinimalDefaultLib: true, noImplicitAny: false }
});
var harnessCompiler = Harness.Compiler.getCompiler();
this.parseOptions();
});

Expand All @@ -343,10 +334,7 @@ class CompilerBaselineRunner extends RunnerBase {
}

describe("Cleanup after compiler baselines", () => {
var harnessCompiler = Harness.Compiler.getCompiler({
useExistingInstance: false,
optionsForFreshInstance: { useMinimalDefaultLib: true, noImplicitAny: false }
});
var harnessCompiler = Harness.Compiler.getCompiler();
});
}

Expand Down
8 changes: 0 additions & 8 deletions src/harness/fourslashRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ class FourslashRunner extends RunnerBase {
}

describe("fourslash tests", () => {
before(() => {
Harness.Compiler.getCompiler({ useExistingInstance: false });
});

this.tests.forEach((fn: string) => {
fn = ts.normalizeSlashes(fn);
var justName = fn.replace(/^.*[\\\/]/, '');
Expand All @@ -33,10 +29,6 @@ class FourslashRunner extends RunnerBase {
});
}
});

after(() => {
Harness.Compiler.getCompiler({ useExistingInstance: false });
});
});

describe('Generate Tao XML', () => {
Expand Down
45 changes: 29 additions & 16 deletions src/harness/harness.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
Expand Down Expand Up @@ -538,6 +539,8 @@ module Harness {

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


// Cache these between executions so we don't have to re-parse them for every test
export var fourslashFilename = 'fourslash.ts';
Expand Down Expand Up @@ -580,15 +583,14 @@ module Harness {
return fourslashSourceFile;
}
else {
var lib = defaultLibFileName;
if (fn === defaultLibFileName) {
return defaultLibSourceFile;
return languageVersion === ts.ScriptTarget.ES6 ? defaultES6LibSourceFile : defaultLibSourceFile;
}
// Don't throw here -- the compiler might be looking for a test that actually doesn't exist as part of the TC
return undefined;
}
},
getDefaultLibFilename: () => defaultLibFileName,
getDefaultLibFilename: options => defaultLibFileName,
writeFile,
getCanonicalFileName,
useCaseSensitiveFileNames: () => useCaseSensitiveFileNames,
Expand Down Expand Up @@ -1016,27 +1018,38 @@ module Harness {
sys.newLine + sys.newLine + outputLines.join('\r\n');
}

/* TODO: Delete?
export function makeDefaultCompilerSettings(options?: { useMinimalDefaultLib: boolean; noImplicitAny: boolean; }) {
var useMinimalDefaultLib = options ? options.useMinimalDefaultLib : true;
var noImplicitAny = options ? options.noImplicitAny : false;
var settings = new TypeScript.CompilationSettings();
settings.codeGenTarget = TypeScript.LanguageVersion.EcmaScript5;
settings.moduleGenTarget = TypeScript.ModuleGenTarget.Synchronous;
settings.noLib = useMinimalDefaultLib;
settings.noResolve = false;
settings.noImplicitAny = noImplicitAny;
return settings;
export function collateOutputs(outputFiles: Harness.Compiler.GeneratedFile[], clean?: (s: string) => string) {
// Collect, test, and sort the filenames
function cleanName(fn: string) {
var lastSlash = ts.normalizeSlashes(fn).lastIndexOf('/');
return fn.substr(lastSlash + 1).toLowerCase();
}
outputFiles.sort((a, b) => cleanName(a.fileName).localeCompare(cleanName(b.fileName)));

// Emit them
var result = '';
ts.forEach(outputFiles, outputFile => {
// Some extra spacing if this isn't the first file
if (result.length) result = result + '\r\n\r\n';

// Filename header + content
result = result + '/*====== ' + outputFile.fileName + ' ======*/\r\n';
if (clean) {
result = result + clean(outputFile.code);
} else {
result = result + outputFile.code;
}
});
return result;
}
*/

/** 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) */
var harnessCompiler: HarnessCompiler;

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

Expand Down
4 changes: 2 additions & 2 deletions src/harness/projectsRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ class ProjectRunner extends RunnerBase {
function getSourceFile(filename: string, languageVersion: ts.ScriptTarget): ts.SourceFile {
var sourceFile: ts.SourceFile = undefined;
if (filename === Harness.Compiler.defaultLibFileName) {
sourceFile = Harness.Compiler.defaultLibSourceFile;
sourceFile = languageVersion === ts.ScriptTarget.ES6 ? Harness.Compiler.defaultES6LibSourceFile : Harness.Compiler.defaultLibSourceFile;
}
else {
var text = getSourceFileText(filename);
Expand All @@ -186,7 +186,7 @@ class ProjectRunner extends RunnerBase {
function createCompilerHost(): ts.CompilerHost {
return {
getSourceFile,
getDefaultLibFilename: () => "lib.d.ts",
getDefaultLibFilename: options => options.target === ts.ScriptTarget.ES6 ? "lib.es6.d.ts" : "lib.d.ts",
writeFile,
getCurrentDirectory,
getCanonicalFileName: Harness.Compiler.getCanonicalFileName,
Expand Down
7 changes: 5 additions & 2 deletions src/harness/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
// limitations under the License.
//

/// <reference path='test262Runner.ts' />
/// <reference path='compilerRunner.ts' />
// TODO: re-enable
// ///<reference path='fourslashRunner.ts' />
/// <reference path='fourslashRunner.ts' />
/// <reference path='projectsRunner.ts' />
/// <reference path='rwcRunner.ts' />

Expand Down Expand Up @@ -69,6 +69,9 @@ if (testConfigFile !== '') {
case 'rwc':
runners.push(new RWCRunner());
break;
case 'test262':
runners.push(new Test262BaselineRunner());
break;
case 'reverse':
reverse = true;
break;
Expand Down
31 changes: 3 additions & 28 deletions src/harness/rwcRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,6 @@ module RWC {
}
}

function collateOutputs(outputFiles: Harness.Compiler.GeneratedFile[], clean?: (s: string) => string) {
// Collect, test, and sort the filenames
function cleanName(fn: string) {
var lastSlash = ts.normalizeSlashes(fn).lastIndexOf('/');
return fn.substr(lastSlash + 1).toLowerCase();
}
outputFiles.sort((a, b) => cleanName(a.fileName).localeCompare(cleanName(b.fileName)));

// Emit them
var result = '';
ts.forEach(outputFiles, outputFile => {
// Some extra spacing if this isn't the first file
if (result.length) result = result + '\r\n\r\n';

// Filename header + content
result = result + '/*====== ' + outputFile.fileName + ' ======*/\r\n';
if (clean) {
result = result + clean(outputFile.code);
} else {
result = result + outputFile.code;
}
});
return result;
}

export function runRWCTest(jsonPath: string) {
describe("Testing a RWC project: " + jsonPath, () => {
var inputFiles: { unitName: string; content: string; }[] = [];
Expand Down Expand Up @@ -136,7 +111,7 @@ module RWC {

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

Expand All @@ -145,7 +120,7 @@ module RWC {
if (compilerResult.errors.length || !compilerResult.declFilesCode.length) {
return null;
}
return collateOutputs(compilerResult.declFilesCode);
return Harness.Compiler.collateOutputs(compilerResult.declFilesCode);
}, false, baselineOpts);
});

Expand All @@ -155,7 +130,7 @@ module RWC {
return null;
}

return collateOutputs(compilerResult.sourceMaps);
return Harness.Compiler.collateOutputs(compilerResult.sourceMaps);
}, false, baselineOpts);
});

Expand Down
Loading