This commit is contained in:
2025-05-09 05:30:08 +02:00
parent 7bb10e7df4
commit 73367bad9e
5322 changed files with 1266973 additions and 313 deletions

View File

@@ -0,0 +1,57 @@
{
"name": "keyv",
"version": "4.5.4",
"description": "Simple key-value storage with support for multiple backends",
"main": "src/index.js",
"scripts": {
"build": "echo 'No build step required.'",
"prepare": "yarn build",
"test": "xo && c8 ava --serial",
"test:ci": "xo && ava --serial",
"clean": "rm -rf node_modules && rm -rf ./coverage && rm -rf ./test/testdb.sqlite"
},
"xo": {
"rules": {
"unicorn/prefer-module": 0,
"unicorn/prefer-node-protocol": 0,
"@typescript-eslint/consistent-type-definitions": 0,
"unicorn/no-typeof-undefined": 0,
"unicorn/prefer-event-target": 0
}
},
"repository": {
"type": "git",
"url": "git+https://github.com/jaredwray/keyv.git"
},
"keywords": [
"key",
"value",
"store",
"cache",
"ttl"
],
"author": "Jared Wray <me@jaredwray.com> (http://jaredwray.com)",
"license": "MIT",
"bugs": {
"url": "https://github.com/jaredwray/keyv/issues"
},
"homepage": "https://github.com/jaredwray/keyv",
"dependencies": {
"json-buffer": "3.0.1"
},
"devDependencies": {
"@keyv/test-suite": "*",
"eslint": "^8.51.0",
"eslint-plugin-promise": "^6.1.1",
"pify": "^5.0.0",
"timekeeper": "^2.3.1",
"tsd": "^0.29.0"
},
"tsd": {
"directory": "test"
},
"types": "./src/index.d.ts",
"files": [
"src"
]
}

View File

@@ -0,0 +1,203 @@
/*
MIT License http://www.opensource.org/licenses/mit-license.php
Author Tobias Koppers @sokra
*/
"use strict";
const path = require("path");
const CHAR_HASH = "#".charCodeAt(0);
const CHAR_SLASH = "/".charCodeAt(0);
const CHAR_BACKSLASH = "\\".charCodeAt(0);
const CHAR_A = "A".charCodeAt(0);
const CHAR_Z = "Z".charCodeAt(0);
const CHAR_LOWER_A = "a".charCodeAt(0);
const CHAR_LOWER_Z = "z".charCodeAt(0);
const CHAR_DOT = ".".charCodeAt(0);
const CHAR_COLON = ":".charCodeAt(0);
const posixNormalize = path.posix.normalize;
const winNormalize = path.win32.normalize;
/**
* @enum {number}
*/
const PathType = Object.freeze({
Empty: 0,
Normal: 1,
Relative: 2,
AbsoluteWin: 3,
AbsolutePosix: 4,
Internal: 5
});
exports.PathType = PathType;
const invalidSegmentRegEx =
/(^|\\|\/)((\.|%2e)(\.|%2e)?|(n|%6e|%4e)(o|%6f|%4f)(d|%64|%44)(e|%65|%45)(_|%5f)(m|%6d|%4d)(o|%6f|%4f)(d|%64|%44)(u|%75|%55)(l|%6c|%4c)(e|%65|%45)(s|%73|%53))?(\\|\/|$)/i;
exports.invalidSegmentRegEx = invalidSegmentRegEx;
const deprecatedInvalidSegmentRegEx =
/(^|\\|\/)((\.|%2e)(\.|%2e)?|(n|%6e|%4e)(o|%6f|%4f)(d|%64|%44)(e|%65|%45)(_|%5f)(m|%6d|%4d)(o|%6f|%4f)(d|%64|%44)(u|%75|%55)(l|%6c|%4c)(e|%65|%45)(s|%73|%53))(\\|\/|$)/i;
exports.deprecatedInvalidSegmentRegEx = deprecatedInvalidSegmentRegEx;
/**
* @param {string} p a path
* @returns {PathType} type of path
*/
const getType = p => {
switch (p.length) {
case 0:
return PathType.Empty;
case 1: {
const c0 = p.charCodeAt(0);
switch (c0) {
case CHAR_DOT:
return PathType.Relative;
case CHAR_SLASH:
return PathType.AbsolutePosix;
case CHAR_HASH:
return PathType.Internal;
}
return PathType.Normal;
}
case 2: {
const c0 = p.charCodeAt(0);
switch (c0) {
case CHAR_DOT: {
const c1 = p.charCodeAt(1);
switch (c1) {
case CHAR_DOT:
case CHAR_SLASH:
return PathType.Relative;
}
return PathType.Normal;
}
case CHAR_SLASH:
return PathType.AbsolutePosix;
case CHAR_HASH:
return PathType.Internal;
}
const c1 = p.charCodeAt(1);
if (c1 === CHAR_COLON) {
if (
(c0 >= CHAR_A && c0 <= CHAR_Z) ||
(c0 >= CHAR_LOWER_A && c0 <= CHAR_LOWER_Z)
) {
return PathType.AbsoluteWin;
}
}
return PathType.Normal;
}
}
const c0 = p.charCodeAt(0);
switch (c0) {
case CHAR_DOT: {
const c1 = p.charCodeAt(1);
switch (c1) {
case CHAR_SLASH:
return PathType.Relative;
case CHAR_DOT: {
const c2 = p.charCodeAt(2);
if (c2 === CHAR_SLASH) return PathType.Relative;
return PathType.Normal;
}
}
return PathType.Normal;
}
case CHAR_SLASH:
return PathType.AbsolutePosix;
case CHAR_HASH:
return PathType.Internal;
}
const c1 = p.charCodeAt(1);
if (c1 === CHAR_COLON) {
const c2 = p.charCodeAt(2);
if (
(c2 === CHAR_BACKSLASH || c2 === CHAR_SLASH) &&
((c0 >= CHAR_A && c0 <= CHAR_Z) ||
(c0 >= CHAR_LOWER_A && c0 <= CHAR_LOWER_Z))
) {
return PathType.AbsoluteWin;
}
}
return PathType.Normal;
};
exports.getType = getType;
/**
* @param {string} p a path
* @returns {string} the normalized path
*/
const normalize = p => {
switch (getType(p)) {
case PathType.Empty:
return p;
case PathType.AbsoluteWin:
return winNormalize(p);
case PathType.Relative: {
const r = posixNormalize(p);
return getType(r) === PathType.Relative ? r : `./${r}`;
}
}
return posixNormalize(p);
};
exports.normalize = normalize;
/**
* @param {string} rootPath the root path
* @param {string | undefined} request the request path
* @returns {string} the joined path
*/
const join = (rootPath, request) => {
if (!request) return normalize(rootPath);
const requestType = getType(request);
switch (requestType) {
case PathType.AbsolutePosix:
return posixNormalize(request);
case PathType.AbsoluteWin:
return winNormalize(request);
}
switch (getType(rootPath)) {
case PathType.Normal:
case PathType.Relative:
case PathType.AbsolutePosix:
return posixNormalize(`${rootPath}/${request}`);
case PathType.AbsoluteWin:
return winNormalize(`${rootPath}\\${request}`);
}
switch (requestType) {
case PathType.Empty:
return rootPath;
case PathType.Relative: {
const r = posixNormalize(rootPath);
return getType(r) === PathType.Relative ? r : `./${r}`;
}
}
return posixNormalize(rootPath);
};
exports.join = join;
/** @type {Map<string, Map<string, string | undefined>>} */
const joinCache = new Map();
/**
* @param {string} rootPath the root path
* @param {string} request the request path
* @returns {string} the joined path
*/
const cachedJoin = (rootPath, request) => {
/** @type {string | undefined} */
let cacheEntry;
let cache = joinCache.get(rootPath);
if (cache === undefined) {
joinCache.set(rootPath, (cache = new Map()));
} else {
cacheEntry = cache.get(request);
if (cacheEntry !== undefined) return cacheEntry;
}
cacheEntry = join(rootPath, request);
cache.set(request, cacheEntry);
return cacheEntry;
};
exports.cachedJoin = cachedJoin;

View File

