Merge from vscode 011858832762aaff245b2336fb1c38166e7a10fb (#4663)

This commit is contained in:
Anthony Dresser
2019-03-22 13:07:54 -07:00
committed by GitHub
parent f5c9174c2f
commit 4a87a24235
296 changed files with 2531 additions and 2472 deletions

View File

@@ -404,9 +404,8 @@ export function firstIndex<T>(array: ReadonlyArray<T>, fn: (item: T) => boolean)
}
export function first<T>(array: ReadonlyArray<T>, fn: (item: T) => boolean, notFoundValue: T): T;
export function first<T>(array: ReadonlyArray<T>, fn: (item: T) => boolean): T | null;
export function first<T>(array: ReadonlyArray<T>, fn: (item: T) => boolean, notFoundValue: T | null): T | null;
export function first<T>(array: ReadonlyArray<T>, fn: (item: T) => boolean, notFoundValue: T | null = null): T | null {
export function first<T>(array: ReadonlyArray<T>, fn: (item: T) => boolean): T | undefined;
export function first<T>(array: ReadonlyArray<T>, fn: (item: T) => boolean, notFoundValue: T | undefined = undefined): T | undefined {
const index = firstIndex(array, fn);
return index < 0 ? notFoundValue : array[index];
}

View File

@@ -178,7 +178,7 @@ export class Delayer<T> implements IDisposable {
private timeout: any;
private completionPromise: Promise<any> | null;
private doResolve: ((value?: any | Promise<any>) => void) | null;
private doReject: (err: any) => void;
private doReject?: (err: any) => void;
private task: ITask<T | Promise<T>> | null;
constructor(public defaultDelay: number) {
@@ -222,7 +222,7 @@ export class Delayer<T> implements IDisposable {
this.cancelTimeout();
if (this.completionPromise) {
this.doReject(errors.canceled());
this.doReject!(errors.canceled());
this.completionPromise = null;
}
}
@@ -282,7 +282,7 @@ export class Barrier {
private _isOpen: boolean;
private _promise: Promise<boolean>;
private _completePromise: (v: boolean) => void;
private _completePromise!: (v: boolean) => void;
constructor() {
this._isOpen = false;
@@ -731,8 +731,8 @@ export class IdleValue<T> {
private readonly _executor: () => void;
private readonly _handle: IDisposable;
private _didRun: boolean;
private _value: T;
private _didRun: boolean = false;
private _value?: T;
private _error: any;
constructor(executor: () => T) {
@@ -760,7 +760,7 @@ export class IdleValue<T> {
if (this._error) {
throw this._error;
}
return this._value;
return this._value!;
}
}

View File

@@ -87,7 +87,7 @@ class MutableToken implements CancellationToken {
export class CancellationTokenSource {
private _token: CancellationToken;
private _token?: CancellationToken;
get token(): CancellationToken {
if (!this._token) {

View File

@@ -260,7 +260,7 @@ export class Color {
}
readonly rgba: RGBA;
private _hsla: HSLA;
private _hsla?: HSLA;
get hsla(): HSLA {
if (this._hsla) {
return this._hsla;
@@ -269,7 +269,7 @@ export class Color {
}
}
private _hsva: HSVA;
private _hsva?: HSVA;
get hsva(): HSVA {
if (this._hsva) {
return this._hsva;

View File

@@ -119,6 +119,15 @@ function isWhitespace(code: number): boolean {
);
}
const wordSeparators = new Set<number>();
'`~!@#$%^&*()-=+[{]}\\|;:\'",.<>/?'
.split('')
.forEach(s => wordSeparators.add(s.charCodeAt(0)));
function isWordSeparator(code: number): boolean {
return wordSeparators.has(code);
}
function isAlphanumeric(code: number): boolean {
return isLower(code) || isUpper(code) || isNumber(code);
}
@@ -308,7 +317,8 @@ function _matchesWords(word: string, target: string, i: number, j: number, conti
function nextWord(word: string, start: number): number {
for (let i = start; i < word.length; i++) {
const c = word.charCodeAt(i);
if (isWhitespace(c) || (i > 0 && isWhitespace(word.charCodeAt(i - 1)))) {
if (isWhitespace(c) || (i > 0 && isWhitespace(word.charCodeAt(i - 1))) ||
isWordSeparator(c) || (i > 0 && isWordSeparator(word.charCodeAt(i - 1)))) {
return i;
}
}

View File

@@ -43,7 +43,7 @@ const CHAR_QUESTION_MARK = 63; /* ? */
class ErrorInvalidArgType extends Error {
code: 'ERR_INVALID_ARG_TYPE';
constructor(name: string, expected: string, actual: string) {
constructor(name: string, expected: string, actual: any) {
// determiner: 'must be' or 'must not be'
let determiner;
if (typeof expected === 'string' && expected.indexOf('not ') === 0) {
@@ -53,36 +53,35 @@ class ErrorInvalidArgType extends Error {
determiner = 'must be';
}
let msg;
const type = name.indexOf('.') !== -1 ? 'property' : 'argument';
msg = `The "${name}" ${type} ${determiner} of type ${expected}`;
let msg = `The "${name}" ${type} ${determiner} of type ${expected}`;
msg += `. Received type ${typeof actual}`;
super(msg);
}
}
function validateString(value: string, name) {
function validateString(value: string, name: string) {
if (typeof value !== 'string') {
throw new ErrorInvalidArgType(name, 'string', value);
}
}
function isPathSeparator(code) {
function isPathSeparator(code: number) {
return code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH;
}
function isPosixPathSeparator(code) {
function isPosixPathSeparator(code: number) {
return code === CHAR_FORWARD_SLASH;
}
function isWindowsDeviceRoot(code) {
function isWindowsDeviceRoot(code: number) {
return code >= CHAR_UPPERCASE_A && code <= CHAR_UPPERCASE_Z ||
code >= CHAR_LOWERCASE_A && code <= CHAR_LOWERCASE_Z;
}
// Resolves . and .. elements in a path with directory names
function normalizeString(path, allowAboveRoot, separator, isPathSeparator) {
function normalizeString(path: string, allowAboveRoot: boolean, separator: string, isPathSeparator: (code?: number) => boolean) {
let res = '';
let lastSegmentLength = 0;
let lastSlash = -1;
@@ -155,7 +154,7 @@ function normalizeString(path, allowAboveRoot, separator, isPathSeparator) {
return res;
}
function _format(sep, pathObject) {
function _format(sep: string, pathObject: ParsedPath) {
const dir = pathObject.dir || pathObject.root;
const base = pathObject.base ||
((pathObject.name || '') + (pathObject.ext || ''));
@@ -185,7 +184,7 @@ interface IPath {
dirname(path: string): string;
basename(path: string, ext?: string): string;
extname(path: string): string;
format(pathObject): string;
format(pathObject: ParsedPath): string;
parse(path: string): ParsedPath;
toNamespacedPath(path: string): string;
sep: '\\' | '/';
@@ -501,7 +500,7 @@ export const win32: IPath = {
}
let joined;
let firstPart;
let firstPart: string | undefined;
for (let i = 0; i < paths.length; ++i) {
const arg = paths[i];
validateString(arg, 'path');
@@ -534,7 +533,7 @@ export const win32: IPath = {
// path.join('//server', 'share') -> '\\\\server\\share\\')
let needsReplace = true;
let slashCount = 0;
if (isPathSeparator(firstPart.charCodeAt(0))) {
if (typeof firstPart === 'string' && isPathSeparator(firstPart.charCodeAt(0))) {
++slashCount;
const firstLen = firstPart.length;
if (firstLen > 1) {

View File

@@ -377,8 +377,8 @@ export class SmoothScrollingOperation {
private readonly _startTime: number;
public animationFrameDisposable: IDisposable | null;
private scrollLeft: IAnimation;
private scrollTop: IAnimation;
private scrollLeft!: IAnimation;
private scrollTop!: IAnimation;
protected constructor(from: ISmoothScrollPosition, to: ISmoothScrollPosition, startTime: number, duration: number) {
this.from = from;

View File

@@ -174,7 +174,7 @@ export function create(ctor: Function, ...args: any[]): any {
}
// https://stackoverflow.com/a/32235645/1499159
function isNativeClass(thing): boolean {
function isNativeClass(thing: any): boolean {
return typeof thing === 'function'
&& thing.hasOwnProperty('prototype')
&& !thing.hasOwnProperty('arguments');