update
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
let urlAlphabet =
|
||||
'useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict'
|
||||
let customAlphabet = (alphabet, defaultSize = 21) => {
|
||||
return (size = defaultSize) => {
|
||||
let id = ''
|
||||
let i = size | 0
|
||||
while (i--) {
|
||||
id += alphabet[(Math.random() * alphabet.length) | 0]
|
||||
}
|
||||
return id
|
||||
}
|
||||
}
|
||||
let nanoid = (size = 21) => {
|
||||
let id = ''
|
||||
let i = size | 0
|
||||
while (i--) {
|
||||
id += urlAlphabet[(Math.random() * 64) | 0]
|
||||
}
|
||||
return id
|
||||
}
|
||||
export { nanoid, customAlphabet }
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"redirect.js","sources":["../../src/redirect.ts"],"sourcesContent":["import type { NavigateOptions } from './link'\nimport type { RoutePaths } from './routeInfo'\nimport type { AnyRouter, RegisteredRouter } from './router'\nimport type { PickAsRequired } from './utils'\n\nexport type AnyRedirect = Redirect<any, any, any, any, any>\n\n/**\n * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RedirectType)\n */\nexport type Redirect<\n TRouter extends AnyRouter = RegisteredRouter,\n TFrom extends RoutePaths<TRouter['routeTree']> | string = '/',\n TTo extends string | undefined = '.',\n TMaskFrom extends RoutePaths<TRouter['routeTree']> | string = TFrom,\n TMaskTo extends string = '.',\n> = {\n href?: string\n /**\n * @deprecated Use `statusCode` instead\n **/\n code?: number\n /**\n * The HTTP status code to use when redirecting.\n * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RedirectType#statuscode-property)\n */\n statusCode?: number\n /**\n * If provided, will throw the redirect object instead of returning it. This can be useful in places where `throwing` in a function might cause it to have a return type of `never`. In that case, you can use `redirect({ throw: true })` to throw the redirect object instead of returning it.\n * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RedirectType#throw-property)\n */\n throw?: any\n /**\n * The HTTP headers to use when redirecting.\n * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RedirectType#headers-property)\n */\n headers?: HeadersInit\n} & NavigateOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>\n\nexport type ResolvedRedirect<\n TRouter extends AnyRouter = RegisteredRouter,\n TFrom extends RoutePaths<TRouter['routeTree']> = '/',\n TTo extends string = '',\n TMaskFrom extends RoutePaths<TRouter['routeTree']> = TFrom,\n TMaskTo extends string = '',\n> = PickAsRequired<\n Redirect<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>,\n 'code' | 'statusCode' | 'headers'\n> & {\n href: string\n}\n\nexport function redirect<\n TRouter extends RegisteredRouter,\n const TTo extends string | undefined,\n const TFrom extends string = string,\n const TMaskFrom extends string = TFrom,\n const TMaskTo extends string = '',\n>(\n opts: Redirect<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>,\n): Redirect<TRouter, TFrom, TTo, TMaskFrom, TMaskTo> {\n ;(opts as any).isRedirect = true\n opts.statusCode = opts.statusCode || opts.code || 307\n opts.headers = opts.headers || {}\n if (!opts.reloadDocument) {\n opts.reloadDocument = false\n try {\n new URL(`${opts.href}`)\n opts.reloadDocument = true\n } catch {}\n }\n\n if (opts.throw) {\n throw opts\n }\n\n return opts\n}\n\nexport function isRedirect(obj: any): obj is AnyRedirect {\n return !!obj?.isRedirect\n}\n\nexport function isResolvedRedirect(obj: any): obj is ResolvedRedirect {\n return !!obj?.isRedirect && obj.href\n}\n"],"names":[],"mappings":"AAoDO,SAAS,SAOd,MACmD;AACjD,OAAa,aAAa;AAC5B,OAAK,aAAa,KAAK,cAAc,KAAK,QAAQ;AAC7C,OAAA,UAAU,KAAK,WAAW,CAAC;AAC5B,MAAA,CAAC,KAAK,gBAAgB;AACxB,SAAK,iBAAiB;AAClB,QAAA;AACF,UAAI,IAAI,GAAG,KAAK,IAAI,EAAE;AACtB,WAAK,iBAAiB;AAAA,IAAA,QAChB;AAAA,IAAA;AAAA,EAAC;AAGX,MAAI,KAAK,OAAO;AACR,UAAA;AAAA,EAAA;AAGD,SAAA;AACT;AAEO,SAAS,WAAW,KAA8B;AAChD,SAAA,CAAC,EAAC,2BAAK;AAChB;AAEO,SAAS,mBAAmB,KAAmC;AACpE,SAAO,CAAC,EAAC,2BAAK,eAAc,IAAI;AAClC;"}
|
||||
@@ -0,0 +1,475 @@
|
||||
/**
|
||||
* @fileoverview A utility for retrying failed async method calls.
|
||||
*/
|
||||
|
||||
/* global setTimeout, clearTimeout */
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Constants
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
const MAX_TASK_TIMEOUT = 60000;
|
||||
const MAX_TASK_DELAY = 100;
|
||||
const MAX_CONCURRENCY = 1000;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Helpers
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Logs a message to the console if the DEBUG environment variable is set.
|
||||
* @param {string} message The message to log.
|
||||
* @returns {void}
|
||||
*/
|
||||
function debug(message) {
|
||||
if (globalThis?.process?.env.DEBUG === "@hwc/retry") {
|
||||
console.debug(message);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* The following logic has been extracted from graceful-fs.
|
||||
*
|
||||
* The ISC License
|
||||
*
|
||||
* Copyright (c) 2011-2023 Isaac Z. Schlueter, Ben Noordhuis, and Contributors
|
||||
*
|
||||
* Permission to use, copy, modify, and/or distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
|
||||
* IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Checks if it is time to retry a task based on the timestamp and last attempt time.
|
||||
* @param {RetryTask} task The task to check.
|
||||
* @param {number} maxDelay The maximum delay for the queue.
|
||||
* @returns {boolean} true if it is time to retry, false otherwise.
|
||||
*/
|
||||
function isTimeToRetry(task, maxDelay) {
|
||||
const timeSinceLastAttempt = Date.now() - task.lastAttempt;
|
||||
const timeSinceStart = Math.max(task.lastAttempt - task.timestamp, 1);
|
||||
const desiredDelay = Math.min(timeSinceStart * 1.2, maxDelay);
|
||||
|
||||
return timeSinceLastAttempt >= desiredDelay;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if it is time to bail out based on the given timestamp.
|
||||
* @param {RetryTask} task The task to check.
|
||||
* @param {number} timeout The timeout for the queue.
|
||||
* @returns {boolean} true if it is time to bail, false otherwise.
|
||||
*/
|
||||
function isTimeToBail(task, timeout) {
|
||||
return task.age > timeout;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new promise with resolve and reject functions.
|
||||
* @returns {{promise:Promise<any>, resolve:(value:any) => any, reject: (value:any) => any}} A new promise.
|
||||
*/
|
||||
function createPromise() {
|
||||
if (Promise.withResolvers) {
|
||||
return Promise.withResolvers();
|
||||
}
|
||||
|
||||
let resolve, reject;
|
||||
|
||||
const promise = new Promise((res, rej) => {
|
||||
resolve = res;
|
||||
reject = rej;
|
||||
});
|
||||
|
||||
if (resolve === undefined || reject === undefined) {
|
||||
throw new Error("Promise executor did not initialize resolve or reject.");
|
||||
}
|
||||
|
||||
return { promise, resolve, reject };
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* A class to represent a task in the retry queue.
|
||||
*/
|
||||
class RetryTask {
|
||||
|
||||
/**
|
||||
* The unique ID for the task.
|
||||
* @type {string}
|
||||
*/
|
||||
id = Math.random().toString(36).slice(2);
|
||||
|
||||
/**
|
||||
* The function to call.
|
||||
* @type {Function}
|
||||
*/
|
||||
fn;
|
||||
|
||||
/**
|
||||
* The error that was thrown.
|
||||
* @type {Error}
|
||||
*/
|
||||
error;
|
||||
|
||||
/**
|
||||
* The timestamp of the task.
|
||||
* @type {number}
|
||||
*/
|
||||
timestamp = Date.now();
|
||||
|
||||
/**
|
||||
* The timestamp of the last attempt.
|
||||
* @type {number}
|
||||
*/
|
||||
lastAttempt = this.timestamp;
|
||||
|
||||
/**
|
||||
* The resolve function for the promise.
|
||||
* @type {Function}
|
||||
*/
|
||||
resolve;
|
||||
|
||||
/**
|
||||
* The reject function for the promise.
|
||||
* @type {Function}
|
||||
*/
|
||||
reject;
|
||||
|
||||
/**
|
||||
* The AbortSignal to monitor for cancellation.
|
||||
* @type {AbortSignal|undefined}
|
||||
*/
|
||||
signal;
|
||||
|
||||
/**
|
||||
* Creates a new instance.
|
||||
* @param {Function} fn The function to call.
|
||||
* @param {Error} error The error that was thrown.
|
||||
* @param {Function} resolve The resolve function for the promise.
|
||||
* @param {Function} reject The reject function for the promise.
|
||||
* @param {AbortSignal|undefined} signal The AbortSignal to monitor for cancellation.
|
||||
*/
|
||||
constructor(fn, error, resolve, reject, signal) {
|
||||
this.fn = fn;
|
||||
this.error = error;
|
||||
this.timestamp = Date.now();
|
||||
this.lastAttempt = Date.now();
|
||||
this.resolve = resolve;
|
||||
this.reject = reject;
|
||||
this.signal = signal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the age of the task.
|
||||
* @returns {number} The age of the task in milliseconds.
|
||||
* @readonly
|
||||
*/
|
||||
get age() {
|
||||
return Date.now() - this.timestamp;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Exports
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* A class that manages a queue of retry jobs.
|
||||
*/
|
||||
class Retrier {
|
||||
|
||||
/**
|
||||
* Represents the queue for processing tasks.
|
||||
* @type {Array<RetryTask>}
|
||||
*/
|
||||
#retrying = [];
|
||||
|
||||
/**
|
||||
* Represents the queue for pending tasks.
|
||||
* @type {Array<Function>}
|
||||
*/
|
||||
#pending = [];
|
||||
|
||||
/**
|
||||
* The number of tasks currently being processed.
|
||||
* @type {number}
|
||||
*/
|
||||
#working = 0;
|
||||
|
||||
/**
|
||||
* The timeout for the queue.
|
||||
* @type {number}
|
||||
*/
|
||||
#timeout;
|
||||
|
||||
/**
|
||||
* The maximum delay for the queue.
|
||||
* @type {number}
|
||||
*/
|
||||
#maxDelay;
|
||||
|
||||
/**
|
||||
* The setTimeout() timer ID.
|
||||
* @type {NodeJS.Timeout|undefined}
|
||||
*/
|
||||
#timerId;
|
||||
|
||||
/**
|
||||
* The function to call.
|
||||
* @type {Function}
|
||||
*/
|
||||
#check;
|
||||
|
||||
/**
|
||||
* The maximum number of concurrent tasks.
|
||||
* @type {number}
|
||||
*/
|
||||
#concurrency;
|
||||
|
||||
/**
|
||||
* Creates a new instance.
|
||||
* @param {Function} check The function to call.
|
||||
* @param {object} [options] The options for the instance.
|
||||
* @param {number} [options.timeout] The timeout for the queue.
|
||||
* @param {number} [options.maxDelay] The maximum delay for the queue.
|
||||
* @param {number} [options.concurrency] The maximum number of concurrent tasks.
|
||||
*/
|
||||
constructor(check, { timeout = MAX_TASK_TIMEOUT, maxDelay = MAX_TASK_DELAY, concurrency = MAX_CONCURRENCY } = {}) {
|
||||
|
||||
if (typeof check !== "function") {
|
||||
throw new Error("Missing function to check errors");
|
||||
}
|
||||
|
||||
this.#check = check;
|
||||
this.#timeout = timeout;
|
||||
this.#maxDelay = maxDelay;
|
||||
this.#concurrency = concurrency;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the number of tasks waiting to be retried.
|
||||
* @returns {number} The number of tasks in the retry queue.
|
||||
*/
|
||||
get retrying() {
|
||||
return this.#retrying.length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the number of tasks waiting to be processed in the pending queue.
|
||||
* @returns {number} The number of tasks in the pending queue.
|
||||
*/
|
||||
get pending() {
|
||||
return this.#pending.length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the number of tasks currently being processed.
|
||||
* @returns {number} The number of tasks currently being processed.
|
||||
*/
|
||||
get working() {
|
||||
return this.#working;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls the function and retries if it fails.
|
||||
* @param {Function} fn The function to call.
|
||||
* @param {Object} options The options for the job.
|
||||
* @param {AbortSignal} [options.signal] The AbortSignal to monitor for cancellation.
|
||||
* @param {Promise<any>} options.promise The promise to return when the function settles.
|
||||
* @param {Function} options.resolve The resolve function for the promise.
|
||||
* @param {Function} options.reject The reject function for the promise.
|
||||
* @returns {Promise<any>} A promise that resolves when the function is
|
||||
* called successfully.
|
||||
*/
|
||||
#call(fn, { signal, promise, resolve, reject }) {
|
||||
|
||||
let result;
|
||||
|
||||
try {
|
||||
result = fn();
|
||||
} catch (/** @type {any} */ error) {
|
||||
reject(new Error(`Synchronous error: ${error.message}`, { cause: error }));
|
||||
return promise;
|
||||
}
|
||||
|
||||
// if the result is not a promise then reject an error
|
||||
if (!result || typeof result.then !== "function") {
|
||||
reject(new Error("Result is not a promise."));
|
||||
return promise;
|
||||
}
|
||||
|
||||
this.#working++;
|
||||
promise.finally(() => {
|
||||
this.#working--;
|
||||
this.#processPending();
|
||||
})
|
||||
// `promise.finally` creates a new promise that may be rejected, so it must be handled.
|
||||
.catch(() => { });
|
||||
|
||||
// call the original function and catch any ENFILE or EMFILE errors
|
||||
Promise.resolve(result)
|
||||
.then(value => {
|
||||
debug("Function called successfully without retry.");
|
||||
resolve(value);
|
||||
})
|
||||
.catch(error => {
|
||||
if (!this.#check(error)) {
|
||||
reject(error);
|
||||
return;
|
||||
}
|
||||
|
||||
const task = new RetryTask(fn, error, resolve, reject, signal);
|
||||
|
||||
debug(`Function failed, queuing for retry with task ${task.id}.`);
|
||||
this.#retrying.push(task);
|
||||
|
||||
signal?.addEventListener("abort", () => {
|
||||
debug(`Task ${task.id} was aborted due to AbortSignal.`);
|
||||
reject(signal.reason);
|
||||
});
|
||||
|
||||
this.#processQueue();
|
||||
});
|
||||
|
||||
return promise;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new retry job to the queue.
|
||||
* @param {Function} fn The function to call.
|
||||
* @param {object} [options] The options for the job.
|
||||
* @param {AbortSignal} [options.signal] The AbortSignal to monitor for cancellation.
|
||||
* @returns {Promise<any>} A promise that resolves when the queue is
|
||||
* processed.
|
||||
*/
|
||||
retry(fn, { signal } = {}) {
|
||||
|
||||
signal?.throwIfAborted();
|
||||
|
||||
const { promise, resolve, reject } = createPromise();
|
||||
|
||||
this.#pending.push(() => this.#call(fn, { signal, promise, resolve, reject }));
|
||||
this.#processPending();
|
||||
|
||||
return promise;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Processes the pending queue and the retry queue.
|
||||
* @returns {void}
|
||||
*/
|
||||
#processAll() {
|
||||
if (this.pending) {
|
||||
this.#processPending();
|
||||
}
|
||||
|
||||
if (this.retrying) {
|
||||
this.#processQueue();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes the pending queue to see which tasks can be started.
|
||||
* @returns {void}
|
||||
*/
|
||||
#processPending() {
|
||||
|
||||
debug(`Processing pending tasks: ${this.pending} pending, ${this.working} working.`);
|
||||
|
||||
const available = this.#concurrency - this.working;
|
||||
|
||||
if (available <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
const count = Math.min(this.pending, available);
|
||||
|
||||
for (let i = 0; i < count; i++) {
|
||||
const task = this.#pending.shift();
|
||||
task?.();
|
||||
}
|
||||
|
||||
debug(`Processed pending tasks: ${this.pending} pending, ${this.working} working.`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes the queue.
|
||||
* @returns {void}
|
||||
*/
|
||||
#processQueue() {
|
||||
// clear any timer because we're going to check right now
|
||||
clearTimeout(this.#timerId);
|
||||
this.#timerId = undefined;
|
||||
|
||||
debug(`Processing retry queue: ${this.retrying} retrying, ${this.working} working.`);
|
||||
|
||||
const processAgain = () => {
|
||||
this.#timerId = setTimeout(() => this.#processAll(), 0);
|
||||
};
|
||||
|
||||
// if there's nothing in the queue, we're done
|
||||
const task = this.#retrying.shift();
|
||||
if (!task) {
|
||||
debug("Queue is empty, exiting.");
|
||||
|
||||
if (this.pending) {
|
||||
processAgain();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// if it's time to bail, then bail
|
||||
if (isTimeToBail(task, this.#timeout)) {
|
||||
debug(`Task ${task.id} was abandoned due to timeout.`);
|
||||
task.reject(task.error);
|
||||
processAgain();
|
||||
return;
|
||||
}
|
||||
|
||||
// if it's not time to retry, then wait and try again
|
||||
if (!isTimeToRetry(task, this.#maxDelay)) {
|
||||
debug(`Task ${task.id} is not ready to retry, skipping.`);
|
||||
this.#retrying.push(task);
|
||||
processAgain();
|
||||
return;
|
||||
}
|
||||
|
||||
// otherwise, try again
|
||||
task.lastAttempt = Date.now();
|
||||
|
||||
// Promise.resolve needed in case it's a thenable but not a Promise
|
||||
Promise.resolve(task.fn())
|
||||
// @ts-ignore because we know it's any
|
||||
.then(result => {
|
||||
debug(`Task ${task.id} succeeded after ${task.age}ms.`);
|
||||
task.resolve(result);
|
||||
})
|
||||
|
||||
// @ts-ignore because we know it's any
|
||||
.catch(error => {
|
||||
if (!this.#check(error)) {
|
||||
debug(`Task ${task.id} failed with non-retryable error: ${error.message}.`);
|
||||
task.reject(error);
|
||||
return;
|
||||
}
|
||||
|
||||
// update the task timestamp and push to back of queue to try again
|
||||
task.lastAttempt = Date.now();
|
||||
this.#retrying.push(task);
|
||||
debug(`Task ${task.id} failed, requeueing to try again.`);
|
||||
})
|
||||
.finally(() => {
|
||||
this.#processAll();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export { Retrier };
|
||||
@@ -0,0 +1,96 @@
|
||||
/**
|
||||
* @fileoverview Common helpers for naming of plugins, formatters and configs
|
||||
*/
|
||||
|
||||
const NAMESPACE_REGEX = /^@.*\//iu;
|
||||
|
||||
/**
|
||||
* Brings package name to correct format based on prefix
|
||||
* @param {string} name The name of the package.
|
||||
* @param {string} prefix Can be either "eslint-plugin", "eslint-config" or "eslint-formatter"
|
||||
* @returns {string} Normalized name of the package
|
||||
* @private
|
||||
*/
|
||||
function normalizePackageName(name, prefix) {
|
||||
let normalizedName = name;
|
||||
|
||||
/**
|
||||
* On Windows, name can come in with Windows slashes instead of Unix slashes.
|
||||
* Normalize to Unix first to avoid errors later on.
|
||||
* https://github.com/eslint/eslint/issues/5644
|
||||
*/
|
||||
if (normalizedName.includes("\\")) {
|
||||
normalizedName = normalizedName.replace(/\\/gu, "/");
|
||||
}
|
||||
|
||||
if (normalizedName.charAt(0) === "@") {
|
||||
|
||||
/**
|
||||
* it's a scoped package
|
||||
* package name is the prefix, or just a username
|
||||
*/
|
||||
const scopedPackageShortcutRegex = new RegExp(`^(@[^/]+)(?:/(?:${prefix})?)?$`, "u"),
|
||||
scopedPackageNameRegex = new RegExp(`^${prefix}(-|$)`, "u");
|
||||
|
||||
if (scopedPackageShortcutRegex.test(normalizedName)) {
|
||||
normalizedName = normalizedName.replace(scopedPackageShortcutRegex, `$1/${prefix}`);
|
||||
} else if (!scopedPackageNameRegex.test(normalizedName.split("/")[1])) {
|
||||
|
||||
/**
|
||||
* for scoped packages, insert the prefix after the first / unless
|
||||
* the path is already @scope/eslint or @scope/eslint-xxx-yyy
|
||||
*/
|
||||
normalizedName = normalizedName.replace(/^@([^/]+)\/(.*)$/u, `@$1/${prefix}-$2`);
|
||||
}
|
||||
} else if (!normalizedName.startsWith(`${prefix}-`)) {
|
||||
normalizedName = `${prefix}-${normalizedName}`;
|
||||
}
|
||||
|
||||
return normalizedName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the prefix from a fullname.
|
||||
* @param {string} fullname The term which may have the prefix.
|
||||
* @param {string} prefix The prefix to remove.
|
||||
* @returns {string} The term without prefix.
|
||||
*/
|
||||
function getShorthandName(fullname, prefix) {
|
||||
if (fullname[0] === "@") {
|
||||
let matchResult = new RegExp(`^(@[^/]+)/${prefix}$`, "u").exec(fullname);
|
||||
|
||||
if (matchResult) {
|
||||
return matchResult[1];
|
||||
}
|
||||
|
||||
matchResult = new RegExp(`^(@[^/]+)/${prefix}-(.+)$`, "u").exec(fullname);
|
||||
if (matchResult) {
|
||||
return `${matchResult[1]}/${matchResult[2]}`;
|
||||
}
|
||||
} else if (fullname.startsWith(`${prefix}-`)) {
|
||||
return fullname.slice(prefix.length + 1);
|
||||
}
|
||||
|
||||
return fullname;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the scope (namespace) of a term.
|
||||
* @param {string} term The term which may have the namespace.
|
||||
* @returns {string} The namespace of the term if it has one.
|
||||
*/
|
||||
function getNamespaceFromTerm(term) {
|
||||
const match = term.match(NAMESPACE_REGEX);
|
||||
|
||||
return match ? match[0] : "";
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Public Interface
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
export {
|
||||
normalizePackageName,
|
||||
getShorthandName,
|
||||
getNamespaceFromTerm
|
||||
};
|
||||
@@ -0,0 +1,6 @@
|
||||
# caniuse-lite
|
||||
|
||||
A smaller version of caniuse-db, with only the essentials!
|
||||
|
||||
## Docs
|
||||
Read full docs **[here](https://github.com/browserslist/caniuse-lite#readme)**.
|
||||
@@ -0,0 +1,590 @@
|
||||
/**
|
||||
* @author Toru Nagashima <https://github.com/mysticatea>
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
const {
|
||||
CALL,
|
||||
CONSTRUCT,
|
||||
ReferenceTracker,
|
||||
getStaticValue,
|
||||
getStringIfConstant,
|
||||
} = require("@eslint-community/eslint-utils");
|
||||
const { RegExpParser, visitRegExpAST } = require("@eslint-community/regexpp");
|
||||
const {
|
||||
isCombiningCharacter,
|
||||
isEmojiModifier,
|
||||
isRegionalIndicatorSymbol,
|
||||
isSurrogatePair,
|
||||
} = require("./utils/unicode");
|
||||
const astUtils = require("./utils/ast-utils.js");
|
||||
const { isValidWithUnicodeFlag } = require("./utils/regular-expressions");
|
||||
const {
|
||||
parseStringLiteral,
|
||||
parseTemplateToken,
|
||||
} = require("./utils/char-source");
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Helpers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* @typedef {import('@eslint-community/regexpp').AST.Character} Character
|
||||
* @typedef {import('@eslint-community/regexpp').AST.CharacterClassElement} CharacterClassElement
|
||||
*/
|
||||
|
||||
/**
|
||||
* Iterate character sequences of a given nodes.
|
||||
*
|
||||
* CharacterClassRange syntax can steal a part of character sequence,
|
||||
* so this function reverts CharacterClassRange syntax and restore the sequence.
|
||||
* @param {CharacterClassElement[]} nodes The node list to iterate character sequences.
|
||||
* @returns {IterableIterator<Character[]>} The list of character sequences.
|
||||
*/
|
||||
function* iterateCharacterSequence(nodes) {
|
||||
/** @type {Character[]} */
|
||||
let seq = [];
|
||||
|
||||
for (const node of nodes) {
|
||||
switch (node.type) {
|
||||
case "Character":
|
||||
seq.push(node);
|
||||
break;
|
||||
|
||||
case "CharacterClassRange":
|
||||
seq.push(node.min);
|
||||
yield seq;
|
||||
seq = [node.max];
|
||||
break;
|
||||
|
||||
case "CharacterSet":
|
||||
case "CharacterClass": // [[]] nesting character class
|
||||
case "ClassStringDisjunction": // \q{...}
|
||||
case "ExpressionCharacterClass": // [A--B]
|
||||
if (seq.length > 0) {
|
||||
yield seq;
|
||||
seq = [];
|
||||
}
|
||||
break;
|
||||
|
||||
// no default
|
||||
}
|
||||
}
|
||||
|
||||
if (seq.length > 0) {
|
||||
yield seq;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the given character node is a Unicode code point escape or not.
|
||||
* @param {Character} char the character node to check.
|
||||
* @returns {boolean} `true` if the character node is a Unicode code point escape.
|
||||
*/
|
||||
function isUnicodeCodePointEscape(char) {
|
||||
return /^\\u\{[\da-f]+\}$/iu.test(char.raw);
|
||||
}
|
||||
|
||||
/**
|
||||
* Each function returns matched characters if it detects that kind of problem.
|
||||
* @type {Record<string, (chars: Character[]) => IterableIterator<Character[]>>}
|
||||
*/
|
||||
const findCharacterSequences = {
|
||||
*surrogatePairWithoutUFlag(chars) {
|
||||
for (const [index, char] of chars.entries()) {
|
||||
const previous = chars[index - 1];
|
||||
|
||||
if (
|
||||
previous &&
|
||||
char &&
|
||||
isSurrogatePair(previous.value, char.value) &&
|
||||
!isUnicodeCodePointEscape(previous) &&
|
||||
!isUnicodeCodePointEscape(char)
|
||||
) {
|
||||
yield [previous, char];
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
*surrogatePair(chars) {
|
||||
for (const [index, char] of chars.entries()) {
|
||||
const previous = chars[index - 1];
|
||||
|
||||
if (
|
||||
previous &&
|
||||
char &&
|
||||
isSurrogatePair(previous.value, char.value) &&
|
||||
(isUnicodeCodePointEscape(previous) ||
|
||||
isUnicodeCodePointEscape(char))
|
||||
) {
|
||||
yield [previous, char];
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
*combiningClass(chars, unfilteredChars) {
|
||||
/*
|
||||
* When `allowEscape` is `true`, a combined character should only be allowed if the combining mark appears as an escape sequence.
|
||||
* This means that the base character should be considered even if it's escaped.
|
||||
*/
|
||||
for (const [index, char] of chars.entries()) {
|
||||
const previous = unfilteredChars[index - 1];
|
||||
|
||||
if (
|
||||
previous &&
|
||||
char &&
|
||||
isCombiningCharacter(char.value) &&
|
||||
!isCombiningCharacter(previous.value)
|
||||
) {
|
||||
yield [previous, char];
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
*emojiModifier(chars) {
|
||||
for (const [index, char] of chars.entries()) {
|
||||
const previous = chars[index - 1];
|
||||
|
||||
if (
|
||||
previous &&
|
||||
char &&
|
||||
isEmojiModifier(char.value) &&
|
||||
!isEmojiModifier(previous.value)
|
||||
) {
|
||||
yield [previous, char];
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
*regionalIndicatorSymbol(chars) {
|
||||
for (const [index, char] of chars.entries()) {
|
||||
const previous = chars[index - 1];
|
||||
|
||||
if (
|
||||
previous &&
|
||||
char &&
|
||||
isRegionalIndicatorSymbol(char.value) &&
|
||||
isRegionalIndicatorSymbol(previous.value)
|
||||
) {
|
||||
yield [previous, char];
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
*zwj(chars) {
|
||||
let sequence = null;
|
||||
|
||||
for (const [index, char] of chars.entries()) {
|
||||
const previous = chars[index - 1];
|
||||
const next = chars[index + 1];
|
||||
|
||||
if (
|
||||
previous &&
|
||||
char &&
|
||||
next &&
|
||||
char.value === 0x200d &&
|
||||
previous.value !== 0x200d &&
|
||||
next.value !== 0x200d
|
||||
) {
|
||||
if (sequence) {
|
||||
if (sequence.at(-1) === previous) {
|
||||
sequence.push(char, next); // append to the sequence
|
||||
} else {
|
||||
yield sequence;
|
||||
sequence = chars.slice(index - 1, index + 2);
|
||||
}
|
||||
} else {
|
||||
sequence = chars.slice(index - 1, index + 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (sequence) {
|
||||
yield sequence;
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
const kinds = Object.keys(findCharacterSequences);
|
||||
|
||||
/**
|
||||
* Gets the value of the given node if it's a static value other than a regular expression object,
|
||||
* or the node's `regex` property.
|
||||
* The purpose of this method is to provide a replacement for `getStaticValue` in environments where certain regular expressions cannot be evaluated.
|
||||
* A known example is Node.js 18 which does not support the `v` flag.
|
||||
* Calling `getStaticValue` on a regular expression node with the `v` flag on Node.js 18 always returns `null`.
|
||||
* A limitation of this method is that it can only detect a regular expression if the specified node is itself a regular expression literal node.
|
||||
* @param {ASTNode | undefined} node The node to be inspected.
|
||||
* @param {Scope} initialScope Scope to start finding variables. This function tries to resolve identifier references which are in the given scope.
|
||||
* @returns {{ value: any } | { regex: { pattern: string, flags: string } } | null} The static value of the node, or `null`.
|
||||
*/
|
||||
function getStaticValueOrRegex(node, initialScope) {
|
||||
if (!node) {
|
||||
return null;
|
||||
}
|
||||
if (node.type === "Literal" && node.regex) {
|
||||
return { regex: node.regex };
|
||||
}
|
||||
|
||||
const staticValue = getStaticValue(node, initialScope);
|
||||
|
||||
if (staticValue?.value instanceof RegExp) {
|
||||
return null;
|
||||
}
|
||||
return staticValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether a specified regexpp character is represented as an acceptable escape sequence.
|
||||
* This function requires the source text of the character to be known.
|
||||
* @param {Character} char Character to check.
|
||||
* @param {string} charSource Source text of the character to check.
|
||||
* @returns {boolean} Whether the specified regexpp character is represented as an acceptable escape sequence.
|
||||
*/
|
||||
function checkForAcceptableEscape(char, charSource) {
|
||||
if (!charSource.startsWith("\\")) {
|
||||
return false;
|
||||
}
|
||||
const match = /(?<=^\\+).$/su.exec(charSource);
|
||||
|
||||
return match?.[0] !== String.fromCodePoint(char.value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether a specified regexpp character is represented as an acceptable escape sequence.
|
||||
* This function works with characters that are produced by a string or template literal.
|
||||
* It requires the source text and the CodeUnit list of the literal to be known.
|
||||
* @param {Character} char Character to check.
|
||||
* @param {string} nodeSource Source text of the string or template literal that produces the character.
|
||||
* @param {CodeUnit[]} codeUnits List of CodeUnit objects of the literal that produces the character.
|
||||
* @returns {boolean} Whether the specified regexpp character is represented as an acceptable escape sequence.
|
||||
*/
|
||||
function checkForAcceptableEscapeInString(char, nodeSource, codeUnits) {
|
||||
const firstIndex = char.start;
|
||||
const lastIndex = char.end - 1;
|
||||
const start = codeUnits[firstIndex].start;
|
||||
const end = codeUnits[lastIndex].end;
|
||||
const charSource = nodeSource.slice(start, end);
|
||||
|
||||
return checkForAcceptableEscape(char, charSource);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Rule Definition
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/** @type {import('../shared/types').Rule} */
|
||||
module.exports = {
|
||||
meta: {
|
||||
type: "problem",
|
||||
|
||||
docs: {
|
||||
description:
|
||||
"Disallow characters which are made with multiple code points in character class syntax",
|
||||
recommended: true,
|
||||
url: "https://eslint.org/docs/latest/rules/no-misleading-character-class",
|
||||
},
|
||||
|
||||
hasSuggestions: true,
|
||||
|
||||
schema: [
|
||||
{
|
||||
type: "object",
|
||||
properties: {
|
||||
allowEscape: {
|
||||
type: "boolean",
|
||||
default: false,
|
||||
},
|
||||
},
|
||||
additionalProperties: false,
|
||||
},
|
||||
],
|
||||
|
||||
messages: {
|
||||
surrogatePairWithoutUFlag:
|
||||
"Unexpected surrogate pair in character class. Use 'u' flag.",
|
||||
surrogatePair: "Unexpected surrogate pair in character class.",
|
||||
combiningClass: "Unexpected combined character in character class.",
|
||||
emojiModifier: "Unexpected modified Emoji in character class.",
|
||||
regionalIndicatorSymbol:
|
||||
"Unexpected national flag in character class.",
|
||||
zwj: "Unexpected joined character sequence in character class.",
|
||||
suggestUnicodeFlag: "Add unicode 'u' flag to regex.",
|
||||
},
|
||||
},
|
||||
create(context) {
|
||||
const allowEscape = context.options[0]?.allowEscape;
|
||||
const sourceCode = context.sourceCode;
|
||||
const parser = new RegExpParser();
|
||||
const checkedPatternNodes = new Set();
|
||||
|
||||
/**
|
||||
* Verify a given regular expression.
|
||||
* @param {Node} node The node to report.
|
||||
* @param {string} pattern The regular expression pattern to verify.
|
||||
* @param {string} flags The flags of the regular expression.
|
||||
* @param {Function} unicodeFixer Fixer for missing "u" flag.
|
||||
* @returns {void}
|
||||
*/
|
||||
function verify(node, pattern, flags, unicodeFixer) {
|
||||
let patternNode;
|
||||
|
||||
try {
|
||||
patternNode = parser.parsePattern(pattern, 0, pattern.length, {
|
||||
unicode: flags.includes("u"),
|
||||
unicodeSets: flags.includes("v"),
|
||||
});
|
||||
} catch {
|
||||
// Ignore regular expressions with syntax errors
|
||||
return;
|
||||
}
|
||||
|
||||
let codeUnits = null;
|
||||
|
||||
/**
|
||||
* Checks whether a specified regexpp character is represented as an acceptable escape sequence.
|
||||
* For the purposes of this rule, an escape sequence is considered acceptable if it consists of one or more backslashes followed by the character being escaped.
|
||||
* @param {Character} char Character to check.
|
||||
* @returns {boolean} Whether the specified regexpp character is represented as an acceptable escape sequence.
|
||||
*/
|
||||
function isAcceptableEscapeSequence(char) {
|
||||
if (node.type === "Literal" && node.regex) {
|
||||
return checkForAcceptableEscape(char, char.raw);
|
||||
}
|
||||
if (node.type === "Literal" && typeof node.value === "string") {
|
||||
const nodeSource = node.raw;
|
||||
|
||||
codeUnits ??= parseStringLiteral(nodeSource);
|
||||
|
||||
return checkForAcceptableEscapeInString(
|
||||
char,
|
||||
nodeSource,
|
||||
codeUnits,
|
||||
);
|
||||
}
|
||||
if (astUtils.isStaticTemplateLiteral(node)) {
|
||||
const nodeSource = sourceCode.getText(node);
|
||||
|
||||
codeUnits ??= parseTemplateToken(nodeSource);
|
||||
|
||||
return checkForAcceptableEscapeInString(
|
||||
char,
|
||||
nodeSource,
|
||||
codeUnits,
|
||||
);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
const foundKindMatches = new Map();
|
||||
|
||||
visitRegExpAST(patternNode, {
|
||||
onCharacterClassEnter(ccNode) {
|
||||
for (const unfilteredChars of iterateCharacterSequence(
|
||||
ccNode.elements,
|
||||
)) {
|
||||
let chars;
|
||||
|
||||
if (allowEscape) {
|
||||
// Replace escape sequences with null to avoid having them flagged.
|
||||
chars = unfilteredChars.map(char =>
|
||||
isAcceptableEscapeSequence(char) ? null : char,
|
||||
);
|
||||
} else {
|
||||
chars = unfilteredChars;
|
||||
}
|
||||
for (const kind of kinds) {
|
||||
const matches = findCharacterSequences[kind](
|
||||
chars,
|
||||
unfilteredChars,
|
||||
);
|
||||
|
||||
if (foundKindMatches.has(kind)) {
|
||||
foundKindMatches.get(kind).push(...matches);
|
||||
} else {
|
||||
foundKindMatches.set(kind, [...matches]);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
/**
|
||||
* Finds the report loc(s) for a range of matches.
|
||||
* Only literals and expression-less templates generate granular errors.
|
||||
* @param {Character[][]} matches Lists of individual characters being reported on.
|
||||
* @returns {Location[]} locs for context.report.
|
||||
* @see https://github.com/eslint/eslint/pull/17515
|
||||
*/
|
||||
function getNodeReportLocations(matches) {
|
||||
if (
|
||||
!astUtils.isStaticTemplateLiteral(node) &&
|
||||
node.type !== "Literal"
|
||||
) {
|
||||
return matches.length ? [node.loc] : [];
|
||||
}
|
||||
return matches.map(chars => {
|
||||
const firstIndex = chars[0].start;
|
||||
const lastIndex = chars.at(-1).end - 1;
|
||||
let start;
|
||||
let end;
|
||||
|
||||
if (node.type === "TemplateLiteral") {
|
||||
const source = sourceCode.getText(node);
|
||||
const offset = node.range[0];
|
||||
|
||||
codeUnits ??= parseTemplateToken(source);
|
||||
start = offset + codeUnits[firstIndex].start;
|
||||
end = offset + codeUnits[lastIndex].end;
|
||||
} else if (typeof node.value === "string") {
|
||||
// String Literal
|
||||
const source = node.raw;
|
||||
const offset = node.range[0];
|
||||
|
||||
codeUnits ??= parseStringLiteral(source);
|
||||
start = offset + codeUnits[firstIndex].start;
|
||||
end = offset + codeUnits[lastIndex].end;
|
||||
} else {
|
||||
// RegExp Literal
|
||||
const offset = node.range[0] + 1; // Add 1 to skip the leading slash.
|
||||
|
||||
start = offset + firstIndex;
|
||||
end = offset + lastIndex + 1;
|
||||
}
|
||||
|
||||
return {
|
||||
start: sourceCode.getLocFromIndex(start),
|
||||
end: sourceCode.getLocFromIndex(end),
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
for (const [kind, matches] of foundKindMatches) {
|
||||
let suggest;
|
||||
|
||||
if (kind === "surrogatePairWithoutUFlag") {
|
||||
suggest = [
|
||||
{
|
||||
messageId: "suggestUnicodeFlag",
|
||||
fix: unicodeFixer,
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
const locs = getNodeReportLocations(matches);
|
||||
|
||||
for (const loc of locs) {
|
||||
context.report({
|
||||
node,
|
||||
loc,
|
||||
messageId: kind,
|
||||
suggest,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
"Literal[regex]"(node) {
|
||||
if (checkedPatternNodes.has(node)) {
|
||||
return;
|
||||
}
|
||||
verify(node, node.regex.pattern, node.regex.flags, fixer => {
|
||||
if (
|
||||
!isValidWithUnicodeFlag(
|
||||
context.languageOptions.ecmaVersion,
|
||||
node.regex.pattern,
|
||||
)
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return fixer.insertTextAfter(node, "u");
|
||||
});
|
||||
},
|
||||
Program(node) {
|
||||
const scope = sourceCode.getScope(node);
|
||||
const tracker = new ReferenceTracker(scope);
|
||||
|
||||
/*
|
||||
* Iterate calls of RegExp.
|
||||
* E.g., `new RegExp()`, `RegExp()`, `new window.RegExp()`,
|
||||
* `const {RegExp: a} = window; new a()`, etc...
|
||||
*/
|
||||
for (const { node: refNode } of tracker.iterateGlobalReferences(
|
||||
{
|
||||
RegExp: { [CALL]: true, [CONSTRUCT]: true },
|
||||
},
|
||||
)) {
|
||||
let pattern, flags;
|
||||
const [patternNode, flagsNode] = refNode.arguments;
|
||||
const evaluatedPattern = getStaticValueOrRegex(
|
||||
patternNode,
|
||||
scope,
|
||||
);
|
||||
|
||||
if (!evaluatedPattern) {
|
||||
continue;
|
||||
}
|
||||
if (flagsNode) {
|
||||
if (evaluatedPattern.regex) {
|
||||
pattern = evaluatedPattern.regex.pattern;
|
||||
checkedPatternNodes.add(patternNode);
|
||||
} else {
|
||||
pattern = String(evaluatedPattern.value);
|
||||
}
|
||||
flags = getStringIfConstant(flagsNode, scope);
|
||||
} else {
|
||||
if (evaluatedPattern.regex) {
|
||||
continue;
|
||||
}
|
||||
pattern = String(evaluatedPattern.value);
|
||||
flags = "";
|
||||
}
|
||||
|
||||
if (typeof flags === "string") {
|
||||
verify(patternNode, pattern, flags, fixer => {
|
||||
if (
|
||||
!isValidWithUnicodeFlag(
|
||||
context.languageOptions.ecmaVersion,
|
||||
pattern,
|
||||
)
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (refNode.arguments.length === 1) {
|
||||
const penultimateToken =
|
||||
sourceCode.getLastToken(refNode, {
|
||||
skip: 1,
|
||||
}); // skip closing parenthesis
|
||||
|
||||
return fixer.insertTextAfter(
|
||||
penultimateToken,
|
||||
astUtils.isCommaToken(penultimateToken)
|
||||
? ' "u",'
|
||||
: ', "u"',
|
||||
);
|
||||
}
|
||||
|
||||
if (
|
||||
(flagsNode.type === "Literal" &&
|
||||
typeof flagsNode.value === "string") ||
|
||||
flagsNode.type === "TemplateLiteral"
|
||||
) {
|
||||
const range = [
|
||||
flagsNode.range[0],
|
||||
flagsNode.range[1] - 1,
|
||||
];
|
||||
|
||||
return fixer.insertTextAfterRange(range, "u");
|
||||
}
|
||||
|
||||
return null;
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,89 @@
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
|
||||
import makeCancellablePromise from './index.js';
|
||||
|
||||
vi.useFakeTimers();
|
||||
|
||||
describe('makeCancellablePromise()', () => {
|
||||
function resolveInFiveSeconds(): Promise<string> {
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(() => {
|
||||
resolve('Success');
|
||||
}, 5000);
|
||||
});
|
||||
}
|
||||
|
||||
function rejectInFiveSeconds() {
|
||||
return new Promise((resolve, reject) => {
|
||||
setTimeout(() => {
|
||||
reject(new Error('Error'));
|
||||
}, 5000);
|
||||
});
|
||||
}
|
||||
|
||||
it('resolves promise if not cancelled', async () => {
|
||||
const resolve = vi.fn();
|
||||
const reject = vi.fn();
|
||||
|
||||
const { promise } = makeCancellablePromise(resolveInFiveSeconds());
|
||||
|
||||
vi.advanceTimersByTime(5000);
|
||||
await promise.then(resolve).catch(reject);
|
||||
|
||||
expect(resolve).toHaveBeenCalledWith('Success');
|
||||
expect(reject).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('rejects promise if not cancelled', async () => {
|
||||
const resolve = vi.fn();
|
||||
const reject = vi.fn();
|
||||
|
||||
const { promise } = makeCancellablePromise(rejectInFiveSeconds());
|
||||
|
||||
vi.runAllTimers();
|
||||
await promise.then(resolve).catch(reject);
|
||||
|
||||
expect(resolve).not.toHaveBeenCalled();
|
||||
expect(reject).toHaveBeenCalledWith(expect.any(Error));
|
||||
});
|
||||
|
||||
it('does not resolve promise if cancelled', async () => {
|
||||
expect.assertions(0);
|
||||
|
||||
const resolve = vi.fn(() => {
|
||||
// Will fail because of expect.assertions(0);
|
||||
expect(true).toBe(true);
|
||||
});
|
||||
const reject = vi.fn(() => {
|
||||
// Will fail because of expect.assertions(0);
|
||||
expect(true).toBe(true);
|
||||
});
|
||||
|
||||
const { promise, cancel } = makeCancellablePromise(rejectInFiveSeconds());
|
||||
promise.then(resolve).catch(reject);
|
||||
|
||||
vi.advanceTimersByTime(2500);
|
||||
cancel();
|
||||
vi.advanceTimersByTime(2500);
|
||||
});
|
||||
|
||||
it('does not reject promise if cancelled', () => {
|
||||
expect.assertions(0);
|
||||
|
||||
const resolve = vi.fn(() => {
|
||||
// Will fail because of expect.assertions(0);
|
||||
expect(true).toBe(true);
|
||||
});
|
||||
const reject = vi.fn(() => {
|
||||
// Will fail because of expect.assertions(0);
|
||||
expect(true).toBe(true);
|
||||
});
|
||||
|
||||
const { promise, cancel } = makeCancellablePromise(rejectInFiveSeconds());
|
||||
promise.then(resolve).catch(reject);
|
||||
|
||||
vi.advanceTimersByTime(2500);
|
||||
cancel();
|
||||
vi.advanceTimersByTime(2500);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,373 @@
|
||||
[
|
||||
{
|
||||
"runtime": "node",
|
||||
"target": "11.0.0",
|
||||
"lts": false,
|
||||
"future": false,
|
||||
"abi": "67"
|
||||
},
|
||||
{
|
||||
"runtime": "node",
|
||||
"target": "12.0.0",
|
||||
"lts": [
|
||||
"2019-10-21",
|
||||
"2020-11-30"
|
||||
],
|
||||
"future": false,
|
||||
"abi": "72"
|
||||
},
|
||||
{
|
||||
"runtime": "node",
|
||||
"target": "13.0.0",
|
||||
"lts": false,
|
||||
"future": false,
|
||||
"abi": "79"
|
||||
},
|
||||
{
|
||||
"runtime": "node",
|
||||
"target": "14.0.0",
|
||||
"lts": [
|
||||
"2020-10-27",
|
||||
"2021-10-19"
|
||||
],
|
||||
"future": false,
|
||||
"abi": "83"
|
||||
},
|
||||
{
|
||||
"runtime": "node",
|
||||
"target": "15.0.0",
|
||||
"lts": false,
|
||||
"future": false,
|
||||
"abi": "88"
|
||||
},
|
||||
{
|
||||
"runtime": "node",
|
||||
"target": "16.0.0",
|
||||
"lts": [
|
||||
"2021-10-26",
|
||||
"2022-10-18"
|
||||
],
|
||||
"future": false,
|
||||
"abi": "93"
|
||||
},
|
||||
{
|
||||
"runtime": "node",
|
||||
"target": "17.0.0",
|
||||
"lts": false,
|
||||
"future": false,
|
||||
"abi": "102"
|
||||
},
|
||||
{
|
||||
"runtime": "node",
|
||||
"target": "18.0.0",
|
||||
"lts": [
|
||||
"2022-10-25",
|
||||
"2023-10-18"
|
||||
],
|
||||
"future": false,
|
||||
"abi": "108"
|
||||
},
|
||||
{
|
||||
"runtime": "node",
|
||||
"target": "19.0.0",
|
||||
"lts": false,
|
||||
"future": false,
|
||||
"abi": "111"
|
||||
},
|
||||
{
|
||||
"runtime": "node",
|
||||
"target": "20.0.0",
|
||||
"lts": [
|
||||
"2023-10-24",
|
||||
"2024-10-22"
|
||||
],
|
||||
"future": false,
|
||||
"abi": "115"
|
||||
},
|
||||
{
|
||||
"runtime": "node",
|
||||
"target": "21.0.0",
|
||||
"lts": false,
|
||||
"future": false,
|
||||
"abi": "120"
|
||||
},
|
||||
{
|
||||
"runtime": "node",
|
||||
"target": "22.0.0",
|
||||
"lts": [
|
||||
"2024-10-29",
|
||||
"2025-10-21"
|
||||
],
|
||||
"future": false,
|
||||
"abi": "127"
|
||||
},
|
||||
{
|
||||
"runtime": "node",
|
||||
"target": "23.0.0",
|
||||
"lts": false,
|
||||
"future": false,
|
||||
"abi": "131"
|
||||
},
|
||||
{
|
||||
"runtime": "node",
|
||||
"target": "24.0.0",
|
||||
"lts": [
|
||||
"2025-10-28",
|
||||
"2026-10-20"
|
||||
],
|
||||
"future": true,
|
||||
"abi": "134"
|
||||
},
|
||||
{
|
||||
"abi": "70",
|
||||
"future": false,
|
||||
"lts": false,
|
||||
"runtime": "electron",
|
||||
"target": "5.0.0-beta.9"
|
||||
},
|
||||
{
|
||||
"abi": "73",
|
||||
"future": false,
|
||||
"lts": false,
|
||||
"runtime": "electron",
|
||||
"target": "6.0.0-beta.1"
|
||||
},
|
||||
{
|
||||
"abi": "75",
|
||||
"future": false,
|
||||
"lts": false,
|
||||
"runtime": "electron",
|
||||
"target": "7.0.0-beta.1"
|
||||
},
|
||||
{
|
||||
"abi": "76",
|
||||
"future": false,
|
||||
"lts": false,
|
||||
"runtime": "electron",
|
||||
"target": "9.0.0-beta.1"
|
||||
},
|
||||
{
|
||||
"abi": "76",
|
||||
"future": false,
|
||||
"lts": false,
|
||||
"runtime": "electron",
|
||||
"target": "8.0.0-beta.1"
|
||||
},
|
||||
{
|
||||
"abi": "80",
|
||||
"future": false,
|
||||
"lts": false,
|
||||
"runtime": "electron",
|
||||
"target": "9.0.0-beta.2"
|
||||
},
|
||||
{
|
||||
"abi": "82",
|
||||
"future": false,
|
||||
"lts": false,
|
||||
"runtime": "electron",
|
||||
"target": "11.0.0-beta.1"
|
||||
},
|
||||
{
|
||||
"abi": "82",
|
||||
"future": false,
|
||||
"lts": false,
|
||||
"runtime": "electron",
|
||||
"target": "10.0.0-beta.1"
|
||||
},
|
||||
{
|
||||
"abi": "85",
|
||||
"future": false,
|
||||
"lts": false,
|
||||
"runtime": "electron",
|
||||
"target": "11.0.0-beta.11"
|
||||
},
|
||||
{
|
||||
"abi": "87",
|
||||
"future": false,
|
||||
"lts": false,
|
||||
"runtime": "electron",
|
||||
"target": "12.0.0-beta.1"
|
||||
},
|
||||
{
|
||||
"abi": "89",
|
||||
"future": false,
|
||||
"lts": false,
|
||||
"runtime": "electron",
|
||||
"target": "15.0.0-alpha.1"
|
||||
},
|
||||
{
|
||||
"abi": "89",
|
||||
"future": false,
|
||||
"lts": false,
|
||||
"runtime": "electron",
|
||||
"target": "14.0.0-beta.1"
|
||||
},
|
||||
{
|
||||
"abi": "89",
|
||||
"future": false,
|
||||
"lts": false,
|
||||
"runtime": "electron",
|
||||
"target": "13.0.0-beta.2"
|
||||
},
|
||||
{
|
||||
"abi": "97",
|
||||
"future": false,
|
||||
"lts": false,
|
||||
"runtime": "electron",
|
||||
"target": "14.0.2"
|
||||
},
|
||||
{
|
||||
"abi": "98",
|
||||
"future": false,
|
||||
"lts": false,
|
||||
"runtime": "electron",
|
||||
"target": "15.0.0-beta.7"
|
||||
},
|
||||
{
|
||||
"abi": "99",
|
||||
"future": false,
|
||||
"lts": false,
|
||||
"runtime": "electron",
|
||||
"target": "16.0.0-alpha.1"
|
||||
},
|
||||
{
|
||||
"abi": "101",
|
||||
"future": false,
|
||||
"lts": false,
|
||||
"runtime": "electron",
|
||||
"target": "17.0.0-alpha.1"
|
||||
},
|
||||
{
|
||||
"abi": "103",
|
||||
"future": false,
|
||||
"lts": false,
|
||||
"runtime": "electron",
|
||||
"target": "18.0.0-alpha.1"
|
||||
},
|
||||
{
|
||||
"abi": "106",
|
||||
"future": false,
|
||||
"lts": false,
|
||||
"runtime": "electron",
|
||||
"target": "19.0.0-alpha.1"
|
||||
},
|
||||
{
|
||||
"abi": "107",
|
||||
"future": false,
|
||||
"lts": false,
|
||||
"runtime": "electron",
|
||||
"target": "20.0.0-alpha.1"
|
||||
},
|
||||
{
|
||||
"abi": "109",
|
||||
"future": false,
|
||||
"lts": false,
|
||||
"runtime": "electron",
|
||||
"target": "21.0.0-alpha.1"
|
||||
},
|
||||
{
|
||||
"abi": "110",
|
||||
"future": false,
|
||||
"lts": false,
|
||||
"runtime": "electron",
|
||||
"target": "22.0.0-alpha.1"
|
||||
},
|
||||
{
|
||||
"abi": "113",
|
||||
"future": false,
|
||||
"lts": false,
|
||||
"runtime": "electron",
|
||||
"target": "23.0.0-alpha.1"
|
||||
},
|
||||
{
|
||||
"abi": "114",
|
||||
"future": false,
|
||||
"lts": false,
|
||||
"runtime": "electron",
|
||||
"target": "24.0.0-alpha.1"
|
||||
},
|
||||
{
|
||||
"abi": "116",
|
||||
"future": false,
|
||||
"lts": false,
|
||||
"runtime": "electron",
|
||||
"target": "26.0.0-alpha.1"
|
||||
},
|
||||
{
|
||||
"abi": "116",
|
||||
"future": false,
|
||||
"lts": false,
|
||||
"runtime": "electron",
|
||||
"target": "25.0.0-alpha.1"
|
||||
},
|
||||
{
|
||||
"abi": "118",
|
||||
"future": false,
|
||||
"lts": false,
|
||||
"runtime": "electron",
|
||||
"target": "27.0.0-alpha.1"
|
||||
},
|
||||
{
|
||||
"abi": "119",
|
||||
"future": false,
|
||||
"lts": false,
|
||||
"runtime": "electron",
|
||||
"target": "28.0.0-alpha.1"
|
||||
},
|
||||
{
|
||||
"abi": "121",
|
||||
"future": false,
|
||||
"lts": false,
|
||||
"runtime": "electron",
|
||||
"target": "29.0.0-alpha.1"
|
||||
},
|
||||
{
|
||||
"abi": "123",
|
||||
"future": false,
|
||||
"lts": false,
|
||||
"runtime": "electron",
|
||||
"target": "31.0.0-alpha.1"
|
||||
},
|
||||
{
|
||||
"abi": "123",
|
||||
"future": false,
|
||||
"lts": false,
|
||||
"runtime": "electron",
|
||||
"target": "30.0.0-alpha.1"
|
||||
},
|
||||
{
|
||||
"abi": "125",
|
||||
"future": false,
|
||||
"lts": false,
|
||||
"runtime": "electron",
|
||||
"target": "31.0.0-beta.7"
|
||||
},
|
||||
{
|
||||
"abi": "128",
|
||||
"future": false,
|
||||
"lts": false,
|
||||
"runtime": "electron",
|
||||
"target": "32.0.0-alpha.1"
|
||||
},
|
||||
{
|
||||
"abi": "130",
|
||||
"future": false,
|
||||
"lts": false,
|
||||
"runtime": "electron",
|
||||
"target": "33.0.0-alpha.1"
|
||||
},
|
||||
{
|
||||
"abi": "132",
|
||||
"future": false,
|
||||
"lts": false,
|
||||
"runtime": "electron",
|
||||
"target": "34.0.0-alpha.1"
|
||||
},
|
||||
{
|
||||
"abi": "133",
|
||||
"future": true,
|
||||
"lts": false,
|
||||
"runtime": "electron",
|
||||
"target": "35.0.0-alpha.1"
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,317 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
class Buffer {
|
||||
constructor(map, indentChar) {
|
||||
this._map = null;
|
||||
this._buf = "";
|
||||
this._str = "";
|
||||
this._appendCount = 0;
|
||||
this._last = 0;
|
||||
this._queue = [];
|
||||
this._queueCursor = 0;
|
||||
this._canMarkIdName = true;
|
||||
this._indentChar = "";
|
||||
this._fastIndentations = [];
|
||||
this._position = {
|
||||
line: 1,
|
||||
column: 0
|
||||
};
|
||||
this._sourcePosition = {
|
||||
identifierName: undefined,
|
||||
identifierNamePos: undefined,
|
||||
line: undefined,
|
||||
column: undefined,
|
||||
filename: undefined
|
||||
};
|
||||
this._map = map;
|
||||
this._indentChar = indentChar;
|
||||
for (let i = 0; i < 64; i++) {
|
||||
this._fastIndentations.push(indentChar.repeat(i));
|
||||
}
|
||||
this._allocQueue();
|
||||
}
|
||||
_allocQueue() {
|
||||
const queue = this._queue;
|
||||
for (let i = 0; i < 16; i++) {
|
||||
queue.push({
|
||||
char: 0,
|
||||
repeat: 1,
|
||||
line: undefined,
|
||||
column: undefined,
|
||||
identifierName: undefined,
|
||||
identifierNamePos: undefined,
|
||||
filename: ""
|
||||
});
|
||||
}
|
||||
}
|
||||
_pushQueue(char, repeat, line, column, filename) {
|
||||
const cursor = this._queueCursor;
|
||||
if (cursor === this._queue.length) {
|
||||
this._allocQueue();
|
||||
}
|
||||
const item = this._queue[cursor];
|
||||
item.char = char;
|
||||
item.repeat = repeat;
|
||||
item.line = line;
|
||||
item.column = column;
|
||||
item.filename = filename;
|
||||
this._queueCursor++;
|
||||
}
|
||||
_popQueue() {
|
||||
if (this._queueCursor === 0) {
|
||||
throw new Error("Cannot pop from empty queue");
|
||||
}
|
||||
return this._queue[--this._queueCursor];
|
||||
}
|
||||
get() {
|
||||
this._flush();
|
||||
const map = this._map;
|
||||
const result = {
|
||||
code: (this._buf + this._str).trimRight(),
|
||||
decodedMap: map == null ? void 0 : map.getDecoded(),
|
||||
get __mergedMap() {
|
||||
return this.map;
|
||||
},
|
||||
get map() {
|
||||
const resultMap = map ? map.get() : null;
|
||||
result.map = resultMap;
|
||||
return resultMap;
|
||||
},
|
||||
set map(value) {
|
||||
Object.defineProperty(result, "map", {
|
||||
value,
|
||||
writable: true
|
||||
});
|
||||
},
|
||||
get rawMappings() {
|
||||
const mappings = map == null ? void 0 : map.getRawMappings();
|
||||
result.rawMappings = mappings;
|
||||
return mappings;
|
||||
},
|
||||
set rawMappings(value) {
|
||||
Object.defineProperty(result, "rawMappings", {
|
||||
value,
|
||||
writable: true
|
||||
});
|
||||
}
|
||||
};
|
||||
return result;
|
||||
}
|
||||
append(str, maybeNewline) {
|
||||
this._flush();
|
||||
this._append(str, this._sourcePosition, maybeNewline);
|
||||
}
|
||||
appendChar(char) {
|
||||
this._flush();
|
||||
this._appendChar(char, 1, this._sourcePosition);
|
||||
}
|
||||
queue(char) {
|
||||
if (char === 10) {
|
||||
while (this._queueCursor !== 0) {
|
||||
const char = this._queue[this._queueCursor - 1].char;
|
||||
if (char !== 32 && char !== 9) {
|
||||
break;
|
||||
}
|
||||
this._queueCursor--;
|
||||
}
|
||||
}
|
||||
const sourcePosition = this._sourcePosition;
|
||||
this._pushQueue(char, 1, sourcePosition.line, sourcePosition.column, sourcePosition.filename);
|
||||
}
|
||||
queueIndentation(repeat) {
|
||||
if (repeat === 0) return;
|
||||
this._pushQueue(-1, repeat, undefined, undefined, undefined);
|
||||
}
|
||||
_flush() {
|
||||
const queueCursor = this._queueCursor;
|
||||
const queue = this._queue;
|
||||
for (let i = 0; i < queueCursor; i++) {
|
||||
const item = queue[i];
|
||||
this._appendChar(item.char, item.repeat, item);
|
||||
}
|
||||
this._queueCursor = 0;
|
||||
}
|
||||
_appendChar(char, repeat, sourcePos) {
|
||||
this._last = char;
|
||||
if (char === -1) {
|
||||
const fastIndentation = this._fastIndentations[repeat];
|
||||
if (fastIndentation !== undefined) {
|
||||
this._str += fastIndentation;
|
||||
} else {
|
||||
this._str += repeat > 1 ? this._indentChar.repeat(repeat) : this._indentChar;
|
||||
}
|
||||
} else {
|
||||
this._str += repeat > 1 ? String.fromCharCode(char).repeat(repeat) : String.fromCharCode(char);
|
||||
}
|
||||
if (char !== 10) {
|
||||
this._mark(sourcePos.line, sourcePos.column, sourcePos.identifierName, sourcePos.identifierNamePos, sourcePos.filename);
|
||||
this._position.column += repeat;
|
||||
} else {
|
||||
this._position.line++;
|
||||
this._position.column = 0;
|
||||
}
|
||||
if (this._canMarkIdName) {
|
||||
sourcePos.identifierName = undefined;
|
||||
sourcePos.identifierNamePos = undefined;
|
||||
}
|
||||
}
|
||||
_append(str, sourcePos, maybeNewline) {
|
||||
const len = str.length;
|
||||
const position = this._position;
|
||||
this._last = str.charCodeAt(len - 1);
|
||||
if (++this._appendCount > 4096) {
|
||||
+this._str;
|
||||
this._buf += this._str;
|
||||
this._str = str;
|
||||
this._appendCount = 0;
|
||||
} else {
|
||||
this._str += str;
|
||||
}
|
||||
if (!maybeNewline && !this._map) {
|
||||
position.column += len;
|
||||
return;
|
||||
}
|
||||
const {
|
||||
column,
|
||||
identifierName,
|
||||
identifierNamePos,
|
||||
filename
|
||||
} = sourcePos;
|
||||
let line = sourcePos.line;
|
||||
if ((identifierName != null || identifierNamePos != null) && this._canMarkIdName) {
|
||||
sourcePos.identifierName = undefined;
|
||||
sourcePos.identifierNamePos = undefined;
|
||||
}
|
||||
let i = str.indexOf("\n");
|
||||
let last = 0;
|
||||
if (i !== 0) {
|
||||
this._mark(line, column, identifierName, identifierNamePos, filename);
|
||||
}
|
||||
while (i !== -1) {
|
||||
position.line++;
|
||||
position.column = 0;
|
||||
last = i + 1;
|
||||
if (last < len && line !== undefined) {
|
||||
this._mark(++line, 0, null, null, filename);
|
||||
}
|
||||
i = str.indexOf("\n", last);
|
||||
}
|
||||
position.column += len - last;
|
||||
}
|
||||
_mark(line, column, identifierName, identifierNamePos, filename) {
|
||||
var _this$_map;
|
||||
(_this$_map = this._map) == null || _this$_map.mark(this._position, line, column, identifierName, identifierNamePos, filename);
|
||||
}
|
||||
removeTrailingNewline() {
|
||||
const queueCursor = this._queueCursor;
|
||||
if (queueCursor !== 0 && this._queue[queueCursor - 1].char === 10) {
|
||||
this._queueCursor--;
|
||||
}
|
||||
}
|
||||
removeLastSemicolon() {
|
||||
const queueCursor = this._queueCursor;
|
||||
if (queueCursor !== 0 && this._queue[queueCursor - 1].char === 59) {
|
||||
this._queueCursor--;
|
||||
}
|
||||
}
|
||||
getLastChar() {
|
||||
const queueCursor = this._queueCursor;
|
||||
return queueCursor !== 0 ? this._queue[queueCursor - 1].char : this._last;
|
||||
}
|
||||
getNewlineCount() {
|
||||
const queueCursor = this._queueCursor;
|
||||
let count = 0;
|
||||
if (queueCursor === 0) return this._last === 10 ? 1 : 0;
|
||||
for (let i = queueCursor - 1; i >= 0; i--) {
|
||||
if (this._queue[i].char !== 10) {
|
||||
break;
|
||||
}
|
||||
count++;
|
||||
}
|
||||
return count === queueCursor && this._last === 10 ? count + 1 : count;
|
||||
}
|
||||
endsWithCharAndNewline() {
|
||||
const queue = this._queue;
|
||||
const queueCursor = this._queueCursor;
|
||||
if (queueCursor !== 0) {
|
||||
const lastCp = queue[queueCursor - 1].char;
|
||||
if (lastCp !== 10) return;
|
||||
if (queueCursor > 1) {
|
||||
return queue[queueCursor - 2].char;
|
||||
} else {
|
||||
return this._last;
|
||||
}
|
||||
}
|
||||
}
|
||||
hasContent() {
|
||||
return this._queueCursor !== 0 || !!this._last;
|
||||
}
|
||||
exactSource(loc, cb) {
|
||||
if (!this._map) {
|
||||
cb();
|
||||
return;
|
||||
}
|
||||
this.source("start", loc);
|
||||
const identifierName = loc.identifierName;
|
||||
const sourcePos = this._sourcePosition;
|
||||
if (identifierName) {
|
||||
this._canMarkIdName = false;
|
||||
sourcePos.identifierName = identifierName;
|
||||
}
|
||||
cb();
|
||||
if (identifierName) {
|
||||
this._canMarkIdName = true;
|
||||
sourcePos.identifierName = undefined;
|
||||
sourcePos.identifierNamePos = undefined;
|
||||
}
|
||||
this.source("end", loc);
|
||||
}
|
||||
source(prop, loc) {
|
||||
if (!this._map) return;
|
||||
this._normalizePosition(prop, loc, 0);
|
||||
}
|
||||
sourceWithOffset(prop, loc, columnOffset) {
|
||||
if (!this._map) return;
|
||||
this._normalizePosition(prop, loc, columnOffset);
|
||||
}
|
||||
_normalizePosition(prop, loc, columnOffset) {
|
||||
const pos = loc[prop];
|
||||
const target = this._sourcePosition;
|
||||
if (pos) {
|
||||
target.line = pos.line;
|
||||
target.column = Math.max(pos.column + columnOffset, 0);
|
||||
target.filename = loc.filename;
|
||||
}
|
||||
}
|
||||
getCurrentColumn() {
|
||||
const queue = this._queue;
|
||||
const queueCursor = this._queueCursor;
|
||||
let lastIndex = -1;
|
||||
let len = 0;
|
||||
for (let i = 0; i < queueCursor; i++) {
|
||||
const item = queue[i];
|
||||
if (item.char === 10) {
|
||||
lastIndex = len;
|
||||
}
|
||||
len += item.repeat;
|
||||
}
|
||||
return lastIndex === -1 ? this._position.column + len : len - 1 - lastIndex;
|
||||
}
|
||||
getCurrentLine() {
|
||||
let count = 0;
|
||||
const queue = this._queue;
|
||||
for (let i = 0; i < this._queueCursor; i++) {
|
||||
if (queue[i].char === 10) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
return this._position.line + count;
|
||||
}
|
||||
}
|
||||
exports.default = Buffer;
|
||||
|
||||
//# sourceMappingURL=buffer.js.map
|
||||
@@ -0,0 +1,104 @@
|
||||
import { N as NamedUtilityValue, P as PluginUtils } from './resolve-config-BIFUA2FY.js';
|
||||
import './colors-b_6i0Oi7.js';
|
||||
|
||||
type Config = UserConfig;
|
||||
type PluginFn = (api: PluginAPI) => void;
|
||||
type PluginWithConfig = {
|
||||
handler: PluginFn;
|
||||
config?: UserConfig;
|
||||
/** @internal */
|
||||
reference?: boolean;
|
||||
};
|
||||
type PluginWithOptions<T> = {
|
||||
(options?: T): PluginWithConfig;
|
||||
__isOptionsFunction: true;
|
||||
};
|
||||
type Plugin = PluginFn | PluginWithConfig | PluginWithOptions<any>;
|
||||
type PluginAPI = {
|
||||
addBase(base: CssInJs): void;
|
||||
addVariant(name: string, variant: string | string[] | CssInJs): void;
|
||||
matchVariant<T = string>(name: string, cb: (value: T | string, extra: {
|
||||
modifier: string | null;
|
||||
}) => string | string[], options?: {
|
||||
values?: Record<string, T>;
|
||||
sort?(a: {
|
||||
value: T | string;
|
||||
modifier: string | null;
|
||||
}, b: {
|
||||
value: T | string;
|
||||
modifier: string | null;
|
||||
}): number;
|
||||
}): void;
|
||||
addUtilities(utilities: Record<string, CssInJs | CssInJs[]> | Record<string, CssInJs | CssInJs[]>[], options?: {}): void;
|
||||
matchUtilities(utilities: Record<string, (value: string, extra: {
|
||||
modifier: string | null;
|
||||
}) => CssInJs | CssInJs[]>, options?: Partial<{
|
||||
type: string | string[];
|
||||
supportsNegativeValues: boolean;
|
||||
values: Record<string, string> & {
|
||||
__BARE_VALUE__?: (value: NamedUtilityValue) => string | undefined;
|
||||
};
|
||||
modifiers: 'any' | Record<string, string>;
|
||||
}>): void;
|
||||
addComponents(utilities: Record<string, CssInJs> | Record<string, CssInJs>[], options?: {}): void;
|
||||
matchComponents(utilities: Record<string, (value: string, extra: {
|
||||
modifier: string | null;
|
||||
}) => CssInJs>, options?: Partial<{
|
||||
type: string | string[];
|
||||
supportsNegativeValues: boolean;
|
||||
values: Record<string, string> & {
|
||||
__BARE_VALUE__?: (value: NamedUtilityValue) => string | undefined;
|
||||
};
|
||||
modifiers: 'any' | Record<string, string>;
|
||||
}>): void;
|
||||
theme(path: string, defaultValue?: any): any;
|
||||
config(path?: string, defaultValue?: any): any;
|
||||
prefix(className: string): string;
|
||||
};
|
||||
type CssInJs = {
|
||||
[key: string]: string | string[] | CssInJs | CssInJs[];
|
||||
};
|
||||
|
||||
type ResolvableTo<T> = T | ((utils: PluginUtils) => T);
|
||||
type ThemeValue = ResolvableTo<Record<string, unknown>> | null | undefined;
|
||||
type ThemeConfig = Record<string, ThemeValue> & {
|
||||
extend?: Record<string, ThemeValue>;
|
||||
};
|
||||
type ContentFile = string | {
|
||||
raw: string;
|
||||
extension?: string;
|
||||
};
|
||||
type DarkModeStrategy = false | 'media' | 'class' | ['class', string] | 'selector' | ['selector', string] | ['variant', string | string[]];
|
||||
interface UserConfig {
|
||||
presets?: UserConfig[];
|
||||
theme?: ThemeConfig;
|
||||
plugins?: Plugin[];
|
||||
}
|
||||
interface UserConfig {
|
||||
content?: ContentFile[] | {
|
||||
relative?: boolean;
|
||||
files: ContentFile[];
|
||||
};
|
||||
}
|
||||
interface UserConfig {
|
||||
darkMode?: DarkModeStrategy;
|
||||
}
|
||||
interface UserConfig {
|
||||
prefix?: string;
|
||||
}
|
||||
interface UserConfig {
|
||||
blocklist?: string[];
|
||||
}
|
||||
interface UserConfig {
|
||||
important?: boolean | string;
|
||||
}
|
||||
interface UserConfig {
|
||||
future?: 'all' | Record<string, boolean>;
|
||||
}
|
||||
|
||||
declare function createPlugin(handler: PluginFn, config?: Partial<Config>): PluginWithConfig;
|
||||
declare namespace createPlugin {
|
||||
var withOptions: <T>(pluginFunction: (options?: T) => PluginFn, configFunction?: (options?: T) => Partial<Config>) => PluginWithOptions<T>;
|
||||
}
|
||||
|
||||
export { createPlugin as default };
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,39 @@
|
||||
{{## def.checkMissingProperty:_properties:
|
||||
{{~ _properties:$propertyKey:$i }}
|
||||
{{?$i}} || {{?}}
|
||||
{{
|
||||
var $prop = it.util.getProperty($propertyKey)
|
||||
, $useData = $data + $prop;
|
||||
}}
|
||||
( ({{# def.noPropertyInData }}) && (missing{{=$lvl}} = {{= it.util.toQuotedString(it.opts.jsonPointers ? $propertyKey : $prop) }}) )
|
||||
{{~}}
|
||||
#}}
|
||||
|
||||
|
||||
{{## def.errorMissingProperty:_error:
|
||||
{{
|
||||
var $propertyPath = 'missing' + $lvl
|
||||
, $missingProperty = '\' + ' + $propertyPath + ' + \'';
|
||||
if (it.opts._errorDataPathProperty) {
|
||||
it.errorPath = it.opts.jsonPointers
|
||||
? it.util.getPathExpr($currentErrorPath, $propertyPath, true)
|
||||
: $currentErrorPath + ' + ' + $propertyPath;
|
||||
}
|
||||
}}
|
||||
{{# def.error:_error }}
|
||||
#}}
|
||||
|
||||
|
||||
{{## def.allErrorsMissingProperty:_error:
|
||||
{{
|
||||
var $prop = it.util.getProperty($propertyKey)
|
||||
, $missingProperty = it.util.escapeQuotes($propertyKey)
|
||||
, $useData = $data + $prop;
|
||||
if (it.opts._errorDataPathProperty) {
|
||||
it.errorPath = it.util.getPath($currentErrorPath, $propertyKey, it.opts.jsonPointers);
|
||||
}
|
||||
}}
|
||||
if ({{# def.noPropertyInData }}) {
|
||||
{{# def.addError:_error }}
|
||||
}
|
||||
#}}
|
||||
@@ -0,0 +1,218 @@
|
||||
/**
|
||||
* @fileoverview Rule to enforce location of semicolons.
|
||||
* @author Toru Nagashima
|
||||
* @deprecated in ESLint v8.53.0
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Requirements
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
const astUtils = require("./utils/ast-utils");
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Rule Definition
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
const SELECTOR = [
|
||||
"BreakStatement",
|
||||
"ContinueStatement",
|
||||
"DebuggerStatement",
|
||||
"DoWhileStatement",
|
||||
"ExportAllDeclaration",
|
||||
"ExportDefaultDeclaration",
|
||||
"ExportNamedDeclaration",
|
||||
"ExpressionStatement",
|
||||
"ImportDeclaration",
|
||||
"ReturnStatement",
|
||||
"ThrowStatement",
|
||||
"VariableDeclaration",
|
||||
"PropertyDefinition",
|
||||
].join(",");
|
||||
|
||||
/**
|
||||
* Get the child node list of a given node.
|
||||
* This returns `BlockStatement#body`, `StaticBlock#body`, `Program#body`,
|
||||
* `ClassBody#body`, or `SwitchCase#consequent`.
|
||||
* This is used to check whether a node is the first/last child.
|
||||
* @param {Node} node A node to get child node list.
|
||||
* @returns {Node[]|null} The child node list.
|
||||
*/
|
||||
function getChildren(node) {
|
||||
const t = node.type;
|
||||
|
||||
if (
|
||||
t === "BlockStatement" ||
|
||||
t === "StaticBlock" ||
|
||||
t === "Program" ||
|
||||
t === "ClassBody"
|
||||
) {
|
||||
return node.body;
|
||||
}
|
||||
if (t === "SwitchCase") {
|
||||
return node.consequent;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether a given node is the last statement in the parent block.
|
||||
* @param {Node} node A node to check.
|
||||
* @returns {boolean} `true` if the node is the last statement in the parent block.
|
||||
*/
|
||||
function isLastChild(node) {
|
||||
const t = node.parent.type;
|
||||
|
||||
if (
|
||||
t === "IfStatement" &&
|
||||
node.parent.consequent === node &&
|
||||
node.parent.alternate
|
||||
) {
|
||||
// before `else` keyword.
|
||||
return true;
|
||||
}
|
||||
if (t === "DoWhileStatement") {
|
||||
// before `while` keyword.
|
||||
return true;
|
||||
}
|
||||
const nodeList = getChildren(node.parent);
|
||||
|
||||
return nodeList !== null && nodeList.at(-1) === node; // before `}` or etc.
|
||||
}
|
||||
|
||||
/** @type {import('../shared/types').Rule} */
|
||||
module.exports = {
|
||||
meta: {
|
||||
deprecated: {
|
||||
message: "Formatting rules are being moved out of ESLint core.",
|
||||
url: "https://eslint.org/blog/2023/10/deprecating-formatting-rules/",
|
||||
deprecatedSince: "8.53.0",
|
||||
availableUntil: "10.0.0",
|
||||
replacedBy: [
|
||||
{
|
||||
message:
|
||||
"ESLint Stylistic now maintains deprecated stylistic core rules.",
|
||||
url: "https://eslint.style/guide/migration",
|
||||
plugin: {
|
||||
name: "@stylistic/eslint-plugin-js",
|
||||
url: "https://eslint.style/packages/js",
|
||||
},
|
||||
rule: {
|
||||
name: "semi-style",
|
||||
url: "https://eslint.style/rules/js/semi-style",
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
type: "layout",
|
||||
|
||||
docs: {
|
||||
description: "Enforce location of semicolons",
|
||||
recommended: false,
|
||||
url: "https://eslint.org/docs/latest/rules/semi-style",
|
||||
},
|
||||
|
||||
schema: [{ enum: ["last", "first"] }],
|
||||
fixable: "whitespace",
|
||||
|
||||
messages: {
|
||||
expectedSemiColon: "Expected this semicolon to be at {{pos}}.",
|
||||
},
|
||||
},
|
||||
|
||||
create(context) {
|
||||
const sourceCode = context.sourceCode;
|
||||
const option = context.options[0] || "last";
|
||||
|
||||
/**
|
||||
* Check the given semicolon token.
|
||||
* @param {Token} semiToken The semicolon token to check.
|
||||
* @param {"first"|"last"} expected The expected location to check.
|
||||
* @returns {void}
|
||||
*/
|
||||
function check(semiToken, expected) {
|
||||
const prevToken = sourceCode.getTokenBefore(semiToken);
|
||||
const nextToken = sourceCode.getTokenAfter(semiToken);
|
||||
const prevIsSameLine =
|
||||
!prevToken || astUtils.isTokenOnSameLine(prevToken, semiToken);
|
||||
const nextIsSameLine =
|
||||
!nextToken || astUtils.isTokenOnSameLine(semiToken, nextToken);
|
||||
|
||||
if (
|
||||
(expected === "last" && !prevIsSameLine) ||
|
||||
(expected === "first" && !nextIsSameLine)
|
||||
) {
|
||||
context.report({
|
||||
loc: semiToken.loc,
|
||||
messageId: "expectedSemiColon",
|
||||
data: {
|
||||
pos:
|
||||
expected === "last"
|
||||
? "the end of the previous line"
|
||||
: "the beginning of the next line",
|
||||
},
|
||||
fix(fixer) {
|
||||
if (
|
||||
prevToken &&
|
||||
nextToken &&
|
||||
sourceCode.commentsExistBetween(
|
||||
prevToken,
|
||||
nextToken,
|
||||
)
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const start = prevToken
|
||||
? prevToken.range[1]
|
||||
: semiToken.range[0];
|
||||
const end = nextToken
|
||||
? nextToken.range[0]
|
||||
: semiToken.range[1];
|
||||
const text = expected === "last" ? ";\n" : "\n;";
|
||||
|
||||
return fixer.replaceTextRange([start, end], text);
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
[SELECTOR](node) {
|
||||
if (option === "first" && isLastChild(node)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const lastToken = sourceCode.getLastToken(node);
|
||||
|
||||
if (astUtils.isSemicolonToken(lastToken)) {
|
||||
check(lastToken, option);
|
||||
}
|
||||
},
|
||||
|
||||
ForStatement(node) {
|
||||
const firstSemi =
|
||||
node.init &&
|
||||
sourceCode.getTokenAfter(
|
||||
node.init,
|
||||
astUtils.isSemicolonToken,
|
||||
);
|
||||
const secondSemi =
|
||||
node.test &&
|
||||
sourceCode.getTokenAfter(
|
||||
node.test,
|
||||
astUtils.isSemicolonToken,
|
||||
);
|
||||
|
||||
if (firstSemi) {
|
||||
check(firstSemi, "last");
|
||||
}
|
||||
if (secondSemi) {
|
||||
check(secondSemi, "last");
|
||||
}
|
||||
},
|
||||
};
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1 @@
|
||||
module.exports={A:{A:{"2":"K D E F A B mC"},B:{"1":"0 9 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","16":"C"},C:{"1":"0 9 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 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"},D:{"1":"0 9 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","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"},E:{"1":"A B L M G 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","2":"J PB K D E F sC SC tC uC vC","129":"C"},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 8 F B C G N O P QB RB 4C 5C 6C 7C FC kC 8C GC"},G:{"1":"ED FD GD HD ID JD 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","129":"KD"},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:6,C:"ES6 Template Literals (Template Strings)",D:true};
|
||||
@@ -0,0 +1,40 @@
|
||||
{
|
||||
"name": "detect-libc",
|
||||
"version": "2.0.3",
|
||||
"description": "Node.js module to detect the C standard library (libc) implementation family and version",
|
||||
"main": "lib/detect-libc.js",
|
||||
"files": [
|
||||
"lib/",
|
||||
"index.d.ts"
|
||||
],
|
||||
"scripts": {
|
||||
"test": "semistandard && nyc --reporter=text --check-coverage --branches=100 ava test/unit.js",
|
||||
"bench": "node benchmark/detect-libc",
|
||||
"bench:calls": "node benchmark/call-familySync.js && sleep 1 && node benchmark/call-isNonGlibcLinuxSync.js && sleep 1 && node benchmark/call-versionSync.js"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/lovell/detect-libc"
|
||||
},
|
||||
"keywords": [
|
||||
"libc",
|
||||
"glibc",
|
||||
"musl"
|
||||
],
|
||||
"author": "Lovell Fuller <npm@lovell.info>",
|
||||
"contributors": [
|
||||
"Niklas Salmoukas <niklas@salmoukas.com>",
|
||||
"Vinícius Lourenço <vinyygamerlol@gmail.com>"
|
||||
],
|
||||
"license": "Apache-2.0",
|
||||
"devDependencies": {
|
||||
"ava": "^2.4.0",
|
||||
"benchmark": "^2.1.4",
|
||||
"nyc": "^15.1.0",
|
||||
"proxyquire": "^2.1.3",
|
||||
"semistandard": "^14.2.3"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=8"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
# Tools
|
||||
|
||||
## clang-format
|
||||
|
||||
The clang-format checking tools is designed to check changed lines of code compared to given git-refs.
|
||||
|
||||
## Migration Script
|
||||
|
||||
The migration tool is designed to reduce repetitive work in the migration process. However, the script is not aiming to convert every thing for you. There are usually some small fixes and major reconstruction required.
|
||||
|
||||
### How To Use
|
||||
|
||||
To run the conversion script, first make sure you have the latest `node-addon-api` in your `node_modules` directory.
|
||||
```
|
||||
npm install node-addon-api
|
||||
```
|
||||
|
||||
Then run the script passing your project directory
|
||||
```
|
||||
node ./node_modules/node-addon-api/tools/conversion.js ./
|
||||
```
|
||||
|
||||
After finish, recompile and debug things that are missed by the script.
|
||||
|
||||
|
||||
### Quick Fixes
|
||||
Here is the list of things that can be fixed easily.
|
||||
1. Change your methods' return value to void if it doesn't return value to JavaScript.
|
||||
2. Use `.` to access attribute or to invoke member function in Napi::Object instead of `->`.
|
||||
3. `Napi::New(env, value);` to `Napi::[Type]::New(env, value);
|
||||
|
||||
|
||||
### Major Reconstructions
|
||||
The implementation of `Napi::ObjectWrap` is significantly different from NAN's. `Napi::ObjectWrap` takes a pointer to the wrapped object and creates a reference to the wrapped object inside ObjectWrap constructor. `Napi::ObjectWrap` also associates wrapped object's instance methods to Javascript module instead of static methods like NAN.
|
||||
|
||||
So if you use Nan::ObjectWrap in your module, you will need to execute the following steps.
|
||||
|
||||
1. Convert your [ClassName]::New function to a constructor function that takes a `Napi::CallbackInfo`. Declare it as
|
||||
```
|
||||
[ClassName](const Napi::CallbackInfo& info);
|
||||
```
|
||||
and define it as
|
||||
```
|
||||
[ClassName]::[ClassName](const Napi::CallbackInfo& info) : Napi::ObjectWrap<[ClassName]>(info){
|
||||
...
|
||||
}
|
||||
```
|
||||
This way, the `Napi::ObjectWrap` constructor will be invoked after the object has been instantiated and `Napi::ObjectWrap` can use the `this` pointer to create a reference to the wrapped object.
|
||||
|
||||
2. Move your original constructor code into the new constructor. Delete your original constructor.
|
||||
3. In your class initialization function, associate native methods in the following way.
|
||||
```
|
||||
Napi::FunctionReference constructor;
|
||||
|
||||
void [ClassName]::Init(Napi::Env env, Napi::Object exports, Napi::Object module) {
|
||||
Napi::HandleScope scope(env);
|
||||
Napi::Function ctor = DefineClass(env, "Canvas", {
|
||||
InstanceMethod<&[ClassName]::Func1>("Func1"),
|
||||
InstanceMethod<&[ClassName]::Func2>("Func2"),
|
||||
InstanceAccessor<&[ClassName]::ValueGetter>("Value"),
|
||||
StaticMethod<&[ClassName]::StaticMethod>("MethodName"),
|
||||
InstanceValue("Value", Napi::[Type]::New(env, value)),
|
||||
});
|
||||
|
||||
constructor = Napi::Persistent(ctor);
|
||||
constructor .SuppressDestruct();
|
||||
exports.Set("[ClassName]", ctor);
|
||||
}
|
||||
```
|
||||
4. In function where you need to Unwrap the ObjectWrap in NAN like `[ClassName]* native = Nan::ObjectWrap::Unwrap<[ClassName]>(info.This());`, use `this` pointer directly as the unwrapped object as each ObjectWrap instance is associated with a unique object instance.
|
||||
|
||||
|
||||
If you still find issues after following this guide, please leave us an issue describing your problem and we will try to resolve it.
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"useRouterState.cjs","sources":["../../src/useRouterState.tsx"],"sourcesContent":["import { useStore } from '@tanstack/react-store'\nimport { useRef } from 'react'\nimport { replaceEqualDeep } from '@tanstack/router-core'\nimport { useRouter } from './useRouter'\nimport type {\n AnyRouter,\n RegisteredRouter,\n RouterState,\n} from '@tanstack/router-core'\nimport type {\n StructuralSharingOption,\n ValidateSelected,\n} from './structuralSharing'\n\nexport type UseRouterStateOptions<\n TRouter extends AnyRouter,\n TSelected,\n TStructuralSharing,\n> = {\n router?: TRouter\n select?: (\n state: RouterState<TRouter['routeTree']>,\n ) => ValidateSelected<TRouter, TSelected, TStructuralSharing>\n} & StructuralSharingOption<TRouter, TSelected, TStructuralSharing>\n\nexport type UseRouterStateResult<\n TRouter extends AnyRouter,\n TSelected,\n> = unknown extends TSelected ? RouterState<TRouter['routeTree']> : TSelected\n\nexport function useRouterState<\n TRouter extends AnyRouter = RegisteredRouter,\n TSelected = unknown,\n TStructuralSharing extends boolean = boolean,\n>(\n opts?: UseRouterStateOptions<TRouter, TSelected, TStructuralSharing>,\n): UseRouterStateResult<TRouter, TSelected> {\n const contextRouter = useRouter<TRouter>({\n warn: opts?.router === undefined,\n })\n const router = opts?.router || contextRouter\n const previousResult =\n useRef<ValidateSelected<TRouter, TSelected, TStructuralSharing>>(undefined)\n\n return useStore(router.__store, (state) => {\n if (opts?.select) {\n if (opts.structuralSharing ?? router.options.defaultStructuralSharing) {\n const newSlice = replaceEqualDeep(\n previousResult.current,\n opts.select(state),\n )\n previousResult.current = newSlice\n return newSlice\n }\n return opts.select(state)\n }\n return state\n }) as UseRouterStateResult<TRouter, TSelected>\n}\n"],"names":["useRouter","useRef","useStore","replaceEqualDeep"],"mappings":";;;;;;AA8BO,SAAS,eAKd,MAC0C;AAC1C,QAAM,gBAAgBA,UAAAA,UAAmB;AAAA,IACvC,OAAM,6BAAM,YAAW;AAAA,EAAA,CACxB;AACK,QAAA,UAAS,6BAAM,WAAU;AACzB,QAAA,iBACJC,aAAiE,MAAS;AAE5E,SAAOC,oBAAS,OAAO,SAAS,CAAC,UAAU;AACzC,QAAI,6BAAM,QAAQ;AAChB,UAAI,KAAK,qBAAqB,OAAO,QAAQ,0BAA0B;AACrE,cAAM,WAAWC,WAAA;AAAA,UACf,eAAe;AAAA,UACf,KAAK,OAAO,KAAK;AAAA,QACnB;AACA,uBAAe,UAAU;AAClB,eAAA;AAAA,MAAA;AAEF,aAAA,KAAK,OAAO,KAAK;AAAA,IAAA;AAEnB,WAAA;AAAA,EAAA,CACR;AACH;;"}
|
||||
@@ -0,0 +1,92 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.run = run;
|
||||
function _traverse() {
|
||||
const data = require("@babel/traverse");
|
||||
_traverse = function () {
|
||||
return data;
|
||||
};
|
||||
return data;
|
||||
}
|
||||
var _pluginPass = require("./plugin-pass.js");
|
||||
var _blockHoistPlugin = require("./block-hoist-plugin.js");
|
||||
var _normalizeOpts = require("./normalize-opts.js");
|
||||
var _normalizeFile = require("./normalize-file.js");
|
||||
var _generate = require("./file/generate.js");
|
||||
var _deepArray = require("../config/helpers/deep-array.js");
|
||||
var _async = require("../gensync-utils/async.js");
|
||||
function* run(config, code, ast) {
|
||||
const file = yield* (0, _normalizeFile.default)(config.passes, (0, _normalizeOpts.default)(config), code, ast);
|
||||
const opts = file.opts;
|
||||
try {
|
||||
yield* transformFile(file, config.passes);
|
||||
} catch (e) {
|
||||
var _opts$filename;
|
||||
e.message = `${(_opts$filename = opts.filename) != null ? _opts$filename : "unknown file"}: ${e.message}`;
|
||||
if (!e.code) {
|
||||
e.code = "BABEL_TRANSFORM_ERROR";
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
let outputCode, outputMap;
|
||||
try {
|
||||
if (opts.code !== false) {
|
||||
({
|
||||
outputCode,
|
||||
outputMap
|
||||
} = (0, _generate.default)(config.passes, file));
|
||||
}
|
||||
} catch (e) {
|
||||
var _opts$filename2;
|
||||
e.message = `${(_opts$filename2 = opts.filename) != null ? _opts$filename2 : "unknown file"}: ${e.message}`;
|
||||
if (!e.code) {
|
||||
e.code = "BABEL_GENERATE_ERROR";
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
return {
|
||||
metadata: file.metadata,
|
||||
options: opts,
|
||||
ast: opts.ast === true ? file.ast : null,
|
||||
code: outputCode === undefined ? null : outputCode,
|
||||
map: outputMap === undefined ? null : outputMap,
|
||||
sourceType: file.ast.program.sourceType,
|
||||
externalDependencies: (0, _deepArray.flattenToSet)(config.externalDependencies)
|
||||
};
|
||||
}
|
||||
function* transformFile(file, pluginPasses) {
|
||||
const async = yield* (0, _async.isAsync)();
|
||||
for (const pluginPairs of pluginPasses) {
|
||||
const passPairs = [];
|
||||
const passes = [];
|
||||
const visitors = [];
|
||||
for (const plugin of pluginPairs.concat([(0, _blockHoistPlugin.default)()])) {
|
||||
const pass = new _pluginPass.default(file, plugin.key, plugin.options, async);
|
||||
passPairs.push([plugin, pass]);
|
||||
passes.push(pass);
|
||||
visitors.push(plugin.visitor);
|
||||
}
|
||||
for (const [plugin, pass] of passPairs) {
|
||||
if (plugin.pre) {
|
||||
const fn = (0, _async.maybeAsync)(plugin.pre, `You appear to be using an async plugin/preset, but Babel has been called synchronously`);
|
||||
yield* fn.call(pass, file);
|
||||
}
|
||||
}
|
||||
const visitor = _traverse().default.visitors.merge(visitors, passes, file.opts.wrapPluginVisitorMethod);
|
||||
{
|
||||
(0, _traverse().default)(file.ast, visitor, file.scope);
|
||||
}
|
||||
for (const [plugin, pass] of passPairs) {
|
||||
if (plugin.post) {
|
||||
const fn = (0, _async.maybeAsync)(plugin.post, `You appear to be using an async plugin/preset, but Babel has been called synchronously`);
|
||||
yield* fn.call(pass, file);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
0 && 0;
|
||||
|
||||
//# sourceMappingURL=index.js.map
|
||||
Reference in New Issue
Block a user