@@ -0,0 +1,247 @@
/**
* @fileoverview Utility functions to locate the source text of each code unit in the value of a string literal or template token.
* @author Francesco Trotta
*/
"use strict";
/**
* Represents a code unit produced by the evaluation of a JavaScript common token like a string
* literal or template token.
*/
class CodeUnit {
constructor(start, source) {
this.start = start;
this.source = source;
}
get end() {
return this.start + this.length;
}
get length() {
return this.source.length;
}
}
/**
* An object used to keep track of the position in a source text where the next characters will be read.
*/
class TextReader {
constructor(source) {
this.source = source;
this.pos = 0;
}
/**
* Advances the reading position of the specified number of characters.
* @param {number} length Number of characters to advance.
* @returns {void}
*/
advance(length) {
this.pos += length;
}
/**
* Reads characters from the source.
* @param {number} [offset=0] The offset where reading starts, relative to the current position.
* @param {number} [length=1] Number of characters to read.
* @returns {string} A substring of source characters.
*/
read(offset = 0, length = 1) {
const start = offset + this.pos;
return this.source.slice(start, start + length);
}
}
const SIMPLE_ESCAPE_SEQUENCES = {
__proto__: null,
b: "\b",
f: "\f",
n: "\n",
r: "\r",
t: "\t",
v: "\v",
};
/**
* Reads a hex escape sequence.
* @param {TextReader} reader The reader should be positioned on the first hexadecimal digit.
* @param {number} length The number of hexadecimal digits.
* @returns {string} A code unit.
*/
function readHexSequence(reader, length) {
const str = reader.read(0, length);
const charCode = parseInt(str, 16);
reader.advance(length);
return String.fromCharCode(charCode);
}
/**
* Reads a Unicode escape sequence.
* @param {TextReader} reader The reader should be positioned after the "u".
* @returns {string} A code unit.
*/
function readUnicodeSequence(reader) {
const regExp = /\{(?<hexDigits>[\dA-Fa-f]+)\}/uy;
regExp.lastIndex = reader.pos;
const match = regExp.exec(reader.source);
if (match) {
const codePoint = parseInt(match.groups.hexDigits, 16);
reader.pos = regExp.lastIndex;
return String.fromCodePoint(codePoint);
}
return readHexSequence(reader, 4);
}
/**
* Reads an octal escape sequence.
* @param {TextReader} reader The reader should be positioned after the first octal digit.
* @param {number} maxLength The maximum number of octal digits.
* @returns {string} A code unit.
*/
function readOctalSequence(reader, maxLength) {
const [octalStr] = reader.read(-1, maxLength).match(/^[0-7]+/u);
reader.advance(octalStr.length - 1);
const octal = parseInt(octalStr, 8);
return String.fromCharCode(octal);
}
/**
* Reads an escape sequence or line continuation.
* @param {TextReader} reader The reader should be positioned on the backslash.
* @returns {string} A string of zero, one or two code units.
*/
function readEscapeSequenceOrLineContinuation(reader) {
const char = reader.read(1);
reader.advance(2);
const unitChar = SIMPLE_ESCAPE_SEQUENCES[char];
if (unitChar) {
return unitChar;
}
switch (char) {
case "x":
return readHexSequence(reader, 2);
case "u":
return readUnicodeSequence(reader);
case "\r":
if (reader.read() === "\n") {
reader.advance(1);
}
// fallthrough
case "\n":
case "\u2028":
case "\u2029":
return "";
case "0":
case "1":
case "2":
case "3":
return readOctalSequence(reader, 3);
case "4":
case "5":
case "6":
case "7":
return readOctalSequence(reader, 2);
default:
return char;
}
}
/**
* Reads an escape sequence or line continuation and generates the respective `CodeUnit` elements.
* @param {TextReader} reader The reader should be positioned on the backslash.
* @returns {Generator<CodeUnit>} Zero, one or two `CodeUnit` elements.
*/
function* mapEscapeSequenceOrLineContinuation(reader) {
const start = reader.pos;
const str = readEscapeSequenceOrLineContinuation(reader);
const end = reader.pos;
const source = reader.source.slice(start, end);
switch (str.length) {
case 0:
break;
case 1:
yield new CodeUnit(start, source);
break;
default:
yield new CodeUnit(start, source);
yield new CodeUnit(start, source);
break;
}
}
/**
* Parses a string literal.
* @param {string} source The string literal to parse, including the delimiting quotes.
* @returns {CodeUnit[]} A list of code units produced by the string literal.
*/
function parseStringLiteral(source) {
const reader = new TextReader(source);
const quote = reader.read();
reader.advance(1);
const codeUnits = [];
for (;;) {
const char = reader.read();
if (char === quote) {
break;
}
if (char === "\\") {
codeUnits.push(...mapEscapeSequenceOrLineContinuation(reader));
} else {
codeUnits.push(new CodeUnit(reader.pos, char));
reader.advance(1);
}
}
return codeUnits;
}
/**
* Parses a template token.
* @param {string} source The template token to parse, including the delimiting sequences `` ` ``, `${` and `}`.
* @returns {CodeUnit[]} A list of code units produced by the template token.
*/
function parseTemplateToken(source) {
const reader = new TextReader(source);
reader.advance(1);
const codeUnits = [];
for (;;) {
const char = reader.read();
if (char === "`" || (char === "$" && reader.read(1) === "{")) {
break;
}
if (char === "\\") {
codeUnits.push(...mapEscapeSequenceOrLineContinuation(reader));
} else {
let unitSource;
if (char === "\r" && reader.read(1) === "\n") {
unitSource = "\r\n";
} else {
unitSource = char;
}
codeUnits.push(new CodeUnit(reader.pos, unitSource));
reader.advance(unitSource.length);
}
}
return codeUnits;
}
module.exports = { parseStringLiteral, parseTemplateToken };

View File

@@ -0,0 +1 @@
{"version":3,"names":["_toBlock","require","ensureBlock","node","key","result","toBlock"],"sources":["../../src/converters/ensureBlock.ts"],"sourcesContent":["import toBlock from \"./toBlock.ts\";\nimport type * as t from \"../index.ts\";\n\n/**\n * Ensure the `key` (defaults to \"body\") of a `node` is a block.\n * Casting it to a block if it is not.\n *\n * Returns the BlockStatement\n */\nexport default function ensureBlock(\n node: t.Node,\n key: string = \"body\",\n): t.BlockStatement {\n // @ts-expect-error Fixme: key may not exist in node, consider remove key = \"body\"\n const result = toBlock(node[key], node);\n // @ts-expect-error Fixme: key may not exist in node, consider remove key = \"body\"\n node[key] = result;\n return result;\n}\n"],"mappings":";;;;;;AAAA,IAAAA,QAAA,GAAAC,OAAA;AASe,SAASC,WAAWA,CACjCC,IAAY,EACZC,GAAW,GAAG,MAAM,EACF;EAElB,MAAMC,MAAM,GAAG,IAAAC,gBAAO,EAACH,IAAI,CAACC,GAAG,CAAC,EAAED,IAAI,CAAC;EAEvCA,IAAI,CAACC,GAAG,CAAC,GAAGC,MAAM;EAClB,OAAOA,MAAM;AACf","ignoreList":[]}

View File

@@ -0,0 +1 @@
{"version":3,"names":["_initializerWarningHelper","descriptor","context","Error"],"sources":["../../src/helpers/initializerWarningHelper.ts"],"sourcesContent":["/* @minVersion 7.0.0-beta.0 */\n\n/* eslint-disable @typescript-eslint/no-unused-vars */\nexport default function _initializerWarningHelper(\n descriptor: PropertyDescriptor,\n context: DecoratorContext,\n): never {\n throw new Error(\n \"Decorating class property failed. Please ensure that \" +\n \"transform-class-properties is enabled and runs after the decorators transform.\",\n );\n}\n"],"mappings":";;;;;;AAGe,SAASA,yBAAyBA,CAC/CC,UAA8B,EAC9BC,OAAyB,EAClB;EACP,MAAM,IAAIC,KAAK,CACb,uDAAuD,GACrD,gFACJ,CAAC;AACH","ignoreList":[]}

View File

@@ -0,0 +1,108 @@
import { trimPathLeft, joinPaths } from "./path.js";
import { notFound } from "./not-found.js";
import { rootRouteId } from "./root.js";
class BaseRoute {
constructor(options) {
this.init = (opts) => {
var _a, _b;
this.originalIndex = opts.originalIndex;
const options2 = this.options;
const isRoot = !(options2 == null ? void 0 : options2.path) && !(options2 == null ? void 0 : options2.id);
this.parentRoute = (_b = (_a = this.options).getParentRoute) == null ? void 0 : _b.call(_a);
if (isRoot) {
this._path = rootRouteId;
} else if (!this.parentRoute) {
throw new Error(
`Child Route instances must pass a 'getParentRoute: () => ParentRoute' option that returns a Route instance.`
);
}
let path = isRoot ? rootRouteId : options2 == null ? void 0 : options2.path;
if (path && path !== "/") {
path = trimPathLeft(path);
}
const customId = (options2 == null ? void 0 : options2.id) || path;
let id = isRoot ? rootRouteId : joinPaths([
this.parentRoute.id === rootRouteId ? "" : this.parentRoute.id,
customId
]);
if (path === rootRouteId) {
path = "/";
}
if (id !== rootRouteId) {
id = joinPaths(["/", id]);
}
const fullPath = id === rootRouteId ? "/" : joinPaths([this.parentRoute.fullPath, path]);
this._path = path;
this._id = id;
this._fullPath = fullPath;
this._to = fullPath;
this._ssr = (options2 == null ? void 0 : options2.ssr) ?? opts.defaultSsr ?? true;
};
this.addChildren = (children) => {
return this._addFileChildren(children);
};
this._addFileChildren = (children) => {
if (Array.isArray(children)) {
this.children = children;
}
if (typeof children === "object" && children !== null) {
this.children = Object.values(children);
}
return this;
};
this._addFileTypes = () => {
return this;
};
this.updateLoader = (options2) => {
Object.assign(this.options, options2);
return this;
};
this.update = (options2) => {
Object.assign(this.options, options2);
return this;
};
this.lazy = (lazyFn) => {
this.lazyFn = lazyFn;
return this;
};
this.options = options || {};
this.isRoot = !(options == null ? void 0 : options.getParentRoute);
if ((options == null ? void 0 : options.id) && (options == null ? void 0 : options.path)) {
throw new Error(`Route cannot have both an 'id' and a 'path' option.`);
}
}
get to() {
return this._to;
}
get id() {
return this._id;
}
get path() {
return this._path;
}
get fullPath() {
return this._fullPath;
}
get ssr() {
return this._ssr;
}
}
class BaseRouteApi {
constructor({ id }) {
this.notFound = (opts) => {
return notFound({ routeId: this.id, ...opts });
};
this.id = id;
}
}
class BaseRootRoute extends BaseRoute {
constructor(options) {
super(options);
}
}
export {
BaseRootRoute,
BaseRoute,
BaseRouteApi
};
//# sourceMappingURL=route.js.map

