WIP: bootstrap and partial real Solana watcher implementation
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
import { type KDFInput } from './utils.ts';
|
||||
export type ScryptOpts = {
|
||||
N: number;
|
||||
r: number;
|
||||
p: number;
|
||||
dkLen?: number;
|
||||
asyncTick?: number;
|
||||
maxmem?: number;
|
||||
onProgress?: (progress: number) => void;
|
||||
};
|
||||
/**
|
||||
* Scrypt KDF from RFC 7914.
|
||||
* @param password - pass
|
||||
* @param salt - salt
|
||||
* @param opts - parameters
|
||||
* - `N` is cpu/mem work factor (power of 2 e.g. 2**18)
|
||||
* - `r` is block size (8 is common), fine-tunes sequential memory read size and performance
|
||||
* - `p` is parallelization factor (1 is common)
|
||||
* - `dkLen` is output key length in bytes e.g. 32.
|
||||
* - `asyncTick` - (default: 10) max time in ms for which async function can block execution
|
||||
* - `maxmem` - (default: `1024 ** 3 + 1024` aka 1GB+1KB). A limit that the app could use for scrypt
|
||||
* - `onProgress` - callback function that would be executed for progress report
|
||||
* @returns Derived key
|
||||
* @example
|
||||
* scrypt('password', 'salt', { N: 2**18, r: 8, p: 1, dkLen: 32 });
|
||||
*/
|
||||
export declare function scrypt(password: KDFInput, salt: KDFInput, opts: ScryptOpts): Uint8Array;
|
||||
/**
|
||||
* Scrypt KDF from RFC 7914. Async version.
|
||||
* @example
|
||||
* await scryptAsync('password', 'salt', { N: 2**18, r: 8, p: 1, dkLen: 32 });
|
||||
*/
|
||||
export declare function scryptAsync(password: KDFInput, salt: KDFInput, opts: ScryptOpts): Promise<Uint8Array>;
|
||||
//# sourceMappingURL=scrypt.d.ts.map
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,56 @@
|
||||
/*! *****************************************************************************
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
||||
this file except in compliance with the License. You may obtain a copy of the
|
||||
License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
|
||||
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
||||
MERCHANTABLITY OR NON-INFRINGEMENT.
|
||||
|
||||
See the Apache Version 2.0 License for specific language governing permissions
|
||||
and limitations under the License.
|
||||
***************************************************************************** */
|
||||
|
||||
|
||||
/// <reference no-default-lib="true"/>
|
||||
|
||||
declare namespace Intl {
|
||||
interface NumberFormatOptionsUseGroupingRegistry {
|
||||
min2: never;
|
||||
auto: never;
|
||||
always: never;
|
||||
}
|
||||
|
||||
interface NumberFormatOptionsSignDisplayRegistry {
|
||||
negative: never;
|
||||
}
|
||||
|
||||
interface NumberFormatOptions {
|
||||
roundingPriority?: "auto" | "morePrecision" | "lessPrecision" | undefined;
|
||||
roundingIncrement?: 1 | 2 | 5 | 10 | 20 | 25 | 50 | 100 | 200 | 250 | 500 | 1000 | 2000 | 2500 | 5000 | undefined;
|
||||
roundingMode?: "ceil" | "floor" | "expand" | "trunc" | "halfCeil" | "halfFloor" | "halfExpand" | "halfTrunc" | "halfEven" | undefined;
|
||||
trailingZeroDisplay?: "auto" | "stripIfInteger" | undefined;
|
||||
}
|
||||
|
||||
interface ResolvedNumberFormatOptions {
|
||||
roundingPriority: "auto" | "morePrecision" | "lessPrecision";
|
||||
roundingMode: "ceil" | "floor" | "expand" | "trunc" | "halfCeil" | "halfFloor" | "halfExpand" | "halfTrunc" | "halfEven";
|
||||
roundingIncrement: 1 | 2 | 5 | 10 | 20 | 25 | 50 | 100 | 200 | 250 | 500 | 1000 | 2000 | 2500 | 5000;
|
||||
trailingZeroDisplay: "auto" | "stripIfInteger";
|
||||
}
|
||||
|
||||
interface NumberRangeFormatPart extends NumberFormatPart {
|
||||
source: "startRange" | "endRange" | "shared";
|
||||
}
|
||||
|
||||
type StringNumericLiteral = `${number}` | "Infinity" | "-Infinity" | "+Infinity";
|
||||
|
||||
interface NumberFormat {
|
||||
format(value: number | bigint | StringNumericLiteral): string;
|
||||
formatToParts(value: number | bigint | StringNumericLiteral): NumberFormatPart[];
|
||||
formatRange(start: number | bigint | StringNumericLiteral, end: number | bigint | StringNumericLiteral): string;
|
||||
formatRangeToParts(start: number | bigint | StringNumericLiteral, end: number | bigint | StringNumericLiteral): NumberRangeFormatPart[];
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 14 KiB |
@@ -0,0 +1,316 @@
|
||||
'use strict'
|
||||
|
||||
const test = require('tape')
|
||||
const concat = require('concat-stream')
|
||||
const fs = require('fs')
|
||||
const os = require('os')
|
||||
const path = require('path')
|
||||
const helpMe = require('./')
|
||||
const proxyquire = require('proxyquire')
|
||||
|
||||
test('throws if no directory is passed', function (t) {
|
||||
try {
|
||||
helpMe()
|
||||
t.fail()
|
||||
} catch (err) {
|
||||
t.equal(err.message, 'missing dir')
|
||||
}
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('throws if a normal file is passed', function (t) {
|
||||
try {
|
||||
helpMe({
|
||||
dir: __filename
|
||||
})
|
||||
t.fail()
|
||||
} catch (err) {
|
||||
t.equal(err.message, `${__filename} is not a directory`)
|
||||
}
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('throws if the directory cannot be accessed', function (t) {
|
||||
try {
|
||||
helpMe({
|
||||
dir: './foo'
|
||||
})
|
||||
t.fail()
|
||||
} catch (err) {
|
||||
t.equal(err.message, './foo is not a directory')
|
||||
}
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('show a generic help.txt from a folder to a stream with relative path in dir', function (t) {
|
||||
t.plan(2)
|
||||
|
||||
helpMe({
|
||||
dir: 'fixture/basic'
|
||||
}).createStream()
|
||||
.pipe(concat(function (data) {
|
||||
fs.readFile('fixture/basic/help.txt', function (err, expected) {
|
||||
t.error(err)
|
||||
t.equal(data.toString(), expected.toString())
|
||||
})
|
||||
}))
|
||||
})
|
||||
|
||||
test('show a generic help.txt from a folder to a stream with absolute path in dir', function (t) {
|
||||
t.plan(2)
|
||||
|
||||
helpMe({
|
||||
dir: path.join(__dirname, 'fixture/basic')
|
||||
}).createStream()
|
||||
.pipe(concat(function (data) {
|
||||
fs.readFile('fixture/basic/help.txt', function (err, expected) {
|
||||
t.error(err)
|
||||
t.equal(data.toString(), expected.toString())
|
||||
})
|
||||
}))
|
||||
})
|
||||
|
||||
test('custom help command with an array', function (t) {
|
||||
t.plan(2)
|
||||
|
||||
helpMe({
|
||||
dir: 'fixture/basic'
|
||||
}).createStream(['hello'])
|
||||
.pipe(concat(function (data) {
|
||||
fs.readFile('fixture/basic/hello.txt', function (err, expected) {
|
||||
t.error(err)
|
||||
t.equal(data.toString(), expected.toString())
|
||||
})
|
||||
}))
|
||||
})
|
||||
|
||||
test('custom help command without an ext', function (t) {
|
||||
t.plan(2)
|
||||
|
||||
helpMe({
|
||||
dir: 'fixture/no-ext',
|
||||
ext: ''
|
||||
}).createStream(['hello'])
|
||||
.pipe(concat(function (data) {
|
||||
fs.readFile('fixture/no-ext/hello', function (err, expected) {
|
||||
t.error(err)
|
||||
t.equal(data.toString(), expected.toString())
|
||||
})
|
||||
}))
|
||||
})
|
||||
|
||||
test('custom help command with a string', function (t) {
|
||||
t.plan(2)
|
||||
|
||||
helpMe({
|
||||
dir: 'fixture/basic'
|
||||
}).createStream('hello')
|
||||
.pipe(concat(function (data) {
|
||||
fs.readFile('fixture/basic/hello.txt', function (err, expected) {
|
||||
t.error(err)
|
||||
t.equal(data.toString(), expected.toString())
|
||||
})
|
||||
}))
|
||||
})
|
||||
|
||||
test('missing help file', function (t) {
|
||||
t.plan(1)
|
||||
|
||||
helpMe({
|
||||
dir: 'fixture/basic'
|
||||
}).createStream('abcde')
|
||||
.on('error', function (err) {
|
||||
t.equal(err.message, 'no such help file')
|
||||
})
|
||||
.resume()
|
||||
})
|
||||
|
||||
test('custom help command with an array', function (t) {
|
||||
const helper = helpMe({
|
||||
dir: 'fixture/shortnames'
|
||||
})
|
||||
|
||||
t.test('abbreviates two words in one', function (t) {
|
||||
t.plan(2)
|
||||
|
||||
helper
|
||||
.createStream(['world'])
|
||||
.pipe(concat(function (data) {
|
||||
fs.readFile('fixture/shortnames/hello world.txt', function (err, expected) {
|
||||
t.error(err)
|
||||
t.equal(data.toString(), expected.toString())
|
||||
})
|
||||
}))
|
||||
})
|
||||
|
||||
t.test('abbreviates three words in two', function (t) {
|
||||
t.plan(2)
|
||||
|
||||
helper
|
||||
.createStream(['abcde', 'fghi'])
|
||||
.pipe(concat(function (data) {
|
||||
fs.readFile('fixture/shortnames/abcde fghi lmno.txt', function (err, expected) {
|
||||
t.error(err)
|
||||
t.equal(data.toString(), expected.toString())
|
||||
})
|
||||
}))
|
||||
})
|
||||
|
||||
t.test('abbreviates a word', function (t) {
|
||||
t.plan(2)
|
||||
|
||||
helper
|
||||
.createStream(['abc', 'fg'])
|
||||
.pipe(concat(function (data) {
|
||||
fs.readFile('fixture/shortnames/abcde fghi lmno.txt', function (err, expected) {
|
||||
t.error(err)
|
||||
t.equal(data.toString(), expected.toString())
|
||||
})
|
||||
}))
|
||||
})
|
||||
|
||||
t.test('abbreviates a word using strings', function (t) {
|
||||
t.plan(2)
|
||||
|
||||
helper
|
||||
.createStream('abc fg')
|
||||
.pipe(concat(function (data) {
|
||||
fs.readFile('fixture/shortnames/abcde fghi lmno.txt', function (err, expected) {
|
||||
t.error(err)
|
||||
t.equal(data.toString(), expected.toString())
|
||||
})
|
||||
}))
|
||||
})
|
||||
|
||||
t.test('print a disambiguation', function (t) {
|
||||
t.plan(1)
|
||||
|
||||
const expected = '' +
|
||||
'There are 2 help pages that matches the given request, please disambiguate:\n' +
|
||||
' * abcde fghi lmno\n' +
|
||||
' * abcde hello\n'
|
||||
|
||||
helper
|
||||
.createStream(['abc'])
|
||||
.pipe(concat({ encoding: 'string' }, function (data) {
|
||||
t.equal(data, expected)
|
||||
}))
|
||||
})
|
||||
|
||||
t.test('choose exact match over partial', function (t) {
|
||||
t.plan(1)
|
||||
|
||||
helpMe({
|
||||
dir: 'fixture/sameprefix'
|
||||
}).createStream(['hello'])
|
||||
.pipe(concat({ encoding: 'string' }, function (data) {
|
||||
t.equal(data, 'hello')
|
||||
}))
|
||||
})
|
||||
})
|
||||
|
||||
test('toStdout helper', async function (t) {
|
||||
t.plan(2)
|
||||
|
||||
let completed = false
|
||||
const stream = concat(function (data) {
|
||||
completed = true
|
||||
fs.readFile('fixture/basic/help.txt', function (err, expected) {
|
||||
t.error(err)
|
||||
t.equal(data.toString(), expected.toString())
|
||||
})
|
||||
})
|
||||
|
||||
await helpMe({
|
||||
dir: 'fixture/basic'
|
||||
}).toStdout([], { stream })
|
||||
|
||||
t.ok(completed)
|
||||
})
|
||||
|
||||
test('handle error in toStdout', async function (t) {
|
||||
t.plan(2)
|
||||
|
||||
let completed = false
|
||||
const stream = concat(function (data) {
|
||||
completed = true
|
||||
fs.readFile('fixture/basic/help.txt', function (err, expected) {
|
||||
t.error(err)
|
||||
t.equal(data.toString(), 'no such help file: something.\n\n' + expected.toString())
|
||||
})
|
||||
})
|
||||
|
||||
await helpMe({
|
||||
dir: 'fixture/basic'
|
||||
}).toStdout(['something'], {
|
||||
stream
|
||||
})
|
||||
|
||||
t.ok(completed)
|
||||
})
|
||||
|
||||
test('customize missing help fle message', async function (t) {
|
||||
t.plan(3)
|
||||
|
||||
const stream = concat(function (data) {
|
||||
t.equal(data.toString(), 'kaboom\n\n')
|
||||
})
|
||||
|
||||
await helpMe({
|
||||
dir: 'fixture/basic'
|
||||
}).toStdout(['something'], {
|
||||
stream,
|
||||
async onMissingHelp (err, args, stream) {
|
||||
t.equal(err.message, 'no such help file')
|
||||
t.deepEquals(args, ['something'])
|
||||
stream.end('kaboom\n\n')
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
test('toStdout without factory', async function (t) {
|
||||
t.plan(2)
|
||||
|
||||
let completed = false
|
||||
const stream = concat(function (data) {
|
||||
completed = true
|
||||
fs.readFile('fixture/basic/help.txt', function (err, expected) {
|
||||
t.error(err)
|
||||
t.equal(data.toString(), expected.toString())
|
||||
})
|
||||
})
|
||||
|
||||
await helpMe.help({
|
||||
dir: 'fixture/basic',
|
||||
stream
|
||||
}, [])
|
||||
|
||||
t.ok(completed)
|
||||
})
|
||||
|
||||
test('should allow for awaiting the response with default stdout stream', async function (t) {
|
||||
t.plan(2)
|
||||
|
||||
const _process = Object.create(process)
|
||||
const stdout = Object.create(process.stdout)
|
||||
Object.defineProperty(_process, 'stdout', {
|
||||
value: stdout
|
||||
})
|
||||
|
||||
let completed = false
|
||||
stdout.write = (data, cb) => {
|
||||
t.equal(data.toString(), 'hello world' + os.EOL)
|
||||
completed = true
|
||||
cb()
|
||||
}
|
||||
|
||||
const helpMe = proxyquire('./help-me', {
|
||||
process: _process
|
||||
})
|
||||
|
||||
await helpMe.help({
|
||||
dir: 'fixture/basic'
|
||||
})
|
||||
|
||||
t.ok(completed)
|
||||
})
|
||||
@@ -0,0 +1,14 @@
|
||||
import type { TypeOrValueSpecifier } from '../util';
|
||||
export type Options = [
|
||||
{
|
||||
allow?: TypeOrValueSpecifier[];
|
||||
checkParameterProperties?: boolean;
|
||||
ignoreInferredTypes?: boolean;
|
||||
treatMethodsAsReadonly?: boolean;
|
||||
}
|
||||
];
|
||||
export type MessageIds = 'shouldBeReadonly';
|
||||
declare const _default: import("@typescript-eslint/utils/ts-eslint").RuleModule<"shouldBeReadonly", Options, import("../../rules").ESLintPluginDocs, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
|
||||
name: string;
|
||||
};
|
||||
export default _default;
|
||||
@@ -0,0 +1,5 @@
|
||||
export declare enum LanguageVariant {
|
||||
Standard = 0,
|
||||
JSX = 1
|
||||
}
|
||||
//# sourceMappingURL=languageVariant.enum.d.ts.map
|
||||
@@ -0,0 +1,61 @@
|
||||
"use strict";
|
||||
// Zod 3 compat layer
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.ZodFirstPartyTypeKind = exports.config = exports.$brand = exports.ZodIssueCode = void 0;
|
||||
exports.setErrorMap = setErrorMap;
|
||||
exports.getErrorMap = getErrorMap;
|
||||
const core = __importStar(require("../core/index.cjs"));
|
||||
/** @deprecated Use the raw string literal codes instead, e.g. "invalid_type". */
|
||||
exports.ZodIssueCode = {
|
||||
invalid_type: "invalid_type",
|
||||
too_big: "too_big",
|
||||
too_small: "too_small",
|
||||
invalid_format: "invalid_format",
|
||||
not_multiple_of: "not_multiple_of",
|
||||
unrecognized_keys: "unrecognized_keys",
|
||||
invalid_union: "invalid_union",
|
||||
invalid_key: "invalid_key",
|
||||
invalid_element: "invalid_element",
|
||||
invalid_value: "invalid_value",
|
||||
custom: "custom",
|
||||
};
|
||||
var index_js_1 = require("../core/index.cjs");
|
||||
Object.defineProperty(exports, "$brand", { enumerable: true, get: function () { return index_js_1.$brand; } });
|
||||
Object.defineProperty(exports, "config", { enumerable: true, get: function () { return index_js_1.config; } });
|
||||
/** @deprecated Use `z.config(params)` instead. */
|
||||
function setErrorMap(map) {
|
||||
core.config({
|
||||
customError: map,
|
||||
});
|
||||
}
|
||||
/** @deprecated Use `z.config()` instead. */
|
||||
function getErrorMap() {
|
||||
return core.config().customError;
|
||||
}
|
||||
/** @deprecated Do not use. Stub definition, only included for zod-to-json-schema compatibility. */
|
||||
var ZodFirstPartyTypeKind;
|
||||
(function (ZodFirstPartyTypeKind) {
|
||||
})(ZodFirstPartyTypeKind || (exports.ZodFirstPartyTypeKind = ZodFirstPartyTypeKind = {}));
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,117 @@
|
||||
/**
|
||||
* License for programmatically and manually incorporated
|
||||
* documentation aka. `JSDoc` from https://github.com/nodejs/node/tree/master/doc
|
||||
*
|
||||
* Copyright Node.js contributors. All rights reserved.
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to
|
||||
* deal in the Software without restriction, including without limitation the
|
||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
* sell copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
* IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
// NOTE: These definitions support Node.js and TypeScript 5.7.
|
||||
|
||||
// Reference required TypeScript libraries:
|
||||
/// <reference lib="es2020" />
|
||||
/// <reference lib="esnext.disposable" />
|
||||
|
||||
// TypeScript library polyfills required for TypeScript 5.7:
|
||||
/// <reference path="./compatibility/float16array.d.ts" />
|
||||
|
||||
// Definitions for Node.js modules specific to TypeScript 5.7+:
|
||||
/// <reference path="../globals.typedarray.d.ts" />
|
||||
/// <reference path="../buffer.buffer.d.ts" />
|
||||
|
||||
// Definitions for Node.js modules that are not specific to any version of TypeScript:
|
||||
/// <reference path="../globals.d.ts" />
|
||||
/// <reference path="../web-globals/abortcontroller.d.ts" />
|
||||
/// <reference path="../web-globals/blob.d.ts" />
|
||||
/// <reference path="../web-globals/console.d.ts" />
|
||||
/// <reference path="../web-globals/crypto.d.ts" />
|
||||
/// <reference path="../web-globals/domexception.d.ts" />
|
||||
/// <reference path="../web-globals/encoding.d.ts" />
|
||||
/// <reference path="../web-globals/events.d.ts" />
|
||||
/// <reference path="../web-globals/fetch.d.ts" />
|
||||
/// <reference path="../web-globals/importmeta.d.ts" />
|
||||
/// <reference path="../web-globals/messaging.d.ts" />
|
||||
/// <reference path="../web-globals/navigator.d.ts" />
|
||||
/// <reference path="../web-globals/performance.d.ts" />
|
||||
/// <reference path="../web-globals/storage.d.ts" />
|
||||
/// <reference path="../web-globals/streams.d.ts" />
|
||||
/// <reference path="../web-globals/timers.d.ts" />
|
||||
/// <reference path="../web-globals/url.d.ts" />
|
||||
/// <reference path="../assert.d.ts" />
|
||||
/// <reference path="../assert/strict.d.ts" />
|
||||
/// <reference path="../async_hooks.d.ts" />
|
||||
/// <reference path="../buffer.d.ts" />
|
||||
/// <reference path="../child_process.d.ts" />
|
||||
/// <reference path="../cluster.d.ts" />
|
||||
/// <reference path="../console.d.ts" />
|
||||
/// <reference path="../constants.d.ts" />
|
||||
/// <reference path="../crypto.d.ts" />
|
||||
/// <reference path="../dgram.d.ts" />
|
||||
/// <reference path="../diagnostics_channel.d.ts" />
|
||||
/// <reference path="../dns.d.ts" />
|
||||
/// <reference path="../dns/promises.d.ts" />
|
||||
/// <reference path="../domain.d.ts" />
|
||||
/// <reference path="../events.d.ts" />
|
||||
/// <reference path="../ffi.d.ts" />
|
||||
/// <reference path="../fs.d.ts" />
|
||||
/// <reference path="../fs/promises.d.ts" />
|
||||
/// <reference path="../http.d.ts" />
|
||||
/// <reference path="../http2.d.ts" />
|
||||
/// <reference path="../https.d.ts" />
|
||||
/// <reference path="../inspector.d.ts" />
|
||||
/// <reference path="../inspector.generated.d.ts" />
|
||||
/// <reference path="../inspector/promises.d.ts" />
|
||||
/// <reference path="../module.d.ts" />
|
||||
/// <reference path="../net.d.ts" />
|
||||
/// <reference path="../os.d.ts" />
|
||||
/// <reference path="../path.d.ts" />
|
||||
/// <reference path="../path/posix.d.ts" />
|
||||
/// <reference path="../path/win32.d.ts" />
|
||||
/// <reference path="../perf_hooks.d.ts" />
|
||||
/// <reference path="../process.d.ts" />
|
||||
/// <reference path="../punycode.d.ts" />
|
||||
/// <reference path="../querystring.d.ts" />
|
||||
/// <reference path="../quic.d.ts" />
|
||||
/// <reference path="../readline.d.ts" />
|
||||
/// <reference path="../readline/promises.d.ts" />
|
||||
/// <reference path="../repl.d.ts" />
|
||||
/// <reference path="../sea.d.ts" />
|
||||
/// <reference path="../sqlite.d.ts" />
|
||||
/// <reference path="../stream.d.ts" />
|
||||
/// <reference path="../stream/consumers.d.ts" />
|
||||
/// <reference path="../stream/iter.d.ts" />
|
||||
/// <reference path="../stream/promises.d.ts" />
|
||||
/// <reference path="../stream/web.d.ts" />
|
||||
/// <reference path="../string_decoder.d.ts" />
|
||||
/// <reference path="../test.d.ts" />
|
||||
/// <reference path="../test/reporters.d.ts" />
|
||||
/// <reference path="../timers.d.ts" />
|
||||
/// <reference path="../timers/promises.d.ts" />
|
||||
/// <reference path="../tls.d.ts" />
|
||||
/// <reference path="../trace_events.d.ts" />
|
||||
/// <reference path="../tty.d.ts" />
|
||||
/// <reference path="../url.d.ts" />
|
||||
/// <reference path="../util.d.ts" />
|
||||
/// <reference path="../util/types.d.ts" />
|
||||
/// <reference path="../v8.d.ts" />
|
||||
/// <reference path="../vm.d.ts" />
|
||||
/// <reference path="../wasi.d.ts" />
|
||||
/// <reference path="../worker_threads.d.ts" />
|
||||
/// <reference path="../zlib.d.ts" />
|
||||
/// <reference path="../zlib/iter.d.ts" />
|
||||
@@ -0,0 +1,5 @@
|
||||
'use strict';
|
||||
|
||||
// do NOT remove this file - it would break pre-compiled schemas
|
||||
// https://github.com/ajv-validator/ajv/issues/889
|
||||
module.exports = require('fast-deep-equal');
|
||||
@@ -0,0 +1,16 @@
|
||||
/**
|
||||
* NIST secp256r1 aka p256.
|
||||
* @module
|
||||
*/
|
||||
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
||||
import {} from "./abstract/hash-to-curve.js";
|
||||
import { p256_hasher, p256 as p256n } from "./nist.js";
|
||||
/** @deprecated use `import { p256 } from '@noble/curves/nist.js';` */
|
||||
export const p256 = p256n;
|
||||
/** @deprecated use `import { p256 } from '@noble/curves/nist.js';` */
|
||||
export const secp256r1 = p256n;
|
||||
/** @deprecated use `import { p256_hasher } from '@noble/curves/nist.js';` */
|
||||
export const hashToCurve = /* @__PURE__ */ (() => p256_hasher.hashToCurve)();
|
||||
/** @deprecated use `import { p256_hasher } from '@noble/curves/nist.js';` */
|
||||
export const encodeToCurve = /* @__PURE__ */ (() => p256_hasher.encodeToCurve)();
|
||||
//# sourceMappingURL=p256.js.map
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"main": "../../cjs/_get.cjs",
|
||||
"module": "../../esm/_get.js"
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
const singleComment = Symbol('singleComment');
|
||||
const multiComment = Symbol('multiComment');
|
||||
|
||||
const stripWithoutWhitespace = () => '';
|
||||
|
||||
// Replace all characters except ASCII spaces, tabs and line endings with regular spaces to ensure valid JSON output.
|
||||
const stripWithWhitespace = (string, start, end) => string.slice(start, end).replace(/[^ \t\r\n]/g, ' ');
|
||||
|
||||
const isEscaped = (jsonString, quotePosition) => {
|
||||
let index = quotePosition - 1;
|
||||
let backslashCount = 0;
|
||||
|
||||
while (jsonString[index] === '\\') {
|
||||
index -= 1;
|
||||
backslashCount += 1;
|
||||
}
|
||||
|
||||
return Boolean(backslashCount % 2);
|
||||
};
|
||||
|
||||
export default function stripJsonComments(jsonString, {whitespace = true, trailingCommas = false} = {}) {
|
||||
if (typeof jsonString !== 'string') {
|
||||
throw new TypeError(`Expected argument \`jsonString\` to be a \`string\`, got \`${typeof jsonString}\``);
|
||||
}
|
||||
|
||||
const strip = whitespace ? stripWithWhitespace : stripWithoutWhitespace;
|
||||
|
||||
let isInsideString = false;
|
||||
let isInsideComment = false;
|
||||
let offset = 0;
|
||||
let buffer = '';
|
||||
let result = '';
|
||||
let commaIndex = -1;
|
||||
|
||||
for (let index = 0; index < jsonString.length; index++) {
|
||||
const currentCharacter = jsonString[index];
|
||||
const nextCharacter = jsonString[index + 1];
|
||||
|
||||
if (!isInsideComment && currentCharacter === '"') {
|
||||
// Enter or exit string
|
||||
const escaped = isEscaped(jsonString, index);
|
||||
if (!escaped) {
|
||||
isInsideString = !isInsideString;
|
||||
}
|
||||
}
|
||||
|
||||
if (isInsideString) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!isInsideComment && currentCharacter + nextCharacter === '//') {
|
||||
// Enter single-line comment
|
||||
buffer += jsonString.slice(offset, index);
|
||||
offset = index;
|
||||
isInsideComment = singleComment;
|
||||
index++;
|
||||
} else if (isInsideComment === singleComment && currentCharacter + nextCharacter === '\r\n') {
|
||||
// Exit single-line comment via \r\n
|
||||
index++;
|
||||
isInsideComment = false;
|
||||
buffer += strip(jsonString, offset, index);
|
||||
offset = index;
|
||||
continue;
|
||||
} else if (isInsideComment === singleComment && currentCharacter === '\n') {
|
||||
// Exit single-line comment via \n
|
||||
isInsideComment = false;
|
||||
buffer += strip(jsonString, offset, index);
|
||||
offset = index;
|
||||
} else if (!isInsideComment && currentCharacter + nextCharacter === '/*') {
|
||||
// Enter multiline comment
|
||||
buffer += jsonString.slice(offset, index);
|
||||
offset = index;
|
||||
isInsideComment = multiComment;
|
||||
index++;
|
||||
continue;
|
||||
} else if (isInsideComment === multiComment && currentCharacter + nextCharacter === '*/') {
|
||||
// Exit multiline comment
|
||||
index++;
|
||||
isInsideComment = false;
|
||||
buffer += strip(jsonString, offset, index + 1);
|
||||
offset = index + 1;
|
||||
continue;
|
||||
} else if (trailingCommas && !isInsideComment) {
|
||||
if (commaIndex !== -1) {
|
||||
if (currentCharacter === '}' || currentCharacter === ']') {
|
||||
// Strip trailing comma
|
||||
buffer += jsonString.slice(offset, index);
|
||||
result += strip(buffer, 0, 1) + buffer.slice(1);
|
||||
buffer = '';
|
||||
offset = index;
|
||||
commaIndex = -1;
|
||||
} else if (currentCharacter !== ' ' && currentCharacter !== '\t' && currentCharacter !== '\r' && currentCharacter !== '\n') {
|
||||
// Hit non-whitespace following a comma; comma is not trailing
|
||||
buffer += jsonString.slice(offset, index);
|
||||
offset = index;
|
||||
commaIndex = -1;
|
||||
}
|
||||
} else if (currentCharacter === ',') {
|
||||
// Flush buffer prior to this point, and save new comma index
|
||||
result += buffer + jsonString.slice(offset, index);
|
||||
buffer = '';
|
||||
offset = index;
|
||||
commaIndex = index;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const remaining = (isInsideComment === singleComment)
|
||||
? strip(jsonString, offset)
|
||||
: jsonString.slice(offset);
|
||||
|
||||
return result + buffer + remaining;
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,30 @@
|
||||
import validate from './validate.js';
|
||||
/**
|
||||
* Convert array of 16 byte values to UUID string format of the form:
|
||||
* XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
|
||||
*/
|
||||
|
||||
var byteToHex = [];
|
||||
|
||||
for (var i = 0; i < 256; ++i) {
|
||||
byteToHex.push((i + 0x100).toString(16).substr(1));
|
||||
}
|
||||
|
||||
function stringify(arr) {
|
||||
var offset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
||||
// Note: Be careful editing this code! It's been tuned for performance
|
||||
// and works in ways you may not expect. See https://github.com/uuidjs/uuid/pull/434
|
||||
var uuid = (byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + '-' + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + '-' + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + '-' + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + '-' + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]]).toLowerCase(); // Consistency check for valid UUID. If this throws, it's likely due to one
|
||||
// of the following:
|
||||
// - One or more input array values don't map to a hex octet (leading to
|
||||
// "undefined" in the uuid)
|
||||
// - Invalid input values for the RFC `version` or `variant` fields
|
||||
|
||||
if (!validate(uuid)) {
|
||||
throw TypeError('Stringified UUID is invalid');
|
||||
}
|
||||
|
||||
return uuid;
|
||||
}
|
||||
|
||||
export default stringify;
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,803 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || (function () {
|
||||
var ownKeys = function(o) {
|
||||
ownKeys = Object.getOwnPropertyNames || function (o) {
|
||||
var ar = [];
|
||||
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
||||
return ar;
|
||||
};
|
||||
return ownKeys(o);
|
||||
};
|
||||
return function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
})();
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const utils_1 = require("@typescript-eslint/utils");
|
||||
const tsutils = __importStar(require("ts-api-utils"));
|
||||
const ts = __importStar(require("typescript"));
|
||||
const util_1 = require("../util");
|
||||
const promiseUtils_1 = require("../util/promiseUtils");
|
||||
function parseChecksVoidReturn(checksVoidReturn) {
|
||||
switch (checksVoidReturn) {
|
||||
case false:
|
||||
return false;
|
||||
case true:
|
||||
case undefined:
|
||||
return {
|
||||
arguments: true,
|
||||
attributes: true,
|
||||
inheritedMethods: true,
|
||||
properties: true,
|
||||
returns: true,
|
||||
variables: true,
|
||||
};
|
||||
default:
|
||||
return {
|
||||
arguments: checksVoidReturn.arguments ?? true,
|
||||
attributes: checksVoidReturn.attributes ?? true,
|
||||
inheritedMethods: checksVoidReturn.inheritedMethods ?? true,
|
||||
properties: checksVoidReturn.properties ?? true,
|
||||
returns: checksVoidReturn.returns ?? true,
|
||||
variables: checksVoidReturn.variables ?? true,
|
||||
};
|
||||
}
|
||||
}
|
||||
exports.default = (0, util_1.createRule)({
|
||||
name: 'no-misused-promises',
|
||||
meta: {
|
||||
type: 'problem',
|
||||
docs: {
|
||||
description: 'Disallow Promises in places not designed to handle them',
|
||||
recommended: 'recommended',
|
||||
requiresTypeChecking: true,
|
||||
},
|
||||
messages: {
|
||||
conditional: 'Expected non-Promise value in a boolean conditional.',
|
||||
predicate: 'Expected a non-Promise value to be returned.',
|
||||
spread: 'Expected a non-Promise value to be spread in an object.',
|
||||
voidReturnArgument: 'Promise returned in function argument where a void return was expected.',
|
||||
voidReturnAttribute: 'Promise-returning function provided to attribute where a void return was expected.',
|
||||
voidReturnInheritedMethod: "Promise-returning method provided where a void return was expected by extended/implemented type '{{ heritageTypeName }}'.",
|
||||
voidReturnProperty: 'Promise-returning function provided to property where a void return was expected.',
|
||||
voidReturnReturnValue: 'Promise-returning function provided to return value where a void return was expected.',
|
||||
voidReturnVariable: 'Promise-returning function provided to variable where a void return was expected.',
|
||||
},
|
||||
schema: [
|
||||
{
|
||||
type: 'object',
|
||||
additionalProperties: false,
|
||||
properties: {
|
||||
checksConditionals: {
|
||||
type: 'boolean',
|
||||
description: 'Whether to warn when a Promise is provided to conditional statements.',
|
||||
},
|
||||
checksSpreads: {
|
||||
type: 'boolean',
|
||||
description: 'Whether to warn when `...` spreading a `Promise`.',
|
||||
},
|
||||
checksVoidReturn: {
|
||||
description: 'Whether to warn when a Promise is returned from a function typed as returning `void`.',
|
||||
oneOf: [
|
||||
{
|
||||
type: 'boolean',
|
||||
description: 'Whether to disable checking all asynchronous functions.',
|
||||
},
|
||||
{
|
||||
type: 'object',
|
||||
additionalProperties: false,
|
||||
description: 'Which forms of functions may have checking disabled.',
|
||||
properties: {
|
||||
arguments: {
|
||||
type: 'boolean',
|
||||
description: 'Disables checking an asynchronous function passed as argument where the parameter type expects a function that returns `void`.',
|
||||
},
|
||||
attributes: {
|
||||
type: 'boolean',
|
||||
description: 'Disables checking an asynchronous function passed as a JSX attribute expected to be a function that returns `void`.',
|
||||
},
|
||||
inheritedMethods: {
|
||||
type: 'boolean',
|
||||
description: 'Disables checking an asynchronous method in a type that extends or implements another type expecting that method to return `void`.',
|
||||
},
|
||||
properties: {
|
||||
type: 'boolean',
|
||||
description: 'Disables checking an asynchronous function passed as an object property expected to be a function that returns `void`.',
|
||||
},
|
||||
returns: {
|
||||
type: 'boolean',
|
||||
description: 'Disables checking an asynchronous function returned in a function whose return type is a function that returns `void`.',
|
||||
},
|
||||
variables: {
|
||||
type: 'boolean',
|
||||
description: 'Disables checking an asynchronous function used as a variable whose return type is a function that returns `void`.',
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
defaultOptions: [
|
||||
{
|
||||
checksConditionals: true,
|
||||
checksSpreads: true,
|
||||
checksVoidReturn: true,
|
||||
},
|
||||
],
|
||||
create(context, [{ checksConditionals, checksSpreads, checksVoidReturn }]) {
|
||||
const services = (0, util_1.getParserServices)(context);
|
||||
const checker = services.program.getTypeChecker();
|
||||
const checkedNodes = new Set();
|
||||
const conditionalChecks = {
|
||||
'CallExpression > MemberExpression': checkArrayPredicates,
|
||||
ConditionalExpression: checkTestConditional,
|
||||
DoWhileStatement: checkTestConditional,
|
||||
ForStatement: checkTestConditional,
|
||||
IfStatement: checkTestConditional,
|
||||
LogicalExpression: checkConditional,
|
||||
'UnaryExpression[operator="!"]'(node) {
|
||||
checkConditional(node.argument, true);
|
||||
},
|
||||
WhileStatement: checkTestConditional,
|
||||
};
|
||||
checksVoidReturn = parseChecksVoidReturn(checksVoidReturn);
|
||||
const voidReturnChecks = checksVoidReturn
|
||||
? {
|
||||
...(checksVoidReturn.arguments && {
|
||||
CallExpression: checkArguments,
|
||||
NewExpression: checkArguments,
|
||||
}),
|
||||
...(checksVoidReturn.attributes && {
|
||||
JSXAttribute: checkJSXAttribute,
|
||||
}),
|
||||
...(checksVoidReturn.inheritedMethods && {
|
||||
ClassDeclaration: checkClassLikeOrInterfaceNode,
|
||||
ClassExpression: checkClassLikeOrInterfaceNode,
|
||||
TSInterfaceDeclaration: checkClassLikeOrInterfaceNode,
|
||||
}),
|
||||
...(checksVoidReturn.properties && {
|
||||
Property: checkProperty,
|
||||
}),
|
||||
...(checksVoidReturn.returns && {
|
||||
ReturnStatement: checkReturnStatement,
|
||||
}),
|
||||
...(checksVoidReturn.variables && {
|
||||
AssignmentExpression: checkAssignment,
|
||||
VariableDeclarator: checkVariableDeclaration,
|
||||
}),
|
||||
}
|
||||
: {};
|
||||
const spreadChecks = {
|
||||
SpreadElement: checkSpread,
|
||||
};
|
||||
/**
|
||||
* A syntactic check to see if an annotated type is maybe a function type.
|
||||
* This is a perf optimization to help avoid requesting types where possible
|
||||
*/
|
||||
function isPossiblyFunctionType(node) {
|
||||
switch (node.typeAnnotation.type) {
|
||||
case utils_1.AST_NODE_TYPES.TSConditionalType:
|
||||
case utils_1.AST_NODE_TYPES.TSConstructorType:
|
||||
case utils_1.AST_NODE_TYPES.TSFunctionType:
|
||||
case utils_1.AST_NODE_TYPES.TSImportType:
|
||||
case utils_1.AST_NODE_TYPES.TSIndexedAccessType:
|
||||
case utils_1.AST_NODE_TYPES.TSInferType:
|
||||
case utils_1.AST_NODE_TYPES.TSIntersectionType:
|
||||
case utils_1.AST_NODE_TYPES.TSQualifiedName:
|
||||
case utils_1.AST_NODE_TYPES.TSThisType:
|
||||
case utils_1.AST_NODE_TYPES.TSTypeOperator:
|
||||
case utils_1.AST_NODE_TYPES.TSTypeQuery:
|
||||
case utils_1.AST_NODE_TYPES.TSTypeReference:
|
||||
case utils_1.AST_NODE_TYPES.TSUnionType:
|
||||
return true;
|
||||
case utils_1.AST_NODE_TYPES.TSTypeLiteral:
|
||||
return node.typeAnnotation.members.some(member => member.type === utils_1.AST_NODE_TYPES.TSCallSignatureDeclaration ||
|
||||
member.type === utils_1.AST_NODE_TYPES.TSConstructSignatureDeclaration);
|
||||
case utils_1.AST_NODE_TYPES.TSAbstractKeyword:
|
||||
case utils_1.AST_NODE_TYPES.TSAnyKeyword:
|
||||
case utils_1.AST_NODE_TYPES.TSArrayType:
|
||||
case utils_1.AST_NODE_TYPES.TSAsyncKeyword:
|
||||
case utils_1.AST_NODE_TYPES.TSBigIntKeyword:
|
||||
case utils_1.AST_NODE_TYPES.TSBooleanKeyword:
|
||||
case utils_1.AST_NODE_TYPES.TSDeclareKeyword:
|
||||
case utils_1.AST_NODE_TYPES.TSExportKeyword:
|
||||
case utils_1.AST_NODE_TYPES.TSIntrinsicKeyword:
|
||||
case utils_1.AST_NODE_TYPES.TSLiteralType:
|
||||
case utils_1.AST_NODE_TYPES.TSMappedType:
|
||||
case utils_1.AST_NODE_TYPES.TSNamedTupleMember:
|
||||
case utils_1.AST_NODE_TYPES.TSNeverKeyword:
|
||||
case utils_1.AST_NODE_TYPES.TSNullKeyword:
|
||||
case utils_1.AST_NODE_TYPES.TSNumberKeyword:
|
||||
case utils_1.AST_NODE_TYPES.TSObjectKeyword:
|
||||
case utils_1.AST_NODE_TYPES.TSOptionalType:
|
||||
case utils_1.AST_NODE_TYPES.TSPrivateKeyword:
|
||||
case utils_1.AST_NODE_TYPES.TSProtectedKeyword:
|
||||
case utils_1.AST_NODE_TYPES.TSPublicKeyword:
|
||||
case utils_1.AST_NODE_TYPES.TSReadonlyKeyword:
|
||||
case utils_1.AST_NODE_TYPES.TSRestType:
|
||||
case utils_1.AST_NODE_TYPES.TSStaticKeyword:
|
||||
case utils_1.AST_NODE_TYPES.TSStringKeyword:
|
||||
case utils_1.AST_NODE_TYPES.TSSymbolKeyword:
|
||||
case utils_1.AST_NODE_TYPES.TSTemplateLiteralType:
|
||||
case utils_1.AST_NODE_TYPES.TSTupleType:
|
||||
case utils_1.AST_NODE_TYPES.TSTypePredicate:
|
||||
case utils_1.AST_NODE_TYPES.TSUndefinedKeyword:
|
||||
case utils_1.AST_NODE_TYPES.TSUnknownKeyword:
|
||||
case utils_1.AST_NODE_TYPES.TSVoidKeyword:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
function checkTestConditional(node) {
|
||||
if (node.test) {
|
||||
checkConditional(node.test, true);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* This function analyzes the type of a node and checks if it is a Promise in a boolean conditional.
|
||||
* It uses recursion when checking nested logical operators.
|
||||
* @param node The AST node to check.
|
||||
* @param isTestExpr Whether the node is a descendant of a test expression.
|
||||
*/
|
||||
function checkConditional(node, isTestExpr = false) {
|
||||
// prevent checking the same node multiple times
|
||||
if (checkedNodes.has(node)) {
|
||||
return;
|
||||
}
|
||||
checkedNodes.add(node);
|
||||
if (node.type === utils_1.AST_NODE_TYPES.LogicalExpression) {
|
||||
// ignore the left operand for nullish coalescing expressions not in a context of a test expression
|
||||
if (node.operator !== '??' || isTestExpr) {
|
||||
checkConditional(node.left, isTestExpr);
|
||||
}
|
||||
// we ignore the right operand when not in a context of a test expression
|
||||
if (isTestExpr) {
|
||||
checkConditional(node.right, isTestExpr);
|
||||
}
|
||||
return;
|
||||
}
|
||||
const tsNode = services.esTreeNodeToTSNodeMap.get(node);
|
||||
if (isAlwaysThenable(checker, tsNode)) {
|
||||
context.report({
|
||||
node,
|
||||
messageId: 'conditional',
|
||||
});
|
||||
}
|
||||
}
|
||||
function checkArrayPredicates(node) {
|
||||
const parent = node.parent;
|
||||
if (parent.type === utils_1.AST_NODE_TYPES.CallExpression) {
|
||||
const callback = parent.arguments.at(0);
|
||||
if (callback &&
|
||||
(0, util_1.isArrayMethodCallWithPredicate)(context, services, parent)) {
|
||||
const type = services.esTreeNodeToTSNodeMap.get(callback);
|
||||
if (returnsThenable(checker, type)) {
|
||||
context.report({
|
||||
node: callback,
|
||||
messageId: 'predicate',
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
function checkArguments(node) {
|
||||
if (node.type === utils_1.AST_NODE_TYPES.CallExpression &&
|
||||
isPromiseFinallyMethod(node)) {
|
||||
return;
|
||||
}
|
||||
const tsNode = services.esTreeNodeToTSNodeMap.get(node);
|
||||
const voidArgs = voidFunctionArguments(checker, tsNode);
|
||||
if (voidArgs.size === 0) {
|
||||
return;
|
||||
}
|
||||
for (const [index, argument] of node.arguments.entries()) {
|
||||
if (!voidArgs.has(index)) {
|
||||
continue;
|
||||
}
|
||||
const tsNode = services.esTreeNodeToTSNodeMap.get(argument);
|
||||
if (returnsThenable(checker, tsNode)) {
|
||||
context.report({
|
||||
node: argument,
|
||||
messageId: 'voidReturnArgument',
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
function checkAssignment(node) {
|
||||
const tsNode = services.esTreeNodeToTSNodeMap.get(node);
|
||||
const varType = services.getTypeAtLocation(node.left);
|
||||
if (!isVoidReturningFunctionType(checker, tsNode.left, varType)) {
|
||||
return;
|
||||
}
|
||||
if (returnsThenable(checker, tsNode.right)) {
|
||||
context.report({
|
||||
node: node.right,
|
||||
messageId: 'voidReturnVariable',
|
||||
});
|
||||
}
|
||||
}
|
||||
function checkVariableDeclaration(node) {
|
||||
const tsNode = services.esTreeNodeToTSNodeMap.get(node);
|
||||
if (tsNode.initializer == null || node.init == null) {
|
||||
return;
|
||||
}
|
||||
if (node.parent.kind === 'using' &&
|
||||
hasWellKnownSymbolWithThenableReturn(checker, tsNode.initializer, checker.getTypeAtLocation(tsNode.initializer), 'dispose')) {
|
||||
context.report({
|
||||
node: node.init,
|
||||
messageId: 'voidReturnVariable',
|
||||
});
|
||||
}
|
||||
if (node.id.typeAnnotation == null) {
|
||||
return;
|
||||
}
|
||||
const variableType = services.getTypeAtLocation(node.id);
|
||||
if (hasWellKnownSymbolWithVoidReturn(checker, tsNode.name, variableType, 'dispose') &&
|
||||
hasWellKnownSymbolWithThenableReturn(checker, tsNode.initializer, checker.getTypeAtLocation(tsNode.initializer), 'dispose')) {
|
||||
context.report({
|
||||
node: node.init,
|
||||
messageId: 'voidReturnVariable',
|
||||
});
|
||||
}
|
||||
// syntactically ignore some known-good cases to avoid touching type info
|
||||
if (!isPossiblyFunctionType(node.id.typeAnnotation)) {
|
||||
return;
|
||||
}
|
||||
const varType = services.getTypeAtLocation(node.id);
|
||||
if (!isVoidReturningFunctionType(checker, tsNode.initializer, varType)) {
|
||||
return;
|
||||
}
|
||||
if (returnsThenable(checker, tsNode.initializer)) {
|
||||
context.report({
|
||||
node: node.init,
|
||||
messageId: 'voidReturnVariable',
|
||||
});
|
||||
}
|
||||
}
|
||||
function checkProperty(node) {
|
||||
const tsNode = services.esTreeNodeToTSNodeMap.get(node);
|
||||
if (ts.isPropertyAssignment(tsNode)) {
|
||||
const contextualType = checker.getContextualType(tsNode.initializer);
|
||||
if (contextualType != null &&
|
||||
isVoidReturningFunctionType(checker, tsNode.initializer, contextualType) &&
|
||||
returnsThenable(checker, tsNode.initializer)) {
|
||||
if ((0, util_1.isFunction)(node.value)) {
|
||||
const functionNode = node.value;
|
||||
if (functionNode.returnType) {
|
||||
context.report({
|
||||
node: functionNode.returnType.typeAnnotation,
|
||||
messageId: 'voidReturnProperty',
|
||||
});
|
||||
}
|
||||
else {
|
||||
context.report({
|
||||
loc: (0, util_1.getFunctionHeadLoc)(functionNode, context.sourceCode),
|
||||
messageId: 'voidReturnProperty',
|
||||
});
|
||||
}
|
||||
}
|
||||
else {
|
||||
context.report({
|
||||
node: node.value,
|
||||
messageId: 'voidReturnProperty',
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (ts.isShorthandPropertyAssignment(tsNode)) {
|
||||
const contextualType = checker.getContextualType(tsNode.name);
|
||||
if (contextualType != null &&
|
||||
isVoidReturningFunctionType(checker, tsNode.name, contextualType) &&
|
||||
returnsThenable(checker, tsNode.name)) {
|
||||
context.report({
|
||||
node: node.value,
|
||||
messageId: 'voidReturnProperty',
|
||||
});
|
||||
}
|
||||
}
|
||||
else if (ts.isMethodDeclaration(tsNode)) {
|
||||
if (ts.isComputedPropertyName(tsNode.name)) {
|
||||
return;
|
||||
}
|
||||
const obj = tsNode.parent;
|
||||
// Below condition isn't satisfied unless something goes wrong,
|
||||
// but is needed for type checking.
|
||||
// 'node' does not include class method declaration so 'obj' is
|
||||
// always an object literal expression, but after converting 'node'
|
||||
// to TypeScript AST, its type includes MethodDeclaration which
|
||||
// does include the case of class method declaration.
|
||||
if (!ts.isObjectLiteralExpression(obj)) {
|
||||
return;
|
||||
}
|
||||
if (!returnsThenable(checker, tsNode)) {
|
||||
return;
|
||||
}
|
||||
const objType = checker.getContextualType(obj);
|
||||
if (objType == null) {
|
||||
return;
|
||||
}
|
||||
const propertySymbol = tsutils
|
||||
.unionConstituents(objType)
|
||||
.map(t => checker.getPropertyOfType(t, tsNode.name.getText()))
|
||||
.find(p => p);
|
||||
if (propertySymbol == null) {
|
||||
return;
|
||||
}
|
||||
const contextualType = checker.getTypeOfSymbolAtLocation(propertySymbol, tsNode.name);
|
||||
if (isVoidReturningFunctionType(checker, tsNode.name, contextualType)) {
|
||||
const functionNode = node.value;
|
||||
if (functionNode.returnType) {
|
||||
context.report({
|
||||
node: functionNode.returnType.typeAnnotation,
|
||||
messageId: 'voidReturnProperty',
|
||||
});
|
||||
}
|
||||
else {
|
||||
context.report({
|
||||
loc: (0, util_1.getFunctionHeadLoc)(functionNode, context.sourceCode),
|
||||
messageId: 'voidReturnProperty',
|
||||
});
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
function checkReturnStatement(node) {
|
||||
const tsNode = services.esTreeNodeToTSNodeMap.get(node);
|
||||
if (tsNode.expression == null || node.argument == null) {
|
||||
return;
|
||||
}
|
||||
// syntactically ignore some known-good cases to avoid touching type info
|
||||
const functionNode = (() => {
|
||||
let current = node.parent;
|
||||
while (current && !(0, util_1.isFunction)(current)) {
|
||||
current = current.parent;
|
||||
}
|
||||
return (0, util_1.nullThrows)(current, util_1.NullThrowsReasons.MissingParent);
|
||||
})();
|
||||
if (functionNode.returnType &&
|
||||
!isPossiblyFunctionType(functionNode.returnType)) {
|
||||
return;
|
||||
}
|
||||
const contextualType = checker.getContextualType(tsNode.expression);
|
||||
if (contextualType != null &&
|
||||
isVoidReturningFunctionType(checker, tsNode.expression, contextualType) &&
|
||||
returnsThenable(checker, tsNode.expression)) {
|
||||
context.report({
|
||||
node: node.argument,
|
||||
messageId: 'voidReturnReturnValue',
|
||||
});
|
||||
}
|
||||
}
|
||||
function isPromiseFinallyMethod(node) {
|
||||
const promiseFinallyCall = (0, promiseUtils_1.parseFinallyCall)(node, context);
|
||||
return (promiseFinallyCall != null &&
|
||||
(0, util_1.isPromiseLike)(services.program, (0, util_1.getConstrainedTypeAtLocation)(services, promiseFinallyCall.object)));
|
||||
}
|
||||
function checkClassLikeOrInterfaceNode(node) {
|
||||
const tsNode = services.esTreeNodeToTSNodeMap.get(node);
|
||||
const heritageTypes = getHeritageTypes(checker, tsNode);
|
||||
if (!heritageTypes?.length) {
|
||||
return;
|
||||
}
|
||||
for (const nodeMember of tsNode.members) {
|
||||
const memberName = nodeMember.name?.getText();
|
||||
if (memberName == null) {
|
||||
// Call/construct/index signatures don't have names. TS allows call signatures to mismatch,
|
||||
// and construct signatures can't be async.
|
||||
// TODO - Once we're able to use `checker.isTypeAssignableTo` (v8), we can check an index
|
||||
// signature here against its compatible index signatures in `heritageTypes`
|
||||
continue;
|
||||
}
|
||||
if (!returnsThenable(checker, nodeMember)) {
|
||||
continue;
|
||||
}
|
||||
const node = services.tsNodeToESTreeNodeMap.get(nodeMember);
|
||||
if (isStaticMember(node)) {
|
||||
continue;
|
||||
}
|
||||
for (const heritageType of heritageTypes) {
|
||||
checkHeritageTypeForMemberReturningVoid(nodeMember, heritageType, memberName);
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Checks `heritageType` for a member named `memberName` that returns void; reports the
|
||||
* 'voidReturnInheritedMethod' message if found.
|
||||
* @param nodeMember Node member that returns a Promise
|
||||
* @param heritageType Heritage type to check against
|
||||
* @param memberName Name of the member to check for
|
||||
*/
|
||||
function checkHeritageTypeForMemberReturningVoid(nodeMember, heritageType, memberName) {
|
||||
const heritageMember = getMemberIfExists(heritageType, memberName);
|
||||
if (heritageMember == null) {
|
||||
return;
|
||||
}
|
||||
const memberType = checker.getTypeOfSymbolAtLocation(heritageMember, nodeMember);
|
||||
if (!isVoidReturningFunctionType(checker, nodeMember, memberType)) {
|
||||
return;
|
||||
}
|
||||
context.report({
|
||||
node: services.tsNodeToESTreeNodeMap.get(nodeMember),
|
||||
messageId: 'voidReturnInheritedMethod',
|
||||
data: { heritageTypeName: checker.typeToString(heritageType) },
|
||||
});
|
||||
}
|
||||
function checkJSXAttribute(node) {
|
||||
if (node.value?.type !== utils_1.AST_NODE_TYPES.JSXExpressionContainer) {
|
||||
return;
|
||||
}
|
||||
const expressionContainer = services.esTreeNodeToTSNodeMap.get(node.value);
|
||||
const expression = services.esTreeNodeToTSNodeMap.get(node.value.expression);
|
||||
const contextualType = checker.getContextualType(expressionContainer);
|
||||
if (contextualType != null &&
|
||||
isVoidReturningFunctionType(checker, expressionContainer, contextualType) &&
|
||||
returnsThenable(checker, expression)) {
|
||||
context.report({
|
||||
node: node.value,
|
||||
messageId: 'voidReturnAttribute',
|
||||
});
|
||||
}
|
||||
}
|
||||
function checkSpread(node) {
|
||||
const tsNode = services.esTreeNodeToTSNodeMap.get(node);
|
||||
if (isSometimesThenable(checker, tsNode.expression)) {
|
||||
context.report({
|
||||
node: node.argument,
|
||||
messageId: 'spread',
|
||||
});
|
||||
}
|
||||
}
|
||||
return {
|
||||
...(checksConditionals ? conditionalChecks : {}),
|
||||
...(checksVoidReturn ? voidReturnChecks : {}),
|
||||
...(checksSpreads ? spreadChecks : {}),
|
||||
};
|
||||
},
|
||||
});
|
||||
function isSometimesThenable(checker, node) {
|
||||
const type = checker.getTypeAtLocation(node);
|
||||
for (const subType of tsutils.unionConstituents(checker.getApparentType(type))) {
|
||||
if (tsutils.isThenableType(checker, node, subType)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
// Variation on the thenable check which requires all forms of the type (read:
|
||||
// alternates in a union) to be thenable. Otherwise, you might be trying to
|
||||
// check if something is defined or undefined and get caught because one of the
|
||||
// branches is thenable.
|
||||
function isAlwaysThenable(checker, node) {
|
||||
const type = checker.getTypeAtLocation(node);
|
||||
for (const subType of tsutils.unionConstituents(checker.getApparentType(type))) {
|
||||
const thenProp = subType.getProperty('then');
|
||||
// If one of the alternates has no then property, it is not thenable in all
|
||||
// cases.
|
||||
if (thenProp == null) {
|
||||
return false;
|
||||
}
|
||||
// We walk through each variation of the then property. Since we know it
|
||||
// exists at this point, we just need at least one of the alternates to
|
||||
// be of the right form to consider it thenable.
|
||||
const thenType = checker.getTypeOfSymbolAtLocation(thenProp, node);
|
||||
let hasThenableSignature = false;
|
||||
for (const subType of tsutils.unionConstituents(thenType)) {
|
||||
for (const signature of subType.getCallSignatures()) {
|
||||
if (signature.parameters.length !== 0 &&
|
||||
isFunctionParam(checker, signature.parameters[0], node)) {
|
||||
hasThenableSignature = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// We only need to find one variant of the then property that has a
|
||||
// function signature for it to be thenable.
|
||||
if (hasThenableSignature) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
// If no flavors of the then property are thenable, we don't consider the
|
||||
// overall type to be thenable
|
||||
if (!hasThenableSignature) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// If all variants are considered thenable (i.e. haven't returned false), we
|
||||
// consider the overall type thenable
|
||||
return true;
|
||||
}
|
||||
function isFunctionParam(checker, param, node) {
|
||||
const type = checker.getApparentType(checker.getTypeOfSymbolAtLocation(param, node));
|
||||
for (const subType of tsutils.unionConstituents(type)) {
|
||||
if (subType.getCallSignatures().length !== 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
function checkThenableOrVoidArgument(checker, node, type, index, thenableReturnIndices, voidReturnIndices) {
|
||||
if (isThenableReturningFunctionType(checker, node.expression, type)) {
|
||||
thenableReturnIndices.add(index);
|
||||
}
|
||||
else if (isVoidReturningFunctionType(checker, node.expression, type) &&
|
||||
// If a certain argument accepts both thenable and void returns,
|
||||
// a promise-returning function is valid
|
||||
!thenableReturnIndices.has(index)) {
|
||||
voidReturnIndices.add(index);
|
||||
}
|
||||
const contextualType = checker.getContextualTypeForArgumentAtIndex(node, index);
|
||||
if (contextualType !== type) {
|
||||
checkThenableOrVoidArgument(checker, node, contextualType, index, thenableReturnIndices, voidReturnIndices);
|
||||
}
|
||||
}
|
||||
// Get the positions of arguments which are void functions (and not also
|
||||
// thenable functions). These are the candidates for the void-return check at
|
||||
// the current call site.
|
||||
// If the function parameters end with a 'rest' parameter, then we consider
|
||||
// the array type parameter (e.g. '...args:Array<SomeType>') when determining
|
||||
// if trailing arguments are candidates.
|
||||
function voidFunctionArguments(checker, node) {
|
||||
// 'new' can be used without any arguments, as in 'let b = new Object;'
|
||||
// In this case, there are no argument positions to check, so return early.
|
||||
if (!node.arguments) {
|
||||
return new Set();
|
||||
}
|
||||
const thenableReturnIndices = new Set();
|
||||
const voidReturnIndices = new Set();
|
||||
const type = checker.getTypeAtLocation(node.expression);
|
||||
// We can't use checker.getResolvedSignature because it prefers an early '() => void' over a later '() => Promise<void>'
|
||||
// See https://github.com/microsoft/TypeScript/issues/48077
|
||||
for (const subType of tsutils.unionConstituents(type)) {
|
||||
// Standard function calls and `new` have two different types of signatures
|
||||
const signatures = ts.isCallExpression(node)
|
||||
? subType.getCallSignatures()
|
||||
: subType.getConstructSignatures();
|
||||
for (const signature of signatures) {
|
||||
for (const [index, parameter] of signature.parameters.entries()) {
|
||||
const decl = parameter.valueDeclaration;
|
||||
let type = checker.getTypeOfSymbolAtLocation(parameter, node.expression);
|
||||
// If this is a array 'rest' parameter, check all of the argument indices
|
||||
// from the current argument to the end.
|
||||
if (decl && (0, util_1.isRestParameterDeclaration)(decl)) {
|
||||
if (checker.isArrayType(type)) {
|
||||
// Unwrap 'Array<MaybeVoidFunction>' to 'MaybeVoidFunction',
|
||||
// so that we'll handle it in the same way as a non-rest
|
||||
// 'param: MaybeVoidFunction'
|
||||
type = checker.getTypeArguments(type)[0];
|
||||
for (let i = index; i < node.arguments.length; i++) {
|
||||
checkThenableOrVoidArgument(checker, node, type, i, thenableReturnIndices, voidReturnIndices);
|
||||
}
|
||||
}
|
||||
else if (checker.isTupleType(type)) {
|
||||
// Check each type in the tuple - for example, [boolean, () => void] would
|
||||
// add the index of the second tuple parameter to 'voidReturnIndices'
|
||||
const typeArgs = checker.getTypeArguments(type);
|
||||
for (let i = index; i < node.arguments.length && i - index < typeArgs.length; i++) {
|
||||
checkThenableOrVoidArgument(checker, node, typeArgs[i - index], i, thenableReturnIndices, voidReturnIndices);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
checkThenableOrVoidArgument(checker, node, type, index, thenableReturnIndices, voidReturnIndices);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (const index of thenableReturnIndices) {
|
||||
voidReturnIndices.delete(index);
|
||||
}
|
||||
return voidReturnIndices;
|
||||
}
|
||||
/**
|
||||
* @returns Whether any call signature of the type has a thenable return type.
|
||||
*/
|
||||
function anySignatureIsThenableType(checker, node, type) {
|
||||
for (const signature of type.getCallSignatures()) {
|
||||
const returnType = signature.getReturnType();
|
||||
if (tsutils.isThenableType(checker, node, returnType)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* @returns Whether type is a thenable-returning function.
|
||||
*/
|
||||
function isThenableReturningFunctionType(checker, node, type) {
|
||||
for (const subType of tsutils.unionConstituents(type)) {
|
||||
if (anySignatureIsThenableType(checker, node, subType)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* @returns Whether type is a void-returning function.
|
||||
*/
|
||||
function isVoidReturningFunctionType(checker, node, type) {
|
||||
let hadVoidReturn = false;
|
||||
for (const subType of tsutils.unionConstituents(type)) {
|
||||
for (const signature of subType.getCallSignatures()) {
|
||||
const returnType = signature.getReturnType();
|
||||
// If a certain positional argument accepts both thenable and void returns,
|
||||
// a promise-returning function is valid
|
||||
if (tsutils.isThenableType(checker, node, returnType)) {
|
||||
return false;
|
||||
}
|
||||
hadVoidReturn ||= tsutils.isTypeFlagSet(returnType, ts.TypeFlags.Void);
|
||||
}
|
||||
}
|
||||
return hadVoidReturn;
|
||||
}
|
||||
/**
|
||||
* @returns Whether expression is a function that returns a thenable.
|
||||
*/
|
||||
function returnsThenable(checker, node) {
|
||||
const type = checker.getApparentType(checker.getTypeAtLocation(node));
|
||||
return tsutils
|
||||
.unionConstituents(type)
|
||||
.some(t => anySignatureIsThenableType(checker, node, t));
|
||||
}
|
||||
function getHeritageTypes(checker, tsNode) {
|
||||
return tsNode.heritageClauses
|
||||
?.flatMap(clause => clause.types)
|
||||
.map(typeExpression => checker.getTypeAtLocation(typeExpression));
|
||||
}
|
||||
/**
|
||||
* @returns The member with the given name in `type`, if it exists.
|
||||
*/
|
||||
function getMemberIfExists(type, memberName) {
|
||||
const escapedMemberName = ts.escapeLeadingUnderscores(memberName);
|
||||
const symbolMemberMatch = type.getSymbol()?.members?.get(escapedMemberName);
|
||||
return (symbolMemberMatch ?? tsutils.getPropertyOfType(type, escapedMemberName));
|
||||
}
|
||||
function isStaticMember(node) {
|
||||
return ((node.type === utils_1.AST_NODE_TYPES.MethodDefinition ||
|
||||
node.type === utils_1.AST_NODE_TYPES.PropertyDefinition ||
|
||||
node.type === utils_1.AST_NODE_TYPES.AccessorProperty) &&
|
||||
node.static);
|
||||
}
|
||||
function hasWellKnownSymbolWithThenableReturn(checker, node, type, symbolName) {
|
||||
return tsutils
|
||||
.unionConstituents(checker.getApparentType(type))
|
||||
.some(typePart => {
|
||||
const symbol = tsutils.getWellKnownSymbolPropertyOfType(typePart, symbolName, checker);
|
||||
if (symbol == null) {
|
||||
return false;
|
||||
}
|
||||
return isThenableReturningFunctionType(checker, node, checker.getTypeOfSymbolAtLocation(symbol, node));
|
||||
});
|
||||
}
|
||||
function hasWellKnownSymbolWithVoidReturn(checker, node, type, symbolName) {
|
||||
return tsutils
|
||||
.unionConstituents(checker.getApparentType(type))
|
||||
.some(typePart => {
|
||||
const symbol = tsutils.getWellKnownSymbolPropertyOfType(typePart, symbolName, checker);
|
||||
if (symbol == null) {
|
||||
return false;
|
||||
}
|
||||
return isVoidReturningFunctionType(checker, node, checker.getTypeOfSymbolAtLocation(symbol, node));
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
function _classPrivateMethodSet() {
|
||||
throw new TypeError("attempted to reassign private method");
|
||||
}
|
||||
export { _classPrivateMethodSet as default };
|
||||
@@ -0,0 +1,118 @@
|
||||
'use strict'
|
||||
|
||||
// **************************************************************
|
||||
// * Code initially copied/adapted from "pony-cause" npm module *
|
||||
// * Please upstream improvements there *
|
||||
// **************************************************************
|
||||
|
||||
const isErrorLike = (err) => {
|
||||
return err && typeof err.message === 'string'
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Error|{ cause?: unknown|(()=>err)}} err
|
||||
* @returns {Error|Object|undefined}
|
||||
*/
|
||||
const getErrorCause = (err) => {
|
||||
if (!err) return
|
||||
|
||||
/** @type {unknown} */
|
||||
// @ts-ignore
|
||||
const cause = err.cause
|
||||
|
||||
// VError / NError style causes
|
||||
if (typeof cause === 'function') {
|
||||
// @ts-ignore
|
||||
const causeResult = err.cause()
|
||||
|
||||
return isErrorLike(causeResult)
|
||||
? causeResult
|
||||
: undefined
|
||||
} else {
|
||||
return isErrorLike(cause)
|
||||
? cause
|
||||
: undefined
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal method that keeps a track of which error we have already added, to avoid circular recursion
|
||||
*
|
||||
* @private
|
||||
* @param {Error} err
|
||||
* @param {Set<Error>} seen
|
||||
* @returns {string}
|
||||
*/
|
||||
const _stackWithCauses = (err, seen) => {
|
||||
if (!isErrorLike(err)) return ''
|
||||
|
||||
const stack = err.stack || ''
|
||||
|
||||
// Ensure we don't go circular or crazily deep
|
||||
if (seen.has(err)) {
|
||||
return stack + '\ncauses have become circular...'
|
||||
}
|
||||
|
||||
const cause = getErrorCause(err)
|
||||
|
||||
if (cause) {
|
||||
seen.add(err)
|
||||
return (stack + '\ncaused by: ' + _stackWithCauses(cause, seen))
|
||||
} else {
|
||||
return stack
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Error} err
|
||||
* @returns {string}
|
||||
*/
|
||||
const stackWithCauses = (err) => _stackWithCauses(err, new Set())
|
||||
|
||||
/**
|
||||
* Internal method that keeps a track of which error we have already added, to avoid circular recursion
|
||||
*
|
||||
* @private
|
||||
* @param {Error} err
|
||||
* @param {Set<Error>} seen
|
||||
* @param {boolean} [skip]
|
||||
* @returns {string}
|
||||
*/
|
||||
const _messageWithCauses = (err, seen, skip) => {
|
||||
if (!isErrorLike(err)) return ''
|
||||
|
||||
const message = skip ? '' : (err.message || '')
|
||||
|
||||
// Ensure we don't go circular or crazily deep
|
||||
if (seen.has(err)) {
|
||||
return message + ': ...'
|
||||
}
|
||||
|
||||
const cause = getErrorCause(err)
|
||||
|
||||
if (cause) {
|
||||
seen.add(err)
|
||||
|
||||
// @ts-ignore
|
||||
const skipIfVErrorStyleCause = typeof err.cause === 'function'
|
||||
|
||||
return (message +
|
||||
(skipIfVErrorStyleCause ? '' : ': ') +
|
||||
_messageWithCauses(cause, seen, skipIfVErrorStyleCause))
|
||||
} else {
|
||||
return message
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Error} err
|
||||
* @returns {string}
|
||||
*/
|
||||
const messageWithCauses = (err) => _messageWithCauses(err, new Set())
|
||||
|
||||
module.exports = {
|
||||
isErrorLike,
|
||||
getErrorCause,
|
||||
stackWithCauses,
|
||||
messageWithCauses
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || (function () {
|
||||
var ownKeys = function(o) {
|
||||
ownKeys = Object.getOwnPropertyNames || function (o) {
|
||||
var ar = [];
|
||||
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
||||
return ar;
|
||||
};
|
||||
return ownKeys(o);
|
||||
};
|
||||
return function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
})();
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.AnyType = void 0;
|
||||
exports.discriminateAnyType = discriminateAnyType;
|
||||
const tsutils = __importStar(require("ts-api-utils"));
|
||||
const predicates_1 = require("./predicates");
|
||||
var AnyType;
|
||||
(function (AnyType) {
|
||||
AnyType[AnyType["Any"] = 0] = "Any";
|
||||
AnyType[AnyType["PromiseAny"] = 1] = "PromiseAny";
|
||||
AnyType[AnyType["AnyArray"] = 2] = "AnyArray";
|
||||
AnyType[AnyType["Safe"] = 3] = "Safe";
|
||||
})(AnyType || (exports.AnyType = AnyType = {}));
|
||||
/**
|
||||
* @returns `AnyType.Any` if the type is `any`, `AnyType.AnyArray` if the type is `any[]` or `readonly any[]`, `AnyType.PromiseAny` if the type is `Promise<any>`,
|
||||
* otherwise it returns `AnyType.Safe`.
|
||||
*/
|
||||
function discriminateAnyType(type, checker, program, tsNode) {
|
||||
return discriminateAnyTypeWorker(type, checker, program, tsNode, new Set());
|
||||
}
|
||||
function discriminateAnyTypeWorker(type, checker, program, tsNode, visited) {
|
||||
if (visited.has(type)) {
|
||||
return AnyType.Safe;
|
||||
}
|
||||
visited.add(type);
|
||||
if ((0, predicates_1.isTypeAnyType)(type)) {
|
||||
return AnyType.Any;
|
||||
}
|
||||
if ((0, predicates_1.isTypeAnyArrayType)(type, checker)) {
|
||||
return AnyType.AnyArray;
|
||||
}
|
||||
for (const part of tsutils.typeConstituents(type)) {
|
||||
if (tsutils.isThenableType(checker, tsNode, part)) {
|
||||
const awaitedType = checker.getAwaitedType(part);
|
||||
if (awaitedType) {
|
||||
const awaitedAnyType = discriminateAnyTypeWorker(awaitedType, checker, program, tsNode, visited);
|
||||
if (awaitedAnyType === AnyType.Any) {
|
||||
return AnyType.PromiseAny;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return AnyType.Safe;
|
||||
}
|
||||
Reference in New Issue
Block a user