diff --git a/.gitignore b/.gitignore
index 740e43525b5a3..8e2c10d7b32bc 100644
--- a/.gitignore
+++ b/.gitignore
@@ -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
@@ -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
diff --git a/Jakefile b/Jakefile
index ba82e9c3f4363..f76110bb5f2ee 100644
--- a/Jakefile
+++ b/Jakefile
@@ -78,6 +78,7 @@ var harnessSources = [
"projectsRunner.ts",
"loggedIO.ts",
"rwcRunner.ts",
+ "test262Runner.ts",
"runner.ts"
].map(function (f) {
return path.join(harnessDirectory, f);
@@ -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) {
@@ -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));
@@ -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";
diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts
index dde4995cd991c..cea57352ae31b 100644
--- a/src/compiler/parser.ts
+++ b/src/compiler/parser.ts
@@ -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);
@@ -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)) {
diff --git a/src/compiler/tsc.ts b/src/compiler/tsc.ts
index 9bb2db719f120..333f80a663e97 100644
--- a/src/compiler/tsc.ts
+++ b/src/compiler/tsc.ts
@@ -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,
diff --git a/src/compiler/types.ts b/src/compiler/types.ts
index de90a49242ec2..e562cbc3b616d 100644
--- a/src/compiler/types.ts
+++ b/src/compiler/types.ts
@@ -1306,6 +1306,7 @@ module ts {
version?: boolean;
watch?: boolean;
preserveConstEnums?: boolean;
+ allowNonTsExtensions?: boolean;
[option: string]: string | number | boolean;
}
@@ -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;
diff --git a/src/harness/compilerRunner.ts b/src/harness/compilerRunner.ts
index cc04d4813a1ae..fd49078d041bb 100644
--- a/src/harness/compilerRunner.ts
+++ b/src/harness/compilerRunner.ts
@@ -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;
}
@@ -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;
}
});
@@ -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();
});
@@ -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();
});
}
diff --git a/src/harness/fourslashRunner.ts b/src/harness/fourslashRunner.ts
index b7e5943745694..1ecb02df292ed 100644
--- a/src/harness/fourslashRunner.ts
+++ b/src/harness/fourslashRunner.ts
@@ -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(/^.*[\\\/]/, '');
@@ -33,10 +29,6 @@ class FourslashRunner extends RunnerBase {
});
}
});
-
- after(() => {
- Harness.Compiler.getCompiler({ useExistingInstance: false });
- });
});
describe('Generate Tao XML', () => {
diff --git a/src/harness/harness.ts b/src/harness/harness.ts
index 1a5938d2be080..640d5f0ae5327 100644
--- a/src/harness/harness.ts
+++ b/src/harness/harness.ts
@@ -1,3 +1,4 @@
+
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
@@ -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';
@@ -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,
@@ -1016,19 +1018,30 @@ 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;
@@ -1036,7 +1049,7 @@ module Harness {
/** 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();
}
diff --git a/src/harness/projectsRunner.ts b/src/harness/projectsRunner.ts
index 4734232d2804d..f46f9ae369846 100644
--- a/src/harness/projectsRunner.ts
+++ b/src/harness/projectsRunner.ts
@@ -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);
@@ -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,
diff --git a/src/harness/runner.ts b/src/harness/runner.ts
index 38e23bb10c5e0..da37c02e2244c 100644
--- a/src/harness/runner.ts
+++ b/src/harness/runner.ts
@@ -13,9 +13,9 @@
// limitations under the License.
//
+///
///
-// TODO: re-enable
-// ///
+///
///
///
@@ -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;
diff --git a/src/harness/rwcRunner.ts b/src/harness/rwcRunner.ts
index 606672e406fd7..b8bc2a80a529c 100644
--- a/src/harness/rwcRunner.ts
+++ b/src/harness/rwcRunner.ts
@@ -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; }[] = [];
@@ -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);
});
@@ -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);
});
@@ -155,7 +130,7 @@ module RWC {
return null;
}
- return collateOutputs(compilerResult.sourceMaps);
+ return Harness.Compiler.collateOutputs(compilerResult.sourceMaps);
}, false, baselineOpts);
});
diff --git a/src/harness/test262Runner.ts b/src/harness/test262Runner.ts
new file mode 100644
index 0000000000000..5527b9383d128
--- /dev/null
+++ b/src/harness/test262Runner.ts
@@ -0,0 +1,139 @@
+///
+///
+///
+
+class Test262BaselineRunner extends RunnerBase {
+ private static basePath = 'tests/cases/test262';
+ private static helpersFilePath = 'tests/cases/test262-harness/helpers.d.ts';
+ private static helperFile = {
+ unitName: Test262BaselineRunner.helpersFilePath,
+ content: Harness.IO.readFile(Test262BaselineRunner.helpersFilePath)
+ };
+ private static testFileExtensionRegex = /\.js$/;
+ private static options: ts.CompilerOptions = {
+ allowNonTsExtensions: true,
+ target: ts.ScriptTarget.Latest,
+ module: ts.ModuleKind.CommonJS
+ };
+ private static baselineOptions: Harness.Baseline.BaselineOptions = { Subfolder: 'test262' };
+
+ private static getTestFilePath(filename: string): string {
+ return Test262BaselineRunner.basePath + "/" + filename;
+ }
+
+ private static serializeSourceFile(file: ts.SourceFile): string {
+ function getKindName(k: number): string {
+ return (ts).SyntaxKind[k]
+ }
+
+ function serializeNode(n: ts.Node): any {
+ var o = { kind: getKindName(n.kind) };
+ ts.forEach(Object.getOwnPropertyNames(n), i => {
+ switch (i) {
+ case "parent":
+ case "symbol":
+ case "locals":
+ case "localSymbol":
+ case "kind":
+ case "semanticDiagnostics":
+ case "parseDiagnostics":
+ case "grammarDiagnostics":
+ return undefined;
+ case "nextContainer":
+ if (n.nextContainer) {
+ (o)[i] = { kind: getKindName(n.nextContainer.kind), pos: n.nextContainer.pos, end: n.nextContainer.end };
+ return undefined;
+ }
+ case "text":
+ if (n.kind === ts.SyntaxKind.SourceFile) return undefined;
+ default:
+ (o)[i] = ((n)[i]);
+ }
+ return undefined;
+ });
+ return o;
+ }
+
+ return JSON.stringify(file,(k, v) => {
+ return (v && typeof v.pos === "number") ? serializeNode(v) : v;
+ }, " ");
+ }
+
+ private runTest(filePath: string) {
+ describe('test262 test for ' + filePath, () => {
+ // Mocha holds onto the closure environment of the describe callback even after the test is done.
+ // Everything declared here should be cleared out in the "after" callback.
+ var testState: {
+ filename: string;
+ compilerResult: Harness.Compiler.CompilerResult;
+ inputFiles: { unitName: string; content: string }[];
+ checker: ts.TypeChecker;
+ };
+
+ before(() => {
+ var content = Harness.IO.readFile(filePath);
+ var testFilename = ts.removeFileExtension(filePath).replace(/\//g, '_') + ".test";
+ var testCaseContent = Harness.TestCaseParser.makeUnitsFromTest(content, testFilename);
+
+ var inputFiles = testCaseContent.testUnitData.map(unit => {
+ return { unitName: Test262BaselineRunner.getTestFilePath(unit.name), content: unit.content };
+ });
+
+ // Emit the results
+ testState = {
+ filename: testFilename,
+ inputFiles: inputFiles,
+ compilerResult: undefined,
+ checker: undefined,
+ };
+
+ Harness.Compiler.getCompiler().compileFiles([Test262BaselineRunner.helperFile].concat(inputFiles), /*otherFiles*/ [], (compilerResult, checker) => {
+ testState.compilerResult = compilerResult;
+ testState.checker = checker;
+ }, /*settingsCallback*/ undefined, Test262BaselineRunner.options);
+ });
+
+ after(() => {
+ testState = undefined;
+ });
+
+ it('has the expected emitted code', () => {
+ Harness.Baseline.runBaseline('has the expected emitted code', testState.filename + '.output.js', () => {
+ var files = testState.compilerResult.files.filter(f=> f.fileName !== Test262BaselineRunner.helpersFilePath);
+ return Harness.Compiler.collateOutputs(files, s => SyntacticCleaner.clean(s));
+ }, false, Test262BaselineRunner.baselineOptions);
+ });
+
+ it('has the expected errors', () => {
+ Harness.Baseline.runBaseline('has the expected errors', testState.filename + '.errors.txt', () => {
+ var errors = testState.compilerResult.errors;
+ if (errors.length === 0) {
+ return null;
+ }
+
+ return Harness.Compiler.getErrorBaseline(testState.inputFiles, errors);
+ }, false, Test262BaselineRunner.baselineOptions);
+ });
+
+ it('has the expected AST',() => {
+ Harness.Baseline.runBaseline('has the expected AST', testState.filename + '.AST.txt',() => {
+ var sourceFile = testState.checker.getProgram().getSourceFile(Test262BaselineRunner.getTestFilePath(testState.filename));
+ return Test262BaselineRunner.serializeSourceFile(sourceFile);
+ }, false, Test262BaselineRunner.baselineOptions);
+ });
+ });
+ }
+
+ public initializeTests() {
+ // 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(Test262BaselineRunner.basePath, Test262BaselineRunner.testFileExtensionRegex, { recursive: true });
+ testFiles.forEach(fn => {
+ this.runTest(ts.normalizePath(fn));
+ });
+ }
+ else {
+ this.tests.forEach(test => this.runTest(test));
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/lib/core.d.ts b/src/lib/core.d.ts
index 5abc7fe203747..1c87984bc2757 100644
--- a/src/lib/core.d.ts
+++ b/src/lib/core.d.ts
@@ -109,10 +109,7 @@ interface Object {
propertyIsEnumerable(v: string): boolean;
}
-/**
- * Provides functionality common to all JavaScript objects.
- */
-declare var Object: {
+interface ObjectConstructor {
new (value?: any): Object;
(): any;
(value: any): any;
@@ -206,6 +203,11 @@ declare var Object: {
keys(o: any): string[];
}
+/**
+ * Provides functionality common to all JavaScript objects.
+ */
+declare var Object: ObjectConstructor;
+
/**
* Creates a new function.
*/
@@ -240,8 +242,8 @@ interface Function {
caller: Function;
}
-declare var Function: {
- /**
+interface FunctionConstructor {
+ /**
* Creates a new function.
* @param args A list of arguments the function accepts.
*/
@@ -250,6 +252,8 @@ declare var Function: {
prototype: Function;
}
+declare var Function: FunctionConstructor;
+
interface IArguments {
[index: number]: any;
length: number;
@@ -409,24 +413,29 @@ interface String {
[index: number]: string;
}
-/**
- * Allows manipulation and formatting of text strings and determination and location of substrings within strings.
- */
-declare var String: {
+interface StringConstructor {
new (value?: any): String;
(value?: any): string;
prototype: String;
fromCharCode(...codes: number[]): string;
}
+/**
+ * Allows manipulation and formatting of text strings and determination and location of substrings within strings.
+ */
+declare var String: StringConstructor;
+
interface Boolean {
}
-declare var Boolean: {
+
+interface BooleanConstructor {
new (value?: any): Boolean;
(value?: any): boolean;
prototype: Boolean;
}
+declare var Boolean: BooleanConstructor;
+
interface Number {
/**
* Returns a string representation of an object.
@@ -453,8 +462,7 @@ interface Number {
toPrecision(precision?: number): string;
}
-/** An object that represents a number of any kind. All JavaScript numbers are 64-bit floating-point numbers. */
-declare var Number: {
+interface NumberConstructor {
new (value?: any): Number;
(value?: any): number;
prototype: Number;
@@ -484,6 +492,9 @@ declare var Number: {
POSITIVE_INFINITY: number;
}
+/** An object that represents a number of any kind. All JavaScript numbers are 64-bit floating-point numbers. */
+declare var Number: NumberConstructor;
+
interface TemplateStringsArray extends Array {
raw: string[];
}
@@ -753,7 +764,7 @@ interface Date {
toJSON(key?: any): string;
}
-declare var Date: {
+interface DateConstructor {
new (): Date;
new (value: number): Date;
new (value: string): Date;
@@ -779,6 +790,8 @@ declare var Date: {
now(): number;
}
+declare var Date: DateConstructor;
+
interface RegExpMatchArray extends Array {
index?: number;
input?: string;
@@ -819,7 +832,8 @@ interface RegExp {
// Non-standard extensions
compile(): RegExp;
}
-declare var RegExp: {
+
+interface RegExpConstructor {
new (pattern: string, flags?: string): RegExp;
(pattern: string, flags?: string): RegExp;
prototype: RegExp;
@@ -837,64 +851,87 @@ declare var RegExp: {
lastMatch: string;
}
+declare var RegExp: RegExpConstructor;
+
interface Error {
name: string;
message: string;
}
-declare var Error: {
+
+interface ErrorConstructor {
new (message?: string): Error;
(message?: string): Error;
prototype: Error;
}
+declare var Error: ErrorConstructor;
+
interface EvalError extends Error {
}
-declare var EvalError: {
+
+interface EvalErrorConstructor {
new (message?: string): EvalError;
(message?: string): EvalError;
prototype: EvalError;
}
+declare var EvalError: EvalErrorConstructor;
+
interface RangeError extends Error {
}
-declare var RangeError: {
+
+interface RangeErrorConstructor {
new (message?: string): RangeError;
(message?: string): RangeError;
prototype: RangeError;
}
+declare var RangeError: RangeErrorConstructor;
+
interface ReferenceError extends Error {
}
-declare var ReferenceError: {
+
+interface ReferenceErrorConstructor {
new (message?: string): ReferenceError;
(message?: string): ReferenceError;
prototype: ReferenceError;
}
+declare var ReferenceError: ReferenceErrorConstructor;
+
interface SyntaxError extends Error {
}
-declare var SyntaxError: {
+
+interface SyntaxErrorConstructor {
new (message?: string): SyntaxError;
(message?: string): SyntaxError;
prototype: SyntaxError;
}
+declare var SyntaxError: SyntaxErrorConstructor;
+
interface TypeError extends Error {
}
-declare var TypeError: {
+
+interface TypeErrorConstructor {
new (message?: string): TypeError;
(message?: string): TypeError;
prototype: TypeError;
}
+declare var TypeError: TypeErrorConstructor;
+
interface URIError extends Error {
}
-declare var URIError: {
+
+interface URIErrorConstructor {
new (message?: string): URIError;
(message?: string): URIError;
prototype: URIError;
}
+declare var URIError: URIErrorConstructor;
+
interface JSON {
/**
* Converts a JavaScript Object Notation (JSON) string into an object.
@@ -1097,7 +1134,8 @@ interface Array {
[n: number]: T;
}
-declare var Array: {
+
+interface ArrayConstructor {
new (arrayLength?: number): any[];
new (arrayLength: number): T[];
new (...items: T[]): T[];
@@ -1107,3 +1145,5 @@ declare var Array: {
isArray(arg: any): boolean;
prototype: Array;
}
+
+declare var Array: ArrayConstructor;
diff --git a/src/lib/es6.d.ts b/src/lib/es6.d.ts
new file mode 100644
index 0000000000000..0940f26cac5ba
--- /dev/null
+++ b/src/lib/es6.d.ts
@@ -0,0 +1,3637 @@
+declare type PropertyKey = string | number | Symbol;
+
+interface Symbol {
+ /** Returns a string representation of an object. */
+ toString(): string;
+
+ /** Returns the primitive value of the specified object. */
+ valueOf(): Object;
+
+ // [Symbol.toStringTag]: string;
+}
+
+interface SymbolConstructor {
+ /**
+ * A reference to the prototype.
+ */
+ prototype: Symbol;
+
+ /**
+ * Returns a new unique Symbol value.
+ * @param description Description of the new Symbol object.
+ */
+ (description?: string|number): Symbol;
+
+ /**
+ * Returns a Symbol object from the global symbol registry matching the given key if found.
+ * Otherwise, returns a new symbol with this key.
+ * @param key key to search for.
+ */
+ for(key: string): Symbol;
+
+ /**
+ * Returns a key from the global symbol registry matching the given Symbol if found.
+ * Otherwise, returns a undefined.
+ * @param sym Symbol to find the key for.
+ */
+ keyFor(sym: Symbol): string;
+
+ // Well-known Symbols
+
+ /**
+ * A method that determines if a constructor object recognizes an object as one of the
+ * constructor’s instances. Called by the semantics of the instanceof operator.
+ */
+ hasInstance: Symbol;
+
+ /**
+ * A Boolean value that if true indicates that an object should flatten to its array elements
+ * by Array.prototype.concat.
+ */
+ isConcatSpreadable: Symbol;
+
+ /**
+ * A Boolean value that if true indicates that an object may be used as a regular expression.
+ */
+ isRegExp: Symbol;
+
+ /**
+ * A method that returns the default iterator for an object.Called by the semantics of the
+ * for-of statement.
+ */
+ iterator: Symbol;
+
+ /**
+ * A method that converts an object to a corresponding primitive value.Called by the ToPrimitive
+ * abstract operation.
+ */
+ toPrimitive: Symbol;
+
+ /**
+ * A String value that is used in the creation of the default string description of an object.
+ * Called by the built- in method Object.prototype.toString.
+ */
+ toStringTag: Symbol;
+
+ /**
+ * An Object whose own property names are property names that are excluded from the with
+ * environment bindings of the associated objects.
+ */
+ unscopables: Symbol;
+}
+declare var Symbol: SymbolConstructor;
+
+interface Object {
+ /**
+ * Determines whether an object has a property with the specified name.
+ * @param v A property name.
+ */
+ hasOwnProperty(v: PropertyKey): boolean;
+
+ /**
+ * Determines whether a specified property is enumerable.
+ * @param v A property name.
+ */
+ propertyIsEnumerable(v: PropertyKey): boolean;
+}
+
+interface ObjectConstructor {
+ /**
+ * Copy the values of all of the enumerable own properties from one or more source objects to a
+ * target object. Returns the target object.
+ * @param target The target object to copy to.
+ * @param sources One or more source objects to copy properties from.
+ */
+ assign(target: any, ...sources: any[]): any;
+
+ /**
+ * Returns an array of all symbol properties found directly on object o.
+ * @param o Object to retrieve the symbols from.
+ */
+ getOwnPropertySymbols(o: any): Symbol[];
+
+ /**
+ * Returns true if the values are the same value, false otherwise.
+ * @param value1 The first value.
+ * @param value2 The second value.
+ */
+ is(value1: any, value2: any): boolean;
+
+ /**
+ * Sets the prototype of a specified object o to object proto or null. Returns the object o.
+ * @param o The object to change its prototype.
+ * @param proto The value of the new prototype or null.
+ */
+ setPrototypeOf(o: any, proto: any): any;
+
+ /**
+ * Gets the own property descriptor of the specified object.
+ * An own property descriptor is one that is defined directly on the object and is not
+ * inherited from the object's prototype.
+ * @param o Object that contains the property.
+ * @param p Name of the property.
+ */
+ getOwnPropertyDescriptor(o: any, propertyKey: PropertyKey): PropertyDescriptor;
+
+ /**
+ * Adds a property to an object, or modifies attributes of an existing property.
+ * @param o Object on which to add or modify the property. This can be a native JavaScript
+ * object (that is, a user-defined object or a built in object) or a DOM object.
+ * @param p The property name.
+ * @param attributes Descriptor for the property. It can be for a data property or an accessor
+ * property.
+ */
+ defineProperty(o: any, propertyKey: PropertyKey, attributes: PropertyDescriptor): any;
+}
+
+interface Function {
+ /**
+ * Returns a new function object that is identical to the argument object in all ways except
+ * for its identity and the value of its HomeObject internal slot.
+ */
+ toMethod(newHome: Object): Function;
+
+ /**
+ * Returns the name of the function. Function names are read-only and can not be changed.
+ */
+ name: string;
+}
+
+interface NumberConstructor {
+ /**
+ * The value of Number.EPSILON is the difference between 1 and the smallest value greater than 1
+ * that is representable as a Number value, which is approximately:
+ * 2.2204460492503130808472633361816 x 10−16.
+ */
+ EPSILON: number;
+
+ /**
+ * Returns true if passed value is finite.
+ * Unlike the global isFininte, Number.isFinite doesn't forcibly convert the parameter to a
+ * number. Only finite values of the type number, result in true.
+ * @param number A numeric value.
+ */
+ isFinite(number: number): boolean;
+
+ /**
+ * Returns true if the value passed is an integer, false otherwise.
+ * @param number A numeric value.
+ */
+ isInteger(number: number): boolean;
+
+ /**
+ * Returns a Boolean value that indicates whether a value is the reserved value NaN (not a
+ * number). Unlike the global isNaN(), Number.isNaN() doesn't forcefully convert the parameter
+ * to a number. Only values of the type number, that are also NaN, result in true.
+ * @param number A numeric value.
+ */
+ isNaN(number: number): boolean;
+
+ /**
+ * Returns true if the value passed is a safe integer.
+ * @param number A numeric value.
+ */
+ isSafeInteger(number: number): boolean;
+
+ /**
+ * The value of the largest integer n such that n and n + 1 are both exactly representable as
+ * a Number value.
+ * The value of Number.MIN_SAFE_INTEGER is 9007199254740991 2^53 − 1.
+ */
+ MAX_SAFE_INTEGER: number;
+
+ /**
+ * The value of the smallest integer n such that n and n − 1 are both exactly representable as
+ * a Number value.
+ * The value of Number.MIN_SAFE_INTEGER is −9007199254740991 (−(2^53 − 1)).
+ */
+ MIN_SAFE_INTEGER: number;
+
+ /**
+ * Converts a string to a floating-point number.
+ * @param string A string that contains a floating-point number.
+ */
+ parseFloat(string: string);
+
+ /**
+ * Converts A string to an integer.
+ * @param s A string to convert into a number.
+ * @param radix A value between 2 and 36 that specifies the base of the number in numString.
+ * If this argument is not supplied, strings with a prefix of '0x' are considered hexadecimal.
+ * All other strings are considered decimal.
+ */
+ parseInt(string: string, radix?: number): number;
+}
+
+interface ArrayLike {
+ length: number;
+ [n: number]: T;
+}
+
+interface Array {
+ /** Iterator */
+ // [Symbol.iterator] (): Iterator;
+
+ /**
+ * Returns an array of key, value pairs for every entry in the array
+ */
+ entries(): Iterator<[number, T]>;
+
+ /**
+ * Returns an list of keys in the array
+ */
+ keys(): Iterator;
+
+ /**
+ * Returns an list of values in the array
+ */
+ values(): Iterator;
+
+ /**
+ * Returns the value of the first element in the array where predicate is true, and undefined
+ * otherwise.
+ * @param predicate find calls predicate once for each element of the array, in ascending
+ * order, until it finds one where predicate returns true. If such an element is found, find
+ * immediately returns that element value. Otherwise, find returns undefined.
+ * @param thisArg If provided, it will be used as the this value for each invocation of
+ * predicate. If it is not provided, undefined is used instead.
+ */
+ find(predicate: (value: T, index: number, obj: Array) => boolean, thisArg?: any): T;
+
+ /**
+ * Returns the index of the first element in the array where predicate is true, and undefined
+ * otherwise.
+ * @param predicate find calls predicate once for each element of the array, in ascending
+ * order, until it finds one where predicate returns true. If such an element is found, find
+ * immediately returns that element value. Otherwise, find returns undefined.
+ * @param thisArg If provided, it will be used as the this value for each invocation of
+ * predicate. If it is not provided, undefined is used instead.
+ */
+ findIndex(predicate: (value: T) => boolean, thisArg?: any): number;
+
+ /**
+ * Returns the this object after filling the section identified by start and end with value
+ * @param value value to fill array section with
+ * @param start index to start filling the array at. If start is negative, it is treated as
+ * length+start where length is the length of the array.
+ * @param end index to stop filling the array at. If end is negative, it is treated as
+ * length+end.
+ */
+ fill(value: T, start?: number, end?: number): T[];
+
+ /**
+ * Returns the this object after copying a section of the array identified by start and end
+ * to the same array starting at position target
+ * @param target If target is negative, it is treated as length+target where length is the
+ * length of the array.
+ * @param start If start is negative, it is treated as length+start. If end is negative, it
+ * is treated as length+end.
+ * @param end If not specified, length of the this object is used as its default value.
+ */
+ copyWithin(target: number, start: number, end?: number): T[];
+}
+
+interface ArrayConstructor {
+ /**
+ * Creates an array from an array-like object.
+ * @param arrayLike An array-like object to convert to an array.
+ * @param mapfn A mapping function to call on every element of the array.
+ * @param thisArg Value of 'this' used to invoke the mapfn.
+ */
+ from(arrayLike: ArrayLike, mapfn: (v: T, k: number) => U, thisArg?: any): Array;
+
+ /**
+ * Creates an array from an iterable object.
+ * @param iterable An iterable object to convert to an array.
+ * @param mapfn A mapping function to call on every element of the array.
+ * @param thisArg Value of 'this' used to invoke the mapfn.
+ */
+ from(iterable: Iterable, mapfn: (v: T, k: number) => U, thisArg?: any): Array;
+
+ /**
+ * Creates an array from an array-like object.
+ * @param arrayLike An array-like object to convert to an array.
+ */
+ from(arrayLike: ArrayLike): Array;
+
+ /**
+ * Creates an array from an iterable object.
+ * @param iterable An iterable object to convert to an array.
+ */
+ from(iterable: Iterable): Array;
+
+ /**
+ * Returns a new array from a set of elements.
+ * @param items A set of elements to include in the new array object.
+ */
+ of(...items: T[]): Array;
+}
+
+interface String {
+ /** Iterator */
+ // [Symbol.iterator] (): Iterator;
+
+ /**
+ * Returns a nonnegative integer Number less than 1114112 (0x110000) that is the code point
+ * value of the UTF-16 encoded code point starting at the string element at position pos in
+ * the String resulting from converting this object to a String.
+ * If there is no element at that position, the result is undefined.
+ * If a valid UTF-16 surrogate pair does not begin at pos, the result is the code unit at pos.
+ */
+ codePointAt(pos: number): number;
+
+ /**
+ * Returns true if searchString appears as a substring of the result of converting this
+ * object to a String, at one or more positions that are
+ * greater than or equal to position; otherwise, returns false.
+ * @param searchString search string
+ * @param position If position is undefined, 0 is assumed, so as to search all of the String.
+ */
+ contains(searchString: string, position?: number): boolean;
+
+ /**
+ * Returns true if the sequence of elements of searchString converted to a String is the
+ * same as the corresponding elements of this object (converted to a String) starting at
+ * endPosition – length(this). Otherwise returns false.
+ */
+ endsWith(searchString: string, endPosition?: number): boolean;
+
+ /**
+ * Returns the String value result of normalizing the string into the normalization form
+ * named by form as specified in Unicode Standard Annex #15, Unicode Normalization Forms.
+ * @param form Applicable values: "NFC", "NFD", "NFKC", or "NFKD", If not specified default
+ * is "NFC"
+ */
+ normalize(form?: string): string;
+
+ /**
+ * Returns a String value that is made from count copies appended together. If count is 0,
+ * T is the empty String is returned.
+ * @param count number of copies to append
+ */
+ repeat(count: number): string;
+
+ /**
+ * Returns true if the sequence of elements of searchString converted to a String is the
+ * same as the corresponding elements of this object (converted to a String) starting at
+ * position. Otherwise returns false.
+ */
+ startsWith(searchString: string, position?: number): boolean;
+
+ /**
+ * Returns an HTML anchor element and sets the name attribute to the text value
+ * @param name
+ */
+ anchor(name: string): string;
+
+ /** Returns a HTML element */
+ big(): string;
+
+ /** Returns a