View File

@@ -0,0 +1,84 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
class Binding {
constructor({
identifier,
scope,
path,
kind
}) {
this.identifier = void 0;
this.scope = void 0;
this.path = void 0;
this.kind = void 0;
this.constantViolations = [];
this.constant = true;
this.referencePaths = [];
this.referenced = false;
this.references = 0;
this.identifier = identifier;
this.scope = scope;
this.path = path;
this.kind = kind;
if ((kind === "var" || kind === "hoisted") && isInitInLoop(path)) {
this.reassign(path);
}
this.clearValue();
}
deoptValue() {
this.clearValue();
this.hasDeoptedValue = true;
}
setValue(value) {
if (this.hasDeoptedValue) return;
this.hasValue = true;
this.value = value;
}
clearValue() {
this.hasDeoptedValue = false;
this.hasValue = false;
this.value = null;
}
reassign(path) {
this.constant = false;
if (this.constantViolations.includes(path)) {
return;
}
this.constantViolations.push(path);
}
reference(path) {
if (this.referencePaths.includes(path)) {
return;
}
this.referenced = true;
this.references++;
this.referencePaths.push(path);
}
dereference() {
this.references--;
this.referenced = !!this.references;
}
}
exports.default = Binding;
function isInitInLoop(path) {
const isFunctionDeclarationOrHasInit = !path.isVariableDeclarator() || path.node.init;
for (let {
parentPath,
key
} = path; parentPath; {
parentPath,
key
} = parentPath) {
if (parentPath.isFunctionParent()) return false;
if (key === "left" && parentPath.isForXStatement() || isFunctionDeclarationOrHasInit && key === "body" && parentPath.isLoop()) {
return true;
}
}
return false;
}
//# sourceMappingURL=binding.js.map

View File

@@ -0,0 +1,55 @@
import type { StateCreator, StoreApi, StoreMutatorIdentifier } from 'zustand/vanilla';
type Config = Parameters<(Window extends {
__REDUX_DEVTOOLS_EXTENSION__?: infer T;
} ? T : {
connect: (param: any) => any;
})['connect']>[0];
declare module '../vanilla.mjs' {
interface StoreMutators<S, A> {
'zustand/devtools': WithDevtools<S>;
}
}
type Cast<T, U> = T extends U ? T : U;
type Write<T, U> = Omit<T, keyof U> & U;
type TakeTwo<T> = T extends {
length: 0;
} ? [undefined, undefined] : T extends {
length: 1;
} ? [...a0: Cast<T, unknown[]>, a1: undefined] : T extends {
length: 0 | 1;
} ? [...a0: Cast<T, unknown[]>, a1: undefined] : T extends {
length: 2;
} ? T : T extends {
length: 1 | 2;
} ? T : T extends {
length: 0 | 1 | 2;
} ? T : T extends [infer A0, infer A1, ...unknown[]] ? [A0, A1] : T extends [infer A0, (infer A1)?, ...unknown[]] ? [A0, A1?] : T extends [(infer A0)?, (infer A1)?, ...unknown[]] ? [A0?, A1?] : never;
type WithDevtools<S> = Write<S, StoreDevtools<S>>;
type Action = string | {
type: string;
[x: string | number | symbol]: unknown;
};
type StoreDevtools<S> = S extends {
setState: {
(...a: infer Sa1): infer Sr1;
(...a: infer Sa2): infer Sr2;
};
} ? {
setState(...a: [...a: TakeTwo<Sa1>, action?: Action]): Sr1;
setState(...a: [...a: TakeTwo<Sa2>, action?: Action]): Sr2;
} : never;
export interface DevtoolsOptions extends Config {
name?: string;
enabled?: boolean;
anonymousActionType?: string;
store?: string;
}
type Devtools = <T, Mps extends [StoreMutatorIdentifier, unknown][] = [], Mcs extends [StoreMutatorIdentifier, unknown][] = [], U = T>(initializer: StateCreator<T, [...Mps, ['zustand/devtools', never]], Mcs, U>, devtoolsOptions?: DevtoolsOptions) => StateCreator<T, Mps, [['zustand/devtools', never], ...Mcs]>;
declare module '../vanilla.mjs' {
interface StoreMutators<S, A> {
'zustand/devtools': WithDevtools<S>;
}
}
export type NamedSet<T> = WithDevtools<StoreApi<T>>['setState'];
export declare const devtools: Devtools;
export {};

View File

