From 0abb4c907ef494c5c29d351b6e7844a9ee9491c1 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Sun, 28 Feb 2016 19:44:18 -0800 Subject: [PATCH 01/52] Added tests. --- ...TypeInBasePropertyAndDerivedContainerOfBase01.ts | 13 +++++++++++++ .../recurringTypeParamForContainerOfBase01.ts | 13 +++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 tests/cases/conformance/types/thisType/thisTypeInBasePropertyAndDerivedContainerOfBase01.ts create mode 100644 tests/cases/conformance/types/typeParameters/recurringTypeParamForContainerOfBase01.ts diff --git a/tests/cases/conformance/types/thisType/thisTypeInBasePropertyAndDerivedContainerOfBase01.ts b/tests/cases/conformance/types/thisType/thisTypeInBasePropertyAndDerivedContainerOfBase01.ts new file mode 100644 index 00000000000..6597f32adc9 --- /dev/null +++ b/tests/cases/conformance/types/thisType/thisTypeInBasePropertyAndDerivedContainerOfBase01.ts @@ -0,0 +1,13 @@ +// @declaration: true + +interface BoxOfFoo { + item: T +} + +interface Foo { + self: this; +} + +interface Bar extends Foo { + other: BoxOfFoo; +} \ No newline at end of file diff --git a/tests/cases/conformance/types/typeParameters/recurringTypeParamForContainerOfBase01.ts b/tests/cases/conformance/types/typeParameters/recurringTypeParamForContainerOfBase01.ts new file mode 100644 index 00000000000..e8484d30f95 --- /dev/null +++ b/tests/cases/conformance/types/typeParameters/recurringTypeParamForContainerOfBase01.ts @@ -0,0 +1,13 @@ +// @declaration: true + +interface BoxOfFoo> { + item: T +} + +interface Foo> { + self: T; +} + +interface Bar> extends Foo { + other: BoxOfFoo; +} \ No newline at end of file From daf15963a35d02e16a371e92e3b1b5f2b0f84bd9 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Sun, 28 Feb 2016 19:57:44 -0800 Subject: [PATCH 02/52] Accepted baselines. --- .../recurringTypeParamForContainerOfBase01.js | 27 ++++++++++++++ ...rringTypeParamForContainerOfBase01.symbols | 37 +++++++++++++++++++ ...curringTypeParamForContainerOfBase01.types | 37 +++++++++++++++++++ ...ertyAndDerivedContainerOfBase01.errors.txt | 24 ++++++++++++ ...BasePropertyAndDerivedContainerOfBase01.js | 27 ++++++++++++++ 5 files changed, 152 insertions(+) create mode 100644 tests/baselines/reference/recurringTypeParamForContainerOfBase01.js create mode 100644 tests/baselines/reference/recurringTypeParamForContainerOfBase01.symbols create mode 100644 tests/baselines/reference/recurringTypeParamForContainerOfBase01.types create mode 100644 tests/baselines/reference/thisTypeInBasePropertyAndDerivedContainerOfBase01.errors.txt create mode 100644 tests/baselines/reference/thisTypeInBasePropertyAndDerivedContainerOfBase01.js diff --git a/tests/baselines/reference/recurringTypeParamForContainerOfBase01.js b/tests/baselines/reference/recurringTypeParamForContainerOfBase01.js new file mode 100644 index 00000000000..b3ef0cba312 --- /dev/null +++ b/tests/baselines/reference/recurringTypeParamForContainerOfBase01.js @@ -0,0 +1,27 @@ +//// [recurringTypeParamForContainerOfBase01.ts] + +interface BoxOfFoo> { + item: T +} + +interface Foo> { + self: T; +} + +interface Bar> extends Foo { + other: BoxOfFoo; +} + +//// [recurringTypeParamForContainerOfBase01.js] + + +//// [recurringTypeParamForContainerOfBase01.d.ts] +interface BoxOfFoo> { + item: T; +} +interface Foo> { + self: T; +} +interface Bar> extends Foo { + other: BoxOfFoo; +} diff --git a/tests/baselines/reference/recurringTypeParamForContainerOfBase01.symbols b/tests/baselines/reference/recurringTypeParamForContainerOfBase01.symbols new file mode 100644 index 00000000000..f0a5eafeae2 --- /dev/null +++ b/tests/baselines/reference/recurringTypeParamForContainerOfBase01.symbols @@ -0,0 +1,37 @@ +=== tests/cases/conformance/types/typeParameters/recurringTypeParamForContainerOfBase01.ts === + +interface BoxOfFoo> { +>BoxOfFoo : Symbol(BoxOfFoo, Decl(recurringTypeParamForContainerOfBase01.ts, 0, 0)) +>T : Symbol(T, Decl(recurringTypeParamForContainerOfBase01.ts, 1, 19)) +>Foo : Symbol(Foo, Decl(recurringTypeParamForContainerOfBase01.ts, 3, 1)) +>T : Symbol(T, Decl(recurringTypeParamForContainerOfBase01.ts, 1, 19)) + + item: T +>item : Symbol(item, Decl(recurringTypeParamForContainerOfBase01.ts, 1, 38)) +>T : Symbol(T, Decl(recurringTypeParamForContainerOfBase01.ts, 1, 19)) +} + +interface Foo> { +>Foo : Symbol(Foo, Decl(recurringTypeParamForContainerOfBase01.ts, 3, 1)) +>T : Symbol(T, Decl(recurringTypeParamForContainerOfBase01.ts, 5, 14)) +>Foo : Symbol(Foo, Decl(recurringTypeParamForContainerOfBase01.ts, 3, 1)) +>T : Symbol(T, Decl(recurringTypeParamForContainerOfBase01.ts, 5, 14)) + + self: T; +>self : Symbol(self, Decl(recurringTypeParamForContainerOfBase01.ts, 5, 33)) +>T : Symbol(T, Decl(recurringTypeParamForContainerOfBase01.ts, 5, 14)) +} + +interface Bar> extends Foo { +>Bar : Symbol(Bar, Decl(recurringTypeParamForContainerOfBase01.ts, 7, 1)) +>T : Symbol(T, Decl(recurringTypeParamForContainerOfBase01.ts, 9, 14)) +>Bar : Symbol(Bar, Decl(recurringTypeParamForContainerOfBase01.ts, 7, 1)) +>T : Symbol(T, Decl(recurringTypeParamForContainerOfBase01.ts, 9, 14)) +>Foo : Symbol(Foo, Decl(recurringTypeParamForContainerOfBase01.ts, 3, 1)) +>T : Symbol(T, Decl(recurringTypeParamForContainerOfBase01.ts, 9, 14)) + + other: BoxOfFoo; +>other : Symbol(other, Decl(recurringTypeParamForContainerOfBase01.ts, 9, 48)) +>BoxOfFoo : Symbol(BoxOfFoo, Decl(recurringTypeParamForContainerOfBase01.ts, 0, 0)) +>T : Symbol(T, Decl(recurringTypeParamForContainerOfBase01.ts, 9, 14)) +} diff --git a/tests/baselines/reference/recurringTypeParamForContainerOfBase01.types b/tests/baselines/reference/recurringTypeParamForContainerOfBase01.types new file mode 100644 index 00000000000..38b23263f01 --- /dev/null +++ b/tests/baselines/reference/recurringTypeParamForContainerOfBase01.types @@ -0,0 +1,37 @@ +=== tests/cases/conformance/types/typeParameters/recurringTypeParamForContainerOfBase01.ts === + +interface BoxOfFoo> { +>BoxOfFoo : BoxOfFoo +>T : T +>Foo : Foo +>T : T + + item: T +>item : T +>T : T +} + +interface Foo> { +>Foo : Foo +>T : T +>Foo : Foo +>T : T + + self: T; +>self : T +>T : T +} + +interface Bar> extends Foo { +>Bar : Bar +>T : T +>Bar : Bar +>T : T +>Foo : Foo +>T : T + + other: BoxOfFoo; +>other : BoxOfFoo +>BoxOfFoo : BoxOfFoo +>T : T +} diff --git a/tests/baselines/reference/thisTypeInBasePropertyAndDerivedContainerOfBase01.errors.txt b/tests/baselines/reference/thisTypeInBasePropertyAndDerivedContainerOfBase01.errors.txt new file mode 100644 index 00000000000..cde44b8a13a --- /dev/null +++ b/tests/baselines/reference/thisTypeInBasePropertyAndDerivedContainerOfBase01.errors.txt @@ -0,0 +1,24 @@ +tests/cases/conformance/types/thisType/thisTypeInBasePropertyAndDerivedContainerOfBase01.ts(11,21): error TS2344: Type 'this' does not satisfy the constraint 'Foo'. + Type 'Bar' is not assignable to type 'Foo'. + Types of property 'self' are incompatible. + Type 'Bar' is not assignable to type 'this'. + + +==== tests/cases/conformance/types/thisType/thisTypeInBasePropertyAndDerivedContainerOfBase01.ts (1 errors) ==== + + interface BoxOfFoo { + item: T + } + + interface Foo { + self: this; + } + + interface Bar extends Foo { + other: BoxOfFoo; + ~~~~ +!!! error TS2344: Type 'this' does not satisfy the constraint 'Foo'. +!!! error TS2344: Type 'Bar' is not assignable to type 'Foo'. +!!! error TS2344: Types of property 'self' are incompatible. +!!! error TS2344: Type 'Bar' is not assignable to type 'this'. + } \ No newline at end of file diff --git a/tests/baselines/reference/thisTypeInBasePropertyAndDerivedContainerOfBase01.js b/tests/baselines/reference/thisTypeInBasePropertyAndDerivedContainerOfBase01.js new file mode 100644 index 00000000000..51cc5a24bb6 --- /dev/null +++ b/tests/baselines/reference/thisTypeInBasePropertyAndDerivedContainerOfBase01.js @@ -0,0 +1,27 @@ +//// [thisTypeInBasePropertyAndDerivedContainerOfBase01.ts] + +interface BoxOfFoo { + item: T +} + +interface Foo { + self: this; +} + +interface Bar extends Foo { + other: BoxOfFoo; +} + +//// [thisTypeInBasePropertyAndDerivedContainerOfBase01.js] + + +//// [thisTypeInBasePropertyAndDerivedContainerOfBase01.d.ts] +interface BoxOfFoo { + item: T; +} +interface Foo { + self: this; +} +interface Bar extends Foo { + other: BoxOfFoo; +} From cdd10b09b19797647cffe0996bd3dc846a14b6aa Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Sun, 28 Feb 2016 20:08:55 -0800 Subject: [PATCH 03/52] Instantiate type parameters with themselves as their 'this' type when relating. --- src/compiler/checker.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index c2a14e5b9a0..b5526e204ca 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5595,9 +5595,14 @@ namespace ts { if (source.flags & TypeFlags.TypeParameter) { let constraint = getConstraintOfTypeParameter(source); + if (!constraint || constraint.flags & TypeFlags.Any) { constraint = emptyObjectType; } + + // The constraint may need to be further instantiated with its 'this' type. + constraint = getTypeWithThisArgument(constraint); + // Report constraint errors only if the constraint is not the empty object type const reportConstraintErrors = reportErrors && constraint !== emptyObjectType; if (result = isRelatedTo(constraint, target, reportConstraintErrors)) { From 268b2d44fa508b9e8ccfc1b2b71d1b25967cf52e Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Sun, 28 Feb 2016 20:22:46 -0800 Subject: [PATCH 04/52] Accepted baselines. --- tests/baselines/reference/fuzzy.errors.txt | 2 -- ...ertyAndDerivedContainerOfBase01.errors.txt | 24 ----------------- ...ropertyAndDerivedContainerOfBase01.symbols | 27 +++++++++++++++++++ ...ePropertyAndDerivedContainerOfBase01.types | 27 +++++++++++++++++++ 4 files changed, 54 insertions(+), 26 deletions(-) delete mode 100644 tests/baselines/reference/thisTypeInBasePropertyAndDerivedContainerOfBase01.errors.txt create mode 100644 tests/baselines/reference/thisTypeInBasePropertyAndDerivedContainerOfBase01.symbols create mode 100644 tests/baselines/reference/thisTypeInBasePropertyAndDerivedContainerOfBase01.types diff --git a/tests/baselines/reference/fuzzy.errors.txt b/tests/baselines/reference/fuzzy.errors.txt index 0aa8207ff98..72ac4c816f9 100644 --- a/tests/baselines/reference/fuzzy.errors.txt +++ b/tests/baselines/reference/fuzzy.errors.txt @@ -4,7 +4,6 @@ tests/cases/compiler/fuzzy.ts(21,20): error TS2322: Type '{ anything: number; on Types of property 'oneI' are incompatible. Type 'this' is not assignable to type 'I'. Type 'C' is not assignable to type 'I'. - Property 'alsoWorks' is missing in type 'C'. tests/cases/compiler/fuzzy.ts(25,20): error TS2352: Neither type '{ oneI: this; }' nor type 'R' is assignable to the other. Property 'anything' is missing in type '{ oneI: this; }'. @@ -39,7 +38,6 @@ tests/cases/compiler/fuzzy.ts(25,20): error TS2352: Neither type '{ oneI: this; !!! error TS2322: Types of property 'oneI' are incompatible. !!! error TS2322: Type 'this' is not assignable to type 'I'. !!! error TS2322: Type 'C' is not assignable to type 'I'. -!!! error TS2322: Property 'alsoWorks' is missing in type 'C'. } worksToo():R { diff --git a/tests/baselines/reference/thisTypeInBasePropertyAndDerivedContainerOfBase01.errors.txt b/tests/baselines/reference/thisTypeInBasePropertyAndDerivedContainerOfBase01.errors.txt deleted file mode 100644 index cde44b8a13a..00000000000 --- a/tests/baselines/reference/thisTypeInBasePropertyAndDerivedContainerOfBase01.errors.txt +++ /dev/null @@ -1,24 +0,0 @@ -tests/cases/conformance/types/thisType/thisTypeInBasePropertyAndDerivedContainerOfBase01.ts(11,21): error TS2344: Type 'this' does not satisfy the constraint 'Foo'. - Type 'Bar' is not assignable to type 'Foo'. - Types of property 'self' are incompatible. - Type 'Bar' is not assignable to type 'this'. - - -==== tests/cases/conformance/types/thisType/thisTypeInBasePropertyAndDerivedContainerOfBase01.ts (1 errors) ==== - - interface BoxOfFoo { - item: T - } - - interface Foo { - self: this; - } - - interface Bar extends Foo { - other: BoxOfFoo; - ~~~~ -!!! error TS2344: Type 'this' does not satisfy the constraint 'Foo'. -!!! error TS2344: Type 'Bar' is not assignable to type 'Foo'. -!!! error TS2344: Types of property 'self' are incompatible. -!!! error TS2344: Type 'Bar' is not assignable to type 'this'. - } \ No newline at end of file diff --git a/tests/baselines/reference/thisTypeInBasePropertyAndDerivedContainerOfBase01.symbols b/tests/baselines/reference/thisTypeInBasePropertyAndDerivedContainerOfBase01.symbols new file mode 100644 index 00000000000..379e4d3c8a4 --- /dev/null +++ b/tests/baselines/reference/thisTypeInBasePropertyAndDerivedContainerOfBase01.symbols @@ -0,0 +1,27 @@ +=== tests/cases/conformance/types/thisType/thisTypeInBasePropertyAndDerivedContainerOfBase01.ts === + +interface BoxOfFoo { +>BoxOfFoo : Symbol(BoxOfFoo, Decl(thisTypeInBasePropertyAndDerivedContainerOfBase01.ts, 0, 0)) +>T : Symbol(T, Decl(thisTypeInBasePropertyAndDerivedContainerOfBase01.ts, 1, 19)) +>Foo : Symbol(Foo, Decl(thisTypeInBasePropertyAndDerivedContainerOfBase01.ts, 3, 1)) + + item: T +>item : Symbol(item, Decl(thisTypeInBasePropertyAndDerivedContainerOfBase01.ts, 1, 35)) +>T : Symbol(T, Decl(thisTypeInBasePropertyAndDerivedContainerOfBase01.ts, 1, 19)) +} + +interface Foo { +>Foo : Symbol(Foo, Decl(thisTypeInBasePropertyAndDerivedContainerOfBase01.ts, 3, 1)) + + self: this; +>self : Symbol(self, Decl(thisTypeInBasePropertyAndDerivedContainerOfBase01.ts, 5, 15)) +} + +interface Bar extends Foo { +>Bar : Symbol(Bar, Decl(thisTypeInBasePropertyAndDerivedContainerOfBase01.ts, 7, 1)) +>Foo : Symbol(Foo, Decl(thisTypeInBasePropertyAndDerivedContainerOfBase01.ts, 3, 1)) + + other: BoxOfFoo; +>other : Symbol(other, Decl(thisTypeInBasePropertyAndDerivedContainerOfBase01.ts, 9, 27)) +>BoxOfFoo : Symbol(BoxOfFoo, Decl(thisTypeInBasePropertyAndDerivedContainerOfBase01.ts, 0, 0)) +} diff --git a/tests/baselines/reference/thisTypeInBasePropertyAndDerivedContainerOfBase01.types b/tests/baselines/reference/thisTypeInBasePropertyAndDerivedContainerOfBase01.types new file mode 100644 index 00000000000..9f6b83df057 --- /dev/null +++ b/tests/baselines/reference/thisTypeInBasePropertyAndDerivedContainerOfBase01.types @@ -0,0 +1,27 @@ +=== tests/cases/conformance/types/thisType/thisTypeInBasePropertyAndDerivedContainerOfBase01.ts === + +interface BoxOfFoo { +>BoxOfFoo : BoxOfFoo +>T : T +>Foo : Foo + + item: T +>item : T +>T : T +} + +interface Foo { +>Foo : Foo + + self: this; +>self : this +} + +interface Bar extends Foo { +>Bar : Bar +>Foo : Foo + + other: BoxOfFoo; +>other : BoxOfFoo +>BoxOfFoo : BoxOfFoo +} From 576e5f8055c88776182b4a6ac3456ca089b08144 Mon Sep 17 00:00:00 2001 From: zhengbli Date: Tue, 19 Apr 2016 14:25:57 -0700 Subject: [PATCH 05/52] So we are back to polling. --- src/compiler/sys.ts | 196 +------------------------------------------ src/server/server.ts | 104 +++++++++++++++++++++++ 2 files changed, 107 insertions(+), 193 deletions(-) diff --git a/src/compiler/sys.ts b/src/compiler/sys.ts index c391560befd..bdefe6fa344 100644 --- a/src/compiler/sys.ts +++ b/src/compiler/sys.ts @@ -26,12 +26,6 @@ namespace ts { exit(exitCode?: number): void; } - interface WatchedFile { - fileName: string; - callback: FileWatcherCallback; - mtime?: Date; - } - export interface FileWatcher { close(): void; } @@ -230,185 +224,9 @@ namespace ts { const _os = require("os"); const _crypto = require("crypto"); - // average async stat takes about 30 microseconds - // set chunk size to do 30 files in < 1 millisecond - function createPollingWatchedFileSet(interval = 2500, chunkSize = 30) { - let watchedFiles: WatchedFile[] = []; - let nextFileToCheck = 0; - let watchTimer: any; - - function getModifiedTime(fileName: string): Date { - return _fs.statSync(fileName).mtime; - } - - function poll(checkedIndex: number) { - const watchedFile = watchedFiles[checkedIndex]; - if (!watchedFile) { - return; - } - - _fs.stat(watchedFile.fileName, (err: any, stats: any) => { - if (err) { - watchedFile.callback(watchedFile.fileName); - } - else if (watchedFile.mtime.getTime() !== stats.mtime.getTime()) { - watchedFile.mtime = getModifiedTime(watchedFile.fileName); - watchedFile.callback(watchedFile.fileName, watchedFile.mtime.getTime() === 0); - } - }); - } - - // this implementation uses polling and - // stat due to inconsistencies of fs.watch - // and efficiency of stat on modern filesystems - function startWatchTimer() { - watchTimer = setInterval(() => { - let count = 0; - let nextToCheck = nextFileToCheck; - let firstCheck = -1; - while ((count < chunkSize) && (nextToCheck !== firstCheck)) { - poll(nextToCheck); - if (firstCheck < 0) { - firstCheck = nextToCheck; - } - nextToCheck++; - if (nextToCheck === watchedFiles.length) { - nextToCheck = 0; - } - count++; - } - nextFileToCheck = nextToCheck; - }, interval); - } - - function addFile(fileName: string, callback: FileWatcherCallback): WatchedFile { - const file: WatchedFile = { - fileName, - callback, - mtime: getModifiedTime(fileName) - }; - - watchedFiles.push(file); - if (watchedFiles.length === 1) { - startWatchTimer(); - } - return file; - } - - function removeFile(file: WatchedFile) { - watchedFiles = copyListRemovingItem(file, watchedFiles); - } - - return { - getModifiedTime: getModifiedTime, - poll: poll, - startWatchTimer: startWatchTimer, - addFile: addFile, - removeFile: removeFile - }; - } - - function createWatchedFileSet() { - const dirWatchers: Map = {}; - // One file can have multiple watchers - const fileWatcherCallbacks: Map = {}; - return { addFile, removeFile }; - - function reduceDirWatcherRefCountForFile(fileName: string) { - const dirName = getDirectoryPath(fileName); - if (hasProperty(dirWatchers, dirName)) { - const watcher = dirWatchers[dirName]; - watcher.referenceCount -= 1; - if (watcher.referenceCount <= 0) { - watcher.close(); - delete dirWatchers[dirName]; - } - } - } - - function addDirWatcher(dirPath: string): void { - if (hasProperty(dirWatchers, dirPath)) { - const watcher = dirWatchers[dirPath]; - watcher.referenceCount += 1; - return; - } - - const watcher: DirectoryWatcher = _fs.watch( - dirPath, - { persistent: true }, - (eventName: string, relativeFileName: string) => fileEventHandler(eventName, relativeFileName, dirPath) - ); - watcher.referenceCount = 1; - dirWatchers[dirPath] = watcher; - return; - } - - function addFileWatcherCallback(filePath: string, callback: FileWatcherCallback): void { - if (hasProperty(fileWatcherCallbacks, filePath)) { - fileWatcherCallbacks[filePath].push(callback); - } - else { - fileWatcherCallbacks[filePath] = [callback]; - } - } - - function addFile(fileName: string, callback: FileWatcherCallback): WatchedFile { - addFileWatcherCallback(fileName, callback); - addDirWatcher(getDirectoryPath(fileName)); - - return { fileName, callback }; - } - - function removeFile(watchedFile: WatchedFile) { - removeFileWatcherCallback(watchedFile.fileName, watchedFile.callback); - reduceDirWatcherRefCountForFile(watchedFile.fileName); - } - - function removeFileWatcherCallback(filePath: string, callback: FileWatcherCallback) { - if (hasProperty(fileWatcherCallbacks, filePath)) { - const newCallbacks = copyListRemovingItem(callback, fileWatcherCallbacks[filePath]); - if (newCallbacks.length === 0) { - delete fileWatcherCallbacks[filePath]; - } - else { - fileWatcherCallbacks[filePath] = newCallbacks; - } - } - } - - function fileEventHandler(eventName: string, relativeFileName: string, baseDirPath: string) { - // When files are deleted from disk, the triggered "rename" event would have a relativefileName of "undefined" - const fileName = typeof relativeFileName !== "string" - ? undefined - : ts.getNormalizedAbsolutePath(relativeFileName, baseDirPath); - // Some applications save a working file via rename operations - if ((eventName === "change" || eventName === "rename") && hasProperty(fileWatcherCallbacks, fileName)) { - for (const fileCallback of fileWatcherCallbacks[fileName]) { - fileCallback(fileName); - } - } - } - } - - // REVIEW: for now this implementation uses polling. - // The advantage of polling is that it works reliably - // on all os and with network mounted files. - // For 90 referenced files, the average time to detect - // changes is 2*msInterval (by default 5 seconds). - // The overhead of this is .04 percent (1/2500) with - // average pause of < 1 millisecond (and max - // pause less than 1.5 milliseconds); question is - // do we anticipate reference sets in the 100s and - // do we care about waiting 10-20 seconds to detect - // changes for large reference sets? If so, do we want - // to increase the chunk size or decrease the interval - // time dynamically to match the large reference set? - const pollingWatchedFileSet = createPollingWatchedFileSet(); - const watchedFileSet = createWatchedFileSet(); - function isNode4OrLater(): boolean { - return parseInt(process.version.charAt(1)) >= 4; - } + return parseInt(process.version.charAt(1)) >= 4; + } const platform: string = _os.platform(); // win32\win64 are case insensitive platforms, MacOS (darwin) by default is also case insensitive @@ -535,15 +353,7 @@ namespace ts { readFile, writeFile, watchFile: (fileName, callback) => { - // Node 4.0 stabilized the `fs.watch` function on Windows which avoids polling - // and is more efficient than `fs.watchFile` (ref: https://github.com/nodejs/node/pull/2649 - // and https://github.com/Microsoft/TypeScript/issues/4643), therefore - // if the current node.js version is newer than 4, use `fs.watch` instead. - const watchSet = isNode4OrLater() ? watchedFileSet : pollingWatchedFileSet; - const watchedFile = watchSet.addFile(fileName, callback); - return { - close: () => watchSet.removeFile(watchedFile) - }; + return _fs.watchFile(fileName, callback); }, watchDirectory: (directoryName, callback, recursive) => { // Node 4.0 `fs.watch` function supports the "recursive" option on both OSX and Windows diff --git a/src/server/server.ts b/src/server/server.ts index 3ffd64fe07d..26ab01adc2b 100644 --- a/src/server/server.ts +++ b/src/server/server.ts @@ -111,6 +111,12 @@ namespace ts.server { detailLevel?: string; } + interface WatchedFile { + fileName: string; + callback: FileWatcherCallback; + mtime?: Date; + } + function parseLoggingEnvironmentString(logEnvStr: string): LogOptions { const logEnv: LogOptions = {}; const args = logEnvStr.split(" "); @@ -153,6 +159,98 @@ namespace ts.server { // This places log file in the directory containing editorServices.js // TODO: check that this location is writable + // average async stat takes about 30 microseconds + // set chunk size to do 30 files in < 1 millisecond + function createPollingWatchedFileSet(interval = 2500, chunkSize = 30) { + let watchedFiles: WatchedFile[] = []; + let nextFileToCheck = 0; + let watchTimer: any; + + function getModifiedTime(fileName: string): Date { + return fs.statSync(fileName).mtime; + } + + function poll(checkedIndex: number) { + const watchedFile = watchedFiles[checkedIndex]; + if (!watchedFile) { + return; + } + + fs.stat(watchedFile.fileName, (err: any, stats: any) => { + if (err) { + watchedFile.callback(watchedFile.fileName); + } + else if (watchedFile.mtime.getTime() !== stats.mtime.getTime()) { + watchedFile.mtime = getModifiedTime(watchedFile.fileName); + watchedFile.callback(watchedFile.fileName, watchedFile.mtime.getTime() === 0); + } + }); + } + + // this implementation uses polling and + // stat due to inconsistencies of fs.watch + // and efficiency of stat on modern filesystems + function startWatchTimer() { + watchTimer = setInterval(() => { + let count = 0; + let nextToCheck = nextFileToCheck; + let firstCheck = -1; + while ((count < chunkSize) && (nextToCheck !== firstCheck)) { + poll(nextToCheck); + if (firstCheck < 0) { + firstCheck = nextToCheck; + } + nextToCheck++; + if (nextToCheck === watchedFiles.length) { + nextToCheck = 0; + } + count++; + } + nextFileToCheck = nextToCheck; + }, interval); + } + + function addFile(fileName: string, callback: FileWatcherCallback): WatchedFile { + const file: WatchedFile = { + fileName, + callback, + mtime: getModifiedTime(fileName) + }; + + watchedFiles.push(file); + if (watchedFiles.length === 1) { + startWatchTimer(); + } + return file; + } + + function removeFile(file: WatchedFile) { + watchedFiles = copyListRemovingItem(file, watchedFiles); + } + + return { + getModifiedTime: getModifiedTime, + poll: poll, + startWatchTimer: startWatchTimer, + addFile: addFile, + removeFile: removeFile + }; + } + + // REVIEW: for now this implementation uses polling. + // The advantage of polling is that it works reliably + // on all os and with network mounted files. + // For 90 referenced files, the average time to detect + // changes is 2*msInterval (by default 5 seconds). + // The overhead of this is .04 percent (1/2500) with + // average pause of < 1 millisecond (and max + // pause less than 1.5 milliseconds); question is + // do we anticipate reference sets in the 100s and + // do we care about waiting 10-20 seconds to detect + // changes for large reference sets? If so, do we want + // to increase the chunk size or decrease the interval + // time dynamically to match the large reference set? + const pollingWatchedFileSet = createPollingWatchedFileSet(); const logger = createLoggerFromEnv(); const pending: string[] = []; @@ -176,6 +274,12 @@ namespace ts.server { // Override sys.write because fs.writeSync is not reliable on Node 4 ts.sys.write = (s: string) => writeMessage(s); + ts.sys.watchFile = (fileName, callback) => { + const watchedFile = pollingWatchedFileSet.addFile(fileName, callback); + return { + close: () => pollingWatchedFileSet.removeFile(watchedFile) + }; + }; const ioSession = new IOSession(ts.sys, logger); process.on("uncaughtException", function(err: Error) { From a09b001c6180b39155832b2f18be708ea92da263 Mon Sep 17 00:00:00 2001 From: zhengbli Date: Fri, 22 Apr 2016 10:20:41 -0700 Subject: [PATCH 06/52] Add env to allow switch to non-polling if really wants to --- src/compiler/sys.ts | 113 +++++++++++++++++++++++++++++++++++++++++- src/compiler/types.ts | 6 +-- src/server/server.ts | 6 --- 3 files changed, 114 insertions(+), 11 deletions(-) diff --git a/src/compiler/sys.ts b/src/compiler/sys.ts index bdefe6fa344..2550ca78877 100644 --- a/src/compiler/sys.ts +++ b/src/compiler/sys.ts @@ -3,6 +3,11 @@ namespace ts { export type FileWatcherCallback = (fileName: string, removed?: boolean) => void; export type DirectoryWatcherCallback = (directoryName: string) => void; + export interface WatchedFile { + fileName: string; + callback: FileWatcherCallback; + mtime?: Date; + } export interface System { args: string[]; @@ -224,6 +229,91 @@ namespace ts { const _os = require("os"); const _crypto = require("crypto"); + const useNonPollingWatchers = process.env["TSC_NONPOLLING_WATCHER"]; + + function createWatchedFileSet() { + const dirWatchers: Map = {}; + // One file can have multiple watchers + const fileWatcherCallbacks: Map = {}; + return { addFile, removeFile }; + + function reduceDirWatcherRefCountForFile(fileName: string) { + const dirName = getDirectoryPath(fileName); + if (hasProperty(dirWatchers, dirName)) { + const watcher = dirWatchers[dirName]; + watcher.referenceCount -= 1; + if (watcher.referenceCount <= 0) { + watcher.close(); + delete dirWatchers[dirName]; + } + } + } + + function addDirWatcher(dirPath: string): void { + if (hasProperty(dirWatchers, dirPath)) { + const watcher = dirWatchers[dirPath]; + watcher.referenceCount += 1; + return; + } + + const watcher: DirectoryWatcher = _fs.watch( + dirPath, + { persistent: true }, + (eventName: string, relativeFileName: string) => fileEventHandler(eventName, relativeFileName, dirPath) + ); + watcher.referenceCount = 1; + dirWatchers[dirPath] = watcher; + return; + } + + function addFileWatcherCallback(filePath: string, callback: FileWatcherCallback): void { + if (hasProperty(fileWatcherCallbacks, filePath)) { + fileWatcherCallbacks[filePath].push(callback); + } + else { + fileWatcherCallbacks[filePath] = [callback]; + } + } + + function addFile(fileName: string, callback: FileWatcherCallback): WatchedFile { + addFileWatcherCallback(fileName, callback); + addDirWatcher(getDirectoryPath(fileName)); + + return { fileName, callback }; + } + + function removeFile(watchedFile: WatchedFile) { + removeFileWatcherCallback(watchedFile.fileName, watchedFile.callback); + reduceDirWatcherRefCountForFile(watchedFile.fileName); + } + + function removeFileWatcherCallback(filePath: string, callback: FileWatcherCallback) { + if (hasProperty(fileWatcherCallbacks, filePath)) { + const newCallbacks = copyListRemovingItem(callback, fileWatcherCallbacks[filePath]); + if (newCallbacks.length === 0) { + delete fileWatcherCallbacks[filePath]; + } + else { + fileWatcherCallbacks[filePath] = newCallbacks; + } + } + } + + function fileEventHandler(eventName: string, relativeFileName: string, baseDirPath: string) { + // When files are deleted from disk, the triggered "rename" event would have a relativefileName of "undefined" + const fileName = typeof relativeFileName !== "string" + ? undefined + : ts.getNormalizedAbsolutePath(relativeFileName, baseDirPath); + // Some applications save a working file via rename operations + if ((eventName === "change" || eventName === "rename") && hasProperty(fileWatcherCallbacks, fileName)) { + for (const fileCallback of fileWatcherCallbacks[fileName]) { + fileCallback(fileName); + } + } + } + } + const watchedFileSet = createWatchedFileSet(); + function isNode4OrLater(): boolean { return parseInt(process.version.charAt(1)) >= 4; } @@ -319,7 +409,7 @@ namespace ts { const files = _fs.readdirSync(path || ".").sort(); const directories: string[] = []; for (const current of files) { - // This is necessary because on some file system node fails to exclude + // This is necessary because on some file system node fails to exclude // "." and "..". See https://github.com/nodejs/node/issues/4002 if (current === "." || current === "..") { continue; @@ -353,7 +443,26 @@ namespace ts { readFile, writeFile, watchFile: (fileName, callback) => { - return _fs.watchFile(fileName, callback); + if (useNonPollingWatchers) { + const watchedFile = watchedFileSet.addFile(fileName, callback); + return { + close: () => watchedFileSet.removeFile(watchedFile) + }; + } + else { + _fs.watchFile(fileName, { persistent: true, interval: 250 }, fileChanged); + return { + close: () => _fs.unwatchFile(fileName, fileChanged) + }; + } + + function fileChanged(curr: any, prev: any) { + if (+curr.mtime <= +prev.mtime) { + return; + } + + callback(fileName); + } }, watchDirectory: (directoryName, callback, recursive) => { // Node 4.0 `fs.watch` function supports the "recursive" option on both OSX and Windows diff --git a/src/compiler/types.ts b/src/compiler/types.ts index c39a4b10cbf..fc25073052f 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -2104,7 +2104,7 @@ namespace ts { jsxFlags?: JsxFlags; // flags for knowing what kind of element/attributes we're dealing with resolvedJsxType?: Type; // resolved element attributes type of a JSX openinglike element hasSuperCall?: boolean; // recorded result when we try to find super-call. We only try to find one if this flag is undefined, indicating that we haven't made an attempt. - superCall?: ExpressionStatement; // Cached first super-call found in the constructor. Used in checking whether super is called before this-accessing + superCall?: ExpressionStatement; // Cached first super-call found in the constructor. Used in checking whether super is called before this-accessing } export const enum TypeFlags { @@ -2484,7 +2484,7 @@ namespace ts { // When options come from a config file, its path is recorded here configFilePath?: string; /* @internal */ - // Path used to used to compute primary search locations + // Path used to used to compute primary search locations typesRoot?: string; types?: string[]; @@ -2801,7 +2801,7 @@ namespace ts { */ resolveModuleNames?(moduleNames: string[], containingFile: string): ResolvedModule[]; /** - * This method is a companion for 'resolveModuleNames' and is used to resolve 'types' references to actual type declaration files + * This method is a companion for 'resolveModuleNames' and is used to resolve 'types' references to actual type declaration files */ resolveTypeReferenceDirectives?(typeReferenceDirectiveNames: string[], containingFile: string): ResolvedTypeReferenceDirective[]; } diff --git a/src/server/server.ts b/src/server/server.ts index 26ab01adc2b..ec83f8cc716 100644 --- a/src/server/server.ts +++ b/src/server/server.ts @@ -111,12 +111,6 @@ namespace ts.server { detailLevel?: string; } - interface WatchedFile { - fileName: string; - callback: FileWatcherCallback; - mtime?: Date; - } - function parseLoggingEnvironmentString(logEnvStr: string): LogOptions { const logEnv: LogOptions = {}; const args = logEnvStr.split(" "); From 39d64a27099bedfdab11ec8e8c9f87b3667f729b Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Sat, 23 Apr 2016 14:10:26 -0700 Subject: [PATCH 07/52] Add configured projects to the list of projects when searching --- src/server/editorServices.ts | 1 + .../server/referencesInConfiguredProject.ts | 20 +++++++++++++++++++ .../server/renameInConfiguredProject.ts | 13 ++++++++++++ 3 files changed, 34 insertions(+) create mode 100644 tests/cases/fourslash/server/referencesInConfiguredProject.ts create mode 100644 tests/cases/fourslash/server/renameInConfiguredProject.ts diff --git a/src/server/editorServices.ts b/src/server/editorServices.ts index c4d4a23ebfa..32beec05426 100644 --- a/src/server/editorServices.ts +++ b/src/server/editorServices.ts @@ -919,6 +919,7 @@ namespace ts.server { configuredProject.updateGraph(); if (configuredProject.getSourceFile(info)) { info.defaultProject = configuredProject; + referencingProjects.push(configuredProject); } } return referencingProjects; diff --git a/tests/cases/fourslash/server/referencesInConfiguredProject.ts b/tests/cases/fourslash/server/referencesInConfiguredProject.ts new file mode 100644 index 00000000000..9a0d7095a93 --- /dev/null +++ b/tests/cases/fourslash/server/referencesInConfiguredProject.ts @@ -0,0 +1,20 @@ +/// + +// Global class reference. + +// @Filename: referencesForGlobals_1.ts +////class /*2*/globalClass { +//// public f() { } +////} + +// @Filename: referencesForGlobals_2.ts +////var c = /*1*/globalClass(); + +// @Filename: tsconfig.json +////{ "files": ["referencesForGlobals_1.ts", "referencesForGlobals_2.ts"] } + +goTo.marker("1"); +verify.referencesCountIs(2); + +goTo.marker("2"); +verify.referencesCountIs(2); \ No newline at end of file diff --git a/tests/cases/fourslash/server/renameInConfiguredProject.ts b/tests/cases/fourslash/server/renameInConfiguredProject.ts new file mode 100644 index 00000000000..ecff87493a8 --- /dev/null +++ b/tests/cases/fourslash/server/renameInConfiguredProject.ts @@ -0,0 +1,13 @@ +/// + +// @Filename: referencesForGlobals_1.ts +////var [|globalName|] = 0; + +// @Filename: referencesForGlobals_2.ts +////var y = /*1*/[|globalName|]; + +// @Filename: tsconfig.json +////{ "files": ["referencesForGlobals_1.ts", "referencesForGlobals_2.ts"] } + +goTo.marker("1"); +verify.renameLocations(/*findInStrings:*/ true, /*findInComments:*/ true); From c7f4cb8b3b670c8603277e7328b6f76bb35db3f5 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Sat, 23 Apr 2016 14:10:52 -0700 Subject: [PATCH 08/52] Format JOSN in failed error messages --- src/harness/fourslash.ts | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index c6cf82a6834..d6035aaa026 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -747,7 +747,7 @@ namespace FourSlash { } const missingItem = { fileName: fileName, start: start, end: end, isWriteAccess: isWriteAccess }; - this.raiseError(`verifyReferencesAtPositionListContains failed - could not find the item: ${JSON.stringify(missingItem)} in the returned list: (${JSON.stringify(references)})`); + this.raiseError(`verifyReferencesAtPositionListContains failed - could not find the item: ${JSON.stringify(missingItem, undefined, 2)} in the returned list: (${JSON.stringify(references, undefined, 2)})`); } public verifyReferencesCountIs(count: number, localFilesOnly = true) { @@ -801,7 +801,7 @@ namespace FourSlash { private testDiagnostics(expected: string, diagnostics: ts.Diagnostic[]) { const realized = ts.realizeDiagnostics(diagnostics, "\r\n"); - const actual = JSON.stringify(realized, null, " "); + const actual = JSON.stringify(realized, undefined, 2); assert.equal(actual, expected); } @@ -876,7 +876,7 @@ namespace FourSlash { } if (ranges.length !== references.length) { - this.raiseError("Rename location count does not match result.\n\nExpected: " + JSON.stringify(ranges) + "\n\nActual:" + JSON.stringify(references)); + this.raiseError("Rename location count does not match result.\n\nExpected: " + JSON.stringify(ranges, undefined, 2) + "\n\nActual:" + JSON.stringify(references, undefined, 2)); } ranges = ranges.sort((r1, r2) => r1.start - r2.start); @@ -889,7 +889,7 @@ namespace FourSlash { if (reference.textSpan.start !== range.start || ts.textSpanEnd(reference.textSpan) !== range.end) { - this.raiseError("Rename location results do not match.\n\nExpected: " + JSON.stringify(ranges) + "\n\nActual:" + JSON.stringify(references)); + this.raiseError("Rename location results do not match.\n\nExpected: " + JSON.stringify(ranges, undefined, 2) + "\n\nActual:" + JSON.stringify(references, undefined, 2)); } } } @@ -973,7 +973,7 @@ namespace FourSlash { } else { if (actual) { - this.raiseError(`Expected no signature help, but got "${JSON.stringify(actual)}"`); + this.raiseError(`Expected no signature help, but got "${JSON.stringify(actual, undefined, 2)}"`); } } } @@ -1185,7 +1185,7 @@ namespace FourSlash { public printCurrentParameterHelp() { const help = this.languageService.getSignatureHelpItems(this.activeFile.fileName, this.currentCaretPosition); - Harness.IO.log(JSON.stringify(help)); + Harness.IO.log(JSON.stringify(help, undefined, 2)); } public printCurrentQuickInfo() { @@ -1227,7 +1227,7 @@ namespace FourSlash { public printCurrentSignatureHelp() { const sigHelp = this.getActiveSignatureHelpItem(); - Harness.IO.log(JSON.stringify(sigHelp)); + Harness.IO.log(JSON.stringify(sigHelp, undefined, 2)); } public printMemberListMembers() { @@ -1257,7 +1257,7 @@ namespace FourSlash { public printReferences() { const references = this.getReferencesAtCaret(); ts.forEach(references, entry => { - Harness.IO.log(JSON.stringify(entry)); + Harness.IO.log(JSON.stringify(entry, undefined, 2)); }); } @@ -1748,8 +1748,8 @@ namespace FourSlash { function jsonMismatchString() { return Harness.IO.newLine() + - "expected: '" + Harness.IO.newLine() + JSON.stringify(expected, (k, v) => v, 2) + "'" + Harness.IO.newLine() + - "actual: '" + Harness.IO.newLine() + JSON.stringify(actual, (k, v) => v, 2) + "'"; + "expected: '" + Harness.IO.newLine() + JSON.stringify(expected, undefined, 2) + "'" + Harness.IO.newLine() + + "actual: '" + Harness.IO.newLine() + JSON.stringify(actual, undefined, 2) + "'"; } } @@ -1964,7 +1964,7 @@ namespace FourSlash { // if there was an explicit match kind specified, then it should be validated. if (matchKind !== undefined) { const missingItem = { name: name, kind: kind, searchValue: searchValue, matchKind: matchKind, fileName: fileName, parentName: parentName }; - this.raiseError(`verifyNavigationItemsListContains failed - could not find the item: ${JSON.stringify(missingItem)} in the returned list: (${JSON.stringify(items)})`); + this.raiseError(`verifyNavigationItemsListContains failed - could not find the item: ${JSON.stringify(missingItem, undefined, 2)} in the returned list: (${JSON.stringify(items, undefined, 2)})`); } } @@ -2001,7 +2001,7 @@ namespace FourSlash { } const missingItem = { name: name, kind: kind }; - this.raiseError(`verifyGetScriptLexicalStructureListContains failed - could not find the item: ${JSON.stringify(missingItem)} in the returned list: (${JSON.stringify(items, null, " ")})`); + this.raiseError(`verifyGetScriptLexicalStructureListContains failed - could not find the item: ${JSON.stringify(missingItem, undefined, 2)} in the returned list: (${JSON.stringify(items, undefined, 2)})`); } private navigationBarItemsContains(items: ts.NavigationBarItem[], name: string, kind: string) { @@ -2066,7 +2066,7 @@ namespace FourSlash { } const missingItem = { fileName: fileName, start: start, end: end, isWriteAccess: isWriteAccess }; - this.raiseError(`verifyOccurrencesAtPositionListContains failed - could not find the item: ${JSON.stringify(missingItem)} in the returned list: (${JSON.stringify(occurrences)})`); + this.raiseError(`verifyOccurrencesAtPositionListContains failed - could not find the item: ${JSON.stringify(missingItem, undefined, 2)} in the returned list: (${JSON.stringify(occurrences, undefined, 2)})`); } public verifyOccurrencesAtPositionListCount(expectedCount: number) { @@ -2105,7 +2105,7 @@ namespace FourSlash { } const missingItem = { fileName: fileName, start: start, end: end, kind: kind }; - this.raiseError(`verifyDocumentHighlightsAtPositionListContains failed - could not find the item: ${JSON.stringify(missingItem)} in the returned list: (${JSON.stringify(documentHighlights)})`); + this.raiseError(`verifyDocumentHighlightsAtPositionListContains failed - could not find the item: ${JSON.stringify(missingItem, undefined, 2)} in the returned list: (${JSON.stringify(documentHighlights, undefined, 2)})`); } public verifyDocumentHighlightsAtPositionListCount(expectedCount: number, fileNamesToSearch: string[]) { @@ -2171,9 +2171,9 @@ namespace FourSlash { } } - const itemsString = items.map((item) => JSON.stringify({ name: item.name, kind: item.kind })).join(",\n"); + const itemsString = items.map((item) => JSON.stringify({ name: item.name, kind: item.kind }, undefined, 2)).join(",\n"); - this.raiseError(`Expected "${JSON.stringify({ name, text, documentation, kind })}" to be in list [${itemsString}]`); + this.raiseError(`Expected "${JSON.stringify({ name, text, documentation, kind }, undefined, 2)}" to be in list [${itemsString}]`); } private findFile(indexOrName: any) { From 743fa3c32dc494d1e3c3c0aa1cee657424846eb5 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Mon, 25 Apr 2016 10:40:14 -0700 Subject: [PATCH 09/52] Fix #8271: Add `undefined` type to index signatures --- src/compiler/types.ts | 4 ++-- src/services/services.ts | 2 +- tests/baselines/reference/APISample_linter.js | 2 +- tests/baselines/reference/APISample_parseConfig.js | 2 +- tests/baselines/reference/APISample_watcher.js | 8 +++++++- tests/cases/compiler/APISample_compile.ts | 3 ++- tests/cases/compiler/APISample_linter.ts | 5 +++-- tests/cases/compiler/APISample_parseConfig.ts | 5 +++-- tests/cases/compiler/APISample_transform.ts | 3 ++- tests/cases/compiler/APISample_watcher.ts | 11 +++++++++-- 10 files changed, 31 insertions(+), 14 deletions(-) diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 25329b7ee2b..fdff2f6cd77 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -2512,14 +2512,14 @@ namespace ts { types?: string[]; list?: string[]; - [option: string]: CompilerOptionsValue; + [option: string]: CompilerOptionsValue | undefined; } export interface TypingOptions { enableAutoDiscovery?: boolean; include?: string[]; exclude?: string[]; - [option: string]: string[] | boolean; + [option: string]: string[] | boolean | undefined; } export interface DiscoverTypingsInfo { diff --git a/src/services/services.ts b/src/services/services.ts index d26222d636b..670a83d50fc 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -1027,7 +1027,7 @@ namespace ts { getScriptFileNames(): string[]; getScriptKind?(fileName: string): ScriptKind; getScriptVersion(fileName: string): string; - getScriptSnapshot(fileName: string): IScriptSnapshot; + getScriptSnapshot(fileName: string): IScriptSnapshot | undefined; getLocalizedDiagnosticMessages?(): any; getCancellationToken?(): HostCancellationToken; getCurrentDirectory(): string; diff --git a/tests/baselines/reference/APISample_linter.js b/tests/baselines/reference/APISample_linter.js index 62b201976cd..4e563c7cac3 100644 --- a/tests/baselines/reference/APISample_linter.js +++ b/tests/baselines/reference/APISample_linter.js @@ -55,7 +55,7 @@ export function delint(sourceFile: ts.SourceFile) { } } -const fileNames = process.argv.slice(2); +const fileNames: string[] = process.argv.slice(2); fileNames.forEach(fileName => { // Parse a file let sourceFile = ts.createSourceFile(fileName, readFileSync(fileName).toString(), ts.ScriptTarget.ES6, /*setParentNodes */ true); diff --git a/tests/baselines/reference/APISample_parseConfig.js b/tests/baselines/reference/APISample_parseConfig.js index 1312f8a4f81..75ab80d3f23 100644 --- a/tests/baselines/reference/APISample_parseConfig.js +++ b/tests/baselines/reference/APISample_parseConfig.js @@ -19,7 +19,7 @@ function printError(error: ts.Diagnostic): void { console.log(`${error.file && error.file.fileName}: ${error.messageText}`); } -export function createProgram(rootFiles: string[], compilerOptionsJson: string): ts.Program { +export function createProgram(rootFiles: string[], compilerOptionsJson: string): ts.Program | undefined { const { config, error } = ts.parseConfigFileTextToJson("tsconfig.json", compilerOptionsJson) if (error) { printError(error); diff --git a/tests/baselines/reference/APISample_watcher.js b/tests/baselines/reference/APISample_watcher.js index 1b6d52255fb..7573f2ba99e 100644 --- a/tests/baselines/reference/APISample_watcher.js +++ b/tests/baselines/reference/APISample_watcher.js @@ -8,7 +8,13 @@ declare var process: any; declare var console: any; -declare var fs: any; +declare var fs: { + existsSync(path: string): boolean; + readdirSync(path: string): string[]; + readFileSync(filename: string, encoding?: string): string; + writeFileSync(filename: string, data: any, options?: { encoding?: string; mode?: number; flag?: string; }): void; + watchFile(filename: string, options: { persistent?: boolean; interval?: number; }, listener: (curr: { mtime: Date }, prev: { mtime: Date }) => void): void; +}; declare var path: any; import * as ts from "typescript"; diff --git a/tests/cases/compiler/APISample_compile.ts b/tests/cases/compiler/APISample_compile.ts index 9672b9863fa..b60c53685aa 100644 --- a/tests/cases/compiler/APISample_compile.ts +++ b/tests/cases/compiler/APISample_compile.ts @@ -1,6 +1,7 @@ // @module: commonjs // @includebuiltfile: typescript_standalone.d.ts -// @stripInternal:true +// @noImplicitAny:true +// @strictNullChecks:true /* * Note: This test is a public API sample. The sample sources can be found diff --git a/tests/cases/compiler/APISample_linter.ts b/tests/cases/compiler/APISample_linter.ts index 8cb6934cee3..89f0be7a0f5 100644 --- a/tests/cases/compiler/APISample_linter.ts +++ b/tests/cases/compiler/APISample_linter.ts @@ -1,6 +1,7 @@ // @module: commonjs // @includebuiltfile: typescript_standalone.d.ts -// @stripInternal:true +// @noImplicitAny:true +// @strictNullChecks:true /* * Note: This test is a public API sample. The sample sources can be found @@ -57,7 +58,7 @@ export function delint(sourceFile: ts.SourceFile) { } } -const fileNames = process.argv.slice(2); +const fileNames: string[] = process.argv.slice(2); fileNames.forEach(fileName => { // Parse a file let sourceFile = ts.createSourceFile(fileName, readFileSync(fileName).toString(), ts.ScriptTarget.ES6, /*setParentNodes */ true); diff --git a/tests/cases/compiler/APISample_parseConfig.ts b/tests/cases/compiler/APISample_parseConfig.ts index 3e88e50727e..f59f64dc4ad 100644 --- a/tests/cases/compiler/APISample_parseConfig.ts +++ b/tests/cases/compiler/APISample_parseConfig.ts @@ -1,6 +1,7 @@ // @module: commonjs // @includebuiltfile: typescript_standalone.d.ts -// @stripInternal:true +// @noImplicitAny:true +// @strictNullChecks:true /* * Note: This test is a public API sample. The sample sources can be found @@ -21,7 +22,7 @@ function printError(error: ts.Diagnostic): void { console.log(`${error.file && error.file.fileName}: ${error.messageText}`); } -export function createProgram(rootFiles: string[], compilerOptionsJson: string): ts.Program { +export function createProgram(rootFiles: string[], compilerOptionsJson: string): ts.Program | undefined { const { config, error } = ts.parseConfigFileTextToJson("tsconfig.json", compilerOptionsJson) if (error) { printError(error); diff --git a/tests/cases/compiler/APISample_transform.ts b/tests/cases/compiler/APISample_transform.ts index 88b9754536a..a76d6b15463 100644 --- a/tests/cases/compiler/APISample_transform.ts +++ b/tests/cases/compiler/APISample_transform.ts @@ -1,6 +1,7 @@ // @module: commonjs // @includebuiltfile: typescript_standalone.d.ts -// @stripInternal:true +// @noImplicitAny:true +// @strictNullChecks:true /* * Note: This test is a public API sample. The sample sources can be found diff --git a/tests/cases/compiler/APISample_watcher.ts b/tests/cases/compiler/APISample_watcher.ts index 9afa53ddf14..34baa04c850 100644 --- a/tests/cases/compiler/APISample_watcher.ts +++ b/tests/cases/compiler/APISample_watcher.ts @@ -1,6 +1,7 @@ // @module: commonjs // @includebuiltfile: typescript_standalone.d.ts -// @stripInternal:true +// @noImplicitAny:true +// @strictNullChecks:true /* * Note: This test is a public API sample. The sample sources can be found @@ -10,7 +11,13 @@ declare var process: any; declare var console: any; -declare var fs: any; +declare var fs: { + existsSync(path: string): boolean; + readdirSync(path: string): string[]; + readFileSync(filename: string, encoding?: string): string; + writeFileSync(filename: string, data: any, options?: { encoding?: string; mode?: number; flag?: string; }): void; + watchFile(filename: string, options: { persistent?: boolean; interval?: number; }, listener: (curr: { mtime: Date }, prev: { mtime: Date }) => void): void; +}; declare var path: any; import * as ts from "typescript"; From b88269bace621082bf7588c4002ccd330aea692b Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Mon, 25 Apr 2016 11:23:56 -0700 Subject: [PATCH 10/52] Cache control flow types only at loop-back junctions --- src/compiler/binder.ts | 17 ++++++++++++----- src/compiler/checker.ts | 12 ++++++++---- src/compiler/types.ts | 1 + 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 3d6db01580a..5ad15f4d5c4 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -645,6 +645,13 @@ namespace ts { }; } + function createFlowLoopLabel(): FlowLabel { + return { + kind: FlowKind.LoopLabel, + antecedents: undefined + }; + } + function addAntecedent(label: FlowLabel, antecedent: FlowNode): void { if (antecedent.kind !== FlowKind.Unreachable && !contains(label.antecedents, antecedent)) { (label.antecedents || (label.antecedents = [])).push(antecedent); @@ -755,7 +762,7 @@ namespace ts { } function bindWhileStatement(node: WhileStatement): void { - const preWhileLabel = createFlowLabel(); + const preWhileLabel = createFlowLoopLabel(); const preBodyLabel = createFlowLabel(); const postWhileLabel = createFlowLabel(); addAntecedent(preWhileLabel, currentFlow); @@ -768,7 +775,7 @@ namespace ts { } function bindDoStatement(node: DoStatement): void { - const preDoLabel = createFlowLabel(); + const preDoLabel = createFlowLoopLabel(); const preConditionLabel = createFlowLabel(); const postDoLabel = createFlowLabel(); addAntecedent(preDoLabel, currentFlow); @@ -781,7 +788,7 @@ namespace ts { } function bindForStatement(node: ForStatement): void { - const preLoopLabel = createFlowLabel(); + const preLoopLabel = createFlowLoopLabel(); const preBodyLabel = createFlowLabel(); const postLoopLabel = createFlowLabel(); bind(node.initializer); @@ -796,7 +803,7 @@ namespace ts { } function bindForInOrForOfStatement(node: ForInStatement | ForOfStatement): void { - const preLoopLabel = createFlowLabel(); + const preLoopLabel = createFlowLoopLabel(); const postLoopLabel = createFlowLabel(); addAntecedent(preLoopLabel, currentFlow); currentFlow = preLoopLabel; @@ -943,7 +950,7 @@ namespace ts { } function bindLabeledStatement(node: LabeledStatement): void { - const preStatementLabel = createFlowLabel(); + const preStatementLabel = createFlowLoopLabel(); const postStatementLabel = createFlowLabel(); bind(node.label); addAntecedent(preStatementLabel, currentFlow); diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 8491ef7de92..992fc466dd7 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -7592,6 +7592,7 @@ namespace ts { case FlowKind.Condition: return getTypeAtFlowCondition(flow); case FlowKind.Label: + case FlowKind.LoopLabel: if ((flow).antecedents.length === 1) { flow = (flow).antecedents[0]; continue; @@ -7639,7 +7640,8 @@ namespace ts { } function getTypeAtFlowCondition(flow: FlowCondition) { - return narrowType(getTypeAtFlowNode(flow.antecedent), flow.expression, flow.assumeTrue); + const type = getTypeAtFlowNode(flow.antecedent); + return type && narrowType(type, flow.expression, flow.assumeTrue); } function getTypeAtFlowNodeCached(flow: FlowNode) { @@ -7665,13 +7667,15 @@ namespace ts { flowStackCount--; // Record the result only if the cache is still empty. If checkExpressionCached was called // during processing it is possible we've already recorded a result. - return cache[key] || (cache[key] = type); + return cache[key] || type && (cache[key] = type); } function getTypeAtFlowLabel(flow: FlowLabel) { const antecedentTypes: Type[] = []; for (const antecedent of flow.antecedents) { - const type = getTypeAtFlowNodeCached(antecedent); + const type = flow.kind === FlowKind.LoopLabel ? + getTypeAtFlowNodeCached(antecedent) : + getTypeAtFlowNode(antecedent); if (type) { // If the type at a particular antecedent path is the declared type and the // reference is known to always be assigned (i.e. when declared and initial types @@ -7685,7 +7689,7 @@ namespace ts { } } } - return antecedentTypes.length === 0 ? declaredType : + return antecedentTypes.length === 0 ? undefined : antecedentTypes.length === 1 ? antecedentTypes[0] : getUnionType(antecedentTypes); } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 25329b7ee2b..e1d7f00ff99 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1519,6 +1519,7 @@ namespace ts { Unreachable, Start, Label, + LoopLabel, Assignment, Condition } From ff108c01421d6e602e87bd2a13a1599ff60f3106 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Mon, 25 Apr 2016 11:24:39 -0700 Subject: [PATCH 11/52] Adding regression test --- .../reference/controlFlowIteration.js | 40 +++++++++++++++++ .../reference/controlFlowIteration.symbols | 39 +++++++++++++++++ .../reference/controlFlowIteration.types | 43 +++++++++++++++++++ .../controlFlow/controlFlowIteration.ts | 20 +++++++++ 4 files changed, 142 insertions(+) create mode 100644 tests/baselines/reference/controlFlowIteration.js create mode 100644 tests/baselines/reference/controlFlowIteration.symbols create mode 100644 tests/baselines/reference/controlFlowIteration.types create mode 100644 tests/cases/conformance/controlFlow/controlFlowIteration.ts diff --git a/tests/baselines/reference/controlFlowIteration.js b/tests/baselines/reference/controlFlowIteration.js new file mode 100644 index 00000000000..7b319ba8098 --- /dev/null +++ b/tests/baselines/reference/controlFlowIteration.js @@ -0,0 +1,40 @@ +//// [controlFlowIteration.ts] + +let cond: boolean; + +function ff() { + let x: string | undefined; + while (true) { + if (cond) { + x = ""; + } + else { + if (x) { + x.length; + } + if (x) { + x.length; + } + } + } +} + + +//// [controlFlowIteration.js] +var cond; +function ff() { + var x; + while (true) { + if (cond) { + x = ""; + } + else { + if (x) { + x.length; + } + if (x) { + x.length; + } + } + } +} diff --git a/tests/baselines/reference/controlFlowIteration.symbols b/tests/baselines/reference/controlFlowIteration.symbols new file mode 100644 index 00000000000..84c1c57b69b --- /dev/null +++ b/tests/baselines/reference/controlFlowIteration.symbols @@ -0,0 +1,39 @@ +=== tests/cases/conformance/controlFlow/controlFlowIteration.ts === + +let cond: boolean; +>cond : Symbol(cond, Decl(controlFlowIteration.ts, 1, 3)) + +function ff() { +>ff : Symbol(ff, Decl(controlFlowIteration.ts, 1, 18)) + + let x: string | undefined; +>x : Symbol(x, Decl(controlFlowIteration.ts, 4, 7)) + + while (true) { + if (cond) { +>cond : Symbol(cond, Decl(controlFlowIteration.ts, 1, 3)) + + x = ""; +>x : Symbol(x, Decl(controlFlowIteration.ts, 4, 7)) + } + else { + if (x) { +>x : Symbol(x, Decl(controlFlowIteration.ts, 4, 7)) + + x.length; +>x.length : Symbol(String.length, Decl(lib.d.ts, --, --)) +>x : Symbol(x, Decl(controlFlowIteration.ts, 4, 7)) +>length : Symbol(String.length, Decl(lib.d.ts, --, --)) + } + if (x) { +>x : Symbol(x, Decl(controlFlowIteration.ts, 4, 7)) + + x.length; +>x.length : Symbol(String.length, Decl(lib.d.ts, --, --)) +>x : Symbol(x, Decl(controlFlowIteration.ts, 4, 7)) +>length : Symbol(String.length, Decl(lib.d.ts, --, --)) + } + } + } +} + diff --git a/tests/baselines/reference/controlFlowIteration.types b/tests/baselines/reference/controlFlowIteration.types new file mode 100644 index 00000000000..52be501d68e --- /dev/null +++ b/tests/baselines/reference/controlFlowIteration.types @@ -0,0 +1,43 @@ +=== tests/cases/conformance/controlFlow/controlFlowIteration.ts === + +let cond: boolean; +>cond : boolean + +function ff() { +>ff : () => void + + let x: string | undefined; +>x : string | undefined + + while (true) { +>true : boolean + + if (cond) { +>cond : boolean + + x = ""; +>x = "" : string +>x : string | undefined +>"" : string + } + else { + if (x) { +>x : string | undefined + + x.length; +>x.length : number +>x : string +>length : number + } + if (x) { +>x : string | undefined + + x.length; +>x.length : number +>x : string +>length : number + } + } + } +} + diff --git a/tests/cases/conformance/controlFlow/controlFlowIteration.ts b/tests/cases/conformance/controlFlow/controlFlowIteration.ts new file mode 100644 index 00000000000..56172b1bbdf --- /dev/null +++ b/tests/cases/conformance/controlFlow/controlFlowIteration.ts @@ -0,0 +1,20 @@ +// @strictNullChecks: true + +let cond: boolean; + +function ff() { + let x: string | undefined; + while (true) { + if (cond) { + x = ""; + } + else { + if (x) { + x.length; + } + if (x) { + x.length; + } + } + } +} From aca769f8c4fe640f30ea780a04da88a94c356edf Mon Sep 17 00:00:00 2001 From: Zhengbo Li Date: Mon, 25 Apr 2016 15:24:34 -0700 Subject: [PATCH 12/52] Remove hard-coded new line character option --- src/server/session.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/server/session.ts b/src/server/session.ts index df8273116c1..e043fff2246 100644 --- a/src/server/session.ts +++ b/src/server/session.ts @@ -647,7 +647,7 @@ namespace ts.server { const editorOptions: ts.EditorOptions = { IndentSize: formatOptions.IndentSize, TabSize: formatOptions.TabSize, - NewLineCharacter: "\n", + NewLineCharacter: formatOptions.NewLineCharacter, ConvertTabsToSpaces: formatOptions.ConvertTabsToSpaces, IndentStyle: ts.IndentStyle.Smart, }; From 71fc58197c9f7d157784a91c52f8d463c48679b1 Mon Sep 17 00:00:00 2001 From: Yui Date: Mon, 25 Apr 2016 16:31:01 -0700 Subject: [PATCH 13/52] Fix8256 (#8292) * Consider identifier in await expression to be expression * Add tests * Update baselines --- src/compiler/emitter.ts | 1 + .../defaultExportInAwaitExpression01.js | 53 +++++++++++++++++++ .../defaultExportInAwaitExpression01.symbols | 22 ++++++++ .../defaultExportInAwaitExpression01.types | 31 +++++++++++ .../defaultExportInAwaitExpression02.js | 35 ++++++++++++ .../defaultExportInAwaitExpression02.symbols | 22 ++++++++ .../defaultExportInAwaitExpression02.types | 31 +++++++++++ .../defaultExportInAwaitExpression01.ts | 12 +++++ .../defaultExportInAwaitExpression02.ts | 12 +++++ 9 files changed, 219 insertions(+) create mode 100644 tests/baselines/reference/defaultExportInAwaitExpression01.js create mode 100644 tests/baselines/reference/defaultExportInAwaitExpression01.symbols create mode 100644 tests/baselines/reference/defaultExportInAwaitExpression01.types create mode 100644 tests/baselines/reference/defaultExportInAwaitExpression02.js create mode 100644 tests/baselines/reference/defaultExportInAwaitExpression02.symbols create mode 100644 tests/baselines/reference/defaultExportInAwaitExpression02.types create mode 100644 tests/cases/conformance/es6/modules/defaultExportInAwaitExpression01.ts create mode 100644 tests/cases/conformance/es6/modules/defaultExportInAwaitExpression02.ts diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index c4e3c8668fd..a1f02f520d8 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -1524,6 +1524,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge switch (parent.kind) { case SyntaxKind.ArrayLiteralExpression: case SyntaxKind.AsExpression: + case SyntaxKind.AwaitExpression: case SyntaxKind.BinaryExpression: case SyntaxKind.CallExpression: case SyntaxKind.CaseClause: diff --git a/tests/baselines/reference/defaultExportInAwaitExpression01.js b/tests/baselines/reference/defaultExportInAwaitExpression01.js new file mode 100644 index 00000000000..afd4dfa7a56 --- /dev/null +++ b/tests/baselines/reference/defaultExportInAwaitExpression01.js @@ -0,0 +1,53 @@ +//// [tests/cases/conformance/es6/modules/defaultExportInAwaitExpression01.ts] //// + +//// [a.ts] +const x = new Promise( ( resolve, reject ) => { resolve( {} ); } ); +export default x; + +//// [b.ts] +import x from './a'; + +( async function() { + const value = await x; +}() ); + + +//// [a.js] +(function (factory) { + if (typeof module === 'object' && typeof module.exports === 'object') { + var v = factory(require, exports); if (v !== undefined) module.exports = v; + } + else if (typeof define === 'function' && define.amd) { + define(["require", "exports"], factory); + } +})(function (require, exports) { + "use strict"; + const x = new Promise((resolve, reject) => { resolve({}); }); + Object.defineProperty(exports, "__esModule", { value: true }); + exports.default = x; +}); +//// [b.js] +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator.throw(value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments)).next()); + }); +}; +(function (factory) { + if (typeof module === 'object' && typeof module.exports === 'object') { + var v = factory(require, exports); if (v !== undefined) module.exports = v; + } + else if (typeof define === 'function' && define.amd) { + define(["require", "exports", './a'], factory); + } +})(function (require, exports) { + "use strict"; + const a_1 = require('./a'); + (function () { + return __awaiter(this, void 0, void 0, function* () { + const value = yield a_1.default; + }); + }()); +}); diff --git a/tests/baselines/reference/defaultExportInAwaitExpression01.symbols b/tests/baselines/reference/defaultExportInAwaitExpression01.symbols new file mode 100644 index 00000000000..eb833f63895 --- /dev/null +++ b/tests/baselines/reference/defaultExportInAwaitExpression01.symbols @@ -0,0 +1,22 @@ +=== tests/cases/conformance/es6/modules/a.ts === +const x = new Promise( ( resolve, reject ) => { resolve( {} ); } ); +>x : Symbol(x, Decl(a.ts, 0, 5)) +>Promise : Symbol(Promise, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) +>resolve : Symbol(resolve, Decl(a.ts, 0, 24)) +>reject : Symbol(reject, Decl(a.ts, 0, 33)) +>resolve : Symbol(resolve, Decl(a.ts, 0, 24)) + +export default x; +>x : Symbol(x, Decl(a.ts, 0, 5)) + +=== tests/cases/conformance/es6/modules/b.ts === +import x from './a'; +>x : Symbol(x, Decl(b.ts, 0, 6)) + +( async function() { + const value = await x; +>value : Symbol(value, Decl(b.ts, 3, 9)) +>x : Symbol(x, Decl(b.ts, 0, 6)) + +}() ); + diff --git a/tests/baselines/reference/defaultExportInAwaitExpression01.types b/tests/baselines/reference/defaultExportInAwaitExpression01.types new file mode 100644 index 00000000000..1f7de76b90e --- /dev/null +++ b/tests/baselines/reference/defaultExportInAwaitExpression01.types @@ -0,0 +1,31 @@ +=== tests/cases/conformance/es6/modules/a.ts === +const x = new Promise( ( resolve, reject ) => { resolve( {} ); } ); +>x : Promise<{}> +>new Promise( ( resolve, reject ) => { resolve( {} ); } ) : Promise<{}> +>Promise : PromiseConstructor +>( resolve, reject ) => { resolve( {} ); } : (resolve: (value?: {} | PromiseLike<{}>) => void, reject: (reason?: any) => void) => void +>resolve : (value?: {} | PromiseLike<{}>) => void +>reject : (reason?: any) => void +>resolve( {} ) : void +>resolve : (value?: {} | PromiseLike<{}>) => void +>{} : {} + +export default x; +>x : Promise<{}> + +=== tests/cases/conformance/es6/modules/b.ts === +import x from './a'; +>x : Promise<{}> + +( async function() { +>( async function() { const value = await x;}() ) : Promise +>async function() { const value = await x;}() : Promise +>async function() { const value = await x;} : () => Promise + + const value = await x; +>value : {} +>await x : {} +>x : Promise<{}> + +}() ); + diff --git a/tests/baselines/reference/defaultExportInAwaitExpression02.js b/tests/baselines/reference/defaultExportInAwaitExpression02.js new file mode 100644 index 00000000000..70a9ce6c2d3 --- /dev/null +++ b/tests/baselines/reference/defaultExportInAwaitExpression02.js @@ -0,0 +1,35 @@ +//// [tests/cases/conformance/es6/modules/defaultExportInAwaitExpression02.ts] //// + +//// [a.ts] +const x = new Promise( ( resolve, reject ) => { resolve( {} ); } ); +export default x; + +//// [b.ts] +import x from './a'; + +( async function() { + const value = await x; +}() ); + + +//// [a.js] +"use strict"; +const x = new Promise((resolve, reject) => { resolve({}); }); +Object.defineProperty(exports, "__esModule", { value: true }); +exports.default = x; +//// [b.js] +"use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator.throw(value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments)).next()); + }); +}; +const a_1 = require('./a'); +(function () { + return __awaiter(this, void 0, void 0, function* () { + const value = yield a_1.default; + }); +}()); diff --git a/tests/baselines/reference/defaultExportInAwaitExpression02.symbols b/tests/baselines/reference/defaultExportInAwaitExpression02.symbols new file mode 100644 index 00000000000..eb833f63895 --- /dev/null +++ b/tests/baselines/reference/defaultExportInAwaitExpression02.symbols @@ -0,0 +1,22 @@ +=== tests/cases/conformance/es6/modules/a.ts === +const x = new Promise( ( resolve, reject ) => { resolve( {} ); } ); +>x : Symbol(x, Decl(a.ts, 0, 5)) +>Promise : Symbol(Promise, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) +>resolve : Symbol(resolve, Decl(a.ts, 0, 24)) +>reject : Symbol(reject, Decl(a.ts, 0, 33)) +>resolve : Symbol(resolve, Decl(a.ts, 0, 24)) + +export default x; +>x : Symbol(x, Decl(a.ts, 0, 5)) + +=== tests/cases/conformance/es6/modules/b.ts === +import x from './a'; +>x : Symbol(x, Decl(b.ts, 0, 6)) + +( async function() { + const value = await x; +>value : Symbol(value, Decl(b.ts, 3, 9)) +>x : Symbol(x, Decl(b.ts, 0, 6)) + +}() ); + diff --git a/tests/baselines/reference/defaultExportInAwaitExpression02.types b/tests/baselines/reference/defaultExportInAwaitExpression02.types new file mode 100644 index 00000000000..1f7de76b90e --- /dev/null +++ b/tests/baselines/reference/defaultExportInAwaitExpression02.types @@ -0,0 +1,31 @@ +=== tests/cases/conformance/es6/modules/a.ts === +const x = new Promise( ( resolve, reject ) => { resolve( {} ); } ); +>x : Promise<{}> +>new Promise( ( resolve, reject ) => { resolve( {} ); } ) : Promise<{}> +>Promise : PromiseConstructor +>( resolve, reject ) => { resolve( {} ); } : (resolve: (value?: {} | PromiseLike<{}>) => void, reject: (reason?: any) => void) => void +>resolve : (value?: {} | PromiseLike<{}>) => void +>reject : (reason?: any) => void +>resolve( {} ) : void +>resolve : (value?: {} | PromiseLike<{}>) => void +>{} : {} + +export default x; +>x : Promise<{}> + +=== tests/cases/conformance/es6/modules/b.ts === +import x from './a'; +>x : Promise<{}> + +( async function() { +>( async function() { const value = await x;}() ) : Promise +>async function() { const value = await x;}() : Promise +>async function() { const value = await x;} : () => Promise + + const value = await x; +>value : {} +>await x : {} +>x : Promise<{}> + +}() ); + diff --git a/tests/cases/conformance/es6/modules/defaultExportInAwaitExpression01.ts b/tests/cases/conformance/es6/modules/defaultExportInAwaitExpression01.ts new file mode 100644 index 00000000000..45f15423016 --- /dev/null +++ b/tests/cases/conformance/es6/modules/defaultExportInAwaitExpression01.ts @@ -0,0 +1,12 @@ +// @target: ES6 +// @module: umd +// @filename: a.ts +const x = new Promise( ( resolve, reject ) => { resolve( {} ); } ); +export default x; + +// @filename: b.ts +import x from './a'; + +( async function() { + const value = await x; +}() ); diff --git a/tests/cases/conformance/es6/modules/defaultExportInAwaitExpression02.ts b/tests/cases/conformance/es6/modules/defaultExportInAwaitExpression02.ts new file mode 100644 index 00000000000..cd878540a3c --- /dev/null +++ b/tests/cases/conformance/es6/modules/defaultExportInAwaitExpression02.ts @@ -0,0 +1,12 @@ +// @target: ES6 +// @module: commonjs +// @filename: a.ts +const x = new Promise( ( resolve, reject ) => { resolve( {} ); } ); +export default x; + +// @filename: b.ts +import x from './a'; + +( async function() { + const value = await x; +}() ); From ecc936167fba12ac8709053621fd8cd2a9b7c661 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Mon, 25 Apr 2016 17:22:06 -0700 Subject: [PATCH 14/52] Variable of type any has initial type any in control flow analysis --- src/compiler/checker.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 992fc466dd7..6a42dc43d51 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -7972,7 +7972,7 @@ namespace ts { return type; } const declaration = localOrExportSymbol.valueDeclaration; - const defaultsToDeclaredType = !strictNullChecks || !declaration || + const defaultsToDeclaredType = !strictNullChecks || type.flags & TypeFlags.Any || !declaration || declaration.kind === SyntaxKind.Parameter || isInAmbientContext(declaration) || getContainingFunctionOrModule(declaration) !== getContainingFunctionOrModule(node); if (defaultsToDeclaredType && !(type.flags & TypeFlags.Narrowable)) { From 6cd7db825748a114d649431bde2a916678fba43e Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Mon, 25 Apr 2016 21:24:42 -0700 Subject: [PATCH 15/52] Adding regression test --- .../defaultOfAnyInStrictNullChecks.js | 22 +++++++++++++++++++ .../defaultOfAnyInStrictNullChecks.symbols | 18 +++++++++++++++ .../defaultOfAnyInStrictNullChecks.types | 20 +++++++++++++++++ .../defaultOfAnyInStrictNullChecks.ts | 11 ++++++++++ 4 files changed, 71 insertions(+) create mode 100644 tests/baselines/reference/defaultOfAnyInStrictNullChecks.js create mode 100644 tests/baselines/reference/defaultOfAnyInStrictNullChecks.symbols create mode 100644 tests/baselines/reference/defaultOfAnyInStrictNullChecks.types create mode 100644 tests/cases/compiler/defaultOfAnyInStrictNullChecks.ts diff --git a/tests/baselines/reference/defaultOfAnyInStrictNullChecks.js b/tests/baselines/reference/defaultOfAnyInStrictNullChecks.js new file mode 100644 index 00000000000..7706181b343 --- /dev/null +++ b/tests/baselines/reference/defaultOfAnyInStrictNullChecks.js @@ -0,0 +1,22 @@ +//// [defaultOfAnyInStrictNullChecks.ts] + +// Regression test for #8295 + +function foo() { + try { + } + catch (e) { + let s = e.message; + } +} + + +//// [defaultOfAnyInStrictNullChecks.js] +// Regression test for #8295 +function foo() { + try { + } + catch (e) { + var s = e.message; + } +} diff --git a/tests/baselines/reference/defaultOfAnyInStrictNullChecks.symbols b/tests/baselines/reference/defaultOfAnyInStrictNullChecks.symbols new file mode 100644 index 00000000000..c7de7f6b2f3 --- /dev/null +++ b/tests/baselines/reference/defaultOfAnyInStrictNullChecks.symbols @@ -0,0 +1,18 @@ +=== tests/cases/compiler/defaultOfAnyInStrictNullChecks.ts === + +// Regression test for #8295 + +function foo() { +>foo : Symbol(foo, Decl(defaultOfAnyInStrictNullChecks.ts, 0, 0)) + + try { + } + catch (e) { +>e : Symbol(e, Decl(defaultOfAnyInStrictNullChecks.ts, 6, 11)) + + let s = e.message; +>s : Symbol(s, Decl(defaultOfAnyInStrictNullChecks.ts, 7, 11)) +>e : Symbol(e, Decl(defaultOfAnyInStrictNullChecks.ts, 6, 11)) + } +} + diff --git a/tests/baselines/reference/defaultOfAnyInStrictNullChecks.types b/tests/baselines/reference/defaultOfAnyInStrictNullChecks.types new file mode 100644 index 00000000000..8e4c1adcd61 --- /dev/null +++ b/tests/baselines/reference/defaultOfAnyInStrictNullChecks.types @@ -0,0 +1,20 @@ +=== tests/cases/compiler/defaultOfAnyInStrictNullChecks.ts === + +// Regression test for #8295 + +function foo() { +>foo : () => void + + try { + } + catch (e) { +>e : any + + let s = e.message; +>s : any +>e.message : any +>e : any +>message : any + } +} + diff --git a/tests/cases/compiler/defaultOfAnyInStrictNullChecks.ts b/tests/cases/compiler/defaultOfAnyInStrictNullChecks.ts new file mode 100644 index 00000000000..17568f48029 --- /dev/null +++ b/tests/cases/compiler/defaultOfAnyInStrictNullChecks.ts @@ -0,0 +1,11 @@ +// @strictNullChecks: true + +// Regression test for #8295 + +function foo() { + try { + } + catch (e) { + let s = e.message; + } +} From fed42cc6bda7d81335f5adc7ca3ba3d573763785 Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Tue, 26 Apr 2016 13:01:14 -0700 Subject: [PATCH 16/52] Add test --- .../reference/ambientNameRestrictions.errors.txt | 10 ++++++++++ tests/baselines/reference/ambientNameRestrictions.js | 8 ++++++++ tests/cases/compiler/ambientNameRestrictions.ts | 3 +++ 3 files changed, 21 insertions(+) create mode 100644 tests/baselines/reference/ambientNameRestrictions.errors.txt create mode 100644 tests/baselines/reference/ambientNameRestrictions.js create mode 100644 tests/cases/compiler/ambientNameRestrictions.ts diff --git a/tests/baselines/reference/ambientNameRestrictions.errors.txt b/tests/baselines/reference/ambientNameRestrictions.errors.txt new file mode 100644 index 00000000000..88dc2e13f4d --- /dev/null +++ b/tests/baselines/reference/ambientNameRestrictions.errors.txt @@ -0,0 +1,10 @@ +tests/cases/compiler/ambientNameRestrictions.ts(2,14): error TS1214: Identifier expected. 'static' is a reserved word in strict mode. Modules are automatically in strict mode. + + +==== tests/cases/compiler/ambientNameRestrictions.ts (1 errors) ==== + export declare namespace Foo { + export var static: any; + ~~~~~~ +!!! error TS1214: Identifier expected. 'static' is a reserved word in strict mode. Modules are automatically in strict mode. + } + \ No newline at end of file diff --git a/tests/baselines/reference/ambientNameRestrictions.js b/tests/baselines/reference/ambientNameRestrictions.js new file mode 100644 index 00000000000..cd4fbf29371 --- /dev/null +++ b/tests/baselines/reference/ambientNameRestrictions.js @@ -0,0 +1,8 @@ +//// [ambientNameRestrictions.ts] +export declare namespace Foo { + export var static: any; +} + + +//// [ambientNameRestrictions.js] +"use strict"; diff --git a/tests/cases/compiler/ambientNameRestrictions.ts b/tests/cases/compiler/ambientNameRestrictions.ts new file mode 100644 index 00000000000..dc601e91851 --- /dev/null +++ b/tests/cases/compiler/ambientNameRestrictions.ts @@ -0,0 +1,3 @@ +export declare namespace Foo { + export var static: any; +} From de4f2797c663e1cb7fa20b468fd5c5353e088b1d Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Tue, 26 Apr 2016 13:10:06 -0700 Subject: [PATCH 17/52] Don't error when 'reserved' names appear in ambient contexts. Fixes #8293 --- src/compiler/binder.ts | 3 ++- .../reference/ambientNameRestrictions.errors.txt | 10 ---------- .../reference/ambientNameRestrictions.symbols | 8 ++++++++ .../baselines/reference/ambientNameRestrictions.types | 8 ++++++++ 4 files changed, 18 insertions(+), 11 deletions(-) delete mode 100644 tests/baselines/reference/ambientNameRestrictions.errors.txt create mode 100644 tests/baselines/reference/ambientNameRestrictions.symbols create mode 100644 tests/baselines/reference/ambientNameRestrictions.types diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 5ad15f4d5c4..bbc4f5990de 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -1377,7 +1377,8 @@ namespace ts { if (inStrictMode && node.originalKeywordKind >= SyntaxKind.FirstFutureReservedWord && node.originalKeywordKind <= SyntaxKind.LastFutureReservedWord && - !isIdentifierName(node)) { + !isIdentifierName(node) && + !isInAmbientContext(node)) { // Report error only if there are no parse errors in file if (!file.parseDiagnostics.length) { diff --git a/tests/baselines/reference/ambientNameRestrictions.errors.txt b/tests/baselines/reference/ambientNameRestrictions.errors.txt deleted file mode 100644 index 88dc2e13f4d..00000000000 --- a/tests/baselines/reference/ambientNameRestrictions.errors.txt +++ /dev/null @@ -1,10 +0,0 @@ -tests/cases/compiler/ambientNameRestrictions.ts(2,14): error TS1214: Identifier expected. 'static' is a reserved word in strict mode. Modules are automatically in strict mode. - - -==== tests/cases/compiler/ambientNameRestrictions.ts (1 errors) ==== - export declare namespace Foo { - export var static: any; - ~~~~~~ -!!! error TS1214: Identifier expected. 'static' is a reserved word in strict mode. Modules are automatically in strict mode. - } - \ No newline at end of file diff --git a/tests/baselines/reference/ambientNameRestrictions.symbols b/tests/baselines/reference/ambientNameRestrictions.symbols new file mode 100644 index 00000000000..d5b3fafaa57 --- /dev/null +++ b/tests/baselines/reference/ambientNameRestrictions.symbols @@ -0,0 +1,8 @@ +=== tests/cases/compiler/ambientNameRestrictions.ts === +export declare namespace Foo { +>Foo : Symbol(Foo, Decl(ambientNameRestrictions.ts, 0, 0)) + + export var static: any; +>static : Symbol(static, Decl(ambientNameRestrictions.ts, 1, 12)) +} + diff --git a/tests/baselines/reference/ambientNameRestrictions.types b/tests/baselines/reference/ambientNameRestrictions.types new file mode 100644 index 00000000000..705319392d8 --- /dev/null +++ b/tests/baselines/reference/ambientNameRestrictions.types @@ -0,0 +1,8 @@ +=== tests/cases/compiler/ambientNameRestrictions.ts === +export declare namespace Foo { +>Foo : typeof Foo + + export var static: any; +>static : any +} + From 0d32570c026c1b8a47cd38ba5bf642c72ef39a50 Mon Sep 17 00:00:00 2001 From: zhengbli Date: Tue, 26 Apr 2016 14:35:51 -0700 Subject: [PATCH 18/52] add dirWatcher for "watch" option in tsconfig.json --- src/compiler/tsc.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/compiler/tsc.ts b/src/compiler/tsc.ts index 2e40cfdc53c..d6dfc9eca8d 100644 --- a/src/compiler/tsc.ts +++ b/src/compiler/tsc.ts @@ -432,6 +432,16 @@ namespace ts { return sys.exit(compileResult.exitStatus); } + if (!directoryWatcher && sys.watchDirectory && configFileName) { + const directory = ts.getDirectoryPath(configFileName); + directoryWatcher = sys.watchDirectory( + // When the configFileName is just "tsconfig.json", the watched directory should be + // the current directory; if there is a given "project" parameter, then the configFileName + // is an absolute file name. + directory == "" ? "." : directory, + watchedDirectoryChanged, /*recursive*/ true); + } + setCachedProgram(compileResult.program); reportWatchDiagnostic(createCompilerDiagnostic(Diagnostics.Compilation_complete_Watching_for_file_changes)); } From 700435bb8e22f35c9cdc9794898ff0c678dd9793 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Tue, 26 Apr 2016 17:32:00 -0700 Subject: [PATCH 19/52] Properly display narrowed types when hovering in IDE --- src/compiler/checker.ts | 72 +++++++++++++++++------------------------ 1 file changed, 30 insertions(+), 42 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 6a42dc43d51..ddaea2285c5 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -7358,12 +7358,6 @@ namespace ts { return flowTypeCaches[flow.id] || (flowTypeCaches[flow.id] = {}); } - function isNarrowableReference(expr: Node): boolean { - return expr.kind === SyntaxKind.Identifier || - expr.kind === SyntaxKind.ThisKeyword || - expr.kind === SyntaxKind.PropertyAccessExpression && isNarrowableReference((expr).expression); - } - function typeMaybeAssignableTo(source: Type, target: Type) { if (!(source.flags & TypeFlags.Union)) { return isTypeAssignableTo(source, target); @@ -7554,30 +7548,12 @@ namespace ts { getInitialTypeOfBindingElement(node); } - function getNarrowedTypeOfReference(type: Type, reference: Node) { - if (!(type.flags & TypeFlags.Narrowable) || !isNarrowableReference(reference)) { - return type; - } - const leftmostNode = getLeftmostIdentifierOrThis(reference); - if (!leftmostNode) { - return type; - } - if (leftmostNode.kind === SyntaxKind.Identifier) { - const leftmostSymbol = getExportSymbolOfValueSymbolIfExported(getResolvedSymbol(leftmostNode)); - if (!leftmostSymbol) { - return type; - } - const declaration = leftmostSymbol.valueDeclaration; - if (!declaration || declaration.kind !== SyntaxKind.VariableDeclaration && declaration.kind !== SyntaxKind.Parameter && declaration.kind !== SyntaxKind.BindingElement) { - return type; - } - } - return getFlowTypeOfReference(reference, type, type); - } - function getFlowTypeOfReference(reference: Node, declaredType: Type, initialType: Type) { let key: string; - return reference.flowNode ? getTypeAtFlowNode(reference.flowNode) : declaredType; + if (!reference.flowNode || declaredType === initialType && !(declaredType.flags & TypeFlags.Narrowable)) { + return declaredType; + } + return getTypeAtFlowNode(reference.flowNode); function getTypeAtFlowNode(flow: FlowNode): Type { while (true) { @@ -7885,19 +7861,18 @@ namespace ts { } function getTypeOfSymbolAtLocation(symbol: Symbol, location: Node) { - // The language service will always care about the narrowed type of a symbol, because that is - // the type the language says the symbol should have. - const type = getTypeOfSymbol(symbol); + // If we have an identifier or a property access at the given location, if the location is + // an dotted name expression, and if the location is not an assignment target, obtain the type + // of the expression (which will reflect control flow analysis). If the expression indeed + // resolved to the given symbol, return the narrowed type. if (location.kind === SyntaxKind.Identifier) { if (isRightSideOfQualifiedNameOrPropertyAccess(location)) { location = location.parent; } - // If location is an identifier or property access that references the given - // symbol, use the location as the reference with respect to which we narrow. if (isExpression(location) && !isAssignmentTarget(location)) { - checkExpression(location); + const type = checkExpression(location); if (getExportSymbolOfValueSymbolIfExported(getNodeLinks(location).resolvedSymbol) === symbol) { - return getNarrowedTypeOfReference(type, location); + return type; } } } @@ -7906,7 +7881,7 @@ namespace ts { // to it at the given location. Since we have no control flow information for the // hypotherical reference (control flow information is created and attached by the // binder), we simply return the declared type of the symbol. - return type; + return getTypeOfSymbol(symbol); } function skipParenthesizedNodes(expression: Expression): Expression { @@ -7975,9 +7950,6 @@ namespace ts { const defaultsToDeclaredType = !strictNullChecks || type.flags & TypeFlags.Any || !declaration || declaration.kind === SyntaxKind.Parameter || isInAmbientContext(declaration) || getContainingFunctionOrModule(declaration) !== getContainingFunctionOrModule(node); - if (defaultsToDeclaredType && !(type.flags & TypeFlags.Narrowable)) { - return type; - } const flowType = getFlowTypeOfReference(node, type, defaultsToDeclaredType ? type : undefinedType); if (strictNullChecks && !(type.flags & TypeFlags.Any) && !(getNullableKind(type) & TypeFlags.Undefined) && getNullableKind(flowType) & TypeFlags.Undefined) { error(node, Diagnostics.Variable_0_is_used_before_being_assigned, symbolToString(symbol)); @@ -8220,7 +8192,7 @@ namespace ts { if (isClassLike(container.parent)) { const symbol = getSymbolOfNode(container.parent); const type = container.flags & NodeFlags.Static ? getTypeOfSymbol(symbol) : (getDeclaredTypeOfSymbol(symbol)).thisType; - return getNarrowedTypeOfReference(type, node); + return getFlowTypeOfReference(node, type, type); } if (isInJavaScriptFile(node)) { @@ -9784,8 +9756,24 @@ namespace ts { } const propType = getTypeOfSymbol(prop); - return node.kind === SyntaxKind.PropertyAccessExpression && prop.flags & (SymbolFlags.Variable | SymbolFlags.Property) && !isAssignmentTarget(node) ? - getNarrowedTypeOfReference(propType, node) : propType; + if (node.kind !== SyntaxKind.PropertyAccessExpression || !(prop.flags & (SymbolFlags.Variable | SymbolFlags.Property)) || isAssignmentTarget(node)) { + return propType; + } + const leftmostNode = getLeftmostIdentifierOrThis(node); + if (!leftmostNode) { + return propType; + } + if (leftmostNode.kind === SyntaxKind.Identifier) { + const leftmostSymbol = getExportSymbolOfValueSymbolIfExported(getResolvedSymbol(leftmostNode)); + if (!leftmostSymbol) { + return propType; + } + const declaration = leftmostSymbol.valueDeclaration; + if (!declaration || declaration.kind !== SyntaxKind.VariableDeclaration && declaration.kind !== SyntaxKind.Parameter && declaration.kind !== SyntaxKind.BindingElement) { + return propType; + } + } + return getFlowTypeOfReference(node, propType, propType); } function isValidPropertyAccess(node: PropertyAccessExpression | QualifiedName, propertyName: string): boolean { From 65edb527f5aeea4a2f364232f8ba8c4175a6fbad Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Wed, 27 Apr 2016 09:08:45 -0700 Subject: [PATCH 20/52] Adding fourslash test --- .../fourslash/quickInfoOnNarrowedType.ts | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/cases/fourslash/quickInfoOnNarrowedType.ts b/tests/cases/fourslash/quickInfoOnNarrowedType.ts index bc1d8126d76..53fe1bed232 100644 --- a/tests/cases/fourslash/quickInfoOnNarrowedType.ts +++ b/tests/cases/fourslash/quickInfoOnNarrowedType.ts @@ -1,5 +1,7 @@ /// +// @strictNullChecks: true + ////function foo(strOrNum: string | number) { //// if (typeof /*1*/strOrNum === "number") { //// return /*2*/strOrNum; @@ -9,6 +11,13 @@ //// } ////} +////function bar() { +//// let s: string | undefined; +//// /*4*/s; +//// /*5*/s = "abc"; +//// /*6*/s; +////} + goTo.marker('1'); verify.quickInfoIs('(parameter) strOrNum: string | number'); verify.completionListContains("strOrNum", "(parameter) strOrNum: string | number"); @@ -20,3 +29,15 @@ verify.completionListContains("strOrNum", "(parameter) strOrNum: number"); goTo.marker('3'); verify.quickInfoIs('(parameter) strOrNum: string'); verify.completionListContains("strOrNum", "(parameter) strOrNum: string"); + +goTo.marker('4'); +verify.quickInfoIs('let s: undefined'); +verify.completionListContains("s", "let s: undefined"); + +goTo.marker('5'); +verify.quickInfoIs('let s: string | undefined'); +verify.completionListContains("s", "let s: string | undefined"); + +goTo.marker('6'); +verify.quickInfoIs('let s: string'); +verify.completionListContains("s", "let s: string"); From a1039bb0614d646722f98b5858b36d407539bbb8 Mon Sep 17 00:00:00 2001 From: Zhengbo Li Date: Wed, 27 Apr 2016 13:22:10 -0700 Subject: [PATCH 21/52] Routine update of dom lib files --- src/lib/dom.generated.d.ts | 956 +++++++++++++++---------------- src/lib/webworker.generated.d.ts | 25 +- 2 files changed, 495 insertions(+), 486 deletions(-) diff --git a/src/lib/dom.generated.d.ts b/src/lib/dom.generated.d.ts index f3ced0f6011..5865e485754 100644 --- a/src/lib/dom.generated.d.ts +++ b/src/lib/dom.generated.d.ts @@ -1,3 +1,4 @@ + ///////////////////////////// /// IE DOM APIs ///////////////////////////// @@ -957,7 +958,7 @@ declare var ApplicationCache: { interface AriaRequestEvent extends Event { readonly attributeName: string; - attributeValue: string; + attributeValue: string | null; } declare var AriaRequestEvent: { @@ -968,7 +969,7 @@ declare var AriaRequestEvent: { interface Attr extends Node { readonly name: string; readonly ownerElement: Element; - readonly prefix: string; + readonly prefix: string | null; readonly specified: boolean; value: string; } @@ -994,7 +995,7 @@ declare var AudioBuffer: { } interface AudioBufferSourceNode extends AudioNode { - buffer: AudioBuffer; + buffer: AudioBuffer | null; readonly detune: AudioParam; loop: boolean; loopEnd: number; @@ -1130,7 +1131,7 @@ interface AudioTrackList extends EventTarget { onaddtrack: (ev: TrackEvent) => any; onchange: (ev: Event) => any; onremovetrack: (ev: TrackEvent) => any; - getTrackById(id: string): AudioTrack; + getTrackById(id: string): AudioTrack | null; item(index: number): AudioTrack; addEventListener(type: "addtrack", listener: (ev: TrackEvent) => any, useCapture?: boolean): void; addEventListener(type: "change", listener: (ev: Event) => any, useCapture?: boolean): void; @@ -1344,343 +1345,343 @@ declare var CSSRuleList: { } interface CSSStyleDeclaration { - alignContent: string; - alignItems: string; - alignSelf: string; - alignmentBaseline: string; - animation: string; - animationDelay: string; - animationDirection: string; - animationDuration: string; - animationFillMode: string; - animationIterationCount: string; - animationName: string; - animationPlayState: string; - animationTimingFunction: string; - backfaceVisibility: string; - background: string; - backgroundAttachment: string; - backgroundClip: string; - backgroundColor: string; - backgroundImage: string; - backgroundOrigin: string; - backgroundPosition: string; - backgroundPositionX: string; - backgroundPositionY: string; - backgroundRepeat: string; - backgroundSize: string; - baselineShift: string; - border: string; - borderBottom: string; - borderBottomColor: string; - borderBottomLeftRadius: string; - borderBottomRightRadius: string; - borderBottomStyle: string; - borderBottomWidth: string; - borderCollapse: string; - borderColor: string; - borderImage: string; - borderImageOutset: string; - borderImageRepeat: string; - borderImageSlice: string; - borderImageSource: string; - borderImageWidth: string; - borderLeft: string; - borderLeftColor: string; - borderLeftStyle: string; - borderLeftWidth: string; - borderRadius: string; - borderRight: string; - borderRightColor: string; - borderRightStyle: string; - borderRightWidth: string; - borderSpacing: string; - borderStyle: string; - borderTop: string; - borderTopColor: string; - borderTopLeftRadius: string; - borderTopRightRadius: string; - borderTopStyle: string; - borderTopWidth: string; - borderWidth: string; - bottom: string; - boxShadow: string; - boxSizing: string; - breakAfter: string; - breakBefore: string; - breakInside: string; - captionSide: string; - clear: string; - clip: string; - clipPath: string; - clipRule: string; - color: string; - colorInterpolationFilters: string; + alignContent: string | null; + alignItems: string | null; + alignSelf: string | null; + alignmentBaseline: string | null; + animation: string | null; + animationDelay: string | null; + animationDirection: string | null; + animationDuration: string | null; + animationFillMode: string | null; + animationIterationCount: string | null; + animationName: string | null; + animationPlayState: string | null; + animationTimingFunction: string | null; + backfaceVisibility: string | null; + background: string | null; + backgroundAttachment: string | null; + backgroundClip: string | null; + backgroundColor: string | null; + backgroundImage: string | null; + backgroundOrigin: string | null; + backgroundPosition: string | null; + backgroundPositionX: string | null; + backgroundPositionY: string | null; + backgroundRepeat: string | null; + backgroundSize: string | null; + baselineShift: string | null; + border: string | null; + borderBottom: string | null; + borderBottomColor: string | null; + borderBottomLeftRadius: string | null; + borderBottomRightRadius: string | null; + borderBottomStyle: string | null; + borderBottomWidth: string | null; + borderCollapse: string | null; + borderColor: string | null; + borderImage: string | null; + borderImageOutset: string | null; + borderImageRepeat: string | null; + borderImageSlice: string | null; + borderImageSource: string | null; + borderImageWidth: string | null; + borderLeft: string | null; + borderLeftColor: string | null; + borderLeftStyle: string | null; + borderLeftWidth: string | null; + borderRadius: string | null; + borderRight: string | null; + borderRightColor: string | null; + borderRightStyle: string | null; + borderRightWidth: string | null; + borderSpacing: string | null; + borderStyle: string | null; + borderTop: string | null; + borderTopColor: string | null; + borderTopLeftRadius: string | null; + borderTopRightRadius: string | null; + borderTopStyle: string | null; + borderTopWidth: string | null; + borderWidth: string | null; + bottom: string | null; + boxShadow: string | null; + boxSizing: string | null; + breakAfter: string | null; + breakBefore: string | null; + breakInside: string | null; + captionSide: string | null; + clear: string | null; + clip: string | null; + clipPath: string | null; + clipRule: string | null; + color: string | null; + colorInterpolationFilters: string | null; columnCount: any; - columnFill: string; + columnFill: string | null; columnGap: any; - columnRule: string; + columnRule: string | null; columnRuleColor: any; - columnRuleStyle: string; + columnRuleStyle: string | null; columnRuleWidth: any; - columnSpan: string; + columnSpan: string | null; columnWidth: any; - columns: string; - content: string; - counterIncrement: string; - counterReset: string; - cssFloat: string; + columns: string | null; + content: string | null; + counterIncrement: string | null; + counterReset: string | null; + cssFloat: string | null; cssText: string; - cursor: string; - direction: string; - display: string; - dominantBaseline: string; - emptyCells: string; - enableBackground: string; - fill: string; - fillOpacity: string; - fillRule: string; - filter: string; - flex: string; - flexBasis: string; - flexDirection: string; - flexFlow: string; - flexGrow: string; - flexShrink: string; - flexWrap: string; - floodColor: string; - floodOpacity: string; - font: string; - fontFamily: string; - fontFeatureSettings: string; - fontSize: string; - fontSizeAdjust: string; - fontStretch: string; - fontStyle: string; - fontVariant: string; - fontWeight: string; - glyphOrientationHorizontal: string; - glyphOrientationVertical: string; - height: string; - imeMode: string; - justifyContent: string; - kerning: string; - left: string; + cursor: string | null; + direction: string | null; + display: string | null; + dominantBaseline: string | null; + emptyCells: string | null; + enableBackground: string | null; + fill: string | null; + fillOpacity: string | null; + fillRule: string | null; + filter: string | null; + flex: string | null; + flexBasis: string | null; + flexDirection: string | null; + flexFlow: string | null; + flexGrow: string | null; + flexShrink: string | null; + flexWrap: string | null; + floodColor: string | null; + floodOpacity: string | null; + font: string | null; + fontFamily: string | null; + fontFeatureSettings: string | null; + fontSize: string | null; + fontSizeAdjust: string | null; + fontStretch: string | null; + fontStyle: string | null; + fontVariant: string | null; + fontWeight: string | null; + glyphOrientationHorizontal: string | null; + glyphOrientationVertical: string | null; + height: string | null; + imeMode: string | null; + justifyContent: string | null; + kerning: string | null; + left: string | null; readonly length: number; - letterSpacing: string; - lightingColor: string; - lineHeight: string; - listStyle: string; - listStyleImage: string; - listStylePosition: string; - listStyleType: string; - margin: string; - marginBottom: string; - marginLeft: string; - marginRight: string; - marginTop: string; - marker: string; - markerEnd: string; - markerMid: string; - markerStart: string; - mask: string; - maxHeight: string; - maxWidth: string; - minHeight: string; - minWidth: string; - msContentZoomChaining: string; - msContentZoomLimit: string; + letterSpacing: string | null; + lightingColor: string | null; + lineHeight: string | null; + listStyle: string | null; + listStyleImage: string | null; + listStylePosition: string | null; + listStyleType: string | null; + margin: string | null; + marginBottom: string | null; + marginLeft: string | null; + marginRight: string | null; + marginTop: string | null; + marker: string | null; + markerEnd: string | null; + markerMid: string | null; + markerStart: string | null; + mask: string | null; + maxHeight: string | null; + maxWidth: string | null; + minHeight: string | null; + minWidth: string | null; + msContentZoomChaining: string | null; + msContentZoomLimit: string | null; msContentZoomLimitMax: any; msContentZoomLimitMin: any; - msContentZoomSnap: string; - msContentZoomSnapPoints: string; - msContentZoomSnapType: string; - msContentZooming: string; - msFlowFrom: string; - msFlowInto: string; - msFontFeatureSettings: string; + msContentZoomSnap: string | null; + msContentZoomSnapPoints: string | null; + msContentZoomSnapType: string | null; + msContentZooming: string | null; + msFlowFrom: string | null; + msFlowInto: string | null; + msFontFeatureSettings: string | null; msGridColumn: any; - msGridColumnAlign: string; + msGridColumnAlign: string | null; msGridColumnSpan: any; - msGridColumns: string; + msGridColumns: string | null; msGridRow: any; - msGridRowAlign: string; + msGridRowAlign: string | null; msGridRowSpan: any; - msGridRows: string; - msHighContrastAdjust: string; - msHyphenateLimitChars: string; + msGridRows: string | null; + msHighContrastAdjust: string | null; + msHyphenateLimitChars: string | null; msHyphenateLimitLines: any; msHyphenateLimitZone: any; - msHyphens: string; - msImeAlign: string; - msOverflowStyle: string; - msScrollChaining: string; - msScrollLimit: string; + msHyphens: string | null; + msImeAlign: string | null; + msOverflowStyle: string | null; + msScrollChaining: string | null; + msScrollLimit: string | null; msScrollLimitXMax: any; msScrollLimitXMin: any; msScrollLimitYMax: any; msScrollLimitYMin: any; - msScrollRails: string; - msScrollSnapPointsX: string; - msScrollSnapPointsY: string; - msScrollSnapType: string; - msScrollSnapX: string; - msScrollSnapY: string; - msScrollTranslation: string; - msTextCombineHorizontal: string; + msScrollRails: string | null; + msScrollSnapPointsX: string | null; + msScrollSnapPointsY: string | null; + msScrollSnapType: string | null; + msScrollSnapX: string | null; + msScrollSnapY: string | null; + msScrollTranslation: string | null; + msTextCombineHorizontal: string | null; msTextSizeAdjust: any; - msTouchAction: string; - msTouchSelect: string; - msUserSelect: string; + msTouchAction: string | null; + msTouchSelect: string | null; + msUserSelect: string | null; msWrapFlow: string; msWrapMargin: any; msWrapThrough: string; - opacity: string; - order: string; - orphans: string; - outline: string; - outlineColor: string; - outlineStyle: string; - outlineWidth: string; - overflow: string; - overflowX: string; - overflowY: string; - padding: string; - paddingBottom: string; - paddingLeft: string; - paddingRight: string; - paddingTop: string; - pageBreakAfter: string; - pageBreakBefore: string; - pageBreakInside: string; + opacity: string | null; + order: string | null; + orphans: string | null; + outline: string | null; + outlineColor: string | null; + outlineStyle: string | null; + outlineWidth: string | null; + overflow: string | null; + overflowX: string | null; + overflowY: string | null; + padding: string | null; + paddingBottom: string | null; + paddingLeft: string | null; + paddingRight: string | null; + paddingTop: string | null; + pageBreakAfter: string | null; + pageBreakBefore: string | null; + pageBreakInside: string | null; readonly parentRule: CSSRule; - perspective: string; - perspectiveOrigin: string; - pointerEvents: string; - position: string; - quotes: string; - right: string; - rubyAlign: string; - rubyOverhang: string; - rubyPosition: string; - stopColor: string; - stopOpacity: string; - stroke: string; - strokeDasharray: string; - strokeDashoffset: string; - strokeLinecap: string; - strokeLinejoin: string; - strokeMiterlimit: string; - strokeOpacity: string; - strokeWidth: string; - tableLayout: string; - textAlign: string; - textAlignLast: string; - textAnchor: string; - textDecoration: string; - textIndent: string; - textJustify: string; - textKashida: string; - textKashidaSpace: string; - textOverflow: string; - textShadow: string; - textTransform: string; - textUnderlinePosition: string; - top: string; - touchAction: string; - transform: string; - transformOrigin: string; - transformStyle: string; - transition: string; - transitionDelay: string; - transitionDuration: string; - transitionProperty: string; - transitionTimingFunction: string; - unicodeBidi: string; - verticalAlign: string; - visibility: string; - webkitAlignContent: string; - webkitAlignItems: string; - webkitAlignSelf: string; - webkitAnimation: string; - webkitAnimationDelay: string; - webkitAnimationDirection: string; - webkitAnimationDuration: string; - webkitAnimationFillMode: string; - webkitAnimationIterationCount: string; - webkitAnimationName: string; - webkitAnimationPlayState: string; - webkitAnimationTimingFunction: string; - webkitAppearance: string; - webkitBackfaceVisibility: string; - webkitBackgroundClip: string; - webkitBackgroundOrigin: string; - webkitBackgroundSize: string; - webkitBorderBottomLeftRadius: string; - webkitBorderBottomRightRadius: string; - webkitBorderImage: string; - webkitBorderRadius: string; - webkitBorderTopLeftRadius: string; - webkitBorderTopRightRadius: string; - webkitBoxAlign: string; - webkitBoxDirection: string; - webkitBoxFlex: string; - webkitBoxOrdinalGroup: string; - webkitBoxOrient: string; - webkitBoxPack: string; - webkitBoxSizing: string; - webkitColumnBreakAfter: string; - webkitColumnBreakBefore: string; - webkitColumnBreakInside: string; + perspective: string | null; + perspectiveOrigin: string | null; + pointerEvents: string | null; + position: string | null; + quotes: string | null; + right: string | null; + rubyAlign: string | null; + rubyOverhang: string | null; + rubyPosition: string | null; + stopColor: string | null; + stopOpacity: string | null; + stroke: string | null; + strokeDasharray: string | null; + strokeDashoffset: string | null; + strokeLinecap: string | null; + strokeLinejoin: string | null; + strokeMiterlimit: string | null; + strokeOpacity: string | null; + strokeWidth: string | null; + tableLayout: string | null; + textAlign: string | null; + textAlignLast: string | null; + textAnchor: string | null; + textDecoration: string | null; + textIndent: string | null; + textJustify: string | null; + textKashida: string | null; + textKashidaSpace: string | null; + textOverflow: string | null; + textShadow: string | null; + textTransform: string | null; + textUnderlinePosition: string | null; + top: string | null; + touchAction: string | null; + transform: string | null; + transformOrigin: string | null; + transformStyle: string | null; + transition: string | null; + transitionDelay: string | null; + transitionDuration: string | null; + transitionProperty: string | null; + transitionTimingFunction: string | null; + unicodeBidi: string | null; + verticalAlign: string | null; + visibility: string | null; + webkitAlignContent: string | null; + webkitAlignItems: string | null; + webkitAlignSelf: string | null; + webkitAnimation: string | null; + webkitAnimationDelay: string | null; + webkitAnimationDirection: string | null; + webkitAnimationDuration: string | null; + webkitAnimationFillMode: string | null; + webkitAnimationIterationCount: string | null; + webkitAnimationName: string | null; + webkitAnimationPlayState: string | null; + webkitAnimationTimingFunction: string | null; + webkitAppearance: string | null; + webkitBackfaceVisibility: string | null; + webkitBackgroundClip: string | null; + webkitBackgroundOrigin: string | null; + webkitBackgroundSize: string | null; + webkitBorderBottomLeftRadius: string | null; + webkitBorderBottomRightRadius: string | null; + webkitBorderImage: string | null; + webkitBorderRadius: string | null; + webkitBorderTopLeftRadius: string | null; + webkitBorderTopRightRadius: string | null; + webkitBoxAlign: string | null; + webkitBoxDirection: string | null; + webkitBoxFlex: string | null; + webkitBoxOrdinalGroup: string | null; + webkitBoxOrient: string | null; + webkitBoxPack: string | null; + webkitBoxSizing: string | null; + webkitColumnBreakAfter: string | null; + webkitColumnBreakBefore: string | null; + webkitColumnBreakInside: string | null; webkitColumnCount: any; webkitColumnGap: any; - webkitColumnRule: string; + webkitColumnRule: string | null; webkitColumnRuleColor: any; - webkitColumnRuleStyle: string; + webkitColumnRuleStyle: string | null; webkitColumnRuleWidth: any; - webkitColumnSpan: string; + webkitColumnSpan: string | null; webkitColumnWidth: any; - webkitColumns: string; - webkitFilter: string; - webkitFlex: string; - webkitFlexBasis: string; - webkitFlexDirection: string; - webkitFlexFlow: string; - webkitFlexGrow: string; - webkitFlexShrink: string; - webkitFlexWrap: string; - webkitJustifyContent: string; - webkitOrder: string; - webkitPerspective: string; - webkitPerspectiveOrigin: string; - webkitTapHighlightColor: string; - webkitTextFillColor: string; + webkitColumns: string | null; + webkitFilter: string | null; + webkitFlex: string | null; + webkitFlexBasis: string | null; + webkitFlexDirection: string | null; + webkitFlexFlow: string | null; + webkitFlexGrow: string | null; + webkitFlexShrink: string | null; + webkitFlexWrap: string | null; + webkitJustifyContent: string | null; + webkitOrder: string | null; + webkitPerspective: string | null; + webkitPerspectiveOrigin: string | null; + webkitTapHighlightColor: string | null; + webkitTextFillColor: string | null; webkitTextSizeAdjust: any; - webkitTransform: string; - webkitTransformOrigin: string; - webkitTransformStyle: string; - webkitTransition: string; - webkitTransitionDelay: string; - webkitTransitionDuration: string; - webkitTransitionProperty: string; - webkitTransitionTimingFunction: string; - webkitUserModify: string; - webkitUserSelect: string; - webkitWritingMode: string; - whiteSpace: string; - widows: string; - width: string; - wordBreak: string; - wordSpacing: string; - wordWrap: string; - writingMode: string; - zIndex: string; - zoom: string; + webkitTransform: string | null; + webkitTransformOrigin: string | null; + webkitTransformStyle: string | null; + webkitTransition: string | null; + webkitTransitionDelay: string | null; + webkitTransitionDuration: string | null; + webkitTransitionProperty: string | null; + webkitTransitionTimingFunction: string | null; + webkitUserModify: string | null; + webkitUserSelect: string | null; + webkitWritingMode: string | null; + whiteSpace: string | null; + widows: string | null; + width: string | null; + wordBreak: string | null; + wordSpacing: string | null; + wordWrap: string | null; + writingMode: string | null; + zIndex: string | null; + zoom: string | null; getPropertyPriority(propertyName: string): string; getPropertyValue(propertyName: string): string; item(index: number): string; removeProperty(propertyName: string): string; - setProperty(propertyName: string, value: string, priority?: string): void; + setProperty(propertyName: string, value: string | null, priority?: string): void; [index: number]: string; } @@ -1772,6 +1773,9 @@ interface CanvasRenderingContext2D extends Object, CanvasPathMethods { strokeStyle: string | CanvasGradient | CanvasPattern; textAlign: string; textBaseline: string; + mozImageSmoothingEnabled: boolean; + webkitImageSmoothingEnabled: boolean; + oImageSmoothingEnabled: boolean; beginPath(): void; clearRect(x: number, y: number, w: number, h: number): void; clip(fillRule?: string): void; @@ -1886,7 +1890,7 @@ declare var CloseEvent: { interface CommandEvent extends Event { readonly commandName: string; - readonly detail: string; + readonly detail: string | null; } declare var CommandEvent: { @@ -1945,7 +1949,7 @@ declare var Console: { } interface ConvolverNode extends AudioNode { - buffer: AudioBuffer; + buffer: AudioBuffer | null; normalize: boolean; } @@ -1956,12 +1960,12 @@ declare var ConvolverNode: { interface Coordinates { readonly accuracy: number; - readonly altitude: number; - readonly altitudeAccuracy: number; - readonly heading: number; + readonly altitude: number | null; + readonly altitudeAccuracy: number | null; + readonly heading: number | null; readonly latitude: number; readonly longitude: number; - readonly speed: number; + readonly speed: number | null; } declare var Coordinates: { @@ -2087,10 +2091,10 @@ declare var DOMException: { } interface DOMImplementation { - createDocument(namespaceURI: string, qualifiedName: string, doctype: DocumentType): Document; - createDocumentType(qualifiedName: string, publicId: string, systemId: string): DocumentType; + createDocument(namespaceURI: string | null, qualifiedName: string | null, doctype: DocumentType): Document; + createDocumentType(qualifiedName: string, publicId: string | null, systemId: string | null): DocumentType; createHTMLDocument(title: string): Document; - hasFeature(feature: string, version: string): boolean; + hasFeature(feature: string | null, version: string | null): boolean; } declare var DOMImplementation: { @@ -2119,7 +2123,7 @@ declare var DOMSettableTokenList: { interface DOMStringList { readonly length: number; contains(str: string): boolean; - item(index: number): string; + item(index: number): string | null; [index: number]: string; } @@ -2181,8 +2185,8 @@ declare var DataTransfer: { interface DataTransferItem { readonly kind: string; readonly type: string; - getAsFile(): File; - getAsString(_callback: FunctionStringCallback): void; + getAsFile(): File | null; + getAsString(_callback: FunctionStringCallback | null): void; } declare var DataTransferItem: { @@ -2192,7 +2196,7 @@ declare var DataTransferItem: { interface DataTransferItemList { readonly length: number; - add(data: File): DataTransferItem; + add(data: File): DataTransferItem | null; clear(): void; item(index: number): DataTransferItem; remove(index: number): void; @@ -2227,9 +2231,9 @@ declare var DelayNode: { } interface DeviceAcceleration { - readonly x: number; - readonly y: number; - readonly z: number; + readonly x: number | null; + readonly y: number | null; + readonly z: number | null; } declare var DeviceAcceleration: { @@ -2247,11 +2251,11 @@ declare var DeviceLightEvent: { } interface DeviceMotionEvent extends Event { - readonly acceleration: DeviceAcceleration; - readonly accelerationIncludingGravity: DeviceAcceleration; - readonly interval: number; - readonly rotationRate: DeviceRotationRate; - initDeviceMotionEvent(type: string, bubbles: boolean, cancelable: boolean, acceleration: DeviceAccelerationDict, accelerationIncludingGravity: DeviceAccelerationDict, rotationRate: DeviceRotationRateDict, interval: number): void; + readonly acceleration: DeviceAcceleration | null; + readonly accelerationIncludingGravity: DeviceAcceleration | null; + readonly interval: number | null; + readonly rotationRate: DeviceRotationRate | null; + initDeviceMotionEvent(type: string, bubbles: boolean, cancelable: boolean, acceleration: DeviceAccelerationDict | null, accelerationIncludingGravity: DeviceAccelerationDict | null, rotationRate: DeviceRotationRateDict | null, interval: number | null): void; } declare var DeviceMotionEvent: { @@ -2261,10 +2265,10 @@ declare var DeviceMotionEvent: { interface DeviceOrientationEvent extends Event { readonly absolute: boolean; - readonly alpha: number; - readonly beta: number; - readonly gamma: number; - initDeviceOrientationEvent(type: string, bubbles: boolean, cancelable: boolean, alpha: number, beta: number, gamma: number, absolute: boolean): void; + readonly alpha: number | null; + readonly beta: number | null; + readonly gamma: number | null; + initDeviceOrientationEvent(type: string, bubbles: boolean, cancelable: boolean, alpha: number | null, beta: number | null, gamma: number | null, absolute: boolean): void; } declare var DeviceOrientationEvent: { @@ -2273,9 +2277,9 @@ declare var DeviceOrientationEvent: { } interface DeviceRotationRate { - readonly alpha: number; - readonly beta: number; - readonly gamma: number; + readonly alpha: number | null; + readonly beta: number | null; + readonly gamma: number | null; } declare var DeviceRotationRate: { @@ -2368,7 +2372,7 @@ interface Document extends Node, GlobalEventHandlers, NodeSelector, DocumentEven * Retrieves a collection, in source order, of all form objects in the document. */ forms: HTMLCollectionOf; - readonly fullscreenElement: Element; + readonly fullscreenElement: Element | null; readonly fullscreenEnabled: boolean; readonly head: HTMLHeadElement; readonly hidden: boolean; @@ -2383,7 +2387,7 @@ interface Document extends Node, GlobalEventHandlers, NodeSelector, DocumentEven /** * Returns the character encoding used to create the webpage that is loaded into the document object. */ - readonly inputEncoding: string; + readonly inputEncoding: string | null; /** * Gets the date that the page was last modified, if the page supplies one. */ @@ -2728,7 +2732,7 @@ interface Document extends Node, GlobalEventHandlers, NodeSelector, DocumentEven * Retrieves a collection of all script objects in the document. */ scripts: HTMLCollectionOf; - readonly scrollingElement: Element; + readonly scrollingElement: Element | null; /** * Retrieves a collection of styleSheet objects representing the style sheets that correspond to each instance of a link or style object in the document. */ @@ -2742,16 +2746,16 @@ interface Document extends Node, GlobalEventHandlers, NodeSelector, DocumentEven * Sets or gets the color of the links that the user has visited. */ vlinkColor: string; - readonly webkitCurrentFullScreenElement: Element; - readonly webkitFullscreenElement: Element; + readonly webkitCurrentFullScreenElement: Element | null; + readonly webkitFullscreenElement: Element | null; readonly webkitFullscreenEnabled: boolean; readonly webkitIsFullScreen: boolean; - readonly xmlEncoding: string; + readonly xmlEncoding: string | null; xmlStandalone: boolean; /** * Gets or sets the version attribute specified in the declaration of an XML document. */ - xmlVersion: string; + xmlVersion: string | null; adoptNode(source: Node): Node; captureEvents(): void; caretRangeFromPoint(x: number, y: number): Range; @@ -2765,7 +2769,7 @@ interface Document extends Node, GlobalEventHandlers, NodeSelector, DocumentEven * @param name String that sets the attribute object's name. */ createAttribute(name: string): Attr; - createAttributeNS(namespaceURI: string, qualifiedName: string): Attr; + createAttributeNS(namespaceURI: string | null, qualifiedName: string): Attr; createCDATASection(data: string): CDATASection; /** * Creates a comment object with the specified data. @@ -2861,6 +2865,7 @@ interface Document extends Node, GlobalEventHandlers, NodeSelector, DocumentEven createElement(tagName: "x-ms-webview"): MSHTMLWebViewElement; createElement(tagName: "xmp"): HTMLPreElement; createElement(tagName: string): HTMLElement; + createElementNS(namespaceURI: "http://www.w3.org/1999/xhtml", qualifiedName: string): HTMLElement createElementNS(namespaceURI: "http://www.w3.org/2000/svg", qualifiedName: "a"): SVGAElement createElementNS(namespaceURI: "http://www.w3.org/2000/svg", qualifiedName: "circle"): SVGCircleElement createElementNS(namespaceURI: "http://www.w3.org/2000/svg", qualifiedName: "clipPath"): SVGClipPathElement @@ -2923,7 +2928,7 @@ interface Document extends Node, GlobalEventHandlers, NodeSelector, DocumentEven createElementNS(namespaceURI: "http://www.w3.org/2000/svg", qualifiedName: "use"): SVGUseElement createElementNS(namespaceURI: "http://www.w3.org/2000/svg", qualifiedName: "view"): SVGViewElement createElementNS(namespaceURI: "http://www.w3.org/2000/svg", qualifiedName: string): SVGElement - createElementNS(namespaceURI: string, qualifiedName: string): Element; + createElementNS(namespaceURI: string | null, qualifiedName: string): Element; createExpression(expression: string, resolver: XPathNSResolver): XPathExpression; createNSResolver(nodeResolver: Node): XPathNSResolver; /** @@ -2984,12 +2989,12 @@ interface Document extends Node, GlobalEventHandlers, NodeSelector, DocumentEven * @param elementId String that specifies the ID value. Case-insensitive. */ getElementById(elementId: string): HTMLElement; - getElementsByClassName(classNames: string): NodeListOf; + getElementsByClassName(classNames: string): HTMLCollectionOf; /** * Gets a collection of objects based on the value of the NAME or ID attribute. * @param elementName Gets a collection of objects based on the value of the NAME or ID attribute. */ - getElementsByName(elementName: string): NodeListOf; + getElementsByName(elementName: string): NodeListOf; /** * Retrieves a collection of objects based on the specified element name. * @param name Specifies the name of an element. @@ -3171,7 +3176,9 @@ interface Document extends Node, GlobalEventHandlers, NodeSelector, DocumentEven getElementsByTagName(tagname: "x-ms-webview"): NodeListOf; getElementsByTagName(tagname: "xmp"): NodeListOf; getElementsByTagName(tagname: string): NodeListOf; - getElementsByTagNameNS(namespaceURI: string, localName: string): NodeListOf; + getElementsByTagNameNS(namespaceURI: "http://www.w3.org/1999/xhtml", localName: string): HTMLCollectionOf; + getElementsByTagNameNS(namespaceURI: "http://www.w3.org/2000/svg", localName: string): HTMLCollectionOf; + getElementsByTagNameNS(namespaceURI: string, localName: string): HTMLCollectionOf; /** * Returns an object representing the current selection of the document that is loaded into the object displaying a webpage. */ @@ -3238,8 +3245,6 @@ interface Document extends Node, GlobalEventHandlers, NodeSelector, DocumentEven * @param content The text and HTML tags to write. */ writeln(...content: string[]): void; - createElement(tagName: "picture"): HTMLPictureElement; - getElementsByTagName(tagname: "picture"): NodeListOf; addEventListener(type: "MSContentZoom", listener: (ev: UIEvent) => any, useCapture?: boolean): void; addEventListener(type: "MSGestureChange", listener: (ev: MSGestureEvent) => any, useCapture?: boolean): void; addEventListener(type: "MSGestureDoubleTap", listener: (ev: MSGestureEvent) => any, useCapture?: boolean): void; @@ -3356,11 +3361,11 @@ declare var DocumentFragment: { interface DocumentType extends Node, ChildNode { readonly entities: NamedNodeMap; - readonly internalSubset: string; + readonly internalSubset: string | null; readonly name: string; readonly notations: NamedNodeMap; - readonly publicId: string; - readonly systemId: string; + readonly publicId: string | null; + readonly systemId: string | null; addEventListener(type: string, listener: EventListenerOrEventListenerObject, useCapture?: boolean): void; } @@ -3451,14 +3456,14 @@ interface Element extends Node, GlobalEventHandlers, ElementTraversal, NodeSelec ontouchstart: (ev: TouchEvent) => any; onwebkitfullscreenchange: (ev: Event) => any; onwebkitfullscreenerror: (ev: Event) => any; - readonly prefix: string; + readonly prefix: string | null; readonly scrollHeight: number; scrollLeft: number; scrollTop: number; readonly scrollWidth: number; readonly tagName: string; innerHTML: string; - getAttribute(name?: string): string; + getAttribute(name?: string): string | null; getAttributeNS(namespaceURI: string, localName: string): string; getAttributeNode(name: string): Attr; getAttributeNodeNS(namespaceURI: string, localName: string): Attr; @@ -3641,7 +3646,9 @@ interface Element extends Node, GlobalEventHandlers, ElementTraversal, NodeSelec getElementsByTagName(name: "x-ms-webview"): NodeListOf; getElementsByTagName(name: "xmp"): NodeListOf; getElementsByTagName(name: string): NodeListOf; - getElementsByTagNameNS(namespaceURI: string, localName: string): NodeListOf; + getElementsByTagNameNS(namespaceURI: "http://www.w3.org/1999/xhtml", localName: string): HTMLCollectionOf; + getElementsByTagNameNS(namespaceURI: "http://www.w3.org/2000/svg", localName: string): HTMLCollectionOf; + getElementsByTagNameNS(namespaceURI: string, localName: string): HTMLCollectionOf; hasAttribute(name: string): boolean; hasAttributeNS(namespaceURI: string, localName: string): boolean; msGetRegionContent(): MSRangeCollection; @@ -3666,7 +3673,6 @@ interface Element extends Node, GlobalEventHandlers, ElementTraversal, NodeSelec webkitRequestFullscreen(): void; getElementsByClassName(classNames: string): NodeListOf; matches(selector: string): boolean; - getElementsByTagName(tagname: "picture"): NodeListOf; addEventListener(type: "MSGestureChange", listener: (ev: MSGestureEvent) => any, useCapture?: boolean): void; addEventListener(type: "MSGestureDoubleTap", listener: (ev: MSGestureEvent) => any, useCapture?: boolean): void; addEventListener(type: "MSGestureEnd", listener: (ev: MSGestureEvent) => any, useCapture?: boolean): void; @@ -3734,7 +3740,7 @@ interface Event { readonly eventPhase: number; readonly isTrusted: boolean; returnValue: boolean; - readonly srcElement: Element; + readonly srcElement: Element | null; readonly target: EventTarget; readonly timeStamp: number; readonly type: string; @@ -4029,7 +4035,7 @@ interface HTMLAppletElement extends HTMLElement { * Sets or retrieves the shape of the object. */ name: string; - object: string; + object: string | null; /** * Sets or retrieves a message to be displayed while an object is loading. */ @@ -6084,7 +6090,7 @@ interface HTMLMediaElement extends HTMLElement { * Gets or sets a flag to specify whether playback should restart after it completes. */ loop: boolean; - readonly mediaKeys: MediaKeys; + readonly mediaKeys: MediaKeys | null; /** * Specifies the purpose of the audio or video media, such as background audio or alerts. */ @@ -6157,7 +6163,7 @@ interface HTMLMediaElement extends HTMLElement { * The address or URL of the a media resource that is to be considered. */ src: string; - srcObject: MediaStream; + srcObject: MediaStream | null; readonly textTracks: TextTrackList; readonly videoTracks: VideoTrackList; /** @@ -6195,7 +6201,7 @@ interface HTMLMediaElement extends HTMLElement { * Loads and starts playback of a media resource. */ play(): void; - setMediaKeys(mediaKeys: MediaKeys): PromiseLike; + setMediaKeys(mediaKeys: MediaKeys | null): PromiseLike; readonly HAVE_CURRENT_DATA: number; readonly HAVE_ENOUGH_DATA: number; readonly HAVE_FUTURE_DATA: number; @@ -7507,8 +7513,8 @@ declare var HTMLVideoElement: { } interface HashChangeEvent extends Event { - readonly newURL: string; - readonly oldURL: string; + readonly newURL: string | null; + readonly oldURL: string | null; } declare var HashChangeEvent: { @@ -7714,7 +7720,7 @@ declare var IDBTransaction: { } interface IDBVersionChangeEvent extends Event { - readonly newVersion: number; + readonly newVersion: number | null; readonly oldVersion: number; } @@ -7737,7 +7743,7 @@ declare var ImageData: { interface KeyboardEvent extends UIEvent { readonly altKey: boolean; - readonly char: string; + readonly char: string | null; readonly charCode: number; readonly ctrlKey: boolean; readonly key: string; @@ -8080,7 +8086,7 @@ declare var MSMediaKeyError: { } interface MSMediaKeyMessageEvent extends Event { - readonly destinationURL: string; + readonly destinationURL: string | null; readonly message: Uint8Array; } @@ -8090,7 +8096,7 @@ declare var MSMediaKeyMessageEvent: { } interface MSMediaKeyNeededEvent extends Event { - readonly initData: Uint8Array; + readonly initData: Uint8Array | null; } declare var MSMediaKeyNeededEvent: { @@ -8099,7 +8105,7 @@ declare var MSMediaKeyNeededEvent: { } interface MSMediaKeySession extends EventTarget { - readonly error: MSMediaKeyError; + readonly error: MSMediaKeyError | null; readonly keySystem: string; readonly sessionId: string; close(): void; @@ -8269,7 +8275,7 @@ declare var MediaElementAudioSourceNode: { } interface MediaEncryptedEvent extends Event { - readonly initData: ArrayBuffer; + readonly initData: ArrayBuffer | null; readonly initDataType: string; } @@ -8411,7 +8417,7 @@ interface MediaStream extends EventTarget { addTrack(track: MediaStreamTrack): void; clone(): MediaStream; getAudioTracks(): MediaStreamTrack[]; - getTrackById(trackId: string): MediaStreamTrack; + getTrackById(trackId: string): MediaStreamTrack | null; getTracks(): MediaStreamTrack[]; getVideoTracks(): MediaStreamTrack[]; removeTrack(track: MediaStreamTrack): void; @@ -8437,8 +8443,8 @@ declare var MediaStreamAudioSourceNode: { } interface MediaStreamError { - readonly constraintName: string; - readonly message: string; + readonly constraintName: string | null; + readonly message: string | null; readonly name: string; } @@ -8448,7 +8454,7 @@ declare var MediaStreamError: { } interface MediaStreamErrorEvent extends Event { - readonly error: MediaStreamError; + readonly error: MediaStreamError | null; } declare var MediaStreamErrorEvent: { @@ -8624,11 +8630,11 @@ declare var MutationObserver: { interface MutationRecord { readonly addedNodes: NodeList; - readonly attributeName: string; - readonly attributeNamespace: string; - readonly nextSibling: Node; - readonly oldValue: string; - readonly previousSibling: Node; + readonly attributeName: string | null; + readonly attributeNamespace: string | null; + readonly nextSibling: Node | null; + readonly oldValue: string | null; + readonly previousSibling: Node | null; readonly removedNodes: NodeList; readonly target: Node; readonly type: string; @@ -8642,10 +8648,10 @@ declare var MutationRecord: { interface NamedNodeMap { readonly length: number; getNamedItem(name: string): Attr; - getNamedItemNS(namespaceURI: string, localName: string): Attr; + getNamedItemNS(namespaceURI: string | null, localName: string | null): Attr; item(index: number): Attr; removeNamedItem(name: string): Attr; - removeNamedItemNS(namespaceURI: string, localName: string): Attr; + removeNamedItemNS(namespaceURI: string | null, localName: string | null): Attr; setNamedItem(arg: Attr): Attr; setNamedItemNS(arg: Attr): Attr; [index: number]: Attr; @@ -8711,33 +8717,33 @@ declare var Navigator: { interface Node extends EventTarget { readonly attributes: NamedNodeMap; - readonly baseURI: string; + readonly baseURI: string | null; readonly childNodes: NodeList; readonly firstChild: Node; readonly lastChild: Node; - readonly localName: string; - readonly namespaceURI: string; + readonly localName: string | null; + readonly namespaceURI: string | null; readonly nextSibling: Node; readonly nodeName: string; readonly nodeType: number; - nodeValue: string; + nodeValue: string | null; readonly ownerDocument: Document; readonly parentElement: HTMLElement; readonly parentNode: Node; readonly previousSibling: Node; - textContent: string; + textContent: string | null; appendChild(newChild: Node): Node; cloneNode(deep?: boolean): Node; compareDocumentPosition(other: Node): number; contains(child: Node): boolean; hasAttributes(): boolean; hasChildNodes(): boolean; - insertBefore(newChild: Node, refChild?: Node): Node; - isDefaultNamespace(namespaceURI: string): boolean; + insertBefore(newChild: Node, refChild: Node): Node; + isDefaultNamespace(namespaceURI: string | null): boolean; isEqualNode(arg: Node): boolean; isSameNode(other: Node): boolean; - lookupNamespaceURI(prefix: string): string; - lookupPrefix(namespaceURI: string): string; + lookupNamespaceURI(prefix: string | null): string | null; + lookupPrefix(namespaceURI: string | null): string | null; normalize(): void; removeChild(oldChild: Node): Node; replaceChild(newChild: Node, oldChild: Node): Node; @@ -8966,10 +8972,10 @@ interface PerfWidgetExternal { addEventListener(eventType: string, callback: Function): void; getMemoryUsage(): number; getProcessCpuUsage(): number; - getRecentCpuUsage(last: number): any; - getRecentFrames(last: number): any; - getRecentMemoryUsage(last: number): any; - getRecentPaintRequests(last: number): any; + getRecentCpuUsage(last: number | null): any; + getRecentFrames(last: number | null): any; + getRecentMemoryUsage(last: number | null): any; + getRecentPaintRequests(last: number | null): any; removeEventListener(eventType: string, callback: Function): void; repositionWindow(x: number, y: number): void; resizeWindow(width: number, height: number): void; @@ -9276,13 +9282,13 @@ declare var RTCDTMFToneChangeEvent: { } interface RTCDtlsTransport extends RTCStatsProvider { - ondtlsstatechange: (ev: RTCDtlsTransportStateChangedEvent) => any; - onerror: (ev: Event) => any; + ondtlsstatechange: ((ev: RTCDtlsTransportStateChangedEvent) => any) | null; + onerror: ((ev: Event) => any) | null; readonly state: string; readonly transport: RTCIceTransport; getLocalParameters(): RTCDtlsParameters; getRemoteCertificates(): ArrayBuffer[]; - getRemoteParameters(): RTCDtlsParameters; + getRemoteParameters(): RTCDtlsParameters | null; start(remoteParameters: RTCDtlsParameters): void; stop(): void; addEventListener(type: "dtlsstatechange", listener: (ev: RTCDtlsTransportStateChangedEvent) => any, useCapture?: boolean): void; @@ -9332,8 +9338,8 @@ declare var RTCIceCandidatePairChangedEvent: { interface RTCIceGatherer extends RTCStatsProvider { readonly component: string; - onerror: (ev: Event) => any; - onlocalcandidate: (ev: RTCIceGathererEvent) => any; + onerror: ((ev: Event) => any) | null; + onlocalcandidate: ((ev: RTCIceGathererEvent) => any) | null; createAssociatedGatherer(): RTCIceGatherer; getLocalCandidates(): RTCIceCandidate[]; getLocalParameters(): RTCIceParameters; @@ -9358,16 +9364,16 @@ declare var RTCIceGathererEvent: { interface RTCIceTransport extends RTCStatsProvider { readonly component: string; - readonly iceGatherer: RTCIceGatherer; - oncandidatepairchange: (ev: RTCIceCandidatePairChangedEvent) => any; - onicestatechange: (ev: RTCIceTransportStateChangedEvent) => any; + readonly iceGatherer: RTCIceGatherer | null; + oncandidatepairchange: ((ev: RTCIceCandidatePairChangedEvent) => any) | null; + onicestatechange: ((ev: RTCIceTransportStateChangedEvent) => any) | null; readonly role: string; readonly state: string; addRemoteCandidate(remoteCandidate: RTCIceCandidate | RTCIceCandidateComplete): void; createAssociatedTransport(): RTCIceTransport; - getNominatedCandidatePair(): RTCIceCandidatePair; + getNominatedCandidatePair(): RTCIceCandidatePair | null; getRemoteCandidates(): RTCIceCandidate[]; - getRemoteParameters(): RTCIceParameters; + getRemoteParameters(): RTCIceParameters | null; setRemoteCandidates(remoteCandidates: RTCIceCandidate[]): void; start(gatherer: RTCIceGatherer, remoteParameters: RTCIceParameters, role?: string): void; stop(): void; @@ -9391,9 +9397,9 @@ declare var RTCIceTransportStateChangedEvent: { } interface RTCRtpReceiver extends RTCStatsProvider { - onerror: (ev: Event) => any; + onerror: ((ev: Event) => any) | null; readonly rtcpTransport: RTCDtlsTransport; - readonly track: MediaStreamTrack; + readonly track: MediaStreamTrack | null; readonly transport: RTCDtlsTransport | RTCSrtpSdesTransport; getContributingSources(): RTCRtpContributingSource[]; receive(parameters: RTCRtpParameters): void; @@ -9411,8 +9417,8 @@ declare var RTCRtpReceiver: { } interface RTCRtpSender extends RTCStatsProvider { - onerror: (ev: Event) => any; - onssrcconflict: (ev: RTCSsrcConflictEvent) => any; + onerror: ((ev: Event) => any) | null; + onssrcconflict: ((ev: RTCSsrcConflictEvent) => any) | null; readonly rtcpTransport: RTCDtlsTransport; readonly track: MediaStreamTrack; readonly transport: RTCDtlsTransport | RTCSrtpSdesTransport; @@ -9432,7 +9438,7 @@ declare var RTCRtpSender: { } interface RTCSrtpSdesTransport extends EventTarget { - onerror: (ev: Event) => any; + onerror: ((ev: Event) => any) | null; readonly transport: RTCIceTransport; addEventListener(type: "error", listener: (ev: ErrorEvent) => any, useCapture?: boolean): void; addEventListener(type: string, listener: EventListenerOrEventListenerObject, useCapture?: boolean): void; @@ -11479,9 +11485,9 @@ interface SubtleCrypto { encrypt(algorithm: string | Algorithm, key: CryptoKey, data: ArrayBufferView): PromiseLike; exportKey(format: string, key: CryptoKey): PromiseLike; generateKey(algorithm: string | Algorithm, extractable: boolean, keyUsages: string[]): PromiseLike; - importKey(format: string, keyData: ArrayBufferView, algorithm: string | Algorithm, extractable: boolean, keyUsages: string[]): PromiseLike; + importKey(format: string, keyData: ArrayBufferView, algorithm: string | Algorithm | null, extractable: boolean, keyUsages: string[]): PromiseLike; sign(algorithm: string | Algorithm, key: CryptoKey, data: ArrayBufferView): PromiseLike; - unwrapKey(format: string, wrappedKey: ArrayBufferView, unwrappingKey: CryptoKey, unwrapAlgorithm: string | Algorithm, unwrappedKeyAlgorithm: string | Algorithm, extractable: boolean, keyUsages: string[]): PromiseLike; + unwrapKey(format: string, wrappedKey: ArrayBufferView, unwrappingKey: CryptoKey, unwrapAlgorithm: string | Algorithm, unwrappedKeyAlgorithm: string | Algorithm | null, extractable: boolean, keyUsages: string[]): PromiseLike; verify(algorithm: string | Algorithm, key: CryptoKey, signature: ArrayBufferView, data: ArrayBufferView): PromiseLike; wrapKey(format: string, key: CryptoKey, wrappingKey: CryptoKey, wrapAlgorithm: string | Algorithm): PromiseLike; } @@ -11615,7 +11621,7 @@ declare var TextTrackCueList: { interface TextTrackList extends EventTarget { readonly length: number; - onaddtrack: (ev: TrackEvent) => any; + onaddtrack: ((ev: TrackEvent) => any) | null; item(index: number): TextTrack; addEventListener(type: "addtrack", listener: (ev: TrackEvent) => any, useCapture?: boolean): void; addEventListener(type: string, listener: EventListenerOrEventListenerObject, useCapture?: boolean): void; @@ -11671,7 +11677,7 @@ declare var TouchEvent: { interface TouchList { readonly length: number; - item(index: number): Touch; + item(index: number): Touch | null; [index: number]: Touch; } @@ -11813,7 +11819,7 @@ interface VideoTrackList extends EventTarget { onchange: (ev: Event) => any; onremovetrack: (ev: TrackEvent) => any; readonly selectedIndex: number; - getTrackById(id: string): VideoTrack; + getTrackById(id: string): VideoTrack | null; item(index: number): VideoTrack; addEventListener(type: "addtrack", listener: (ev: TrackEvent) => any, useCapture?: boolean): void; addEventListener(type: "change", listener: (ev: Event) => any, useCapture?: boolean): void; @@ -11866,7 +11872,7 @@ declare var WEBGL_depth_texture: { } interface WaveShaperNode extends AudioNode { - curve: Float32Array; + curve: Float32Array | null; oversample: string; } @@ -11940,12 +11946,12 @@ interface WebGLRenderingContext { readonly drawingBufferHeight: number; readonly drawingBufferWidth: number; activeTexture(texture: number): void; - attachShader(program: WebGLProgram, shader: WebGLShader): void; - bindAttribLocation(program: WebGLProgram, index: number, name: string): void; - bindBuffer(target: number, buffer: WebGLBuffer): void; - bindFramebuffer(target: number, framebuffer: WebGLFramebuffer): void; - bindRenderbuffer(target: number, renderbuffer: WebGLRenderbuffer): void; - bindTexture(target: number, texture: WebGLTexture): void; + attachShader(program: WebGLProgram | null, shader: WebGLShader | null): void; + bindAttribLocation(program: WebGLProgram | null, index: number, name: string): void; + bindBuffer(target: number, buffer: WebGLBuffer | null): void; + bindFramebuffer(target: number, framebuffer: WebGLFramebuffer | null): void; + bindRenderbuffer(target: number, renderbuffer: WebGLRenderbuffer | null): void; + bindTexture(target: number, texture: WebGLTexture | null): void; blendColor(red: number, green: number, blue: number, alpha: number): void; blendEquation(mode: number): void; blendEquationSeparate(modeRGB: number, modeAlpha: number): void; @@ -11959,28 +11965,28 @@ interface WebGLRenderingContext { clearDepth(depth: number): void; clearStencil(s: number): void; colorMask(red: boolean, green: boolean, blue: boolean, alpha: boolean): void; - compileShader(shader: WebGLShader): void; + compileShader(shader: WebGLShader | null): void; compressedTexImage2D(target: number, level: number, internalformat: number, width: number, height: number, border: number, data: ArrayBufferView): void; compressedTexSubImage2D(target: number, level: number, xoffset: number, yoffset: number, width: number, height: number, format: number, data: ArrayBufferView): void; copyTexImage2D(target: number, level: number, internalformat: number, x: number, y: number, width: number, height: number, border: number): void; copyTexSubImage2D(target: number, level: number, xoffset: number, yoffset: number, x: number, y: number, width: number, height: number): void; - createBuffer(): WebGLBuffer; - createFramebuffer(): WebGLFramebuffer; - createProgram(): WebGLProgram; - createRenderbuffer(): WebGLRenderbuffer; - createShader(type: number): WebGLShader; - createTexture(): WebGLTexture; + createBuffer(): WebGLBuffer | null; + createFramebuffer(): WebGLFramebuffer | null; + createProgram(): WebGLProgram | null; + createRenderbuffer(): WebGLRenderbuffer | null; + createShader(type: number): WebGLShader | null; + createTexture(): WebGLTexture | null; cullFace(mode: number): void; - deleteBuffer(buffer: WebGLBuffer): void; - deleteFramebuffer(framebuffer: WebGLFramebuffer): void; - deleteProgram(program: WebGLProgram): void; - deleteRenderbuffer(renderbuffer: WebGLRenderbuffer): void; - deleteShader(shader: WebGLShader): void; - deleteTexture(texture: WebGLTexture): void; + deleteBuffer(buffer: WebGLBuffer | null): void; + deleteFramebuffer(framebuffer: WebGLFramebuffer | null): void; + deleteProgram(program: WebGLProgram | null): void; + deleteRenderbuffer(renderbuffer: WebGLRenderbuffer | null): void; + deleteShader(shader: WebGLShader | null): void; + deleteTexture(texture: WebGLTexture | null): void; depthFunc(func: number): void; depthMask(flag: boolean): void; depthRange(zNear: number, zFar: number): void; - detachShader(program: WebGLProgram, shader: WebGLShader): void; + detachShader(program: WebGLProgram | null, shader: WebGLShader | null): void; disable(cap: number): void; disableVertexAttribArray(index: number): void; drawArrays(mode: number, first: number, count: number): void; @@ -11989,51 +11995,51 @@ interface WebGLRenderingContext { enableVertexAttribArray(index: number): void; finish(): void; flush(): void; - framebufferRenderbuffer(target: number, attachment: number, renderbuffertarget: number, renderbuffer: WebGLRenderbuffer): void; - framebufferTexture2D(target: number, attachment: number, textarget: number, texture: WebGLTexture, level: number): void; + framebufferRenderbuffer(target: number, attachment: number, renderbuffertarget: number, renderbuffer: WebGLRenderbuffer | null): void; + framebufferTexture2D(target: number, attachment: number, textarget: number, texture: WebGLTexture | null, level: number): void; frontFace(mode: number): void; generateMipmap(target: number): void; - getActiveAttrib(program: WebGLProgram, index: number): WebGLActiveInfo; - getActiveUniform(program: WebGLProgram, index: number): WebGLActiveInfo; - getAttachedShaders(program: WebGLProgram): WebGLShader[]; - getAttribLocation(program: WebGLProgram, name: string): number; + getActiveAttrib(program: WebGLProgram | null, index: number): WebGLActiveInfo | null; + getActiveUniform(program: WebGLProgram | null, index: number): WebGLActiveInfo | null; + getAttachedShaders(program: WebGLProgram | null): WebGLShader[] | null; + getAttribLocation(program: WebGLProgram | null, name: string): number; getBufferParameter(target: number, pname: number): any; getContextAttributes(): WebGLContextAttributes; getError(): number; getExtension(name: string): any; getFramebufferAttachmentParameter(target: number, attachment: number, pname: number): any; getParameter(pname: number): any; - getProgramInfoLog(program: WebGLProgram): string; - getProgramParameter(program: WebGLProgram, pname: number): any; + getProgramInfoLog(program: WebGLProgram | null): string | null; + getProgramParameter(program: WebGLProgram | null, pname: number): any; getRenderbufferParameter(target: number, pname: number): any; - getShaderInfoLog(shader: WebGLShader): string; - getShaderParameter(shader: WebGLShader, pname: number): any; - getShaderPrecisionFormat(shadertype: number, precisiontype: number): WebGLShaderPrecisionFormat; - getShaderSource(shader: WebGLShader): string; - getSupportedExtensions(): string[]; + getShaderInfoLog(shader: WebGLShader | null): string | null; + getShaderParameter(shader: WebGLShader | null, pname: number): any; + getShaderPrecisionFormat(shadertype: number, precisiontype: number): WebGLShaderPrecisionFormat | null; + getShaderSource(shader: WebGLShader | null): string | null; + getSupportedExtensions(): string[] | null; getTexParameter(target: number, pname: number): any; - getUniform(program: WebGLProgram, location: WebGLUniformLocation): any; - getUniformLocation(program: WebGLProgram, name: string): WebGLUniformLocation; + getUniform(program: WebGLProgram | null, location: WebGLUniformLocation | null): any; + getUniformLocation(program: WebGLProgram | null, name: string): WebGLUniformLocation | null; getVertexAttrib(index: number, pname: number): any; getVertexAttribOffset(index: number, pname: number): number; hint(target: number, mode: number): void; - isBuffer(buffer: WebGLBuffer): boolean; + isBuffer(buffer: WebGLBuffer | null): boolean; isContextLost(): boolean; isEnabled(cap: number): boolean; - isFramebuffer(framebuffer: WebGLFramebuffer): boolean; - isProgram(program: WebGLProgram): boolean; - isRenderbuffer(renderbuffer: WebGLRenderbuffer): boolean; - isShader(shader: WebGLShader): boolean; - isTexture(texture: WebGLTexture): boolean; + isFramebuffer(framebuffer: WebGLFramebuffer | null): boolean; + isProgram(program: WebGLProgram | null): boolean; + isRenderbuffer(renderbuffer: WebGLRenderbuffer | null): boolean; + isShader(shader: WebGLShader | null): boolean; + isTexture(texture: WebGLTexture | null): boolean; lineWidth(width: number): void; - linkProgram(program: WebGLProgram): void; + linkProgram(program: WebGLProgram | null): void; pixelStorei(pname: number, param: number): void; polygonOffset(factor: number, units: number): void; - readPixels(x: number, y: number, width: number, height: number, format: number, type: number, pixels: ArrayBufferView): void; + readPixels(x: number, y: number, width: number, height: number, format: number, type: number, pixels: ArrayBufferView | null): void; renderbufferStorage(target: number, internalformat: number, width: number, height: number): void; sampleCoverage(value: number, invert: boolean): void; scissor(x: number, y: number, width: number, height: number): void; - shaderSource(shader: WebGLShader, source: string): void; + shaderSource(shader: WebGLShader | null, source: string): void; stencilFunc(func: number, ref: number, mask: number): void; stencilFuncSeparate(face: number, func: number, ref: number, mask: number): void; stencilMask(mask: number): void; @@ -12052,27 +12058,27 @@ interface WebGLRenderingContext { texSubImage2D(target: number, level: number, xoffset: number, yoffset: number, format: number, type: number, canvas: HTMLCanvasElement): void; texSubImage2D(target: number, level: number, xoffset: number, yoffset: number, format: number, type: number, video: HTMLVideoElement): void; texSubImage2D(target: number, level: number, xoffset: number, yoffset: number, format: number, type: number, pixels: ImageData): void; - uniform1f(location: WebGLUniformLocation, x: number): void; + uniform1f(location: WebGLUniformLocation | null, x: number): void; uniform1fv(location: WebGLUniformLocation, v: Float32Array | number[]): void; - uniform1i(location: WebGLUniformLocation, x: number): void; + uniform1i(location: WebGLUniformLocation | null, x: number): void; uniform1iv(location: WebGLUniformLocation, v: Int32Array | number[]): void; - uniform2f(location: WebGLUniformLocation, x: number, y: number): void; + uniform2f(location: WebGLUniformLocation | null, x: number, y: number): void; uniform2fv(location: WebGLUniformLocation, v: Float32Array | number[]): void; - uniform2i(location: WebGLUniformLocation, x: number, y: number): void; + uniform2i(location: WebGLUniformLocation | null, x: number, y: number): void; uniform2iv(location: WebGLUniformLocation, v: Int32Array | number[]): void; - uniform3f(location: WebGLUniformLocation, x: number, y: number, z: number): void; + uniform3f(location: WebGLUniformLocation | null, x: number, y: number, z: number): void; uniform3fv(location: WebGLUniformLocation, v: Float32Array | number[]): void; - uniform3i(location: WebGLUniformLocation, x: number, y: number, z: number): void; + uniform3i(location: WebGLUniformLocation | null, x: number, y: number, z: number): void; uniform3iv(location: WebGLUniformLocation, v: Int32Array | number[]): void; - uniform4f(location: WebGLUniformLocation, x: number, y: number, z: number, w: number): void; + uniform4f(location: WebGLUniformLocation | null, x: number, y: number, z: number, w: number): void; uniform4fv(location: WebGLUniformLocation, v: Float32Array | number[]): void; - uniform4i(location: WebGLUniformLocation, x: number, y: number, z: number, w: number): void; + uniform4i(location: WebGLUniformLocation | null, x: number, y: number, z: number, w: number): void; uniform4iv(location: WebGLUniformLocation, v: Int32Array | number[]): void; uniformMatrix2fv(location: WebGLUniformLocation, transpose: boolean, value: Float32Array | number[]): void; uniformMatrix3fv(location: WebGLUniformLocation, transpose: boolean, value: Float32Array | number[]): void; uniformMatrix4fv(location: WebGLUniformLocation, transpose: boolean, value: Float32Array | number[]): void; - useProgram(program: WebGLProgram): void; - validateProgram(program: WebGLProgram): void; + useProgram(program: WebGLProgram | null): void; + validateProgram(program: WebGLProgram | null): void; vertexAttrib1f(indx: number, x: number): void; vertexAttrib1fv(indx: number, values: Float32Array | number[]): void; vertexAttrib2f(indx: number, x: number, y: number): void; @@ -12982,7 +12988,7 @@ interface Window extends EventTarget, WindowTimers, WindowSessionStorage, Window open(url?: string, target?: string, features?: string, replace?: boolean): Window; postMessage(message: any, targetOrigin: string, transfer?: any[]): void; print(): void; - prompt(message?: string, _default?: string): string; + prompt(message?: string, _default?: string): string | null; releaseEvents(): void; requestAnimationFrame(callback: FrameRequestCallback): number; resizeBy(x?: number, y?: number): void; @@ -13135,7 +13141,7 @@ interface XMLHttpRequest extends EventTarget, XMLHttpRequestEventTarget { withCredentials: boolean; abort(): void; getAllResponseHeaders(): string; - getResponseHeader(header: string): string; + getResponseHeader(header: string): string | null; msCachingEnabled(): boolean; open(method: string, url: string, async?: boolean, user?: string, password?: string): void; overrideMimeType(mime: string): void; @@ -13659,14 +13665,6 @@ interface ProgressEventInit extends EventInit { total?: number; } -interface HTMLPictureElement extends HTMLElement { -} - -declare var HTMLPictureElement: { - prototype: HTMLPictureElement; - new(): HTMLPictureElement; -} - interface ClipboardEventInit extends EventInit { data?: string; dataType?: string; @@ -13880,7 +13878,7 @@ declare function msWriteProfilerMark(profilerMarkName: string): void; declare function open(url?: string, target?: string, features?: string, replace?: boolean): Window; declare function postMessage(message: any, targetOrigin: string, transfer?: any[]): void; declare function print(): void; -declare function prompt(message?: string, _default?: string): string; +declare function prompt(message?: string, _default?: string): string | null; declare function releaseEvents(): void; declare function requestAnimationFrame(callback: FrameRequestCallback): number; declare function resizeBy(x?: number, y?: number): void; diff --git a/src/lib/webworker.generated.d.ts b/src/lib/webworker.generated.d.ts index 2b302dea6a2..f5c77b8594d 100644 --- a/src/lib/webworker.generated.d.ts +++ b/src/lib/webworker.generated.d.ts @@ -8,6 +8,16 @@ interface EventInit { cancelable?: boolean; } +interface IDBIndexParameters { + multiEntry?: boolean; + unique?: boolean; +} + +interface IDBObjectStoreParameters { + autoIncrement?: boolean; + keyPath?: IDBKeyPath; +} + interface EventListener { (evt: Event): void; } @@ -84,12 +94,12 @@ declare var Console: { interface Coordinates { readonly accuracy: number; - readonly altitude: number; - readonly altitudeAccuracy: number; - readonly heading: number; + readonly altitude: number | null; + readonly altitudeAccuracy: number | null; + readonly heading: number | null; readonly latitude: number; readonly longitude: number; - readonly speed: number; + readonly speed: number | null; } declare var Coordinates: { @@ -176,7 +186,7 @@ declare var DOMException: { interface DOMStringList { readonly length: number; contains(str: string): boolean; - item(index: number): string; + item(index: number): string | null; [index: number]: string; } @@ -459,7 +469,7 @@ declare var IDBTransaction: { } interface IDBVersionChangeEvent extends Event { - readonly newVersion: number; + readonly newVersion: number | null; readonly oldVersion: number; } @@ -712,7 +722,7 @@ interface XMLHttpRequest extends EventTarget, XMLHttpRequestEventTarget { withCredentials: boolean; abort(): void; getAllResponseHeaders(): string; - getResponseHeader(header: string): string; + getResponseHeader(header: string): string | null; msCachingEnabled(): boolean; open(method: string, url: string, async?: boolean, user?: string, password?: string): void; overrideMimeType(mime: string): void; @@ -991,4 +1001,5 @@ declare var console: Console; declare function addEventListener(type: "error", listener: (ev: ErrorEvent) => any, useCapture?: boolean): void; declare function addEventListener(type: "message", listener: (ev: MessageEvent) => any, useCapture?: boolean): void; declare function addEventListener(type: string, listener: EventListenerOrEventListenerObject, useCapture?: boolean): void; +type IDBKeyPath = string; type IDBValidKey = number | string | Date | IDBArrayKey; \ No newline at end of file From 8cd32535acef07ecb0cc4c788c883de35eb1b809 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Wed, 27 Apr 2016 13:54:40 -0700 Subject: [PATCH 22/52] Display the name 'nothing' for the empty union type --- src/compiler/checker.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index ddaea2285c5..516a01ecf44 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -2014,7 +2014,12 @@ namespace ts { writeUnionOrIntersectionType(type, flags); } else if (type.flags & TypeFlags.Anonymous) { - writeAnonymousType(type, flags); + if (type === emptyUnionType) { + writer.writeKeyword("nothing"); + } + else { + writeAnonymousType(type, flags); + } } else if (type.flags & TypeFlags.StringLiteral) { writer.writeStringLiteral(`"${escapeString((type).text)}"`); @@ -4247,7 +4252,9 @@ namespace ts { propTypes.push(getTypeOfSymbol(prop)); } } - return getUnionType(propTypes); + if (propTypes.length) { + return getUnionType(propTypes); + } } return undefined; } From 9da4323c8011cbcc07b5cc710b1910e619f7d2e8 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Wed, 27 Apr 2016 13:54:52 -0700 Subject: [PATCH 23/52] Accepting new baselines --- tests/baselines/reference/instanceOfAssignability.types | 4 ++-- tests/baselines/reference/stringLiteralTypesAsTags01.types | 4 ++-- tests/baselines/reference/stringLiteralTypesAsTags02.types | 4 ++-- tests/baselines/reference/stringLiteralTypesAsTags03.types | 4 ++-- .../baselines/reference/typeGuardOfFormTypeOfBoolean.types | 4 ++-- tests/baselines/reference/typeGuardOfFormTypeOfNumber.types | 4 ++-- tests/baselines/reference/typeGuardOfFormTypeOfOther.types | 4 ++-- tests/baselines/reference/typeGuardOfFormTypeOfString.types | 4 ++-- .../reference/typeGuardTautologicalConsistiency.types | 4 ++-- tests/baselines/reference/typeGuardTypeOfUndefined.types | 6 +++--- .../baselines/reference/typeGuardsWithInstanceOf.errors.txt | 4 ++-- 11 files changed, 23 insertions(+), 23 deletions(-) diff --git a/tests/baselines/reference/instanceOfAssignability.types b/tests/baselines/reference/instanceOfAssignability.types index 5fa55aa6d88..0a9e1a3e996 100644 --- a/tests/baselines/reference/instanceOfAssignability.types +++ b/tests/baselines/reference/instanceOfAssignability.types @@ -133,8 +133,8 @@ function fn5(x: Derived1) { // 1.5: y: Derived1 // Want: ??? let y = x; ->y : {} ->x : {} +>y : nothing +>x : nothing } } diff --git a/tests/baselines/reference/stringLiteralTypesAsTags01.types b/tests/baselines/reference/stringLiteralTypesAsTags01.types index 243b55c4419..9f273cf93a9 100644 --- a/tests/baselines/reference/stringLiteralTypesAsTags01.types +++ b/tests/baselines/reference/stringLiteralTypesAsTags01.types @@ -116,6 +116,6 @@ if (!hasKind(x, "B")) { } else { let d = x; ->d : {} ->x : {} +>d : nothing +>x : nothing } diff --git a/tests/baselines/reference/stringLiteralTypesAsTags02.types b/tests/baselines/reference/stringLiteralTypesAsTags02.types index 20834e1dfef..bcfa74ef55f 100644 --- a/tests/baselines/reference/stringLiteralTypesAsTags02.types +++ b/tests/baselines/reference/stringLiteralTypesAsTags02.types @@ -110,6 +110,6 @@ if (!hasKind(x, "B")) { } else { let d = x; ->d : {} ->x : {} +>d : nothing +>x : nothing } diff --git a/tests/baselines/reference/stringLiteralTypesAsTags03.types b/tests/baselines/reference/stringLiteralTypesAsTags03.types index 78ad260b719..c7fdfc7152e 100644 --- a/tests/baselines/reference/stringLiteralTypesAsTags03.types +++ b/tests/baselines/reference/stringLiteralTypesAsTags03.types @@ -113,6 +113,6 @@ if (!hasKind(x, "B")) { } else { let d = x; ->d : {} ->x : {} +>d : nothing +>x : nothing } diff --git a/tests/baselines/reference/typeGuardOfFormTypeOfBoolean.types b/tests/baselines/reference/typeGuardOfFormTypeOfBoolean.types index a5dcc9207cd..564c6ceaa72 100644 --- a/tests/baselines/reference/typeGuardOfFormTypeOfBoolean.types +++ b/tests/baselines/reference/typeGuardOfFormTypeOfBoolean.types @@ -121,7 +121,7 @@ if (typeof strOrNum === "boolean") { let z1: {} = strOrNum; // {} >z1 : {} ->strOrNum : {} +>strOrNum : nothing } else { let z2: string | number = strOrNum; // string | number @@ -215,6 +215,6 @@ if (typeof strOrNum !== "boolean") { else { let z2: {} = strOrNum; // {} >z2 : {} ->strOrNum : {} +>strOrNum : nothing } diff --git a/tests/baselines/reference/typeGuardOfFormTypeOfNumber.types b/tests/baselines/reference/typeGuardOfFormTypeOfNumber.types index 99f927b7137..51326c68cd9 100644 --- a/tests/baselines/reference/typeGuardOfFormTypeOfNumber.types +++ b/tests/baselines/reference/typeGuardOfFormTypeOfNumber.types @@ -120,7 +120,7 @@ if (typeof strOrBool === "number") { let y1: {} = strOrBool; // {} >y1 : {} ->strOrBool : {} +>strOrBool : nothing } else { let y2: string | boolean = strOrBool; // string | boolean @@ -212,6 +212,6 @@ if (typeof strOrBool !== "number") { else { let y2: {} = strOrBool; // {} >y2 : {} ->strOrBool : {} +>strOrBool : nothing } diff --git a/tests/baselines/reference/typeGuardOfFormTypeOfOther.types b/tests/baselines/reference/typeGuardOfFormTypeOfOther.types index aba8e429b8c..c8c150b5a3b 100644 --- a/tests/baselines/reference/typeGuardOfFormTypeOfOther.types +++ b/tests/baselines/reference/typeGuardOfFormTypeOfOther.types @@ -105,7 +105,7 @@ if (typeof strOrNumOrBool === "Object") { let q1: {} = strOrNumOrBool; // {} >q1 : {} ->strOrNumOrBool : {} +>strOrNumOrBool : nothing } else { let q2: string | number | boolean = strOrNumOrBool; // string | number | boolean @@ -178,6 +178,6 @@ if (typeof strOrNumOrBool !== "Object") { else { let q2: {} = strOrNumOrBool; // {} >q2 : {} ->strOrNumOrBool : {} +>strOrNumOrBool : nothing } diff --git a/tests/baselines/reference/typeGuardOfFormTypeOfString.types b/tests/baselines/reference/typeGuardOfFormTypeOfString.types index c77f9f3207a..23c789fb987 100644 --- a/tests/baselines/reference/typeGuardOfFormTypeOfString.types +++ b/tests/baselines/reference/typeGuardOfFormTypeOfString.types @@ -121,7 +121,7 @@ if (typeof numOrBool === "string") { let x1: {} = numOrBool; // {} >x1 : {} ->numOrBool : {} +>numOrBool : nothing } else { let x2: number | boolean = numOrBool; // number | boolean @@ -214,6 +214,6 @@ if (typeof numOrBool !== "string") { else { let x2: {} = numOrBool; // {} >x2 : {} ->numOrBool : {} +>numOrBool : nothing } diff --git a/tests/baselines/reference/typeGuardTautologicalConsistiency.types b/tests/baselines/reference/typeGuardTautologicalConsistiency.types index 100e528f616..cf9e82d9fd2 100644 --- a/tests/baselines/reference/typeGuardTautologicalConsistiency.types +++ b/tests/baselines/reference/typeGuardTautologicalConsistiency.types @@ -15,7 +15,7 @@ if (typeof stringOrNumber === "number") { >"number" : string stringOrNumber; ->stringOrNumber : {} +>stringOrNumber : nothing } } @@ -31,6 +31,6 @@ if (typeof stringOrNumber === "number" && typeof stringOrNumber !== "number") { >"number" : string stringOrNumber; ->stringOrNumber : {} +>stringOrNumber : nothing } diff --git a/tests/baselines/reference/typeGuardTypeOfUndefined.types b/tests/baselines/reference/typeGuardTypeOfUndefined.types index 7073d9aeacb..ac648d36f01 100644 --- a/tests/baselines/reference/typeGuardTypeOfUndefined.types +++ b/tests/baselines/reference/typeGuardTypeOfUndefined.types @@ -47,7 +47,7 @@ function test2(a: any) { >"boolean" : string a; ->a : {} +>a : nothing } else { a; @@ -129,7 +129,7 @@ function test5(a: boolean | void) { } else { a; ->a : {} +>a : nothing } } else { @@ -188,7 +188,7 @@ function test7(a: boolean | void) { } else { a; ->a : {} +>a : nothing } } diff --git a/tests/baselines/reference/typeGuardsWithInstanceOf.errors.txt b/tests/baselines/reference/typeGuardsWithInstanceOf.errors.txt index 28cc85695bc..662d3697159 100644 --- a/tests/baselines/reference/typeGuardsWithInstanceOf.errors.txt +++ b/tests/baselines/reference/typeGuardsWithInstanceOf.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOf.ts(7,20): error TS2339: Property 'global' does not exist on type '{}'. +tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOf.ts(7,20): error TS2339: Property 'global' does not exist on type 'nothing'. ==== tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOf.ts (1 errors) ==== @@ -10,5 +10,5 @@ tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOf.ts(7,20) result = result2; } else if (!result.global) { ~~~~~~ -!!! error TS2339: Property 'global' does not exist on type '{}'. +!!! error TS2339: Property 'global' does not exist on type 'nothing'. } \ No newline at end of file From cff98d529493b8775d8724c3c1fdfe7d2bffa876 Mon Sep 17 00:00:00 2001 From: zhengbli Date: Wed, 27 Apr 2016 14:40:59 -0700 Subject: [PATCH 24/52] Move the dir watcher to parseConfigFile --- src/compiler/tsc.ts | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/compiler/tsc.ts b/src/compiler/tsc.ts index d6dfc9eca8d..e25ae37e21f 100644 --- a/src/compiler/tsc.ts +++ b/src/compiler/tsc.ts @@ -391,9 +391,21 @@ namespace ts { sys.exit(ExitStatus.DiagnosticsPresent_OutputsSkipped); return; } - if (isWatchSet(configParseResult.options) && !sys.watchFile) { - reportDiagnostic(createCompilerDiagnostic(Diagnostics.The_current_host_does_not_support_the_0_option, "--watch"), /* compilerHost */ undefined); - sys.exit(ExitStatus.DiagnosticsPresent_OutputsSkipped); + if (isWatchSet(configParseResult.options)) { + if (!sys.watchFile) { + reportDiagnostic(createCompilerDiagnostic(Diagnostics.The_current_host_does_not_support_the_0_option, "--watch"), /* compilerHost */ undefined); + sys.exit(ExitStatus.DiagnosticsPresent_OutputsSkipped); + } + + if (!directoryWatcher && sys.watchDirectory && configFileName) { + const directory = ts.getDirectoryPath(configFileName); + directoryWatcher = sys.watchDirectory( + // When the configFileName is just "tsconfig.json", the watched directory should be + // the current directory; if there is a given "project" parameter, then the configFileName + // is an absolute file name. + directory == "" ? "." : directory, + watchedDirectoryChanged, /*recursive*/ true); + }; } return configParseResult; } @@ -432,16 +444,6 @@ namespace ts { return sys.exit(compileResult.exitStatus); } - if (!directoryWatcher && sys.watchDirectory && configFileName) { - const directory = ts.getDirectoryPath(configFileName); - directoryWatcher = sys.watchDirectory( - // When the configFileName is just "tsconfig.json", the watched directory should be - // the current directory; if there is a given "project" parameter, then the configFileName - // is an absolute file name. - directory == "" ? "." : directory, - watchedDirectoryChanged, /*recursive*/ true); - } - setCachedProgram(compileResult.program); reportWatchDiagnostic(createCompilerDiagnostic(Diagnostics.Compilation_complete_Watching_for_file_changes)); } From 3437fe5846f18e9623ec194008b5ece4b7bb7dc7 Mon Sep 17 00:00:00 2001 From: Paul van Brenk Date: Wed, 27 Apr 2016 14:45:24 -0700 Subject: [PATCH 25/52] Exclude the files in the .vs folder These are user spefic settings, that shouldn't be in the git repo. --- .gitignore | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 79fefb71a85..4f9ec0649b3 100644 --- a/.gitignore +++ b/.gitignore @@ -46,5 +46,6 @@ coverage/ internal/ **/.DS_Store .settings -.vscode/* -!.vscode/tasks.json +**/.vs +**/.vscode +!**/.vscode/tasks.json From 465e9c82fffb98a71857a70cbad798a65bb5119f Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Thu, 28 Apr 2016 08:48:08 -0700 Subject: [PATCH 26/52] Revert Function.bind/apply/call this-overloads --- src/lib/es5.d.ts | 3 - .../assignmentToObjectAndFunction.errors.txt | 4 +- ...ArrowFunctionCapturesArguments_es6.symbols | 4 +- ...ncArrowFunctionCapturesArguments_es6.types | 12 +-- .../reference/declarationEmitPromise.symbols | 8 +- .../reference/declarationEmitPromise.types | 12 +-- ...nctionsInFunctionParameterDefaults.symbols | 4 +- ...functionsInFunctionParameterDefaults.types | 4 +- .../baselines/reference/functionType.symbols | 4 +- tests/baselines/reference/functionType.types | 6 +- .../genericTypeParameterEquivalence2.symbols | 4 +- .../genericTypeParameterEquivalence2.types | 6 +- ...eCompilationRestParamJsDocFunction.symbols | 20 ++--- ...ileCompilationRestParamJsDocFunction.types | 20 ++--- ...llSignatureAppearsToBeFunctionType.symbols | 8 +- ...CallSignatureAppearsToBeFunctionType.types | 8 +- .../returnTypeParameterWithModules.symbols | 4 +- .../returnTypeParameterWithModules.types | 4 +- .../reference/thisTypeInFunctions2.js | 51 +++++++++++ .../reference/thisTypeInFunctions2.symbols | 56 ++++++++++++ .../reference/thisTypeInFunctions2.types | 87 +++++++++++++++++++ .../types/thisType/thisTypeInFunctions2.ts | 26 ++++++ 22 files changed, 286 insertions(+), 69 deletions(-) create mode 100644 tests/baselines/reference/thisTypeInFunctions2.js create mode 100644 tests/baselines/reference/thisTypeInFunctions2.symbols create mode 100644 tests/baselines/reference/thisTypeInFunctions2.types create mode 100644 tests/cases/conformance/types/thisType/thisTypeInFunctions2.ts diff --git a/src/lib/es5.d.ts b/src/lib/es5.d.ts index 17916d5548e..967aeb42aaf 100644 --- a/src/lib/es5.d.ts +++ b/src/lib/es5.d.ts @@ -215,7 +215,6 @@ interface Function { * @param thisArg The object to be used as the this object. * @param argArray A set of arguments to be passed to the function. */ - apply(this: (this: T, ...argArray: any[]) => U, thisArg: T, argArray?: any): U; apply(this: Function, thisArg: any, argArray?: any): any; /** @@ -223,7 +222,6 @@ interface Function { * @param thisArg The object to be used as the current object. * @param argArray A list of arguments to be passed to the method. */ - call(this: (this: T, ...argArray: any[]) => U, thisArg: T, ...argArray: any[]): U; call(this: Function, thisArg: any, ...argArray: any[]): any; /** @@ -232,7 +230,6 @@ interface Function { * @param thisArg An object to which the this keyword can refer inside the new function. * @param argArray A list of arguments to be passed to the new function. */ - bind(this: (this: T, ...argArray: any[]) => U, thisArg: T, ...argArray: any[]): (this: void, ...argArray: any[]) => U; bind(this: Function, thisArg: any, ...argArray: any[]): any; prototype: any; diff --git a/tests/baselines/reference/assignmentToObjectAndFunction.errors.txt b/tests/baselines/reference/assignmentToObjectAndFunction.errors.txt index 454ac41b5b8..204135cd004 100644 --- a/tests/baselines/reference/assignmentToObjectAndFunction.errors.txt +++ b/tests/baselines/reference/assignmentToObjectAndFunction.errors.txt @@ -5,7 +5,7 @@ tests/cases/compiler/assignmentToObjectAndFunction.ts(8,5): error TS2322: Type ' Property 'apply' is missing in type '{}'. tests/cases/compiler/assignmentToObjectAndFunction.ts(29,5): error TS2322: Type 'typeof bad' is not assignable to type 'Function'. Types of property 'apply' are incompatible. - Type 'number' is not assignable to type '{ (this: (this: T, ...argArray: any[]) => U, thisArg: T, argArray?: any): U; (this: Function, thisArg: any, argArray?: any): any; }'. + Type 'number' is not assignable to type '(this: Function, thisArg: any, argArray?: any) => any'. ==== tests/cases/compiler/assignmentToObjectAndFunction.ts (3 errors) ==== @@ -48,4 +48,4 @@ tests/cases/compiler/assignmentToObjectAndFunction.ts(29,5): error TS2322: Type ~~~~~~~~~~ !!! error TS2322: Type 'typeof bad' is not assignable to type 'Function'. !!! error TS2322: Types of property 'apply' are incompatible. -!!! error TS2322: Type 'number' is not assignable to type '{ (this: (this: T, ...argArray: any[]) => U, thisArg: T, argArray?: any): U; (this: Function, thisArg: any, argArray?: any): any; }'. \ No newline at end of file +!!! error TS2322: Type 'number' is not assignable to type '(this: Function, thisArg: any, argArray?: any) => any'. \ No newline at end of file diff --git a/tests/baselines/reference/asyncArrowFunctionCapturesArguments_es6.symbols b/tests/baselines/reference/asyncArrowFunctionCapturesArguments_es6.symbols index 06999513192..4b312fd4646 100644 --- a/tests/baselines/reference/asyncArrowFunctionCapturesArguments_es6.symbols +++ b/tests/baselines/reference/asyncArrowFunctionCapturesArguments_es6.symbols @@ -10,9 +10,9 @@ class C { var fn = async () => await other.apply(this, arguments); >fn : Symbol(fn, Decl(asyncArrowFunctionCapturesArguments_es6.ts, 3, 9)) ->other.apply : Symbol(Function.apply, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) +>other.apply : Symbol(Function.apply, Decl(lib.es5.d.ts, --, --)) >other : Symbol(other, Decl(asyncArrowFunctionCapturesArguments_es6.ts, 1, 13)) ->apply : Symbol(Function.apply, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) +>apply : Symbol(Function.apply, Decl(lib.es5.d.ts, --, --)) >this : Symbol(C, Decl(asyncArrowFunctionCapturesArguments_es6.ts, 0, 0)) >arguments : Symbol(arguments) } diff --git a/tests/baselines/reference/asyncArrowFunctionCapturesArguments_es6.types b/tests/baselines/reference/asyncArrowFunctionCapturesArguments_es6.types index 18a08ffface..bb9df9af139 100644 --- a/tests/baselines/reference/asyncArrowFunctionCapturesArguments_es6.types +++ b/tests/baselines/reference/asyncArrowFunctionCapturesArguments_es6.types @@ -9,13 +9,13 @@ class C { >other : () => void var fn = async () => await other.apply(this, arguments); ->fn : () => Promise ->async () => await other.apply(this, arguments) : () => Promise ->await other.apply(this, arguments) : void ->other.apply(this, arguments) : void ->other.apply : { (this: (this: T, ...argArray: any[]) => U, thisArg: T, argArray?: any): U; (this: Function, thisArg: any, argArray?: any): any; } +>fn : () => Promise +>async () => await other.apply(this, arguments) : () => Promise +>await other.apply(this, arguments) : any +>other.apply(this, arguments) : any +>other.apply : (this: Function, thisArg: any, argArray?: any) => any >other : () => void ->apply : { (this: (this: T, ...argArray: any[]) => U, thisArg: T, argArray?: any): U; (this: Function, thisArg: any, argArray?: any): any; } +>apply : (this: Function, thisArg: any, argArray?: any) => any >this : this >arguments : IArguments } diff --git a/tests/baselines/reference/declarationEmitPromise.symbols b/tests/baselines/reference/declarationEmitPromise.symbols index 894a20e03a6..2c37e1dfa78 100644 --- a/tests/baselines/reference/declarationEmitPromise.symbols +++ b/tests/baselines/reference/declarationEmitPromise.symbols @@ -68,9 +68,9 @@ export async function runSampleWorks( >T : Symbol(T, Decl(declarationEmitPromise.ts, 8, 16)) f.apply(this, result); ->f.apply : Symbol(Function.apply, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) +>f.apply : Symbol(Function.apply, Decl(lib.es5.d.ts, --, --)) >f : Symbol(f, Decl(declarationEmitPromise.ts, 8, 19)) ->apply : Symbol(Function.apply, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) +>apply : Symbol(Function.apply, Decl(lib.es5.d.ts, --, --)) >result : Symbol(result, Decl(declarationEmitPromise.ts, 7, 7)) let rfunc: typeof func & {} = func as any; // <- This is the only difference @@ -140,9 +140,9 @@ export async function runSampleBreaks( >T : Symbol(T, Decl(declarationEmitPromise.ts, 17, 16)) f.apply(this, result); ->f.apply : Symbol(Function.apply, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) +>f.apply : Symbol(Function.apply, Decl(lib.es5.d.ts, --, --)) >f : Symbol(f, Decl(declarationEmitPromise.ts, 17, 19)) ->apply : Symbol(Function.apply, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) +>apply : Symbol(Function.apply, Decl(lib.es5.d.ts, --, --)) >result : Symbol(result, Decl(declarationEmitPromise.ts, 16, 7)) let rfunc: typeof func = func as any; // <- This is the only difference diff --git a/tests/baselines/reference/declarationEmitPromise.types b/tests/baselines/reference/declarationEmitPromise.types index 0306c72762b..4edaa444326 100644 --- a/tests/baselines/reference/declarationEmitPromise.types +++ b/tests/baselines/reference/declarationEmitPromise.types @@ -78,10 +78,10 @@ export async function runSampleWorks( >T : T f.apply(this, result); ->f.apply(this, result) : T ->f.apply : { (this: (this: T, ...argArray: any[]) => U, thisArg: T, argArray?: any): U; (this: Function, thisArg: any, argArray?: any): any; } +>f.apply(this, result) : any +>f.apply : (this: Function, thisArg: any, argArray?: any) => any >f : (a: A, b?: B, c?: C, d?: D, e?: E) => T ->apply : { (this: (this: T, ...argArray: any[]) => U, thisArg: T, argArray?: any): U; (this: Function, thisArg: any, argArray?: any): any; } +>apply : (this: Function, thisArg: any, argArray?: any) => any >this : any >result : any @@ -163,10 +163,10 @@ export async function runSampleBreaks( >T : T f.apply(this, result); ->f.apply(this, result) : T ->f.apply : { (this: (this: T, ...argArray: any[]) => U, thisArg: T, argArray?: any): U; (this: Function, thisArg: any, argArray?: any): any; } +>f.apply(this, result) : any +>f.apply : (this: Function, thisArg: any, argArray?: any) => any >f : (a: A, b?: B, c?: C, d?: D, e?: E) => T ->apply : { (this: (this: T, ...argArray: any[]) => U, thisArg: T, argArray?: any): U; (this: Function, thisArg: any, argArray?: any): any; } +>apply : (this: Function, thisArg: any, argArray?: any) => any >this : any >result : any diff --git a/tests/baselines/reference/fatarrowfunctionsInFunctionParameterDefaults.symbols b/tests/baselines/reference/fatarrowfunctionsInFunctionParameterDefaults.symbols index b836bc88573..ea0ed9a605c 100644 --- a/tests/baselines/reference/fatarrowfunctionsInFunctionParameterDefaults.symbols +++ b/tests/baselines/reference/fatarrowfunctionsInFunctionParameterDefaults.symbols @@ -12,7 +12,7 @@ function fn(x = () => this, y = x()) { } fn.call(4); // Should be 4 ->fn.call : Symbol(Function.call, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>fn.call : Symbol(Function.call, Decl(lib.d.ts, --, --)) >fn : Symbol(fn, Decl(fatarrowfunctionsInFunctionParameterDefaults.ts, 0, 0)) ->call : Symbol(Function.call, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>call : Symbol(Function.call, Decl(lib.d.ts, --, --)) diff --git a/tests/baselines/reference/fatarrowfunctionsInFunctionParameterDefaults.types b/tests/baselines/reference/fatarrowfunctionsInFunctionParameterDefaults.types index 58c576bf24e..39cd994dcc1 100644 --- a/tests/baselines/reference/fatarrowfunctionsInFunctionParameterDefaults.types +++ b/tests/baselines/reference/fatarrowfunctionsInFunctionParameterDefaults.types @@ -16,8 +16,8 @@ function fn(x = () => this, y = x()) { fn.call(4); // Should be 4 >fn.call(4) : any ->fn.call : { (this: (this: T, ...argArray: any[]) => U, thisArg: T, ...argArray: any[]): U; (this: Function, thisArg: any, ...argArray: any[]): any; } +>fn.call : (this: Function, thisArg: any, ...argArray: any[]) => any >fn : (x?: () => any, y?: any) => any ->call : { (this: (this: T, ...argArray: any[]) => U, thisArg: T, ...argArray: any[]): U; (this: Function, thisArg: any, ...argArray: any[]): any; } +>call : (this: Function, thisArg: any, ...argArray: any[]) => any >4 : number diff --git a/tests/baselines/reference/functionType.symbols b/tests/baselines/reference/functionType.symbols index 65347d39b5a..30a5a7cc447 100644 --- a/tests/baselines/reference/functionType.symbols +++ b/tests/baselines/reference/functionType.symbols @@ -3,9 +3,9 @@ function salt() {} >salt : Symbol(salt, Decl(functionType.ts, 0, 0)) salt.apply("hello", []); ->salt.apply : Symbol(Function.apply, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>salt.apply : Symbol(Function.apply, Decl(lib.d.ts, --, --)) >salt : Symbol(salt, Decl(functionType.ts, 0, 0)) ->apply : Symbol(Function.apply, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>apply : Symbol(Function.apply, Decl(lib.d.ts, --, --)) (new Function("return 5"))(); >Function : Symbol(Function, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) diff --git a/tests/baselines/reference/functionType.types b/tests/baselines/reference/functionType.types index 9183ec4a13e..ac3d5c9944d 100644 --- a/tests/baselines/reference/functionType.types +++ b/tests/baselines/reference/functionType.types @@ -3,10 +3,10 @@ function salt() {} >salt : () => void salt.apply("hello", []); ->salt.apply("hello", []) : void ->salt.apply : { (this: (this: T, ...argArray: any[]) => U, thisArg: T, argArray?: any): U; (this: Function, thisArg: any, argArray?: any): any; } +>salt.apply("hello", []) : any +>salt.apply : (this: Function, thisArg: any, argArray?: any) => any >salt : () => void ->apply : { (this: (this: T, ...argArray: any[]) => U, thisArg: T, argArray?: any): U; (this: Function, thisArg: any, argArray?: any): any; } +>apply : (this: Function, thisArg: any, argArray?: any) => any >"hello" : string >[] : undefined[] diff --git a/tests/baselines/reference/genericTypeParameterEquivalence2.symbols b/tests/baselines/reference/genericTypeParameterEquivalence2.symbols index 1aa22b1e994..cd558fdd10a 100644 --- a/tests/baselines/reference/genericTypeParameterEquivalence2.symbols +++ b/tests/baselines/reference/genericTypeParameterEquivalence2.symbols @@ -24,9 +24,9 @@ function compose(f: (b: B) => C, g: (a:A) => B): (a:A) => C { return f(g.apply(null, a)); >f : Symbol(f, Decl(genericTypeParameterEquivalence2.ts, 1, 26)) ->g.apply : Symbol(Function.apply, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>g.apply : Symbol(Function.apply, Decl(lib.d.ts, --, --)) >g : Symbol(g, Decl(genericTypeParameterEquivalence2.ts, 1, 41)) ->apply : Symbol(Function.apply, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>apply : Symbol(Function.apply, Decl(lib.d.ts, --, --)) >a : Symbol(a, Decl(genericTypeParameterEquivalence2.ts, 2, 21)) }; diff --git a/tests/baselines/reference/genericTypeParameterEquivalence2.types b/tests/baselines/reference/genericTypeParameterEquivalence2.types index 9fdb03b0fbe..44e495088bc 100644 --- a/tests/baselines/reference/genericTypeParameterEquivalence2.types +++ b/tests/baselines/reference/genericTypeParameterEquivalence2.types @@ -26,10 +26,10 @@ function compose(f: (b: B) => C, g: (a:A) => B): (a:A) => C { return f(g.apply(null, a)); >f(g.apply(null, a)) : C >f : (b: B) => C ->g.apply(null, a) : B ->g.apply : { (this: (this: T, ...argArray: any[]) => U, thisArg: T, argArray?: any): U; (this: Function, thisArg: any, argArray?: any): any; } +>g.apply(null, a) : any +>g.apply : (this: Function, thisArg: any, argArray?: any) => any >g : (a: A) => B ->apply : { (this: (this: T, ...argArray: any[]) => U, thisArg: T, argArray?: any): U; (this: Function, thisArg: any, argArray?: any): any; } +>apply : (this: Function, thisArg: any, argArray?: any) => any >null : null >a : A diff --git a/tests/baselines/reference/jsFileCompilationRestParamJsDocFunction.symbols b/tests/baselines/reference/jsFileCompilationRestParamJsDocFunction.symbols index 62e47c8a3c4..f21653d475b 100644 --- a/tests/baselines/reference/jsFileCompilationRestParamJsDocFunction.symbols +++ b/tests/baselines/reference/jsFileCompilationRestParamJsDocFunction.symbols @@ -26,39 +26,39 @@ function apply(func, thisArg, args) { >length : Symbol(length, Decl(_apply.js, 12, 7)) case 0: return func.call(thisArg); ->func.call : Symbol(Function.call, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>func.call : Symbol(Function.call, Decl(lib.d.ts, --, --)) >func : Symbol(func, Decl(_apply.js, 11, 15)) ->call : Symbol(Function.call, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>call : Symbol(Function.call, Decl(lib.d.ts, --, --)) >thisArg : Symbol(thisArg, Decl(_apply.js, 11, 20)) case 1: return func.call(thisArg, args[0]); ->func.call : Symbol(Function.call, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>func.call : Symbol(Function.call, Decl(lib.d.ts, --, --)) >func : Symbol(func, Decl(_apply.js, 11, 15)) ->call : Symbol(Function.call, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>call : Symbol(Function.call, Decl(lib.d.ts, --, --)) >thisArg : Symbol(thisArg, Decl(_apply.js, 11, 20)) >args : Symbol(args, Decl(_apply.js, 11, 29)) case 2: return func.call(thisArg, args[0], args[1]); ->func.call : Symbol(Function.call, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>func.call : Symbol(Function.call, Decl(lib.d.ts, --, --)) >func : Symbol(func, Decl(_apply.js, 11, 15)) ->call : Symbol(Function.call, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>call : Symbol(Function.call, Decl(lib.d.ts, --, --)) >thisArg : Symbol(thisArg, Decl(_apply.js, 11, 20)) >args : Symbol(args, Decl(_apply.js, 11, 29)) >args : Symbol(args, Decl(_apply.js, 11, 29)) case 3: return func.call(thisArg, args[0], args[1], args[2]); ->func.call : Symbol(Function.call, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>func.call : Symbol(Function.call, Decl(lib.d.ts, --, --)) >func : Symbol(func, Decl(_apply.js, 11, 15)) ->call : Symbol(Function.call, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>call : Symbol(Function.call, Decl(lib.d.ts, --, --)) >thisArg : Symbol(thisArg, Decl(_apply.js, 11, 20)) >args : Symbol(args, Decl(_apply.js, 11, 29)) >args : Symbol(args, Decl(_apply.js, 11, 29)) >args : Symbol(args, Decl(_apply.js, 11, 29)) } return func.apply(thisArg, args); ->func.apply : Symbol(Function.apply, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>func.apply : Symbol(Function.apply, Decl(lib.d.ts, --, --)) >func : Symbol(func, Decl(_apply.js, 11, 15)) ->apply : Symbol(Function.apply, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>apply : Symbol(Function.apply, Decl(lib.d.ts, --, --)) >thisArg : Symbol(thisArg, Decl(_apply.js, 11, 20)) >args : Symbol(args, Decl(_apply.js, 11, 29)) } diff --git a/tests/baselines/reference/jsFileCompilationRestParamJsDocFunction.types b/tests/baselines/reference/jsFileCompilationRestParamJsDocFunction.types index 78d0fd1392b..fbfe9d3edae 100644 --- a/tests/baselines/reference/jsFileCompilationRestParamJsDocFunction.types +++ b/tests/baselines/reference/jsFileCompilationRestParamJsDocFunction.types @@ -28,17 +28,17 @@ function apply(func, thisArg, args) { case 0: return func.call(thisArg); >0 : number >func.call(thisArg) : any ->func.call : { (this: (this: T, ...argArray: any[]) => U, thisArg: T, ...argArray: any[]): U; (this: Function, thisArg: any, ...argArray: any[]): any; } +>func.call : (this: Function, thisArg: any, ...argArray: any[]) => any >func : Function ->call : { (this: (this: T, ...argArray: any[]) => U, thisArg: T, ...argArray: any[]): U; (this: Function, thisArg: any, ...argArray: any[]): any; } +>call : (this: Function, thisArg: any, ...argArray: any[]) => any >thisArg : any case 1: return func.call(thisArg, args[0]); >1 : number >func.call(thisArg, args[0]) : any ->func.call : { (this: (this: T, ...argArray: any[]) => U, thisArg: T, ...argArray: any[]): U; (this: Function, thisArg: any, ...argArray: any[]): any; } +>func.call : (this: Function, thisArg: any, ...argArray: any[]) => any >func : Function ->call : { (this: (this: T, ...argArray: any[]) => U, thisArg: T, ...argArray: any[]): U; (this: Function, thisArg: any, ...argArray: any[]): any; } +>call : (this: Function, thisArg: any, ...argArray: any[]) => any >thisArg : any >args[0] : any >args : any[] @@ -47,9 +47,9 @@ function apply(func, thisArg, args) { case 2: return func.call(thisArg, args[0], args[1]); >2 : number >func.call(thisArg, args[0], args[1]) : any ->func.call : { (this: (this: T, ...argArray: any[]) => U, thisArg: T, ...argArray: any[]): U; (this: Function, thisArg: any, ...argArray: any[]): any; } +>func.call : (this: Function, thisArg: any, ...argArray: any[]) => any >func : Function ->call : { (this: (this: T, ...argArray: any[]) => U, thisArg: T, ...argArray: any[]): U; (this: Function, thisArg: any, ...argArray: any[]): any; } +>call : (this: Function, thisArg: any, ...argArray: any[]) => any >thisArg : any >args[0] : any >args : any[] @@ -61,9 +61,9 @@ function apply(func, thisArg, args) { case 3: return func.call(thisArg, args[0], args[1], args[2]); >3 : number >func.call(thisArg, args[0], args[1], args[2]) : any ->func.call : { (this: (this: T, ...argArray: any[]) => U, thisArg: T, ...argArray: any[]): U; (this: Function, thisArg: any, ...argArray: any[]): any; } +>func.call : (this: Function, thisArg: any, ...argArray: any[]) => any >func : Function ->call : { (this: (this: T, ...argArray: any[]) => U, thisArg: T, ...argArray: any[]): U; (this: Function, thisArg: any, ...argArray: any[]): any; } +>call : (this: Function, thisArg: any, ...argArray: any[]) => any >thisArg : any >args[0] : any >args : any[] @@ -77,9 +77,9 @@ function apply(func, thisArg, args) { } return func.apply(thisArg, args); >func.apply(thisArg, args) : any ->func.apply : { (this: (this: T, ...argArray: any[]) => U, thisArg: T, argArray?: any): U; (this: Function, thisArg: any, argArray?: any): any; } +>func.apply : (this: Function, thisArg: any, argArray?: any) => any >func : Function ->apply : { (this: (this: T, ...argArray: any[]) => U, thisArg: T, argArray?: any): U; (this: Function, thisArg: any, argArray?: any): any; } +>apply : (this: Function, thisArg: any, argArray?: any) => any >thisArg : any >args : any[] } diff --git a/tests/baselines/reference/objectTypeWithCallSignatureAppearsToBeFunctionType.symbols b/tests/baselines/reference/objectTypeWithCallSignatureAppearsToBeFunctionType.symbols index 08d3d75e9dc..60b7b08397a 100644 --- a/tests/baselines/reference/objectTypeWithCallSignatureAppearsToBeFunctionType.symbols +++ b/tests/baselines/reference/objectTypeWithCallSignatureAppearsToBeFunctionType.symbols @@ -20,9 +20,9 @@ var r2b: (x: any, y?: any) => any = i.apply; >r2b : Symbol(r2b, Decl(objectTypeWithCallSignatureAppearsToBeFunctionType.ts, 9, 3)) >x : Symbol(x, Decl(objectTypeWithCallSignatureAppearsToBeFunctionType.ts, 9, 10)) >y : Symbol(y, Decl(objectTypeWithCallSignatureAppearsToBeFunctionType.ts, 9, 17)) ->i.apply : Symbol(Function.apply, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>i.apply : Symbol(Function.apply, Decl(lib.d.ts, --, --)) >i : Symbol(i, Decl(objectTypeWithCallSignatureAppearsToBeFunctionType.ts, 7, 3)) ->apply : Symbol(Function.apply, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>apply : Symbol(Function.apply, Decl(lib.d.ts, --, --)) var b: { >b : Symbol(b, Decl(objectTypeWithCallSignatureAppearsToBeFunctionType.ts, 11, 3)) @@ -38,7 +38,7 @@ var rb4: (x: any, y?: any) => any = b.apply; >rb4 : Symbol(rb4, Decl(objectTypeWithCallSignatureAppearsToBeFunctionType.ts, 16, 3)) >x : Symbol(x, Decl(objectTypeWithCallSignatureAppearsToBeFunctionType.ts, 16, 10)) >y : Symbol(y, Decl(objectTypeWithCallSignatureAppearsToBeFunctionType.ts, 16, 17)) ->b.apply : Symbol(Function.apply, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>b.apply : Symbol(Function.apply, Decl(lib.d.ts, --, --)) >b : Symbol(b, Decl(objectTypeWithCallSignatureAppearsToBeFunctionType.ts, 11, 3)) ->apply : Symbol(Function.apply, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>apply : Symbol(Function.apply, Decl(lib.d.ts, --, --)) diff --git a/tests/baselines/reference/objectTypeWithCallSignatureAppearsToBeFunctionType.types b/tests/baselines/reference/objectTypeWithCallSignatureAppearsToBeFunctionType.types index 496734c9183..80408cff962 100644 --- a/tests/baselines/reference/objectTypeWithCallSignatureAppearsToBeFunctionType.types +++ b/tests/baselines/reference/objectTypeWithCallSignatureAppearsToBeFunctionType.types @@ -21,9 +21,9 @@ var r2b: (x: any, y?: any) => any = i.apply; >r2b : (x: any, y?: any) => any >x : any >y : any ->i.apply : { (this: (this: T, ...argArray: any[]) => U, thisArg: T, argArray?: any): U; (this: Function, thisArg: any, argArray?: any): any; } +>i.apply : (this: Function, thisArg: any, argArray?: any) => any >i : I ->apply : { (this: (this: T, ...argArray: any[]) => U, thisArg: T, argArray?: any): U; (this: Function, thisArg: any, argArray?: any): any; } +>apply : (this: Function, thisArg: any, argArray?: any) => any var b: { >b : () => void @@ -40,7 +40,7 @@ var rb4: (x: any, y?: any) => any = b.apply; >rb4 : (x: any, y?: any) => any >x : any >y : any ->b.apply : { (this: (this: T, ...argArray: any[]) => U, thisArg: T, argArray?: any): U; (this: Function, thisArg: any, argArray?: any): any; } +>b.apply : (this: Function, thisArg: any, argArray?: any) => any >b : () => void ->apply : { (this: (this: T, ...argArray: any[]) => U, thisArg: T, argArray?: any): U; (this: Function, thisArg: any, argArray?: any): any; } +>apply : (this: Function, thisArg: any, argArray?: any) => any diff --git a/tests/baselines/reference/returnTypeParameterWithModules.symbols b/tests/baselines/reference/returnTypeParameterWithModules.symbols index e3b7c50948f..7f8fab382a3 100644 --- a/tests/baselines/reference/returnTypeParameterWithModules.symbols +++ b/tests/baselines/reference/returnTypeParameterWithModules.symbols @@ -12,13 +12,13 @@ module M1 { >A : Symbol(A, Decl(returnTypeParameterWithModules.ts, 1, 27)) return Array.prototype.reduce.apply(ar, e ? [f, e] : [f]); ->Array.prototype.reduce.apply : Symbol(Function.apply, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>Array.prototype.reduce.apply : Symbol(Function.apply, Decl(lib.d.ts, --, --)) >Array.prototype.reduce : Symbol(Array.reduce, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) >Array.prototype : Symbol(ArrayConstructor.prototype, Decl(lib.d.ts, --, --)) >Array : Symbol(Array, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) >prototype : Symbol(ArrayConstructor.prototype, Decl(lib.d.ts, --, --)) >reduce : Symbol(Array.reduce, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) ->apply : Symbol(Function.apply, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>apply : Symbol(Function.apply, Decl(lib.d.ts, --, --)) >ar : Symbol(ar, Decl(returnTypeParameterWithModules.ts, 1, 30)) >e : Symbol(e, Decl(returnTypeParameterWithModules.ts, 1, 36)) >f : Symbol(f, Decl(returnTypeParameterWithModules.ts, 1, 33)) diff --git a/tests/baselines/reference/returnTypeParameterWithModules.types b/tests/baselines/reference/returnTypeParameterWithModules.types index ffb058daa08..584c962a170 100644 --- a/tests/baselines/reference/returnTypeParameterWithModules.types +++ b/tests/baselines/reference/returnTypeParameterWithModules.types @@ -13,13 +13,13 @@ module M1 { return Array.prototype.reduce.apply(ar, e ? [f, e] : [f]); >Array.prototype.reduce.apply(ar, e ? [f, e] : [f]) : any ->Array.prototype.reduce.apply : { (this: (this: T, ...argArray: any[]) => U, thisArg: T, argArray?: any): U; (this: Function, thisArg: any, argArray?: any): any; } +>Array.prototype.reduce.apply : (this: Function, thisArg: any, argArray?: any) => any >Array.prototype.reduce : { (callbackfn: (previousValue: any, currentValue: any, currentIndex: number, array: any[]) => any, initialValue?: any): any; (callbackfn: (previousValue: U, currentValue: any, currentIndex: number, array: any[]) => U, initialValue: U): U; } >Array.prototype : any[] >Array : ArrayConstructor >prototype : any[] >reduce : { (callbackfn: (previousValue: any, currentValue: any, currentIndex: number, array: any[]) => any, initialValue?: any): any; (callbackfn: (previousValue: U, currentValue: any, currentIndex: number, array: any[]) => U, initialValue: U): U; } ->apply : { (this: (this: T, ...argArray: any[]) => U, thisArg: T, argArray?: any): U; (this: Function, thisArg: any, argArray?: any): any; } +>apply : (this: Function, thisArg: any, argArray?: any) => any >ar : any >e ? [f, e] : [f] : any[] >e : any diff --git a/tests/baselines/reference/thisTypeInFunctions2.js b/tests/baselines/reference/thisTypeInFunctions2.js new file mode 100644 index 00000000000..7fc52877191 --- /dev/null +++ b/tests/baselines/reference/thisTypeInFunctions2.js @@ -0,0 +1,51 @@ +//// [thisTypeInFunctions2.ts] +interface Arguments { + init?: (this: void) => void; + willDestroy?: (this: any) => void; + [propName: string]: number | string | boolean | symbol | undefined | null | {} | ((this: any, ...args:any[]) => any); +} +declare function extend(arguments: Arguments): void; +class Mixin { + stuff: number; +} + +extend({ + init() { + this + }, + mine: 12, + bar() { + this.init(); + }, + foo() { + this.bar; + this.url + this.handler() + this.baz + this.willDestroy + } +}) + + +//// [thisTypeInFunctions2.js] +var Mixin = (function () { + function Mixin() { + } + return Mixin; +}()); +extend({ + init: function () { + this; + }, + mine: 12, + bar: function () { + this.init(); + }, + foo: function () { + this.bar; + this.url; + this.handler(); + this.baz; + this.willDestroy; + } +}); diff --git a/tests/baselines/reference/thisTypeInFunctions2.symbols b/tests/baselines/reference/thisTypeInFunctions2.symbols new file mode 100644 index 00000000000..5e186e9485d --- /dev/null +++ b/tests/baselines/reference/thisTypeInFunctions2.symbols @@ -0,0 +1,56 @@ +=== tests/cases/conformance/types/thisType/thisTypeInFunctions2.ts === +interface Arguments { +>Arguments : Symbol(Arguments, Decl(thisTypeInFunctions2.ts, 0, 0)) + + init?: (this: void) => void; +>init : Symbol(Arguments.init, Decl(thisTypeInFunctions2.ts, 0, 21)) +>this : Symbol(this, Decl(thisTypeInFunctions2.ts, 1, 12)) + + willDestroy?: (this: any) => void; +>willDestroy : Symbol(Arguments.willDestroy, Decl(thisTypeInFunctions2.ts, 1, 32)) +>this : Symbol(this, Decl(thisTypeInFunctions2.ts, 2, 19)) + + [propName: string]: number | string | boolean | symbol | undefined | null | {} | ((this: any, ...args:any[]) => any); +>propName : Symbol(propName, Decl(thisTypeInFunctions2.ts, 3, 5)) +>this : Symbol(this, Decl(thisTypeInFunctions2.ts, 3, 87)) +>args : Symbol(args, Decl(thisTypeInFunctions2.ts, 3, 97)) +} +declare function extend(arguments: Arguments): void; +>extend : Symbol(extend, Decl(thisTypeInFunctions2.ts, 4, 1)) +>arguments : Symbol(arguments, Decl(thisTypeInFunctions2.ts, 5, 24)) +>Arguments : Symbol(Arguments, Decl(thisTypeInFunctions2.ts, 0, 0)) + +class Mixin { +>Mixin : Symbol(Mixin, Decl(thisTypeInFunctions2.ts, 5, 52)) + + stuff: number; +>stuff : Symbol(Mixin.stuff, Decl(thisTypeInFunctions2.ts, 6, 13)) +} + +extend({ +>extend : Symbol(extend, Decl(thisTypeInFunctions2.ts, 4, 1)) + + init() { +>init : Symbol(init, Decl(thisTypeInFunctions2.ts, 10, 8)) + + this + }, + mine: 12, +>mine : Symbol(mine, Decl(thisTypeInFunctions2.ts, 13, 6)) + + bar() { +>bar : Symbol(bar, Decl(thisTypeInFunctions2.ts, 14, 13)) + + this.init(); + }, + foo() { +>foo : Symbol(foo, Decl(thisTypeInFunctions2.ts, 17, 6)) + + this.bar; + this.url + this.handler() + this.baz + this.willDestroy + } +}) + diff --git a/tests/baselines/reference/thisTypeInFunctions2.types b/tests/baselines/reference/thisTypeInFunctions2.types new file mode 100644 index 00000000000..3e3e9123549 --- /dev/null +++ b/tests/baselines/reference/thisTypeInFunctions2.types @@ -0,0 +1,87 @@ +=== tests/cases/conformance/types/thisType/thisTypeInFunctions2.ts === +interface Arguments { +>Arguments : Arguments + + init?: (this: void) => void; +>init : (this: void) => void +>this : void + + willDestroy?: (this: any) => void; +>willDestroy : (this: any) => void +>this : any + + [propName: string]: number | string | boolean | symbol | undefined | null | {} | ((this: any, ...args:any[]) => any); +>propName : string +>null : null +>this : any +>args : any[] +} +declare function extend(arguments: Arguments): void; +>extend : (arguments: Arguments) => void +>arguments : Arguments +>Arguments : Arguments + +class Mixin { +>Mixin : Mixin + + stuff: number; +>stuff : number +} + +extend({ +>extend({ init() { this }, mine: 12, bar() { this.init(); }, foo() { this.bar; this.url this.handler() this.baz this.willDestroy }}) : void +>extend : (arguments: Arguments) => void +>{ init() { this }, mine: 12, bar() { this.init(); }, foo() { this.bar; this.url this.handler() this.baz this.willDestroy }} : { init(): void; mine: number; bar(): void; foo(): void; } + + init() { +>init : () => void + + this +>this : void + + }, + mine: 12, +>mine : number +>12 : number + + bar() { +>bar : () => void + + this.init(); +>this.init() : any +>this.init : any +>this : any +>init : any + + }, + foo() { +>foo : () => void + + this.bar; +>this.bar : any +>this : any +>bar : any + + this.url +>this.url : any +>this : any +>url : any + + this.handler() +>this.handler() : any +>this.handler : any +>this : any +>handler : any + + this.baz +>this.baz : any +>this : any +>baz : any + + this.willDestroy +>this.willDestroy : any +>this : any +>willDestroy : any + } +}) + diff --git a/tests/cases/conformance/types/thisType/thisTypeInFunctions2.ts b/tests/cases/conformance/types/thisType/thisTypeInFunctions2.ts new file mode 100644 index 00000000000..c33c5062249 --- /dev/null +++ b/tests/cases/conformance/types/thisType/thisTypeInFunctions2.ts @@ -0,0 +1,26 @@ +interface Arguments { + init?: (this: void) => void; + willDestroy?: (this: any) => void; + [propName: string]: number | string | boolean | symbol | undefined | null | {} | ((this: any, ...args:any[]) => any); +} +declare function extend(arguments: Arguments): void; +class Mixin { + stuff: number; +} + +extend({ + init() { + this + }, + mine: 12, + bar() { + this.init(); + }, + foo() { + this.bar; + this.url + this.handler() + this.baz + this.willDestroy + } +}) From 3520c6e833a6b95baa81235db4de66bfd5dc79c5 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Thu, 28 Apr 2016 09:02:20 -0700 Subject: [PATCH 27/52] Remove incorrectly added extra test --- .../reference/thisTypeInFunctions2.js | 51 ----------- .../reference/thisTypeInFunctions2.symbols | 56 ------------ .../reference/thisTypeInFunctions2.types | 87 ------------------- .../types/thisType/thisTypeInFunctions2.ts | 26 ------ 4 files changed, 220 deletions(-) delete mode 100644 tests/baselines/reference/thisTypeInFunctions2.js delete mode 100644 tests/baselines/reference/thisTypeInFunctions2.symbols delete mode 100644 tests/baselines/reference/thisTypeInFunctions2.types delete mode 100644 tests/cases/conformance/types/thisType/thisTypeInFunctions2.ts diff --git a/tests/baselines/reference/thisTypeInFunctions2.js b/tests/baselines/reference/thisTypeInFunctions2.js deleted file mode 100644 index 7fc52877191..00000000000 --- a/tests/baselines/reference/thisTypeInFunctions2.js +++ /dev/null @@ -1,51 +0,0 @@ -//// [thisTypeInFunctions2.ts] -interface Arguments { - init?: (this: void) => void; - willDestroy?: (this: any) => void; - [propName: string]: number | string | boolean | symbol | undefined | null | {} | ((this: any, ...args:any[]) => any); -} -declare function extend(arguments: Arguments): void; -class Mixin { - stuff: number; -} - -extend({ - init() { - this - }, - mine: 12, - bar() { - this.init(); - }, - foo() { - this.bar; - this.url - this.handler() - this.baz - this.willDestroy - } -}) - - -//// [thisTypeInFunctions2.js] -var Mixin = (function () { - function Mixin() { - } - return Mixin; -}()); -extend({ - init: function () { - this; - }, - mine: 12, - bar: function () { - this.init(); - }, - foo: function () { - this.bar; - this.url; - this.handler(); - this.baz; - this.willDestroy; - } -}); diff --git a/tests/baselines/reference/thisTypeInFunctions2.symbols b/tests/baselines/reference/thisTypeInFunctions2.symbols deleted file mode 100644 index 5e186e9485d..00000000000 --- a/tests/baselines/reference/thisTypeInFunctions2.symbols +++ /dev/null @@ -1,56 +0,0 @@ -=== tests/cases/conformance/types/thisType/thisTypeInFunctions2.ts === -interface Arguments { ->Arguments : Symbol(Arguments, Decl(thisTypeInFunctions2.ts, 0, 0)) - - init?: (this: void) => void; ->init : Symbol(Arguments.init, Decl(thisTypeInFunctions2.ts, 0, 21)) ->this : Symbol(this, Decl(thisTypeInFunctions2.ts, 1, 12)) - - willDestroy?: (this: any) => void; ->willDestroy : Symbol(Arguments.willDestroy, Decl(thisTypeInFunctions2.ts, 1, 32)) ->this : Symbol(this, Decl(thisTypeInFunctions2.ts, 2, 19)) - - [propName: string]: number | string | boolean | symbol | undefined | null | {} | ((this: any, ...args:any[]) => any); ->propName : Symbol(propName, Decl(thisTypeInFunctions2.ts, 3, 5)) ->this : Symbol(this, Decl(thisTypeInFunctions2.ts, 3, 87)) ->args : Symbol(args, Decl(thisTypeInFunctions2.ts, 3, 97)) -} -declare function extend(arguments: Arguments): void; ->extend : Symbol(extend, Decl(thisTypeInFunctions2.ts, 4, 1)) ->arguments : Symbol(arguments, Decl(thisTypeInFunctions2.ts, 5, 24)) ->Arguments : Symbol(Arguments, Decl(thisTypeInFunctions2.ts, 0, 0)) - -class Mixin { ->Mixin : Symbol(Mixin, Decl(thisTypeInFunctions2.ts, 5, 52)) - - stuff: number; ->stuff : Symbol(Mixin.stuff, Decl(thisTypeInFunctions2.ts, 6, 13)) -} - -extend({ ->extend : Symbol(extend, Decl(thisTypeInFunctions2.ts, 4, 1)) - - init() { ->init : Symbol(init, Decl(thisTypeInFunctions2.ts, 10, 8)) - - this - }, - mine: 12, ->mine : Symbol(mine, Decl(thisTypeInFunctions2.ts, 13, 6)) - - bar() { ->bar : Symbol(bar, Decl(thisTypeInFunctions2.ts, 14, 13)) - - this.init(); - }, - foo() { ->foo : Symbol(foo, Decl(thisTypeInFunctions2.ts, 17, 6)) - - this.bar; - this.url - this.handler() - this.baz - this.willDestroy - } -}) - diff --git a/tests/baselines/reference/thisTypeInFunctions2.types b/tests/baselines/reference/thisTypeInFunctions2.types deleted file mode 100644 index 3e3e9123549..00000000000 --- a/tests/baselines/reference/thisTypeInFunctions2.types +++ /dev/null @@ -1,87 +0,0 @@ -=== tests/cases/conformance/types/thisType/thisTypeInFunctions2.ts === -interface Arguments { ->Arguments : Arguments - - init?: (this: void) => void; ->init : (this: void) => void ->this : void - - willDestroy?: (this: any) => void; ->willDestroy : (this: any) => void ->this : any - - [propName: string]: number | string | boolean | symbol | undefined | null | {} | ((this: any, ...args:any[]) => any); ->propName : string ->null : null ->this : any ->args : any[] -} -declare function extend(arguments: Arguments): void; ->extend : (arguments: Arguments) => void ->arguments : Arguments ->Arguments : Arguments - -class Mixin { ->Mixin : Mixin - - stuff: number; ->stuff : number -} - -extend({ ->extend({ init() { this }, mine: 12, bar() { this.init(); }, foo() { this.bar; this.url this.handler() this.baz this.willDestroy }}) : void ->extend : (arguments: Arguments) => void ->{ init() { this }, mine: 12, bar() { this.init(); }, foo() { this.bar; this.url this.handler() this.baz this.willDestroy }} : { init(): void; mine: number; bar(): void; foo(): void; } - - init() { ->init : () => void - - this ->this : void - - }, - mine: 12, ->mine : number ->12 : number - - bar() { ->bar : () => void - - this.init(); ->this.init() : any ->this.init : any ->this : any ->init : any - - }, - foo() { ->foo : () => void - - this.bar; ->this.bar : any ->this : any ->bar : any - - this.url ->this.url : any ->this : any ->url : any - - this.handler() ->this.handler() : any ->this.handler : any ->this : any ->handler : any - - this.baz ->this.baz : any ->this : any ->baz : any - - this.willDestroy ->this.willDestroy : any ->this : any ->willDestroy : any - } -}) - diff --git a/tests/cases/conformance/types/thisType/thisTypeInFunctions2.ts b/tests/cases/conformance/types/thisType/thisTypeInFunctions2.ts deleted file mode 100644 index c33c5062249..00000000000 --- a/tests/cases/conformance/types/thisType/thisTypeInFunctions2.ts +++ /dev/null @@ -1,26 +0,0 @@ -interface Arguments { - init?: (this: void) => void; - willDestroy?: (this: any) => void; - [propName: string]: number | string | boolean | symbol | undefined | null | {} | ((this: any, ...args:any[]) => any); -} -declare function extend(arguments: Arguments): void; -class Mixin { - stuff: number; -} - -extend({ - init() { - this - }, - mine: 12, - bar() { - this.init(); - }, - foo() { - this.bar; - this.url - this.handler() - this.baz - this.willDestroy - } -}) From 3a74f483babbeccdad3a3aec6a2f40410f350ab3 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Thu, 28 Apr 2016 10:09:04 -0700 Subject: [PATCH 28/52] `this` in object literals intersects contextual type and literal type --- src/compiler/checker.ts | 47 ++++++---- .../reference/thisTypeInFunctions2.js | 51 +++++++++++ .../reference/thisTypeInFunctions2.symbols | 56 ++++++++++++ .../reference/thisTypeInFunctions2.types | 87 +++++++++++++++++++ .../types/thisType/thisTypeInFunctions2.ts | 26 ++++++ 5 files changed, 248 insertions(+), 19 deletions(-) create mode 100644 tests/baselines/reference/thisTypeInFunctions2.js create mode 100644 tests/baselines/reference/thisTypeInFunctions2.symbols create mode 100644 tests/baselines/reference/thisTypeInFunctions2.types create mode 100644 tests/cases/conformance/types/thisType/thisTypeInFunctions2.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 516a01ecf44..2f3bd4b285f 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -8179,6 +8179,21 @@ namespace ts { captureLexicalThis(node, container); } if (isFunctionLike(container)) { + // If this is a function in a JS file, it might be a class method. Check if it's the RHS + // of a x.prototype.y = function [name]() { .... } + if (container.kind === SyntaxKind.FunctionExpression && + isInJavaScriptFile(container.parent) && + getSpecialPropertyAssignmentKind(container.parent) === SpecialPropertyAssignmentKind.PrototypeProperty) { + // Get the 'x' of 'x.prototype.y = f' (here, 'f' is 'container') + const className = (((container.parent as BinaryExpression) // x.prototype.y = f + .left as PropertyAccessExpression) // x.prototype.y + .expression as PropertyAccessExpression) // x.prototype + .expression; // x + const classSymbol = checkExpression(className).symbol; + if (classSymbol && classSymbol.members && (classSymbol.flags & SymbolFlags.Function)) { + return getInferredClassType(classSymbol); + } + } const type = getContextuallyTypedThisType(container); if (type) { return type; @@ -8190,9 +8205,13 @@ namespace ts { if (container.parent && container.parent.kind === SyntaxKind.ObjectLiteralExpression) { // Note: this works because object literal methods are deferred, // which means that the type of the containing object literal is already known. - const type = checkExpressionCached(container.parent); - if (type) { - return type; + const contextualType = getContextualType(container.parent as ObjectLiteralExpression); + const literalType = checkExpressionCached(container.parent); + if (contextualType && literalType) { + return getIntersectionType([contextualType, literalType]); + } + else if (contextualType || literalType) { + return contextualType || literalType; } } } @@ -8207,22 +8226,6 @@ namespace ts { if (type && type !== unknownType) { return type; } - - // If this is a function in a JS file, it might be a class method. Check if it's the RHS - // of a x.prototype.y = function [name]() { .... } - if (container.kind === SyntaxKind.FunctionExpression) { - if (getSpecialPropertyAssignmentKind(container.parent) === SpecialPropertyAssignmentKind.PrototypeProperty) { - // Get the 'x' of 'x.prototype.y = f' (here, 'f' is 'container') - const className = (((container.parent as BinaryExpression) // x.prototype.y = f - .left as PropertyAccessExpression) // x.prototype.y - .expression as PropertyAccessExpression) // x.prototype - .expression; // x - const classSymbol = checkExpression(className).symbol; - if (classSymbol && classSymbol.members && (classSymbol.flags & SymbolFlags.Function)) { - return getInferredClassType(classSymbol); - } - } - } } if (compilerOptions.noImplicitThis) { @@ -8450,6 +8453,12 @@ namespace ts { if ((isFunctionExpressionOrArrowFunction(func) || isObjectLiteralMethod(func)) && isContextSensitive(func) && func.kind !== SyntaxKind.ArrowFunction) { + const type = isObjectLiteralMethod(func) + ? getContextualTypeForObjectLiteralMethod(func) + : getApparentTypeOfContextualType(func); + if (type === anyType) { + return anyType; + } const contextualSignature = getContextualSignature(func); if (contextualSignature) { return contextualSignature.thisType; diff --git a/tests/baselines/reference/thisTypeInFunctions2.js b/tests/baselines/reference/thisTypeInFunctions2.js new file mode 100644 index 00000000000..7fc52877191 --- /dev/null +++ b/tests/baselines/reference/thisTypeInFunctions2.js @@ -0,0 +1,51 @@ +//// [thisTypeInFunctions2.ts] +interface Arguments { + init?: (this: void) => void; + willDestroy?: (this: any) => void; + [propName: string]: number | string | boolean | symbol | undefined | null | {} | ((this: any, ...args:any[]) => any); +} +declare function extend(arguments: Arguments): void; +class Mixin { + stuff: number; +} + +extend({ + init() { + this + }, + mine: 12, + bar() { + this.init(); + }, + foo() { + this.bar; + this.url + this.handler() + this.baz + this.willDestroy + } +}) + + +//// [thisTypeInFunctions2.js] +var Mixin = (function () { + function Mixin() { + } + return Mixin; +}()); +extend({ + init: function () { + this; + }, + mine: 12, + bar: function () { + this.init(); + }, + foo: function () { + this.bar; + this.url; + this.handler(); + this.baz; + this.willDestroy; + } +}); diff --git a/tests/baselines/reference/thisTypeInFunctions2.symbols b/tests/baselines/reference/thisTypeInFunctions2.symbols new file mode 100644 index 00000000000..5e186e9485d --- /dev/null +++ b/tests/baselines/reference/thisTypeInFunctions2.symbols @@ -0,0 +1,56 @@ +=== tests/cases/conformance/types/thisType/thisTypeInFunctions2.ts === +interface Arguments { +>Arguments : Symbol(Arguments, Decl(thisTypeInFunctions2.ts, 0, 0)) + + init?: (this: void) => void; +>init : Symbol(Arguments.init, Decl(thisTypeInFunctions2.ts, 0, 21)) +>this : Symbol(this, Decl(thisTypeInFunctions2.ts, 1, 12)) + + willDestroy?: (this: any) => void; +>willDestroy : Symbol(Arguments.willDestroy, Decl(thisTypeInFunctions2.ts, 1, 32)) +>this : Symbol(this, Decl(thisTypeInFunctions2.ts, 2, 19)) + + [propName: string]: number | string | boolean | symbol | undefined | null | {} | ((this: any, ...args:any[]) => any); +>propName : Symbol(propName, Decl(thisTypeInFunctions2.ts, 3, 5)) +>this : Symbol(this, Decl(thisTypeInFunctions2.ts, 3, 87)) +>args : Symbol(args, Decl(thisTypeInFunctions2.ts, 3, 97)) +} +declare function extend(arguments: Arguments): void; +>extend : Symbol(extend, Decl(thisTypeInFunctions2.ts, 4, 1)) +>arguments : Symbol(arguments, Decl(thisTypeInFunctions2.ts, 5, 24)) +>Arguments : Symbol(Arguments, Decl(thisTypeInFunctions2.ts, 0, 0)) + +class Mixin { +>Mixin : Symbol(Mixin, Decl(thisTypeInFunctions2.ts, 5, 52)) + + stuff: number; +>stuff : Symbol(Mixin.stuff, Decl(thisTypeInFunctions2.ts, 6, 13)) +} + +extend({ +>extend : Symbol(extend, Decl(thisTypeInFunctions2.ts, 4, 1)) + + init() { +>init : Symbol(init, Decl(thisTypeInFunctions2.ts, 10, 8)) + + this + }, + mine: 12, +>mine : Symbol(mine, Decl(thisTypeInFunctions2.ts, 13, 6)) + + bar() { +>bar : Symbol(bar, Decl(thisTypeInFunctions2.ts, 14, 13)) + + this.init(); + }, + foo() { +>foo : Symbol(foo, Decl(thisTypeInFunctions2.ts, 17, 6)) + + this.bar; + this.url + this.handler() + this.baz + this.willDestroy + } +}) + diff --git a/tests/baselines/reference/thisTypeInFunctions2.types b/tests/baselines/reference/thisTypeInFunctions2.types new file mode 100644 index 00000000000..3e3e9123549 --- /dev/null +++ b/tests/baselines/reference/thisTypeInFunctions2.types @@ -0,0 +1,87 @@ +=== tests/cases/conformance/types/thisType/thisTypeInFunctions2.ts === +interface Arguments { +>Arguments : Arguments + + init?: (this: void) => void; +>init : (this: void) => void +>this : void + + willDestroy?: (this: any) => void; +>willDestroy : (this: any) => void +>this : any + + [propName: string]: number | string | boolean | symbol | undefined | null | {} | ((this: any, ...args:any[]) => any); +>propName : string +>null : null +>this : any +>args : any[] +} +declare function extend(arguments: Arguments): void; +>extend : (arguments: Arguments) => void +>arguments : Arguments +>Arguments : Arguments + +class Mixin { +>Mixin : Mixin + + stuff: number; +>stuff : number +} + +extend({ +>extend({ init() { this }, mine: 12, bar() { this.init(); }, foo() { this.bar; this.url this.handler() this.baz this.willDestroy }}) : void +>extend : (arguments: Arguments) => void +>{ init() { this }, mine: 12, bar() { this.init(); }, foo() { this.bar; this.url this.handler() this.baz this.willDestroy }} : { init(): void; mine: number; bar(): void; foo(): void; } + + init() { +>init : () => void + + this +>this : void + + }, + mine: 12, +>mine : number +>12 : number + + bar() { +>bar : () => void + + this.init(); +>this.init() : any +>this.init : any +>this : any +>init : any + + }, + foo() { +>foo : () => void + + this.bar; +>this.bar : any +>this : any +>bar : any + + this.url +>this.url : any +>this : any +>url : any + + this.handler() +>this.handler() : any +>this.handler : any +>this : any +>handler : any + + this.baz +>this.baz : any +>this : any +>baz : any + + this.willDestroy +>this.willDestroy : any +>this : any +>willDestroy : any + } +}) + diff --git a/tests/cases/conformance/types/thisType/thisTypeInFunctions2.ts b/tests/cases/conformance/types/thisType/thisTypeInFunctions2.ts new file mode 100644 index 00000000000..c33c5062249 --- /dev/null +++ b/tests/cases/conformance/types/thisType/thisTypeInFunctions2.ts @@ -0,0 +1,26 @@ +interface Arguments { + init?: (this: void) => void; + willDestroy?: (this: any) => void; + [propName: string]: number | string | boolean | symbol | undefined | null | {} | ((this: any, ...args:any[]) => any); +} +declare function extend(arguments: Arguments): void; +class Mixin { + stuff: number; +} + +extend({ + init() { + this + }, + mine: 12, + bar() { + this.init(); + }, + foo() { + this.bar; + this.url + this.handler() + this.baz + this.willDestroy + } +}) From 88854d2c0f50ce39ef8357b0379bb1fa0d704ba5 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Thu, 28 Apr 2016 13:17:06 -0700 Subject: [PATCH 29/52] Address PR comments. 1. Remove intersection code. The any-defaulting code means that it's never hit. 2. Remove some code duplication. --- src/compiler/checker.ts | 74 +++++++++++++++++++---------------------- 1 file changed, 35 insertions(+), 39 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 2f3bd4b285f..7a301884b4e 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5508,6 +5508,10 @@ namespace ts { return !node.typeParameters && areAllParametersUntyped && !isNullaryArrow; } + function isContextSensitiveFunctionOrObjectLiteralMethod(func: Node): func is FunctionExpression | MethodDeclaration { + return (isFunctionExpressionOrArrowFunction(func) || isObjectLiteralMethod(func)) && isContextSensitiveFunctionLikeDeclaration(func); + } + function getTypeWithoutSignatures(type: Type): Type { if (type.flags & TypeFlags.ObjectType) { const resolved = resolveStructuredTypeMembers(type); @@ -8205,13 +8209,9 @@ namespace ts { if (container.parent && container.parent.kind === SyntaxKind.ObjectLiteralExpression) { // Note: this works because object literal methods are deferred, // which means that the type of the containing object literal is already known. - const contextualType = getContextualType(container.parent as ObjectLiteralExpression); - const literalType = checkExpressionCached(container.parent); - if (contextualType && literalType) { - return getIntersectionType([contextualType, literalType]); - } - else if (contextualType || literalType) { - return contextualType || literalType; + const type = checkExpressionCached(container.parent); + if (type) { + return type; } } } @@ -8450,19 +8450,14 @@ namespace ts { } function getContextuallyTypedThisType(func: FunctionLikeDeclaration): Type { - if ((isFunctionExpressionOrArrowFunction(func) || isObjectLiteralMethod(func)) && - isContextSensitive(func) && - func.kind !== SyntaxKind.ArrowFunction) { - const type = isObjectLiteralMethod(func) - ? getContextualTypeForObjectLiteralMethod(func) - : getApparentTypeOfContextualType(func); - if (type === anyType) { - return anyType; - } + if (isContextSensitiveFunctionOrObjectLiteralMethod(func) && func.kind !== SyntaxKind.ArrowFunction) { const contextualSignature = getContextualSignature(func); if (contextualSignature) { return contextualSignature.thisType; } + else if (getContextualTypeForFunctionLikeDeclaration(func) === anyType) { + return anyType; + } } return undefined; @@ -8471,24 +8466,21 @@ namespace ts { // Return contextual type of parameter or undefined if no contextual type is available function getContextuallyTypedParameterType(parameter: ParameterDeclaration): Type { const func = parameter.parent; - if (isFunctionExpressionOrArrowFunction(func) || isObjectLiteralMethod(func)) { - if (isContextSensitive(func)) { - const contextualSignature = getContextualSignature(func); - if (contextualSignature) { + if (isContextSensitiveFunctionOrObjectLiteralMethod(func)) { + const contextualSignature = getContextualSignature(func); + if (contextualSignature) { + const funcHasRestParameters = hasRestParameter(func); + const len = func.parameters.length - (funcHasRestParameters ? 1 : 0); + const indexOfParameter = indexOf(func.parameters, parameter); + if (indexOfParameter < len) { + return getTypeAtPosition(contextualSignature, indexOfParameter); + } - const funcHasRestParameters = hasRestParameter(func); - const len = func.parameters.length - (funcHasRestParameters ? 1 : 0); - const indexOfParameter = indexOf(func.parameters, parameter); - if (indexOfParameter < len) { - return getTypeAtPosition(contextualSignature, indexOfParameter); - } - - // If last parameter is contextually rest parameter get its type - if (funcHasRestParameters && - indexOfParameter === (func.parameters.length - 1) && - isRestParameterIndex(contextualSignature, func.parameters.length - 1)) { - return getTypeOfSymbol(lastOrUndefined(contextualSignature.parameters)); - } + // If last parameter is contextually rest parameter get its type + if (funcHasRestParameters && + indexOfParameter === (func.parameters.length - 1) && + isRestParameterIndex(contextualSignature, func.parameters.length - 1)) { + return getTypeOfSymbol(lastOrUndefined(contextualSignature.parameters)); } } } @@ -8496,9 +8488,9 @@ namespace ts { } // In a variable, parameter or property declaration with a type annotation, - // the contextual type of an initializer expression is the type of the variable, parameter or property. - // Otherwise, in a parameter declaration of a contextually typed function expression, - // the contextual type of an initializer expression is the contextual type of the parameter. + // the contextual type of an initializer expression is the type of the variable, parameter or property. + // Otherwise, in a parameter declaration of a contextually typed function expression, + // the contextual type of an initializer expression is the contextual type of the parameter. // Otherwise, in a variable or parameter declaration with a binding pattern name, // the contextual type of an initializer expression is the type implied by the binding pattern. // Otherwise, in a binding pattern inside a variable or parameter declaration, @@ -8852,6 +8844,12 @@ namespace ts { : undefined; } + function getContextualTypeForFunctionLikeDeclaration(node: FunctionExpression | MethodDeclaration) { + return isObjectLiteralMethod(node) + ? getContextualTypeForObjectLiteralMethod(node) + : getApparentTypeOfContextualType(node); + } + // Return the contextual signature for a given expression node. A contextual type provides a // contextual signature if it has a single call signature and if that call signature is non-generic. // If the contextual type is a union type, get the signature from each type possible and if they are @@ -8859,9 +8857,7 @@ namespace ts { // union type of return types from these signatures function getContextualSignature(node: FunctionExpression | MethodDeclaration): Signature { Debug.assert(node.kind !== SyntaxKind.MethodDeclaration || isObjectLiteralMethod(node)); - const type = isObjectLiteralMethod(node) - ? getContextualTypeForObjectLiteralMethod(node) - : getApparentTypeOfContextualType(node); + const type = getContextualTypeForFunctionLikeDeclaration(node); if (!type) { return undefined; } From 9f7621c7e26fcdd02ef15f0bbbe65f2d9104843a Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Thu, 28 Apr 2016 14:17:11 -0700 Subject: [PATCH 30/52] Contextual signatures without thisType return anyType If a contextual signature is found, if its thisType is undefined, then the contextual type of `this` is now `any`. Previously `checkThisExpression` would keep looking for a different type for `this`. Also update tests to show this new behaviour. --- src/compiler/checker.ts | 2 +- .../reference/thisTypeInFunctions2.js | 96 ++++++++--- .../reference/thisTypeInFunctions2.symbols | 134 +++++++++++---- .../reference/thisTypeInFunctions2.types | 162 +++++++++++++----- .../types/thisType/thisTypeInFunctions2.ts | 56 ++++-- 5 files changed, 332 insertions(+), 118 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 7a301884b4e..6cedb78686d 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -8453,7 +8453,7 @@ namespace ts { if (isContextSensitiveFunctionOrObjectLiteralMethod(func) && func.kind !== SyntaxKind.ArrowFunction) { const contextualSignature = getContextualSignature(func); if (contextualSignature) { - return contextualSignature.thisType; + return contextualSignature.thisType || anyType; } else if (getContextualTypeForFunctionLikeDeclaration(func) === anyType) { return anyType; diff --git a/tests/baselines/reference/thisTypeInFunctions2.js b/tests/baselines/reference/thisTypeInFunctions2.js index 7fc52877191..f52438a19ab 100644 --- a/tests/baselines/reference/thisTypeInFunctions2.js +++ b/tests/baselines/reference/thisTypeInFunctions2.js @@ -1,51 +1,91 @@ //// [thisTypeInFunctions2.ts] -interface Arguments { - init?: (this: void) => void; +interface IndexedWithThis { + // this is a workaround for React + init?: (this: this) => void; willDestroy?: (this: any) => void; [propName: string]: number | string | boolean | symbol | undefined | null | {} | ((this: any, ...args:any[]) => any); } -declare function extend(arguments: Arguments): void; -class Mixin { - stuff: number; +interface IndexedWithoutThis { + // this is what React would like to write (and what they write today) + init?: () => void; + willDestroy?: () => void; + [propName: string]: any; } +interface SimpleInterface { + foo(n: string); + bar(): number; +} +declare function extend1(args: IndexedWithThis): void; +declare function extend2(args: IndexedWithoutThis): void; +declare function simple(arg: SimpleInterface): void; -extend({ +extend1({ init() { - this + this // this: IndexedWithThis because of contextual typing. + // this.mine + this.willDestroy }, mine: 12, - bar() { - this.init(); - }, foo() { - this.bar; - this.url - this.handler() - this.baz + this.url; // this: any because 'foo' matches the string indexer + this.willDestroy; + } +}); +extend2({ + init() { + this // this: any because the contextual signature of init doesn't specify this' type + this.mine this.willDestroy + }, + mine: 13, + foo() { + this // this: any because of the string indexer + this.mine + this.willDestroy + } +}); + +simple({ + foo(n) { + return n.length + this.bar(); + }, + bar() { + return 14; } }) //// [thisTypeInFunctions2.js] -var Mixin = (function () { - function Mixin() { - } - return Mixin; -}()); -extend({ +extend1({ init: function () { - this; + this; // this: IndexedWithThis because of contextual typing. + // this.mine + this.willDestroy; }, mine: 12, - bar: function () { - this.init(); - }, foo: function () { - this.bar; - this.url; - this.handler(); - this.baz; + this.url; // this: any because 'foo' matches the string indexer this.willDestroy; } }); +extend2({ + init: function () { + this; // this: any because the contextual signature of init doesn't specify this' type + this.mine; + this.willDestroy; + }, + mine: 13, + foo: function () { + this; // this: any because of the string indexer + this.mine; + this.willDestroy; + } +}); +simple({ + foo: function (n) { + return n.length + this.bar(); + }, + bar: function () { + return 14; + } +}); diff --git a/tests/baselines/reference/thisTypeInFunctions2.symbols b/tests/baselines/reference/thisTypeInFunctions2.symbols index 5e186e9485d..cdc7fb321d4 100644 --- a/tests/baselines/reference/thisTypeInFunctions2.symbols +++ b/tests/baselines/reference/thisTypeInFunctions2.symbols @@ -1,56 +1,124 @@ === tests/cases/conformance/types/thisType/thisTypeInFunctions2.ts === -interface Arguments { ->Arguments : Symbol(Arguments, Decl(thisTypeInFunctions2.ts, 0, 0)) +interface IndexedWithThis { +>IndexedWithThis : Symbol(IndexedWithThis, Decl(thisTypeInFunctions2.ts, 0, 0)) - init?: (this: void) => void; ->init : Symbol(Arguments.init, Decl(thisTypeInFunctions2.ts, 0, 21)) ->this : Symbol(this, Decl(thisTypeInFunctions2.ts, 1, 12)) + // this is a workaround for React + init?: (this: this) => void; +>init : Symbol(IndexedWithThis.init, Decl(thisTypeInFunctions2.ts, 0, 27)) +>this : Symbol(this, Decl(thisTypeInFunctions2.ts, 2, 12)) willDestroy?: (this: any) => void; ->willDestroy : Symbol(Arguments.willDestroy, Decl(thisTypeInFunctions2.ts, 1, 32)) ->this : Symbol(this, Decl(thisTypeInFunctions2.ts, 2, 19)) +>willDestroy : Symbol(IndexedWithThis.willDestroy, Decl(thisTypeInFunctions2.ts, 2, 32)) +>this : Symbol(this, Decl(thisTypeInFunctions2.ts, 3, 19)) [propName: string]: number | string | boolean | symbol | undefined | null | {} | ((this: any, ...args:any[]) => any); ->propName : Symbol(propName, Decl(thisTypeInFunctions2.ts, 3, 5)) ->this : Symbol(this, Decl(thisTypeInFunctions2.ts, 3, 87)) ->args : Symbol(args, Decl(thisTypeInFunctions2.ts, 3, 97)) +>propName : Symbol(propName, Decl(thisTypeInFunctions2.ts, 4, 5)) +>this : Symbol(this, Decl(thisTypeInFunctions2.ts, 4, 87)) +>args : Symbol(args, Decl(thisTypeInFunctions2.ts, 4, 97)) } -declare function extend(arguments: Arguments): void; ->extend : Symbol(extend, Decl(thisTypeInFunctions2.ts, 4, 1)) ->arguments : Symbol(arguments, Decl(thisTypeInFunctions2.ts, 5, 24)) ->Arguments : Symbol(Arguments, Decl(thisTypeInFunctions2.ts, 0, 0)) +interface IndexedWithoutThis { +>IndexedWithoutThis : Symbol(IndexedWithoutThis, Decl(thisTypeInFunctions2.ts, 5, 1)) -class Mixin { ->Mixin : Symbol(Mixin, Decl(thisTypeInFunctions2.ts, 5, 52)) + // this is what React would like to write (and what they write today) + init?: () => void; +>init : Symbol(IndexedWithoutThis.init, Decl(thisTypeInFunctions2.ts, 6, 30)) - stuff: number; ->stuff : Symbol(Mixin.stuff, Decl(thisTypeInFunctions2.ts, 6, 13)) + willDestroy?: () => void; +>willDestroy : Symbol(IndexedWithoutThis.willDestroy, Decl(thisTypeInFunctions2.ts, 8, 22)) + + [propName: string]: any; +>propName : Symbol(propName, Decl(thisTypeInFunctions2.ts, 10, 5)) } +interface SimpleInterface { +>SimpleInterface : Symbol(SimpleInterface, Decl(thisTypeInFunctions2.ts, 11, 1)) -extend({ ->extend : Symbol(extend, Decl(thisTypeInFunctions2.ts, 4, 1)) + foo(n: string); +>foo : Symbol(SimpleInterface.foo, Decl(thisTypeInFunctions2.ts, 12, 27)) +>n : Symbol(n, Decl(thisTypeInFunctions2.ts, 13, 8)) + + bar(): number; +>bar : Symbol(SimpleInterface.bar, Decl(thisTypeInFunctions2.ts, 13, 19)) +} +declare function extend1(args: IndexedWithThis): void; +>extend1 : Symbol(extend1, Decl(thisTypeInFunctions2.ts, 15, 1)) +>args : Symbol(args, Decl(thisTypeInFunctions2.ts, 16, 25)) +>IndexedWithThis : Symbol(IndexedWithThis, Decl(thisTypeInFunctions2.ts, 0, 0)) + +declare function extend2(args: IndexedWithoutThis): void; +>extend2 : Symbol(extend2, Decl(thisTypeInFunctions2.ts, 16, 54)) +>args : Symbol(args, Decl(thisTypeInFunctions2.ts, 17, 25)) +>IndexedWithoutThis : Symbol(IndexedWithoutThis, Decl(thisTypeInFunctions2.ts, 5, 1)) + +declare function simple(arg: SimpleInterface): void; +>simple : Symbol(simple, Decl(thisTypeInFunctions2.ts, 17, 57)) +>arg : Symbol(arg, Decl(thisTypeInFunctions2.ts, 18, 24)) +>SimpleInterface : Symbol(SimpleInterface, Decl(thisTypeInFunctions2.ts, 11, 1)) + +extend1({ +>extend1 : Symbol(extend1, Decl(thisTypeInFunctions2.ts, 15, 1)) init() { ->init : Symbol(init, Decl(thisTypeInFunctions2.ts, 10, 8)) +>init : Symbol(init, Decl(thisTypeInFunctions2.ts, 20, 9)) + + this // this: IndexedWithThis because of contextual typing. +>this : Symbol(IndexedWithThis, Decl(thisTypeInFunctions2.ts, 0, 0)) + + // this.mine + this.willDestroy +>this.willDestroy : Symbol(IndexedWithThis.willDestroy, Decl(thisTypeInFunctions2.ts, 2, 32)) +>this : Symbol(IndexedWithThis, Decl(thisTypeInFunctions2.ts, 0, 0)) +>willDestroy : Symbol(IndexedWithThis.willDestroy, Decl(thisTypeInFunctions2.ts, 2, 32)) - this }, mine: 12, ->mine : Symbol(mine, Decl(thisTypeInFunctions2.ts, 13, 6)) +>mine : Symbol(mine, Decl(thisTypeInFunctions2.ts, 25, 6)) - bar() { ->bar : Symbol(bar, Decl(thisTypeInFunctions2.ts, 14, 13)) - - this.init(); - }, foo() { ->foo : Symbol(foo, Decl(thisTypeInFunctions2.ts, 17, 6)) +>foo : Symbol(foo, Decl(thisTypeInFunctions2.ts, 26, 13)) - this.bar; - this.url - this.handler() - this.baz + this.url; // this: any because 'foo' matches the string indexer + this.willDestroy; + } +}); +extend2({ +>extend2 : Symbol(extend2, Decl(thisTypeInFunctions2.ts, 16, 54)) + + init() { +>init : Symbol(init, Decl(thisTypeInFunctions2.ts, 32, 9)) + + this // this: any because the contextual signature of init doesn't specify this' type + this.mine this.willDestroy + }, + mine: 13, +>mine : Symbol(mine, Decl(thisTypeInFunctions2.ts, 37, 6)) + + foo() { +>foo : Symbol(foo, Decl(thisTypeInFunctions2.ts, 38, 13)) + + this // this: any because of the string indexer + this.mine + this.willDestroy + } +}); + +simple({ +>simple : Symbol(simple, Decl(thisTypeInFunctions2.ts, 17, 57)) + + foo(n) { +>foo : Symbol(foo, Decl(thisTypeInFunctions2.ts, 46, 8)) +>n : Symbol(n, Decl(thisTypeInFunctions2.ts, 47, 8)) + + return n.length + this.bar(); +>n.length : Symbol(String.length, Decl(lib.d.ts, --, --)) +>n : Symbol(n, Decl(thisTypeInFunctions2.ts, 47, 8)) +>length : Symbol(String.length, Decl(lib.d.ts, --, --)) + + }, + bar() { +>bar : Symbol(bar, Decl(thisTypeInFunctions2.ts, 49, 6)) + + return 14; } }) diff --git a/tests/baselines/reference/thisTypeInFunctions2.types b/tests/baselines/reference/thisTypeInFunctions2.types index 3e3e9123549..371b5f5cafc 100644 --- a/tests/baselines/reference/thisTypeInFunctions2.types +++ b/tests/baselines/reference/thisTypeInFunctions2.types @@ -1,10 +1,11 @@ === tests/cases/conformance/types/thisType/thisTypeInFunctions2.ts === -interface Arguments { ->Arguments : Arguments +interface IndexedWithThis { +>IndexedWithThis : IndexedWithThis - init?: (this: void) => void; ->init : (this: void) => void ->this : void + // this is a workaround for React + init?: (this: this) => void; +>init : (this: this) => void +>this : this willDestroy?: (this: any) => void; >willDestroy : (this: any) => void @@ -16,72 +17,149 @@ interface Arguments { >this : any >args : any[] } -declare function extend(arguments: Arguments): void; ->extend : (arguments: Arguments) => void ->arguments : Arguments ->Arguments : Arguments +interface IndexedWithoutThis { +>IndexedWithoutThis : IndexedWithoutThis -class Mixin { ->Mixin : Mixin + // this is what React would like to write (and what they write today) + init?: () => void; +>init : () => void - stuff: number; ->stuff : number + willDestroy?: () => void; +>willDestroy : () => void + + [propName: string]: any; +>propName : string } +interface SimpleInterface { +>SimpleInterface : SimpleInterface -extend({ ->extend({ init() { this }, mine: 12, bar() { this.init(); }, foo() { this.bar; this.url this.handler() this.baz this.willDestroy }}) : void ->extend : (arguments: Arguments) => void ->{ init() { this }, mine: 12, bar() { this.init(); }, foo() { this.bar; this.url this.handler() this.baz this.willDestroy }} : { init(): void; mine: number; bar(): void; foo(): void; } + foo(n: string); +>foo : (n: string) => any +>n : string + + bar(): number; +>bar : () => number +} +declare function extend1(args: IndexedWithThis): void; +>extend1 : (args: IndexedWithThis) => void +>args : IndexedWithThis +>IndexedWithThis : IndexedWithThis + +declare function extend2(args: IndexedWithoutThis): void; +>extend2 : (args: IndexedWithoutThis) => void +>args : IndexedWithoutThis +>IndexedWithoutThis : IndexedWithoutThis + +declare function simple(arg: SimpleInterface): void; +>simple : (arg: SimpleInterface) => void +>arg : SimpleInterface +>SimpleInterface : SimpleInterface + +extend1({ +>extend1({ init() { this // this: IndexedWithThis because of contextual typing. // this.mine this.willDestroy }, mine: 12, foo() { this.url; // this: any because 'foo' matches the string indexer this.willDestroy; }}) : void +>extend1 : (args: IndexedWithThis) => void +>{ init() { this // this: IndexedWithThis because of contextual typing. // this.mine this.willDestroy }, mine: 12, foo() { this.url; // this: any because 'foo' matches the string indexer this.willDestroy; }} : { init(): void; mine: number; foo(): void; } init() { >init : () => void - this ->this : void + this // this: IndexedWithThis because of contextual typing. +>this : IndexedWithThis + + // this.mine + this.willDestroy +>this.willDestroy : (this: any) => void +>this : IndexedWithThis +>willDestroy : (this: any) => void }, mine: 12, >mine : number >12 : number - bar() { ->bar : () => void - - this.init(); ->this.init() : any ->this.init : any ->this : any ->init : any - - }, foo() { >foo : () => void - this.bar; ->this.bar : any ->this : any ->bar : any - - this.url + this.url; // this: any because 'foo' matches the string indexer >this.url : any >this : any >url : any - this.handler() ->this.handler() : any ->this.handler : any + this.willDestroy; +>this.willDestroy : any >this : any ->handler : any +>willDestroy : any + } +}); +extend2({ +>extend2({ init() { this // this: any because the contextual signature of init doesn't specify this' type this.mine this.willDestroy }, mine: 13, foo() { this // this: any because of the string indexer this.mine this.willDestroy }}) : void +>extend2 : (args: IndexedWithoutThis) => void +>{ init() { this // this: any because the contextual signature of init doesn't specify this' type this.mine this.willDestroy }, mine: 13, foo() { this // this: any because of the string indexer this.mine this.willDestroy }} : { init(): void; mine: number; foo(): void; } - this.baz ->this.baz : any + init() { +>init : () => void + + this // this: any because the contextual signature of init doesn't specify this' type >this : any ->baz : any + + this.mine +>this.mine : any +>this : any +>mine : any + + this.willDestroy +>this.willDestroy : any +>this : any +>willDestroy : any + + }, + mine: 13, +>mine : number +>13 : number + + foo() { +>foo : () => void + + this // this: any because of the string indexer +>this : any + + this.mine +>this.mine : any +>this : any +>mine : any this.willDestroy >this.willDestroy : any >this : any >willDestroy : any } +}); + +simple({ +>simple({ foo(n) { return n.length + this.bar(); }, bar() { return 14; }}) : void +>simple : (arg: SimpleInterface) => void +>{ foo(n) { return n.length + this.bar(); }, bar() { return 14; }} : { foo(n: string): any; bar(): number; } + + foo(n) { +>foo : (n: string) => any +>n : string + + return n.length + this.bar(); +>n.length + this.bar() : any +>n.length : number +>n : string +>length : number +>this.bar() : any +>this.bar : any +>this : any +>bar : any + + }, + bar() { +>bar : () => number + + return 14; +>14 : number + } }) diff --git a/tests/cases/conformance/types/thisType/thisTypeInFunctions2.ts b/tests/cases/conformance/types/thisType/thisTypeInFunctions2.ts index c33c5062249..a574c7a07e9 100644 --- a/tests/cases/conformance/types/thisType/thisTypeInFunctions2.ts +++ b/tests/cases/conformance/types/thisType/thisTypeInFunctions2.ts @@ -1,26 +1,54 @@ -interface Arguments { - init?: (this: void) => void; +interface IndexedWithThis { + // this is a workaround for React + init?: (this: this) => void; willDestroy?: (this: any) => void; [propName: string]: number | string | boolean | symbol | undefined | null | {} | ((this: any, ...args:any[]) => any); } -declare function extend(arguments: Arguments): void; -class Mixin { - stuff: number; +interface IndexedWithoutThis { + // this is what React would like to write (and what they write today) + init?: () => void; + willDestroy?: () => void; + [propName: string]: any; } +interface SimpleInterface { + foo(n: string); + bar(): number; +} +declare function extend1(args: IndexedWithThis): void; +declare function extend2(args: IndexedWithoutThis): void; +declare function simple(arg: SimpleInterface): void; -extend({ +extend1({ init() { - this + this // this: IndexedWithThis because of contextual typing. + // this.mine + this.willDestroy }, mine: 12, - bar() { - this.init(); - }, foo() { - this.bar; - this.url - this.handler() - this.baz + this.url; // this: any because 'foo' matches the string indexer + this.willDestroy; + } +}); +extend2({ + init() { + this // this: any because the contextual signature of init doesn't specify this' type + this.mine + this.willDestroy + }, + mine: 13, + foo() { + this // this: any because of the string indexer + this.mine this.willDestroy } +}); + +simple({ + foo(n) { + return n.length + this.bar(); + }, + bar() { + return 14; + } }) From b6e98e52c695d11451e69084754028e3874b5164 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Thu, 28 Apr 2016 14:48:53 -0700 Subject: [PATCH 31/52] Fix #8338: add signatures to RegExp constructor accepting RegExp --- src/lib/es2015.core.d.ts | 129 ++-- src/lib/es5.d.ts | 1494 +++++++++++++++++++------------------- 2 files changed, 815 insertions(+), 808 deletions(-) diff --git a/src/lib/es2015.core.d.ts b/src/lib/es2015.core.d.ts index fc93847f8af..34833b9c70d 100644 --- a/src/lib/es2015.core.d.ts +++ b/src/lib/es2015.core.d.ts @@ -1,24 +1,24 @@ declare type PropertyKey = string | number | symbol; interface Array { - /** - * Returns the value of the first element in the array where predicate is true, and undefined + /** + * 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 + * @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 + * @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 | undefined; - /** - * Returns the index of the first element in the array where predicate is true, and undefined + /** + * 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 + * @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 + * @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 | undefined; @@ -26,21 +26,21 @@ interface Array { /** * 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 + * @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 + * @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. + * @param end If not specified, length of the this object is used as its default value. */ copyWithin(target: number, start: number, end?: number): T[]; } @@ -114,7 +114,7 @@ interface Math { log1p(x: number): number; /** - * Returns the result of (e^x - 1) of x (e raised to the power of x, where e is the base of + * Returns the result of (e^x - 1) of x (e raised to the power of x, where e is the base of * the natural logarithms). * @param x A numeric expression. */ @@ -190,14 +190,14 @@ interface Math { 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: + * that is representable as a Number value, which is approximately: * 2.2204460492503130808472633361816 x 10‍−‍16. */ readonly EPSILON: number; /** * Returns true if passed value is finite. - * Unlike the global isFininte, Number.isFinite doesn't forcibly convert the parameter to a + * 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. */ @@ -210,7 +210,7 @@ interface NumberConstructor { isInteger(number: number): boolean; /** - * Returns a Boolean value that indicates whether a value is the reserved value NaN (not a + * 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. @@ -223,30 +223,30 @@ interface NumberConstructor { */ 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 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. */ readonly 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 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)). */ readonly MIN_SAFE_INTEGER: number; /** - * Converts a string to a floating-point number. - * @param string A string that contains a floating-point number. + * Converts a string to a floating-point number. + * @param string A string that contains a floating-point number. */ parseFloat(string: string): number; /** * 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. + * @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. */ @@ -255,12 +255,12 @@ interface NumberConstructor { interface Object { /** - * Determines whether an object has a property with the specified name. + * 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. */ @@ -269,7 +269,7 @@ interface Object { interface ObjectConstructor { /** - * Copy the values of all of the enumerable own properties from one or more source objects to a + * 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 source The source object from which to copy properties. @@ -277,7 +277,7 @@ interface ObjectConstructor { assign(target: T, source: U): T & U; /** - * Copy the values of all of the enumerable own properties from one or more source objects to a + * 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 source1 The first source object from which to copy properties. @@ -286,7 +286,7 @@ interface ObjectConstructor { assign(target: T, source1: U, source2: V): T & U & V; /** - * Copy the values of all of the enumerable own properties from one or more source objects to a + * 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 source1 The first source object from which to copy properties. @@ -296,7 +296,7 @@ interface ObjectConstructor { assign(target: T, source1: U, source2: V, source3: W): T & U & V & W; /** - * Copy the values of all of the enumerable own properties from one or more source objects to a + * 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 from which to copy properties @@ -324,17 +324,17 @@ interface ObjectConstructor { 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. + * 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 + * 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 @@ -358,47 +358,52 @@ interface RegExp { */ readonly flags: string; - /** - * Returns a Boolean value indicating the state of the sticky flag (y) used with a regular - * expression. Default is false. Read-only. + /** + * Returns a Boolean value indicating the state of the sticky flag (y) used with a regular + * expression. Default is false. Read-only. */ readonly sticky: boolean; - /** - * Returns a Boolean value indicating the state of the Unicode flag (u) used with a regular - * expression. Default is false. Read-only. + /** + * Returns a Boolean value indicating the state of the Unicode flag (u) used with a regular + * expression. Default is false. Read-only. */ readonly unicode: boolean; } +interface RegExpConstructor { + new (pattern: RegExp, flags?: string): RegExp; + (pattern: RegExp, flags?: string): RegExp; +} + interface String { /** - * 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. + * 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 | undefined; /** - * 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 + * 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 searchString search string * @param position If position is undefined, 0 is assumed, so as to search all of the String. */ includes(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 + * 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 + * 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" @@ -406,15 +411,15 @@ interface String { normalize(form?: string): string; /** - * Returns a String value that is made from count copies appended together. If count is 0, + * 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 + * 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; @@ -474,7 +479,7 @@ interface StringConstructor { /** * String.raw is intended for use as a tag function of a Tagged Template String. When called - * as such the first argument will be a well formed template call site object and the rest + * as such the first argument will be a well formed template call site object and the rest * parameter will contain the substitution values. * @param template A well-formed template string call site representation. * @param substitutions A set of substitution values. diff --git a/src/lib/es5.d.ts b/src/lib/es5.d.ts index 967aeb42aaf..f450371f90d 100644 --- a/src/lib/es5.d.ts +++ b/src/lib/es5.d.ts @@ -6,7 +6,7 @@ declare const NaN: number; declare const Infinity: number; /** - * Evaluates JavaScript code and executes it. + * Evaluates JavaScript code and executes it. * @param x A String value that contains valid JavaScript code. */ declare function eval(x: string): any; @@ -14,25 +14,25 @@ declare function eval(x: string): any; /** * 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. + * @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. */ declare function parseInt(s: string, radix?: number): number; /** - * Converts a string to a floating-point number. - * @param string A string that contains a floating-point number. + * Converts a string to a floating-point number. + * @param string A string that contains a floating-point number. */ declare function parseFloat(string: string): number; /** - * Returns a Boolean value that indicates whether a value is the reserved value NaN (not a number). + * Returns a Boolean value that indicates whether a value is the reserved value NaN (not a number). * @param number A numeric value. */ declare function isNaN(number: number): boolean; -/** +/** * Determines whether a supplied number is finite. * @param number Any numeric value. */ @@ -50,7 +50,7 @@ declare function decodeURI(encodedURI: string): string; */ declare function decodeURIComponent(encodedURIComponent: string): string; -/** +/** * Encodes a text string as a valid Uniform Resource Identifier (URI) * @param uri A value representing an encoded URI. */ @@ -89,18 +89,18 @@ interface Object { valueOf(): Object; /** - * Determines whether an object has a property with the specified name. + * Determines whether an object has a property with the specified name. * @param v A property name. */ hasOwnProperty(v: string): boolean; /** - * Determines whether an object exists in another object's prototype chain. + * Determines whether an object exists in another object's prototype chain. * @param v Another object whose prototype chain is to be checked. */ isPrototypeOf(v: Object): boolean; - /** + /** * Determines whether a specified property is enumerable. * @param v A property name. */ @@ -115,36 +115,36 @@ interface ObjectConstructor { /** A reference to the prototype for a class of objects. */ readonly prototype: Object; - /** - * Returns the prototype of an object. + /** + * Returns the prototype of an object. * @param o The object that references the prototype. */ getPrototypeOf(o: 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. + * 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, p: string): PropertyDescriptor; - /** - * Returns the names of the own properties of an object. The own properties of an object are those that are defined directly + /** + * Returns the names of the own properties of an object. The own properties of an object are those that are defined directly * on that object, and are not inherited from the object's prototype. The properties of an object include both fields (objects) and functions. * @param o Object that contains the own properties. */ getOwnPropertyNames(o: any): string[]; - /** + /** * Creates an object that has the specified prototype, and that optionally contains specified properties. * @param o Object to use as a prototype. May be null - * @param properties JavaScript object that contains one or more property descriptors. + * @param properties JavaScript object that contains one or more property descriptors. */ create(o: any, properties?: PropertyDescriptorMap): any; /** - * Adds a property to an object, or modifies attributes of an existing property. + * 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. @@ -152,7 +152,7 @@ interface ObjectConstructor { defineProperty(o: any, p: string, attributes: PropertyDescriptor): any; /** - * Adds one or more properties to an object, and/or modifies attributes of existing properties. + * Adds one or more properties to an object, and/or modifies attributes of existing properties. * @param o Object on which to add or modify the properties. This can be a native JavaScript object or a DOM object. * @param properties JavaScript object that contains one or more descriptor objects. Each descriptor object describes a data property or an accessor property. */ @@ -160,7 +160,7 @@ interface ObjectConstructor { /** * Prevents the modification of attributes of existing properties, and prevents the addition of new properties. - * @param o Object on which to lock the attributes. + * @param o Object on which to lock the attributes. */ seal(o: T): T; @@ -172,25 +172,25 @@ interface ObjectConstructor { /** * Prevents the addition of new properties to an object. - * @param o Object to make non-extensible. + * @param o Object to make non-extensible. */ preventExtensions(o: T): T; /** * Returns true if existing property attributes cannot be modified in an object and new properties cannot be added to the object. - * @param o Object to test. + * @param o Object to test. */ isSealed(o: any): boolean; /** * Returns true if existing property attributes and values cannot be modified in an object, and new properties cannot be added to the object. - * @param o Object to test. + * @param o Object to test. */ isFrozen(o: any): boolean; /** * Returns a value that indicates whether new properties can be added to an object. - * @param o Object to test. + * @param o Object to test. */ isExtensible(o: any): boolean; @@ -225,7 +225,7 @@ interface Function { call(this: Function, thisArg: any, ...argArray: any[]): any; /** - * For a given function, creates a bound function that has the same body as the original function. + * For a given function, creates a bound function that has the same body as the original function. * The this object of the bound function is associated with the specified object, and has the specified initial parameters. * @param thisArg An object to which the this keyword can refer inside the new function. * @param argArray A list of arguments to be passed to the new function. @@ -268,7 +268,7 @@ interface String { */ charAt(pos: number): string; - /** + /** * Returns the Unicode value of the character at the specified location. * @param index The zero-based index of the desired character. If there is no character at the specified index, NaN is returned. */ @@ -276,12 +276,12 @@ interface String { /** * Returns a string that contains the concatenation of two or more strings. - * @param strings The strings to append to the end of the string. + * @param strings The strings to append to the end of the string. */ concat(...strings: string[]): string; /** - * Returns the position of the first occurrence of a substring. + * Returns the position of the first occurrence of a substring. * @param searchString The substring to search for in the string * @param position The index at which to begin searching the String object. If omitted, search starts at the beginning of the string. */ @@ -300,15 +300,15 @@ interface String { */ localeCompare(that: string): number; - /** + /** * Matches a string with a regular expression, and returns an array containing the results of that search. * @param regexp A variable name or string literal containing the regular expression pattern and flags. */ match(regexp: string): RegExpMatchArray | null; - /** + /** * Matches a string with a regular expression, and returns an array containing the results of that search. - * @param regexp A regular expression object that contains the regular expression pattern and applicable flags. + * @param regexp A regular expression object that contains the regular expression pattern and applicable flags. */ match(regexp: RegExp): RegExpMatchArray | null; @@ -342,40 +342,40 @@ interface String { /** * Finds the first substring match in a regular expression search. - * @param regexp The regular expression pattern and applicable flags. + * @param regexp The regular expression pattern and applicable flags. */ search(regexp: string): number; /** * Finds the first substring match in a regular expression search. - * @param regexp The regular expression pattern and applicable flags. + * @param regexp The regular expression pattern and applicable flags. */ search(regexp: RegExp): number; /** * Returns a section of a string. - * @param start The index to the beginning of the specified portion of stringObj. - * @param end The index to the end of the specified portion of stringObj. The substring includes the characters up to, but not including, the character indicated by end. + * @param start The index to the beginning of the specified portion of stringObj. + * @param end The index to the end of the specified portion of stringObj. The substring includes the characters up to, but not including, the character indicated by end. * If this value is not specified, the substring continues to the end of stringObj. */ slice(start?: number, end?: number): string; /** * Split a string into substrings using the specified separator and return them as an array. - * @param separator A string that identifies character or characters to use in separating the string. If omitted, a single-element array containing the entire string is returned. + * @param separator A string that identifies character or characters to use in separating the string. If omitted, a single-element array containing the entire string is returned. * @param limit A value used to limit the number of elements returned in the array. */ split(separator: string, limit?: number): string[]; /** * Split a string into substrings using the specified separator and return them as an array. - * @param separator A Regular Express that identifies character or characters to use in separating the string. If omitted, a single-element array containing the entire string is returned. + * @param separator A Regular Express that identifies character or characters to use in separating the string. If omitted, a single-element array containing the entire string is returned. * @param limit A value used to limit the number of elements returned in the array. */ split(separator: RegExp, limit?: number): string[]; /** - * Returns the substring at the specified location within a String object. + * Returns the substring at the specified location within a String object. * @param start The zero-based index number indicating the beginning of the substring. * @param end Zero-based index number indicating the end of the substring. The substring includes the characters up to, but not including, the character indicated by end. * If end is omitted, the characters from start through the end of the original string are returned. @@ -421,8 +421,8 @@ interface StringConstructor { fromCharCode(...codes: number[]): string; } -/** - * Allows manipulation and formatting of text strings and determination and location of substrings within strings. +/** + * Allows manipulation and formatting of text strings and determination and location of substrings within strings. */ declare const String: StringConstructor; @@ -446,7 +446,7 @@ interface Number { */ toString(radix?: number): string; - /** + /** * Returns a string representing a number in fixed-point notation. * @param fractionDigits Number of digits after the decimal point. Must be in the range 0 - 20, inclusive. */ @@ -479,21 +479,21 @@ interface NumberConstructor { /** The closest number to zero that can be represented in JavaScript. Equal to approximately 5.00E-324. */ readonly MIN_VALUE: number; - /** + /** * A value that is not a number. * In equality comparisons, NaN does not equal any value, including itself. To test whether a value is equivalent to NaN, use the isNaN function. */ readonly NaN: number; - /** + /** * A value that is less than the largest negative number that can be represented in JavaScript. - * JavaScript displays NEGATIVE_INFINITY values as -infinity. + * JavaScript displays NEGATIVE_INFINITY values as -infinity. */ readonly NEGATIVE_INFINITY: number; /** - * A value greater than the largest number that can be represented in JavaScript. - * JavaScript displays POSITIVE_INFINITY values as infinity. + * A value greater than the largest number that can be represented in JavaScript. + * JavaScript displays POSITIVE_INFINITY values as infinity. */ readonly POSITIVE_INFINITY: number; } @@ -523,23 +523,23 @@ interface Math { /** The square root of 2. */ readonly SQRT2: number; /** - * Returns the absolute value of a number (the value without regard to whether it is positive or negative). + * Returns the absolute value of a number (the value without regard to whether it is positive or negative). * For example, the absolute value of -5 is the same as the absolute value of 5. * @param x A numeric expression for which the absolute value is needed. */ abs(x: number): number; /** - * Returns the arc cosine (or inverse cosine) of a number. + * Returns the arc cosine (or inverse cosine) of a number. * @param x A numeric expression. */ acos(x: number): number; - /** - * Returns the arcsine of a number. + /** + * Returns the arcsine of a number. * @param x A numeric expression. */ asin(x: number): number; /** - * Returns the arctangent of a number. + * Returns the arctangent of a number. * @param x A numeric expression for which the arctangent is needed. */ atan(x: number): number; @@ -550,49 +550,49 @@ interface Math { */ atan2(y: number, x: number): number; /** - * Returns the smallest number greater than or equal to its numeric argument. + * Returns the smallest number greater than or equal to its numeric argument. * @param x A numeric expression. */ ceil(x: number): number; /** - * Returns the cosine of a number. + * Returns the cosine of a number. * @param x A numeric expression that contains an angle measured in radians. */ cos(x: number): number; /** - * Returns e (the base of natural logarithms) raised to a power. + * Returns e (the base of natural logarithms) raised to a power. * @param x A numeric expression representing the power of e. */ exp(x: number): number; /** - * Returns the greatest number less than or equal to its numeric argument. + * Returns the greatest number less than or equal to its numeric argument. * @param x A numeric expression. */ floor(x: number): number; /** - * Returns the natural logarithm (base e) of a number. + * Returns the natural logarithm (base e) of a number. * @param x A numeric expression. */ log(x: number): number; /** - * Returns the larger of a set of supplied numeric expressions. + * Returns the larger of a set of supplied numeric expressions. * @param values Numeric expressions to be evaluated. */ max(...values: number[]): number; /** - * Returns the smaller of a set of supplied numeric expressions. + * Returns the smaller of a set of supplied numeric expressions. * @param values Numeric expressions to be evaluated. */ min(...values: number[]): number; /** - * Returns the value of a base expression taken to a specified power. + * Returns the value of a base expression taken to a specified power. * @param x The base value of the expression. * @param y The exponent value of the expression. */ pow(x: number, y: number): number; /** Returns a pseudorandom number between 0 and 1. */ random(): number; - /** + /** * Returns a supplied numeric expression rounded to the nearest number. * @param x The value to be rounded to the nearest number. */ @@ -668,24 +668,24 @@ interface Date { getUTCMilliseconds(): number; /** Gets the difference in minutes between the time on the local computer and Universal Coordinated Time (UTC). */ getTimezoneOffset(): number; - /** + /** * Sets the date and time value in the Date object. - * @param time A numeric value representing the number of elapsed milliseconds since midnight, January 1, 1970 GMT. + * @param time A numeric value representing the number of elapsed milliseconds since midnight, January 1, 1970 GMT. */ setTime(time: number): number; /** - * Sets the milliseconds value in the Date object using local time. + * Sets the milliseconds value in the Date object using local time. * @param ms A numeric value equal to the millisecond value. */ setMilliseconds(ms: number): number; - /** + /** * Sets the milliseconds value in the Date object using Universal Coordinated Time (UTC). - * @param ms A numeric value equal to the millisecond value. + * @param ms A numeric value equal to the millisecond value. */ setUTCMilliseconds(ms: number): number; /** - * Sets the seconds value in the Date object using local time. + * Sets the seconds value in the Date object using local time. * @param sec A numeric value equal to the seconds value. * @param ms A numeric value equal to the milliseconds value. */ @@ -697,16 +697,16 @@ interface Date { */ setUTCSeconds(sec: number, ms?: number): number; /** - * Sets the minutes value in the Date object using local time. - * @param min A numeric value equal to the minutes value. - * @param sec A numeric value equal to the seconds value. + * Sets the minutes value in the Date object using local time. + * @param min A numeric value equal to the minutes value. + * @param sec A numeric value equal to the seconds value. * @param ms A numeric value equal to the milliseconds value. */ setMinutes(min: number, sec?: number, ms?: number): number; /** * Sets the minutes value in the Date object using Universal Coordinated Time (UTC). - * @param min A numeric value equal to the minutes value. - * @param sec A numeric value equal to the seconds value. + * @param min A numeric value equal to the minutes value. + * @param sec A numeric value equal to the seconds value. * @param ms A numeric value equal to the milliseconds value. */ setUTCMinutes(min: number, sec?: number, ms?: number): number; @@ -714,7 +714,7 @@ interface Date { * Sets the hour value in the Date object using local time. * @param hours A numeric value equal to the hours value. * @param min A numeric value equal to the minutes value. - * @param sec A numeric value equal to the seconds value. + * @param sec A numeric value equal to the seconds value. * @param ms A numeric value equal to the milliseconds value. */ setHours(hours: number, min?: number, sec?: number, ms?: number): number; @@ -722,23 +722,23 @@ interface Date { * Sets the hours value in the Date object using Universal Coordinated Time (UTC). * @param hours A numeric value equal to the hours value. * @param min A numeric value equal to the minutes value. - * @param sec A numeric value equal to the seconds value. + * @param sec A numeric value equal to the seconds value. * @param ms A numeric value equal to the milliseconds value. */ setUTCHours(hours: number, min?: number, sec?: number, ms?: number): number; /** - * Sets the numeric day-of-the-month value of the Date object using local time. + * Sets the numeric day-of-the-month value of the Date object using local time. * @param date A numeric value equal to the day of the month. */ setDate(date: number): number; - /** + /** * Sets the numeric day of the month in the Date object using Universal Coordinated Time (UTC). - * @param date A numeric value equal to the day of the month. + * @param date A numeric value equal to the day of the month. */ setUTCDate(date: number): number; - /** - * Sets the month value in the Date object using local time. - * @param month A numeric value equal to the month. The value for January is 0, and other month values follow consecutively. + /** + * Sets the month value in the Date object using local time. + * @param month A numeric value equal to the month. The value for January is 0, and other month values follow consecutively. * @param date A numeric value representing the day of the month. If this value is not supplied, the value from a call to the getDate method is used. */ setMonth(month: number, date?: number): number; @@ -783,7 +783,7 @@ interface DateConstructor { */ parse(s: string): number; /** - * Returns the number of milliseconds between midnight, January 1, 1970 Universal Coordinated Time (UTC) (or GMT) and the specified date. + * Returns the number of milliseconds between midnight, January 1, 1970 Universal Coordinated Time (UTC) (or GMT) and the specified date. * @param year The full year designation is required for cross-century date accuracy. If year is between 0 and 99 is used, then year is assumed to be 1900 + year. * @param month The month as an number between 0 and 11 (January to December). * @param date The date as an number between 1 and 31. @@ -809,13 +809,13 @@ interface RegExpExecArray extends Array { } interface RegExp { - /** + /** * Executes a search on a string using a regular expression pattern, and returns an array containing the results of that search. * @param string The String object or string literal on which to perform the search. */ exec(string: string): RegExpExecArray | null; - /** + /** * Returns a Boolean value that indicates whether or not a pattern exists in a searched string. * @param string String on which to perform the search. */ @@ -840,7 +840,9 @@ interface RegExp { } interface RegExpConstructor { + new (pattern: RegExp): RegExp; new (pattern: string, flags?: string): RegExp; + (pattern: RegExp): RegExp; (pattern: string, flags?: string): RegExp; readonly prototype: RegExp; @@ -942,8 +944,8 @@ interface JSON { /** * Converts a JavaScript Object Notation (JSON) string into an object. * @param text A valid JSON string. - * @param reviver A function that transforms the results. This function is called for each member of the object. - * If a member contains nested objects, the nested objects are transformed before the parent object is. + * @param reviver A function that transforms the results. This function is called for each member of the object. + * If a member contains nested objects, the nested objects are transformed before the parent object is. */ parse(text: string, reviver?: (key: any, value: any) => any): any; /** @@ -1046,19 +1048,19 @@ interface ReadonlyArray { some(callbackfn: (value: T, index: number, array: ReadonlyArray) => boolean, thisArg?: any): boolean; /** * Performs the specified action for each element in an array. - * @param callbackfn A function that accepts up to three arguments. forEach calls the callbackfn function one time for each element in the array. + * @param callbackfn A function that accepts up to three arguments. forEach calls the callbackfn function one time for each element in the array. * @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value. */ forEach(callbackfn: (value: T, index: number, array: ReadonlyArray) => void, thisArg?: any): void; /** * Calls a defined callback function on each element of an array, and returns an array that contains the results. - * @param callbackfn A function that accepts up to three arguments. The map method calls the callbackfn function one time for each element in the array. + * @param callbackfn A function that accepts up to three arguments. The map method calls the callbackfn function one time for each element in the array. * @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value. */ map(callbackfn: (value: T, index: number, array: ReadonlyArray) => U, thisArg?: any): U[]; /** * Returns the elements of an array that meet the condition specified in a callback function. - * @param callbackfn A function that accepts up to three arguments. The filter method calls the callbackfn function one time for each element in the array. + * @param callbackfn A function that accepts up to three arguments. The filter method calls the callbackfn function one time for each element in the array. * @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value. */ filter(callbackfn: (value: T, index: number, array: ReadonlyArray) => any, thisArg?: any): T[]; @@ -1076,13 +1078,13 @@ interface ReadonlyArray { reduce(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: ReadonlyArray) => U, initialValue: U): U; /** * Calls the specified callback function for all the elements in an array, in descending order. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function. - * @param callbackfn A function that accepts up to four arguments. The reduceRight method calls the callbackfn function one time for each element in the array. + * @param callbackfn A function that accepts up to four arguments. The reduceRight method calls the callbackfn function one time for each element in the array. * @param initialValue If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value. */ reduceRight(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: ReadonlyArray) => T, initialValue?: T): T; /** * Calls the specified callback function for all the elements in an array, in descending order. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function. - * @param callbackfn A function that accepts up to four arguments. The reduceRight method calls the callbackfn function one time for each element in the array. + * @param callbackfn A function that accepts up to four arguments. The reduceRight method calls the callbackfn function one time for each element in the array. * @param initialValue If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value. */ reduceRight(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: ReadonlyArray) => U, initialValue: U): U; @@ -1120,14 +1122,14 @@ interface Array { */ join(separator?: string): string; /** - * Reverses the elements in an Array. + * Reverses the elements in an Array. */ reverse(): T[]; /** * Removes the first element from an array and returns it. */ shift(): T | undefined; - /** + /** * Returns a section of an array. * @param start The beginning of the specified portion of the array. * @param end The end of the specified portion of the array. @@ -1181,19 +1183,19 @@ interface Array { some(callbackfn: (value: T, index: number, array: T[]) => boolean, thisArg?: any): boolean; /** * Performs the specified action for each element in an array. - * @param callbackfn A function that accepts up to three arguments. forEach calls the callbackfn function one time for each element in the array. + * @param callbackfn A function that accepts up to three arguments. forEach calls the callbackfn function one time for each element in the array. * @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value. */ forEach(callbackfn: (value: T, index: number, array: T[]) => void, thisArg?: any): void; /** * Calls a defined callback function on each element of an array, and returns an array that contains the results. - * @param callbackfn A function that accepts up to three arguments. The map method calls the callbackfn function one time for each element in the array. + * @param callbackfn A function that accepts up to three arguments. The map method calls the callbackfn function one time for each element in the array. * @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value. */ map(callbackfn: (value: T, index: number, array: T[]) => U, thisArg?: any): U[]; /** - * Returns the elements of an array that meet the condition specified in a callback function. - * @param callbackfn A function that accepts up to three arguments. The filter method calls the callbackfn function one time for each element in the array. + * Returns the elements of an array that meet the condition specified in a callback function. + * @param callbackfn A function that accepts up to three arguments. The filter method calls the callbackfn function one time for each element in the array. * @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value. */ filter(callbackfn: (value: T, index: number, array: T[]) => any, thisArg?: any): T[]; @@ -1209,15 +1211,15 @@ interface Array { * @param initialValue If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value. */ reduce(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: T[]) => U, initialValue: U): U; - /** + /** * Calls the specified callback function for all the elements in an array, in descending order. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function. - * @param callbackfn A function that accepts up to four arguments. The reduceRight method calls the callbackfn function one time for each element in the array. + * @param callbackfn A function that accepts up to four arguments. The reduceRight method calls the callbackfn function one time for each element in the array. * @param initialValue If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value. */ reduceRight(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T, initialValue?: T): T; - /** + /** * Calls the specified callback function for all the elements in an array, in descending order. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function. - * @param callbackfn A function that accepts up to four arguments. The reduceRight method calls the callbackfn function one time for each element in the array. + * @param callbackfn A function that accepts up to four arguments. The reduceRight method calls the callbackfn function one time for each element in the array. * @param initialValue If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value. */ reduceRight(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: T[]) => U, initialValue: U): U; @@ -1271,10 +1273,10 @@ interface ArrayLike { } /** - * Represents a raw buffer of binary data, which is used to store data for the - * different typed arrays. ArrayBuffers cannot be read from or written to directly, - * but can be passed to a typed array or DataView Object to interpret the raw - * buffer as needed. + * Represents a raw buffer of binary data, which is used to store data for the + * different typed arrays. ArrayBuffers cannot be read from or written to directly, + * but can be passed to a typed array or DataView Object to interpret the raw + * buffer as needed. */ interface ArrayBuffer { /** @@ -1297,7 +1299,7 @@ declare const ArrayBuffer: ArrayBufferConstructor; interface ArrayBufferView { /** - * The ArrayBuffer instance referenced by the array. + * The ArrayBuffer instance referenced by the array. */ buffer: ArrayBuffer; @@ -1317,124 +1319,124 @@ interface DataView { readonly byteLength: number; readonly byteOffset: number; /** - * Gets the Float32 value at the specified byte offset from the start of the view. There is - * no alignment constraint; multi-byte values may be fetched from any offset. + * Gets the Float32 value at the specified byte offset from the start of the view. There is + * no alignment constraint; multi-byte values may be fetched from any offset. * @param byteOffset The place in the buffer at which the value should be retrieved. */ getFloat32(byteOffset: number, littleEndian?: boolean): number; /** * Gets the Float64 value at the specified byte offset from the start of the view. There is - * no alignment constraint; multi-byte values may be fetched from any offset. + * no alignment constraint; multi-byte values may be fetched from any offset. * @param byteOffset The place in the buffer at which the value should be retrieved. */ getFloat64(byteOffset: number, littleEndian?: boolean): number; /** - * Gets the Int8 value at the specified byte offset from the start of the view. There is - * no alignment constraint; multi-byte values may be fetched from any offset. + * Gets the Int8 value at the specified byte offset from the start of the view. There is + * no alignment constraint; multi-byte values may be fetched from any offset. * @param byteOffset The place in the buffer at which the value should be retrieved. */ getInt8(byteOffset: number): number; /** - * Gets the Int16 value at the specified byte offset from the start of the view. There is - * no alignment constraint; multi-byte values may be fetched from any offset. + * Gets the Int16 value at the specified byte offset from the start of the view. There is + * no alignment constraint; multi-byte values may be fetched from any offset. * @param byteOffset The place in the buffer at which the value should be retrieved. */ getInt16(byteOffset: number, littleEndian?: boolean): number; /** - * Gets the Int32 value at the specified byte offset from the start of the view. There is - * no alignment constraint; multi-byte values may be fetched from any offset. + * Gets the Int32 value at the specified byte offset from the start of the view. There is + * no alignment constraint; multi-byte values may be fetched from any offset. * @param byteOffset The place in the buffer at which the value should be retrieved. */ getInt32(byteOffset: number, littleEndian?: boolean): number; /** - * Gets the Uint8 value at the specified byte offset from the start of the view. There is - * no alignment constraint; multi-byte values may be fetched from any offset. + * Gets the Uint8 value at the specified byte offset from the start of the view. There is + * no alignment constraint; multi-byte values may be fetched from any offset. * @param byteOffset The place in the buffer at which the value should be retrieved. */ getUint8(byteOffset: number): number; /** - * Gets the Uint16 value at the specified byte offset from the start of the view. There is - * no alignment constraint; multi-byte values may be fetched from any offset. + * Gets the Uint16 value at the specified byte offset from the start of the view. There is + * no alignment constraint; multi-byte values may be fetched from any offset. * @param byteOffset The place in the buffer at which the value should be retrieved. */ getUint16(byteOffset: number, littleEndian?: boolean): number; /** - * Gets the Uint32 value at the specified byte offset from the start of the view. There is - * no alignment constraint; multi-byte values may be fetched from any offset. + * Gets the Uint32 value at the specified byte offset from the start of the view. There is + * no alignment constraint; multi-byte values may be fetched from any offset. * @param byteOffset The place in the buffer at which the value should be retrieved. */ getUint32(byteOffset: number, littleEndian?: boolean): number; /** - * Stores an Float32 value at the specified byte offset from the start of the view. + * Stores an Float32 value at the specified byte offset from the start of the view. * @param byteOffset The place in the buffer at which the value should be set. * @param value The value to set. - * @param littleEndian If false or undefined, a big-endian value should be written, + * @param littleEndian If false or undefined, a big-endian value should be written, * otherwise a little-endian value should be written. */ setFloat32(byteOffset: number, value: number, littleEndian?: boolean): void; /** - * Stores an Float64 value at the specified byte offset from the start of the view. + * Stores an Float64 value at the specified byte offset from the start of the view. * @param byteOffset The place in the buffer at which the value should be set. * @param value The value to set. - * @param littleEndian If false or undefined, a big-endian value should be written, + * @param littleEndian If false or undefined, a big-endian value should be written, * otherwise a little-endian value should be written. */ setFloat64(byteOffset: number, value: number, littleEndian?: boolean): void; /** - * Stores an Int8 value at the specified byte offset from the start of the view. + * Stores an Int8 value at the specified byte offset from the start of the view. * @param byteOffset The place in the buffer at which the value should be set. * @param value The value to set. */ setInt8(byteOffset: number, value: number): void; /** - * Stores an Int16 value at the specified byte offset from the start of the view. + * Stores an Int16 value at the specified byte offset from the start of the view. * @param byteOffset The place in the buffer at which the value should be set. * @param value The value to set. - * @param littleEndian If false or undefined, a big-endian value should be written, + * @param littleEndian If false or undefined, a big-endian value should be written, * otherwise a little-endian value should be written. */ setInt16(byteOffset: number, value: number, littleEndian?: boolean): void; /** - * Stores an Int32 value at the specified byte offset from the start of the view. + * Stores an Int32 value at the specified byte offset from the start of the view. * @param byteOffset The place in the buffer at which the value should be set. * @param value The value to set. - * @param littleEndian If false or undefined, a big-endian value should be written, + * @param littleEndian If false or undefined, a big-endian value should be written, * otherwise a little-endian value should be written. */ setInt32(byteOffset: number, value: number, littleEndian?: boolean): void; /** - * Stores an Uint8 value at the specified byte offset from the start of the view. + * Stores an Uint8 value at the specified byte offset from the start of the view. * @param byteOffset The place in the buffer at which the value should be set. * @param value The value to set. */ setUint8(byteOffset: number, value: number): void; /** - * Stores an Uint16 value at the specified byte offset from the start of the view. + * Stores an Uint16 value at the specified byte offset from the start of the view. * @param byteOffset The place in the buffer at which the value should be set. * @param value The value to set. - * @param littleEndian If false or undefined, a big-endian value should be written, + * @param littleEndian If false or undefined, a big-endian value should be written, * otherwise a little-endian value should be written. */ setUint16(byteOffset: number, value: number, littleEndian?: boolean): void; /** - * Stores an Uint32 value at the specified byte offset from the start of the view. + * Stores an Uint32 value at the specified byte offset from the start of the view. * @param byteOffset The place in the buffer at which the value should be set. * @param value The value to set. - * @param littleEndian If false or undefined, a big-endian value should be written, + * @param littleEndian If false or undefined, a big-endian value should be written, * otherwise a little-endian value should be written. */ setUint32(byteOffset: number, value: number, littleEndian?: boolean): void; @@ -1446,17 +1448,17 @@ interface DataViewConstructor { declare const DataView: DataViewConstructor; /** - * A typed array of 8-bit integer values. The contents are initialized to 0. If the requested + * A typed array of 8-bit integer values. The contents are initialized to 0. If the requested * number of bytes could not be allocated an exception is raised. */ interface Int8Array { /** - * The size in bytes of each element in the array. + * The size in bytes of each element in the array. */ readonly BYTES_PER_ELEMENT: number; /** - * The ArrayBuffer instance referenced by the array. + * The ArrayBuffer instance referenced by the array. */ readonly buffer: ArrayBuffer; @@ -1470,21 +1472,21 @@ interface Int8Array { */ readonly byteOffset: number; - /** + /** * 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 + * @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. + * @param end If not specified, length of the this object is used as its default value. */ copyWithin(target: number, start: number, end?: number): Int8Array; /** * Determines whether all the members of an array satisfy the specified test. - * @param callbackfn A function that accepts up to three arguments. The every method calls - * the callbackfn function for each element in array1 until the callbackfn returns false, + * @param callbackfn A function that accepts up to three arguments. The every method calls + * the callbackfn function for each element in array1 until the callbackfn returns false, * or until the end of the array. * @param thisArg An object to which the this keyword can refer in the callbackfn function. * If thisArg is omitted, undefined is used as the this value. @@ -1494,49 +1496,49 @@ interface Int8Array { /** * 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 + * @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: number, start?: number, end?: number): Int8Array; /** - * Returns the elements of an array that meet the condition specified in a callback function. - * @param callbackfn A function that accepts up to three arguments. The filter method calls - * the callbackfn function one time for each element in the array. - * @param thisArg An object to which the this keyword can refer in the callbackfn function. + * Returns the elements of an array that meet the condition specified in a callback function. + * @param callbackfn A function that accepts up to three arguments. The filter method calls + * the callbackfn function one time for each element in the array. + * @param thisArg An object to which the this keyword can refer in the callbackfn function. * If thisArg is omitted, undefined is used as the this value. */ filter(callbackfn: (value: number, index: number, array: Int8Array) => any, thisArg?: any): Int8Array; - /** - * Returns the value of the first element in the array where predicate is true, and undefined + /** + * 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 + * @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 + * @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: number, index: number, obj: Array) => boolean, thisArg?: any): number | undefined; - /** - * Returns the index of the first element in the array where predicate is true, and undefined + /** + * 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 + * @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 + * @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: number) => boolean, thisArg?: any): number | undefined; /** * Performs the specified action for each element in an array. - * @param callbackfn A function that accepts up to three arguments. forEach calls the - * callbackfn function one time for each element in the array. - * @param thisArg An object to which the this keyword can refer in the callbackfn function. + * @param callbackfn A function that accepts up to three arguments. forEach calls the + * callbackfn function one time for each element in the array. + * @param thisArg An object to which the this keyword can refer in the callbackfn function. * If thisArg is omitted, undefined is used as the this value. */ forEach(callbackfn: (value: number, index: number, array: Int8Array) => void, thisArg?: any): void; @@ -1551,7 +1553,7 @@ interface Int8Array { /** * Adds all the elements of an array separated by the specified separator string. - * @param separator A string used to separate one element of an array from the next in the + * @param separator A string used to separate one element of an array from the next in the * resulting String. If omitted, the array elements are separated with a comma. */ join(separator?: string): string; @@ -1559,7 +1561,7 @@ interface Int8Array { /** * Returns the index of the last occurrence of a value in an array. * @param searchElement The value to locate in the array. - * @param fromIndex The array index at which to begin the search. If fromIndex is omitted, the + * @param fromIndex The array index at which to begin the search. If fromIndex is omitted, the * search starts at index 0. */ lastIndexOf(searchElement: number, fromIndex?: number): number; @@ -1570,65 +1572,65 @@ interface Int8Array { readonly length: number; /** - * Calls a defined callback function on each element of an array, and returns an array that + * Calls a defined callback function on each element of an array, and returns an array that * contains the results. - * @param callbackfn A function that accepts up to three arguments. The map method calls the - * callbackfn function one time for each element in the array. - * @param thisArg An object to which the this keyword can refer in the callbackfn function. + * @param callbackfn A function that accepts up to three arguments. The map method calls the + * callbackfn function one time for each element in the array. + * @param thisArg An object to which the this keyword can refer in the callbackfn function. * If thisArg is omitted, undefined is used as the this value. */ map(callbackfn: (value: number, index: number, array: Int8Array) => number, thisArg?: any): Int8Array; /** - * Calls the specified callback function for all the elements in an array. The return value of - * the callback function is the accumulated result, and is provided as an argument in the next + * Calls the specified callback function for all the elements in an array. The return value of + * the callback function is the accumulated result, and is provided as an argument in the next * call to the callback function. - * @param callbackfn A function that accepts up to four arguments. The reduce method calls the + * @param callbackfn A function that accepts up to four arguments. The reduce method calls the * callbackfn function one time for each element in the array. - * @param initialValue If initialValue is specified, it is used as the initial value to start + * @param initialValue If initialValue is specified, it is used as the initial value to start * the accumulation. The first call to the callbackfn function provides this value as an argument * instead of an array value. */ reduce(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Int8Array) => number, initialValue?: number): number; /** - * Calls the specified callback function for all the elements in an array. The return value of - * the callback function is the accumulated result, and is provided as an argument in the next + * Calls the specified callback function for all the elements in an array. The return value of + * the callback function is the accumulated result, and is provided as an argument in the next * call to the callback function. - * @param callbackfn A function that accepts up to four arguments. The reduce method calls the + * @param callbackfn A function that accepts up to four arguments. The reduce method calls the * callbackfn function one time for each element in the array. - * @param initialValue If initialValue is specified, it is used as the initial value to start - * the accumulation. The first call to the callbackfn function provides this value as an argument + * @param initialValue If initialValue is specified, it is used as the initial value to start + * the accumulation. The first call to the callbackfn function provides this value as an argument * instead of an array value. */ reduce(callbackfn: (previousValue: U, currentValue: number, currentIndex: number, array: Int8Array) => U, initialValue: U): U; - /** - * Calls the specified callback function for all the elements in an array, in descending order. - * The return value of the callback function is the accumulated result, and is provided as an + /** + * Calls the specified callback function for all the elements in an array, in descending order. + * The return value of the callback function is the accumulated result, and is provided as an * argument in the next call to the callback function. - * @param callbackfn A function that accepts up to four arguments. The reduceRight method calls - * the callbackfn function one time for each element in the array. - * @param initialValue If initialValue is specified, it is used as the initial value to start - * the accumulation. The first call to the callbackfn function provides this value as an + * @param callbackfn A function that accepts up to four arguments. The reduceRight method calls + * the callbackfn function one time for each element in the array. + * @param initialValue If initialValue is specified, it is used as the initial value to start + * the accumulation. The first call to the callbackfn function provides this value as an * argument instead of an array value. */ reduceRight(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Int8Array) => number, initialValue?: number): number; - /** - * Calls the specified callback function for all the elements in an array, in descending order. - * The return value of the callback function is the accumulated result, and is provided as an + /** + * Calls the specified callback function for all the elements in an array, in descending order. + * The return value of the callback function is the accumulated result, and is provided as an * argument in the next call to the callback function. * @param callbackfn A function that accepts up to four arguments. The reduceRight method calls - * the callbackfn function one time for each element in the array. - * @param initialValue If initialValue is specified, it is used as the initial value to start + * the callbackfn function one time for each element in the array. + * @param initialValue If initialValue is specified, it is used as the initial value to start * the accumulation. The first call to the callbackfn function provides this value as an argument * instead of an array value. */ reduceRight(callbackfn: (previousValue: U, currentValue: number, currentIndex: number, array: Int8Array) => U, initialValue: U): U; /** - * Reverses the elements in an Array. + * Reverses the elements in an Array. */ reverse(): Int8Array; @@ -1646,7 +1648,7 @@ interface Int8Array { */ set(array: ArrayLike, offset?: number): void; - /** + /** * Returns a section of an array. * @param start The beginning of the specified portion of the array. * @param end The end of the specified portion of the array. @@ -1655,31 +1657,31 @@ interface Int8Array { /** * Determines whether the specified callback function returns true for any element of an array. - * @param callbackfn A function that accepts up to three arguments. The some method calls the - * callbackfn function for each element in array1 until the callbackfn returns true, or until + * @param callbackfn A function that accepts up to three arguments. The some method calls the + * callbackfn function for each element in array1 until the callbackfn returns true, or until * the end of the array. - * @param thisArg An object to which the this keyword can refer in the callbackfn function. + * @param thisArg An object to which the this keyword can refer in the callbackfn function. * If thisArg is omitted, undefined is used as the this value. */ some(callbackfn: (value: number, index: number, array: Int8Array) => boolean, thisArg?: any): boolean; /** * Sorts an array. - * @param compareFn The name of the function used to determine the order of the elements. If + * @param compareFn The name of the function used to determine the order of the elements. If * omitted, the elements are sorted in ascending, ASCII character order. */ sort(compareFn?: (a: number, b: number) => number): Int8Array; /** * Gets a new Int8Array view of the ArrayBuffer store for this array, referencing the elements - * at begin, inclusive, up to end, exclusive. + * at begin, inclusive, up to end, exclusive. * @param begin The index of the beginning of the array. * @param end The index of the end of the array. */ subarray(begin: number, end?: number): Int8Array; /** - * Converts a number to a string by using the current locale. + * Converts a number to a string by using the current locale. */ toLocaleString(): string; @@ -1697,7 +1699,7 @@ interface Int8ArrayConstructor { new (buffer: ArrayBuffer, byteOffset?: number, length?: number): Int8Array; /** - * The size in bytes of each element in the array. + * The size in bytes of each element in the array. */ readonly BYTES_PER_ELEMENT: number; @@ -1706,7 +1708,7 @@ interface Int8ArrayConstructor { * @param items A set of elements to include in the new array object. */ of(...items: number[]): Int8Array; - + /** * Creates an array from an array-like or iterable object. * @param arrayLike An array-like or iterable object to convert to an array. @@ -1719,17 +1721,17 @@ interface Int8ArrayConstructor { declare const Int8Array: Int8ArrayConstructor; /** - * A typed array of 8-bit unsigned integer values. The contents are initialized to 0. If the + * A typed array of 8-bit unsigned integer values. The contents are initialized to 0. If the * requested number of bytes could not be allocated an exception is raised. */ interface Uint8Array { /** - * The size in bytes of each element in the array. + * The size in bytes of each element in the array. */ readonly BYTES_PER_ELEMENT: number; /** - * The ArrayBuffer instance referenced by the array. + * The ArrayBuffer instance referenced by the array. */ readonly buffer: ArrayBuffer; @@ -1743,21 +1745,21 @@ interface Uint8Array { */ readonly byteOffset: number; - /** + /** * 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 + * @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. + * @param end If not specified, length of the this object is used as its default value. */ copyWithin(target: number, start: number, end?: number): Uint8Array; /** * Determines whether all the members of an array satisfy the specified test. - * @param callbackfn A function that accepts up to three arguments. The every method calls - * the callbackfn function for each element in array1 until the callbackfn returns false, + * @param callbackfn A function that accepts up to three arguments. The every method calls + * the callbackfn function for each element in array1 until the callbackfn returns false, * or until the end of the array. * @param thisArg An object to which the this keyword can refer in the callbackfn function. * If thisArg is omitted, undefined is used as the this value. @@ -1767,49 +1769,49 @@ interface Uint8Array { /** * 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 + * @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: number, start?: number, end?: number): Uint8Array; /** - * Returns the elements of an array that meet the condition specified in a callback function. - * @param callbackfn A function that accepts up to three arguments. The filter method calls - * the callbackfn function one time for each element in the array. - * @param thisArg An object to which the this keyword can refer in the callbackfn function. + * Returns the elements of an array that meet the condition specified in a callback function. + * @param callbackfn A function that accepts up to three arguments. The filter method calls + * the callbackfn function one time for each element in the array. + * @param thisArg An object to which the this keyword can refer in the callbackfn function. * If thisArg is omitted, undefined is used as the this value. */ filter(callbackfn: (value: number, index: number, array: Uint8Array) => any, thisArg?: any): Uint8Array; - /** - * Returns the value of the first element in the array where predicate is true, and undefined + /** + * 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 + * @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 + * @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: number, index: number, obj: Array) => boolean, thisArg?: any): number | undefined; - /** - * Returns the index of the first element in the array where predicate is true, and undefined + /** + * 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 + * @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 + * @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: number) => boolean, thisArg?: any): number | undefined; /** * Performs the specified action for each element in an array. - * @param callbackfn A function that accepts up to three arguments. forEach calls the - * callbackfn function one time for each element in the array. - * @param thisArg An object to which the this keyword can refer in the callbackfn function. + * @param callbackfn A function that accepts up to three arguments. forEach calls the + * callbackfn function one time for each element in the array. + * @param thisArg An object to which the this keyword can refer in the callbackfn function. * If thisArg is omitted, undefined is used as the this value. */ forEach(callbackfn: (value: number, index: number, array: Uint8Array) => void, thisArg?: any): void; @@ -1824,7 +1826,7 @@ interface Uint8Array { /** * Adds all the elements of an array separated by the specified separator string. - * @param separator A string used to separate one element of an array from the next in the + * @param separator A string used to separate one element of an array from the next in the * resulting String. If omitted, the array elements are separated with a comma. */ join(separator?: string): string; @@ -1832,7 +1834,7 @@ interface Uint8Array { /** * Returns the index of the last occurrence of a value in an array. * @param searchElement The value to locate in the array. - * @param fromIndex The array index at which to begin the search. If fromIndex is omitted, the + * @param fromIndex The array index at which to begin the search. If fromIndex is omitted, the * search starts at index 0. */ lastIndexOf(searchElement: number, fromIndex?: number): number; @@ -1843,65 +1845,65 @@ interface Uint8Array { readonly length: number; /** - * Calls a defined callback function on each element of an array, and returns an array that + * Calls a defined callback function on each element of an array, and returns an array that * contains the results. - * @param callbackfn A function that accepts up to three arguments. The map method calls the - * callbackfn function one time for each element in the array. - * @param thisArg An object to which the this keyword can refer in the callbackfn function. + * @param callbackfn A function that accepts up to three arguments. The map method calls the + * callbackfn function one time for each element in the array. + * @param thisArg An object to which the this keyword can refer in the callbackfn function. * If thisArg is omitted, undefined is used as the this value. */ map(callbackfn: (value: number, index: number, array: Uint8Array) => number, thisArg?: any): Uint8Array; /** - * Calls the specified callback function for all the elements in an array. The return value of - * the callback function is the accumulated result, and is provided as an argument in the next + * Calls the specified callback function for all the elements in an array. The return value of + * the callback function is the accumulated result, and is provided as an argument in the next * call to the callback function. - * @param callbackfn A function that accepts up to four arguments. The reduce method calls the + * @param callbackfn A function that accepts up to four arguments. The reduce method calls the * callbackfn function one time for each element in the array. - * @param initialValue If initialValue is specified, it is used as the initial value to start + * @param initialValue If initialValue is specified, it is used as the initial value to start * the accumulation. The first call to the callbackfn function provides this value as an argument * instead of an array value. */ reduce(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Uint8Array) => number, initialValue?: number): number; /** - * Calls the specified callback function for all the elements in an array. The return value of - * the callback function is the accumulated result, and is provided as an argument in the next + * Calls the specified callback function for all the elements in an array. The return value of + * the callback function is the accumulated result, and is provided as an argument in the next * call to the callback function. - * @param callbackfn A function that accepts up to four arguments. The reduce method calls the + * @param callbackfn A function that accepts up to four arguments. The reduce method calls the * callbackfn function one time for each element in the array. - * @param initialValue If initialValue is specified, it is used as the initial value to start - * the accumulation. The first call to the callbackfn function provides this value as an argument + * @param initialValue If initialValue is specified, it is used as the initial value to start + * the accumulation. The first call to the callbackfn function provides this value as an argument * instead of an array value. */ reduce(callbackfn: (previousValue: U, currentValue: number, currentIndex: number, array: Uint8Array) => U, initialValue: U): U; - /** - * Calls the specified callback function for all the elements in an array, in descending order. - * The return value of the callback function is the accumulated result, and is provided as an + /** + * Calls the specified callback function for all the elements in an array, in descending order. + * The return value of the callback function is the accumulated result, and is provided as an * argument in the next call to the callback function. - * @param callbackfn A function that accepts up to four arguments. The reduceRight method calls - * the callbackfn function one time for each element in the array. - * @param initialValue If initialValue is specified, it is used as the initial value to start - * the accumulation. The first call to the callbackfn function provides this value as an + * @param callbackfn A function that accepts up to four arguments. The reduceRight method calls + * the callbackfn function one time for each element in the array. + * @param initialValue If initialValue is specified, it is used as the initial value to start + * the accumulation. The first call to the callbackfn function provides this value as an * argument instead of an array value. */ reduceRight(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Uint8Array) => number, initialValue?: number): number; - /** - * Calls the specified callback function for all the elements in an array, in descending order. - * The return value of the callback function is the accumulated result, and is provided as an + /** + * Calls the specified callback function for all the elements in an array, in descending order. + * The return value of the callback function is the accumulated result, and is provided as an * argument in the next call to the callback function. * @param callbackfn A function that accepts up to four arguments. The reduceRight method calls - * the callbackfn function one time for each element in the array. - * @param initialValue If initialValue is specified, it is used as the initial value to start + * the callbackfn function one time for each element in the array. + * @param initialValue If initialValue is specified, it is used as the initial value to start * the accumulation. The first call to the callbackfn function provides this value as an argument * instead of an array value. */ reduceRight(callbackfn: (previousValue: U, currentValue: number, currentIndex: number, array: Uint8Array) => U, initialValue: U): U; /** - * Reverses the elements in an Array. + * Reverses the elements in an Array. */ reverse(): Uint8Array; @@ -1919,7 +1921,7 @@ interface Uint8Array { */ set(array: ArrayLike, offset?: number): void; - /** + /** * Returns a section of an array. * @param start The beginning of the specified portion of the array. * @param end The end of the specified portion of the array. @@ -1928,31 +1930,31 @@ interface Uint8Array { /** * Determines whether the specified callback function returns true for any element of an array. - * @param callbackfn A function that accepts up to three arguments. The some method calls the - * callbackfn function for each element in array1 until the callbackfn returns true, or until + * @param callbackfn A function that accepts up to three arguments. The some method calls the + * callbackfn function for each element in array1 until the callbackfn returns true, or until * the end of the array. - * @param thisArg An object to which the this keyword can refer in the callbackfn function. + * @param thisArg An object to which the this keyword can refer in the callbackfn function. * If thisArg is omitted, undefined is used as the this value. */ some(callbackfn: (value: number, index: number, array: Uint8Array) => boolean, thisArg?: any): boolean; /** * Sorts an array. - * @param compareFn The name of the function used to determine the order of the elements. If + * @param compareFn The name of the function used to determine the order of the elements. If * omitted, the elements are sorted in ascending, ASCII character order. */ sort(compareFn?: (a: number, b: number) => number): Uint8Array; /** * Gets a new Uint8Array view of the ArrayBuffer store for this array, referencing the elements - * at begin, inclusive, up to end, exclusive. + * at begin, inclusive, up to end, exclusive. * @param begin The index of the beginning of the array. * @param end The index of the end of the array. */ subarray(begin: number, end?: number): Uint8Array; /** - * Converts a number to a string by using the current locale. + * Converts a number to a string by using the current locale. */ toLocaleString(): string; @@ -1971,7 +1973,7 @@ interface Uint8ArrayConstructor { new (buffer: ArrayBuffer, byteOffset?: number, length?: number): Uint8Array; /** - * The size in bytes of each element in the array. + * The size in bytes of each element in the array. */ readonly BYTES_PER_ELEMENT: number; @@ -1980,7 +1982,7 @@ interface Uint8ArrayConstructor { * @param items A set of elements to include in the new array object. */ of(...items: number[]): Uint8Array; - + /** * Creates an array from an array-like or iterable object. * @param arrayLike An array-like or iterable object to convert to an array. @@ -1993,17 +1995,17 @@ interface Uint8ArrayConstructor { declare const Uint8Array: Uint8ArrayConstructor; /** - * A typed array of 8-bit unsigned integer (clamped) values. The contents are initialized to 0. + * A typed array of 8-bit unsigned integer (clamped) values. The contents are initialized to 0. * If the requested number of bytes could not be allocated an exception is raised. */ interface Uint8ClampedArray { /** - * The size in bytes of each element in the array. + * The size in bytes of each element in the array. */ readonly BYTES_PER_ELEMENT: number; /** - * The ArrayBuffer instance referenced by the array. + * The ArrayBuffer instance referenced by the array. */ readonly buffer: ArrayBuffer; @@ -2017,21 +2019,21 @@ interface Uint8ClampedArray { */ readonly byteOffset: number; - /** + /** * 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 + * @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. + * @param end If not specified, length of the this object is used as its default value. */ copyWithin(target: number, start: number, end?: number): Uint8ClampedArray; /** * Determines whether all the members of an array satisfy the specified test. - * @param callbackfn A function that accepts up to three arguments. The every method calls - * the callbackfn function for each element in array1 until the callbackfn returns false, + * @param callbackfn A function that accepts up to three arguments. The every method calls + * the callbackfn function for each element in array1 until the callbackfn returns false, * or until the end of the array. * @param thisArg An object to which the this keyword can refer in the callbackfn function. * If thisArg is omitted, undefined is used as the this value. @@ -2041,49 +2043,49 @@ interface Uint8ClampedArray { /** * 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 + * @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: number, start?: number, end?: number): Uint8ClampedArray; /** - * Returns the elements of an array that meet the condition specified in a callback function. - * @param callbackfn A function that accepts up to three arguments. The filter method calls - * the callbackfn function one time for each element in the array. - * @param thisArg An object to which the this keyword can refer in the callbackfn function. + * Returns the elements of an array that meet the condition specified in a callback function. + * @param callbackfn A function that accepts up to three arguments. The filter method calls + * the callbackfn function one time for each element in the array. + * @param thisArg An object to which the this keyword can refer in the callbackfn function. * If thisArg is omitted, undefined is used as the this value. */ filter(callbackfn: (value: number, index: number, array: Uint8ClampedArray) => any, thisArg?: any): Uint8ClampedArray; - /** - * Returns the value of the first element in the array where predicate is true, and undefined + /** + * 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 + * @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 + * @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: number, index: number, obj: Array) => boolean, thisArg?: any): number | undefined; - /** - * Returns the index of the first element in the array where predicate is true, and undefined + /** + * 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 + * @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 + * @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: number) => boolean, thisArg?: any): number | undefined; /** * Performs the specified action for each element in an array. - * @param callbackfn A function that accepts up to three arguments. forEach calls the - * callbackfn function one time for each element in the array. - * @param thisArg An object to which the this keyword can refer in the callbackfn function. + * @param callbackfn A function that accepts up to three arguments. forEach calls the + * callbackfn function one time for each element in the array. + * @param thisArg An object to which the this keyword can refer in the callbackfn function. * If thisArg is omitted, undefined is used as the this value. */ forEach(callbackfn: (value: number, index: number, array: Uint8ClampedArray) => void, thisArg?: any): void; @@ -2098,7 +2100,7 @@ interface Uint8ClampedArray { /** * Adds all the elements of an array separated by the specified separator string. - * @param separator A string used to separate one element of an array from the next in the + * @param separator A string used to separate one element of an array from the next in the * resulting String. If omitted, the array elements are separated with a comma. */ join(separator?: string): string; @@ -2106,7 +2108,7 @@ interface Uint8ClampedArray { /** * Returns the index of the last occurrence of a value in an array. * @param searchElement The value to locate in the array. - * @param fromIndex The array index at which to begin the search. If fromIndex is omitted, the + * @param fromIndex The array index at which to begin the search. If fromIndex is omitted, the * search starts at index 0. */ lastIndexOf(searchElement: number, fromIndex?: number): number; @@ -2117,65 +2119,65 @@ interface Uint8ClampedArray { readonly length: number; /** - * Calls a defined callback function on each element of an array, and returns an array that + * Calls a defined callback function on each element of an array, and returns an array that * contains the results. - * @param callbackfn A function that accepts up to three arguments. The map method calls the - * callbackfn function one time for each element in the array. - * @param thisArg An object to which the this keyword can refer in the callbackfn function. + * @param callbackfn A function that accepts up to three arguments. The map method calls the + * callbackfn function one time for each element in the array. + * @param thisArg An object to which the this keyword can refer in the callbackfn function. * If thisArg is omitted, undefined is used as the this value. */ map(callbackfn: (value: number, index: number, array: Uint8ClampedArray) => number, thisArg?: any): Uint8ClampedArray; /** - * Calls the specified callback function for all the elements in an array. The return value of - * the callback function is the accumulated result, and is provided as an argument in the next + * Calls the specified callback function for all the elements in an array. The return value of + * the callback function is the accumulated result, and is provided as an argument in the next * call to the callback function. - * @param callbackfn A function that accepts up to four arguments. The reduce method calls the + * @param callbackfn A function that accepts up to four arguments. The reduce method calls the * callbackfn function one time for each element in the array. - * @param initialValue If initialValue is specified, it is used as the initial value to start + * @param initialValue If initialValue is specified, it is used as the initial value to start * the accumulation. The first call to the callbackfn function provides this value as an argument * instead of an array value. */ reduce(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Uint8ClampedArray) => number, initialValue?: number): number; /** - * Calls the specified callback function for all the elements in an array. The return value of - * the callback function is the accumulated result, and is provided as an argument in the next + * Calls the specified callback function for all the elements in an array. The return value of + * the callback function is the accumulated result, and is provided as an argument in the next * call to the callback function. - * @param callbackfn A function that accepts up to four arguments. The reduce method calls the + * @param callbackfn A function that accepts up to four arguments. The reduce method calls the * callbackfn function one time for each element in the array. - * @param initialValue If initialValue is specified, it is used as the initial value to start - * the accumulation. The first call to the callbackfn function provides this value as an argument + * @param initialValue If initialValue is specified, it is used as the initial value to start + * the accumulation. The first call to the callbackfn function provides this value as an argument * instead of an array value. */ reduce(callbackfn: (previousValue: U, currentValue: number, currentIndex: number, array: Uint8ClampedArray) => U, initialValue: U): U; - /** - * Calls the specified callback function for all the elements in an array, in descending order. - * The return value of the callback function is the accumulated result, and is provided as an + /** + * Calls the specified callback function for all the elements in an array, in descending order. + * The return value of the callback function is the accumulated result, and is provided as an * argument in the next call to the callback function. - * @param callbackfn A function that accepts up to four arguments. The reduceRight method calls - * the callbackfn function one time for each element in the array. - * @param initialValue If initialValue is specified, it is used as the initial value to start - * the accumulation. The first call to the callbackfn function provides this value as an + * @param callbackfn A function that accepts up to four arguments. The reduceRight method calls + * the callbackfn function one time for each element in the array. + * @param initialValue If initialValue is specified, it is used as the initial value to start + * the accumulation. The first call to the callbackfn function provides this value as an * argument instead of an array value. */ reduceRight(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Uint8ClampedArray) => number, initialValue?: number): number; - /** - * Calls the specified callback function for all the elements in an array, in descending order. - * The return value of the callback function is the accumulated result, and is provided as an + /** + * Calls the specified callback function for all the elements in an array, in descending order. + * The return value of the callback function is the accumulated result, and is provided as an * argument in the next call to the callback function. * @param callbackfn A function that accepts up to four arguments. The reduceRight method calls - * the callbackfn function one time for each element in the array. - * @param initialValue If initialValue is specified, it is used as the initial value to start + * the callbackfn function one time for each element in the array. + * @param initialValue If initialValue is specified, it is used as the initial value to start * the accumulation. The first call to the callbackfn function provides this value as an argument * instead of an array value. */ reduceRight(callbackfn: (previousValue: U, currentValue: number, currentIndex: number, array: Uint8ClampedArray) => U, initialValue: U): U; /** - * Reverses the elements in an Array. + * Reverses the elements in an Array. */ reverse(): Uint8ClampedArray; @@ -2193,7 +2195,7 @@ interface Uint8ClampedArray { */ set(array: Uint8ClampedArray, offset?: number): void; - /** + /** * Returns a section of an array. * @param start The beginning of the specified portion of the array. * @param end The end of the specified portion of the array. @@ -2202,31 +2204,31 @@ interface Uint8ClampedArray { /** * Determines whether the specified callback function returns true for any element of an array. - * @param callbackfn A function that accepts up to three arguments. The some method calls the - * callbackfn function for each element in array1 until the callbackfn returns true, or until + * @param callbackfn A function that accepts up to three arguments. The some method calls the + * callbackfn function for each element in array1 until the callbackfn returns true, or until * the end of the array. - * @param thisArg An object to which the this keyword can refer in the callbackfn function. + * @param thisArg An object to which the this keyword can refer in the callbackfn function. * If thisArg is omitted, undefined is used as the this value. */ some(callbackfn: (value: number, index: number, array: Uint8ClampedArray) => boolean, thisArg?: any): boolean; /** * Sorts an array. - * @param compareFn The name of the function used to determine the order of the elements. If + * @param compareFn The name of the function used to determine the order of the elements. If * omitted, the elements are sorted in ascending, ASCII character order. */ sort(compareFn?: (a: number, b: number) => number): Uint8ClampedArray; /** * Gets a new Uint8ClampedArray view of the ArrayBuffer store for this array, referencing the elements - * at begin, inclusive, up to end, exclusive. + * at begin, inclusive, up to end, exclusive. * @param begin The index of the beginning of the array. * @param end The index of the end of the array. */ subarray(begin: number, end?: number): Uint8ClampedArray; /** - * Converts a number to a string by using the current locale. + * Converts a number to a string by using the current locale. */ toLocaleString(): string; @@ -2245,7 +2247,7 @@ interface Uint8ClampedArrayConstructor { new (buffer: ArrayBuffer, byteOffset?: number, length?: number): Uint8ClampedArray; /** - * The size in bytes of each element in the array. + * The size in bytes of each element in the array. */ readonly BYTES_PER_ELEMENT: number; @@ -2266,17 +2268,17 @@ interface Uint8ClampedArrayConstructor { declare const Uint8ClampedArray: Uint8ClampedArrayConstructor; /** - * A typed array of 16-bit signed integer values. The contents are initialized to 0. If the + * A typed array of 16-bit signed integer values. The contents are initialized to 0. If the * requested number of bytes could not be allocated an exception is raised. */ interface Int16Array { /** - * The size in bytes of each element in the array. + * The size in bytes of each element in the array. */ readonly BYTES_PER_ELEMENT: number; /** - * The ArrayBuffer instance referenced by the array. + * The ArrayBuffer instance referenced by the array. */ readonly buffer: ArrayBuffer; @@ -2290,21 +2292,21 @@ interface Int16Array { */ readonly byteOffset: number; - /** + /** * 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 + * @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. + * @param end If not specified, length of the this object is used as its default value. */ copyWithin(target: number, start: number, end?: number): Int16Array; /** * Determines whether all the members of an array satisfy the specified test. - * @param callbackfn A function that accepts up to three arguments. The every method calls - * the callbackfn function for each element in array1 until the callbackfn returns false, + * @param callbackfn A function that accepts up to three arguments. The every method calls + * the callbackfn function for each element in array1 until the callbackfn returns false, * or until the end of the array. * @param thisArg An object to which the this keyword can refer in the callbackfn function. * If thisArg is omitted, undefined is used as the this value. @@ -2314,49 +2316,49 @@ interface Int16Array { /** * 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 + * @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: number, start?: number, end?: number): Int16Array; /** - * Returns the elements of an array that meet the condition specified in a callback function. - * @param callbackfn A function that accepts up to three arguments. The filter method calls - * the callbackfn function one time for each element in the array. - * @param thisArg An object to which the this keyword can refer in the callbackfn function. + * Returns the elements of an array that meet the condition specified in a callback function. + * @param callbackfn A function that accepts up to three arguments. The filter method calls + * the callbackfn function one time for each element in the array. + * @param thisArg An object to which the this keyword can refer in the callbackfn function. * If thisArg is omitted, undefined is used as the this value. */ filter(callbackfn: (value: number, index: number, array: Int16Array) => any, thisArg?: any): Int16Array; - /** - * Returns the value of the first element in the array where predicate is true, and undefined + /** + * 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 + * @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 + * @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: number, index: number, obj: Array) => boolean, thisArg?: any): number | undefined; - /** - * Returns the index of the first element in the array where predicate is true, and undefined + /** + * 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 + * @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 + * @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: number) => boolean, thisArg?: any): number | undefined; /** * Performs the specified action for each element in an array. - * @param callbackfn A function that accepts up to three arguments. forEach calls the - * callbackfn function one time for each element in the array. - * @param thisArg An object to which the this keyword can refer in the callbackfn function. + * @param callbackfn A function that accepts up to three arguments. forEach calls the + * callbackfn function one time for each element in the array. + * @param thisArg An object to which the this keyword can refer in the callbackfn function. * If thisArg is omitted, undefined is used as the this value. */ forEach(callbackfn: (value: number, index: number, array: Int16Array) => void, thisArg?: any): void; @@ -2371,7 +2373,7 @@ interface Int16Array { /** * Adds all the elements of an array separated by the specified separator string. - * @param separator A string used to separate one element of an array from the next in the + * @param separator A string used to separate one element of an array from the next in the * resulting String. If omitted, the array elements are separated with a comma. */ join(separator?: string): string; @@ -2379,7 +2381,7 @@ interface Int16Array { /** * Returns the index of the last occurrence of a value in an array. * @param searchElement The value to locate in the array. - * @param fromIndex The array index at which to begin the search. If fromIndex is omitted, the + * @param fromIndex The array index at which to begin the search. If fromIndex is omitted, the * search starts at index 0. */ lastIndexOf(searchElement: number, fromIndex?: number): number; @@ -2390,65 +2392,65 @@ interface Int16Array { readonly length: number; /** - * Calls a defined callback function on each element of an array, and returns an array that + * Calls a defined callback function on each element of an array, and returns an array that * contains the results. - * @param callbackfn A function that accepts up to three arguments. The map method calls the - * callbackfn function one time for each element in the array. - * @param thisArg An object to which the this keyword can refer in the callbackfn function. + * @param callbackfn A function that accepts up to three arguments. The map method calls the + * callbackfn function one time for each element in the array. + * @param thisArg An object to which the this keyword can refer in the callbackfn function. * If thisArg is omitted, undefined is used as the this value. */ map(callbackfn: (value: number, index: number, array: Int16Array) => number, thisArg?: any): Int16Array; /** - * Calls the specified callback function for all the elements in an array. The return value of - * the callback function is the accumulated result, and is provided as an argument in the next + * Calls the specified callback function for all the elements in an array. The return value of + * the callback function is the accumulated result, and is provided as an argument in the next * call to the callback function. - * @param callbackfn A function that accepts up to four arguments. The reduce method calls the + * @param callbackfn A function that accepts up to four arguments. The reduce method calls the * callbackfn function one time for each element in the array. - * @param initialValue If initialValue is specified, it is used as the initial value to start + * @param initialValue If initialValue is specified, it is used as the initial value to start * the accumulation. The first call to the callbackfn function provides this value as an argument * instead of an array value. */ reduce(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Int16Array) => number, initialValue?: number): number; /** - * Calls the specified callback function for all the elements in an array. The return value of - * the callback function is the accumulated result, and is provided as an argument in the next + * Calls the specified callback function for all the elements in an array. The return value of + * the callback function is the accumulated result, and is provided as an argument in the next * call to the callback function. - * @param callbackfn A function that accepts up to four arguments. The reduce method calls the + * @param callbackfn A function that accepts up to four arguments. The reduce method calls the * callbackfn function one time for each element in the array. - * @param initialValue If initialValue is specified, it is used as the initial value to start - * the accumulation. The first call to the callbackfn function provides this value as an argument + * @param initialValue If initialValue is specified, it is used as the initial value to start + * the accumulation. The first call to the callbackfn function provides this value as an argument * instead of an array value. */ reduce(callbackfn: (previousValue: U, currentValue: number, currentIndex: number, array: Int16Array) => U, initialValue: U): U; - /** - * Calls the specified callback function for all the elements in an array, in descending order. - * The return value of the callback function is the accumulated result, and is provided as an + /** + * Calls the specified callback function for all the elements in an array, in descending order. + * The return value of the callback function is the accumulated result, and is provided as an * argument in the next call to the callback function. - * @param callbackfn A function that accepts up to four arguments. The reduceRight method calls - * the callbackfn function one time for each element in the array. - * @param initialValue If initialValue is specified, it is used as the initial value to start - * the accumulation. The first call to the callbackfn function provides this value as an + * @param callbackfn A function that accepts up to four arguments. The reduceRight method calls + * the callbackfn function one time for each element in the array. + * @param initialValue If initialValue is specified, it is used as the initial value to start + * the accumulation. The first call to the callbackfn function provides this value as an * argument instead of an array value. */ reduceRight(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Int16Array) => number, initialValue?: number): number; - /** - * Calls the specified callback function for all the elements in an array, in descending order. - * The return value of the callback function is the accumulated result, and is provided as an + /** + * Calls the specified callback function for all the elements in an array, in descending order. + * The return value of the callback function is the accumulated result, and is provided as an * argument in the next call to the callback function. * @param callbackfn A function that accepts up to four arguments. The reduceRight method calls - * the callbackfn function one time for each element in the array. - * @param initialValue If initialValue is specified, it is used as the initial value to start + * the callbackfn function one time for each element in the array. + * @param initialValue If initialValue is specified, it is used as the initial value to start * the accumulation. The first call to the callbackfn function provides this value as an argument * instead of an array value. */ reduceRight(callbackfn: (previousValue: U, currentValue: number, currentIndex: number, array: Int16Array) => U, initialValue: U): U; /** - * Reverses the elements in an Array. + * Reverses the elements in an Array. */ reverse(): Int16Array; @@ -2466,7 +2468,7 @@ interface Int16Array { */ set(array: ArrayLike, offset?: number): void; - /** + /** * Returns a section of an array. * @param start The beginning of the specified portion of the array. * @param end The end of the specified portion of the array. @@ -2475,31 +2477,31 @@ interface Int16Array { /** * Determines whether the specified callback function returns true for any element of an array. - * @param callbackfn A function that accepts up to three arguments. The some method calls the - * callbackfn function for each element in array1 until the callbackfn returns true, or until + * @param callbackfn A function that accepts up to three arguments. The some method calls the + * callbackfn function for each element in array1 until the callbackfn returns true, or until * the end of the array. - * @param thisArg An object to which the this keyword can refer in the callbackfn function. + * @param thisArg An object to which the this keyword can refer in the callbackfn function. * If thisArg is omitted, undefined is used as the this value. */ some(callbackfn: (value: number, index: number, array: Int16Array) => boolean, thisArg?: any): boolean; /** * Sorts an array. - * @param compareFn The name of the function used to determine the order of the elements. If + * @param compareFn The name of the function used to determine the order of the elements. If * omitted, the elements are sorted in ascending, ASCII character order. */ sort(compareFn?: (a: number, b: number) => number): Int16Array; /** * Gets a new Int16Array view of the ArrayBuffer store for this array, referencing the elements - * at begin, inclusive, up to end, exclusive. + * at begin, inclusive, up to end, exclusive. * @param begin The index of the beginning of the array. * @param end The index of the end of the array. */ subarray(begin: number, end?: number): Int16Array; /** - * Converts a number to a string by using the current locale. + * Converts a number to a string by using the current locale. */ toLocaleString(): string; @@ -2518,7 +2520,7 @@ interface Int16ArrayConstructor { new (buffer: ArrayBuffer, byteOffset?: number, length?: number): Int16Array; /** - * The size in bytes of each element in the array. + * The size in bytes of each element in the array. */ readonly BYTES_PER_ELEMENT: number; @@ -2527,7 +2529,7 @@ interface Int16ArrayConstructor { * @param items A set of elements to include in the new array object. */ of(...items: number[]): Int16Array; - + /** * Creates an array from an array-like or iterable object. * @param arrayLike An array-like or iterable object to convert to an array. @@ -2540,17 +2542,17 @@ interface Int16ArrayConstructor { declare const Int16Array: Int16ArrayConstructor; /** - * A typed array of 16-bit unsigned integer values. The contents are initialized to 0. If the + * A typed array of 16-bit unsigned integer values. The contents are initialized to 0. If the * requested number of bytes could not be allocated an exception is raised. */ interface Uint16Array { /** - * The size in bytes of each element in the array. + * The size in bytes of each element in the array. */ readonly BYTES_PER_ELEMENT: number; /** - * The ArrayBuffer instance referenced by the array. + * The ArrayBuffer instance referenced by the array. */ readonly buffer: ArrayBuffer; @@ -2564,21 +2566,21 @@ interface Uint16Array { */ readonly byteOffset: number; - /** + /** * 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 + * @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. + * @param end If not specified, length of the this object is used as its default value. */ copyWithin(target: number, start: number, end?: number): Uint16Array; /** * Determines whether all the members of an array satisfy the specified test. - * @param callbackfn A function that accepts up to three arguments. The every method calls - * the callbackfn function for each element in array1 until the callbackfn returns false, + * @param callbackfn A function that accepts up to three arguments. The every method calls + * the callbackfn function for each element in array1 until the callbackfn returns false, * or until the end of the array. * @param thisArg An object to which the this keyword can refer in the callbackfn function. * If thisArg is omitted, undefined is used as the this value. @@ -2588,49 +2590,49 @@ interface Uint16Array { /** * 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 + * @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: number, start?: number, end?: number): Uint16Array; /** - * Returns the elements of an array that meet the condition specified in a callback function. - * @param callbackfn A function that accepts up to three arguments. The filter method calls - * the callbackfn function one time for each element in the array. - * @param thisArg An object to which the this keyword can refer in the callbackfn function. + * Returns the elements of an array that meet the condition specified in a callback function. + * @param callbackfn A function that accepts up to three arguments. The filter method calls + * the callbackfn function one time for each element in the array. + * @param thisArg An object to which the this keyword can refer in the callbackfn function. * If thisArg is omitted, undefined is used as the this value. */ filter(callbackfn: (value: number, index: number, array: Uint16Array) => any, thisArg?: any): Uint16Array; - /** - * Returns the value of the first element in the array where predicate is true, and undefined + /** + * 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 + * @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 + * @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: number, index: number, obj: Array) => boolean, thisArg?: any): number | undefined; - /** - * Returns the index of the first element in the array where predicate is true, and undefined + /** + * 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 + * @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 + * @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: number) => boolean, thisArg?: any): number | undefined; /** * Performs the specified action for each element in an array. - * @param callbackfn A function that accepts up to three arguments. forEach calls the - * callbackfn function one time for each element in the array. - * @param thisArg An object to which the this keyword can refer in the callbackfn function. + * @param callbackfn A function that accepts up to three arguments. forEach calls the + * callbackfn function one time for each element in the array. + * @param thisArg An object to which the this keyword can refer in the callbackfn function. * If thisArg is omitted, undefined is used as the this value. */ forEach(callbackfn: (value: number, index: number, array: Uint16Array) => void, thisArg?: any): void; @@ -2645,7 +2647,7 @@ interface Uint16Array { /** * Adds all the elements of an array separated by the specified separator string. - * @param separator A string used to separate one element of an array from the next in the + * @param separator A string used to separate one element of an array from the next in the * resulting String. If omitted, the array elements are separated with a comma. */ join(separator?: string): string; @@ -2653,7 +2655,7 @@ interface Uint16Array { /** * Returns the index of the last occurrence of a value in an array. * @param searchElement The value to locate in the array. - * @param fromIndex The array index at which to begin the search. If fromIndex is omitted, the + * @param fromIndex The array index at which to begin the search. If fromIndex is omitted, the * search starts at index 0. */ lastIndexOf(searchElement: number, fromIndex?: number): number; @@ -2664,65 +2666,65 @@ interface Uint16Array { readonly length: number; /** - * Calls a defined callback function on each element of an array, and returns an array that + * Calls a defined callback function on each element of an array, and returns an array that * contains the results. - * @param callbackfn A function that accepts up to three arguments. The map method calls the - * callbackfn function one time for each element in the array. - * @param thisArg An object to which the this keyword can refer in the callbackfn function. + * @param callbackfn A function that accepts up to three arguments. The map method calls the + * callbackfn function one time for each element in the array. + * @param thisArg An object to which the this keyword can refer in the callbackfn function. * If thisArg is omitted, undefined is used as the this value. */ map(callbackfn: (value: number, index: number, array: Uint16Array) => number, thisArg?: any): Uint16Array; /** - * Calls the specified callback function for all the elements in an array. The return value of - * the callback function is the accumulated result, and is provided as an argument in the next + * Calls the specified callback function for all the elements in an array. The return value of + * the callback function is the accumulated result, and is provided as an argument in the next * call to the callback function. - * @param callbackfn A function that accepts up to four arguments. The reduce method calls the + * @param callbackfn A function that accepts up to four arguments. The reduce method calls the * callbackfn function one time for each element in the array. - * @param initialValue If initialValue is specified, it is used as the initial value to start + * @param initialValue If initialValue is specified, it is used as the initial value to start * the accumulation. The first call to the callbackfn function provides this value as an argument * instead of an array value. */ reduce(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Uint16Array) => number, initialValue?: number): number; /** - * Calls the specified callback function for all the elements in an array. The return value of - * the callback function is the accumulated result, and is provided as an argument in the next + * Calls the specified callback function for all the elements in an array. The return value of + * the callback function is the accumulated result, and is provided as an argument in the next * call to the callback function. - * @param callbackfn A function that accepts up to four arguments. The reduce method calls the + * @param callbackfn A function that accepts up to four arguments. The reduce method calls the * callbackfn function one time for each element in the array. - * @param initialValue If initialValue is specified, it is used as the initial value to start - * the accumulation. The first call to the callbackfn function provides this value as an argument + * @param initialValue If initialValue is specified, it is used as the initial value to start + * the accumulation. The first call to the callbackfn function provides this value as an argument * instead of an array value. */ reduce(callbackfn: (previousValue: U, currentValue: number, currentIndex: number, array: Uint16Array) => U, initialValue: U): U; - /** - * Calls the specified callback function for all the elements in an array, in descending order. - * The return value of the callback function is the accumulated result, and is provided as an + /** + * Calls the specified callback function for all the elements in an array, in descending order. + * The return value of the callback function is the accumulated result, and is provided as an * argument in the next call to the callback function. - * @param callbackfn A function that accepts up to four arguments. The reduceRight method calls - * the callbackfn function one time for each element in the array. - * @param initialValue If initialValue is specified, it is used as the initial value to start - * the accumulation. The first call to the callbackfn function provides this value as an + * @param callbackfn A function that accepts up to four arguments. The reduceRight method calls + * the callbackfn function one time for each element in the array. + * @param initialValue If initialValue is specified, it is used as the initial value to start + * the accumulation. The first call to the callbackfn function provides this value as an * argument instead of an array value. */ reduceRight(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Uint16Array) => number, initialValue?: number): number; - /** - * Calls the specified callback function for all the elements in an array, in descending order. - * The return value of the callback function is the accumulated result, and is provided as an + /** + * Calls the specified callback function for all the elements in an array, in descending order. + * The return value of the callback function is the accumulated result, and is provided as an * argument in the next call to the callback function. * @param callbackfn A function that accepts up to four arguments. The reduceRight method calls - * the callbackfn function one time for each element in the array. - * @param initialValue If initialValue is specified, it is used as the initial value to start + * the callbackfn function one time for each element in the array. + * @param initialValue If initialValue is specified, it is used as the initial value to start * the accumulation. The first call to the callbackfn function provides this value as an argument * instead of an array value. */ reduceRight(callbackfn: (previousValue: U, currentValue: number, currentIndex: number, array: Uint16Array) => U, initialValue: U): U; /** - * Reverses the elements in an Array. + * Reverses the elements in an Array. */ reverse(): Uint16Array; @@ -2740,7 +2742,7 @@ interface Uint16Array { */ set(array: ArrayLike, offset?: number): void; - /** + /** * Returns a section of an array. * @param start The beginning of the specified portion of the array. * @param end The end of the specified portion of the array. @@ -2749,31 +2751,31 @@ interface Uint16Array { /** * Determines whether the specified callback function returns true for any element of an array. - * @param callbackfn A function that accepts up to three arguments. The some method calls the - * callbackfn function for each element in array1 until the callbackfn returns true, or until + * @param callbackfn A function that accepts up to three arguments. The some method calls the + * callbackfn function for each element in array1 until the callbackfn returns true, or until * the end of the array. - * @param thisArg An object to which the this keyword can refer in the callbackfn function. + * @param thisArg An object to which the this keyword can refer in the callbackfn function. * If thisArg is omitted, undefined is used as the this value. */ some(callbackfn: (value: number, index: number, array: Uint16Array) => boolean, thisArg?: any): boolean; /** * Sorts an array. - * @param compareFn The name of the function used to determine the order of the elements. If + * @param compareFn The name of the function used to determine the order of the elements. If * omitted, the elements are sorted in ascending, ASCII character order. */ sort(compareFn?: (a: number, b: number) => number): Uint16Array; /** * Gets a new Uint16Array view of the ArrayBuffer store for this array, referencing the elements - * at begin, inclusive, up to end, exclusive. + * at begin, inclusive, up to end, exclusive. * @param begin The index of the beginning of the array. * @param end The index of the end of the array. */ subarray(begin: number, end?: number): Uint16Array; /** - * Converts a number to a string by using the current locale. + * Converts a number to a string by using the current locale. */ toLocaleString(): string; @@ -2792,7 +2794,7 @@ interface Uint16ArrayConstructor { new (buffer: ArrayBuffer, byteOffset?: number, length?: number): Uint16Array; /** - * The size in bytes of each element in the array. + * The size in bytes of each element in the array. */ readonly BYTES_PER_ELEMENT: number; @@ -2801,7 +2803,7 @@ interface Uint16ArrayConstructor { * @param items A set of elements to include in the new array object. */ of(...items: number[]): Uint16Array; - + /** * Creates an array from an array-like or iterable object. * @param arrayLike An array-like or iterable object to convert to an array. @@ -2813,17 +2815,17 @@ interface Uint16ArrayConstructor { } declare const Uint16Array: Uint16ArrayConstructor; /** - * A typed array of 32-bit signed integer values. The contents are initialized to 0. If the + * A typed array of 32-bit signed integer values. The contents are initialized to 0. If the * requested number of bytes could not be allocated an exception is raised. */ interface Int32Array { /** - * The size in bytes of each element in the array. + * The size in bytes of each element in the array. */ readonly BYTES_PER_ELEMENT: number; /** - * The ArrayBuffer instance referenced by the array. + * The ArrayBuffer instance referenced by the array. */ readonly buffer: ArrayBuffer; @@ -2837,21 +2839,21 @@ interface Int32Array { */ readonly byteOffset: number; - /** + /** * 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 + * @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. + * @param end If not specified, length of the this object is used as its default value. */ copyWithin(target: number, start: number, end?: number): Int32Array; /** * Determines whether all the members of an array satisfy the specified test. - * @param callbackfn A function that accepts up to three arguments. The every method calls - * the callbackfn function for each element in array1 until the callbackfn returns false, + * @param callbackfn A function that accepts up to three arguments. The every method calls + * the callbackfn function for each element in array1 until the callbackfn returns false, * or until the end of the array. * @param thisArg An object to which the this keyword can refer in the callbackfn function. * If thisArg is omitted, undefined is used as the this value. @@ -2861,49 +2863,49 @@ interface Int32Array { /** * 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 + * @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: number, start?: number, end?: number): Int32Array; /** - * Returns the elements of an array that meet the condition specified in a callback function. - * @param callbackfn A function that accepts up to three arguments. The filter method calls - * the callbackfn function one time for each element in the array. - * @param thisArg An object to which the this keyword can refer in the callbackfn function. + * Returns the elements of an array that meet the condition specified in a callback function. + * @param callbackfn A function that accepts up to three arguments. The filter method calls + * the callbackfn function one time for each element in the array. + * @param thisArg An object to which the this keyword can refer in the callbackfn function. * If thisArg is omitted, undefined is used as the this value. */ filter(callbackfn: (value: number, index: number, array: Int32Array) => any, thisArg?: any): Int32Array; - /** - * Returns the value of the first element in the array where predicate is true, and undefined + /** + * 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 + * @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 + * @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: number, index: number, obj: Array) => boolean, thisArg?: any): number | undefined; - /** - * Returns the index of the first element in the array where predicate is true, and undefined + /** + * 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 + * @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 + * @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: number) => boolean, thisArg?: any): number | undefined; /** * Performs the specified action for each element in an array. - * @param callbackfn A function that accepts up to three arguments. forEach calls the - * callbackfn function one time for each element in the array. - * @param thisArg An object to which the this keyword can refer in the callbackfn function. + * @param callbackfn A function that accepts up to three arguments. forEach calls the + * callbackfn function one time for each element in the array. + * @param thisArg An object to which the this keyword can refer in the callbackfn function. * If thisArg is omitted, undefined is used as the this value. */ forEach(callbackfn: (value: number, index: number, array: Int32Array) => void, thisArg?: any): void; @@ -2918,7 +2920,7 @@ interface Int32Array { /** * Adds all the elements of an array separated by the specified separator string. - * @param separator A string used to separate one element of an array from the next in the + * @param separator A string used to separate one element of an array from the next in the * resulting String. If omitted, the array elements are separated with a comma. */ join(separator?: string): string; @@ -2926,7 +2928,7 @@ interface Int32Array { /** * Returns the index of the last occurrence of a value in an array. * @param searchElement The value to locate in the array. - * @param fromIndex The array index at which to begin the search. If fromIndex is omitted, the + * @param fromIndex The array index at which to begin the search. If fromIndex is omitted, the * search starts at index 0. */ lastIndexOf(searchElement: number, fromIndex?: number): number; @@ -2937,65 +2939,65 @@ interface Int32Array { readonly length: number; /** - * Calls a defined callback function on each element of an array, and returns an array that + * Calls a defined callback function on each element of an array, and returns an array that * contains the results. - * @param callbackfn A function that accepts up to three arguments. The map method calls the - * callbackfn function one time for each element in the array. - * @param thisArg An object to which the this keyword can refer in the callbackfn function. + * @param callbackfn A function that accepts up to three arguments. The map method calls the + * callbackfn function one time for each element in the array. + * @param thisArg An object to which the this keyword can refer in the callbackfn function. * If thisArg is omitted, undefined is used as the this value. */ map(callbackfn: (value: number, index: number, array: Int32Array) => number, thisArg?: any): Int32Array; /** - * Calls the specified callback function for all the elements in an array. The return value of - * the callback function is the accumulated result, and is provided as an argument in the next + * Calls the specified callback function for all the elements in an array. The return value of + * the callback function is the accumulated result, and is provided as an argument in the next * call to the callback function. - * @param callbackfn A function that accepts up to four arguments. The reduce method calls the + * @param callbackfn A function that accepts up to four arguments. The reduce method calls the * callbackfn function one time for each element in the array. - * @param initialValue If initialValue is specified, it is used as the initial value to start + * @param initialValue If initialValue is specified, it is used as the initial value to start * the accumulation. The first call to the callbackfn function provides this value as an argument * instead of an array value. */ reduce(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Int32Array) => number, initialValue?: number): number; /** - * Calls the specified callback function for all the elements in an array. The return value of - * the callback function is the accumulated result, and is provided as an argument in the next + * Calls the specified callback function for all the elements in an array. The return value of + * the callback function is the accumulated result, and is provided as an argument in the next * call to the callback function. - * @param callbackfn A function that accepts up to four arguments. The reduce method calls the + * @param callbackfn A function that accepts up to four arguments. The reduce method calls the * callbackfn function one time for each element in the array. - * @param initialValue If initialValue is specified, it is used as the initial value to start - * the accumulation. The first call to the callbackfn function provides this value as an argument + * @param initialValue If initialValue is specified, it is used as the initial value to start + * the accumulation. The first call to the callbackfn function provides this value as an argument * instead of an array value. */ reduce(callbackfn: (previousValue: U, currentValue: number, currentIndex: number, array: Int32Array) => U, initialValue: U): U; - /** - * Calls the specified callback function for all the elements in an array, in descending order. - * The return value of the callback function is the accumulated result, and is provided as an + /** + * Calls the specified callback function for all the elements in an array, in descending order. + * The return value of the callback function is the accumulated result, and is provided as an * argument in the next call to the callback function. - * @param callbackfn A function that accepts up to four arguments. The reduceRight method calls - * the callbackfn function one time for each element in the array. - * @param initialValue If initialValue is specified, it is used as the initial value to start - * the accumulation. The first call to the callbackfn function provides this value as an + * @param callbackfn A function that accepts up to four arguments. The reduceRight method calls + * the callbackfn function one time for each element in the array. + * @param initialValue If initialValue is specified, it is used as the initial value to start + * the accumulation. The first call to the callbackfn function provides this value as an * argument instead of an array value. */ reduceRight(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Int32Array) => number, initialValue?: number): number; - /** - * Calls the specified callback function for all the elements in an array, in descending order. - * The return value of the callback function is the accumulated result, and is provided as an + /** + * Calls the specified callback function for all the elements in an array, in descending order. + * The return value of the callback function is the accumulated result, and is provided as an * argument in the next call to the callback function. * @param callbackfn A function that accepts up to four arguments. The reduceRight method calls - * the callbackfn function one time for each element in the array. - * @param initialValue If initialValue is specified, it is used as the initial value to start + * the callbackfn function one time for each element in the array. + * @param initialValue If initialValue is specified, it is used as the initial value to start * the accumulation. The first call to the callbackfn function provides this value as an argument * instead of an array value. */ reduceRight(callbackfn: (previousValue: U, currentValue: number, currentIndex: number, array: Int32Array) => U, initialValue: U): U; /** - * Reverses the elements in an Array. + * Reverses the elements in an Array. */ reverse(): Int32Array; @@ -3013,7 +3015,7 @@ interface Int32Array { */ set(array: ArrayLike, offset?: number): void; - /** + /** * Returns a section of an array. * @param start The beginning of the specified portion of the array. * @param end The end of the specified portion of the array. @@ -3022,31 +3024,31 @@ interface Int32Array { /** * Determines whether the specified callback function returns true for any element of an array. - * @param callbackfn A function that accepts up to three arguments. The some method calls the - * callbackfn function for each element in array1 until the callbackfn returns true, or until + * @param callbackfn A function that accepts up to three arguments. The some method calls the + * callbackfn function for each element in array1 until the callbackfn returns true, or until * the end of the array. - * @param thisArg An object to which the this keyword can refer in the callbackfn function. + * @param thisArg An object to which the this keyword can refer in the callbackfn function. * If thisArg is omitted, undefined is used as the this value. */ some(callbackfn: (value: number, index: number, array: Int32Array) => boolean, thisArg?: any): boolean; /** * Sorts an array. - * @param compareFn The name of the function used to determine the order of the elements. If + * @param compareFn The name of the function used to determine the order of the elements. If * omitted, the elements are sorted in ascending, ASCII character order. */ sort(compareFn?: (a: number, b: number) => number): Int32Array; /** * Gets a new Int32Array view of the ArrayBuffer store for this array, referencing the elements - * at begin, inclusive, up to end, exclusive. + * at begin, inclusive, up to end, exclusive. * @param begin The index of the beginning of the array. * @param end The index of the end of the array. */ subarray(begin: number, end?: number): Int32Array; /** - * Converts a number to a string by using the current locale. + * Converts a number to a string by using the current locale. */ toLocaleString(): string; @@ -3065,7 +3067,7 @@ interface Int32ArrayConstructor { new (buffer: ArrayBuffer, byteOffset?: number, length?: number): Int32Array; /** - * The size in bytes of each element in the array. + * The size in bytes of each element in the array. */ readonly BYTES_PER_ELEMENT: number; @@ -3074,7 +3076,7 @@ interface Int32ArrayConstructor { * @param items A set of elements to include in the new array object. */ of(...items: number[]): Int32Array; - + /** * Creates an array from an array-like or iterable object. * @param arrayLike An array-like or iterable object to convert to an array. @@ -3086,17 +3088,17 @@ interface Int32ArrayConstructor { declare const Int32Array: Int32ArrayConstructor; /** - * A typed array of 32-bit unsigned integer values. The contents are initialized to 0. If the + * A typed array of 32-bit unsigned integer values. The contents are initialized to 0. If the * requested number of bytes could not be allocated an exception is raised. */ interface Uint32Array { /** - * The size in bytes of each element in the array. + * The size in bytes of each element in the array. */ readonly BYTES_PER_ELEMENT: number; /** - * The ArrayBuffer instance referenced by the array. + * The ArrayBuffer instance referenced by the array. */ readonly buffer: ArrayBuffer; @@ -3110,21 +3112,21 @@ interface Uint32Array { */ readonly byteOffset: number; - /** + /** * 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 + * @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. + * @param end If not specified, length of the this object is used as its default value. */ copyWithin(target: number, start: number, end?: number): Uint32Array; /** * Determines whether all the members of an array satisfy the specified test. - * @param callbackfn A function that accepts up to three arguments. The every method calls - * the callbackfn function for each element in array1 until the callbackfn returns false, + * @param callbackfn A function that accepts up to three arguments. The every method calls + * the callbackfn function for each element in array1 until the callbackfn returns false, * or until the end of the array. * @param thisArg An object to which the this keyword can refer in the callbackfn function. * If thisArg is omitted, undefined is used as the this value. @@ -3134,49 +3136,49 @@ interface Uint32Array { /** * 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 + * @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: number, start?: number, end?: number): Uint32Array; /** - * Returns the elements of an array that meet the condition specified in a callback function. - * @param callbackfn A function that accepts up to three arguments. The filter method calls - * the callbackfn function one time for each element in the array. - * @param thisArg An object to which the this keyword can refer in the callbackfn function. + * Returns the elements of an array that meet the condition specified in a callback function. + * @param callbackfn A function that accepts up to three arguments. The filter method calls + * the callbackfn function one time for each element in the array. + * @param thisArg An object to which the this keyword can refer in the callbackfn function. * If thisArg is omitted, undefined is used as the this value. */ filter(callbackfn: (value: number, index: number, array: Uint32Array) => any, thisArg?: any): Uint32Array; - /** - * Returns the value of the first element in the array where predicate is true, and undefined + /** + * 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 + * @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 + * @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: number, index: number, obj: Array) => boolean, thisArg?: any): number | undefined; - /** - * Returns the index of the first element in the array where predicate is true, and undefined + /** + * 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 + * @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 + * @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: number) => boolean, thisArg?: any): number | undefined; /** * Performs the specified action for each element in an array. - * @param callbackfn A function that accepts up to three arguments. forEach calls the - * callbackfn function one time for each element in the array. - * @param thisArg An object to which the this keyword can refer in the callbackfn function. + * @param callbackfn A function that accepts up to three arguments. forEach calls the + * callbackfn function one time for each element in the array. + * @param thisArg An object to which the this keyword can refer in the callbackfn function. * If thisArg is omitted, undefined is used as the this value. */ forEach(callbackfn: (value: number, index: number, array: Uint32Array) => void, thisArg?: any): void; @@ -3191,7 +3193,7 @@ interface Uint32Array { /** * Adds all the elements of an array separated by the specified separator string. - * @param separator A string used to separate one element of an array from the next in the + * @param separator A string used to separate one element of an array from the next in the * resulting String. If omitted, the array elements are separated with a comma. */ join(separator?: string): string; @@ -3199,7 +3201,7 @@ interface Uint32Array { /** * Returns the index of the last occurrence of a value in an array. * @param searchElement The value to locate in the array. - * @param fromIndex The array index at which to begin the search. If fromIndex is omitted, the + * @param fromIndex The array index at which to begin the search. If fromIndex is omitted, the * search starts at index 0. */ lastIndexOf(searchElement: number, fromIndex?: number): number; @@ -3210,65 +3212,65 @@ interface Uint32Array { readonly length: number; /** - * Calls a defined callback function on each element of an array, and returns an array that + * Calls a defined callback function on each element of an array, and returns an array that * contains the results. - * @param callbackfn A function that accepts up to three arguments. The map method calls the - * callbackfn function one time for each element in the array. - * @param thisArg An object to which the this keyword can refer in the callbackfn function. + * @param callbackfn A function that accepts up to three arguments. The map method calls the + * callbackfn function one time for each element in the array. + * @param thisArg An object to which the this keyword can refer in the callbackfn function. * If thisArg is omitted, undefined is used as the this value. */ map(callbackfn: (value: number, index: number, array: Uint32Array) => number, thisArg?: any): Uint32Array; /** - * Calls the specified callback function for all the elements in an array. The return value of - * the callback function is the accumulated result, and is provided as an argument in the next + * Calls the specified callback function for all the elements in an array. The return value of + * the callback function is the accumulated result, and is provided as an argument in the next * call to the callback function. - * @param callbackfn A function that accepts up to four arguments. The reduce method calls the + * @param callbackfn A function that accepts up to four arguments. The reduce method calls the * callbackfn function one time for each element in the array. - * @param initialValue If initialValue is specified, it is used as the initial value to start + * @param initialValue If initialValue is specified, it is used as the initial value to start * the accumulation. The first call to the callbackfn function provides this value as an argument * instead of an array value. */ reduce(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Uint32Array) => number, initialValue?: number): number; /** - * Calls the specified callback function for all the elements in an array. The return value of - * the callback function is the accumulated result, and is provided as an argument in the next + * Calls the specified callback function for all the elements in an array. The return value of + * the callback function is the accumulated result, and is provided as an argument in the next * call to the callback function. - * @param callbackfn A function that accepts up to four arguments. The reduce method calls the + * @param callbackfn A function that accepts up to four arguments. The reduce method calls the * callbackfn function one time for each element in the array. - * @param initialValue If initialValue is specified, it is used as the initial value to start - * the accumulation. The first call to the callbackfn function provides this value as an argument + * @param initialValue If initialValue is specified, it is used as the initial value to start + * the accumulation. The first call to the callbackfn function provides this value as an argument * instead of an array value. */ reduce(callbackfn: (previousValue: U, currentValue: number, currentIndex: number, array: Uint32Array) => U, initialValue: U): U; - /** - * Calls the specified callback function for all the elements in an array, in descending order. - * The return value of the callback function is the accumulated result, and is provided as an + /** + * Calls the specified callback function for all the elements in an array, in descending order. + * The return value of the callback function is the accumulated result, and is provided as an * argument in the next call to the callback function. - * @param callbackfn A function that accepts up to four arguments. The reduceRight method calls - * the callbackfn function one time for each element in the array. - * @param initialValue If initialValue is specified, it is used as the initial value to start - * the accumulation. The first call to the callbackfn function provides this value as an + * @param callbackfn A function that accepts up to four arguments. The reduceRight method calls + * the callbackfn function one time for each element in the array. + * @param initialValue If initialValue is specified, it is used as the initial value to start + * the accumulation. The first call to the callbackfn function provides this value as an * argument instead of an array value. */ reduceRight(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Uint32Array) => number, initialValue?: number): number; - /** - * Calls the specified callback function for all the elements in an array, in descending order. - * The return value of the callback function is the accumulated result, and is provided as an + /** + * Calls the specified callback function for all the elements in an array, in descending order. + * The return value of the callback function is the accumulated result, and is provided as an * argument in the next call to the callback function. * @param callbackfn A function that accepts up to four arguments. The reduceRight method calls - * the callbackfn function one time for each element in the array. - * @param initialValue If initialValue is specified, it is used as the initial value to start + * the callbackfn function one time for each element in the array. + * @param initialValue If initialValue is specified, it is used as the initial value to start * the accumulation. The first call to the callbackfn function provides this value as an argument * instead of an array value. */ reduceRight(callbackfn: (previousValue: U, currentValue: number, currentIndex: number, array: Uint32Array) => U, initialValue: U): U; /** - * Reverses the elements in an Array. + * Reverses the elements in an Array. */ reverse(): Uint32Array; @@ -3286,7 +3288,7 @@ interface Uint32Array { */ set(array: ArrayLike, offset?: number): void; - /** + /** * Returns a section of an array. * @param start The beginning of the specified portion of the array. * @param end The end of the specified portion of the array. @@ -3295,31 +3297,31 @@ interface Uint32Array { /** * Determines whether the specified callback function returns true for any element of an array. - * @param callbackfn A function that accepts up to three arguments. The some method calls the - * callbackfn function for each element in array1 until the callbackfn returns true, or until + * @param callbackfn A function that accepts up to three arguments. The some method calls the + * callbackfn function for each element in array1 until the callbackfn returns true, or until * the end of the array. - * @param thisArg An object to which the this keyword can refer in the callbackfn function. + * @param thisArg An object to which the this keyword can refer in the callbackfn function. * If thisArg is omitted, undefined is used as the this value. */ some(callbackfn: (value: number, index: number, array: Uint32Array) => boolean, thisArg?: any): boolean; /** * Sorts an array. - * @param compareFn The name of the function used to determine the order of the elements. If + * @param compareFn The name of the function used to determine the order of the elements. If * omitted, the elements are sorted in ascending, ASCII character order. */ sort(compareFn?: (a: number, b: number) => number): Uint32Array; /** * Gets a new Uint32Array view of the ArrayBuffer store for this array, referencing the elements - * at begin, inclusive, up to end, exclusive. + * at begin, inclusive, up to end, exclusive. * @param begin The index of the beginning of the array. * @param end The index of the end of the array. */ subarray(begin: number, end?: number): Uint32Array; /** - * Converts a number to a string by using the current locale. + * Converts a number to a string by using the current locale. */ toLocaleString(): string; @@ -3338,7 +3340,7 @@ interface Uint32ArrayConstructor { new (buffer: ArrayBuffer, byteOffset?: number, length?: number): Uint32Array; /** - * The size in bytes of each element in the array. + * The size in bytes of each element in the array. */ readonly BYTES_PER_ELEMENT: number; @@ -3347,7 +3349,7 @@ interface Uint32ArrayConstructor { * @param items A set of elements to include in the new array object. */ of(...items: number[]): Uint32Array; - + /** * Creates an array from an array-like or iterable object. * @param arrayLike An array-like or iterable object to convert to an array. @@ -3364,12 +3366,12 @@ declare const Uint32Array: Uint32ArrayConstructor; */ interface Float32Array { /** - * The size in bytes of each element in the array. + * The size in bytes of each element in the array. */ readonly BYTES_PER_ELEMENT: number; /** - * The ArrayBuffer instance referenced by the array. + * The ArrayBuffer instance referenced by the array. */ readonly buffer: ArrayBuffer; @@ -3383,21 +3385,21 @@ interface Float32Array { */ readonly byteOffset: number; - /** + /** * 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 + * @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. + * @param end If not specified, length of the this object is used as its default value. */ copyWithin(target: number, start: number, end?: number): Float32Array; /** * Determines whether all the members of an array satisfy the specified test. - * @param callbackfn A function that accepts up to three arguments. The every method calls - * the callbackfn function for each element in array1 until the callbackfn returns false, + * @param callbackfn A function that accepts up to three arguments. The every method calls + * the callbackfn function for each element in array1 until the callbackfn returns false, * or until the end of the array. * @param thisArg An object to which the this keyword can refer in the callbackfn function. * If thisArg is omitted, undefined is used as the this value. @@ -3407,49 +3409,49 @@ interface Float32Array { /** * 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 + * @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: number, start?: number, end?: number): Float32Array; /** - * Returns the elements of an array that meet the condition specified in a callback function. - * @param callbackfn A function that accepts up to three arguments. The filter method calls - * the callbackfn function one time for each element in the array. - * @param thisArg An object to which the this keyword can refer in the callbackfn function. + * Returns the elements of an array that meet the condition specified in a callback function. + * @param callbackfn A function that accepts up to three arguments. The filter method calls + * the callbackfn function one time for each element in the array. + * @param thisArg An object to which the this keyword can refer in the callbackfn function. * If thisArg is omitted, undefined is used as the this value. */ filter(callbackfn: (value: number, index: number, array: Float32Array) => any, thisArg?: any): Float32Array; - /** - * Returns the value of the first element in the array where predicate is true, and undefined + /** + * 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 + * @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 + * @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: number, index: number, obj: Array) => boolean, thisArg?: any): number | undefined; - /** - * Returns the index of the first element in the array where predicate is true, and undefined + /** + * 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 + * @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 + * @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: number) => boolean, thisArg?: any): number | undefined; /** * Performs the specified action for each element in an array. - * @param callbackfn A function that accepts up to three arguments. forEach calls the - * callbackfn function one time for each element in the array. - * @param thisArg An object to which the this keyword can refer in the callbackfn function. + * @param callbackfn A function that accepts up to three arguments. forEach calls the + * callbackfn function one time for each element in the array. + * @param thisArg An object to which the this keyword can refer in the callbackfn function. * If thisArg is omitted, undefined is used as the this value. */ forEach(callbackfn: (value: number, index: number, array: Float32Array) => void, thisArg?: any): void; @@ -3464,7 +3466,7 @@ interface Float32Array { /** * Adds all the elements of an array separated by the specified separator string. - * @param separator A string used to separate one element of an array from the next in the + * @param separator A string used to separate one element of an array from the next in the * resulting String. If omitted, the array elements are separated with a comma. */ join(separator?: string): string; @@ -3472,7 +3474,7 @@ interface Float32Array { /** * Returns the index of the last occurrence of a value in an array. * @param searchElement The value to locate in the array. - * @param fromIndex The array index at which to begin the search. If fromIndex is omitted, the + * @param fromIndex The array index at which to begin the search. If fromIndex is omitted, the * search starts at index 0. */ lastIndexOf(searchElement: number, fromIndex?: number): number; @@ -3483,65 +3485,65 @@ interface Float32Array { readonly length: number; /** - * Calls a defined callback function on each element of an array, and returns an array that + * Calls a defined callback function on each element of an array, and returns an array that * contains the results. - * @param callbackfn A function that accepts up to three arguments. The map method calls the - * callbackfn function one time for each element in the array. - * @param thisArg An object to which the this keyword can refer in the callbackfn function. + * @param callbackfn A function that accepts up to three arguments. The map method calls the + * callbackfn function one time for each element in the array. + * @param thisArg An object to which the this keyword can refer in the callbackfn function. * If thisArg is omitted, undefined is used as the this value. */ map(callbackfn: (value: number, index: number, array: Float32Array) => number, thisArg?: any): Float32Array; /** - * Calls the specified callback function for all the elements in an array. The return value of - * the callback function is the accumulated result, and is provided as an argument in the next + * Calls the specified callback function for all the elements in an array. The return value of + * the callback function is the accumulated result, and is provided as an argument in the next * call to the callback function. - * @param callbackfn A function that accepts up to four arguments. The reduce method calls the + * @param callbackfn A function that accepts up to four arguments. The reduce method calls the * callbackfn function one time for each element in the array. - * @param initialValue If initialValue is specified, it is used as the initial value to start + * @param initialValue If initialValue is specified, it is used as the initial value to start * the accumulation. The first call to the callbackfn function provides this value as an argument * instead of an array value. */ reduce(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Float32Array) => number, initialValue?: number): number; /** - * Calls the specified callback function for all the elements in an array. The return value of - * the callback function is the accumulated result, and is provided as an argument in the next + * Calls the specified callback function for all the elements in an array. The return value of + * the callback function is the accumulated result, and is provided as an argument in the next * call to the callback function. - * @param callbackfn A function that accepts up to four arguments. The reduce method calls the + * @param callbackfn A function that accepts up to four arguments. The reduce method calls the * callbackfn function one time for each element in the array. - * @param initialValue If initialValue is specified, it is used as the initial value to start - * the accumulation. The first call to the callbackfn function provides this value as an argument + * @param initialValue If initialValue is specified, it is used as the initial value to start + * the accumulation. The first call to the callbackfn function provides this value as an argument * instead of an array value. */ reduce(callbackfn: (previousValue: U, currentValue: number, currentIndex: number, array: Float32Array) => U, initialValue: U): U; - /** - * Calls the specified callback function for all the elements in an array, in descending order. - * The return value of the callback function is the accumulated result, and is provided as an + /** + * Calls the specified callback function for all the elements in an array, in descending order. + * The return value of the callback function is the accumulated result, and is provided as an * argument in the next call to the callback function. - * @param callbackfn A function that accepts up to four arguments. The reduceRight method calls - * the callbackfn function one time for each element in the array. - * @param initialValue If initialValue is specified, it is used as the initial value to start - * the accumulation. The first call to the callbackfn function provides this value as an + * @param callbackfn A function that accepts up to four arguments. The reduceRight method calls + * the callbackfn function one time for each element in the array. + * @param initialValue If initialValue is specified, it is used as the initial value to start + * the accumulation. The first call to the callbackfn function provides this value as an * argument instead of an array value. */ reduceRight(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Float32Array) => number, initialValue?: number): number; - /** - * Calls the specified callback function for all the elements in an array, in descending order. - * The return value of the callback function is the accumulated result, and is provided as an + /** + * Calls the specified callback function for all the elements in an array, in descending order. + * The return value of the callback function is the accumulated result, and is provided as an * argument in the next call to the callback function. * @param callbackfn A function that accepts up to four arguments. The reduceRight method calls - * the callbackfn function one time for each element in the array. - * @param initialValue If initialValue is specified, it is used as the initial value to start + * the callbackfn function one time for each element in the array. + * @param initialValue If initialValue is specified, it is used as the initial value to start * the accumulation. The first call to the callbackfn function provides this value as an argument * instead of an array value. */ reduceRight(callbackfn: (previousValue: U, currentValue: number, currentIndex: number, array: Float32Array) => U, initialValue: U): U; /** - * Reverses the elements in an Array. + * Reverses the elements in an Array. */ reverse(): Float32Array; @@ -3559,7 +3561,7 @@ interface Float32Array { */ set(array: ArrayLike, offset?: number): void; - /** + /** * Returns a section of an array. * @param start The beginning of the specified portion of the array. * @param end The end of the specified portion of the array. @@ -3568,31 +3570,31 @@ interface Float32Array { /** * Determines whether the specified callback function returns true for any element of an array. - * @param callbackfn A function that accepts up to three arguments. The some method calls the - * callbackfn function for each element in array1 until the callbackfn returns true, or until + * @param callbackfn A function that accepts up to three arguments. The some method calls the + * callbackfn function for each element in array1 until the callbackfn returns true, or until * the end of the array. - * @param thisArg An object to which the this keyword can refer in the callbackfn function. + * @param thisArg An object to which the this keyword can refer in the callbackfn function. * If thisArg is omitted, undefined is used as the this value. */ some(callbackfn: (value: number, index: number, array: Float32Array) => boolean, thisArg?: any): boolean; /** * Sorts an array. - * @param compareFn The name of the function used to determine the order of the elements. If + * @param compareFn The name of the function used to determine the order of the elements. If * omitted, the elements are sorted in ascending, ASCII character order. */ sort(compareFn?: (a: number, b: number) => number): Float32Array; /** * Gets a new Float32Array view of the ArrayBuffer store for this array, referencing the elements - * at begin, inclusive, up to end, exclusive. + * at begin, inclusive, up to end, exclusive. * @param begin The index of the beginning of the array. * @param end The index of the end of the array. */ subarray(begin: number, end?: number): Float32Array; /** - * Converts a number to a string by using the current locale. + * Converts a number to a string by using the current locale. */ toLocaleString(): string; @@ -3611,7 +3613,7 @@ interface Float32ArrayConstructor { new (buffer: ArrayBuffer, byteOffset?: number, length?: number): Float32Array; /** - * The size in bytes of each element in the array. + * The size in bytes of each element in the array. */ readonly BYTES_PER_ELEMENT: number; @@ -3620,7 +3622,7 @@ interface Float32ArrayConstructor { * @param items A set of elements to include in the new array object. */ of(...items: number[]): Float32Array; - + /** * Creates an array from an array-like or iterable object. * @param arrayLike An array-like or iterable object to convert to an array. @@ -3633,17 +3635,17 @@ interface Float32ArrayConstructor { declare const Float32Array: Float32ArrayConstructor; /** - * A typed array of 64-bit float values. The contents are initialized to 0. If the requested + * A typed array of 64-bit float values. The contents are initialized to 0. If the requested * number of bytes could not be allocated an exception is raised. */ interface Float64Array { /** - * The size in bytes of each element in the array. + * The size in bytes of each element in the array. */ readonly BYTES_PER_ELEMENT: number; /** - * The ArrayBuffer instance referenced by the array. + * The ArrayBuffer instance referenced by the array. */ readonly buffer: ArrayBuffer; @@ -3657,21 +3659,21 @@ interface Float64Array { */ readonly byteOffset: number; - /** + /** * 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 + * @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. + * @param end If not specified, length of the this object is used as its default value. */ copyWithin(target: number, start: number, end?: number): Float64Array; /** * Determines whether all the members of an array satisfy the specified test. - * @param callbackfn A function that accepts up to three arguments. The every method calls - * the callbackfn function for each element in array1 until the callbackfn returns false, + * @param callbackfn A function that accepts up to three arguments. The every method calls + * the callbackfn function for each element in array1 until the callbackfn returns false, * or until the end of the array. * @param thisArg An object to which the this keyword can refer in the callbackfn function. * If thisArg is omitted, undefined is used as the this value. @@ -3681,49 +3683,49 @@ interface Float64Array { /** * 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 + * @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: number, start?: number, end?: number): Float64Array; /** - * Returns the elements of an array that meet the condition specified in a callback function. - * @param callbackfn A function that accepts up to three arguments. The filter method calls - * the callbackfn function one time for each element in the array. - * @param thisArg An object to which the this keyword can refer in the callbackfn function. + * Returns the elements of an array that meet the condition specified in a callback function. + * @param callbackfn A function that accepts up to three arguments. The filter method calls + * the callbackfn function one time for each element in the array. + * @param thisArg An object to which the this keyword can refer in the callbackfn function. * If thisArg is omitted, undefined is used as the this value. */ filter(callbackfn: (value: number, index: number, array: Float64Array) => any, thisArg?: any): Float64Array; - /** - * Returns the value of the first element in the array where predicate is true, and undefined + /** + * 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 + * @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 + * @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: number, index: number, obj: Array) => boolean, thisArg?: any): number | undefined; - /** - * Returns the index of the first element in the array where predicate is true, and undefined + /** + * 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 + * @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 + * @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: number) => boolean, thisArg?: any): number | undefined; /** * Performs the specified action for each element in an array. - * @param callbackfn A function that accepts up to three arguments. forEach calls the - * callbackfn function one time for each element in the array. - * @param thisArg An object to which the this keyword can refer in the callbackfn function. + * @param callbackfn A function that accepts up to three arguments. forEach calls the + * callbackfn function one time for each element in the array. + * @param thisArg An object to which the this keyword can refer in the callbackfn function. * If thisArg is omitted, undefined is used as the this value. */ forEach(callbackfn: (value: number, index: number, array: Float64Array) => void, thisArg?: any): void; @@ -3738,7 +3740,7 @@ interface Float64Array { /** * Adds all the elements of an array separated by the specified separator string. - * @param separator A string used to separate one element of an array from the next in the + * @param separator A string used to separate one element of an array from the next in the * resulting String. If omitted, the array elements are separated with a comma. */ join(separator?: string): string; @@ -3746,7 +3748,7 @@ interface Float64Array { /** * Returns the index of the last occurrence of a value in an array. * @param searchElement The value to locate in the array. - * @param fromIndex The array index at which to begin the search. If fromIndex is omitted, the + * @param fromIndex The array index at which to begin the search. If fromIndex is omitted, the * search starts at index 0. */ lastIndexOf(searchElement: number, fromIndex?: number): number; @@ -3757,65 +3759,65 @@ interface Float64Array { readonly length: number; /** - * Calls a defined callback function on each element of an array, and returns an array that + * Calls a defined callback function on each element of an array, and returns an array that * contains the results. - * @param callbackfn A function that accepts up to three arguments. The map method calls the - * callbackfn function one time for each element in the array. - * @param thisArg An object to which the this keyword can refer in the callbackfn function. + * @param callbackfn A function that accepts up to three arguments. The map method calls the + * callbackfn function one time for each element in the array. + * @param thisArg An object to which the this keyword can refer in the callbackfn function. * If thisArg is omitted, undefined is used as the this value. */ map(callbackfn: (value: number, index: number, array: Float64Array) => number, thisArg?: any): Float64Array; /** - * Calls the specified callback function for all the elements in an array. The return value of - * the callback function is the accumulated result, and is provided as an argument in the next + * Calls the specified callback function for all the elements in an array. The return value of + * the callback function is the accumulated result, and is provided as an argument in the next * call to the callback function. - * @param callbackfn A function that accepts up to four arguments. The reduce method calls the + * @param callbackfn A function that accepts up to four arguments. The reduce method calls the * callbackfn function one time for each element in the array. - * @param initialValue If initialValue is specified, it is used as the initial value to start + * @param initialValue If initialValue is specified, it is used as the initial value to start * the accumulation. The first call to the callbackfn function provides this value as an argument * instead of an array value. */ reduce(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Float64Array) => number, initialValue?: number): number; /** - * Calls the specified callback function for all the elements in an array. The return value of - * the callback function is the accumulated result, and is provided as an argument in the next + * Calls the specified callback function for all the elements in an array. The return value of + * the callback function is the accumulated result, and is provided as an argument in the next * call to the callback function. - * @param callbackfn A function that accepts up to four arguments. The reduce method calls the + * @param callbackfn A function that accepts up to four arguments. The reduce method calls the * callbackfn function one time for each element in the array. - * @param initialValue If initialValue is specified, it is used as the initial value to start - * the accumulation. The first call to the callbackfn function provides this value as an argument + * @param initialValue If initialValue is specified, it is used as the initial value to start + * the accumulation. The first call to the callbackfn function provides this value as an argument * instead of an array value. */ reduce(callbackfn: (previousValue: U, currentValue: number, currentIndex: number, array: Float64Array) => U, initialValue: U): U; - /** - * Calls the specified callback function for all the elements in an array, in descending order. - * The return value of the callback function is the accumulated result, and is provided as an + /** + * Calls the specified callback function for all the elements in an array, in descending order. + * The return value of the callback function is the accumulated result, and is provided as an * argument in the next call to the callback function. - * @param callbackfn A function that accepts up to four arguments. The reduceRight method calls - * the callbackfn function one time for each element in the array. - * @param initialValue If initialValue is specified, it is used as the initial value to start - * the accumulation. The first call to the callbackfn function provides this value as an + * @param callbackfn A function that accepts up to four arguments. The reduceRight method calls + * the callbackfn function one time for each element in the array. + * @param initialValue If initialValue is specified, it is used as the initial value to start + * the accumulation. The first call to the callbackfn function provides this value as an * argument instead of an array value. */ reduceRight(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Float64Array) => number, initialValue?: number): number; - /** - * Calls the specified callback function for all the elements in an array, in descending order. - * The return value of the callback function is the accumulated result, and is provided as an + /** + * Calls the specified callback function for all the elements in an array, in descending order. + * The return value of the callback function is the accumulated result, and is provided as an * argument in the next call to the callback function. * @param callbackfn A function that accepts up to four arguments. The reduceRight method calls - * the callbackfn function one time for each element in the array. - * @param initialValue If initialValue is specified, it is used as the initial value to start + * the callbackfn function one time for each element in the array. + * @param initialValue If initialValue is specified, it is used as the initial value to start * the accumulation. The first call to the callbackfn function provides this value as an argument * instead of an array value. */ reduceRight(callbackfn: (previousValue: U, currentValue: number, currentIndex: number, array: Float64Array) => U, initialValue: U): U; /** - * Reverses the elements in an Array. + * Reverses the elements in an Array. */ reverse(): Float64Array; @@ -3833,7 +3835,7 @@ interface Float64Array { */ set(array: ArrayLike, offset?: number): void; - /** + /** * Returns a section of an array. * @param start The beginning of the specified portion of the array. * @param end The end of the specified portion of the array. @@ -3842,31 +3844,31 @@ interface Float64Array { /** * Determines whether the specified callback function returns true for any element of an array. - * @param callbackfn A function that accepts up to three arguments. The some method calls the - * callbackfn function for each element in array1 until the callbackfn returns true, or until + * @param callbackfn A function that accepts up to three arguments. The some method calls the + * callbackfn function for each element in array1 until the callbackfn returns true, or until * the end of the array. - * @param thisArg An object to which the this keyword can refer in the callbackfn function. + * @param thisArg An object to which the this keyword can refer in the callbackfn function. * If thisArg is omitted, undefined is used as the this value. */ some(callbackfn: (value: number, index: number, array: Float64Array) => boolean, thisArg?: any): boolean; /** * Sorts an array. - * @param compareFn The name of the function used to determine the order of the elements. If + * @param compareFn The name of the function used to determine the order of the elements. If * omitted, the elements are sorted in ascending, ASCII character order. */ sort(compareFn?: (a: number, b: number) => number): Float64Array; /** * Gets a new Float64Array view of the ArrayBuffer store for this array, referencing the elements - * at begin, inclusive, up to end, exclusive. + * at begin, inclusive, up to end, exclusive. * @param begin The index of the beginning of the array. * @param end The index of the end of the array. */ subarray(begin: number, end?: number): Float64Array; /** - * Converts a number to a string by using the current locale. + * Converts a number to a string by using the current locale. */ toLocaleString(): string; @@ -3885,7 +3887,7 @@ interface Float64ArrayConstructor { new (buffer: ArrayBuffer, byteOffset?: number, length?: number): Float64Array; /** - * The size in bytes of each element in the array. + * The size in bytes of each element in the array. */ readonly BYTES_PER_ELEMENT: number; @@ -3894,7 +3896,7 @@ interface Float64ArrayConstructor { * @param items A set of elements to include in the new array object. */ of(...items: number[]): Float64Array; - + /** * Creates an array from an array-like or iterable object. * @param arrayLike An array-like or iterable object to convert to an array. @@ -3906,7 +3908,7 @@ interface Float64ArrayConstructor { declare const Float64Array: Float64ArrayConstructor; ///////////////////////////// -/// ECMAScript Internationalization API +/// ECMAScript Internationalization API ///////////////////////////// declare module Intl { @@ -4049,14 +4051,14 @@ interface String { interface Number { /** - * Converts a number to a string by using the current or specified locale. + * Converts a number to a string by using the current or specified locale. * @param locales An array of locale strings that contain one or more language or locale tags. If you include more than one locale string, list them in descending order of priority so that the first entry is the preferred locale. If you omit this parameter, the default locale of the JavaScript runtime is used. * @param options An object that contains one or more properties that specify comparison options. */ toLocaleString(locales?: string[], options?: Intl.NumberFormatOptions): string; /** - * Converts a number to a string by using the current or specified locale. + * Converts a number to a string by using the current or specified locale. * @param locale Locale tag. If you omit this parameter, the default locale of the JavaScript runtime is used. * @param options An object that contains one or more properties that specify comparison options. */ @@ -4065,41 +4067,41 @@ interface Number { interface Date { /** - * Converts a date and time to a string by using the current or specified locale. + * Converts a date and time to a string by using the current or specified locale. * @param locales An array of locale strings that contain one or more language or locale tags. If you include more than one locale string, list them in descending order of priority so that the first entry is the preferred locale. If you omit this parameter, the default locale of the JavaScript runtime is used. * @param options An object that contains one or more properties that specify comparison options. */ toLocaleString(locales?: string[], options?: Intl.DateTimeFormatOptions): string; /** - * Converts a date to a string by using the current or specified locale. + * Converts a date to a string by using the current or specified locale. * @param locales An array of locale strings that contain one or more language or locale tags. If you include more than one locale string, list them in descending order of priority so that the first entry is the preferred locale. If you omit this parameter, the default locale of the JavaScript runtime is used. * @param options An object that contains one or more properties that specify comparison options. */ toLocaleDateString(locales?: string[], options?: Intl.DateTimeFormatOptions): string; /** - * Converts a time to a string by using the current or specified locale. + * Converts a time to a string by using the current or specified locale. * @param locale Locale tag. If you omit this parameter, the default locale of the JavaScript runtime is used. * @param options An object that contains one or more properties that specify comparison options. */ toLocaleTimeString(locale?: string[], options?: Intl.DateTimeFormatOptions): string; - + /** - * Converts a date and time to a string by using the current or specified locale. + * Converts a date and time to a string by using the current or specified locale. * @param locale Locale tag. If you omit this parameter, the default locale of the JavaScript runtime is used. * @param options An object that contains one or more properties that specify comparison options. */ toLocaleString(locale?: string, options?: Intl.DateTimeFormatOptions): string; - + /** - * Converts a date to a string by using the current or specified locale. + * Converts a date to a string by using the current or specified locale. * @param locale Locale tag. If you omit this parameter, the default locale of the JavaScript runtime is used. * @param options An object that contains one or more properties that specify comparison options. */ toLocaleDateString(locale?: string, options?: Intl.DateTimeFormatOptions): string; /** - * Converts a time to a string by using the current or specified locale. + * Converts a time to a string by using the current or specified locale. * @param locale Locale tag. If you omit this parameter, the default locale of the JavaScript runtime is used. * @param options An object that contains one or more properties that specify comparison options. */ From 423503c883ae1d34c9134873d82c431b8b3c9a78 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Thu, 28 Apr 2016 23:25:22 -0700 Subject: [PATCH 32/52] Fix #7611: Add support for String Literal Types in find all refs and occurances --- src/services/services.ts | 168 ++++++++++++++---- .../findAllRefsForStringLiteralTypes.ts | 14 ++ .../getOccurrencesStringLiteralTypes.ts | 13 ++ .../fourslash/renameStingPropertyNames.ts | 20 +++ .../fourslash/renameStringLiteralTypes.ts | 18 ++ 5 files changed, 196 insertions(+), 37 deletions(-) create mode 100644 tests/cases/fourslash/findAllRefsForStringLiteralTypes.ts create mode 100644 tests/cases/fourslash/getOccurrencesStringLiteralTypes.ts create mode 100644 tests/cases/fourslash/renameStingPropertyNames.ts create mode 100644 tests/cases/fourslash/renameStringLiteralTypes.ts diff --git a/src/services/services.ts b/src/services/services.ts index 670a83d50fc..173aea2dfc4 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -4891,8 +4891,8 @@ namespace ts { node.kind === SyntaxKind.ThisKeyword || node.kind === SyntaxKind.ThisType || node.kind === SyntaxKind.SuperKeyword || - isLiteralNameOfPropertyDeclarationOrIndexAccess(node) || - isNameOfExternalModuleImportOrDeclaration(node)) { + node.kind === SyntaxKind.StringLiteral || + isLiteralNameOfPropertyDeclarationOrIndexAccess(node)) { const referencedSymbols = getReferencedSymbolsForNode(node, sourceFilesToSearch, /*findInStrings*/ false, /*findInComments*/ false); return convertReferencedSymbols(referencedSymbols); @@ -5559,8 +5559,8 @@ namespace ts { // TODO (drosen): This should be enabled in a later release - currently breaks rename. // node.kind !== SyntaxKind.ThisKeyword && // node.kind !== SyntaxKind.SuperKeyword && - !isLiteralNameOfPropertyDeclarationOrIndexAccess(node) && - !isNameOfExternalModuleImportOrDeclaration(node)) { + node.kind !== SyntaxKind.StringLiteral && + !isLiteralNameOfPropertyDeclarationOrIndexAccess(node)) { return undefined; } @@ -5595,6 +5595,10 @@ namespace ts { const symbol = typeChecker.getSymbolAtLocation(node); + if (!symbol && node.kind === SyntaxKind.StringLiteral) { + return getReferencesForStringLiteral(node, sourceFiles); + } + // Could not find a symbol e.g. unknown identifier if (!symbol) { // Can't have references to something that we have no symbol for. @@ -6151,6 +6155,52 @@ namespace ts { } } + + function getReferencesForStringLiteral(node: StringLiteral, sourceFiles: SourceFile[]): ReferencedSymbol[] { + const typeChecker = program.getTypeChecker(); + const type = getStringLiteralTypeForNode(node, typeChecker); + + if (!type) { + // nothing to do here. moving on + return undefined; + } + + const references: ReferenceEntry[] = []; + + forEach(sourceFiles, sourceFile => { + const possiblePositions = getPossibleSymbolReferencePositions(sourceFile, type.text , sourceFile.getStart(), sourceFile.getEnd()); + getReferencesForStringLiteralInFile(sourceFile, type, possiblePositions, references); + }); + + return [{ + definition: { + containerKind: "", + containerName: "", + fileName: node.getSourceFile().fileName, + kind: ScriptElementKind.variableElement, + name: type.text, + textSpan: createTextSpanFromBounds(node.getStart(), node.getEnd()) + }, + references: references + }]; + + function getReferencesForStringLiteralInFile(sourceFile: SourceFile, searchType: Type, possiblePositions: number[], references: ReferenceEntry[]): void { + forEach(possiblePositions, position => { + cancellationToken.throwIfCancellationRequested(); + + const node = getTouchingWord(sourceFile, position); + if (!node || node.kind !== SyntaxKind.StringLiteral) { + return; + } + + const type = getStringLiteralTypeForNode(node, typeChecker); + if (type === searchType) { + references.push(getReferenceEntryFromNode(node)); + } + }); + } + } + function populateSearchSymbolSet(symbol: Symbol, location: Node): Symbol[] { // The search set contains at least the current symbol let result = [symbol]; @@ -7671,6 +7721,14 @@ namespace ts { } } + function getStringLiteralTypeForNode(node: StringLiteral | StringLiteralTypeNode, typeChecker: TypeChecker): StringLiteralType { + const searchNode = node.parent.kind === SyntaxKind.StringLiteralType ? node.parent : node; + const type = typeChecker.getTypeAtLocation(searchNode); + if (type && type.flags & TypeFlags.StringLiteral) { + return type; + } + return undefined; + } function getRenameInfo(fileName: string, position: number): RenameInfo { synchronizeHostData(); @@ -7678,46 +7736,60 @@ namespace ts { const sourceFile = getValidSourceFile(fileName); const typeChecker = program.getTypeChecker(); + const defaultLibFileName = host.getDefaultLibFileName(host.getCompilationSettings()); + const canonicalDefaultLibName = getCanonicalFileName(ts.normalizePath(defaultLibFileName)); + const node = getTouchingWord(sourceFile, position); // Can only rename an identifier. - if (node && node.kind === SyntaxKind.Identifier) { - const symbol = typeChecker.getSymbolAtLocation(node); + if (node) { + if (node.kind === SyntaxKind.Identifier || + node.kind === SyntaxKind.StringLiteral || + isLiteralNameOfPropertyDeclarationOrIndexAccess(node)) { + const symbol = typeChecker.getSymbolAtLocation(node); - // Only allow a symbol to be renamed if it actually has at least one declaration. - if (symbol) { - const declarations = symbol.getDeclarations(); - if (declarations && declarations.length > 0) { - // Disallow rename for elements that are defined in the standard TypeScript library. - const defaultLibFileName = host.getDefaultLibFileName(host.getCompilationSettings()); - const canonicalDefaultLibName = getCanonicalFileName(ts.normalizePath(defaultLibFileName)); - if (defaultLibFileName) { - for (const current of declarations) { - const sourceFile = current.getSourceFile(); - // TODO (drosen): When is there no source file? - if (!sourceFile) { - continue; - } + // Only allow a symbol to be renamed if it actually has at least one declaration. + if (symbol) { + const declarations = symbol.getDeclarations(); + if (declarations && declarations.length > 0) { + // Disallow rename for elements that are defined in the standard TypeScript library. + if (forEach(declarations, isDefinedInLibraryFile)) { + return getRenameInfoError(getLocaleSpecificMessage(Diagnostics.You_cannot_rename_elements_that_are_defined_in_the_standard_TypeScript_library)); + } - const canonicalName = getCanonicalFileName(ts.normalizePath(sourceFile.fileName)); - if (canonicalName === canonicalDefaultLibName) { - return getRenameInfoError(getLocaleSpecificMessage(Diagnostics.You_cannot_rename_elements_that_are_defined_in_the_standard_TypeScript_library)); - } + const displayName = stripQuotes(getDeclaredName(typeChecker, symbol, node)); + const kind = getSymbolKind(symbol, node); + if (kind) { + return { + canRename: true, + kind, + displayName, + localizedErrorMessage: undefined, + fullDisplayName: typeChecker.getFullyQualifiedName(symbol), + kindModifiers: getSymbolModifiers(symbol), + triggerSpan: createTriggerSpanForNode(node) + }; } } - - const displayName = stripQuotes(getDeclaredName(typeChecker, symbol, node)); - const kind = getSymbolKind(symbol, node); - if (kind) { - return { - canRename: true, - kind, - displayName, - localizedErrorMessage: undefined, - fullDisplayName: typeChecker.getFullyQualifiedName(symbol), - kindModifiers: getSymbolModifiers(symbol), - triggerSpan: createTextSpan(node.getStart(), node.getWidth()) - }; + } + else if (node.kind === SyntaxKind.StringLiteral) { + const type = getStringLiteralTypeForNode(node, typeChecker); + if (type) { + if (isDefinedInLibraryFile(node)) { + return getRenameInfoError(getLocaleSpecificMessage(Diagnostics.You_cannot_rename_elements_that_are_defined_in_the_standard_TypeScript_library)); + } + else { + const displayName = stripQuotes(type.text); + return { + canRename: true, + kind: ScriptElementKind.variableElement, + displayName, + localizedErrorMessage: undefined, + fullDisplayName: displayName, + kindModifiers: ScriptElementKindModifier.none, + triggerSpan: createTriggerSpanForNode(node) + }; + } } } } @@ -7736,6 +7808,28 @@ namespace ts { triggerSpan: undefined }; } + + function isDefinedInLibraryFile(declaration: Node) { + if (defaultLibFileName) { + const sourceFile = declaration.getSourceFile(); + const canonicalName = getCanonicalFileName(ts.normalizePath(sourceFile.fileName)); + if (canonicalName === canonicalDefaultLibName) { + return true; + } + } + return false; + } + + function createTriggerSpanForNode(node: Node) { + let start = node.getStart(); + let width = node.getWidth(); + if (node.kind === SyntaxKind.StringLiteral) { + // Exclude the quotes + start += 1; + width -= 2; + } + return createTextSpan(start, width); + } } return { diff --git a/tests/cases/fourslash/findAllRefsForStringLiteralTypes.ts b/tests/cases/fourslash/findAllRefsForStringLiteralTypes.ts new file mode 100644 index 00000000000..dcf7240312c --- /dev/null +++ b/tests/cases/fourslash/findAllRefsForStringLiteralTypes.ts @@ -0,0 +1,14 @@ +/// + +////type Options = "[|option 1|]" | "option 2"; +////let myOption: Options = "[|option 1|]"; + +let ranges = test.ranges(); +for (let range of ranges) { + goTo.position(range.start); + + verify.referencesCountIs(ranges.length); + for (let expectedReference of ranges) { + verify.referencesAtPositionContains(expectedReference); + } +} \ No newline at end of file diff --git a/tests/cases/fourslash/getOccurrencesStringLiteralTypes.ts b/tests/cases/fourslash/getOccurrencesStringLiteralTypes.ts new file mode 100644 index 00000000000..56af87497d5 --- /dev/null +++ b/tests/cases/fourslash/getOccurrencesStringLiteralTypes.ts @@ -0,0 +1,13 @@ +/// + +////function foo(a: "[|option 1|]") { } +////foo("[|option 1|]"); + +const ranges = test.ranges(); +for (let r of ranges) { + goTo.position(r.start); + + for (let range of ranges) { + verify.occurrencesAtPositionContains(range, false); + } +} diff --git a/tests/cases/fourslash/renameStingPropertyNames.ts b/tests/cases/fourslash/renameStingPropertyNames.ts new file mode 100644 index 00000000000..a948220efad --- /dev/null +++ b/tests/cases/fourslash/renameStingPropertyNames.ts @@ -0,0 +1,20 @@ +/// + +////var o = { +//// [|prop|]: 0 +////}; +//// +////o = { +//// "[|prop|]": 1 +////}; +//// +////o["[|prop|]"]; +////o['[|prop|]']; +////o.[|prop|]; + + +let ranges = test.ranges(); +for (let range of ranges) { + goTo.position(range.start); + verify.renameLocations(/*findInStrings*/ false, /*findInComments*/ false); +} diff --git a/tests/cases/fourslash/renameStringLiteralTypes.ts b/tests/cases/fourslash/renameStringLiteralTypes.ts new file mode 100644 index 00000000000..f9df83371c1 --- /dev/null +++ b/tests/cases/fourslash/renameStringLiteralTypes.ts @@ -0,0 +1,18 @@ +/// + + +////interface AnimationOptions { +//// deltaX: number; +//// deltaY: number; +//// easing: "ease-in" | "ease-out" | "[|ease-in-out|]"; +////} +//// +////function animate(o: AnimationOptions) { } +//// +////animate({ deltaX: 100, deltaY: 100, easing: "[|ease-in-out|]" }); + +let ranges = test.ranges(); +for (let range of ranges) { + goTo.position(range.start); + verify.renameLocations(/*findInStrings*/ false, /*findInComments*/ false); +} From 4d94ae874966d321619f2566147576a9a87260dc Mon Sep 17 00:00:00 2001 From: zhengbli Date: Fri, 29 Apr 2016 02:13:50 -0700 Subject: [PATCH 33/52] Wipe out the cached script content if failed to read it --- src/server/editorServices.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/server/editorServices.ts b/src/server/editorServices.ts index 32beec05426..02fe374471b 100644 --- a/src/server/editorServices.ts +++ b/src/server/editorServices.ts @@ -1685,7 +1685,12 @@ namespace ts.server { } reloadFromFile(filename: string, cb?: () => any) { - const content = this.host.readFile(filename); + let content = this.host.readFile(filename); + // If the file doesn't exist or cannot be read, we should + // wipe out its cached content on the server to avoid side effects. + if (!content) { + content = ""; + } this.reload(content); if (cb) cb(); From c12cb83fb7b1054c4c87cd7c12dc60931ec2f055 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Fri, 29 Apr 2016 10:31:01 -0700 Subject: [PATCH 34/52] Type 'this' in object literal function properties Previously, methods of object literals would give a type to 'this'. Now function properties of object literals also give a type to 'this'. --- src/compiler/checker.ts | 5 +- .../commentsOnObjectLiteral2.errors.txt | 5 +- .../reference/fatarrowfunctions.symbols | 5 ++ .../reference/fatarrowfunctions.types | 12 +-- .../fatarrowfunctionsInFunctions.symbols | 5 ++ .../fatarrowfunctionsInFunctions.types | 16 ++-- .../looseThisTypeInFunctions.errors.txt | 5 +- .../baselines/reference/selfInLambdas.symbols | 7 ++ tests/baselines/reference/selfInLambdas.types | 16 ++-- .../baselines/reference/thisBinding2.symbols | 3 + tests/baselines/reference/thisBinding2.types | 8 +- .../thisInPropertyBoundDeclarations.symbols | 2 + .../thisInPropertyBoundDeclarations.types | 12 +-- .../reference/thisTypeInObjectLiterals.js | 7 ++ .../thisTypeInObjectLiterals.symbols | 86 +++++++++++-------- .../reference/thisTypeInObjectLiterals.types | 19 +++- .../reference/underscoreTest1.symbols | 6 ++ .../baselines/reference/underscoreTest1.types | 12 +-- .../thisType/looseThisTypeInFunctions.ts | 10 +-- .../thisType/thisTypeInObjectLiterals.ts | 4 + 20 files changed, 158 insertions(+), 87 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 6cedb78686d..a1340db32c2 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -8206,10 +8206,11 @@ namespace ts { if (signature.thisType) { return signature.thisType; } - if (container.parent && container.parent.kind === SyntaxKind.ObjectLiteralExpression) { + const parentObject = container.parent && container.parent.kind === SyntaxKind.PropertyAssignment ? container.parent.parent : container.parent; + if (parentObject && parentObject.kind === SyntaxKind.ObjectLiteralExpression) { // Note: this works because object literal methods are deferred, // which means that the type of the containing object literal is already known. - const type = checkExpressionCached(container.parent); + const type = checkExpressionCached(parentObject); if (type) { return type; } diff --git a/tests/baselines/reference/commentsOnObjectLiteral2.errors.txt b/tests/baselines/reference/commentsOnObjectLiteral2.errors.txt index 2a2394ced48..3748d0387b6 100644 --- a/tests/baselines/reference/commentsOnObjectLiteral2.errors.txt +++ b/tests/baselines/reference/commentsOnObjectLiteral2.errors.txt @@ -1,7 +1,8 @@ tests/cases/compiler/commentsOnObjectLiteral2.ts(1,14): error TS2304: Cannot find name 'makeClass'. +tests/cases/compiler/commentsOnObjectLiteral2.ts(9,17): error TS2339: Property 'name' does not exist on type '{ initialize: (name: any) => void; }'. -==== tests/cases/compiler/commentsOnObjectLiteral2.ts (1 errors) ==== +==== tests/cases/compiler/commentsOnObjectLiteral2.ts (2 errors) ==== var Person = makeClass( ~~~~~~~~~ !!! error TS2304: Cannot find name 'makeClass'. @@ -13,6 +14,8 @@ tests/cases/compiler/commentsOnObjectLiteral2.ts(1,14): error TS2304: Cannot fin */ initialize: function(name) { this.name = name; + ~~~~ +!!! error TS2339: Property 'name' does not exist on type '{ initialize: (name: any) => void; }'. } /* trailing comment 1*/, } ); \ No newline at end of file diff --git a/tests/baselines/reference/fatarrowfunctions.symbols b/tests/baselines/reference/fatarrowfunctions.symbols index 6ed865b0914..178e2d4b109 100644 --- a/tests/baselines/reference/fatarrowfunctions.symbols +++ b/tests/baselines/reference/fatarrowfunctions.symbols @@ -163,6 +163,11 @@ var messenger = { setTimeout(() => { this.message.toString(); }, 3000); >setTimeout : Symbol(setTimeout, Decl(fatarrowfunctions.ts, 34, 1)) +>this.message.toString : Symbol(String.toString, Decl(lib.d.ts, --, --)) +>this.message : Symbol(message, Decl(fatarrowfunctions.ts, 38, 17)) +>this : Symbol(, Decl(fatarrowfunctions.ts, 38, 15)) +>message : Symbol(message, Decl(fatarrowfunctions.ts, 38, 17)) +>toString : Symbol(String.toString, Decl(lib.d.ts, --, --)) } }; diff --git a/tests/baselines/reference/fatarrowfunctions.types b/tests/baselines/reference/fatarrowfunctions.types index e48b63e50ee..845d91dbd08 100644 --- a/tests/baselines/reference/fatarrowfunctions.types +++ b/tests/baselines/reference/fatarrowfunctions.types @@ -234,12 +234,12 @@ var messenger = { >setTimeout(() => { this.message.toString(); }, 3000) : number >setTimeout : (expression: any, msec?: number, language?: any) => number >() => { this.message.toString(); } : () => void ->this.message.toString() : any ->this.message.toString : any ->this.message : any ->this : any ->message : any ->toString : any +>this.message.toString() : string +>this.message.toString : () => string +>this.message : string +>this : { message: string; start: () => void; } +>message : string +>toString : () => string >3000 : number } }; diff --git a/tests/baselines/reference/fatarrowfunctionsInFunctions.symbols b/tests/baselines/reference/fatarrowfunctionsInFunctions.symbols index 0a86affc215..4c8d3aa2440 100644 --- a/tests/baselines/reference/fatarrowfunctionsInFunctions.symbols +++ b/tests/baselines/reference/fatarrowfunctionsInFunctions.symbols @@ -16,12 +16,17 @@ var messenger = { var _self = this; >_self : Symbol(_self, Decl(fatarrowfunctionsInFunctions.ts, 5, 11)) +>this : Symbol(, Decl(fatarrowfunctionsInFunctions.ts, 2, 15)) setTimeout(function() { >setTimeout : Symbol(setTimeout, Decl(fatarrowfunctionsInFunctions.ts, 0, 0)) _self.message.toString(); +>_self.message.toString : Symbol(String.toString, Decl(lib.d.ts, --, --)) +>_self.message : Symbol(message, Decl(fatarrowfunctionsInFunctions.ts, 2, 17)) >_self : Symbol(_self, Decl(fatarrowfunctionsInFunctions.ts, 5, 11)) +>message : Symbol(message, Decl(fatarrowfunctionsInFunctions.ts, 2, 17)) +>toString : Symbol(String.toString, Decl(lib.d.ts, --, --)) }, 3000); } diff --git a/tests/baselines/reference/fatarrowfunctionsInFunctions.types b/tests/baselines/reference/fatarrowfunctionsInFunctions.types index 00abaec9f25..66e4eb17351 100644 --- a/tests/baselines/reference/fatarrowfunctionsInFunctions.types +++ b/tests/baselines/reference/fatarrowfunctionsInFunctions.types @@ -18,8 +18,8 @@ var messenger = { >function() { var _self = this; setTimeout(function() { _self.message.toString(); }, 3000); } : () => void var _self = this; ->_self : any ->this : any +>_self : { message: string; start: () => void; } +>this : { message: string; start: () => void; } setTimeout(function() { >setTimeout(function() { _self.message.toString(); }, 3000) : number @@ -27,12 +27,12 @@ var messenger = { >function() { _self.message.toString(); } : () => void _self.message.toString(); ->_self.message.toString() : any ->_self.message.toString : any ->_self.message : any ->_self : any ->message : any ->toString : any +>_self.message.toString() : string +>_self.message.toString : () => string +>_self.message : string +>_self : { message: string; start: () => void; } +>message : string +>toString : () => string }, 3000); >3000 : number diff --git a/tests/baselines/reference/looseThisTypeInFunctions.errors.txt b/tests/baselines/reference/looseThisTypeInFunctions.errors.txt index b7a36b99ad4..f19c918ce44 100644 --- a/tests/baselines/reference/looseThisTypeInFunctions.errors.txt +++ b/tests/baselines/reference/looseThisTypeInFunctions.errors.txt @@ -1,12 +1,13 @@ tests/cases/conformance/types/thisType/looseThisTypeInFunctions.ts(21,1): error TS2322: Type '(this: C, m: number) => number' is not assignable to type '(this: void, m: number) => number'. The 'this' types of each signature are incompatible. Type 'void' is not assignable to type 'C'. +tests/cases/conformance/types/thisType/looseThisTypeInFunctions.ts(25,27): error TS2339: Property 'length' does not exist on type 'number'. tests/cases/conformance/types/thisType/looseThisTypeInFunctions.ts(33,28): error TS2339: Property 'length' does not exist on type 'number'. tests/cases/conformance/types/thisType/looseThisTypeInFunctions.ts(37,9): error TS2684: The 'this' context of type 'void' is not assignable to method's 'this' of type 'I'. tests/cases/conformance/types/thisType/looseThisTypeInFunctions.ts(46,20): error TS2339: Property 'length' does not exist on type 'number'. -==== tests/cases/conformance/types/thisType/looseThisTypeInFunctions.ts (4 errors) ==== +==== tests/cases/conformance/types/thisType/looseThisTypeInFunctions.ts (5 errors) ==== interface I { n: number; explicitThis(this: this, m: number): number; @@ -36,6 +37,8 @@ tests/cases/conformance/types/thisType/looseThisTypeInFunctions.ts(46,20): error n: 101, explicitThis: function (m: number) { return m + this.n.length; // ok, this.n: any + ~~~~~~ +!!! error TS2339: Property 'length' does not exist on type 'number'. }, implicitThis(m: number): number { return m; } }; diff --git a/tests/baselines/reference/selfInLambdas.symbols b/tests/baselines/reference/selfInLambdas.symbols index edcc03b6bf6..d5c6e89fcaa 100644 --- a/tests/baselines/reference/selfInLambdas.symbols +++ b/tests/baselines/reference/selfInLambdas.symbols @@ -37,8 +37,15 @@ var o = { >onmousemove : Symbol(Window.onmousemove, Decl(selfInLambdas.ts, 6, 18)) this.counter++ +>this.counter : Symbol(counter, Decl(selfInLambdas.ts, 10, 9)) +>this : Symbol(, Decl(selfInLambdas.ts, 10, 7)) +>counter : Symbol(counter, Decl(selfInLambdas.ts, 10, 9)) + var f = () => this.counter; >f : Symbol(f, Decl(selfInLambdas.ts, 18, 15)) +>this.counter : Symbol(counter, Decl(selfInLambdas.ts, 10, 9)) +>this : Symbol(, Decl(selfInLambdas.ts, 10, 7)) +>counter : Symbol(counter, Decl(selfInLambdas.ts, 10, 9)) } diff --git a/tests/baselines/reference/selfInLambdas.types b/tests/baselines/reference/selfInLambdas.types index 3addf07c75a..acfd850e63c 100644 --- a/tests/baselines/reference/selfInLambdas.types +++ b/tests/baselines/reference/selfInLambdas.types @@ -43,16 +43,16 @@ var o = { this.counter++ >this.counter++ : number ->this.counter : any ->this : any ->counter : any +>this.counter : number +>this : { counter: number; start: () => void; } +>counter : number var f = () => this.counter; ->f : () => any ->() => this.counter : () => any ->this.counter : any ->this : any ->counter : any +>f : () => number +>() => this.counter : () => number +>this.counter : number +>this : { counter: number; start: () => void; } +>counter : number } diff --git a/tests/baselines/reference/thisBinding2.symbols b/tests/baselines/reference/thisBinding2.symbols index cdef9b60b3e..c9ef34b13fa 100644 --- a/tests/baselines/reference/thisBinding2.symbols +++ b/tests/baselines/reference/thisBinding2.symbols @@ -50,6 +50,9 @@ var messenger = { return setTimeout(() => { var x = this.message; }, 3000); >setTimeout : Symbol(setTimeout, Decl(thisBinding2.ts, 12, 1)) >x : Symbol(x, Decl(thisBinding2.ts, 17, 37)) +>this.message : Symbol(message, Decl(thisBinding2.ts, 14, 17)) +>this : Symbol(, Decl(thisBinding2.ts, 14, 15)) +>message : Symbol(message, Decl(thisBinding2.ts, 14, 17)) } }; diff --git a/tests/baselines/reference/thisBinding2.types b/tests/baselines/reference/thisBinding2.types index 99668ca4901..6e437d3ed2d 100644 --- a/tests/baselines/reference/thisBinding2.types +++ b/tests/baselines/reference/thisBinding2.types @@ -67,10 +67,10 @@ var messenger = { >setTimeout(() => { var x = this.message; }, 3000) : number >setTimeout : (expression: any, msec?: number, language?: any) => number >() => { var x = this.message; } : () => void ->x : any ->this.message : any ->this : any ->message : any +>x : string +>this.message : string +>this : { message: string; start: () => number; } +>message : string >3000 : number } }; diff --git a/tests/baselines/reference/thisInPropertyBoundDeclarations.symbols b/tests/baselines/reference/thisInPropertyBoundDeclarations.symbols index 12d3b2db31e..621bdecfc44 100644 --- a/tests/baselines/reference/thisInPropertyBoundDeclarations.symbols +++ b/tests/baselines/reference/thisInPropertyBoundDeclarations.symbols @@ -70,6 +70,7 @@ class A { a: function() { return this; }, >a : Symbol(a, Decl(thisInPropertyBoundDeclarations.ts, 33, 13)) +>this : Symbol(, Decl(thisInPropertyBoundDeclarations.ts, 33, 11)) }; @@ -79,6 +80,7 @@ class A { return { a: function() { return this; }, >a : Symbol(a, Decl(thisInPropertyBoundDeclarations.ts, 38, 16)) +>this : Symbol(, Decl(thisInPropertyBoundDeclarations.ts, 38, 14)) }; }; diff --git a/tests/baselines/reference/thisInPropertyBoundDeclarations.types b/tests/baselines/reference/thisInPropertyBoundDeclarations.types index f871e78d219..64dcd5ce7ea 100644 --- a/tests/baselines/reference/thisInPropertyBoundDeclarations.types +++ b/tests/baselines/reference/thisInPropertyBoundDeclarations.types @@ -84,9 +84,9 @@ class A { >{ a: function() { return this; }, } : { a: () => any; } a: function() { return this; }, ->a : () => any ->function() { return this; } : () => any ->this : any +>a : () => { a: any; } +>function() { return this; } : () => { a: any; } +>this : { a: () => any; } }; @@ -98,9 +98,9 @@ class A { >{ a: function() { return this; }, } : { a: () => any; } a: function() { return this; }, ->a : () => any ->function() { return this; } : () => any ->this : any +>a : () => { a: any; } +>function() { return this; } : () => { a: any; } +>this : { a: () => any; } }; }; diff --git a/tests/baselines/reference/thisTypeInObjectLiterals.js b/tests/baselines/reference/thisTypeInObjectLiterals.js index 5af13a41af8..342c9d58c84 100644 --- a/tests/baselines/reference/thisTypeInObjectLiterals.js +++ b/tests/baselines/reference/thisTypeInObjectLiterals.js @@ -3,8 +3,12 @@ let o = { d: "bar", m() { return this.d.length; + }, + f: function() { + return this.d.length; } } + let mutuallyRecursive = { a: 100, start() { @@ -35,6 +39,9 @@ var o = { d: "bar", m: function () { return this.d.length; + }, + f: function () { + return this.d.length; } }; var mutuallyRecursive = { diff --git a/tests/baselines/reference/thisTypeInObjectLiterals.symbols b/tests/baselines/reference/thisTypeInObjectLiterals.symbols index 9ae4a990d5b..6b9849279d2 100644 --- a/tests/baselines/reference/thisTypeInObjectLiterals.symbols +++ b/tests/baselines/reference/thisTypeInObjectLiterals.symbols @@ -13,80 +13,92 @@ let o = { >this.d : Symbol(d, Decl(thisTypeInObjectLiterals.ts, 0, 9)) >this : Symbol(, Decl(thisTypeInObjectLiterals.ts, 0, 7)) >d : Symbol(d, Decl(thisTypeInObjectLiterals.ts, 0, 9)) +>length : Symbol(String.length, Decl(lib.d.ts, --, --)) + + }, + f: function() { +>f : Symbol(f, Decl(thisTypeInObjectLiterals.ts, 4, 6)) + + return this.d.length; +>this.d.length : Symbol(String.length, Decl(lib.d.ts, --, --)) +>this.d : Symbol(d, Decl(thisTypeInObjectLiterals.ts, 0, 9)) +>this : Symbol(, Decl(thisTypeInObjectLiterals.ts, 0, 7)) +>d : Symbol(d, Decl(thisTypeInObjectLiterals.ts, 0, 9)) >length : Symbol(String.length, Decl(lib.d.ts, --, --)) } } + let mutuallyRecursive = { ->mutuallyRecursive : Symbol(mutuallyRecursive, Decl(thisTypeInObjectLiterals.ts, 6, 3)) +>mutuallyRecursive : Symbol(mutuallyRecursive, Decl(thisTypeInObjectLiterals.ts, 10, 3)) a: 100, ->a : Symbol(a, Decl(thisTypeInObjectLiterals.ts, 6, 25)) +>a : Symbol(a, Decl(thisTypeInObjectLiterals.ts, 10, 25)) start() { ->start : Symbol(start, Decl(thisTypeInObjectLiterals.ts, 7, 11)) +>start : Symbol(start, Decl(thisTypeInObjectLiterals.ts, 11, 11)) return this.passthrough(this.a); ->this.passthrough : Symbol(passthrough, Decl(thisTypeInObjectLiterals.ts, 10, 6)) ->this : Symbol(, Decl(thisTypeInObjectLiterals.ts, 6, 23)) ->passthrough : Symbol(passthrough, Decl(thisTypeInObjectLiterals.ts, 10, 6)) ->this.a : Symbol(a, Decl(thisTypeInObjectLiterals.ts, 6, 25)) ->this : Symbol(, Decl(thisTypeInObjectLiterals.ts, 6, 23)) ->a : Symbol(a, Decl(thisTypeInObjectLiterals.ts, 6, 25)) +>this.passthrough : Symbol(passthrough, Decl(thisTypeInObjectLiterals.ts, 14, 6)) +>this : Symbol(, Decl(thisTypeInObjectLiterals.ts, 10, 23)) +>passthrough : Symbol(passthrough, Decl(thisTypeInObjectLiterals.ts, 14, 6)) +>this.a : Symbol(a, Decl(thisTypeInObjectLiterals.ts, 10, 25)) +>this : Symbol(, Decl(thisTypeInObjectLiterals.ts, 10, 23)) +>a : Symbol(a, Decl(thisTypeInObjectLiterals.ts, 10, 25)) }, passthrough(n: number) { ->passthrough : Symbol(passthrough, Decl(thisTypeInObjectLiterals.ts, 10, 6)) ->n : Symbol(n, Decl(thisTypeInObjectLiterals.ts, 11, 16)) +>passthrough : Symbol(passthrough, Decl(thisTypeInObjectLiterals.ts, 14, 6)) +>n : Symbol(n, Decl(thisTypeInObjectLiterals.ts, 15, 16)) return this.sub1(n); ->this.sub1 : Symbol(sub1, Decl(thisTypeInObjectLiterals.ts, 13, 6)) ->this : Symbol(, Decl(thisTypeInObjectLiterals.ts, 6, 23)) ->sub1 : Symbol(sub1, Decl(thisTypeInObjectLiterals.ts, 13, 6)) ->n : Symbol(n, Decl(thisTypeInObjectLiterals.ts, 11, 16)) +>this.sub1 : Symbol(sub1, Decl(thisTypeInObjectLiterals.ts, 17, 6)) +>this : Symbol(, Decl(thisTypeInObjectLiterals.ts, 10, 23)) +>sub1 : Symbol(sub1, Decl(thisTypeInObjectLiterals.ts, 17, 6)) +>n : Symbol(n, Decl(thisTypeInObjectLiterals.ts, 15, 16)) }, sub1(n: number): number { ->sub1 : Symbol(sub1, Decl(thisTypeInObjectLiterals.ts, 13, 6)) ->n : Symbol(n, Decl(thisTypeInObjectLiterals.ts, 14, 9)) +>sub1 : Symbol(sub1, Decl(thisTypeInObjectLiterals.ts, 17, 6)) +>n : Symbol(n, Decl(thisTypeInObjectLiterals.ts, 18, 9)) if (n > 0) { ->n : Symbol(n, Decl(thisTypeInObjectLiterals.ts, 14, 9)) +>n : Symbol(n, Decl(thisTypeInObjectLiterals.ts, 18, 9)) return this.passthrough(n - 1); ->this.passthrough : Symbol(passthrough, Decl(thisTypeInObjectLiterals.ts, 10, 6)) ->this : Symbol(, Decl(thisTypeInObjectLiterals.ts, 6, 23)) ->passthrough : Symbol(passthrough, Decl(thisTypeInObjectLiterals.ts, 10, 6)) ->n : Symbol(n, Decl(thisTypeInObjectLiterals.ts, 14, 9)) +>this.passthrough : Symbol(passthrough, Decl(thisTypeInObjectLiterals.ts, 14, 6)) +>this : Symbol(, Decl(thisTypeInObjectLiterals.ts, 10, 23)) +>passthrough : Symbol(passthrough, Decl(thisTypeInObjectLiterals.ts, 14, 6)) +>n : Symbol(n, Decl(thisTypeInObjectLiterals.ts, 18, 9)) } return n; ->n : Symbol(n, Decl(thisTypeInObjectLiterals.ts, 14, 9)) +>n : Symbol(n, Decl(thisTypeInObjectLiterals.ts, 18, 9)) } } var i: number = mutuallyRecursive.start(); ->i : Symbol(i, Decl(thisTypeInObjectLiterals.ts, 21, 3)) ->mutuallyRecursive.start : Symbol(start, Decl(thisTypeInObjectLiterals.ts, 7, 11)) ->mutuallyRecursive : Symbol(mutuallyRecursive, Decl(thisTypeInObjectLiterals.ts, 6, 3)) ->start : Symbol(start, Decl(thisTypeInObjectLiterals.ts, 7, 11)) +>i : Symbol(i, Decl(thisTypeInObjectLiterals.ts, 25, 3)) +>mutuallyRecursive.start : Symbol(start, Decl(thisTypeInObjectLiterals.ts, 11, 11)) +>mutuallyRecursive : Symbol(mutuallyRecursive, Decl(thisTypeInObjectLiterals.ts, 10, 3)) +>start : Symbol(start, Decl(thisTypeInObjectLiterals.ts, 11, 11)) interface I { ->I : Symbol(I, Decl(thisTypeInObjectLiterals.ts, 21, 42)) +>I : Symbol(I, Decl(thisTypeInObjectLiterals.ts, 25, 42)) a: number; ->a : Symbol(I.a, Decl(thisTypeInObjectLiterals.ts, 22, 13)) +>a : Symbol(I.a, Decl(thisTypeInObjectLiterals.ts, 26, 13)) start(): number; ->start : Symbol(I.start, Decl(thisTypeInObjectLiterals.ts, 23, 14)) +>start : Symbol(I.start, Decl(thisTypeInObjectLiterals.ts, 27, 14)) passthrough(n: number): number; ->passthrough : Symbol(I.passthrough, Decl(thisTypeInObjectLiterals.ts, 24, 20)) ->n : Symbol(n, Decl(thisTypeInObjectLiterals.ts, 25, 16)) +>passthrough : Symbol(I.passthrough, Decl(thisTypeInObjectLiterals.ts, 28, 20)) +>n : Symbol(n, Decl(thisTypeInObjectLiterals.ts, 29, 16)) sub1(n: number): number; ->sub1 : Symbol(I.sub1, Decl(thisTypeInObjectLiterals.ts, 25, 35)) ->n : Symbol(n, Decl(thisTypeInObjectLiterals.ts, 26, 9)) +>sub1 : Symbol(I.sub1, Decl(thisTypeInObjectLiterals.ts, 29, 35)) +>n : Symbol(n, Decl(thisTypeInObjectLiterals.ts, 30, 9)) } var impl: I = mutuallyRecursive; ->impl : Symbol(impl, Decl(thisTypeInObjectLiterals.ts, 28, 3)) ->I : Symbol(I, Decl(thisTypeInObjectLiterals.ts, 21, 42)) ->mutuallyRecursive : Symbol(mutuallyRecursive, Decl(thisTypeInObjectLiterals.ts, 6, 3)) +>impl : Symbol(impl, Decl(thisTypeInObjectLiterals.ts, 32, 3)) +>I : Symbol(I, Decl(thisTypeInObjectLiterals.ts, 25, 42)) +>mutuallyRecursive : Symbol(mutuallyRecursive, Decl(thisTypeInObjectLiterals.ts, 10, 3)) diff --git a/tests/baselines/reference/thisTypeInObjectLiterals.types b/tests/baselines/reference/thisTypeInObjectLiterals.types index 0b164209219..5b169a904b5 100644 --- a/tests/baselines/reference/thisTypeInObjectLiterals.types +++ b/tests/baselines/reference/thisTypeInObjectLiterals.types @@ -1,7 +1,7 @@ === tests/cases/conformance/types/thisType/thisTypeInObjectLiterals.ts === let o = { ->o : { d: string; m(): number; } ->{ d: "bar", m() { return this.d.length; }} : { d: string; m(): number; } +>o : { d: string; m(): number; f: () => number; } +>{ d: "bar", m() { return this.d.length; }, f: function() { return this.d.length; }} : { d: string; m(): number; f: () => number; } d: "bar", >d : string @@ -13,11 +13,24 @@ let o = { return this.d.length; >this.d.length : number >this.d : string ->this : { d: string; m(): number; } +>this : { d: string; m(): number; f: () => number; } +>d : string +>length : number + + }, + f: function() { +>f : () => number +>function() { return this.d.length; } : () => number + + return this.d.length; +>this.d.length : number +>this.d : string +>this : { d: string; m(): number; f: () => number; } >d : string >length : number } } + let mutuallyRecursive = { >mutuallyRecursive : { a: number; start(): number; passthrough(n: number): number; sub1(n: number): number; } >{ a: 100, start() { return this.passthrough(this.a); }, passthrough(n: number) { return this.sub1(n); }, sub1(n: number): number { if (n > 0) { return this.passthrough(n - 1); } return n; }} : { a: number; start(): number; passthrough(n: number): number; sub1(n: number): number; } diff --git a/tests/baselines/reference/underscoreTest1.symbols b/tests/baselines/reference/underscoreTest1.symbols index 3506f23510e..151b170006e 100644 --- a/tests/baselines/reference/underscoreTest1.symbols +++ b/tests/baselines/reference/underscoreTest1.symbols @@ -395,10 +395,16 @@ var buttonView = { onClick: function () { alert('clicked: ' + this.label); }, >onClick : Symbol(onClick, Decl(underscoreTest1_underscoreTests.ts, 97, 24)) >alert : Symbol(alert, Decl(underscoreTest1_underscoreTests.ts, 2, 14)) +>this.label : Symbol(label, Decl(underscoreTest1_underscoreTests.ts, 96, 18)) +>this : Symbol(, Decl(underscoreTest1_underscoreTests.ts, 96, 16)) +>label : Symbol(label, Decl(underscoreTest1_underscoreTests.ts, 96, 18)) onHover: function () { alert('hovering: ' + this.label); } >onHover : Symbol(onHover, Decl(underscoreTest1_underscoreTests.ts, 98, 62)) >alert : Symbol(alert, Decl(underscoreTest1_underscoreTests.ts, 2, 14)) +>this.label : Symbol(label, Decl(underscoreTest1_underscoreTests.ts, 96, 18)) +>this : Symbol(, Decl(underscoreTest1_underscoreTests.ts, 96, 16)) +>label : Symbol(label, Decl(underscoreTest1_underscoreTests.ts, 96, 18)) }; _.bindAll(buttonView); diff --git a/tests/baselines/reference/underscoreTest1.types b/tests/baselines/reference/underscoreTest1.types index 37f3bdb12ab..432954e5083 100644 --- a/tests/baselines/reference/underscoreTest1.types +++ b/tests/baselines/reference/underscoreTest1.types @@ -827,9 +827,9 @@ var buttonView = { >alert : (x: string) => void >'clicked: ' + this.label : string >'clicked: ' : string ->this.label : any ->this : any ->label : any +>this.label : string +>this : { label: string; onClick: () => void; onHover: () => void; } +>label : string onHover: function () { alert('hovering: ' + this.label); } >onHover : () => void @@ -838,9 +838,9 @@ var buttonView = { >alert : (x: string) => void >'hovering: ' + this.label : string >'hovering: ' : string ->this.label : any ->this : any ->label : any +>this.label : string +>this : { label: string; onClick: () => void; onHover: () => void; } +>label : string }; _.bindAll(buttonView); diff --git a/tests/cases/conformance/types/thisType/looseThisTypeInFunctions.ts b/tests/cases/conformance/types/thisType/looseThisTypeInFunctions.ts index b151961e324..b70f064f43a 100644 --- a/tests/cases/conformance/types/thisType/looseThisTypeInFunctions.ts +++ b/tests/cases/conformance/types/thisType/looseThisTypeInFunctions.ts @@ -19,12 +19,12 @@ class C implements I { } let c = new C(); c.explicitVoid = c.explicitThis; // error, 'void' is missing everything -let o = { +let o = { n: 101, - explicitThis: function (m: number) { - return m + this.n.length; // ok, this.n: any + explicitThis: function (m: number) { + return m + this.n.length; // error, 'length' does not exist on 'number' }, - implicitThis(m: number): number { return m; } + implicitThis(m: number): number { return m; } }; let i: I = o; let o2: I = { @@ -44,4 +44,4 @@ o.implicitThis = c.explicitThis; // ok, implicitThis(this:any) is assignable to o.implicitThis = i.explicitThis; i.explicitThis = function(m) { return this.n.length; // error, this.n: number -} \ No newline at end of file +} diff --git a/tests/cases/conformance/types/thisType/thisTypeInObjectLiterals.ts b/tests/cases/conformance/types/thisType/thisTypeInObjectLiterals.ts index cfdb0883fed..599caf70f30 100644 --- a/tests/cases/conformance/types/thisType/thisTypeInObjectLiterals.ts +++ b/tests/cases/conformance/types/thisType/thisTypeInObjectLiterals.ts @@ -2,8 +2,12 @@ let o = { d: "bar", m() { return this.d.length; + }, + f: function() { + return this.d.length; } } + let mutuallyRecursive = { a: 100, start() { From 755ba737dac9e8553267ffa0ccf3c563200155e9 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Fri, 29 Apr 2016 10:37:45 -0700 Subject: [PATCH 35/52] Update looseThisTypeInFunctions baselines --- .../reference/looseThisTypeInFunctions.errors.txt | 11 ++++++----- .../baselines/reference/looseThisTypeInFunctions.js | 13 +++++++------ 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/tests/baselines/reference/looseThisTypeInFunctions.errors.txt b/tests/baselines/reference/looseThisTypeInFunctions.errors.txt index f19c918ce44..7e12a714406 100644 --- a/tests/baselines/reference/looseThisTypeInFunctions.errors.txt +++ b/tests/baselines/reference/looseThisTypeInFunctions.errors.txt @@ -33,14 +33,14 @@ tests/cases/conformance/types/thisType/looseThisTypeInFunctions.ts(46,20): error !!! error TS2322: Type '(this: C, m: number) => number' is not assignable to type '(this: void, m: number) => number'. !!! error TS2322: The 'this' types of each signature are incompatible. !!! error TS2322: Type 'void' is not assignable to type 'C'. - let o = { + let o = { n: 101, - explicitThis: function (m: number) { - return m + this.n.length; // ok, this.n: any + explicitThis: function (m: number) { + return m + this.n.length; // error, 'length' does not exist on 'number' ~~~~~~ !!! error TS2339: Property 'length' does not exist on type 'number'. }, - implicitThis(m: number): number { return m; } + implicitThis(m: number): number { return m; } }; let i: I = o; let o2: I = { @@ -66,4 +66,5 @@ tests/cases/conformance/types/thisType/looseThisTypeInFunctions.ts(46,20): error return this.n.length; // error, this.n: number ~~~~~~ !!! error TS2339: Property 'length' does not exist on type 'number'. - } \ No newline at end of file + } + \ No newline at end of file diff --git a/tests/baselines/reference/looseThisTypeInFunctions.js b/tests/baselines/reference/looseThisTypeInFunctions.js index 3b172877e0e..cb1fbcc8b95 100644 --- a/tests/baselines/reference/looseThisTypeInFunctions.js +++ b/tests/baselines/reference/looseThisTypeInFunctions.js @@ -20,12 +20,12 @@ class C implements I { } let c = new C(); c.explicitVoid = c.explicitThis; // error, 'void' is missing everything -let o = { +let o = { n: 101, - explicitThis: function (m: number) { - return m + this.n.length; // ok, this.n: any + explicitThis: function (m: number) { + return m + this.n.length; // error, 'length' does not exist on 'number' }, - implicitThis(m: number): number { return m; } + implicitThis(m: number): number { return m; } }; let i: I = o; let o2: I = { @@ -45,7 +45,8 @@ o.implicitThis = c.explicitThis; // ok, implicitThis(this:any) is assignable to o.implicitThis = i.explicitThis; i.explicitThis = function(m) { return this.n.length; // error, this.n: number -} +} + //// [looseThisTypeInFunctions.js] var C = (function () { @@ -67,7 +68,7 @@ c.explicitVoid = c.explicitThis; // error, 'void' is missing everything var o = { n: 101, explicitThis: function (m) { - return m + this.n.length; // ok, this.n: any + return m + this.n.length; // error, 'length' does not exist on 'number' }, implicitThis: function (m) { return m; } }; From bd08e882fa122741e6d95dd66c2d0369db94ce68 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Fri, 29 Apr 2016 13:57:28 -0700 Subject: [PATCH 36/52] Correct handling of destructuring parameters in control flow analysis --- src/compiler/checker.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 6cedb78686d..57490019f1f 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -7959,7 +7959,7 @@ namespace ts { } const declaration = localOrExportSymbol.valueDeclaration; const defaultsToDeclaredType = !strictNullChecks || type.flags & TypeFlags.Any || !declaration || - declaration.kind === SyntaxKind.Parameter || isInAmbientContext(declaration) || + getRootDeclaration(declaration).kind === SyntaxKind.Parameter || isInAmbientContext(declaration) || getContainingFunctionOrModule(declaration) !== getContainingFunctionOrModule(node); const flowType = getFlowTypeOfReference(node, type, defaultsToDeclaredType ? type : undefinedType); if (strictNullChecks && !(type.flags & TypeFlags.Any) && !(getNullableKind(type) & TypeFlags.Undefined) && getNullableKind(flowType) & TypeFlags.Undefined) { From 81bab64ade2013b456976cf344f739090b3fafef Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Fri, 29 Apr 2016 13:57:41 -0700 Subject: [PATCH 37/52] Adding regression test --- .../controlFlowDestructuringParameters.js | 15 ++++++++++++++ ...controlFlowDestructuringParameters.symbols | 15 ++++++++++++++ .../controlFlowDestructuringParameters.types | 20 +++++++++++++++++++ .../controlFlowDestructuringParameters.ts | 7 +++++++ 4 files changed, 57 insertions(+) create mode 100644 tests/baselines/reference/controlFlowDestructuringParameters.js create mode 100644 tests/baselines/reference/controlFlowDestructuringParameters.symbols create mode 100644 tests/baselines/reference/controlFlowDestructuringParameters.types create mode 100644 tests/cases/compiler/controlFlowDestructuringParameters.ts diff --git a/tests/baselines/reference/controlFlowDestructuringParameters.js b/tests/baselines/reference/controlFlowDestructuringParameters.js new file mode 100644 index 00000000000..66b8e656193 --- /dev/null +++ b/tests/baselines/reference/controlFlowDestructuringParameters.js @@ -0,0 +1,15 @@ +//// [controlFlowDestructuringParameters.ts] +// Repro for #8376 + + +[{ x: 1 }].map( + ({ x }) => x +); + + +//// [controlFlowDestructuringParameters.js] +// Repro for #8376 +[{ x: 1 }].map(function (_a) { + var x = _a.x; + return x; +}); diff --git a/tests/baselines/reference/controlFlowDestructuringParameters.symbols b/tests/baselines/reference/controlFlowDestructuringParameters.symbols new file mode 100644 index 00000000000..668d346b929 --- /dev/null +++ b/tests/baselines/reference/controlFlowDestructuringParameters.symbols @@ -0,0 +1,15 @@ +=== tests/cases/compiler/controlFlowDestructuringParameters.ts === +// Repro for #8376 + + +[{ x: 1 }].map( +>[{ x: 1 }].map : Symbol(Array.map, Decl(lib.d.ts, --, --)) +>x : Symbol(x, Decl(controlFlowDestructuringParameters.ts, 3, 2)) +>map : Symbol(Array.map, Decl(lib.d.ts, --, --)) + + ({ x }) => x +>x : Symbol(x, Decl(controlFlowDestructuringParameters.ts, 4, 4)) +>x : Symbol(x, Decl(controlFlowDestructuringParameters.ts, 4, 4)) + +); + diff --git a/tests/baselines/reference/controlFlowDestructuringParameters.types b/tests/baselines/reference/controlFlowDestructuringParameters.types new file mode 100644 index 00000000000..396852bf37a --- /dev/null +++ b/tests/baselines/reference/controlFlowDestructuringParameters.types @@ -0,0 +1,20 @@ +=== tests/cases/compiler/controlFlowDestructuringParameters.ts === +// Repro for #8376 + + +[{ x: 1 }].map( +>[{ x: 1 }].map( ({ x }) => x) : number[] +>[{ x: 1 }].map : (callbackfn: (value: { x: number; }, index: number, array: { x: number; }[]) => U, thisArg?: any) => U[] +>[{ x: 1 }] : { x: number; }[] +>{ x: 1 } : { x: number; } +>x : number +>1 : number +>map : (callbackfn: (value: { x: number; }, index: number, array: { x: number; }[]) => U, thisArg?: any) => U[] + + ({ x }) => x +>({ x }) => x : ({x}: { x: number; }) => number +>x : number +>x : number + +); + diff --git a/tests/cases/compiler/controlFlowDestructuringParameters.ts b/tests/cases/compiler/controlFlowDestructuringParameters.ts new file mode 100644 index 00000000000..3efcd8c4814 --- /dev/null +++ b/tests/cases/compiler/controlFlowDestructuringParameters.ts @@ -0,0 +1,7 @@ +// Repro for #8376 + +// @strictNullChecks: true + +[{ x: 1 }].map( + ({ x }) => x +); From 0a2ba0cc1582f37ea3849c2e7912b019459420b6 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Fri, 29 Apr 2016 15:36:29 -0700 Subject: [PATCH 38/52] Make `this` in object literal always of type `any` Previously, `this` was implicitly typed by the shape of its containing object literal. This is not correct for JavaScript-style inheritance uses of object literals, and the previous fix was not correct either. So we're going back to `this: any` in object literals for now. --- src/compiler/checker.ts | 14 +--- .../commentsOnObjectLiteral2.errors.txt | 5 +- .../commentsOnObjectLiteral3.symbols | 7 -- .../reference/commentsOnObjectLiteral3.types | 12 +-- ...declFileObjectLiteralWithAccessors.symbols | 3 - .../declFileObjectLiteralWithAccessors.types | 6 +- ...eclFileObjectLiteralWithOnlySetter.symbols | 3 - .../declFileObjectLiteralWithOnlySetter.types | 6 +- ...declarationEmitThisPredicates02.errors.txt | 7 +- ...ThisPredicatesWithPrivateName02.errors.txt | 7 +- ...iationAssignmentWithIndexingOnLHS3.symbols | 7 -- ...ntiationAssignmentWithIndexingOnLHS3.types | 12 +-- .../reference/fatarrowfunctions.symbols | 5 -- .../reference/fatarrowfunctions.types | 12 +-- .../fatarrowfunctionsInFunctions.symbols | 5 -- .../fatarrowfunctionsInFunctions.types | 16 ++-- .../looseThisTypeInFunctions.errors.txt | 5 +- .../baselines/reference/selfInLambdas.symbols | 7 -- tests/baselines/reference/selfInLambdas.types | 16 ++-- .../baselines/reference/thisBinding2.symbols | 3 - tests/baselines/reference/thisBinding2.types | 8 +- .../reference/thisInObjectLiterals.errors.txt | 5 +- .../thisInPropertyBoundDeclarations.symbols | 2 - .../thisInPropertyBoundDeclarations.types | 12 +-- .../thisTypeInObjectLiterals.symbols | 24 ------ .../reference/thisTypeInObjectLiterals.types | 78 +++++++++---------- .../throwInEnclosingStatements.symbols | 1 - .../throwInEnclosingStatements.types | 2 +- .../reference/underscoreTest1.symbols | 6 -- .../baselines/reference/underscoreTest1.types | 12 +-- 30 files changed, 102 insertions(+), 206 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index e507118a197..494f7dee38b 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -8206,15 +8206,6 @@ namespace ts { if (signature.thisType) { return signature.thisType; } - const parentObject = container.parent && container.parent.kind === SyntaxKind.PropertyAssignment ? container.parent.parent : container.parent; - if (parentObject && parentObject.kind === SyntaxKind.ObjectLiteralExpression) { - // Note: this works because object literal methods are deferred, - // which means that the type of the containing object literal is already known. - const type = checkExpressionCached(parentObject); - if (type) { - return type; - } - } } if (isClassLike(container.parent)) { const symbol = getSymbolOfNode(container.parent); @@ -8454,10 +8445,7 @@ namespace ts { if (isContextSensitiveFunctionOrObjectLiteralMethod(func) && func.kind !== SyntaxKind.ArrowFunction) { const contextualSignature = getContextualSignature(func); if (contextualSignature) { - return contextualSignature.thisType || anyType; - } - else if (getContextualTypeForFunctionLikeDeclaration(func) === anyType) { - return anyType; + return contextualSignature.thisType; } } diff --git a/tests/baselines/reference/commentsOnObjectLiteral2.errors.txt b/tests/baselines/reference/commentsOnObjectLiteral2.errors.txt index 3748d0387b6..2a2394ced48 100644 --- a/tests/baselines/reference/commentsOnObjectLiteral2.errors.txt +++ b/tests/baselines/reference/commentsOnObjectLiteral2.errors.txt @@ -1,8 +1,7 @@ tests/cases/compiler/commentsOnObjectLiteral2.ts(1,14): error TS2304: Cannot find name 'makeClass'. -tests/cases/compiler/commentsOnObjectLiteral2.ts(9,17): error TS2339: Property 'name' does not exist on type '{ initialize: (name: any) => void; }'. -==== tests/cases/compiler/commentsOnObjectLiteral2.ts (2 errors) ==== +==== tests/cases/compiler/commentsOnObjectLiteral2.ts (1 errors) ==== var Person = makeClass( ~~~~~~~~~ !!! error TS2304: Cannot find name 'makeClass'. @@ -14,8 +13,6 @@ tests/cases/compiler/commentsOnObjectLiteral2.ts(9,17): error TS2339: Property ' */ initialize: function(name) { this.name = name; - ~~~~ -!!! error TS2339: Property 'name' does not exist on type '{ initialize: (name: any) => void; }'. } /* trailing comment 1*/, } ); \ No newline at end of file diff --git a/tests/baselines/reference/commentsOnObjectLiteral3.symbols b/tests/baselines/reference/commentsOnObjectLiteral3.symbols index 81fa15b6a11..3d58fe2d6d7 100644 --- a/tests/baselines/reference/commentsOnObjectLiteral3.symbols +++ b/tests/baselines/reference/commentsOnObjectLiteral3.symbols @@ -21,10 +21,6 @@ var v = { >a : Symbol(a, Decl(commentsOnObjectLiteral3.ts, 8, 13), Decl(commentsOnObjectLiteral3.ts, 12, 18)) return this.prop; ->this.prop : Symbol(prop, Decl(commentsOnObjectLiteral3.ts, 1, 9)) ->this : Symbol(, Decl(commentsOnObjectLiteral3.ts, 1, 7)) ->prop : Symbol(prop, Decl(commentsOnObjectLiteral3.ts, 1, 9)) - } /*trailing 1*/, //setter set a(value) { @@ -32,9 +28,6 @@ var v = { >value : Symbol(value, Decl(commentsOnObjectLiteral3.ts, 14, 7)) this.prop = value; ->this.prop : Symbol(prop, Decl(commentsOnObjectLiteral3.ts, 1, 9)) ->this : Symbol(, Decl(commentsOnObjectLiteral3.ts, 1, 7)) ->prop : Symbol(prop, Decl(commentsOnObjectLiteral3.ts, 1, 9)) >value : Symbol(value, Decl(commentsOnObjectLiteral3.ts, 14, 7)) } // trailing 2 diff --git a/tests/baselines/reference/commentsOnObjectLiteral3.types b/tests/baselines/reference/commentsOnObjectLiteral3.types index 26a1e2e4250..a63920fce0f 100644 --- a/tests/baselines/reference/commentsOnObjectLiteral3.types +++ b/tests/baselines/reference/commentsOnObjectLiteral3.types @@ -24,9 +24,9 @@ var v = { >a : any return this.prop; ->this.prop : number ->this : { prop: number; func: () => void; func1(): void; a: any; } ->prop : number +>this.prop : any +>this : any +>prop : any } /*trailing 1*/, //setter @@ -36,9 +36,9 @@ var v = { this.prop = value; >this.prop = value : any ->this.prop : number ->this : { prop: number; func: () => void; func1(): void; a: any; } ->prop : number +>this.prop : any +>this : any +>prop : any >value : any } // trailing 2 diff --git a/tests/baselines/reference/declFileObjectLiteralWithAccessors.symbols b/tests/baselines/reference/declFileObjectLiteralWithAccessors.symbols index 9b3599da674..862b0b3781e 100644 --- a/tests/baselines/reference/declFileObjectLiteralWithAccessors.symbols +++ b/tests/baselines/reference/declFileObjectLiteralWithAccessors.symbols @@ -15,9 +15,6 @@ function /*1*/makePoint(x: number) { set x(a: number) { this.b = a; } >x : Symbol(x, Decl(declFileObjectLiteralWithAccessors.ts, 3, 14), Decl(declFileObjectLiteralWithAccessors.ts, 4, 30)) >a : Symbol(a, Decl(declFileObjectLiteralWithAccessors.ts, 5, 14)) ->this.b : Symbol(b, Decl(declFileObjectLiteralWithAccessors.ts, 2, 12)) ->this : Symbol(, Decl(declFileObjectLiteralWithAccessors.ts, 2, 10)) ->b : Symbol(b, Decl(declFileObjectLiteralWithAccessors.ts, 2, 12)) >a : Symbol(a, Decl(declFileObjectLiteralWithAccessors.ts, 5, 14)) }; diff --git a/tests/baselines/reference/declFileObjectLiteralWithAccessors.types b/tests/baselines/reference/declFileObjectLiteralWithAccessors.types index 1bf012605c1..f7bb57b0e1e 100644 --- a/tests/baselines/reference/declFileObjectLiteralWithAccessors.types +++ b/tests/baselines/reference/declFileObjectLiteralWithAccessors.types @@ -19,9 +19,9 @@ function /*1*/makePoint(x: number) { >x : number >a : number >this.b = a : number ->this.b : number ->this : { b: number; x: number; } ->b : number +>this.b : any +>this : any +>b : any >a : number }; diff --git a/tests/baselines/reference/declFileObjectLiteralWithOnlySetter.symbols b/tests/baselines/reference/declFileObjectLiteralWithOnlySetter.symbols index 89b7b9dd747..f7474466140 100644 --- a/tests/baselines/reference/declFileObjectLiteralWithOnlySetter.symbols +++ b/tests/baselines/reference/declFileObjectLiteralWithOnlySetter.symbols @@ -11,9 +11,6 @@ function /*1*/makePoint(x: number) { set x(a: number) { this.b = a; } >x : Symbol(x, Decl(declFileObjectLiteralWithOnlySetter.ts, 3, 14)) >a : Symbol(a, Decl(declFileObjectLiteralWithOnlySetter.ts, 4, 14)) ->this.b : Symbol(b, Decl(declFileObjectLiteralWithOnlySetter.ts, 2, 12)) ->this : Symbol(, Decl(declFileObjectLiteralWithOnlySetter.ts, 2, 10)) ->b : Symbol(b, Decl(declFileObjectLiteralWithOnlySetter.ts, 2, 12)) >a : Symbol(a, Decl(declFileObjectLiteralWithOnlySetter.ts, 4, 14)) }; diff --git a/tests/baselines/reference/declFileObjectLiteralWithOnlySetter.types b/tests/baselines/reference/declFileObjectLiteralWithOnlySetter.types index 1bce86915ad..2b9b98a8963 100644 --- a/tests/baselines/reference/declFileObjectLiteralWithOnlySetter.types +++ b/tests/baselines/reference/declFileObjectLiteralWithOnlySetter.types @@ -15,9 +15,9 @@ function /*1*/makePoint(x: number) { >x : number >a : number >this.b = a : number ->this.b : number ->this : { b: number; x: number; } ->b : number +>this.b : any +>this : any +>b : any >a : number }; diff --git a/tests/baselines/reference/declarationEmitThisPredicates02.errors.txt b/tests/baselines/reference/declarationEmitThisPredicates02.errors.txt index d3597ad2507..4d95cf01136 100644 --- a/tests/baselines/reference/declarationEmitThisPredicates02.errors.txt +++ b/tests/baselines/reference/declarationEmitThisPredicates02.errors.txt @@ -1,9 +1,7 @@ tests/cases/conformance/declarationEmit/typePredicates/declarationEmitThisPredicates02.ts(9,10): error TS2526: A 'this' type is available only in a non-static member of a class or interface. -tests/cases/conformance/declarationEmit/typePredicates/declarationEmitThisPredicates02.ts(10,19): error TS2352: Type '{ m(): this is Foo; }' cannot be converted to type 'Foo'. - Property 'a' is missing in type '{ m(): this is Foo; }'. -==== tests/cases/conformance/declarationEmit/typePredicates/declarationEmitThisPredicates02.ts (2 errors) ==== +==== tests/cases/conformance/declarationEmit/typePredicates/declarationEmitThisPredicates02.ts (1 errors) ==== export interface Foo { a: string; @@ -16,9 +14,6 @@ tests/cases/conformance/declarationEmit/typePredicates/declarationEmitThisPredic ~~~~ !!! error TS2526: A 'this' type is available only in a non-static member of a class or interface. let dis = this as Foo; - ~~~~~~~~~~~ -!!! error TS2352: Type '{ m(): this is Foo; }' cannot be converted to type 'Foo'. -!!! error TS2352: Property 'a' is missing in type '{ m(): this is Foo; }'. return dis.a != null && dis.b != null && dis.c != null; } } \ No newline at end of file diff --git a/tests/baselines/reference/declarationEmitThisPredicatesWithPrivateName02.errors.txt b/tests/baselines/reference/declarationEmitThisPredicatesWithPrivateName02.errors.txt index 7a4716a92e0..86c0f478133 100644 --- a/tests/baselines/reference/declarationEmitThisPredicatesWithPrivateName02.errors.txt +++ b/tests/baselines/reference/declarationEmitThisPredicatesWithPrivateName02.errors.txt @@ -1,10 +1,8 @@ tests/cases/conformance/declarationEmit/typePredicates/declarationEmitThisPredicatesWithPrivateName02.ts(8,14): error TS4025: Exported variable 'obj' has or is using private name 'Foo'. tests/cases/conformance/declarationEmit/typePredicates/declarationEmitThisPredicatesWithPrivateName02.ts(9,10): error TS2526: A 'this' type is available only in a non-static member of a class or interface. -tests/cases/conformance/declarationEmit/typePredicates/declarationEmitThisPredicatesWithPrivateName02.ts(10,19): error TS2352: Type '{ m(): this is Foo; }' cannot be converted to type 'Foo'. - Property 'a' is missing in type '{ m(): this is Foo; }'. -==== tests/cases/conformance/declarationEmit/typePredicates/declarationEmitThisPredicatesWithPrivateName02.ts (3 errors) ==== +==== tests/cases/conformance/declarationEmit/typePredicates/declarationEmitThisPredicatesWithPrivateName02.ts (2 errors) ==== interface Foo { a: string; @@ -19,9 +17,6 @@ tests/cases/conformance/declarationEmit/typePredicates/declarationEmitThisPredic ~~~~ !!! error TS2526: A 'this' type is available only in a non-static member of a class or interface. let dis = this as Foo; - ~~~~~~~~~~~ -!!! error TS2352: Type '{ m(): this is Foo; }' cannot be converted to type 'Foo'. -!!! error TS2352: Property 'a' is missing in type '{ m(): this is Foo; }'. return dis.a != null && dis.b != null && dis.c != null; } } \ No newline at end of file diff --git a/tests/baselines/reference/emitCompoundExponentiationAssignmentWithIndexingOnLHS3.symbols b/tests/baselines/reference/emitCompoundExponentiationAssignmentWithIndexingOnLHS3.symbols index 4da659c4a1a..dbd5aa150dc 100644 --- a/tests/baselines/reference/emitCompoundExponentiationAssignmentWithIndexingOnLHS3.symbols +++ b/tests/baselines/reference/emitCompoundExponentiationAssignmentWithIndexingOnLHS3.symbols @@ -8,18 +8,11 @@ var object = { get 0() { return this._0; ->this._0 : Symbol(_0, Decl(emitCompoundExponentiationAssignmentWithIndexingOnLHS3.ts, 1, 14)) ->this : Symbol(, Decl(emitCompoundExponentiationAssignmentWithIndexingOnLHS3.ts, 1, 12)) ->_0 : Symbol(_0, Decl(emitCompoundExponentiationAssignmentWithIndexingOnLHS3.ts, 1, 14)) - }, set 0(x: number) { >x : Symbol(x, Decl(emitCompoundExponentiationAssignmentWithIndexingOnLHS3.ts, 6, 10)) this._0 = x; ->this._0 : Symbol(_0, Decl(emitCompoundExponentiationAssignmentWithIndexingOnLHS3.ts, 1, 14)) ->this : Symbol(, Decl(emitCompoundExponentiationAssignmentWithIndexingOnLHS3.ts, 1, 12)) ->_0 : Symbol(_0, Decl(emitCompoundExponentiationAssignmentWithIndexingOnLHS3.ts, 1, 14)) >x : Symbol(x, Decl(emitCompoundExponentiationAssignmentWithIndexingOnLHS3.ts, 6, 10)) }, diff --git a/tests/baselines/reference/emitCompoundExponentiationAssignmentWithIndexingOnLHS3.types b/tests/baselines/reference/emitCompoundExponentiationAssignmentWithIndexingOnLHS3.types index b47c88f3de3..1877f391207 100644 --- a/tests/baselines/reference/emitCompoundExponentiationAssignmentWithIndexingOnLHS3.types +++ b/tests/baselines/reference/emitCompoundExponentiationAssignmentWithIndexingOnLHS3.types @@ -10,9 +10,9 @@ var object = { get 0() { return this._0; ->this._0 : number ->this : { 0: number; _0: number; } ->_0 : number +>this._0 : any +>this : any +>_0 : any }, set 0(x: number) { @@ -20,9 +20,9 @@ var object = { this._0 = x; >this._0 = x : number ->this._0 : number ->this : { 0: number; _0: number; } ->_0 : number +>this._0 : any +>this : any +>_0 : any >x : number }, diff --git a/tests/baselines/reference/fatarrowfunctions.symbols b/tests/baselines/reference/fatarrowfunctions.symbols index 178e2d4b109..6ed865b0914 100644 --- a/tests/baselines/reference/fatarrowfunctions.symbols +++ b/tests/baselines/reference/fatarrowfunctions.symbols @@ -163,11 +163,6 @@ var messenger = { setTimeout(() => { this.message.toString(); }, 3000); >setTimeout : Symbol(setTimeout, Decl(fatarrowfunctions.ts, 34, 1)) ->this.message.toString : Symbol(String.toString, Decl(lib.d.ts, --, --)) ->this.message : Symbol(message, Decl(fatarrowfunctions.ts, 38, 17)) ->this : Symbol(, Decl(fatarrowfunctions.ts, 38, 15)) ->message : Symbol(message, Decl(fatarrowfunctions.ts, 38, 17)) ->toString : Symbol(String.toString, Decl(lib.d.ts, --, --)) } }; diff --git a/tests/baselines/reference/fatarrowfunctions.types b/tests/baselines/reference/fatarrowfunctions.types index 845d91dbd08..e48b63e50ee 100644 --- a/tests/baselines/reference/fatarrowfunctions.types +++ b/tests/baselines/reference/fatarrowfunctions.types @@ -234,12 +234,12 @@ var messenger = { >setTimeout(() => { this.message.toString(); }, 3000) : number >setTimeout : (expression: any, msec?: number, language?: any) => number >() => { this.message.toString(); } : () => void ->this.message.toString() : string ->this.message.toString : () => string ->this.message : string ->this : { message: string; start: () => void; } ->message : string ->toString : () => string +>this.message.toString() : any +>this.message.toString : any +>this.message : any +>this : any +>message : any +>toString : any >3000 : number } }; diff --git a/tests/baselines/reference/fatarrowfunctionsInFunctions.symbols b/tests/baselines/reference/fatarrowfunctionsInFunctions.symbols index 4c8d3aa2440..0a86affc215 100644 --- a/tests/baselines/reference/fatarrowfunctionsInFunctions.symbols +++ b/tests/baselines/reference/fatarrowfunctionsInFunctions.symbols @@ -16,17 +16,12 @@ var messenger = { var _self = this; >_self : Symbol(_self, Decl(fatarrowfunctionsInFunctions.ts, 5, 11)) ->this : Symbol(, Decl(fatarrowfunctionsInFunctions.ts, 2, 15)) setTimeout(function() { >setTimeout : Symbol(setTimeout, Decl(fatarrowfunctionsInFunctions.ts, 0, 0)) _self.message.toString(); ->_self.message.toString : Symbol(String.toString, Decl(lib.d.ts, --, --)) ->_self.message : Symbol(message, Decl(fatarrowfunctionsInFunctions.ts, 2, 17)) >_self : Symbol(_self, Decl(fatarrowfunctionsInFunctions.ts, 5, 11)) ->message : Symbol(message, Decl(fatarrowfunctionsInFunctions.ts, 2, 17)) ->toString : Symbol(String.toString, Decl(lib.d.ts, --, --)) }, 3000); } diff --git a/tests/baselines/reference/fatarrowfunctionsInFunctions.types b/tests/baselines/reference/fatarrowfunctionsInFunctions.types index 66e4eb17351..00abaec9f25 100644 --- a/tests/baselines/reference/fatarrowfunctionsInFunctions.types +++ b/tests/baselines/reference/fatarrowfunctionsInFunctions.types @@ -18,8 +18,8 @@ var messenger = { >function() { var _self = this; setTimeout(function() { _self.message.toString(); }, 3000); } : () => void var _self = this; ->_self : { message: string; start: () => void; } ->this : { message: string; start: () => void; } +>_self : any +>this : any setTimeout(function() { >setTimeout(function() { _self.message.toString(); }, 3000) : number @@ -27,12 +27,12 @@ var messenger = { >function() { _self.message.toString(); } : () => void _self.message.toString(); ->_self.message.toString() : string ->_self.message.toString : () => string ->_self.message : string ->_self : { message: string; start: () => void; } ->message : string ->toString : () => string +>_self.message.toString() : any +>_self.message.toString : any +>_self.message : any +>_self : any +>message : any +>toString : any }, 3000); >3000 : number diff --git a/tests/baselines/reference/looseThisTypeInFunctions.errors.txt b/tests/baselines/reference/looseThisTypeInFunctions.errors.txt index 7e12a714406..bf76c9c9641 100644 --- a/tests/baselines/reference/looseThisTypeInFunctions.errors.txt +++ b/tests/baselines/reference/looseThisTypeInFunctions.errors.txt @@ -1,13 +1,12 @@ tests/cases/conformance/types/thisType/looseThisTypeInFunctions.ts(21,1): error TS2322: Type '(this: C, m: number) => number' is not assignable to type '(this: void, m: number) => number'. The 'this' types of each signature are incompatible. Type 'void' is not assignable to type 'C'. -tests/cases/conformance/types/thisType/looseThisTypeInFunctions.ts(25,27): error TS2339: Property 'length' does not exist on type 'number'. tests/cases/conformance/types/thisType/looseThisTypeInFunctions.ts(33,28): error TS2339: Property 'length' does not exist on type 'number'. tests/cases/conformance/types/thisType/looseThisTypeInFunctions.ts(37,9): error TS2684: The 'this' context of type 'void' is not assignable to method's 'this' of type 'I'. tests/cases/conformance/types/thisType/looseThisTypeInFunctions.ts(46,20): error TS2339: Property 'length' does not exist on type 'number'. -==== tests/cases/conformance/types/thisType/looseThisTypeInFunctions.ts (5 errors) ==== +==== tests/cases/conformance/types/thisType/looseThisTypeInFunctions.ts (4 errors) ==== interface I { n: number; explicitThis(this: this, m: number): number; @@ -37,8 +36,6 @@ tests/cases/conformance/types/thisType/looseThisTypeInFunctions.ts(46,20): error n: 101, explicitThis: function (m: number) { return m + this.n.length; // error, 'length' does not exist on 'number' - ~~~~~~ -!!! error TS2339: Property 'length' does not exist on type 'number'. }, implicitThis(m: number): number { return m; } }; diff --git a/tests/baselines/reference/selfInLambdas.symbols b/tests/baselines/reference/selfInLambdas.symbols index d5c6e89fcaa..edcc03b6bf6 100644 --- a/tests/baselines/reference/selfInLambdas.symbols +++ b/tests/baselines/reference/selfInLambdas.symbols @@ -37,15 +37,8 @@ var o = { >onmousemove : Symbol(Window.onmousemove, Decl(selfInLambdas.ts, 6, 18)) this.counter++ ->this.counter : Symbol(counter, Decl(selfInLambdas.ts, 10, 9)) ->this : Symbol(, Decl(selfInLambdas.ts, 10, 7)) ->counter : Symbol(counter, Decl(selfInLambdas.ts, 10, 9)) - var f = () => this.counter; >f : Symbol(f, Decl(selfInLambdas.ts, 18, 15)) ->this.counter : Symbol(counter, Decl(selfInLambdas.ts, 10, 9)) ->this : Symbol(, Decl(selfInLambdas.ts, 10, 7)) ->counter : Symbol(counter, Decl(selfInLambdas.ts, 10, 9)) } diff --git a/tests/baselines/reference/selfInLambdas.types b/tests/baselines/reference/selfInLambdas.types index acfd850e63c..3addf07c75a 100644 --- a/tests/baselines/reference/selfInLambdas.types +++ b/tests/baselines/reference/selfInLambdas.types @@ -43,16 +43,16 @@ var o = { this.counter++ >this.counter++ : number ->this.counter : number ->this : { counter: number; start: () => void; } ->counter : number +>this.counter : any +>this : any +>counter : any var f = () => this.counter; ->f : () => number ->() => this.counter : () => number ->this.counter : number ->this : { counter: number; start: () => void; } ->counter : number +>f : () => any +>() => this.counter : () => any +>this.counter : any +>this : any +>counter : any } diff --git a/tests/baselines/reference/thisBinding2.symbols b/tests/baselines/reference/thisBinding2.symbols index c9ef34b13fa..cdef9b60b3e 100644 --- a/tests/baselines/reference/thisBinding2.symbols +++ b/tests/baselines/reference/thisBinding2.symbols @@ -50,9 +50,6 @@ var messenger = { return setTimeout(() => { var x = this.message; }, 3000); >setTimeout : Symbol(setTimeout, Decl(thisBinding2.ts, 12, 1)) >x : Symbol(x, Decl(thisBinding2.ts, 17, 37)) ->this.message : Symbol(message, Decl(thisBinding2.ts, 14, 17)) ->this : Symbol(, Decl(thisBinding2.ts, 14, 15)) ->message : Symbol(message, Decl(thisBinding2.ts, 14, 17)) } }; diff --git a/tests/baselines/reference/thisBinding2.types b/tests/baselines/reference/thisBinding2.types index 6e437d3ed2d..99668ca4901 100644 --- a/tests/baselines/reference/thisBinding2.types +++ b/tests/baselines/reference/thisBinding2.types @@ -67,10 +67,10 @@ var messenger = { >setTimeout(() => { var x = this.message; }, 3000) : number >setTimeout : (expression: any, msec?: number, language?: any) => number >() => { var x = this.message; } : () => void ->x : string ->this.message : string ->this : { message: string; start: () => number; } ->message : string +>x : any +>this.message : any +>this : any +>message : any >3000 : number } }; diff --git a/tests/baselines/reference/thisInObjectLiterals.errors.txt b/tests/baselines/reference/thisInObjectLiterals.errors.txt index b0b1c63a34a..e89980dc244 100644 --- a/tests/baselines/reference/thisInObjectLiterals.errors.txt +++ b/tests/baselines/reference/thisInObjectLiterals.errors.txt @@ -1,8 +1,7 @@ tests/cases/conformance/expressions/thisKeyword/thisInObjectLiterals.ts(7,13): error TS2403: Subsequent variable declarations must have the same type. Variable 't' must be of type '{ x: this; y: number; }', but here has type '{ x: MyClass; y: number; }'. -tests/cases/conformance/expressions/thisKeyword/thisInObjectLiterals.ts(14,21): error TS2339: Property 'spaaace' does not exist on type '{ f(): any; }'. -==== tests/cases/conformance/expressions/thisKeyword/thisInObjectLiterals.ts (2 errors) ==== +==== tests/cases/conformance/expressions/thisKeyword/thisInObjectLiterals.ts (1 errors) ==== class MyClass { t: number; @@ -19,8 +18,6 @@ tests/cases/conformance/expressions/thisKeyword/thisInObjectLiterals.ts(14,21): var obj = { f() { return this.spaaace; - ~~~~~~~ -!!! error TS2339: Property 'spaaace' does not exist on type '{ f(): any; }'. } }; var obj: { f: () => any; }; diff --git a/tests/baselines/reference/thisInPropertyBoundDeclarations.symbols b/tests/baselines/reference/thisInPropertyBoundDeclarations.symbols index 621bdecfc44..12d3b2db31e 100644 --- a/tests/baselines/reference/thisInPropertyBoundDeclarations.symbols +++ b/tests/baselines/reference/thisInPropertyBoundDeclarations.symbols @@ -70,7 +70,6 @@ class A { a: function() { return this; }, >a : Symbol(a, Decl(thisInPropertyBoundDeclarations.ts, 33, 13)) ->this : Symbol(, Decl(thisInPropertyBoundDeclarations.ts, 33, 11)) }; @@ -80,7 +79,6 @@ class A { return { a: function() { return this; }, >a : Symbol(a, Decl(thisInPropertyBoundDeclarations.ts, 38, 16)) ->this : Symbol(, Decl(thisInPropertyBoundDeclarations.ts, 38, 14)) }; }; diff --git a/tests/baselines/reference/thisInPropertyBoundDeclarations.types b/tests/baselines/reference/thisInPropertyBoundDeclarations.types index 64dcd5ce7ea..f871e78d219 100644 --- a/tests/baselines/reference/thisInPropertyBoundDeclarations.types +++ b/tests/baselines/reference/thisInPropertyBoundDeclarations.types @@ -84,9 +84,9 @@ class A { >{ a: function() { return this; }, } : { a: () => any; } a: function() { return this; }, ->a : () => { a: any; } ->function() { return this; } : () => { a: any; } ->this : { a: () => any; } +>a : () => any +>function() { return this; } : () => any +>this : any }; @@ -98,9 +98,9 @@ class A { >{ a: function() { return this; }, } : { a: () => any; } a: function() { return this; }, ->a : () => { a: any; } ->function() { return this; } : () => { a: any; } ->this : { a: () => any; } +>a : () => any +>function() { return this; } : () => any +>this : any }; }; diff --git a/tests/baselines/reference/thisTypeInObjectLiterals.symbols b/tests/baselines/reference/thisTypeInObjectLiterals.symbols index 6b9849279d2..af4badf1c0f 100644 --- a/tests/baselines/reference/thisTypeInObjectLiterals.symbols +++ b/tests/baselines/reference/thisTypeInObjectLiterals.symbols @@ -9,22 +9,11 @@ let o = { >m : Symbol(m, Decl(thisTypeInObjectLiterals.ts, 1, 13)) return this.d.length; ->this.d.length : Symbol(String.length, Decl(lib.d.ts, --, --)) ->this.d : Symbol(d, Decl(thisTypeInObjectLiterals.ts, 0, 9)) ->this : Symbol(, Decl(thisTypeInObjectLiterals.ts, 0, 7)) ->d : Symbol(d, Decl(thisTypeInObjectLiterals.ts, 0, 9)) ->length : Symbol(String.length, Decl(lib.d.ts, --, --)) - }, f: function() { >f : Symbol(f, Decl(thisTypeInObjectLiterals.ts, 4, 6)) return this.d.length; ->this.d.length : Symbol(String.length, Decl(lib.d.ts, --, --)) ->this.d : Symbol(d, Decl(thisTypeInObjectLiterals.ts, 0, 9)) ->this : Symbol(, Decl(thisTypeInObjectLiterals.ts, 0, 7)) ->d : Symbol(d, Decl(thisTypeInObjectLiterals.ts, 0, 9)) ->length : Symbol(String.length, Decl(lib.d.ts, --, --)) } } @@ -38,22 +27,12 @@ let mutuallyRecursive = { >start : Symbol(start, Decl(thisTypeInObjectLiterals.ts, 11, 11)) return this.passthrough(this.a); ->this.passthrough : Symbol(passthrough, Decl(thisTypeInObjectLiterals.ts, 14, 6)) ->this : Symbol(, Decl(thisTypeInObjectLiterals.ts, 10, 23)) ->passthrough : Symbol(passthrough, Decl(thisTypeInObjectLiterals.ts, 14, 6)) ->this.a : Symbol(a, Decl(thisTypeInObjectLiterals.ts, 10, 25)) ->this : Symbol(, Decl(thisTypeInObjectLiterals.ts, 10, 23)) ->a : Symbol(a, Decl(thisTypeInObjectLiterals.ts, 10, 25)) - }, passthrough(n: number) { >passthrough : Symbol(passthrough, Decl(thisTypeInObjectLiterals.ts, 14, 6)) >n : Symbol(n, Decl(thisTypeInObjectLiterals.ts, 15, 16)) return this.sub1(n); ->this.sub1 : Symbol(sub1, Decl(thisTypeInObjectLiterals.ts, 17, 6)) ->this : Symbol(, Decl(thisTypeInObjectLiterals.ts, 10, 23)) ->sub1 : Symbol(sub1, Decl(thisTypeInObjectLiterals.ts, 17, 6)) >n : Symbol(n, Decl(thisTypeInObjectLiterals.ts, 15, 16)) }, @@ -65,9 +44,6 @@ let mutuallyRecursive = { >n : Symbol(n, Decl(thisTypeInObjectLiterals.ts, 18, 9)) return this.passthrough(n - 1); ->this.passthrough : Symbol(passthrough, Decl(thisTypeInObjectLiterals.ts, 14, 6)) ->this : Symbol(, Decl(thisTypeInObjectLiterals.ts, 10, 23)) ->passthrough : Symbol(passthrough, Decl(thisTypeInObjectLiterals.ts, 14, 6)) >n : Symbol(n, Decl(thisTypeInObjectLiterals.ts, 18, 9)) } return n; diff --git a/tests/baselines/reference/thisTypeInObjectLiterals.types b/tests/baselines/reference/thisTypeInObjectLiterals.types index 5b169a904b5..91d95d5f0a8 100644 --- a/tests/baselines/reference/thisTypeInObjectLiterals.types +++ b/tests/baselines/reference/thisTypeInObjectLiterals.types @@ -1,66 +1,66 @@ === tests/cases/conformance/types/thisType/thisTypeInObjectLiterals.ts === let o = { ->o : { d: string; m(): number; f: () => number; } ->{ d: "bar", m() { return this.d.length; }, f: function() { return this.d.length; }} : { d: string; m(): number; f: () => number; } +>o : { d: string; m(): any; f: () => any; } +>{ d: "bar", m() { return this.d.length; }, f: function() { return this.d.length; }} : { d: string; m(): any; f: () => any; } d: "bar", >d : string >"bar" : string m() { ->m : () => number +>m : () => any return this.d.length; ->this.d.length : number ->this.d : string ->this : { d: string; m(): number; f: () => number; } ->d : string ->length : number +>this.d.length : any +>this.d : any +>this : any +>d : any +>length : any }, f: function() { ->f : () => number ->function() { return this.d.length; } : () => number +>f : () => any +>function() { return this.d.length; } : () => any return this.d.length; ->this.d.length : number ->this.d : string ->this : { d: string; m(): number; f: () => number; } ->d : string ->length : number +>this.d.length : any +>this.d : any +>this : any +>d : any +>length : any } } let mutuallyRecursive = { ->mutuallyRecursive : { a: number; start(): number; passthrough(n: number): number; sub1(n: number): number; } ->{ a: 100, start() { return this.passthrough(this.a); }, passthrough(n: number) { return this.sub1(n); }, sub1(n: number): number { if (n > 0) { return this.passthrough(n - 1); } return n; }} : { a: number; start(): number; passthrough(n: number): number; sub1(n: number): number; } +>mutuallyRecursive : { a: number; start(): any; passthrough(n: number): any; sub1(n: number): number; } +>{ a: 100, start() { return this.passthrough(this.a); }, passthrough(n: number) { return this.sub1(n); }, sub1(n: number): number { if (n > 0) { return this.passthrough(n - 1); } return n; }} : { a: number; start(): any; passthrough(n: number): any; sub1(n: number): number; } a: 100, >a : number >100 : number start() { ->start : () => number +>start : () => any return this.passthrough(this.a); ->this.passthrough(this.a) : number ->this.passthrough : (n: number) => number ->this : { a: number; start(): number; passthrough(n: number): number; sub1(n: number): number; } ->passthrough : (n: number) => number ->this.a : number ->this : { a: number; start(): number; passthrough(n: number): number; sub1(n: number): number; } ->a : number +>this.passthrough(this.a) : any +>this.passthrough : any +>this : any +>passthrough : any +>this.a : any +>this : any +>a : any }, passthrough(n: number) { ->passthrough : (n: number) => number +>passthrough : (n: number) => any >n : number return this.sub1(n); ->this.sub1(n) : number ->this.sub1 : (n: number) => number ->this : { a: number; start(): number; passthrough(n: number): number; sub1(n: number): number; } ->sub1 : (n: number) => number +>this.sub1(n) : any +>this.sub1 : any +>this : any +>sub1 : any >n : number }, @@ -74,10 +74,10 @@ let mutuallyRecursive = { >0 : number return this.passthrough(n - 1); ->this.passthrough(n - 1) : number ->this.passthrough : (n: number) => number ->this : { a: number; start(): number; passthrough(n: number): number; sub1(n: number): number; } ->passthrough : (n: number) => number +>this.passthrough(n - 1) : any +>this.passthrough : any +>this : any +>passthrough : any >n - 1 : number >n : number >1 : number @@ -88,10 +88,10 @@ let mutuallyRecursive = { } var i: number = mutuallyRecursive.start(); >i : number ->mutuallyRecursive.start() : number ->mutuallyRecursive.start : () => number ->mutuallyRecursive : { a: number; start(): number; passthrough(n: number): number; sub1(n: number): number; } ->start : () => number +>mutuallyRecursive.start() : any +>mutuallyRecursive.start : () => any +>mutuallyRecursive : { a: number; start(): any; passthrough(n: number): any; sub1(n: number): number; } +>start : () => any interface I { >I : I @@ -113,5 +113,5 @@ interface I { var impl: I = mutuallyRecursive; >impl : I >I : I ->mutuallyRecursive : { a: number; start(): number; passthrough(n: number): number; sub1(n: number): number; } +>mutuallyRecursive : { a: number; start(): any; passthrough(n: number): any; sub1(n: number): number; } diff --git a/tests/baselines/reference/throwInEnclosingStatements.symbols b/tests/baselines/reference/throwInEnclosingStatements.symbols index 858b6484e53..63ed9dde578 100644 --- a/tests/baselines/reference/throwInEnclosingStatements.symbols +++ b/tests/baselines/reference/throwInEnclosingStatements.symbols @@ -89,7 +89,6 @@ var aa = { >biz : Symbol(biz, Decl(throwInEnclosingStatements.ts, 41, 10)) throw this; ->this : Symbol(, Decl(throwInEnclosingStatements.ts, 40, 8)) } } diff --git a/tests/baselines/reference/throwInEnclosingStatements.types b/tests/baselines/reference/throwInEnclosingStatements.types index 8add6e8b1a8..32f0fb093bc 100644 --- a/tests/baselines/reference/throwInEnclosingStatements.types +++ b/tests/baselines/reference/throwInEnclosingStatements.types @@ -104,7 +104,7 @@ var aa = { >biz : () => void throw this; ->this : { id: number; biz(): void; } +>this : any } } diff --git a/tests/baselines/reference/underscoreTest1.symbols b/tests/baselines/reference/underscoreTest1.symbols index 151b170006e..3506f23510e 100644 --- a/tests/baselines/reference/underscoreTest1.symbols +++ b/tests/baselines/reference/underscoreTest1.symbols @@ -395,16 +395,10 @@ var buttonView = { onClick: function () { alert('clicked: ' + this.label); }, >onClick : Symbol(onClick, Decl(underscoreTest1_underscoreTests.ts, 97, 24)) >alert : Symbol(alert, Decl(underscoreTest1_underscoreTests.ts, 2, 14)) ->this.label : Symbol(label, Decl(underscoreTest1_underscoreTests.ts, 96, 18)) ->this : Symbol(, Decl(underscoreTest1_underscoreTests.ts, 96, 16)) ->label : Symbol(label, Decl(underscoreTest1_underscoreTests.ts, 96, 18)) onHover: function () { alert('hovering: ' + this.label); } >onHover : Symbol(onHover, Decl(underscoreTest1_underscoreTests.ts, 98, 62)) >alert : Symbol(alert, Decl(underscoreTest1_underscoreTests.ts, 2, 14)) ->this.label : Symbol(label, Decl(underscoreTest1_underscoreTests.ts, 96, 18)) ->this : Symbol(, Decl(underscoreTest1_underscoreTests.ts, 96, 16)) ->label : Symbol(label, Decl(underscoreTest1_underscoreTests.ts, 96, 18)) }; _.bindAll(buttonView); diff --git a/tests/baselines/reference/underscoreTest1.types b/tests/baselines/reference/underscoreTest1.types index 432954e5083..37f3bdb12ab 100644 --- a/tests/baselines/reference/underscoreTest1.types +++ b/tests/baselines/reference/underscoreTest1.types @@ -827,9 +827,9 @@ var buttonView = { >alert : (x: string) => void >'clicked: ' + this.label : string >'clicked: ' : string ->this.label : string ->this : { label: string; onClick: () => void; onHover: () => void; } ->label : string +>this.label : any +>this : any +>label : any onHover: function () { alert('hovering: ' + this.label); } >onHover : () => void @@ -838,9 +838,9 @@ var buttonView = { >alert : (x: string) => void >'hovering: ' + this.label : string >'hovering: ' : string ->this.label : string ->this : { label: string; onClick: () => void; onHover: () => void; } ->label : string +>this.label : any +>this : any +>label : any }; _.bindAll(buttonView); From bd4923a295dcc93822cb338093d353e516f73409 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Fri, 29 Apr 2016 16:20:21 -0700 Subject: [PATCH 39/52] Reset dotted name narrowed types when type guards affect base name --- src/compiler/checker.ts | 60 ++++++++++++++++++++++++++++------------- 1 file changed, 41 insertions(+), 19 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index a1340db32c2..5b7f4988b3b 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -7335,27 +7335,29 @@ namespace ts { } function containsMatchingReference(source: Node, target: Node) { - while (true) { + while (source.kind === SyntaxKind.PropertyAccessExpression) { + source = (source).expression; if (isMatchingReference(source, target)) { return true; } - if (source.kind !== SyntaxKind.PropertyAccessExpression) { - return false; - } - source = (source).expression; } + return false; } - function hasMatchingArgument(callExpression: CallExpression, target: Node) { + function isOrContainsMatchingReference(source: Node, target: Node) { + return isMatchingReference(source, target) || containsMatchingReference(source, target); + } + + function hasMatchingArgument(callExpression: CallExpression, reference: Node) { if (callExpression.arguments) { for (const argument of callExpression.arguments) { - if (isMatchingReference(argument, target)) { + if (isOrContainsMatchingReference(reference, argument)) { return true; } } } if (callExpression.expression.kind === SyntaxKind.PropertyAccessExpression && - isMatchingReference((callExpression.expression).expression, target)) { + isOrContainsMatchingReference(reference, (callExpression.expression).expression)) { return true; } return false; @@ -7618,8 +7620,7 @@ namespace ts { // may be an assignment to a left hand part of the reference. For example, for a // reference 'x.y.z', we may be at an assignment to 'x.y' or 'x'. In that case, // return the declared type. - if (reference.kind === SyntaxKind.PropertyAccessExpression && - containsMatchingReference((reference).expression, node)) { + if (containsMatchingReference(reference, node)) { return declaredType; } // Assignment doesn't affect reference @@ -7682,7 +7683,7 @@ namespace ts { } function narrowTypeByTruthiness(type: Type, expr: Expression, assumeTrue: boolean): Type { - return isMatchingReference(expr, reference) ? getTypeWithFacts(type, assumeTrue ? TypeFacts.Truthy : TypeFacts.Falsy) : type; + return isMatchingReference(reference, expr) ? getTypeWithFacts(type, assumeTrue ? TypeFacts.Truthy : TypeFacts.Falsy) : type; } function narrowTypeByBinaryExpression(type: Type, expr: BinaryExpression, assumeTrue: boolean): Type { @@ -7714,7 +7715,7 @@ namespace ts { if (operator === SyntaxKind.ExclamationEqualsToken || operator === SyntaxKind.ExclamationEqualsEqualsToken) { assumeTrue = !assumeTrue; } - if (!strictNullChecks || !isMatchingReference(expr.left, reference)) { + if (!strictNullChecks || !isMatchingReference(reference, expr.left)) { return type; } const doubleEquals = operator === SyntaxKind.EqualsEqualsToken || operator === SyntaxKind.ExclamationEqualsToken; @@ -7731,7 +7732,12 @@ namespace ts { // and string literal on the right const left = expr.left; const right = expr.right; - if (!isMatchingReference(left.expression, reference)) { + if (!isMatchingReference(reference, left.expression)) { + // For a reference of the form 'x.y', a 'typeof x === ...' type guard resets the + // narrowed type of 'y' to its declared type. + if (containsMatchingReference(reference, left.expression)) { + return declaredType; + } return type; } if (expr.operatorToken.kind === SyntaxKind.ExclamationEqualsToken || @@ -7754,8 +7760,16 @@ namespace ts { } function narrowTypeByInstanceof(type: Type, expr: BinaryExpression, assumeTrue: boolean): Type { - // Check that type is not any, assumed result is true, and we have variable symbol on the left - if (isTypeAny(type) || !isMatchingReference(expr.left, reference)) { + if (!isMatchingReference(reference, expr.left)) { + // For a reference of the form 'x.y', an 'x instanceof T' type guard resets the + // narrowed type of 'y' to its declared type. + if (containsMatchingReference(reference, expr.left)) { + return declaredType; + } + return type; + } + // We never narrow type any in an instanceof guard + if (isTypeAny(type)) { return type; } @@ -7830,18 +7844,26 @@ namespace ts { } if (isIdentifierTypePredicate(predicate)) { const predicateArgument = callExpression.arguments[predicate.parameterIndex]; - if (predicateArgument && isMatchingReference(predicateArgument, reference)) { - return getNarrowedType(type, predicate.type, assumeTrue); + if (predicateArgument) { + if (isMatchingReference(reference, predicateArgument)) { + return getNarrowedType(type, predicate.type, assumeTrue); + } + if (containsMatchingReference(reference, predicateArgument)) { + return declaredType; + } } } else { const invokedExpression = skipParenthesizedNodes(callExpression.expression); if (invokedExpression.kind === SyntaxKind.ElementAccessExpression || invokedExpression.kind === SyntaxKind.PropertyAccessExpression) { const accessExpression = invokedExpression as ElementAccessExpression | PropertyAccessExpression; - const possibleReference= skipParenthesizedNodes(accessExpression.expression); - if (isMatchingReference(possibleReference, reference)) { + const possibleReference = skipParenthesizedNodes(accessExpression.expression); + if (isMatchingReference(reference, possibleReference)) { return getNarrowedType(type, predicate.type, assumeTrue); } + if (containsMatchingReference(reference, possibleReference)) { + return declaredType; + } } } return type; From 644e9876332f04ea4427ba7b24f199deef5fd8a4 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Fri, 29 Apr 2016 16:20:32 -0700 Subject: [PATCH 40/52] Adding regression test --- .../reference/narrowingOfDottedNames.js | 80 ++++++++++++ .../reference/narrowingOfDottedNames.symbols | 105 ++++++++++++++++ .../reference/narrowingOfDottedNames.types | 115 ++++++++++++++++++ .../cases/compiler/narrowingOfDottedNames.ts | 39 ++++++ 4 files changed, 339 insertions(+) create mode 100644 tests/baselines/reference/narrowingOfDottedNames.js create mode 100644 tests/baselines/reference/narrowingOfDottedNames.symbols create mode 100644 tests/baselines/reference/narrowingOfDottedNames.types create mode 100644 tests/cases/compiler/narrowingOfDottedNames.ts diff --git a/tests/baselines/reference/narrowingOfDottedNames.js b/tests/baselines/reference/narrowingOfDottedNames.js new file mode 100644 index 00000000000..5a159f38220 --- /dev/null +++ b/tests/baselines/reference/narrowingOfDottedNames.js @@ -0,0 +1,80 @@ +//// [narrowingOfDottedNames.ts] +// Repro from #8383 + +class A { + prop: { a: string; }; +} + +class B { + prop: { b: string; } +} + +function isA(x: any): x is A { + return x instanceof A; +} + +function isB(x: any): x is B { + return x instanceof B; +} + +function f1(x: A | B) { + while (true) { + if (x instanceof A) { + x.prop.a; + } + else if (x instanceof B) { + x.prop.b; // error: property 'b' doesn't exist on type { a: string } + } + } +} + +function f2(x: A | B) { + while (true) { + if (isA(x)) { + x.prop.a; + } + else if (isB(x)) { + x.prop.b; // error: property 'b' doesn't exist on type { a: string } + } + } +} + + +//// [narrowingOfDottedNames.js] +// Repro from #8383 +var A = (function () { + function A() { + } + return A; +}()); +var B = (function () { + function B() { + } + return B; +}()); +function isA(x) { + return x instanceof A; +} +function isB(x) { + return x instanceof B; +} +function f1(x) { + while (true) { + if (x instanceof A) { + x.prop.a; + } + else if (x instanceof B) { + x.prop.b; // error: property 'b' doesn't exist on type { a: string } + } + } +} +function f2(x) { + while (true) { + if (isA(x)) { + x.prop.a; + } + else if (isB(x)) { + x.prop.b; // error: property 'b' doesn't exist on type { a: string } + } + } +} diff --git a/tests/baselines/reference/narrowingOfDottedNames.symbols b/tests/baselines/reference/narrowingOfDottedNames.symbols new file mode 100644 index 00000000000..474b8c0b655 --- /dev/null +++ b/tests/baselines/reference/narrowingOfDottedNames.symbols @@ -0,0 +1,105 @@ +=== tests/cases/compiler/narrowingOfDottedNames.ts === +// Repro from #8383 + +class A { +>A : Symbol(A, Decl(narrowingOfDottedNames.ts, 0, 0)) + + prop: { a: string; }; +>prop : Symbol(A.prop, Decl(narrowingOfDottedNames.ts, 2, 9)) +>a : Symbol(a, Decl(narrowingOfDottedNames.ts, 3, 11)) +} + +class B { +>B : Symbol(B, Decl(narrowingOfDottedNames.ts, 4, 1)) + + prop: { b: string; } +>prop : Symbol(B.prop, Decl(narrowingOfDottedNames.ts, 6, 9)) +>b : Symbol(b, Decl(narrowingOfDottedNames.ts, 7, 11)) +} + +function isA(x: any): x is A { +>isA : Symbol(isA, Decl(narrowingOfDottedNames.ts, 8, 1)) +>x : Symbol(x, Decl(narrowingOfDottedNames.ts, 10, 13)) +>x : Symbol(x, Decl(narrowingOfDottedNames.ts, 10, 13)) +>A : Symbol(A, Decl(narrowingOfDottedNames.ts, 0, 0)) + + return x instanceof A; +>x : Symbol(x, Decl(narrowingOfDottedNames.ts, 10, 13)) +>A : Symbol(A, Decl(narrowingOfDottedNames.ts, 0, 0)) +} + +function isB(x: any): x is B { +>isB : Symbol(isB, Decl(narrowingOfDottedNames.ts, 12, 1)) +>x : Symbol(x, Decl(narrowingOfDottedNames.ts, 14, 13)) +>x : Symbol(x, Decl(narrowingOfDottedNames.ts, 14, 13)) +>B : Symbol(B, Decl(narrowingOfDottedNames.ts, 4, 1)) + + return x instanceof B; +>x : Symbol(x, Decl(narrowingOfDottedNames.ts, 14, 13)) +>B : Symbol(B, Decl(narrowingOfDottedNames.ts, 4, 1)) +} + +function f1(x: A | B) { +>f1 : Symbol(f1, Decl(narrowingOfDottedNames.ts, 16, 1)) +>x : Symbol(x, Decl(narrowingOfDottedNames.ts, 18, 12)) +>A : Symbol(A, Decl(narrowingOfDottedNames.ts, 0, 0)) +>B : Symbol(B, Decl(narrowingOfDottedNames.ts, 4, 1)) + + while (true) { + if (x instanceof A) { +>x : Symbol(x, Decl(narrowingOfDottedNames.ts, 18, 12)) +>A : Symbol(A, Decl(narrowingOfDottedNames.ts, 0, 0)) + + x.prop.a; +>x.prop.a : Symbol(a, Decl(narrowingOfDottedNames.ts, 3, 11)) +>x.prop : Symbol(A.prop, Decl(narrowingOfDottedNames.ts, 2, 9)) +>x : Symbol(x, Decl(narrowingOfDottedNames.ts, 18, 12)) +>prop : Symbol(A.prop, Decl(narrowingOfDottedNames.ts, 2, 9)) +>a : Symbol(a, Decl(narrowingOfDottedNames.ts, 3, 11)) + } + else if (x instanceof B) { +>x : Symbol(x, Decl(narrowingOfDottedNames.ts, 18, 12)) +>B : Symbol(B, Decl(narrowingOfDottedNames.ts, 4, 1)) + + x.prop.b; // error: property 'b' doesn't exist on type { a: string } +>x.prop.b : Symbol(b, Decl(narrowingOfDottedNames.ts, 7, 11)) +>x.prop : Symbol(B.prop, Decl(narrowingOfDottedNames.ts, 6, 9)) +>x : Symbol(x, Decl(narrowingOfDottedNames.ts, 18, 12)) +>prop : Symbol(B.prop, Decl(narrowingOfDottedNames.ts, 6, 9)) +>b : Symbol(b, Decl(narrowingOfDottedNames.ts, 7, 11)) + } + } +} + +function f2(x: A | B) { +>f2 : Symbol(f2, Decl(narrowingOfDottedNames.ts, 27, 1)) +>x : Symbol(x, Decl(narrowingOfDottedNames.ts, 29, 12)) +>A : Symbol(A, Decl(narrowingOfDottedNames.ts, 0, 0)) +>B : Symbol(B, Decl(narrowingOfDottedNames.ts, 4, 1)) + + while (true) { + if (isA(x)) { +>isA : Symbol(isA, Decl(narrowingOfDottedNames.ts, 8, 1)) +>x : Symbol(x, Decl(narrowingOfDottedNames.ts, 29, 12)) + + x.prop.a; +>x.prop.a : Symbol(a, Decl(narrowingOfDottedNames.ts, 3, 11)) +>x.prop : Symbol(A.prop, Decl(narrowingOfDottedNames.ts, 2, 9)) +>x : Symbol(x, Decl(narrowingOfDottedNames.ts, 29, 12)) +>prop : Symbol(A.prop, Decl(narrowingOfDottedNames.ts, 2, 9)) +>a : Symbol(a, Decl(narrowingOfDottedNames.ts, 3, 11)) + } + else if (isB(x)) { +>isB : Symbol(isB, Decl(narrowingOfDottedNames.ts, 12, 1)) +>x : Symbol(x, Decl(narrowingOfDottedNames.ts, 29, 12)) + + x.prop.b; // error: property 'b' doesn't exist on type { a: string } +>x.prop.b : Symbol(b, Decl(narrowingOfDottedNames.ts, 7, 11)) +>x.prop : Symbol(B.prop, Decl(narrowingOfDottedNames.ts, 6, 9)) +>x : Symbol(x, Decl(narrowingOfDottedNames.ts, 29, 12)) +>prop : Symbol(B.prop, Decl(narrowingOfDottedNames.ts, 6, 9)) +>b : Symbol(b, Decl(narrowingOfDottedNames.ts, 7, 11)) + } + } +} + diff --git a/tests/baselines/reference/narrowingOfDottedNames.types b/tests/baselines/reference/narrowingOfDottedNames.types new file mode 100644 index 00000000000..f9d640dccab --- /dev/null +++ b/tests/baselines/reference/narrowingOfDottedNames.types @@ -0,0 +1,115 @@ +=== tests/cases/compiler/narrowingOfDottedNames.ts === +// Repro from #8383 + +class A { +>A : A + + prop: { a: string; }; +>prop : { a: string; } +>a : string +} + +class B { +>B : B + + prop: { b: string; } +>prop : { b: string; } +>b : string +} + +function isA(x: any): x is A { +>isA : (x: any) => x is A +>x : any +>x : any +>A : A + + return x instanceof A; +>x instanceof A : boolean +>x : any +>A : typeof A +} + +function isB(x: any): x is B { +>isB : (x: any) => x is B +>x : any +>x : any +>B : B + + return x instanceof B; +>x instanceof B : boolean +>x : any +>B : typeof B +} + +function f1(x: A | B) { +>f1 : (x: A | B) => void +>x : A | B +>A : A +>B : B + + while (true) { +>true : boolean + + if (x instanceof A) { +>x instanceof A : boolean +>x : A | B +>A : typeof A + + x.prop.a; +>x.prop.a : string +>x.prop : { a: string; } +>x : A +>prop : { a: string; } +>a : string + } + else if (x instanceof B) { +>x instanceof B : boolean +>x : B +>B : typeof B + + x.prop.b; // error: property 'b' doesn't exist on type { a: string } +>x.prop.b : string +>x.prop : { b: string; } +>x : B +>prop : { b: string; } +>b : string + } + } +} + +function f2(x: A | B) { +>f2 : (x: A | B) => void +>x : A | B +>A : A +>B : B + + while (true) { +>true : boolean + + if (isA(x)) { +>isA(x) : boolean +>isA : (x: any) => x is A +>x : A | B + + x.prop.a; +>x.prop.a : string +>x.prop : { a: string; } +>x : A +>prop : { a: string; } +>a : string + } + else if (isB(x)) { +>isB(x) : boolean +>isB : (x: any) => x is B +>x : B + + x.prop.b; // error: property 'b' doesn't exist on type { a: string } +>x.prop.b : string +>x.prop : { b: string; } +>x : B +>prop : { b: string; } +>b : string + } + } +} + diff --git a/tests/cases/compiler/narrowingOfDottedNames.ts b/tests/cases/compiler/narrowingOfDottedNames.ts new file mode 100644 index 00000000000..fd64d6d8874 --- /dev/null +++ b/tests/cases/compiler/narrowingOfDottedNames.ts @@ -0,0 +1,39 @@ +// Repro from #8383 + +class A { + prop: { a: string; }; +} + +class B { + prop: { b: string; } +} + +function isA(x: any): x is A { + return x instanceof A; +} + +function isB(x: any): x is B { + return x instanceof B; +} + +function f1(x: A | B) { + while (true) { + if (x instanceof A) { + x.prop.a; + } + else if (x instanceof B) { + x.prop.b; // error: property 'b' doesn't exist on type { a: string } + } + } +} + +function f2(x: A | B) { + while (true) { + if (isA(x)) { + x.prop.a; + } + else if (isB(x)) { + x.prop.b; // error: property 'b' doesn't exist on type { a: string } + } + } +} From ef5119590b1a328542924020d505621f912346ed Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Fri, 29 Apr 2016 16:40:07 -0700 Subject: [PATCH 41/52] Removing comments from test --- tests/baselines/reference/narrowingOfDottedNames.js | 8 ++++---- tests/baselines/reference/narrowingOfDottedNames.symbols | 4 ++-- tests/baselines/reference/narrowingOfDottedNames.types | 4 ++-- tests/cases/compiler/narrowingOfDottedNames.ts | 4 ++-- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/baselines/reference/narrowingOfDottedNames.js b/tests/baselines/reference/narrowingOfDottedNames.js index 5a159f38220..14cdcd55631 100644 --- a/tests/baselines/reference/narrowingOfDottedNames.js +++ b/tests/baselines/reference/narrowingOfDottedNames.js @@ -23,7 +23,7 @@ function f1(x: A | B) { x.prop.a; } else if (x instanceof B) { - x.prop.b; // error: property 'b' doesn't exist on type { a: string } + x.prop.b; } } } @@ -34,7 +34,7 @@ function f2(x: A | B) { x.prop.a; } else if (isB(x)) { - x.prop.b; // error: property 'b' doesn't exist on type { a: string } + x.prop.b; } } } @@ -64,7 +64,7 @@ function f1(x) { x.prop.a; } else if (x instanceof B) { - x.prop.b; // error: property 'b' doesn't exist on type { a: string } + x.prop.b; } } } @@ -74,7 +74,7 @@ function f2(x) { x.prop.a; } else if (isB(x)) { - x.prop.b; // error: property 'b' doesn't exist on type { a: string } + x.prop.b; } } } diff --git a/tests/baselines/reference/narrowingOfDottedNames.symbols b/tests/baselines/reference/narrowingOfDottedNames.symbols index 474b8c0b655..98f75372a4e 100644 --- a/tests/baselines/reference/narrowingOfDottedNames.symbols +++ b/tests/baselines/reference/narrowingOfDottedNames.symbols @@ -61,7 +61,7 @@ function f1(x: A | B) { >x : Symbol(x, Decl(narrowingOfDottedNames.ts, 18, 12)) >B : Symbol(B, Decl(narrowingOfDottedNames.ts, 4, 1)) - x.prop.b; // error: property 'b' doesn't exist on type { a: string } + x.prop.b; >x.prop.b : Symbol(b, Decl(narrowingOfDottedNames.ts, 7, 11)) >x.prop : Symbol(B.prop, Decl(narrowingOfDottedNames.ts, 6, 9)) >x : Symbol(x, Decl(narrowingOfDottedNames.ts, 18, 12)) @@ -93,7 +93,7 @@ function f2(x: A | B) { >isB : Symbol(isB, Decl(narrowingOfDottedNames.ts, 12, 1)) >x : Symbol(x, Decl(narrowingOfDottedNames.ts, 29, 12)) - x.prop.b; // error: property 'b' doesn't exist on type { a: string } + x.prop.b; >x.prop.b : Symbol(b, Decl(narrowingOfDottedNames.ts, 7, 11)) >x.prop : Symbol(B.prop, Decl(narrowingOfDottedNames.ts, 6, 9)) >x : Symbol(x, Decl(narrowingOfDottedNames.ts, 29, 12)) diff --git a/tests/baselines/reference/narrowingOfDottedNames.types b/tests/baselines/reference/narrowingOfDottedNames.types index f9d640dccab..697e080b661 100644 --- a/tests/baselines/reference/narrowingOfDottedNames.types +++ b/tests/baselines/reference/narrowingOfDottedNames.types @@ -67,7 +67,7 @@ function f1(x: A | B) { >x : B >B : typeof B - x.prop.b; // error: property 'b' doesn't exist on type { a: string } + x.prop.b; >x.prop.b : string >x.prop : { b: string; } >x : B @@ -103,7 +103,7 @@ function f2(x: A | B) { >isB : (x: any) => x is B >x : B - x.prop.b; // error: property 'b' doesn't exist on type { a: string } + x.prop.b; >x.prop.b : string >x.prop : { b: string; } >x : B diff --git a/tests/cases/compiler/narrowingOfDottedNames.ts b/tests/cases/compiler/narrowingOfDottedNames.ts index fd64d6d8874..af417f0830c 100644 --- a/tests/cases/compiler/narrowingOfDottedNames.ts +++ b/tests/cases/compiler/narrowingOfDottedNames.ts @@ -22,7 +22,7 @@ function f1(x: A | B) { x.prop.a; } else if (x instanceof B) { - x.prop.b; // error: property 'b' doesn't exist on type { a: string } + x.prop.b; } } } @@ -33,7 +33,7 @@ function f2(x: A | B) { x.prop.a; } else if (isB(x)) { - x.prop.b; // error: property 'b' doesn't exist on type { a: string } + x.prop.b; } } } From 8d45a73f126b6c5779bb7ee07ae6923bfe9dbe8c Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Fri, 29 Apr 2016 16:42:51 -0700 Subject: [PATCH 42/52] Add --noImplicitThis test for object literals --- .../noImplicitThisObjectLiterals.errors.txt | 22 +++++++++++++++++++ .../reference/noImplicitThisObjectLiterals.js | 22 +++++++++++++++++++ .../compiler/noImplicitThisObjectLiterals.ts | 10 +++++++++ 3 files changed, 54 insertions(+) create mode 100644 tests/baselines/reference/noImplicitThisObjectLiterals.errors.txt create mode 100644 tests/baselines/reference/noImplicitThisObjectLiterals.js create mode 100644 tests/cases/compiler/noImplicitThisObjectLiterals.ts diff --git a/tests/baselines/reference/noImplicitThisObjectLiterals.errors.txt b/tests/baselines/reference/noImplicitThisObjectLiterals.errors.txt new file mode 100644 index 00000000000..6f25f2d3a08 --- /dev/null +++ b/tests/baselines/reference/noImplicitThisObjectLiterals.errors.txt @@ -0,0 +1,22 @@ +tests/cases/compiler/noImplicitThisObjectLiterals.ts(2,8): error TS2683: 'this' implicitly has type 'any' because it does not have a type annotation. +tests/cases/compiler/noImplicitThisObjectLiterals.ts(4,16): error TS2683: 'this' implicitly has type 'any' because it does not have a type annotation. +tests/cases/compiler/noImplicitThisObjectLiterals.ts(7,16): error TS2683: 'this' implicitly has type 'any' because it does not have a type annotation. + + +==== tests/cases/compiler/noImplicitThisObjectLiterals.ts (3 errors) ==== + let o = { + d: this, // error, this: any + ~~~~ +!!! error TS2683: 'this' implicitly has type 'any' because it does not have a type annotation. + m() { + return this.d.length; // error, this: any + ~~~~ +!!! error TS2683: 'this' implicitly has type 'any' because it does not have a type annotation. + }, + f: function() { + return this.d.length; // error, this: any + ~~~~ +!!! error TS2683: 'this' implicitly has type 'any' because it does not have a type annotation. + } + } + \ No newline at end of file diff --git a/tests/baselines/reference/noImplicitThisObjectLiterals.js b/tests/baselines/reference/noImplicitThisObjectLiterals.js new file mode 100644 index 00000000000..3888708a8da --- /dev/null +++ b/tests/baselines/reference/noImplicitThisObjectLiterals.js @@ -0,0 +1,22 @@ +//// [noImplicitThisObjectLiterals.ts] +let o = { + d: this, // error, this: any + m() { + return this.d.length; // error, this: any + }, + f: function() { + return this.d.length; // error, this: any + } +} + + +//// [noImplicitThisObjectLiterals.js] +var o = { + d: this, + m: function () { + return this.d.length; // error, this: any + }, + f: function () { + return this.d.length; // error, this: any + } +}; diff --git a/tests/cases/compiler/noImplicitThisObjectLiterals.ts b/tests/cases/compiler/noImplicitThisObjectLiterals.ts new file mode 100644 index 00000000000..abd5d9dcfba --- /dev/null +++ b/tests/cases/compiler/noImplicitThisObjectLiterals.ts @@ -0,0 +1,10 @@ +// @noImplicitThis: true +let o = { + d: this, // error, this: any + m() { + return this.d.length; // error, this: any + }, + f: function() { + return this.d.length; // error, this: any + } +} From 0cd0e0b5eace51ca6574283741474e126c4bd077 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Fri, 29 Apr 2016 17:04:53 -0700 Subject: [PATCH 43/52] Code review comments --- src/services/services.ts | 20 +++++++++---------- .../fourslash/getOccurrencesStringLiterals.ts | 10 ++++++++++ tests/cases/fourslash/renameStingLiterals.ts | 11 ++++++++++ 3 files changed, 31 insertions(+), 10 deletions(-) create mode 100644 tests/cases/fourslash/getOccurrencesStringLiterals.ts create mode 100644 tests/cases/fourslash/renameStingLiterals.ts diff --git a/src/services/services.ts b/src/services/services.ts index 173aea2dfc4..8d28d5d958a 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -6167,10 +6167,10 @@ namespace ts { const references: ReferenceEntry[] = []; - forEach(sourceFiles, sourceFile => { - const possiblePositions = getPossibleSymbolReferencePositions(sourceFile, type.text , sourceFile.getStart(), sourceFile.getEnd()); + for (const sourceFile of sourceFiles) { + const possiblePositions = getPossibleSymbolReferencePositions(sourceFile, type.text, sourceFile.getStart(), sourceFile.getEnd()); getReferencesForStringLiteralInFile(sourceFile, type, possiblePositions, references); - }); + } return [{ definition: { @@ -6185,7 +6185,7 @@ namespace ts { }]; function getReferencesForStringLiteralInFile(sourceFile: SourceFile, searchType: Type, possiblePositions: number[], references: ReferenceEntry[]): void { - forEach(possiblePositions, position => { + for (const position of possiblePositions) { cancellationToken.throwIfCancellationRequested(); const node = getTouchingWord(sourceFile, position); @@ -6197,7 +6197,7 @@ namespace ts { if (type === searchType) { references.push(getReferenceEntryFromNode(node)); } - }); + } } } @@ -7767,7 +7767,7 @@ namespace ts { localizedErrorMessage: undefined, fullDisplayName: typeChecker.getFullyQualifiedName(symbol), kindModifiers: getSymbolModifiers(symbol), - triggerSpan: createTriggerSpanForNode(node) + triggerSpan: createTriggerSpanForNode(node, sourceFile) }; } } @@ -7787,7 +7787,7 @@ namespace ts { localizedErrorMessage: undefined, fullDisplayName: displayName, kindModifiers: ScriptElementKindModifier.none, - triggerSpan: createTriggerSpanForNode(node) + triggerSpan: createTriggerSpanForNode(node, sourceFile) }; } } @@ -7820,9 +7820,9 @@ namespace ts { return false; } - function createTriggerSpanForNode(node: Node) { - let start = node.getStart(); - let width = node.getWidth(); + function createTriggerSpanForNode(node: Node, sourceFile: SourceFile) { + let start = node.getStart(sourceFile); + let width = node.getWidth(sourceFile); if (node.kind === SyntaxKind.StringLiteral) { // Exclude the quotes start += 1; diff --git a/tests/cases/fourslash/getOccurrencesStringLiterals.ts b/tests/cases/fourslash/getOccurrencesStringLiterals.ts new file mode 100644 index 00000000000..efa365cbbb8 --- /dev/null +++ b/tests/cases/fourslash/getOccurrencesStringLiterals.ts @@ -0,0 +1,10 @@ +/// + +////var x = "[|string|]"; +////function f(a = "[|initial value|]") { } + +const ranges = test.ranges(); +for (let r of ranges) { + goTo.position(r.start); + verify.occurrencesAtPositionCount(0); +} diff --git a/tests/cases/fourslash/renameStingLiterals.ts b/tests/cases/fourslash/renameStingLiterals.ts new file mode 100644 index 00000000000..2e31deb46e1 --- /dev/null +++ b/tests/cases/fourslash/renameStingLiterals.ts @@ -0,0 +1,11 @@ +/// + +////var x = "/*1*/string"; +////function f(a = "/*2*/initial value") { } + + +goTo.marker("1"); +verify.renameInfoFailed(); + +goTo.marker("2"); +verify.renameInfoFailed(); From 9adc42a20cb55258ae7fc780dd093c39e3f9103a Mon Sep 17 00:00:00 2001 From: Stanislav Sysoev Date: Sat, 23 Apr 2016 23:12:23 +0300 Subject: [PATCH 44/52] Remove name length limit in navigation bar service for function expression --- src/services/navigationBar.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/services/navigationBar.ts b/src/services/navigationBar.ts index 1d7e968444e..d83d0738ec8 100644 --- a/src/services/navigationBar.ts +++ b/src/services/navigationBar.ts @@ -758,9 +758,6 @@ namespace ts.NavigationBar { else if (fnExpr.parent.kind === SyntaxKind.BinaryExpression && (fnExpr.parent as BinaryExpression).operatorToken.kind === SyntaxKind.EqualsToken) { fnName = (fnExpr.parent as BinaryExpression).left.getText(); - if (fnName.length > 20) { - fnName = fnName.substring(0, 17) + "..."; - } } // See if it is a property assignment, and if so use the property name else if (fnExpr.parent.kind === SyntaxKind.PropertyAssignment && From fa86d1383e1fb8364f9a20edba03c405335c10a5 Mon Sep 17 00:00:00 2001 From: Andrew Z Allen Date: Fri, 29 Apr 2016 22:59:07 -0600 Subject: [PATCH 45/52] Add start target to package.json This allows tsc to be packaged hermetically by https://github.com/h2non/nar. --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index cc74bf2c27c..bb476070286 100644 --- a/package.json +++ b/package.json @@ -45,6 +45,7 @@ "build": "npm run build:compiler && npm run build:tests", "build:compiler": "jake local", "build:tests": "jake tests", + "start": "node lib/tsc", "clean": "jake clean", "jake": "jake", "lint": "jake lint", From be9d8bd67a41c4ce05ae347958c7be22013b957d Mon Sep 17 00:00:00 2001 From: Alex Eagle Date: Sun, 1 May 2016 11:11:09 -0700 Subject: [PATCH 46/52] Include sourcefiles in the WriteFileCallback for .d.ts emit Fixes #7438 --- src/compiler/declarationEmitter.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/declarationEmitter.ts b/src/compiler/declarationEmitter.ts index 58ce2286627..aceec933227 100644 --- a/src/compiler/declarationEmitter.ts +++ b/src/compiler/declarationEmitter.ts @@ -1753,7 +1753,7 @@ namespace ts { if (!emitSkipped) { const declarationOutput = emitDeclarationResult.referencesOutput + getDeclarationOutput(emitDeclarationResult.synchronousDeclarationOutput, emitDeclarationResult.moduleElementDeclarationEmitInfo); - writeFile(host, emitterDiagnostics, declarationFilePath, declarationOutput, host.getCompilerOptions().emitBOM); + writeFile(host, emitterDiagnostics, declarationFilePath, declarationOutput, host.getCompilerOptions().emitBOM, sourceFiles); } return emitSkipped; From ee4baef51fba69ed6fcd9ea89cd44d3f77f21a46 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Sun, 1 May 2016 21:08:53 -0700 Subject: [PATCH 47/52] Applied suggested change. --- src/compiler/checker.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index ef53b6e7d61..f182ce899ce 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5912,7 +5912,7 @@ namespace ts { } // The constraint may need to be further instantiated with its 'this' type. - constraint = getTypeWithThisArgument(constraint); + constraint = getTypeWithThisArgument(constraint, source); // Report constraint errors only if the constraint is not the empty object type const reportConstraintErrors = reportErrors && constraint !== emptyObjectType; From b75605e55e7425f1f763b56bcefa64f1b8c2a1f6 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Sun, 1 May 2016 21:53:27 -0700 Subject: [PATCH 48/52] Accepted baselines. --- .../recurringTypeParamForContainerOfBase01.symbols | 6 +++--- ...hisTypeInBasePropertyAndDerivedContainerOfBase01.symbols | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/baselines/reference/recurringTypeParamForContainerOfBase01.symbols b/tests/baselines/reference/recurringTypeParamForContainerOfBase01.symbols index f0a5eafeae2..48ea1ffa0cf 100644 --- a/tests/baselines/reference/recurringTypeParamForContainerOfBase01.symbols +++ b/tests/baselines/reference/recurringTypeParamForContainerOfBase01.symbols @@ -7,7 +7,7 @@ interface BoxOfFoo> { >T : Symbol(T, Decl(recurringTypeParamForContainerOfBase01.ts, 1, 19)) item: T ->item : Symbol(item, Decl(recurringTypeParamForContainerOfBase01.ts, 1, 38)) +>item : Symbol(BoxOfFoo.item, Decl(recurringTypeParamForContainerOfBase01.ts, 1, 38)) >T : Symbol(T, Decl(recurringTypeParamForContainerOfBase01.ts, 1, 19)) } @@ -18,7 +18,7 @@ interface Foo> { >T : Symbol(T, Decl(recurringTypeParamForContainerOfBase01.ts, 5, 14)) self: T; ->self : Symbol(self, Decl(recurringTypeParamForContainerOfBase01.ts, 5, 33)) +>self : Symbol(Foo.self, Decl(recurringTypeParamForContainerOfBase01.ts, 5, 33)) >T : Symbol(T, Decl(recurringTypeParamForContainerOfBase01.ts, 5, 14)) } @@ -31,7 +31,7 @@ interface Bar> extends Foo { >T : Symbol(T, Decl(recurringTypeParamForContainerOfBase01.ts, 9, 14)) other: BoxOfFoo; ->other : Symbol(other, Decl(recurringTypeParamForContainerOfBase01.ts, 9, 48)) +>other : Symbol(Bar.other, Decl(recurringTypeParamForContainerOfBase01.ts, 9, 48)) >BoxOfFoo : Symbol(BoxOfFoo, Decl(recurringTypeParamForContainerOfBase01.ts, 0, 0)) >T : Symbol(T, Decl(recurringTypeParamForContainerOfBase01.ts, 9, 14)) } diff --git a/tests/baselines/reference/thisTypeInBasePropertyAndDerivedContainerOfBase01.symbols b/tests/baselines/reference/thisTypeInBasePropertyAndDerivedContainerOfBase01.symbols index 379e4d3c8a4..566bf3aa093 100644 --- a/tests/baselines/reference/thisTypeInBasePropertyAndDerivedContainerOfBase01.symbols +++ b/tests/baselines/reference/thisTypeInBasePropertyAndDerivedContainerOfBase01.symbols @@ -6,7 +6,7 @@ interface BoxOfFoo { >Foo : Symbol(Foo, Decl(thisTypeInBasePropertyAndDerivedContainerOfBase01.ts, 3, 1)) item: T ->item : Symbol(item, Decl(thisTypeInBasePropertyAndDerivedContainerOfBase01.ts, 1, 35)) +>item : Symbol(BoxOfFoo.item, Decl(thisTypeInBasePropertyAndDerivedContainerOfBase01.ts, 1, 35)) >T : Symbol(T, Decl(thisTypeInBasePropertyAndDerivedContainerOfBase01.ts, 1, 19)) } @@ -14,7 +14,7 @@ interface Foo { >Foo : Symbol(Foo, Decl(thisTypeInBasePropertyAndDerivedContainerOfBase01.ts, 3, 1)) self: this; ->self : Symbol(self, Decl(thisTypeInBasePropertyAndDerivedContainerOfBase01.ts, 5, 15)) +>self : Symbol(Foo.self, Decl(thisTypeInBasePropertyAndDerivedContainerOfBase01.ts, 5, 15)) } interface Bar extends Foo { @@ -22,6 +22,6 @@ interface Bar extends Foo { >Foo : Symbol(Foo, Decl(thisTypeInBasePropertyAndDerivedContainerOfBase01.ts, 3, 1)) other: BoxOfFoo; ->other : Symbol(other, Decl(thisTypeInBasePropertyAndDerivedContainerOfBase01.ts, 9, 27)) +>other : Symbol(Bar.other, Decl(thisTypeInBasePropertyAndDerivedContainerOfBase01.ts, 9, 27)) >BoxOfFoo : Symbol(BoxOfFoo, Decl(thisTypeInBasePropertyAndDerivedContainerOfBase01.ts, 0, 0)) } From f183f1ab387331f3957faf9a581c26ab54aa775a Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Mon, 2 May 2016 09:21:54 -0700 Subject: [PATCH 49/52] Quicker bail out for type analysis in nested loops --- src/compiler/checker.ts | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index c434721d714..b3174766347 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -7664,17 +7664,18 @@ namespace ts { const type = flow.kind === FlowKind.LoopLabel ? getTypeAtFlowNodeCached(antecedent) : getTypeAtFlowNode(antecedent); - if (type) { - // If the type at a particular antecedent path is the declared type and the - // reference is known to always be assigned (i.e. when declared and initial types - // are the same), there is no reason to process more antecedents since the only - // possible outcome is subtypes that will be removed in the final union type anyway. - if (type === declaredType && declaredType === initialType) { - return type; - } - if (!contains(antecedentTypes, type)) { - antecedentTypes.push(type); - } + if (!type) { + break; + } + // If the type at a particular antecedent path is the declared type and the + // reference is known to always be assigned (i.e. when declared and initial types + // are the same), there is no reason to process more antecedents since the only + // possible outcome is subtypes that will be removed in the final union type anyway. + if (type === declaredType && declaredType === initialType) { + return type; + } + if (!contains(antecedentTypes, type)) { + antecedentTypes.push(type); } } return antecedentTypes.length === 0 ? undefined : From 82d4f4288f6f4bd7320d60b7693c3e877965122e Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Mon, 2 May 2016 09:22:04 -0700 Subject: [PATCH 50/52] Adding regression test --- .../reference/controlFlowWhileStatement.js | 46 ++++++++++++++ .../controlFlowWhileStatement.symbols | 53 ++++++++++++++++ .../reference/controlFlowWhileStatement.types | 62 +++++++++++++++++++ .../controlFlow/controlFlowWhileStatement.ts | 23 +++++++ 4 files changed, 184 insertions(+) diff --git a/tests/baselines/reference/controlFlowWhileStatement.js b/tests/baselines/reference/controlFlowWhileStatement.js index d9faf9bd0ea..c9299330082 100644 --- a/tests/baselines/reference/controlFlowWhileStatement.js +++ b/tests/baselines/reference/controlFlowWhileStatement.js @@ -105,6 +105,29 @@ function h3() { } x; // string | number } +// Repro for #8418 +function foo(x: number): number { return 1; } +function test1() { + let x: number | undefined; + while (cond) { + while (cond) { + while (cond) { + x = foo(x); + } + } + x = 1; + } +} +// Repro for #8418 +function test2() { + let x: number | undefined; + x = 1; + while (cond) { + while (cond) { + x = foo(x); + } + } +} //// [controlFlowWhileStatement.js] @@ -214,3 +237,26 @@ function h3() { } x; // string | number } +// Repro for #8418 +function foo(x) { return 1; } +function test1() { + var x; + while (cond) { + while (cond) { + while (cond) { + x = foo(x); + } + } + x = 1; + } +} +// Repro for #8418 +function test2() { + var x; + x = 1; + while (cond) { + while (cond) { + x = foo(x); + } + } +} diff --git a/tests/baselines/reference/controlFlowWhileStatement.symbols b/tests/baselines/reference/controlFlowWhileStatement.symbols index 3b4def93b45..c38908240ee 100644 --- a/tests/baselines/reference/controlFlowWhileStatement.symbols +++ b/tests/baselines/reference/controlFlowWhileStatement.symbols @@ -254,4 +254,57 @@ function h3() { x; // string | number >x : Symbol(x, Decl(controlFlowWhileStatement.ts, 98, 7)) } +// Repro for #8418 +function foo(x: number): number { return 1; } +>foo : Symbol(foo, Decl(controlFlowWhileStatement.ts, 105, 1)) +>x : Symbol(x, Decl(controlFlowWhileStatement.ts, 107, 13)) + +function test1() { +>test1 : Symbol(test1, Decl(controlFlowWhileStatement.ts, 107, 45)) + + let x: number | undefined; +>x : Symbol(x, Decl(controlFlowWhileStatement.ts, 109, 7)) + + while (cond) { +>cond : Symbol(cond, Decl(controlFlowWhileStatement.ts, 0, 3)) + + while (cond) { +>cond : Symbol(cond, Decl(controlFlowWhileStatement.ts, 0, 3)) + + while (cond) { +>cond : Symbol(cond, Decl(controlFlowWhileStatement.ts, 0, 3)) + + x = foo(x); +>x : Symbol(x, Decl(controlFlowWhileStatement.ts, 109, 7)) +>foo : Symbol(foo, Decl(controlFlowWhileStatement.ts, 105, 1)) +>x : Symbol(x, Decl(controlFlowWhileStatement.ts, 109, 7)) + } + } + x = 1; +>x : Symbol(x, Decl(controlFlowWhileStatement.ts, 109, 7)) + } +} +// Repro for #8418 +function test2() { +>test2 : Symbol(test2, Decl(controlFlowWhileStatement.ts, 118, 1)) + + let x: number | undefined; +>x : Symbol(x, Decl(controlFlowWhileStatement.ts, 121, 7)) + + x = 1; +>x : Symbol(x, Decl(controlFlowWhileStatement.ts, 121, 7)) + + while (cond) { +>cond : Symbol(cond, Decl(controlFlowWhileStatement.ts, 0, 3)) + + while (cond) { +>cond : Symbol(cond, Decl(controlFlowWhileStatement.ts, 0, 3)) + + x = foo(x); +>x : Symbol(x, Decl(controlFlowWhileStatement.ts, 121, 7)) +>foo : Symbol(foo, Decl(controlFlowWhileStatement.ts, 105, 1)) +>x : Symbol(x, Decl(controlFlowWhileStatement.ts, 121, 7)) + } + } +} diff --git a/tests/baselines/reference/controlFlowWhileStatement.types b/tests/baselines/reference/controlFlowWhileStatement.types index a17c084228b..48af317e2ec 100644 --- a/tests/baselines/reference/controlFlowWhileStatement.types +++ b/tests/baselines/reference/controlFlowWhileStatement.types @@ -307,4 +307,66 @@ function h3() { x; // string | number >x : string | number } +// Repro for #8418 +function foo(x: number): number { return 1; } +>foo : (x: number) => number +>x : number +>1 : number + +function test1() { +>test1 : () => void + + let x: number | undefined; +>x : number + + while (cond) { +>cond : boolean + + while (cond) { +>cond : boolean + + while (cond) { +>cond : boolean + + x = foo(x); +>x = foo(x) : number +>x : number +>foo(x) : number +>foo : (x: number) => number +>x : number + } + } + x = 1; +>x = 1 : number +>x : number +>1 : number + } +} +// Repro for #8418 +function test2() { +>test2 : () => void + + let x: number | undefined; +>x : number + + x = 1; +>x = 1 : number +>x : number +>1 : number + + while (cond) { +>cond : boolean + + while (cond) { +>cond : boolean + + x = foo(x); +>x = foo(x) : number +>x : number +>foo(x) : number +>foo : (x: number) => number +>x : number + } + } +} diff --git a/tests/cases/conformance/controlFlow/controlFlowWhileStatement.ts b/tests/cases/conformance/controlFlow/controlFlowWhileStatement.ts index 7bf49dd7224..61c09094e56 100644 --- a/tests/cases/conformance/controlFlow/controlFlowWhileStatement.ts +++ b/tests/cases/conformance/controlFlow/controlFlowWhileStatement.ts @@ -104,3 +104,26 @@ function h3() { } x; // string | number } +// Repro for #8418 +function foo(x: number): number { return 1; } +function test1() { + let x: number | undefined; + while (cond) { + while (cond) { + while (cond) { + x = foo(x); + } + } + x = 1; + } +} +// Repro for #8418 +function test2() { + let x: number | undefined; + x = 1; + while (cond) { + while (cond) { + x = foo(x); + } + } +} From 0c507747c89bd01d183b8d82c55fefa1fcbda104 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Mon, 2 May 2016 10:18:13 -0700 Subject: [PATCH 51/52] Add a contextual type in test case --- tests/cases/fourslash/renameStingLiterals.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/cases/fourslash/renameStingLiterals.ts b/tests/cases/fourslash/renameStingLiterals.ts index 2e31deb46e1..0e1222f327a 100644 --- a/tests/cases/fourslash/renameStingLiterals.ts +++ b/tests/cases/fourslash/renameStingLiterals.ts @@ -1,5 +1,6 @@ /// +////var y: "string" = "string; ////var x = "/*1*/string"; ////function f(a = "/*2*/initial value") { } From d9f0293c6cdb6d94d80f3ca801cdd268b245c344 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Mon, 2 May 2016 11:17:10 -0700 Subject: [PATCH 52/52] Fixing repro test --- .../controlFlowLoopAnalysis.errors.txt | 39 ++++++++++++ .../reference/controlFlowLoopAnalysis.js | 58 +++++++++++++++++ .../reference/controlFlowWhileStatement.js | 46 -------------- .../controlFlowWhileStatement.symbols | 53 ---------------- .../reference/controlFlowWhileStatement.types | 62 ------------------- .../cases/compiler/controlFlowLoopAnalysis.ts | 31 ++++++++++ .../controlFlow/controlFlowWhileStatement.ts | 23 ------- 7 files changed, 128 insertions(+), 184 deletions(-) create mode 100644 tests/baselines/reference/controlFlowLoopAnalysis.errors.txt create mode 100644 tests/baselines/reference/controlFlowLoopAnalysis.js create mode 100644 tests/cases/compiler/controlFlowLoopAnalysis.ts diff --git a/tests/baselines/reference/controlFlowLoopAnalysis.errors.txt b/tests/baselines/reference/controlFlowLoopAnalysis.errors.txt new file mode 100644 index 00000000000..21bf6b1c19a --- /dev/null +++ b/tests/baselines/reference/controlFlowLoopAnalysis.errors.txt @@ -0,0 +1,39 @@ +tests/cases/compiler/controlFlowLoopAnalysis.ts(13,25): error TS2345: Argument of type 'number | undefined' is not assignable to parameter of type 'number'. + Type 'undefined' is not assignable to type 'number'. + + +==== tests/cases/compiler/controlFlowLoopAnalysis.ts (1 errors) ==== + + // Repro from #8418 + + let cond: boolean; + + function foo(x: number): number { return 1; } + + function test1() { + let x: number | undefined; + while (cond) { + while (cond) { + while (cond) { + x = foo(x); + ~ +!!! error TS2345: Argument of type 'number | undefined' is not assignable to parameter of type 'number'. +!!! error TS2345: Type 'undefined' is not assignable to type 'number'. + } + } + x = 1; + } + } + + // Repro from #8418 + + function test2() { + let x: number | undefined; + x = 1; + while (cond) { + while (cond) { + x = foo(x); + } + } + } + \ No newline at end of file diff --git a/tests/baselines/reference/controlFlowLoopAnalysis.js b/tests/baselines/reference/controlFlowLoopAnalysis.js new file mode 100644 index 00000000000..3cf2ce2caac --- /dev/null +++ b/tests/baselines/reference/controlFlowLoopAnalysis.js @@ -0,0 +1,58 @@ +//// [controlFlowLoopAnalysis.ts] + +// Repro from #8418 + +let cond: boolean; + +function foo(x: number): number { return 1; } + +function test1() { + let x: number | undefined; + while (cond) { + while (cond) { + while (cond) { + x = foo(x); + } + } + x = 1; + } +} + +// Repro from #8418 + +function test2() { + let x: number | undefined; + x = 1; + while (cond) { + while (cond) { + x = foo(x); + } + } +} + + +//// [controlFlowLoopAnalysis.js] +// Repro from #8418 +var cond; +function foo(x) { return 1; } +function test1() { + var x; + while (cond) { + while (cond) { + while (cond) { + x = foo(x); + } + } + x = 1; + } +} +// Repro from #8418 +function test2() { + var x; + x = 1; + while (cond) { + while (cond) { + x = foo(x); + } + } +} diff --git a/tests/baselines/reference/controlFlowWhileStatement.js b/tests/baselines/reference/controlFlowWhileStatement.js index c9299330082..d9faf9bd0ea 100644 --- a/tests/baselines/reference/controlFlowWhileStatement.js +++ b/tests/baselines/reference/controlFlowWhileStatement.js @@ -105,29 +105,6 @@ function h3() { } x; // string | number } -// Repro for #8418 -function foo(x: number): number { return 1; } -function test1() { - let x: number | undefined; - while (cond) { - while (cond) { - while (cond) { - x = foo(x); - } - } - x = 1; - } -} -// Repro for #8418 -function test2() { - let x: number | undefined; - x = 1; - while (cond) { - while (cond) { - x = foo(x); - } - } -} //// [controlFlowWhileStatement.js] @@ -237,26 +214,3 @@ function h3() { } x; // string | number } -// Repro for #8418 -function foo(x) { return 1; } -function test1() { - var x; - while (cond) { - while (cond) { - while (cond) { - x = foo(x); - } - } - x = 1; - } -} -// Repro for #8418 -function test2() { - var x; - x = 1; - while (cond) { - while (cond) { - x = foo(x); - } - } -} diff --git a/tests/baselines/reference/controlFlowWhileStatement.symbols b/tests/baselines/reference/controlFlowWhileStatement.symbols index c38908240ee..3b4def93b45 100644 --- a/tests/baselines/reference/controlFlowWhileStatement.symbols +++ b/tests/baselines/reference/controlFlowWhileStatement.symbols @@ -254,57 +254,4 @@ function h3() { x; // string | number >x : Symbol(x, Decl(controlFlowWhileStatement.ts, 98, 7)) } -// Repro for #8418 -function foo(x: number): number { return 1; } ->foo : Symbol(foo, Decl(controlFlowWhileStatement.ts, 105, 1)) ->x : Symbol(x, Decl(controlFlowWhileStatement.ts, 107, 13)) - -function test1() { ->test1 : Symbol(test1, Decl(controlFlowWhileStatement.ts, 107, 45)) - - let x: number | undefined; ->x : Symbol(x, Decl(controlFlowWhileStatement.ts, 109, 7)) - - while (cond) { ->cond : Symbol(cond, Decl(controlFlowWhileStatement.ts, 0, 3)) - - while (cond) { ->cond : Symbol(cond, Decl(controlFlowWhileStatement.ts, 0, 3)) - - while (cond) { ->cond : Symbol(cond, Decl(controlFlowWhileStatement.ts, 0, 3)) - - x = foo(x); ->x : Symbol(x, Decl(controlFlowWhileStatement.ts, 109, 7)) ->foo : Symbol(foo, Decl(controlFlowWhileStatement.ts, 105, 1)) ->x : Symbol(x, Decl(controlFlowWhileStatement.ts, 109, 7)) - } - } - x = 1; ->x : Symbol(x, Decl(controlFlowWhileStatement.ts, 109, 7)) - } -} -// Repro for #8418 -function test2() { ->test2 : Symbol(test2, Decl(controlFlowWhileStatement.ts, 118, 1)) - - let x: number | undefined; ->x : Symbol(x, Decl(controlFlowWhileStatement.ts, 121, 7)) - - x = 1; ->x : Symbol(x, Decl(controlFlowWhileStatement.ts, 121, 7)) - - while (cond) { ->cond : Symbol(cond, Decl(controlFlowWhileStatement.ts, 0, 3)) - - while (cond) { ->cond : Symbol(cond, Decl(controlFlowWhileStatement.ts, 0, 3)) - - x = foo(x); ->x : Symbol(x, Decl(controlFlowWhileStatement.ts, 121, 7)) ->foo : Symbol(foo, Decl(controlFlowWhileStatement.ts, 105, 1)) ->x : Symbol(x, Decl(controlFlowWhileStatement.ts, 121, 7)) - } - } -} diff --git a/tests/baselines/reference/controlFlowWhileStatement.types b/tests/baselines/reference/controlFlowWhileStatement.types index 48af317e2ec..a17c084228b 100644 --- a/tests/baselines/reference/controlFlowWhileStatement.types +++ b/tests/baselines/reference/controlFlowWhileStatement.types @@ -307,66 +307,4 @@ function h3() { x; // string | number >x : string | number } -// Repro for #8418 -function foo(x: number): number { return 1; } ->foo : (x: number) => number ->x : number ->1 : number - -function test1() { ->test1 : () => void - - let x: number | undefined; ->x : number - - while (cond) { ->cond : boolean - - while (cond) { ->cond : boolean - - while (cond) { ->cond : boolean - - x = foo(x); ->x = foo(x) : number ->x : number ->foo(x) : number ->foo : (x: number) => number ->x : number - } - } - x = 1; ->x = 1 : number ->x : number ->1 : number - } -} -// Repro for #8418 -function test2() { ->test2 : () => void - - let x: number | undefined; ->x : number - - x = 1; ->x = 1 : number ->x : number ->1 : number - - while (cond) { ->cond : boolean - - while (cond) { ->cond : boolean - - x = foo(x); ->x = foo(x) : number ->x : number ->foo(x) : number ->foo : (x: number) => number ->x : number - } - } -} diff --git a/tests/cases/compiler/controlFlowLoopAnalysis.ts b/tests/cases/compiler/controlFlowLoopAnalysis.ts new file mode 100644 index 00000000000..60cb9436006 --- /dev/null +++ b/tests/cases/compiler/controlFlowLoopAnalysis.ts @@ -0,0 +1,31 @@ +// @strictNullChecks: true + +// Repro from #8418 + +let cond: boolean; + +function foo(x: number): number { return 1; } + +function test1() { + let x: number | undefined; + while (cond) { + while (cond) { + while (cond) { + x = foo(x); + } + } + x = 1; + } +} + +// Repro from #8418 + +function test2() { + let x: number | undefined; + x = 1; + while (cond) { + while (cond) { + x = foo(x); + } + } +} diff --git a/tests/cases/conformance/controlFlow/controlFlowWhileStatement.ts b/tests/cases/conformance/controlFlow/controlFlowWhileStatement.ts index 61c09094e56..7bf49dd7224 100644 --- a/tests/cases/conformance/controlFlow/controlFlowWhileStatement.ts +++ b/tests/cases/conformance/controlFlow/controlFlowWhileStatement.ts @@ -104,26 +104,3 @@ function h3() { } x; // string | number } -// Repro for #8418 -function foo(x: number): number { return 1; } -function test1() { - let x: number | undefined; - while (cond) { - while (cond) { - while (cond) { - x = foo(x); - } - } - x = 1; - } -} -// Repro for #8418 -function test2() { - let x: number | undefined; - x = 1; - while (cond) { - while (cond) { - x = foo(x); - } - } -}