@@ -0,0 +1,229 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports._containerInsert = _containerInsert;
exports._containerInsertAfter = _containerInsertAfter;
exports._containerInsertBefore = _containerInsertBefore;
exports._verifyNodeList = _verifyNodeList;
exports.insertAfter = insertAfter;
exports.insertBefore = insertBefore;
exports.pushContainer = pushContainer;
exports.unshiftContainer = unshiftContainer;
exports.updateSiblingKeys = updateSiblingKeys;
var _cache = require("../cache.js");
var _index = require("./index.js");
var _context = require("./context.js");
var _removal = require("./removal.js");
var _t = require("@babel/types");
var _hoister = require("./lib/hoister.js");
const {
arrowFunctionExpression,
assertExpression,
assignmentExpression,
blockStatement,
callExpression,
cloneNode,
expressionStatement,
isAssignmentExpression,
isCallExpression,
isExportNamedDeclaration,
isExpression,
isIdentifier,
isSequenceExpression,
isSuper,
thisExpression
} = _t;
function insertBefore(nodes_) {
_removal._assertUnremoved.call(this);
const nodes = _verifyNodeList.call(this, nodes_);
const {
parentPath,
parent
} = this;
if (parentPath.isExpressionStatement() || parentPath.isLabeledStatement() || isExportNamedDeclaration(parent) || parentPath.isExportDefaultDeclaration() && this.isDeclaration()) {
return parentPath.insertBefore(nodes);
} else if (this.isNodeType("Expression") && !this.isJSXElement() || parentPath.isForStatement() && this.key === "init") {
if (this.node) nodes.push(this.node);
return this.replaceExpressionWithStatements(nodes);
} else if (Array.isArray(this.container)) {
return _containerInsertBefore.call(this, nodes);
} else if (this.isStatementOrBlock()) {
const node = this.node;
const shouldInsertCurrentNode = node && (!this.isExpressionStatement() || node.expression != null);
this.replaceWith(blockStatement(shouldInsertCurrentNode ? [node] : []));
return this.unshiftContainer("body", nodes);
} else {
throw new Error("We don't know what to do with this node type. " + "We were previously a Statement but we can't fit in here?");
}
}
function _containerInsert(from, nodes) {
updateSiblingKeys.call(this, from, nodes.length);
const paths = [];
this.container.splice(from, 0, ...nodes);
for (let i = 0; i < nodes.length; i++) {
var _this$context;
const to = from + i;
const path = this.getSibling(to);
paths.push(path);
if ((_this$context = this.context) != null && _this$context.queue) {
_context.pushContext.call(path, this.context);
}
}
const contexts = _context._getQueueContexts.call(this);
for (const path of paths) {
_context.setScope.call(path);
path.debug("Inserted.");
for (const context of contexts) {
context.maybeQueue(path, true);
}
}
return paths;
}
function _containerInsertBefore(nodes) {
return _containerInsert.call(this, this.key, nodes);
}
function _containerInsertAfter(nodes) {
return _containerInsert.call(this, this.key + 1, nodes);
}
const last = arr => arr[arr.length - 1];
function isHiddenInSequenceExpression(path) {
return isSequenceExpression(path.parent) && (last(path.parent.expressions) !== path.node || isHiddenInSequenceExpression(path.parentPath));
}
function isAlmostConstantAssignment(node, scope) {
if (!isAssignmentExpression(node) || !isIdentifier(node.left)) {
return false;
}
const blockScope = scope.getBlockParent();
return blockScope.hasOwnBinding(node.left.name) && blockScope.getOwnBinding(node.left.name).constantViolations.length <= 1;
}
function insertAfter(nodes_) {
_removal._assertUnremoved.call(this);
if (this.isSequenceExpression()) {
return last(this.get("expressions")).insertAfter(nodes_);
}
const nodes = _verifyNodeList.call(this, nodes_);
const {
parentPath,
parent
} = this;
if (parentPath.isExpressionStatement() || parentPath.isLabeledStatement() || isExportNamedDeclaration(parent) || parentPath.isExportDefaultDeclaration() && this.isDeclaration()) {
return parentPath.insertAfter(nodes.map(node => {
return isExpression(node) ? expressionStatement(node) : node;
}));
} else if (this.isNodeType("Expression") && !this.isJSXElement() && !parentPath.isJSXElement() || parentPath.isForStatement() && this.key === "init") {
const self = this;
if (self.node) {
const node = self.node;
let {
scope
} = this;
if (scope.path.isPattern()) {
assertExpression(node);
self.replaceWith(callExpression(arrowFunctionExpression([], node), []));
self.get("callee.body").insertAfter(nodes);
return [self];
}
if (isHiddenInSequenceExpression(self)) {
nodes.unshift(node);
} else if (isCallExpression(node) && isSuper(node.callee)) {
nodes.unshift(node);
nodes.push(thisExpression());
} else if (isAlmostConstantAssignment(node, scope)) {
nodes.unshift(node);
nodes.push(cloneNode(node.left));
} else if (scope.isPure(node, true)) {
nodes.push(node);
} else {
if (parentPath.isMethod({
computed: true,
key: node
})) {
scope = scope.parent;
}
const temp = scope.generateDeclaredUidIdentifier();
nodes.unshift(expressionStatement(assignmentExpression("=", cloneNode(temp), node)));
nodes.push(expressionStatement(cloneNode(temp)));
}
}
return this.replaceExpressionWithStatements(nodes);
} else if (Array.isArray(this.container)) {
return _containerInsertAfter.call(this, nodes);
} else if (this.isStatementOrBlock()) {
const node = this.node;
const shouldInsertCurrentNode = node && (!this.isExpressionStatement() || node.expression != null);
this.replaceWith(blockStatement(shouldInsertCurrentNode ? [node] : []));
return this.pushContainer("body", nodes);
} else {
throw new Error("We don't know what to do with this node type. " + "We were previously a Statement but we can't fit in here?");
}
}
function updateSiblingKeys(fromIndex, incrementBy) {
if (!this.parent) return;
const paths = (0, _cache.getCachedPaths)(this.hub, this.parent) || [];
for (const [, path] of paths) {
if (typeof path.key === "number" && path.container === this.container && path.key >= fromIndex) {
path.key += incrementBy;
}
}
}
function _verifyNodeList(nodes) {
if (!nodes) {
return [];
}
if (!Array.isArray(nodes)) {
nodes = [nodes];
}
for (let i = 0; i < nodes.length; i++) {
const node = nodes[i];
let msg;
if (!node) {
msg = "has falsy node";
} else if (typeof node !== "object") {
msg = "contains a non-object node";
} else if (!node.type) {
msg = "without a type";
} else if (node instanceof _index.default) {
msg = "has a NodePath when it expected a raw object";
}
if (msg) {
const type = Array.isArray(node) ? "array" : typeof node;
throw new Error(`Node list ${msg} with the index of ${i} and type of ${type}`);
}
}
return nodes;
}
function unshiftContainer(listKey, nodes) {
_removal._assertUnremoved.call(this);
nodes = _verifyNodeList.call(this, nodes);
const path = _index.default.get({
parentPath: this,
parent: this.node,
container: this.node[listKey],
listKey,
key: 0
}).setContext(this.context);
return _containerInsertBefore.call(path, nodes);
}
function pushContainer(listKey, nodes) {
_removal._assertUnremoved.call(this);
const verifiedNodes = _verifyNodeList.call(this, nodes);
const container = this.node[listKey];
const path = _index.default.get({
parentPath: this,
parent: this.node,
container: container,
listKey,
key: container.length
}).setContext(this.context);
return path.replaceWithMultiple(verifiedNodes);
}
{
exports.hoist = function hoist(scope = this.scope) {
const hoister = new _hoister.default(this, scope);
return hoister.run();
};
}
//# sourceMappingURL=modification.js.map

View File

@@ -0,0 +1,2 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

View File

@@ -0,0 +1,68 @@
/**
* @fileoverview Rule to disallow `javascript:` URLs
* @author Ilya Volodin
*/
/* eslint no-script-url: 0 -- Code is checking to report such URLs */
"use strict";
const astUtils = require("./utils/ast-utils");
//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------
/** @type {import('../shared/types').Rule} */
module.exports = {
meta: {
type: "suggestion",
docs: {
description: "Disallow `javascript:` URLs",
recommended: false,
url: "https://eslint.org/docs/latest/rules/no-script-url",
},
schema: [],
messages: {
unexpectedScriptURL: "Script URL is a form of eval.",
},
},
create(context) {
/**
* Check whether a node's static value starts with `javascript:` or not.
* And report an error for unexpected script URL.
* @param {ASTNode} node node to check
* @returns {void}
*/
function check(node) {
const value = astUtils.getStaticStringValue(node);
if (
typeof value === "string" &&
value.toLowerCase().indexOf("javascript:") === 0
) {
context.report({ node, messageId: "unexpectedScriptURL" });
}
}
return {
Literal(node) {
if (node.value && typeof node.value === "string") {
check(node);
}
},
TemplateLiteral(node) {
if (
!(
node.parent &&
node.parent.type === "TaggedTemplateExpression"
)
) {
check(node);
}
},
};
},
};

View File

@@ -0,0 +1,91 @@
/**
* @fileoverview Rule to flag when initializing to undefined
* @author Ilya Volodin
*/
"use strict";
const astUtils = require("./utils/ast-utils");
//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------
/** @type {import('../shared/types').Rule} */
module.exports = {
meta: {
type: "suggestion",
docs: {
description: "Disallow initializing variables to `undefined`",
recommended: false,
frozen: true,
url: "https://eslint.org/docs/latest/rules/no-undef-init",
},
schema: [],
fixable: "code",
messages: {
unnecessaryUndefinedInit:
"It's not necessary to initialize '{{name}}' to undefined.",
},
},
create(context) {
const sourceCode = context.sourceCode;
return {
VariableDeclarator(node) {
const name = sourceCode.getText(node.id),
init = node.init && node.init.name,
scope = sourceCode.getScope(node),
undefinedVar = astUtils.getVariableByName(
scope,
"undefined",
),
shadowed = undefinedVar && undefinedVar.defs.length > 0,
lastToken = sourceCode.getLastToken(node);
if (
init === "undefined" &&
node.parent.kind !== "const" &&
!shadowed
) {
context.report({
node,
messageId: "unnecessaryUndefinedInit",
data: { name },
fix(fixer) {
if (node.parent.kind === "var") {
return null;
}
if (
node.id.type === "ArrayPattern" ||
node.id.type === "ObjectPattern"
) {
// Don't fix destructuring assignment to `undefined`.
return null;
}
if (
sourceCode.commentsExistBetween(
node.id,
lastToken,
)
) {
return null;
}
return fixer.removeRange([
node.id.range[1],
node.range[1],
]);
},
});
}
},
};
},
};

View File

@@ -0,0 +1,167 @@
declare namespace ESTree {
interface FlowTypeAnnotation extends Node {}
interface FlowBaseTypeAnnotation extends FlowTypeAnnotation {}
interface FlowLiteralTypeAnnotation extends FlowTypeAnnotation, Literal {}
interface FlowDeclaration extends Declaration {}
interface AnyTypeAnnotation extends FlowBaseTypeAnnotation {}
interface ArrayTypeAnnotation extends FlowTypeAnnotation {
elementType: FlowTypeAnnotation;
}
interface BooleanLiteralTypeAnnotation extends FlowLiteralTypeAnnotation {}
interface BooleanTypeAnnotation extends FlowBaseTypeAnnotation {}
interface ClassImplements extends Node {
id: Identifier;
typeParameters?: TypeParameterInstantiation | null;
}
interface ClassProperty {
key: Expression;
value?: Expression | null;
typeAnnotation?: TypeAnnotation | null;
computed: boolean;
static: boolean;
}
interface DeclareClass extends FlowDeclaration {
id: Identifier;
typeParameters?: TypeParameterDeclaration | null;
body: ObjectTypeAnnotation;
extends: InterfaceExtends[];
}
interface DeclareFunction extends FlowDeclaration {
id: Identifier;
}
interface DeclareModule extends FlowDeclaration {
id: Literal | Identifier;
body: BlockStatement;
}
interface DeclareVariable extends FlowDeclaration {
id: Identifier;
}
interface FunctionTypeAnnotation extends FlowTypeAnnotation {
params: FunctionTypeParam[];
returnType: FlowTypeAnnotation;
rest?: FunctionTypeParam | null;
typeParameters?: TypeParameterDeclaration | null;
}
interface FunctionTypeParam {
name: Identifier;
typeAnnotation: FlowTypeAnnotation;
optional: boolean;
}
interface GenericTypeAnnotation extends FlowTypeAnnotation {
id: Identifier | QualifiedTypeIdentifier;
typeParameters?: TypeParameterInstantiation | null;
}
interface InterfaceExtends extends Node {
id: Identifier | QualifiedTypeIdentifier;
typeParameters?: TypeParameterInstantiation | null;
}
interface InterfaceDeclaration extends FlowDeclaration {
id: Identifier;
typeParameters?: TypeParameterDeclaration | null;
extends: InterfaceExtends[];
body: ObjectTypeAnnotation;
}
interface IntersectionTypeAnnotation extends FlowTypeAnnotation {
types: FlowTypeAnnotation[];
}
interface MixedTypeAnnotation extends FlowBaseTypeAnnotation {}
interface NullableTypeAnnotation extends FlowTypeAnnotation {
typeAnnotation: TypeAnnotation;
}
interface NumberLiteralTypeAnnotation extends FlowLiteralTypeAnnotation {}
interface NumberTypeAnnotation extends FlowBaseTypeAnnotation {}
interface StringLiteralTypeAnnotation extends FlowLiteralTypeAnnotation {}
interface StringTypeAnnotation extends FlowBaseTypeAnnotation {}
interface TupleTypeAnnotation extends FlowTypeAnnotation {
types: FlowTypeAnnotation[];
}
interface TypeofTypeAnnotation extends FlowTypeAnnotation {
argument: FlowTypeAnnotation;
}
interface TypeAlias extends FlowDeclaration {
id: Identifier;
typeParameters?: TypeParameterDeclaration | null;
right: FlowTypeAnnotation;
}
interface TypeAnnotation extends Node {
typeAnnotation: FlowTypeAnnotation;
}
interface TypeCastExpression extends Expression {
expression: Expression;
typeAnnotation: TypeAnnotation;
}
interface TypeParameterDeclaration extends Node {
params: Identifier[];
}
interface TypeParameterInstantiation extends Node {
params: FlowTypeAnnotation[];
}
interface ObjectTypeAnnotation extends FlowTypeAnnotation {
properties: ObjectTypeProperty[];
indexers: ObjectTypeIndexer[];
callProperties: ObjectTypeCallProperty[];
}
interface ObjectTypeCallProperty extends Node {
value: FunctionTypeAnnotation;
static: boolean;
}
interface ObjectTypeIndexer extends Node {
id: Identifier;
key: FlowTypeAnnotation;
value: FlowTypeAnnotation;
static: boolean;
}
interface ObjectTypeProperty extends Node {
key: Expression;
value: FlowTypeAnnotation;
optional: boolean;
static: boolean;
}
interface QualifiedTypeIdentifier extends Node {
qualification: Identifier | QualifiedTypeIdentifier;
id: Identifier;
}
interface UnionTypeAnnotation extends FlowTypeAnnotation {
types: FlowTypeAnnotation[];
}
interface VoidTypeAnnotation extends FlowBaseTypeAnnotation {}
}

View File

@@ -0,0 +1,26 @@
// Copyright (c) 2010 LearnBoost <tj@learnboost.com>
#pragma once
#include <napi.h>
#include <stdint.h> // node < 7 uses libstdc++ on macOS which lacks complete c++11
class ImageData : public Napi::ObjectWrap<ImageData> {
public:
static void Initialize(Napi::Env& env, Napi::Object& exports);
ImageData(const Napi::CallbackInfo& info);
Napi::Value GetWidth(const Napi::CallbackInfo& info);
Napi::Value GetHeight(const Napi::CallbackInfo& info);
inline int width() { return _width; }
inline int height() { return _height; }
inline uint8_t *data() { return _data; }
Napi::Env env;
private:
int _width;
int _height;
uint8_t *_data;
};

View File

@@ -0,0 +1,101 @@
'use strict';
var common = require('./common');
// get snippet for a single line, respecting maxLength
function getLine(buffer, lineStart, lineEnd, position, maxLineLength) {
var head = '';
var tail = '';
var maxHalfLength = Math.floor(maxLineLength / 2) - 1;
if (position - lineStart > maxHalfLength) {
head = ' ... ';
lineStart = position - maxHalfLength + head.length;
}
if (lineEnd - position > maxHalfLength) {
tail = ' ...';
lineEnd = position + maxHalfLength - tail.length;
}
return {
str: head + buffer.slice(lineStart, lineEnd).replace(/\t/g, '→') + tail,
pos: position - lineStart + head.length // relative position
};
}
function padStart(string, max) {
return common.repeat(' ', max - string.length) + string;
}
function makeSnippet(mark, options) {
options = Object.create(options || null);
if (!mark.buffer) return null;
if (!options.maxLength) options.maxLength = 79;
if (typeof options.indent !== 'number') options.indent = 1;
if (typeof options.linesBefore !== 'number') options.linesBefore = 3;
if (typeof options.linesAfter !== 'number') options.linesAfter = 2;
var re = /\r?\n|\r|\0/g;
var lineStarts = [ 0 ];
var lineEnds = [];
var match;
var foundLineNo = -1;
while ((match = re.exec(mark.buffer))) {
lineEnds.push(match.index);
lineStarts.push(match.index + match[0].length);
if (mark.position <= match.index && foundLineNo < 0) {
foundLineNo = lineStarts.length - 2;
}
}
if (foundLineNo < 0) foundLineNo = lineStarts.length - 1;
var result = '', i, line;
var lineNoLength = Math.min(mark.line + options.linesAfter, lineEnds.length).toString().length;
var maxLineLength = options.maxLength - (options.indent + lineNoLength + 3);
for (i = 1; i <= options.linesBefore; i++) {
if (foundLineNo - i < 0) break;
line = getLine(
mark.buffer,
lineStarts[foundLineNo - i],
lineEnds[foundLineNo - i],
mark.position - (lineStarts[foundLineNo] - lineStarts[foundLineNo - i]),
maxLineLength
);
result = common.repeat(' ', options.indent) + padStart((mark.line - i + 1).toString(), lineNoLength) +
' | ' + line.str + '\n' + result;
}
line = getLine(mark.buffer, lineStarts[foundLineNo], lineEnds[foundLineNo], mark.position, maxLineLength);
result += common.repeat(' ', options.indent) + padStart((mark.line + 1).toString(), lineNoLength) +
' | ' + line.str + '\n';
result += common.repeat('-', options.indent + lineNoLength + 3 + line.pos) + '^' + '\n';
for (i = 1; i <= options.linesAfter; i++) {
if (foundLineNo + i >= lineEnds.length) break;
line = getLine(
mark.buffer,
lineStarts[foundLineNo + i],
lineEnds[foundLineNo + i],
mark.position - (lineStarts[foundLineNo] - lineStarts[foundLineNo + i]),
maxLineLength
);
result += common.repeat(' ', options.indent) + padStart((mark.line + i + 1).toString(), lineNoLength) +
' | ' + line.str + '\n';
}
return result.replace(/\n$/, '');
}
module.exports = makeSnippet;

View File

@@ -0,0 +1 @@
{"version":3,"names":["_classStaticPrivateMethodSet","TypeError"],"sources":["../../src/helpers/classStaticPrivateMethodSet.js"],"sourcesContent":["/* @minVersion 7.3.2 */\n/* @onlyBabel7 */\n\nexport default function _classStaticPrivateMethodSet() {\n throw new TypeError(\"attempted to set read only static private field\");\n}\n"],"mappings":";;;;;;AAGe,SAASA,4BAA4BA,CAAA,EAAG;EACrD,MAAM,IAAIC,SAAS,CAAC,iDAAiD,CAAC;AACxE","ignoreList":[]}

View File

@@ -0,0 +1 @@
module.exports={A:{A:{"2":"K D E F A B mC"},B:{"1":"0 9 O P Q H R S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z AB BB CB DB EB FB GB HB IB JB KB LB MB NB OB I","2":"C L M G N"},C:{"1":"0 9 fB gB hB iB jB kB lB mB nB oB pB qB rB sB tB uB vB MC wB NC xB yB zB 0B 1B 2B 3B 4B 5B 6B 7B 8B 9B AC BC CC DC Q H R OC S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z AB BB CB DB EB FB GB HB IB JB KB LB MB NB OB I PC EC QC RC oC pC","2":"1 2 3 4 5 6 7 8 nC LC J PB K D E F A B C L M G N O P QB RB SB TB UB VB WB XB YB ZB aB bB cB dB eB qC rC"},D:{"1":"0 9 gB hB iB jB kB lB mB nB oB pB qB rB sB tB uB vB MC wB NC xB yB zB 0B 1B 2B 3B 4B 5B 6B 7B 8B 9B AC BC CC DC Q H R S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z AB BB CB DB EB FB GB HB IB JB KB LB MB NB OB I PC EC QC RC","2":"1 2 3 4 5 6 7 8 J PB K D E F A B C L M G N O P QB RB SB TB UB VB WB XB YB ZB aB bB cB dB eB fB"},E:{"1":"B C L M G TC FC GC xC yC zC UC VC HC 0C IC WC XC YC ZC aC 1C JC bC cC dC eC fC 2C KC gC hC iC jC 3C","2":"J PB K D E F A sC SC tC uC vC wC"},F:{"1":"0 TB UB VB WB XB YB ZB aB bB cB dB eB fB gB hB iB jB kB lB mB nB oB pB qB rB sB tB uB vB wB xB yB zB 0B 1B 2B 3B 4B 5B 6B 7B 8B 9B AC BC CC DC Q H R OC S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z","2":"1 2 3 4 5 6 7 8 F B C G N O P QB RB SB 4C 5C 6C 7C FC kC 8C GC"},G:{"1":"HD ID JD KD LD MD ND OD PD QD RD SD UC VC HC TD IC WC XC YC ZC aC UD JC bC cC dC eC fC VD KC gC hC iC jC","2":"E SC 9C lC AD BD CD DD ED FD GD"},H:{"2":"WD"},I:{"1":"I","2":"LC J XD YD ZD aD lC bD cD"},J:{"2":"D A"},K:{"1":"H","2":"A B C FC kC GC"},L:{"1":"I"},M:{"1":"EC"},N:{"2":"A B"},O:{"1":"HC"},P:{"1":"1 2 3 4 5 6 7 8 J dD eD fD gD hD TC iD jD kD lD mD IC JC KC nD"},Q:{"1":"oD"},R:{"1":"pD"},S:{"1":"qD rD"}},B:4,C:"Upgrade Insecure Requests",D:true};

View File

@@ -0,0 +1 @@
module.exports={C:{"77":0.00997,"115":0.12958,"126":0.00997,"131":0.04984,"135":0.02492,"136":0.28907,_:"2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 116 117 118 119 120 121 122 123 124 125 127 128 129 130 132 133 134 137 138 139 140 3.5 3.6"},D:{"43":0.00997,"44":0.00997,"45":0.00997,"54":0.00997,"55":0.02492,"90":0.03489,"109":0.03489,"116":2.67641,"120":0.47846,"121":0.00997,"124":0.05981,"126":2.54184,"127":0.04984,"129":0.00997,"131":0.17942,"132":1.85903,"133":11.86192,"134":14.49846,_:"4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 46 47 48 49 50 51 52 53 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 83 84 85 86 87 88 89 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 110 111 112 113 114 115 117 118 119 122 123 125 128 130 135 136 137 138"},F:{_:"9 11 12 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 60 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 9.5-9.6 10.0-10.1 10.5 10.6 11.1 11.5 11.6 12.1"},B:{"107":0.00997,"121":0.0947,"126":1.11642,"130":1.1513,"131":0.34888,"132":3.50375,"133":1.10146,"134":1.94376,_:"12 13 14 15 16 17 18 79 80 81 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 108 109 110 111 112 113 114 115 116 117 118 119 120 122 123 124 125 127 128 129"},E:{_:"0 4 5 6 7 8 9 10 11 12 13 14 15 3.1 3.2 5.1 6.1 7.1 9.1 10.1 11.1 12.1 13.1 14.1 15.1 15.2-15.3 15.4 15.5 16.0 16.1 16.2 16.3 16.4 16.6 17.0 17.2 17.5 18.0 18.4","15.6":0.00997,"16.5":0.05981,"17.1":0.06978,"17.3":0.04984,"17.4":0.00997,"17.6":0.97188,"18.1":0.28907,"18.2":0.00997,"18.3":0.22926},G:{"8":0,"3.2":0,"4.0-4.1":0,"4.2-4.3":0.00172,"5.0-5.1":0,"6.0-6.1":0.00515,"7.0-7.1":0.00343,"8.1-8.4":0,"9.0-9.2":0.00258,"9.3":0.01202,"10.0-10.2":0.00086,"10.3":0.01975,"11.0-11.2":0.09103,"11.3-11.4":0.00601,"12.0-12.1":0.00343,"12.2-12.5":0.08502,"13.0-13.1":0.00172,"13.2":0.00258,"13.3":0.00343,"13.4-13.7":0.01202,"14.0-14.4":0.03006,"14.5-14.8":0.03607,"15.0-15.1":0.01975,"15.2-15.3":0.01975,"15.4":0.02404,"15.5":0.02748,"15.6-15.8":0.33834,"16.0":0.04809,"16.1":0.09876,"16.2":0.05152,"16.3":0.08931,"16.4":0.01975,"16.5":0.03693,"16.6-16.7":0.40103,"17.0":0.02404,"17.1":0.04294,"17.2":0.03263,"17.3":0.04551,"17.4":0.09103,"17.5":0.20266,"17.6-17.7":0.58824,"18.0":0.16488,"18.1":0.53929,"18.2":0.24131,"18.3":5.04338,"18.4":0.07471},P:{"27":0.2207,_:"4 20 21 22 23 24 25 26 5.0-5.4 6.2-6.4 7.2-7.4 8.2 9.2 10.1 11.1-11.2 12.0 13.0 14.0 15.0 16.0 17.0 18.0 19.0"},I:{"0":0.02503,"3":0,"4":0,"2.1":0,"2.2":0,"2.3":0,"4.1":0,"4.2-4.3":0.00001,"4.4":0,"4.4.3-4.4.4":0.00003},K:{"0":0,_:"10 11 12 11.1 11.5 12.1"},A:{_:"6 7 8 9 10 11 5.5"},S:{_:"2.5 3.0-3.1"},J:{_:"7 10"},N:{_:"10 11"},R:{_:"0"},M:{"0":3.34567},Q:{_:"14.9"},O:{"0":0.45144},H:{"0":0},L:{"0":41.09675}};

View File

@@ -0,0 +1,239 @@
import type { AnyRoute, StaticDataRouteOption } from './route'
import type {
AllContext,
AllLoaderData,
AllParams,
FullSearchSchema,
ParseRoute,
RouteById,
RouteIds,
} from './routeInfo'
import type { AnyRouter, RegisteredRouter } from './router'
import type { Constrain, ControlledPromise } from './utils'
export type AnyMatchAndValue = { match: any; value: any }
export type FindValueByIndex<
TKey,
TValue extends ReadonlyArray<any>,
> = TKey extends `${infer TIndex extends number}` ? TValue[TIndex] : never
export type FindValueByKey<TKey, TValue> =
TValue extends ReadonlyArray<any>
? FindValueByIndex<TKey, TValue>
: TValue[TKey & keyof TValue]
export type CreateMatchAndValue<TMatch, TValue> = TValue extends any
? {
match: TMatch
value: TValue
}
: never
export type NextMatchAndValue<
TKey,
TMatchAndValue extends AnyMatchAndValue,
> = TMatchAndValue extends any
? CreateMatchAndValue<
TMatchAndValue['match'],
FindValueByKey<TKey, TMatchAndValue['value']>
>
: never
export type IsMatchKeyOf<TValue> =
TValue extends ReadonlyArray<any>
? number extends TValue['length']
? `${number}`
: keyof TValue & `${number}`
: TValue extends object
? keyof TValue & string
: never
export type IsMatchPath<
TParentPath extends string,
TMatchAndValue extends AnyMatchAndValue,
> = `${TParentPath}${IsMatchKeyOf<TMatchAndValue['value']>}`
export type IsMatchResult<
TKey,
TMatchAndValue extends AnyMatchAndValue,
> = TMatchAndValue extends any
? TKey extends keyof TMatchAndValue['value']
? TMatchAndValue['match']
: never
: never
export type IsMatchParse<
TPath,
TMatchAndValue extends AnyMatchAndValue,
TParentPath extends string = '',
> = TPath extends `${string}.${string}`
? TPath extends `${infer TFirst}.${infer TRest}`
? IsMatchParse<
TRest,
NextMatchAndValue<TFirst, TMatchAndValue>,
`${TParentPath}${TFirst}.`
>
: never
: {
path: IsMatchPath<TParentPath, TMatchAndValue>
result: IsMatchResult<TPath, TMatchAndValue>
}
export type IsMatch<TMatch, TPath> = IsMatchParse<
TPath,
TMatch extends any ? { match: TMatch; value: TMatch } : never
>
/**
* Narrows matches based on a path
* @experimental
*/
export const isMatch = <TMatch, TPath extends string>(
match: TMatch,
path: Constrain<TPath, IsMatch<TMatch, TPath>['path']>,
): match is IsMatch<TMatch, TPath>['result'] => {
const parts = (path as string).split('.')
let part
let value: any = match
while ((part = parts.shift()) != null && value != null) {
value = value[part]
}
return value != null
}
export interface DefaultRouteMatchExtensions {
scripts?: unknown
links?: unknown
headScripts?: unknown
meta?: unknown
}
export interface RouteMatchExtensions extends DefaultRouteMatchExtensions {}
export interface RouteMatch<
out TRouteId,
out TFullPath,
out TAllParams,
out TFullSearchSchema,
out TLoaderData,
out TAllContext,
out TLoaderDeps,
> extends RouteMatchExtensions {
id: string
routeId: TRouteId
fullPath: TFullPath
index: number
pathname: string
params: TAllParams
_strictParams: TAllParams
status: 'pending' | 'success' | 'error' | 'redirected' | 'notFound'
isFetching: false | 'beforeLoad' | 'loader'
error: unknown
paramsError: unknown
searchError: unknown
updatedAt: number
loadPromise?: ControlledPromise<void>
beforeLoadPromise?: ControlledPromise<void>
loaderPromise?: ControlledPromise<void>
loaderData?: TLoaderData
__routeContext: Record<string, unknown>
__beforeLoadContext: Record<string, unknown>
context: TAllContext
search: TFullSearchSchema
_strictSearch: TFullSearchSchema
fetchCount: number
abortController: AbortController
cause: 'preload' | 'enter' | 'stay'
loaderDeps: TLoaderDeps
preload: boolean
invalid: boolean
headers?: Record<string, string>
globalNotFound?: boolean
staticData: StaticDataRouteOption
minPendingPromise?: ControlledPromise<void>
pendingTimeout?: ReturnType<typeof setTimeout>
}
export type MakeRouteMatchFromRoute<TRoute extends AnyRoute> = RouteMatch<
TRoute['types']['id'],
TRoute['types']['fullPath'],
TRoute['types']['allParams'],
TRoute['types']['fullSearchSchema'],
TRoute['types']['loaderData'],
TRoute['types']['allContext'],
TRoute['types']['loaderDeps']
>
export type MakeRouteMatch<
TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],
TRouteId = RouteIds<TRouteTree>,
TStrict extends boolean = true,
> = RouteMatch<
TRouteId,
RouteById<TRouteTree, TRouteId>['types']['fullPath'],
TStrict extends false
? AllParams<TRouteTree>
: RouteById<TRouteTree, TRouteId>['types']['allParams'],
TStrict extends false
? FullSearchSchema<TRouteTree>
: RouteById<TRouteTree, TRouteId>['types']['fullSearchSchema'],
TStrict extends false
? AllLoaderData<TRouteTree>
: RouteById<TRouteTree, TRouteId>['types']['loaderData'],
TStrict extends false
? AllContext<TRouteTree>
: RouteById<TRouteTree, TRouteId>['types']['allContext'],
RouteById<TRouteTree, TRouteId>['types']['loaderDeps']
>
export type AnyRouteMatch = RouteMatch<any, any, any, any, any, any, any>
export type MakeRouteMatchUnion<
TRouter extends AnyRouter = RegisteredRouter,
TRoute extends AnyRoute = ParseRoute<TRouter['routeTree']>,
> = TRoute extends any
? RouteMatch<
TRoute['id'],
TRoute['fullPath'],
TRoute['types']['allParams'],
TRoute['types']['fullSearchSchema'],
TRoute['types']['loaderData'],
TRoute['types']['allContext'],
TRoute['types']['loaderDeps']
>
: never
/**
* The `MatchRouteOptions` type is used to describe the options that can be used when matching a route.
*
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/MatchRouteOptionsType#matchrouteoptions-type)
*/
export interface MatchRouteOptions {
/**
* If `true`, will match against pending location instead of the current location.
*
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/MatchRouteOptionsType#pending-property)
*/
pending?: boolean
/**
* If `true`, will match against the current location with case sensitivity.
*
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/MatchRouteOptionsType#casesensitive-property)
*/
caseSensitive?: boolean
/**
* If `true`, will match against the current location's search params using a deep inclusive check. e.g. `{ a: 1 }` will match for a current location of `{ a: 1, b: 2 }`.
*
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/MatchRouteOptionsType#includesearch-property)
*/
includeSearch?: boolean
/**
* If `true`, will match against the current location using a fuzzy match. e.g. `/posts` will match for a current location of `/posts/123`.
*
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/MatchRouteOptionsType#fuzzy-property)
*/
fuzzy?: boolean
}

View File

@@ -0,0 +1,5 @@
import { AllParams, RouteById } from './routeInfo.cjs';
import { AnyRouter } from './router.cjs';
import { Expand } from './utils.cjs';
export type ResolveUseParams<TRouter extends AnyRouter, TFrom, TStrict extends boolean> = TStrict extends false ? AllParams<TRouter['routeTree']> : Expand<RouteById<TRouter['routeTree'], TFrom>['types']['allParams']>;
export type UseParamsResult<TRouter extends AnyRouter, TFrom, TStrict extends boolean, TSelected> = unknown extends TSelected ? ResolveUseParams<TRouter, TFrom, TStrict> : TSelected;

View File

@@ -0,0 +1 @@
module.exports={A:{A:{"2":"K D E F A B mC"},B:{"1":"0 9 M G N O P Q H R S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z AB BB CB DB EB FB GB HB IB JB KB LB MB NB OB I","2":"C L"},C:{"1":"0 9 dB eB fB gB hB iB jB kB lB mB nB oB pB qB rB sB tB uB vB MC wB NC xB yB zB 0B 1B 2B 3B 4B 5B 6B 7B 8B 9B AC BC CC DC Q H R OC S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z AB BB CB DB EB FB GB HB IB JB KB LB MB NB OB I PC EC QC RC oC pC","2":"1 2 3 4 5 6 7 8 nC LC J PB K D E F A B C L M G N O P QB RB SB TB UB VB WB qC rC","1025":"cB","1218":"XB YB ZB aB bB"},D:{"1":"0 9 fB gB hB iB jB kB lB mB nB oB pB qB rB sB tB uB vB MC wB NC xB yB zB 0B 1B 2B 3B 4B 5B 6B 7B 8B 9B AC BC CC DC Q H R S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z AB BB CB DB EB FB GB HB IB JB KB LB MB NB OB I PC EC QC RC","2":"1 2 3 4 5 6 7 8 J PB K D E F A B C L M G N O P QB RB SB TB UB VB WB XB YB ZB aB bB cB","260":"dB","772":"eB"},E:{"1":"B C L M G TC FC GC xC yC zC UC VC HC 0C IC WC XC YC ZC aC 1C JC bC cC dC eC fC 2C KC gC hC iC jC 3C","2":"J PB K D E F A sC SC tC uC vC wC"},F:{"1":"0 SB TB UB VB WB XB YB ZB aB bB cB dB eB fB gB hB iB jB kB lB mB nB oB pB qB rB sB tB uB vB wB xB yB zB 0B 1B 2B 3B 4B 5B 6B 7B 8B 9B AC BC CC DC Q H R OC S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z","2":"1 2 3 4 5 6 7 F B C G N O P QB 4C 5C 6C 7C FC kC 8C GC","260":"8","772":"RB"},G:{"1":"HD ID JD KD LD MD ND OD PD QD RD SD UC VC HC TD IC WC XC YC ZC aC UD JC bC cC dC eC fC VD KC gC hC iC jC","2":"E SC 9C lC AD BD CD DD ED FD GD"},H:{"2":"WD"},I:{"1":"I","2":"LC J XD YD ZD aD lC bD cD"},J:{"2":"D A"},K:{"1":"H","2":"A B C FC kC GC"},L:{"1":"I"},M:{"1":"EC"},N:{"2":"A B"},O:{"1":"HC"},P:{"1":"1 2 3 4 5 6 7 8 J dD eD fD gD hD TC iD jD kD lD mD IC JC KC nD"},Q:{"1":"oD"},R:{"1":"pD"},S:{"1":"qD rD"}},B:1,C:"Fetch",D:true};

View File

@@ -0,0 +1,21 @@
MIT License
Copyright (c) Arnaud Barré (https://github.com/ArnaudBarre)
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.

View File

@@ -0,0 +1,252 @@
/**
* @fileoverview Rule to flag the use of redundant constructors in classes.
* @author Alberto Rodríguez
*/
"use strict";
const astUtils = require("./utils/ast-utils");
//------------------------------------------------------------------------------
// Helpers
//------------------------------------------------------------------------------
/**
* Checks whether any of a method's parameters have a decorator or are a parameter property.
* @param {ASTNode} node A method definition node.
* @returns {boolean} `true` if any parameter had a decorator or is a parameter property.
*/
function hasDecoratorsOrParameterProperty(node) {
return node.value.params.some(
param =>
param.decorators?.length || param.type === "TSParameterProperty",
);
}
/**
* Checks whether a node's accessibility makes it not useless.
* @param {ASTNode} node A method definition node.
* @returns {boolean} `true` if the node has a useful accessibility.
*/
function hasUsefulAccessibility(node) {
switch (node.accessibility) {
case "protected":
case "private":
return true;
case "public":
return !!node.parent.parent.superClass;
default:
return false;
}
}
/**
* Checks whether a given array of statements is a single call of `super`.
* @param {ASTNode[]} body An array of statements to check.
* @returns {boolean} `true` if the body is a single call of `super`.
*/
function isSingleSuperCall(body) {
return (
body.length === 1 &&
body[0].type === "ExpressionStatement" &&
body[0].expression.type === "CallExpression" &&
body[0].expression.callee.type === "Super"
);
}
/**
* Checks whether a given node is a pattern which doesn't have any side effects.
* Default parameters and Destructuring parameters can have side effects.
* @param {ASTNode} node A pattern node.
* @returns {boolean} `true` if the node doesn't have any side effects.
*/
function isSimple(node) {
return node.type === "Identifier" || node.type === "RestElement";
}
/**
* Checks whether a given array of expressions is `...arguments` or not.
* `super(...arguments)` passes all arguments through.
* @param {ASTNode[]} superArgs An array of expressions to check.
* @returns {boolean} `true` if the superArgs is `...arguments`.
*/
function isSpreadArguments(superArgs) {
return (
superArgs.length === 1 &&
superArgs[0].type === "SpreadElement" &&
superArgs[0].argument.type === "Identifier" &&
superArgs[0].argument.name === "arguments"
);
}
/**
* Checks whether given 2 nodes are identifiers which have the same name or not.
* @param {ASTNode} ctorParam A node to check.
* @param {ASTNode} superArg A node to check.
* @returns {boolean} `true` if the nodes are identifiers which have the same
* name.
*/
function isValidIdentifierPair(ctorParam, superArg) {
return (
ctorParam.type === "Identifier" &&
superArg.type === "Identifier" &&
ctorParam.name === superArg.name
);
}
/**
* Checks whether given 2 nodes are a rest/spread pair which has the same values.
* @param {ASTNode} ctorParam A node to check.
* @param {ASTNode} superArg A node to check.
* @returns {boolean} `true` if the nodes are a rest/spread pair which has the
* same values.
*/
function isValidRestSpreadPair(ctorParam, superArg) {
return (
ctorParam.type === "RestElement" &&
superArg.type === "SpreadElement" &&
isValidIdentifierPair(ctorParam.argument, superArg.argument)
);
}
/**
* Checks whether given 2 nodes have the same value or not.
* @param {ASTNode} ctorParam A node to check.
* @param {ASTNode} superArg A node to check.
* @returns {boolean} `true` if the nodes have the same value or not.
*/
function isValidPair(ctorParam, superArg) {
return (
isValidIdentifierPair(ctorParam, superArg) ||
isValidRestSpreadPair(ctorParam, superArg)
);
}
/**
* Checks whether the parameters of a constructor and the arguments of `super()`
* have the same values or not.
* @param {ASTNode} ctorParams The parameters of a constructor to check.
* @param {ASTNode} superArgs The arguments of `super()` to check.
* @returns {boolean} `true` if those have the same values.
*/
function isPassingThrough(ctorParams, superArgs) {
if (ctorParams.length !== superArgs.length) {
return false;
}
for (let i = 0; i < ctorParams.length; ++i) {
if (!isValidPair(ctorParams[i], superArgs[i])) {
return false;
}
}
return true;
}
/**
* Checks whether the constructor body is a redundant super call.
* @param {Array} body constructor body content.
* @param {Array} ctorParams The params to check against super call.
* @returns {boolean} true if the constructor body is redundant
*/
function isRedundantSuperCall(body, ctorParams) {
return (
isSingleSuperCall(body) &&
ctorParams.every(isSimple) &&
(isSpreadArguments(body[0].expression.arguments) ||
isPassingThrough(ctorParams, body[0].expression.arguments))
);
}
//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------
/** @type {import('../shared/types').Rule} */
module.exports = {
meta: {
dialects: ["javascript", "typescript"],
language: "javascript",
type: "suggestion",
docs: {
description: "Disallow unnecessary constructors",
recommended: false,
url: "https://eslint.org/docs/latest/rules/no-useless-constructor",
},
hasSuggestions: true,
schema: [],
messages: {
noUselessConstructor: "Useless constructor.",
removeConstructor: "Remove the constructor.",
},
},
create(context) {
/**
* Checks whether a node is a redundant constructor
* @param {ASTNode} node node to check
* @returns {void}
*/
function checkForConstructor(node) {
if (
node.kind !== "constructor" ||
node.value.type !== "FunctionExpression" ||
hasDecoratorsOrParameterProperty(node) ||
hasUsefulAccessibility(node)
) {
return;
}
/*
* Prevent crashing on parsers which do not require class constructor
* to have a body, e.g. typescript and flow
*/
if (!node.value.body) {
return;
}
const body = node.value.body.body;
const ctorParams = node.value.params;
const superClass = node.parent.parent.superClass;
if (
superClass
? isRedundantSuperCall(body, ctorParams)
: body.length === 0
) {
context.report({
node,
messageId: "noUselessConstructor",
suggest: [
{
messageId: "removeConstructor",
*fix(fixer) {
const nextToken =
context.sourceCode.getTokenAfter(node);
const addSemiColon =
nextToken.type === "Punctuator" &&
nextToken.value === "[" &&
astUtils.needsPrecedingSemicolon(
context.sourceCode,
node,
);
yield fixer.replaceText(
node,
addSemiColon ? ";" : "",
);
},
},
],
});
}
}
return {
MethodDefinition: checkForConstructor,
};
},
};

View File

@@ -0,0 +1 @@
module.exports={A:{A:{"1":"K D E F A B","16":"mC"},B:{"1":"0 9 C L M G N O P Q H R S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z AB BB CB DB EB FB GB HB IB JB KB LB MB NB OB I"},C:{"1":"0 9 iB jB kB lB mB nB oB pB qB rB sB tB uB vB MC wB NC xB yB zB 0B 1B 2B 3B 4B 5B 6B 7B 8B 9B AC BC CC DC Q H R OC S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z AB BB CB DB EB FB GB HB IB JB KB LB MB NB OB I PC EC QC RC oC pC","2":"1 2 3 4 5 6 7 8 nC LC J PB K D E F A B C L M G N O P QB RB SB TB UB VB WB XB YB ZB aB bB cB dB eB fB gB hB qC rC"},D:{"1":"0 1 2 3 4 5 6 7 8 9 J PB K D E F A B C L M G N O P QB RB SB TB UB VB WB XB YB ZB aB bB cB dB eB fB gB hB iB jB kB lB mB nB oB pB qB rB sB tB uB vB MC wB NC xB yB zB 0B 1B 2B 3B 4B 5B 6B 7B 8B 9B AC BC CC DC Q H R S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z AB BB CB DB EB FB GB HB IB JB KB LB MB NB OB I PC EC QC RC"},E:{"1":"J PB K D E F A B C L M G SC tC uC vC wC TC FC GC xC yC zC UC VC HC 0C IC WC XC YC ZC aC 1C JC bC cC dC eC fC 2C KC gC hC iC jC 3C","16":"sC"},F:{"1":"0 1 2 3 4 5 6 7 8 B C G N O P QB RB SB TB UB VB WB XB YB ZB aB bB cB dB eB fB gB hB iB jB kB lB mB nB oB pB qB rB sB tB uB vB wB xB yB zB 0B 1B 2B 3B 4B 5B 6B 7B 8B 9B AC BC CC DC Q H R OC S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z 4C 5C 6C 7C FC kC 8C GC","16":"F"},G:{"1":"E 9C lC AD BD CD DD ED FD GD HD ID JD KD LD MD ND OD PD QD RD SD UC VC HC TD IC WC XC YC ZC aC UD JC bC cC dC eC fC VD KC gC hC iC jC","16":"SC"},H:{"1":"WD"},I:{"1":"LC J I ZD aD lC bD cD","16":"XD YD"},J:{"1":"D A"},K:{"1":"A B C H FC kC GC"},L:{"1":"I"},M:{"1":"EC"},N:{"1":"A B"},O:{"1":"HC"},P:{"1":"1 2 3 4 5 6 7 8 J dD eD fD gD hD TC iD jD kD lD mD IC JC KC nD"},Q:{"1":"oD"},R:{"1":"pD"},S:{"1":"qD rD"}},B:1,C:"HTMLElement.innerText",D:true};