update
This commit is contained in:
@@ -0,0 +1,131 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
var t = require("@babel/types");
|
||||
var _t = t;
|
||||
var _traverseNode = require("../../traverse-node.js");
|
||||
var _visitors = require("../../visitors.js");
|
||||
var _context = require("../../path/context.js");
|
||||
const {
|
||||
getAssignmentIdentifiers
|
||||
} = _t;
|
||||
const renameVisitor = {
|
||||
ReferencedIdentifier({
|
||||
node
|
||||
}, state) {
|
||||
if (node.name === state.oldName) {
|
||||
node.name = state.newName;
|
||||
}
|
||||
},
|
||||
Scope(path, state) {
|
||||
if (!path.scope.bindingIdentifierEquals(state.oldName, state.binding.identifier)) {
|
||||
path.skip();
|
||||
if (path.isMethod()) {
|
||||
if (!path.requeueComputedKeyAndDecorators) {
|
||||
_context.requeueComputedKeyAndDecorators.call(path);
|
||||
} else {
|
||||
path.requeueComputedKeyAndDecorators();
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
ObjectProperty({
|
||||
node,
|
||||
scope
|
||||
}, state) {
|
||||
const {
|
||||
name
|
||||
} = node.key;
|
||||
if (node.shorthand && (name === state.oldName || name === state.newName) && scope.getBindingIdentifier(name) === state.binding.identifier) {
|
||||
node.shorthand = false;
|
||||
{
|
||||
var _node$extra;
|
||||
if ((_node$extra = node.extra) != null && _node$extra.shorthand) node.extra.shorthand = false;
|
||||
}
|
||||
}
|
||||
},
|
||||
"AssignmentExpression|Declaration|VariableDeclarator"(path, state) {
|
||||
if (path.isVariableDeclaration()) return;
|
||||
const ids = path.isAssignmentExpression() ? getAssignmentIdentifiers(path.node) : path.getOuterBindingIdentifiers();
|
||||
for (const name in ids) {
|
||||
if (name === state.oldName) ids[name].name = state.newName;
|
||||
}
|
||||
}
|
||||
};
|
||||
class Renamer {
|
||||
constructor(binding, oldName, newName) {
|
||||
this.newName = newName;
|
||||
this.oldName = oldName;
|
||||
this.binding = binding;
|
||||
}
|
||||
maybeConvertFromExportDeclaration(parentDeclar) {
|
||||
const maybeExportDeclar = parentDeclar.parentPath;
|
||||
if (!maybeExportDeclar.isExportDeclaration()) {
|
||||
return;
|
||||
}
|
||||
if (maybeExportDeclar.isExportDefaultDeclaration()) {
|
||||
const {
|
||||
declaration
|
||||
} = maybeExportDeclar.node;
|
||||
if (t.isDeclaration(declaration) && !declaration.id) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (maybeExportDeclar.isExportAllDeclaration()) {
|
||||
return;
|
||||
}
|
||||
maybeExportDeclar.splitExportDeclaration();
|
||||
}
|
||||
maybeConvertFromClassFunctionDeclaration(path) {
|
||||
return path;
|
||||
}
|
||||
maybeConvertFromClassFunctionExpression(path) {
|
||||
return path;
|
||||
}
|
||||
rename() {
|
||||
const {
|
||||
binding,
|
||||
oldName,
|
||||
newName
|
||||
} = this;
|
||||
const {
|
||||
scope,
|
||||
path
|
||||
} = binding;
|
||||
const parentDeclar = path.find(path => path.isDeclaration() || path.isFunctionExpression() || path.isClassExpression());
|
||||
if (parentDeclar) {
|
||||
const bindingIds = parentDeclar.getOuterBindingIdentifiers();
|
||||
if (bindingIds[oldName] === binding.identifier) {
|
||||
this.maybeConvertFromExportDeclaration(parentDeclar);
|
||||
}
|
||||
}
|
||||
const blockToTraverse = arguments[0] || scope.block;
|
||||
const skipKeys = {
|
||||
discriminant: true
|
||||
};
|
||||
if (t.isMethod(blockToTraverse)) {
|
||||
if (blockToTraverse.computed) {
|
||||
skipKeys.key = true;
|
||||
}
|
||||
if (!t.isObjectMethod(blockToTraverse)) {
|
||||
skipKeys.decorators = true;
|
||||
}
|
||||
}
|
||||
(0, _traverseNode.traverseNode)(blockToTraverse, (0, _visitors.explode)(renameVisitor), scope, this, scope.path, skipKeys);
|
||||
if (!arguments[0]) {
|
||||
scope.removeOwnBinding(oldName);
|
||||
scope.bindings[newName] = binding;
|
||||
this.binding.identifier.name = newName;
|
||||
}
|
||||
if (parentDeclar) {
|
||||
this.maybeConvertFromClassFunctionDeclaration(path);
|
||||
this.maybeConvertFromClassFunctionExpression(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.default = Renamer;
|
||||
|
||||
//# sourceMappingURL=renamer.js.map
|
||||
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"name": "@rollup/rollup-linux-arm64-musl",
|
||||
"version": "4.39.0",
|
||||
"os": [
|
||||
"linux"
|
||||
],
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
"files": [
|
||||
"rollup.linux-arm64-musl.node"
|
||||
],
|
||||
"description": "Native bindings for Rollup",
|
||||
"author": "Lukas Taegert-Atkinson",
|
||||
"homepage": "https://rollupjs.org/",
|
||||
"license": "MIT",
|
||||
"repository": "rollup/rollup",
|
||||
"libc": [
|
||||
"musl"
|
||||
],
|
||||
"main": "./rollup.linux-arm64-musl.node"
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
'use strict';
|
||||
module.exports = require('./globals.json');
|
||||
@@ -0,0 +1,42 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = validate;
|
||||
exports.validateChild = validateChild;
|
||||
exports.validateField = validateField;
|
||||
exports.validateInternal = validateInternal;
|
||||
var _index = require("../definitions/index.js");
|
||||
function validate(node, key, val) {
|
||||
if (!node) return;
|
||||
const fields = _index.NODE_FIELDS[node.type];
|
||||
if (!fields) return;
|
||||
const field = fields[key];
|
||||
validateField(node, key, val, field);
|
||||
validateChild(node, key, val);
|
||||
}
|
||||
function validateInternal(field, node, key, val, maybeNode) {
|
||||
if (!(field != null && field.validate)) return;
|
||||
if (field.optional && val == null) return;
|
||||
field.validate(node, key, val);
|
||||
if (maybeNode) {
|
||||
var _NODE_PARENT_VALIDATI;
|
||||
const type = val.type;
|
||||
if (type == null) return;
|
||||
(_NODE_PARENT_VALIDATI = _index.NODE_PARENT_VALIDATIONS[type]) == null || _NODE_PARENT_VALIDATI.call(_index.NODE_PARENT_VALIDATIONS, node, key, val);
|
||||
}
|
||||
}
|
||||
function validateField(node, key, val, field) {
|
||||
if (!(field != null && field.validate)) return;
|
||||
if (field.optional && val == null) return;
|
||||
field.validate(node, key, val);
|
||||
}
|
||||
function validateChild(node, key, val) {
|
||||
var _NODE_PARENT_VALIDATI2;
|
||||
const type = val == null ? void 0 : val.type;
|
||||
if (type == null) return;
|
||||
(_NODE_PARENT_VALIDATI2 = _index.NODE_PARENT_VALIDATIONS[type]) == null || _NODE_PARENT_VALIDATI2.call(_index.NODE_PARENT_VALIDATIONS, node, key, val);
|
||||
}
|
||||
|
||||
//# sourceMappingURL=validate.js.map
|
||||
@@ -0,0 +1,14 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = _assertClassBrand;
|
||||
function _assertClassBrand(brand, receiver, returnValue) {
|
||||
if (typeof brand === "function" ? brand === receiver : brand.has(receiver)) {
|
||||
return arguments.length < 3 ? receiver : returnValue;
|
||||
}
|
||||
throw new TypeError("Private element is not present on this object");
|
||||
}
|
||||
|
||||
//# sourceMappingURL=assertClassBrand.js.map
|
||||
@@ -0,0 +1,294 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
||||
const utils = require("./utils.cjs");
|
||||
function joinPaths(paths) {
|
||||
return cleanPath(
|
||||
paths.filter((val) => {
|
||||
return val !== void 0;
|
||||
}).join("/")
|
||||
);
|
||||
}
|
||||
function cleanPath(path) {
|
||||
return path.replace(/\/{2,}/g, "/");
|
||||
}
|
||||
function trimPathLeft(path) {
|
||||
return path === "/" ? path : path.replace(/^\/{1,}/, "");
|
||||
}
|
||||
function trimPathRight(path) {
|
||||
return path === "/" ? path : path.replace(/\/{1,}$/, "");
|
||||
}
|
||||
function trimPath(path) {
|
||||
return trimPathRight(trimPathLeft(path));
|
||||
}
|
||||
function removeTrailingSlash(value, basepath) {
|
||||
if ((value == null ? void 0 : value.endsWith("/")) && value !== "/" && value !== `${basepath}/`) {
|
||||
return value.slice(0, -1);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
function exactPathTest(pathName1, pathName2, basepath) {
|
||||
return removeTrailingSlash(pathName1, basepath) === removeTrailingSlash(pathName2, basepath);
|
||||
}
|
||||
function resolvePath({
|
||||
basepath,
|
||||
base,
|
||||
to,
|
||||
trailingSlash = "never",
|
||||
caseSensitive
|
||||
}) {
|
||||
var _a, _b;
|
||||
base = removeBasepath(basepath, base, caseSensitive);
|
||||
to = removeBasepath(basepath, to, caseSensitive);
|
||||
let baseSegments = parsePathname(base);
|
||||
const toSegments = parsePathname(to);
|
||||
if (baseSegments.length > 1 && ((_a = utils.last(baseSegments)) == null ? void 0 : _a.value) === "/") {
|
||||
baseSegments.pop();
|
||||
}
|
||||
toSegments.forEach((toSegment, index) => {
|
||||
if (toSegment.value === "/") {
|
||||
if (!index) {
|
||||
baseSegments = [toSegment];
|
||||
} else if (index === toSegments.length - 1) {
|
||||
baseSegments.push(toSegment);
|
||||
} else ;
|
||||
} else if (toSegment.value === "..") {
|
||||
baseSegments.pop();
|
||||
} else if (toSegment.value === ".") ;
|
||||
else {
|
||||
baseSegments.push(toSegment);
|
||||
}
|
||||
});
|
||||
if (baseSegments.length > 1) {
|
||||
if (((_b = utils.last(baseSegments)) == null ? void 0 : _b.value) === "/") {
|
||||
if (trailingSlash === "never") {
|
||||
baseSegments.pop();
|
||||
}
|
||||
} else if (trailingSlash === "always") {
|
||||
baseSegments.push({ type: "pathname", value: "/" });
|
||||
}
|
||||
}
|
||||
const joined = joinPaths([basepath, ...baseSegments.map((d) => d.value)]);
|
||||
return cleanPath(joined);
|
||||
}
|
||||
function parsePathname(pathname) {
|
||||
if (!pathname) {
|
||||
return [];
|
||||
}
|
||||
pathname = cleanPath(pathname);
|
||||
const segments = [];
|
||||
if (pathname.slice(0, 1) === "/") {
|
||||
pathname = pathname.substring(1);
|
||||
segments.push({
|
||||
type: "pathname",
|
||||
value: "/"
|
||||
});
|
||||
}
|
||||
if (!pathname) {
|
||||
return segments;
|
||||
}
|
||||
const split = pathname.split("/").filter(Boolean);
|
||||
segments.push(
|
||||
...split.map((part) => {
|
||||
if (part === "$" || part === "*") {
|
||||
return {
|
||||
type: "wildcard",
|
||||
value: part
|
||||
};
|
||||
}
|
||||
if (part.charAt(0) === "$") {
|
||||
return {
|
||||
type: "param",
|
||||
value: part
|
||||
};
|
||||
}
|
||||
return {
|
||||
type: "pathname",
|
||||
value: part.includes("%25") ? part.split("%25").map((segment) => decodeURI(segment)).join("%25") : decodeURI(part)
|
||||
};
|
||||
})
|
||||
);
|
||||
if (pathname.slice(-1) === "/") {
|
||||
pathname = pathname.substring(1);
|
||||
segments.push({
|
||||
type: "pathname",
|
||||
value: "/"
|
||||
});
|
||||
}
|
||||
return segments;
|
||||
}
|
||||
function interpolatePath({
|
||||
path,
|
||||
params,
|
||||
leaveWildcards,
|
||||
leaveParams,
|
||||
decodeCharMap
|
||||
}) {
|
||||
const interpolatedPathSegments = parsePathname(path);
|
||||
function encodeParam(key) {
|
||||
const value = params[key];
|
||||
const isValueString = typeof value === "string";
|
||||
if (["*", "_splat"].includes(key)) {
|
||||
return isValueString ? encodeURI(value) : value;
|
||||
} else {
|
||||
return isValueString ? encodePathParam(value, decodeCharMap) : value;
|
||||
}
|
||||
}
|
||||
const usedParams = {};
|
||||
const interpolatedPath = joinPaths(
|
||||
interpolatedPathSegments.map((segment) => {
|
||||
if (segment.type === "wildcard") {
|
||||
usedParams._splat = params._splat;
|
||||
const value = encodeParam("_splat");
|
||||
if (leaveWildcards) return `${segment.value}${value ?? ""}`;
|
||||
return value;
|
||||
}
|
||||
if (segment.type === "param") {
|
||||
const key = segment.value.substring(1);
|
||||
usedParams[key] = params[key];
|
||||
if (leaveParams) {
|
||||
const value = encodeParam(segment.value);
|
||||
return `${segment.value}${value ?? ""}`;
|
||||
}
|
||||
return encodeParam(key) ?? "undefined";
|
||||
}
|
||||
return segment.value;
|
||||
})
|
||||
);
|
||||
return { usedParams, interpolatedPath };
|
||||
}
|
||||
function encodePathParam(value, decodeCharMap) {
|
||||
let encoded = encodeURIComponent(value);
|
||||
if (decodeCharMap) {
|
||||
for (const [encodedChar, char] of decodeCharMap) {
|
||||
encoded = encoded.replaceAll(encodedChar, char);
|
||||
}
|
||||
}
|
||||
return encoded;
|
||||
}
|
||||
function matchPathname(basepath, currentPathname, matchLocation) {
|
||||
const pathParams = matchByPath(basepath, currentPathname, matchLocation);
|
||||
if (matchLocation.to && !pathParams) {
|
||||
return;
|
||||
}
|
||||
return pathParams ?? {};
|
||||
}
|
||||
function removeBasepath(basepath, pathname, caseSensitive = false) {
|
||||
const normalizedBasepath = caseSensitive ? basepath : basepath.toLowerCase();
|
||||
const normalizedPathname = caseSensitive ? pathname : pathname.toLowerCase();
|
||||
switch (true) {
|
||||
// default behaviour is to serve app from the root - pathname
|
||||
// left untouched
|
||||
case normalizedBasepath === "/":
|
||||
return pathname;
|
||||
// shortcut for removing the basepath if it matches the pathname
|
||||
case normalizedPathname === normalizedBasepath:
|
||||
return "";
|
||||
// in case pathname is shorter than basepath - there is
|
||||
// nothing to remove
|
||||
case pathname.length < basepath.length:
|
||||
return pathname;
|
||||
// avoid matching partial segments - strict equality handled
|
||||
// earlier, otherwise, basepath separated from pathname with
|
||||
// separator, therefore lack of separator means partial
|
||||
// segment match (`/app` should not match `/application`)
|
||||
case normalizedPathname[normalizedBasepath.length] !== "/":
|
||||
return pathname;
|
||||
// remove the basepath from the pathname if it starts with it
|
||||
case normalizedPathname.startsWith(normalizedBasepath):
|
||||
return pathname.slice(basepath.length);
|
||||
// otherwise, return the pathname as is
|
||||
default:
|
||||
return pathname;
|
||||
}
|
||||
}
|
||||
function matchByPath(basepath, from, matchLocation) {
|
||||
if (basepath !== "/" && !from.startsWith(basepath)) {
|
||||
return void 0;
|
||||
}
|
||||
from = removeBasepath(basepath, from, matchLocation.caseSensitive);
|
||||
const to = removeBasepath(
|
||||
basepath,
|
||||
`${matchLocation.to ?? "$"}`,
|
||||
matchLocation.caseSensitive
|
||||
);
|
||||
const baseSegments = parsePathname(from);
|
||||
const routeSegments = parsePathname(to);
|
||||
if (!from.startsWith("/")) {
|
||||
baseSegments.unshift({
|
||||
type: "pathname",
|
||||
value: "/"
|
||||
});
|
||||
}
|
||||
if (!to.startsWith("/")) {
|
||||
routeSegments.unshift({
|
||||
type: "pathname",
|
||||
value: "/"
|
||||
});
|
||||
}
|
||||
const params = {};
|
||||
const isMatch = (() => {
|
||||
for (let i = 0; i < Math.max(baseSegments.length, routeSegments.length); i++) {
|
||||
const baseSegment = baseSegments[i];
|
||||
const routeSegment = routeSegments[i];
|
||||
const isLastBaseSegment = i >= baseSegments.length - 1;
|
||||
const isLastRouteSegment = i >= routeSegments.length - 1;
|
||||
if (routeSegment) {
|
||||
if (routeSegment.type === "wildcard") {
|
||||
const _splat = decodeURI(
|
||||
joinPaths(baseSegments.slice(i).map((d) => d.value))
|
||||
);
|
||||
params["*"] = _splat;
|
||||
params["_splat"] = _splat;
|
||||
return true;
|
||||
}
|
||||
if (routeSegment.type === "pathname") {
|
||||
if (routeSegment.value === "/" && !(baseSegment == null ? void 0 : baseSegment.value)) {
|
||||
return true;
|
||||
}
|
||||
if (baseSegment) {
|
||||
if (matchLocation.caseSensitive) {
|
||||
if (routeSegment.value !== baseSegment.value) {
|
||||
return false;
|
||||
}
|
||||
} else if (routeSegment.value.toLowerCase() !== baseSegment.value.toLowerCase()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!baseSegment) {
|
||||
return false;
|
||||
}
|
||||
if (routeSegment.type === "param") {
|
||||
if (baseSegment.value === "/") {
|
||||
return false;
|
||||
}
|
||||
if (baseSegment.value.charAt(0) !== "$") {
|
||||
params[routeSegment.value.substring(1)] = decodeURIComponent(
|
||||
baseSegment.value
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!isLastBaseSegment && isLastRouteSegment) {
|
||||
params["**"] = joinPaths(baseSegments.slice(i + 1).map((d) => d.value));
|
||||
return !!matchLocation.fuzzy && (routeSegment == null ? void 0 : routeSegment.value) !== "/";
|
||||
}
|
||||
}
|
||||
return true;
|
||||
})();
|
||||
return isMatch ? params : void 0;
|
||||
}
|
||||
exports.cleanPath = cleanPath;
|
||||
exports.exactPathTest = exactPathTest;
|
||||
exports.interpolatePath = interpolatePath;
|
||||
exports.joinPaths = joinPaths;
|
||||
exports.matchByPath = matchByPath;
|
||||
exports.matchPathname = matchPathname;
|
||||
exports.parsePathname = parsePathname;
|
||||
exports.removeBasepath = removeBasepath;
|
||||
exports.removeTrailingSlash = removeTrailingSlash;
|
||||
exports.resolvePath = resolvePath;
|
||||
exports.trimPath = trimPath;
|
||||
exports.trimPathLeft = trimPathLeft;
|
||||
exports.trimPathRight = trimPathRight;
|
||||
//# sourceMappingURL=path.cjs.map
|
||||
@@ -0,0 +1,306 @@
|
||||
import * as React from 'react'
|
||||
import { useRouter } from './useRouter'
|
||||
import type {
|
||||
BlockerFnArgs,
|
||||
HistoryAction,
|
||||
HistoryLocation,
|
||||
} from '@tanstack/history'
|
||||
import type {
|
||||
AnyRoute,
|
||||
AnyRouter,
|
||||
ParseRoute,
|
||||
RegisteredRouter,
|
||||
} from '@tanstack/router-core'
|
||||
|
||||
interface ShouldBlockFnLocation<
|
||||
out TRouteId,
|
||||
out TFullPath,
|
||||
out TAllParams,
|
||||
out TFullSearchSchema,
|
||||
> {
|
||||
routeId: TRouteId
|
||||
fullPath: TFullPath
|
||||
pathname: string
|
||||
params: TAllParams
|
||||
search: TFullSearchSchema
|
||||
}
|
||||
|
||||
type AnyShouldBlockFnLocation = ShouldBlockFnLocation<any, any, any, any>
|
||||
type MakeShouldBlockFnLocationUnion<
|
||||
TRouter extends AnyRouter = RegisteredRouter,
|
||||
TRoute extends AnyRoute = ParseRoute<TRouter['routeTree']>,
|
||||
> = TRoute extends any
|
||||
? ShouldBlockFnLocation<
|
||||
TRoute['id'],
|
||||
TRoute['fullPath'],
|
||||
TRoute['types']['allParams'],
|
||||
TRoute['types']['fullSearchSchema']
|
||||
>
|
||||
: never
|
||||
|
||||
type BlockerResolver<TRouter extends AnyRouter = RegisteredRouter> =
|
||||
| {
|
||||
status: 'blocked'
|
||||
current: MakeShouldBlockFnLocationUnion<TRouter>
|
||||
next: MakeShouldBlockFnLocationUnion<TRouter>
|
||||
action: HistoryAction
|
||||
proceed: () => void
|
||||
reset: () => void
|
||||
}
|
||||
| {
|
||||
status: 'idle'
|
||||
current: undefined
|
||||
next: undefined
|
||||
action: undefined
|
||||
proceed: undefined
|
||||
reset: undefined
|
||||
}
|
||||
|
||||
type ShouldBlockFnArgs<TRouter extends AnyRouter = RegisteredRouter> = {
|
||||
current: MakeShouldBlockFnLocationUnion<TRouter>
|
||||
next: MakeShouldBlockFnLocationUnion<TRouter>
|
||||
action: HistoryAction
|
||||
}
|
||||
|
||||
export type ShouldBlockFn<TRouter extends AnyRouter = RegisteredRouter> = (
|
||||
args: ShouldBlockFnArgs<TRouter>,
|
||||
) => boolean | Promise<boolean>
|
||||
export type UseBlockerOpts<
|
||||
TRouter extends AnyRouter = RegisteredRouter,
|
||||
TWithResolver extends boolean = boolean,
|
||||
> = {
|
||||
shouldBlockFn: ShouldBlockFn<TRouter>
|
||||
enableBeforeUnload?: boolean | (() => boolean)
|
||||
disabled?: boolean
|
||||
withResolver?: TWithResolver
|
||||
}
|
||||
|
||||
type LegacyBlockerFn = () => Promise<any> | any
|
||||
type LegacyBlockerOpts = {
|
||||
blockerFn?: LegacyBlockerFn
|
||||
condition?: boolean | any
|
||||
}
|
||||
|
||||
function _resolveBlockerOpts(
|
||||
opts?: UseBlockerOpts | LegacyBlockerOpts | LegacyBlockerFn,
|
||||
condition?: boolean | any,
|
||||
): UseBlockerOpts {
|
||||
if (opts === undefined) {
|
||||
return {
|
||||
shouldBlockFn: () => true,
|
||||
withResolver: false,
|
||||
}
|
||||
}
|
||||
|
||||
if ('shouldBlockFn' in opts) {
|
||||
return opts
|
||||
}
|
||||
|
||||
if (typeof opts === 'function') {
|
||||
const shouldBlock = Boolean(condition ?? true)
|
||||
|
||||
const _customBlockerFn = async () => {
|
||||
if (shouldBlock) return await opts()
|
||||
return false
|
||||
}
|
||||
|
||||
return {
|
||||
shouldBlockFn: _customBlockerFn,
|
||||
enableBeforeUnload: shouldBlock,
|
||||
withResolver: false,
|
||||
}
|
||||
}
|
||||
|
||||
const shouldBlock = Boolean(opts.condition ?? true)
|
||||
const fn = opts.blockerFn
|
||||
|
||||
const _customBlockerFn = async () => {
|
||||
if (shouldBlock && fn !== undefined) {
|
||||
return await fn()
|
||||
}
|
||||
return shouldBlock
|
||||
}
|
||||
|
||||
return {
|
||||
shouldBlockFn: _customBlockerFn,
|
||||
enableBeforeUnload: shouldBlock,
|
||||
withResolver: fn === undefined,
|
||||
}
|
||||
}
|
||||
|
||||
export function useBlocker<
|
||||
TRouter extends AnyRouter = RegisteredRouter,
|
||||
TWithResolver extends boolean = false,
|
||||
>(
|
||||
opts: UseBlockerOpts<TRouter, TWithResolver>,
|
||||
): TWithResolver extends true ? BlockerResolver<TRouter> : void
|
||||
|
||||
/**
|
||||
* @deprecated Use the shouldBlockFn property instead
|
||||
*/
|
||||
export function useBlocker(blockerFnOrOpts?: LegacyBlockerOpts): BlockerResolver
|
||||
|
||||
/**
|
||||
* @deprecated Use the UseBlockerOpts object syntax instead
|
||||
*/
|
||||
export function useBlocker(
|
||||
blockerFn?: LegacyBlockerFn,
|
||||
condition?: boolean | any,
|
||||
): BlockerResolver
|
||||
|
||||
export function useBlocker(
|
||||
opts?: UseBlockerOpts | LegacyBlockerOpts | LegacyBlockerFn,
|
||||
condition?: boolean | any,
|
||||
): BlockerResolver | void {
|
||||
const {
|
||||
shouldBlockFn,
|
||||
enableBeforeUnload = true,
|
||||
disabled = false,
|
||||
withResolver = false,
|
||||
} = _resolveBlockerOpts(opts, condition)
|
||||
|
||||
const router = useRouter()
|
||||
const { history } = router
|
||||
|
||||
const [resolver, setResolver] = React.useState<BlockerResolver>({
|
||||
status: 'idle',
|
||||
current: undefined,
|
||||
next: undefined,
|
||||
action: undefined,
|
||||
proceed: undefined,
|
||||
reset: undefined,
|
||||
})
|
||||
|
||||
React.useEffect(() => {
|
||||
const blockerFnComposed = async (blockerFnArgs: BlockerFnArgs) => {
|
||||
function getLocation(
|
||||
location: HistoryLocation,
|
||||
): AnyShouldBlockFnLocation {
|
||||
const parsedLocation = router.parseLocation(undefined, location)
|
||||
const matchedRoutes = router.getMatchedRoutes(parsedLocation)
|
||||
if (matchedRoutes.foundRoute === undefined) {
|
||||
throw new Error(`No route found for location ${location.href}`)
|
||||
}
|
||||
return {
|
||||
routeId: matchedRoutes.foundRoute.id,
|
||||
fullPath: matchedRoutes.foundRoute.fullPath,
|
||||
pathname: parsedLocation.pathname,
|
||||
params: matchedRoutes.routeParams,
|
||||
search: parsedLocation.search,
|
||||
}
|
||||
}
|
||||
|
||||
const current = getLocation(blockerFnArgs.currentLocation)
|
||||
const next = getLocation(blockerFnArgs.nextLocation)
|
||||
|
||||
const shouldBlock = await shouldBlockFn({
|
||||
action: blockerFnArgs.action,
|
||||
current,
|
||||
next,
|
||||
})
|
||||
if (!withResolver) {
|
||||
return shouldBlock
|
||||
}
|
||||
|
||||
if (!shouldBlock) {
|
||||
return false
|
||||
}
|
||||
|
||||
const promise = new Promise<boolean>((resolve) => {
|
||||
setResolver({
|
||||
status: 'blocked',
|
||||
current,
|
||||
next,
|
||||
action: blockerFnArgs.action,
|
||||
proceed: () => resolve(false),
|
||||
reset: () => resolve(true),
|
||||
})
|
||||
})
|
||||
|
||||
const canNavigateAsync = await promise
|
||||
setResolver({
|
||||
status: 'idle',
|
||||
current: undefined,
|
||||
next: undefined,
|
||||
action: undefined,
|
||||
proceed: undefined,
|
||||
reset: undefined,
|
||||
})
|
||||
|
||||
return canNavigateAsync
|
||||
}
|
||||
|
||||
return disabled
|
||||
? undefined
|
||||
: history.block({ blockerFn: blockerFnComposed, enableBeforeUnload })
|
||||
}, [
|
||||
shouldBlockFn,
|
||||
enableBeforeUnload,
|
||||
disabled,
|
||||
withResolver,
|
||||
history,
|
||||
router,
|
||||
])
|
||||
|
||||
return resolver
|
||||
}
|
||||
|
||||
const _resolvePromptBlockerArgs = (
|
||||
props: PromptProps | LegacyPromptProps,
|
||||
): UseBlockerOpts => {
|
||||
if ('shouldBlockFn' in props) {
|
||||
return { ...props }
|
||||
}
|
||||
|
||||
const shouldBlock = Boolean(props.condition ?? true)
|
||||
const fn = props.blockerFn
|
||||
|
||||
const _customBlockerFn = async () => {
|
||||
if (shouldBlock && fn !== undefined) {
|
||||
return await fn()
|
||||
}
|
||||
return shouldBlock
|
||||
}
|
||||
|
||||
return {
|
||||
shouldBlockFn: _customBlockerFn,
|
||||
enableBeforeUnload: shouldBlock,
|
||||
withResolver: fn === undefined,
|
||||
}
|
||||
}
|
||||
|
||||
export function Block<
|
||||
TRouter extends AnyRouter = RegisteredRouter,
|
||||
TWithResolver extends boolean = boolean,
|
||||
>(opts: PromptProps<TRouter, TWithResolver>): React.ReactNode
|
||||
|
||||
/**
|
||||
* @deprecated Use the UseBlockerOpts property instead
|
||||
*/
|
||||
export function Block(opts: LegacyPromptProps): React.ReactNode
|
||||
|
||||
export function Block(opts: PromptProps | LegacyPromptProps): React.ReactNode {
|
||||
const { children, ...rest } = opts
|
||||
const args = _resolvePromptBlockerArgs(rest)
|
||||
|
||||
const resolver = useBlocker(args)
|
||||
return children
|
||||
? typeof children === 'function'
|
||||
? children(resolver as any)
|
||||
: children
|
||||
: null
|
||||
}
|
||||
|
||||
type LegacyPromptProps = {
|
||||
blockerFn?: LegacyBlockerFn
|
||||
condition?: boolean | any
|
||||
children?: React.ReactNode | ((params: BlockerResolver) => React.ReactNode)
|
||||
}
|
||||
|
||||
type PromptProps<
|
||||
TRouter extends AnyRouter = RegisteredRouter,
|
||||
TWithResolver extends boolean = boolean,
|
||||
TParams = TWithResolver extends true ? BlockerResolver<TRouter> : void,
|
||||
> = UseBlockerOpts<TRouter, TWithResolver> & {
|
||||
children?: React.ReactNode | ((params: TParams) => React.ReactNode)
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
width="40"
|
||||
height="40"
|
||||
viewBox="0 0 40 40">
|
||||
<rect
|
||||
width="36.075428"
|
||||
height="31.096582"
|
||||
x="1.962286"
|
||||
y="4.4517088"
|
||||
id="rect4"
|
||||
style="fill:#ffff00;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1.23004246;stroke-opacity:1" />
|
||||
<rect
|
||||
width="27.96859"
|
||||
height="1.5012145"
|
||||
x="6.0157046"
|
||||
y="10.285"
|
||||
id="rect6"
|
||||
style="fill:#000000;fill-opacity:1;stroke:none" />
|
||||
<rect
|
||||
width="27.96859"
|
||||
height="0.85783684"
|
||||
x="6.0157056"
|
||||
y="23.21689"
|
||||
id="rect8"
|
||||
style="fill:#000000;fill-opacity:1;stroke:none" />
|
||||
<rect
|
||||
width="27.96859"
|
||||
height="0.85783684"
|
||||
x="5.8130345"
|
||||
y="28.964394"
|
||||
id="rect10"
|
||||
style="fill:#000000;fill-opacity:1;stroke:none" />
|
||||
<rect
|
||||
width="27.96859"
|
||||
height="0.85783684"
|
||||
x="6.0157046"
|
||||
y="17.426493"
|
||||
id="rect12"
|
||||
style="fill:#000000;fill-opacity:1;stroke:none" />
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.0 KiB |
@@ -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 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 XB YB ZB aB bB qC rC"},D:{"1":"0 9 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","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"},E:{"1":"C L M G 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 wC","132":"A B TC FC"},F:{"1":"0 4 5 6 7 8 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","2":"1 2 3 F B C G N O P QB 4C 5C 6C 7C FC kC 8C GC"},G:{"1":"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","2":"E SC 9C lC AD BD CD DD ED FD"},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:2,C:"WOFF 2.0 - Web Open Font Format",D:true};
|
||||
@@ -0,0 +1,355 @@
|
||||
/**
|
||||
* @fileoverview Rule to check for the usage of var.
|
||||
* @author Jamund Ferguson
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Requirements
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
const astUtils = require("./utils/ast-utils");
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Helpers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Check whether a given variable is a global variable or not.
|
||||
* @param {eslint-scope.Variable} variable The variable to check.
|
||||
* @returns {boolean} `true` if the variable is a global variable.
|
||||
*/
|
||||
function isGlobal(variable) {
|
||||
return Boolean(variable.scope) && variable.scope.type === "global";
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the nearest function scope or global scope walking up the scope
|
||||
* hierarchy.
|
||||
* @param {eslint-scope.Scope} scope The scope to traverse.
|
||||
* @returns {eslint-scope.Scope} a function scope or global scope containing the given
|
||||
* scope.
|
||||
*/
|
||||
function getEnclosingFunctionScope(scope) {
|
||||
let currentScope = scope;
|
||||
|
||||
while (currentScope.type !== "function" && currentScope.type !== "global") {
|
||||
currentScope = currentScope.upper;
|
||||
}
|
||||
return currentScope;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the given variable has any references from a more specific
|
||||
* function expression (i.e. a closure).
|
||||
* @param {eslint-scope.Variable} variable A variable to check.
|
||||
* @returns {boolean} `true` if the variable is used from a closure.
|
||||
*/
|
||||
function isReferencedInClosure(variable) {
|
||||
const enclosingFunctionScope = getEnclosingFunctionScope(variable.scope);
|
||||
|
||||
return variable.references.some(
|
||||
reference =>
|
||||
getEnclosingFunctionScope(reference.from) !==
|
||||
enclosingFunctionScope,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the given node is the assignee of a loop.
|
||||
* @param {ASTNode} node A VariableDeclaration node to check.
|
||||
* @returns {boolean} `true` if the declaration is assigned as part of loop
|
||||
* iteration.
|
||||
*/
|
||||
function isLoopAssignee(node) {
|
||||
return (
|
||||
(node.parent.type === "ForOfStatement" ||
|
||||
node.parent.type === "ForInStatement") &&
|
||||
node === node.parent.left
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the given variable declaration is immediately initialized.
|
||||
* @param {ASTNode} node A VariableDeclaration node to check.
|
||||
* @returns {boolean} `true` if the declaration has an initializer.
|
||||
*/
|
||||
function isDeclarationInitialized(node) {
|
||||
return node.declarations.every(declarator => declarator.init !== null);
|
||||
}
|
||||
|
||||
const SCOPE_NODE_TYPE =
|
||||
/^(?:Program|BlockStatement|SwitchStatement|ForStatement|ForInStatement|ForOfStatement)$/u;
|
||||
|
||||
/**
|
||||
* Gets the scope node which directly contains a given node.
|
||||
* @param {ASTNode} node A node to get. This is a `VariableDeclaration` or
|
||||
* an `Identifier`.
|
||||
* @returns {ASTNode} A scope node. This is one of `Program`, `BlockStatement`,
|
||||
* `SwitchStatement`, `ForStatement`, `ForInStatement`, and
|
||||
* `ForOfStatement`.
|
||||
*/
|
||||
function getScopeNode(node) {
|
||||
for (
|
||||
let currentNode = node;
|
||||
currentNode;
|
||||
currentNode = currentNode.parent
|
||||
) {
|
||||
if (SCOPE_NODE_TYPE.test(currentNode.type)) {
|
||||
return currentNode;
|
||||
}
|
||||
}
|
||||
|
||||
/* c8 ignore next */
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether a given variable is redeclared or not.
|
||||
* @param {eslint-scope.Variable} variable A variable to check.
|
||||
* @returns {boolean} `true` if the variable is redeclared.
|
||||
*/
|
||||
function isRedeclared(variable) {
|
||||
return variable.defs.length >= 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether a given variable is used from outside of the specified scope.
|
||||
* @param {ASTNode} scopeNode A scope node to check.
|
||||
* @returns {Function} The predicate function which checks whether a given
|
||||
* variable is used from outside of the specified scope.
|
||||
*/
|
||||
function isUsedFromOutsideOf(scopeNode) {
|
||||
/**
|
||||
* Checks whether a given reference is inside of the specified scope or not.
|
||||
* @param {eslint-scope.Reference} reference A reference to check.
|
||||
* @returns {boolean} `true` if the reference is inside of the specified
|
||||
* scope.
|
||||
*/
|
||||
function isOutsideOfScope(reference) {
|
||||
const scope = scopeNode.range;
|
||||
const id = reference.identifier.range;
|
||||
|
||||
return id[0] < scope[0] || id[1] > scope[1];
|
||||
}
|
||||
|
||||
return function (variable) {
|
||||
return variable.references.some(isOutsideOfScope);
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the predicate function which checks whether a variable has their references in TDZ.
|
||||
*
|
||||
* The predicate function would return `true`:
|
||||
*
|
||||
* - if a reference is before the declarator. E.g. (var a = b, b = 1;)(var {a = b, b} = {};)
|
||||
* - if a reference is in the expression of their default value. E.g. (var {a = a} = {};)
|
||||
* - if a reference is in the expression of their initializer. E.g. (var a = a;)
|
||||
* @param {ASTNode} node The initializer node of VariableDeclarator.
|
||||
* @returns {Function} The predicate function.
|
||||
* @private
|
||||
*/
|
||||
function hasReferenceInTDZ(node) {
|
||||
const initStart = node.range[0];
|
||||
const initEnd = node.range[1];
|
||||
|
||||
return variable => {
|
||||
const id = variable.defs[0].name;
|
||||
const idStart = id.range[0];
|
||||
const defaultValue =
|
||||
id.parent.type === "AssignmentPattern" ? id.parent.right : null;
|
||||
const defaultStart = defaultValue && defaultValue.range[0];
|
||||
const defaultEnd = defaultValue && defaultValue.range[1];
|
||||
|
||||
return variable.references.some(reference => {
|
||||
const start = reference.identifier.range[0];
|
||||
const end = reference.identifier.range[1];
|
||||
|
||||
return (
|
||||
!reference.init &&
|
||||
(start < idStart ||
|
||||
(defaultValue !== null &&
|
||||
start >= defaultStart &&
|
||||
end <= defaultEnd) ||
|
||||
(!astUtils.isFunction(node) &&
|
||||
start >= initStart &&
|
||||
end <= initEnd))
|
||||
);
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether a given variable has name that is allowed for 'var' declarations,
|
||||
* but disallowed for `let` declarations.
|
||||
* @param {eslint-scope.Variable} variable The variable to check.
|
||||
* @returns {boolean} `true` if the variable has a disallowed name.
|
||||
*/
|
||||
function hasNameDisallowedForLetDeclarations(variable) {
|
||||
return variable.name === "let";
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Rule Definition
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/** @type {import('../shared/types').Rule} */
|
||||
module.exports = {
|
||||
meta: {
|
||||
type: "suggestion",
|
||||
|
||||
docs: {
|
||||
description: "Require `let` or `const` instead of `var`",
|
||||
recommended: false,
|
||||
url: "https://eslint.org/docs/latest/rules/no-var",
|
||||
},
|
||||
|
||||
schema: [],
|
||||
fixable: "code",
|
||||
|
||||
messages: {
|
||||
unexpectedVar: "Unexpected var, use let or const instead.",
|
||||
},
|
||||
},
|
||||
|
||||
create(context) {
|
||||
const sourceCode = context.sourceCode;
|
||||
|
||||
/**
|
||||
* Checks whether the variables which are defined by the given declarator node have their references in TDZ.
|
||||
* @param {ASTNode} declarator The VariableDeclarator node to check.
|
||||
* @returns {boolean} `true` if one of the variables which are defined by the given declarator node have their references in TDZ.
|
||||
*/
|
||||
function hasSelfReferenceInTDZ(declarator) {
|
||||
if (!declarator.init) {
|
||||
return false;
|
||||
}
|
||||
const variables = sourceCode.getDeclaredVariables(declarator);
|
||||
|
||||
return variables.some(hasReferenceInTDZ(declarator.init));
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether it can fix a given variable declaration or not.
|
||||
* It cannot fix if the following cases:
|
||||
*
|
||||
* - A variable is a global variable.
|
||||
* - A variable is declared on a SwitchCase node.
|
||||
* - A variable is redeclared.
|
||||
* - A variable is used from outside the scope.
|
||||
* - A variable is used from a closure within a loop.
|
||||
* - A variable might be used before it is assigned within a loop.
|
||||
* - A variable might be used in TDZ.
|
||||
* - A variable is declared in statement position (e.g. a single-line `IfStatement`)
|
||||
* - A variable has name that is disallowed for `let` declarations.
|
||||
*
|
||||
* ## A variable is declared on a SwitchCase node.
|
||||
*
|
||||
* If this rule modifies 'var' declarations on a SwitchCase node, it
|
||||
* would generate the warnings of 'no-case-declarations' rule. And the
|
||||
* 'eslint:recommended' preset includes 'no-case-declarations' rule, so
|
||||
* this rule doesn't modify those declarations.
|
||||
*
|
||||
* ## A variable is redeclared.
|
||||
*
|
||||
* The language spec disallows redeclarations of `let` declarations.
|
||||
* Those variables would cause syntax errors.
|
||||
*
|
||||
* ## A variable is used from outside the scope.
|
||||
*
|
||||
* The language spec disallows accesses from outside of the scope for
|
||||
* `let` declarations. Those variables would cause reference errors.
|
||||
*
|
||||
* ## A variable is used from a closure within a loop.
|
||||
*
|
||||
* A `var` declaration within a loop shares the same variable instance
|
||||
* across all loop iterations, while a `let` declaration creates a new
|
||||
* instance for each iteration. This means if a variable in a loop is
|
||||
* referenced by any closure, changing it from `var` to `let` would
|
||||
* change the behavior in a way that is generally unsafe.
|
||||
*
|
||||
* ## A variable might be used before it is assigned within a loop.
|
||||
*
|
||||
* Within a loop, a `let` declaration without an initializer will be
|
||||
* initialized to null, while a `var` declaration will retain its value
|
||||
* from the previous iteration, so it is only safe to change `var` to
|
||||
* `let` if we can statically determine that the variable is always
|
||||
* assigned a value before its first access in the loop body. To keep
|
||||
* the implementation simple, we only convert `var` to `let` within
|
||||
* loops when the variable is a loop assignee or the declaration has an
|
||||
* initializer.
|
||||
* @param {ASTNode} node A variable declaration node to check.
|
||||
* @returns {boolean} `true` if it can fix the node.
|
||||
*/
|
||||
function canFix(node) {
|
||||
const variables = sourceCode.getDeclaredVariables(node);
|
||||
const scopeNode = getScopeNode(node);
|
||||
|
||||
if (
|
||||
node.parent.type === "SwitchCase" ||
|
||||
node.declarations.some(hasSelfReferenceInTDZ) ||
|
||||
variables.some(isGlobal) ||
|
||||
variables.some(isRedeclared) ||
|
||||
variables.some(isUsedFromOutsideOf(scopeNode)) ||
|
||||
variables.some(hasNameDisallowedForLetDeclarations)
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (astUtils.isInLoop(node)) {
|
||||
if (variables.some(isReferencedInClosure)) {
|
||||
return false;
|
||||
}
|
||||
if (!isLoopAssignee(node) && !isDeclarationInitialized(node)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
!isLoopAssignee(node) &&
|
||||
!(
|
||||
node.parent.type === "ForStatement" &&
|
||||
node.parent.init === node
|
||||
) &&
|
||||
!astUtils.STATEMENT_LIST_PARENTS.has(node.parent.type)
|
||||
) {
|
||||
// If the declaration is not in a block, e.g. `if (foo) var bar = 1;`, then it can't be fixed.
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reports a given variable declaration node.
|
||||
* @param {ASTNode} node A variable declaration node to report.
|
||||
* @returns {void}
|
||||
*/
|
||||
function report(node) {
|
||||
context.report({
|
||||
node,
|
||||
messageId: "unexpectedVar",
|
||||
|
||||
fix(fixer) {
|
||||
const varToken = sourceCode.getFirstToken(node, {
|
||||
filter: t => t.value === "var",
|
||||
});
|
||||
|
||||
return canFix(node)
|
||||
? fixer.replaceText(varToken, "let")
|
||||
: null;
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
"VariableDeclaration:exit"(node) {
|
||||
if (node.kind === "var") {
|
||||
report(node);
|
||||
}
|
||||
},
|
||||
};
|
||||
},
|
||||
};
|
||||
Binary file not shown.
@@ -0,0 +1,3 @@
|
||||
// @flow
|
||||
|
||||
export * from '../src';
|
||||
@@ -0,0 +1 @@
|
||||
module.exports={A:{A:{"1":"A B","2":"F mC","8":"K D E"},B:{"1":"C L M G N O P Q H R S T","2":"0 9 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":"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 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 qC rC","2":"0 9 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","4":"LC","8":"nC"},D:{"1":"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 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","2":"0 9 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 tC uC vC wC TC FC GC xC yC","2":"G 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","8":"sC SC"},F:{"1":"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 7C FC kC 8C GC","2":"0 F 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","8":"5C 6C"},G:{"1":"E SC 9C lC AD BD CD DD ED FD GD HD ID JD KD LD MD ND OD PD QD RD","2":"SD UC VC HC TD IC WC XC YC ZC aC UD JC bC cC dC eC fC VD KC gC hC iC jC"},H:{"2":"WD"},I:{"1":"LC J XD YD ZD aD lC bD cD","2":"I"},J:{"1":"D A"},K:{"1":"B C FC kC GC","2":"A H"},L:{"2":"I"},M:{"2":"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:{"2":"pD"},S:{"1":"qD","2":"rD"}},B:7,C:"Offline web applications",D:true};
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"names":["dispose_SuppressedError","error","suppressed","SuppressedError","stack","Error","prototype","Object","create","constructor","value","writable","configurable","_dispose","hasError","next","length","r","pop","p","d","call","v","a","Promise","resolve","then","err","e"],"sources":["../../src/helpers/dispose.js"],"sourcesContent":["/* @minVersion 7.22.0 */\n/* @onlyBabel7 */\n\nfunction dispose_SuppressedError(error, suppressed) {\n if (typeof SuppressedError !== \"undefined\") {\n // eslint-disable-next-line no-undef\n dispose_SuppressedError = SuppressedError;\n } else {\n dispose_SuppressedError = function SuppressedError(error, suppressed) {\n this.suppressed = suppressed;\n this.error = error;\n this.stack = new Error().stack;\n };\n dispose_SuppressedError.prototype = Object.create(Error.prototype, {\n constructor: {\n value: dispose_SuppressedError,\n writable: true,\n configurable: true,\n },\n });\n }\n return new dispose_SuppressedError(error, suppressed);\n}\n\nexport default function _dispose(stack, error, hasError) {\n function next() {\n while (stack.length > 0) {\n try {\n var r = stack.pop();\n var p = r.d.call(r.v);\n if (r.a) return Promise.resolve(p).then(next, err);\n } catch (e) {\n return err(e);\n }\n }\n if (hasError) throw error;\n }\n\n function err(e) {\n error = hasError ? new dispose_SuppressedError(error, e) : e;\n hasError = true;\n\n return next();\n }\n\n return next();\n}\n"],"mappings":";;;;;;AAGA,SAASA,uBAAuBA,CAACC,KAAK,EAAEC,UAAU,EAAE;EAClD,IAAI,OAAOC,eAAe,KAAK,WAAW,EAAE;IAE1CH,uBAAuB,GAAGG,eAAe;EAC3C,CAAC,MAAM;IACLH,uBAAuB,GAAG,SAASG,eAAeA,CAACF,KAAK,EAAEC,UAAU,EAAE;MACpE,IAAI,CAACA,UAAU,GAAGA,UAAU;MAC5B,IAAI,CAACD,KAAK,GAAGA,KAAK;MAClB,IAAI,CAACG,KAAK,GAAG,IAAIC,KAAK,CAAC,CAAC,CAACD,KAAK;IAChC,CAAC;IACDJ,uBAAuB,CAACM,SAAS,GAAGC,MAAM,CAACC,MAAM,CAACH,KAAK,CAACC,SAAS,EAAE;MACjEG,WAAW,EAAE;QACXC,KAAK,EAAEV,uBAAuB;QAC9BW,QAAQ,EAAE,IAAI;QACdC,YAAY,EAAE;MAChB;IACF,CAAC,CAAC;EACJ;EACA,OAAO,IAAIZ,uBAAuB,CAACC,KAAK,EAAEC,UAAU,CAAC;AACvD;AAEe,SAASW,QAAQA,CAACT,KAAK,EAAEH,KAAK,EAAEa,QAAQ,EAAE;EACvD,SAASC,IAAIA,CAAA,EAAG;IACd,OAAOX,KAAK,CAACY,MAAM,GAAG,CAAC,EAAE;MACvB,IAAI;QACF,IAAIC,CAAC,GAAGb,KAAK,CAACc,GAAG,CAAC,CAAC;QACnB,IAAIC,CAAC,GAAGF,CAAC,CAACG,CAAC,CAACC,IAAI,CAACJ,CAAC,CAACK,CAAC,CAAC;QACrB,IAAIL,CAAC,CAACM,CAAC,EAAE,OAAOC,OAAO,CAACC,OAAO,CAACN,CAAC,CAAC,CAACO,IAAI,CAACX,IAAI,EAAEY,GAAG,CAAC;MACpD,CAAC,CAAC,OAAOC,CAAC,EAAE;QACV,OAAOD,GAAG,CAACC,CAAC,CAAC;MACf;IACF;IACA,IAAId,QAAQ,EAAE,MAAMb,KAAK;EAC3B;EAEA,SAAS0B,GAAGA,CAACC,CAAC,EAAE;IACd3B,KAAK,GAAGa,QAAQ,GAAG,IAAId,uBAAuB,CAACC,KAAK,EAAE2B,CAAC,CAAC,GAAGA,CAAC;IAC5Dd,QAAQ,GAAG,IAAI;IAEf,OAAOC,IAAI,CAAC,CAAC;EACf;EAEA,OAAOA,IAAI,CAAC,CAAC;AACf","ignoreList":[]}
|
||||
@@ -0,0 +1,6 @@
|
||||
const parse = require('./parse')
|
||||
const valid = (version, options) => {
|
||||
const v = parse(version, options)
|
||||
return v ? v.version : null
|
||||
}
|
||||
module.exports = valid
|
||||
@@ -0,0 +1,118 @@
|
||||
/**
|
||||
* Interface that represents PDF data transport. If possible, it allows
|
||||
* progressively load entire or fragment of the PDF binary data.
|
||||
*
|
||||
* @interface
|
||||
*/
|
||||
export class IPDFStream {
|
||||
/**
|
||||
* Gets a reader for the entire PDF data.
|
||||
* @returns {IPDFStreamReader}
|
||||
*/
|
||||
getFullReader(): IPDFStreamReader;
|
||||
/**
|
||||
* Gets a reader for the range of the PDF data.
|
||||
* @param {number} begin - the start offset of the data.
|
||||
* @param {number} end - the end offset of the data.
|
||||
* @returns {IPDFStreamRangeReader}
|
||||
*/
|
||||
getRangeReader(begin: number, end: number): IPDFStreamRangeReader;
|
||||
/**
|
||||
* Cancels all opened reader and closes all their opened requests.
|
||||
* @param {Object} reason - the reason for cancelling
|
||||
*/
|
||||
cancelAllRequests(reason: Object): void;
|
||||
}
|
||||
/**
|
||||
* Interface for a PDF binary data fragment reader.
|
||||
*
|
||||
* @interface
|
||||
*/
|
||||
export class IPDFStreamRangeReader {
|
||||
/**
|
||||
* Sets or gets the progress callback. The callback can be useful when the
|
||||
* isStreamingSupported property of the object is defined as false.
|
||||
* The callback is called with one parameter: an object with the loaded
|
||||
* property.
|
||||
*/
|
||||
onProgress: any;
|
||||
/**
|
||||
* Gets ability of the stream to progressively load binary data.
|
||||
* @type {boolean}
|
||||
*/
|
||||
get isStreamingSupported(): boolean;
|
||||
/**
|
||||
* Requests a chunk of the binary data. The method returns the promise, which
|
||||
* is resolved into object with properties "value" and "done". If the done
|
||||
* is set to true, then the stream has reached its end, otherwise the value
|
||||
* contains binary data. Cancelled requests will be resolved with the done is
|
||||
* set to true.
|
||||
* @returns {Promise}
|
||||
*/
|
||||
read(): Promise<any>;
|
||||
/**
|
||||
* Cancels all pending read requests and closes the stream.
|
||||
* @param {Object} reason
|
||||
*/
|
||||
cancel(reason: Object): void;
|
||||
}
|
||||
/**
|
||||
* Interface for a PDF binary data reader.
|
||||
*
|
||||
* @interface
|
||||
*/
|
||||
export class IPDFStreamReader {
|
||||
/**
|
||||
* Sets or gets the progress callback. The callback can be useful when the
|
||||
* isStreamingSupported property of the object is defined as false.
|
||||
* The callback is called with one parameter: an object with the loaded and
|
||||
* total properties.
|
||||
*/
|
||||
onProgress: any;
|
||||
/**
|
||||
* Gets a promise that is resolved when the headers and other metadata of
|
||||
* the PDF data stream are available.
|
||||
* @type {Promise}
|
||||
*/
|
||||
get headersReady(): Promise<any>;
|
||||
/**
|
||||
* Gets the Content-Disposition filename. It is defined after the headersReady
|
||||
* promise is resolved.
|
||||
* @type {string|null} The filename, or `null` if the Content-Disposition
|
||||
* header is missing/invalid.
|
||||
*/
|
||||
get filename(): string | null;
|
||||
/**
|
||||
* Gets PDF binary data length. It is defined after the headersReady promise
|
||||
* is resolved.
|
||||
* @type {number} The data length (or 0 if unknown).
|
||||
*/
|
||||
get contentLength(): number;
|
||||
/**
|
||||
* Gets ability of the stream to handle range requests. It is defined after
|
||||
* the headersReady promise is resolved. Rejected when the reader is cancelled
|
||||
* or an error occurs.
|
||||
* @type {boolean}
|
||||
*/
|
||||
get isRangeSupported(): boolean;
|
||||
/**
|
||||
* Gets ability of the stream to progressively load binary data. It is defined
|
||||
* after the headersReady promise is resolved.
|
||||
* @type {boolean}
|
||||
*/
|
||||
get isStreamingSupported(): boolean;
|
||||
/**
|
||||
* Requests a chunk of the binary data. The method returns the promise, which
|
||||
* is resolved into object with properties "value" and "done". If the done
|
||||
* is set to true, then the stream has reached its end, otherwise the value
|
||||
* contains binary data. Cancelled requests will be resolved with the done is
|
||||
* set to true.
|
||||
* @returns {Promise}
|
||||
*/
|
||||
read(): Promise<any>;
|
||||
/**
|
||||
* Cancels all pending read requests and closes the stream.
|
||||
* @param {Object} reason
|
||||
*/
|
||||
cancel(reason: Object): void;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
module.exports = {
|
||||
1: 'ls', // WHATWG Living Standard
|
||||
2: 'rec', // W3C Recommendation
|
||||
3: 'pr', // W3C Proposed Recommendation
|
||||
4: 'cr', // W3C Candidate Recommendation
|
||||
5: 'wd', // W3C Working Draft
|
||||
6: 'other', // Non-W3C, but reputable
|
||||
7: 'unoff' // Unofficial, Editor's Draft or W3C "Note"
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
module.exports={C:{"42":0.00171,"49":0.00171,"52":0.00171,"56":0.00171,"72":0.00171,"87":0.00171,"91":0.00171,"103":0.00171,"112":0.00171,"115":0.1197,"121":0.00513,"125":0.00513,"127":0.00171,"128":0.01026,"130":0.00171,"131":0.00171,"132":0.00171,"133":0.01539,"134":0.00342,"135":0.09405,"136":0.21546,"137":0.00342,_:"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 43 44 45 46 47 48 50 51 53 54 55 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 73 74 75 76 77 78 79 80 81 82 83 84 85 86 88 89 90 92 93 94 95 96 97 98 99 100 101 102 104 105 106 107 108 109 110 111 113 114 116 117 118 119 120 122 123 124 126 129 138 139 140 3.5 3.6"},D:{"11":0.00855,"29":0.00171,"39":0.00171,"40":0.00171,"41":0.00342,"42":0.00171,"43":0.00171,"44":0.00171,"45":0.00171,"46":0.00171,"47":0.00684,"49":0.00342,"50":0.00171,"51":0.02223,"52":0.00171,"53":0.00171,"54":0.00171,"55":0.00171,"56":0.00171,"57":0.00171,"58":0.27531,"59":0.00171,"60":0.00171,"63":0.00342,"64":0.00171,"65":0.00342,"66":0.00171,"67":0.00513,"69":0.00171,"70":0.01197,"71":0.00171,"72":0.01197,"73":0.01197,"75":0.00855,"78":0.00684,"79":0.06498,"80":0.00171,"81":0.00513,"83":0.0171,"85":0.00171,"86":0.02052,"87":0.02223,"88":0.00342,"89":0.01881,"90":0.00855,"91":0.00855,"92":0.01026,"93":0.00171,"94":0.00855,"95":0.00342,"96":0.00513,"98":0.0171,"99":0.00171,"100":0.00171,"101":0.00342,"102":0.01026,"103":0.05643,"104":0.44118,"105":0.00513,"106":0.00171,"107":0.00171,"108":0.00684,"109":0.76437,"110":0.00855,"111":0.00855,"112":0.00684,"113":0.00171,"114":0.00342,"115":0.00342,"116":0.01368,"117":0.00684,"118":0.01539,"119":0.01197,"120":0.02052,"121":0.00684,"122":0.01539,"123":0.01539,"124":0.01539,"125":0.05301,"126":0.03249,"127":0.01368,"128":0.01026,"129":0.02565,"130":0.03249,"131":0.17442,"132":0.17784,"133":2.34612,"134":4.18437,"135":0.01026,"136":0.00342,_:"4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 30 31 32 33 34 35 36 37 38 48 61 62 68 74 76 77 84 97 137 138"},F:{"28":0.00171,"46":0.00342,"79":0.00684,"84":0.00171,"85":0.00171,"87":0.0342,"88":0.01881,"95":0.04959,"112":0.00171,"114":0.00342,"115":0.00342,"116":0.05814,"117":0.76608,_:"9 11 12 15 16 17 18 19 20 21 22 23 24 25 26 27 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 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 80 81 82 83 86 89 90 91 92 93 94 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 113 9.5-9.6 10.0-10.1 10.5 10.6 11.1 11.5 11.6 12.1"},B:{"14":0.00171,"17":0.00171,"18":0.00342,"84":0.00513,"89":0.00513,"90":0.00171,"91":0.00171,"92":0.0342,"100":0.00684,"103":0.00171,"109":0.02052,"114":0.00855,"117":0.00684,"120":0.00342,"121":0.00171,"122":0.00342,"126":0.00171,"127":0.00171,"128":0.00342,"129":0.00171,"130":0.00342,"131":0.02394,"132":0.13167,"133":0.48735,"134":1.15083,_:"12 13 15 16 79 80 81 83 85 86 87 88 93 94 95 96 97 98 99 101 102 104 105 106 107 108 110 111 112 113 115 116 118 119 123 124 125"},E:{"14":0.00171,_:"0 4 5 6 7 8 9 10 11 12 13 15 3.1 3.2 6.1 7.1 9.1 11.1 12.1 15.1 15.2-15.3 15.4 16.2 17.3 18.4","5.1":0.03762,"10.1":0.00171,"13.1":0.00171,"14.1":0.01539,"15.5":0.00171,"15.6":0.01197,"16.0":0.00171,"16.1":0.00513,"16.3":0.00513,"16.4":0.00342,"16.5":0.00171,"16.6":0.02736,"17.0":0.00171,"17.1":0.00855,"17.2":0.00171,"17.4":0.01026,"17.5":0.02394,"17.6":0.04446,"18.0":0.03762,"18.1":0.03762,"18.2":0.02907,"18.3":0.22572},G:{"8":0,"3.2":0,"4.0-4.1":0,"4.2-4.3":0.00226,"5.0-5.1":0,"6.0-6.1":0.00678,"7.0-7.1":0.00452,"8.1-8.4":0,"9.0-9.2":0.00339,"9.3":0.01581,"10.0-10.2":0.00113,"10.3":0.02597,"11.0-11.2":0.1197,"11.3-11.4":0.0079,"12.0-12.1":0.00452,"12.2-12.5":0.11179,"13.0-13.1":0.00226,"13.2":0.00339,"13.3":0.00452,"13.4-13.7":0.01581,"14.0-14.4":0.03952,"14.5-14.8":0.04743,"15.0-15.1":0.02597,"15.2-15.3":0.02597,"15.4":0.03162,"15.5":0.03614,"15.6-15.8":0.44492,"16.0":0.06324,"16.1":0.12986,"16.2":0.06775,"16.3":0.11744,"16.4":0.02597,"16.5":0.04856,"16.6-16.7":0.52735,"17.0":0.03162,"17.1":0.05646,"17.2":0.04291,"17.3":0.05985,"17.4":0.1197,"17.5":0.2665,"17.6-17.7":0.77353,"18.0":0.21681,"18.1":0.70916,"18.2":0.31731,"18.3":6.63199,"18.4":0.09824},P:{"4":0.05093,"20":0.01019,"21":0.0713,"22":0.12223,"23":0.10186,"24":0.34631,"25":0.41761,"26":0.36668,"27":1.94543,_:"5.0-5.4 10.1 12.0","6.2-6.4":0.05093,"7.2-7.4":0.29538,"8.2":0.06111,"9.2":0.02037,"11.1-11.2":0.04074,"13.0":0.02037,"14.0":0.03056,"15.0":0.01019,"16.0":0.05093,"17.0":0.02037,"18.0":0.04074,"19.0":0.05093},I:{"0":0.07446,"3":0,"4":0,"2.1":0,"2.2":0,"2.3":0,"4.1":0,"4.2-4.3":0.00002,"4.4":0,"4.4.3-4.4.4":0.00008},K:{"0":6.04559,_:"10 11 12 11.1 11.5 12.1"},A:{"11":0.00684,_:"6 7 8 9 10 5.5"},S:{_:"2.5 3.0-3.1"},J:{_:"7 10"},N:{_:"10 11"},R:{_:"0"},M:{"0":0.09949},Q:{_:"14.9"},O:{"0":0.31506},H:{"0":0.04},L:{"0":64.3605}};
|
||||
@@ -0,0 +1 @@
|
||||
module.exports={A:{A:{"1":"F A B","2":"K D E 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 1 2 3 4 5 6 7 8 9 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 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 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":"K D E F A B C L M G 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","2":"J sC SC","16":"PB"},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 5C 6C 7C FC kC 8C GC","16":"F 4C"},G:{"1":"E 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 9C lC"},H:{"2":"WD"},I:{"1":"LC J I ZD aD lC","16":"XD YD","132":"bD cD"},J:{"1":"D A"},K:{"1":"A B C H FC kC GC"},L:{"132":"I"},M:{"132":"EC"},N:{"1":"A B"},O:{"1":"HC"},P:{"2":"J","132":"1 2 3 4 5 6 7 8 dD eD fD gD hD TC iD jD kD lD mD IC JC KC nD"},Q:{"1":"oD"},R:{"132":"pD"},S:{"1":"qD rD"}},B:7,C:"KeyboardEvent.which",D:true};
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.js","sources":["../../src/index.ts"],"sourcesContent":["import { useSyncExternalStoreWithSelector } from 'use-sync-external-store/shim/with-selector.js'\nimport type { Derived, Store } from '@tanstack/store'\n\nexport * from '@tanstack/store'\n\n/**\n * @private\n */\nexport type NoInfer<T> = [T][T extends any ? 0 : never]\n\nexport function useStore<TState, TSelected = NoInfer<TState>>(\n store: Store<TState, any>,\n selector?: (state: NoInfer<TState>) => TSelected,\n): TSelected\nexport function useStore<TState, TSelected = NoInfer<TState>>(\n store: Derived<TState, any>,\n selector?: (state: NoInfer<TState>) => TSelected,\n): TSelected\nexport function useStore<TState, TSelected = NoInfer<TState>>(\n store: Store<TState, any> | Derived<TState, any>,\n selector: (state: NoInfer<TState>) => TSelected = (d) => d as any,\n): TSelected {\n const slice = useSyncExternalStoreWithSelector(\n store.subscribe,\n () => store.state,\n () => store.state,\n selector,\n shallow,\n )\n\n return slice\n}\n\nexport function shallow<T>(objA: T, objB: T) {\n if (Object.is(objA, objB)) {\n return true\n }\n\n if (\n typeof objA !== 'object' ||\n objA === null ||\n typeof objB !== 'object' ||\n objB === null\n ) {\n return false\n }\n\n if (objA instanceof Map && objB instanceof Map) {\n if (objA.size !== objB.size) return false\n for (const [k, v] of objA) {\n if (!objB.has(k) || !Object.is(v, objB.get(k))) return false\n }\n return true\n }\n\n if (objA instanceof Set && objB instanceof Set) {\n if (objA.size !== objB.size) return false\n for (const v of objA) {\n if (!objB.has(v)) return false\n }\n return true\n }\n\n const keysA = Object.keys(objA)\n if (keysA.length !== Object.keys(objB).length) {\n return false\n }\n\n for (let i = 0; i < keysA.length; i++) {\n if (\n !Object.prototype.hasOwnProperty.call(objB, keysA[i] as string) ||\n !Object.is(objA[keysA[i] as keyof T], objB[keysA[i] as keyof T])\n ) {\n return false\n }\n }\n return true\n}\n"],"names":[],"mappings":";;AAkBO,SAAS,SACd,OACA,WAAkD,CAAC,MAAM,GAC9C;AACX,QAAM,QAAQ;AAAA,IACZ,MAAM;AAAA,IACN,MAAM,MAAM;AAAA,IACZ,MAAM,MAAM;AAAA,IACZ;AAAA,IACA;AAAA,EACF;AAEO,SAAA;AACT;AAEgB,SAAA,QAAW,MAAS,MAAS;AAC3C,MAAI,OAAO,GAAG,MAAM,IAAI,GAAG;AAClB,WAAA;AAAA,EAAA;AAIP,MAAA,OAAO,SAAS,YAChB,SAAS,QACT,OAAO,SAAS,YAChB,SAAS,MACT;AACO,WAAA;AAAA,EAAA;AAGL,MAAA,gBAAgB,OAAO,gBAAgB,KAAK;AAC9C,QAAI,KAAK,SAAS,KAAK,KAAa,QAAA;AACpC,eAAW,CAAC,GAAG,CAAC,KAAK,MAAM;AACzB,UAAI,CAAC,KAAK,IAAI,CAAC,KAAK,CAAC,OAAO,GAAG,GAAG,KAAK,IAAI,CAAC,CAAC,EAAU,QAAA;AAAA,IAAA;AAElD,WAAA;AAAA,EAAA;AAGL,MAAA,gBAAgB,OAAO,gBAAgB,KAAK;AAC9C,QAAI,KAAK,SAAS,KAAK,KAAa,QAAA;AACpC,eAAW,KAAK,MAAM;AACpB,UAAI,CAAC,KAAK,IAAI,CAAC,EAAU,QAAA;AAAA,IAAA;AAEpB,WAAA;AAAA,EAAA;AAGH,QAAA,QAAQ,OAAO,KAAK,IAAI;AAC9B,MAAI,MAAM,WAAW,OAAO,KAAK,IAAI,EAAE,QAAQ;AACtC,WAAA;AAAA,EAAA;AAGT,WAAS,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK;AAEnC,QAAA,CAAC,OAAO,UAAU,eAAe,KAAK,MAAM,MAAM,CAAC,CAAW,KAC9D,CAAC,OAAO,GAAG,KAAK,MAAM,CAAC,CAAY,GAAG,KAAK,MAAM,CAAC,CAAY,CAAC,GAC/D;AACO,aAAA;AAAA,IAAA;AAAA,EACT;AAEK,SAAA;AACT;"}
|
||||
@@ -0,0 +1,69 @@
|
||||
import {
|
||||
defaultGetScrollRestorationKey,
|
||||
getCssSelector,
|
||||
scrollRestorationCache,
|
||||
setupScrollRestoration,
|
||||
} from '@tanstack/router-core'
|
||||
import { useRouter } from './useRouter'
|
||||
import type {
|
||||
ParsedLocation,
|
||||
ScrollRestorationEntry,
|
||||
ScrollRestorationOptions,
|
||||
} from '@tanstack/router-core'
|
||||
|
||||
function useScrollRestoration() {
|
||||
const router = useRouter()
|
||||
setupScrollRestoration(router, true)
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use createRouter's `scrollRestoration` option instead
|
||||
*/
|
||||
export function ScrollRestoration(_props: ScrollRestorationOptions) {
|
||||
useScrollRestoration()
|
||||
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
console.warn(
|
||||
"The ScrollRestoration component is deprecated. Use createRouter's `scrollRestoration` option instead.",
|
||||
)
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
export function useElementScrollRestoration(
|
||||
options: (
|
||||
| {
|
||||
id: string
|
||||
getElement?: () => Window | Element | undefined | null
|
||||
}
|
||||
| {
|
||||
id?: string
|
||||
getElement: () => Window | Element | undefined | null
|
||||
}
|
||||
) & {
|
||||
getKey?: (location: ParsedLocation) => string
|
||||
},
|
||||
): ScrollRestorationEntry | undefined {
|
||||
useScrollRestoration()
|
||||
|
||||
const router = useRouter()
|
||||
const getKey = options.getKey || defaultGetScrollRestorationKey
|
||||
|
||||
let elementSelector = ''
|
||||
|
||||
if (options.id) {
|
||||
elementSelector = `[data-scroll-restoration-id="${options.id}"]`
|
||||
} else {
|
||||
const element = options.getElement?.()
|
||||
if (!element) {
|
||||
return
|
||||
}
|
||||
elementSelector =
|
||||
element instanceof Window ? 'window' : getCssSelector(element)
|
||||
}
|
||||
|
||||
const restoreKey = getKey(router.latestLocation)
|
||||
const byKey = scrollRestorationCache.state[restoreKey]
|
||||
return byKey?.[elementSelector]
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = traverse;
|
||||
var _index = require("../definitions/index.js");
|
||||
function traverse(node, handlers, state) {
|
||||
if (typeof handlers === "function") {
|
||||
handlers = {
|
||||
enter: handlers
|
||||
};
|
||||
}
|
||||
const {
|
||||
enter,
|
||||
exit
|
||||
} = handlers;
|
||||
traverseSimpleImpl(node, enter, exit, state, []);
|
||||
}
|
||||
function traverseSimpleImpl(node, enter, exit, state, ancestors) {
|
||||
const keys = _index.VISITOR_KEYS[node.type];
|
||||
if (!keys) return;
|
||||
if (enter) enter(node, ancestors, state);
|
||||
for (const key of keys) {
|
||||
const subNode = node[key];
|
||||
if (Array.isArray(subNode)) {
|
||||
for (let i = 0; i < subNode.length; i++) {
|
||||
const child = subNode[i];
|
||||
if (!child) continue;
|
||||
ancestors.push({
|
||||
node,
|
||||
key,
|
||||
index: i
|
||||
});
|
||||
traverseSimpleImpl(child, enter, exit, state, ancestors);
|
||||
ancestors.pop();
|
||||
}
|
||||
} else if (subNode) {
|
||||
ancestors.push({
|
||||
node,
|
||||
key
|
||||
});
|
||||
traverseSimpleImpl(subNode, enter, exit, state, ancestors);
|
||||
ancestors.pop();
|
||||
}
|
||||
}
|
||||
if (exit) exit(node, ancestors, state);
|
||||
}
|
||||
|
||||
//# sourceMappingURL=traverse.js.map
|
||||
@@ -0,0 +1,77 @@
|
||||
{
|
||||
"name": "@jridgewell/trace-mapping",
|
||||
"version": "0.3.25",
|
||||
"description": "Trace the original position through a source map",
|
||||
"keywords": [
|
||||
"source",
|
||||
"map"
|
||||
],
|
||||
"main": "dist/trace-mapping.umd.js",
|
||||
"module": "dist/trace-mapping.mjs",
|
||||
"types": "dist/types/trace-mapping.d.ts",
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"exports": {
|
||||
".": [
|
||||
{
|
||||
"types": "./dist/types/trace-mapping.d.ts",
|
||||
"browser": "./dist/trace-mapping.umd.js",
|
||||
"require": "./dist/trace-mapping.umd.js",
|
||||
"import": "./dist/trace-mapping.mjs"
|
||||
},
|
||||
"./dist/trace-mapping.umd.js"
|
||||
],
|
||||
"./package.json": "./package.json"
|
||||
},
|
||||
"author": "Justin Ridgewell <justin@ridgewell.name>",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/jridgewell/trace-mapping.git"
|
||||
},
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"benchmark": "run-s build:rollup benchmark:*",
|
||||
"benchmark:install": "cd benchmark && npm install",
|
||||
"benchmark:only": "node --expose-gc benchmark/index.mjs",
|
||||
"build": "run-s -n build:*",
|
||||
"build:rollup": "rollup -c rollup.config.mjs",
|
||||
"build:ts": "tsc --project tsconfig.build.json",
|
||||
"lint": "run-s -n lint:*",
|
||||
"lint:prettier": "npm run test:lint:prettier -- --write",
|
||||
"lint:ts": "npm run test:lint:ts -- --fix",
|
||||
"prebuild": "rm -rf dist",
|
||||
"prepublishOnly": "npm run preversion",
|
||||
"preversion": "run-s test build",
|
||||
"test": "run-s -n test:lint test:only",
|
||||
"test:debug": "mocha --inspect-brk",
|
||||
"test:lint": "run-s -n test:lint:*",
|
||||
"test:lint:prettier": "prettier --check '{src,test}/**/*.ts' '**/*.md'",
|
||||
"test:lint:ts": "eslint '{src,test}/**/*.ts'",
|
||||
"test:only": "c8 mocha",
|
||||
"test:watch": "mocha --watch"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@rollup/plugin-typescript": "11.1.6",
|
||||
"@types/mocha": "10.0.6",
|
||||
"@types/node": "20.11.20",
|
||||
"@typescript-eslint/eslint-plugin": "6.18.1",
|
||||
"@typescript-eslint/parser": "6.18.1",
|
||||
"benchmark": "2.1.4",
|
||||
"c8": "9.0.0",
|
||||
"esbuild": "0.19.11",
|
||||
"eslint": "8.56.0",
|
||||
"eslint-config-prettier": "9.1.0",
|
||||
"eslint-plugin-no-only-tests": "3.1.0",
|
||||
"mocha": "10.3.0",
|
||||
"npm-run-all": "4.1.5",
|
||||
"prettier": "3.1.1",
|
||||
"rollup": "4.9.4",
|
||||
"tsx": "4.7.0",
|
||||
"typescript": "5.3.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"@jridgewell/resolve-uri": "^3.1.0",
|
||||
"@jridgewell/sourcemap-codec": "^1.4.14"
|
||||
}
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,15 @@
|
||||
import { Derived } from "./derived.js";
|
||||
import { Effect } from "./effect.js";
|
||||
import { Store } from "./store.js";
|
||||
import { __depsThatHaveWrittenThisTick, __derivedToStore, __flush, __storeToDerived, batch } from "./scheduler.js";
|
||||
export {
|
||||
Derived,
|
||||
Effect,
|
||||
Store,
|
||||
__depsThatHaveWrittenThisTick,
|
||||
__derivedToStore,
|
||||
__flush,
|
||||
__storeToDerived,
|
||||
batch
|
||||
};
|
||||
//# sourceMappingURL=index.js.map
|
||||
@@ -0,0 +1,7 @@
|
||||
Copyright 2018 Logan Smyth <loganfsmyth@gmail.com>
|
||||
|
||||
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.
|
||||
Reference in New Issue
Block a user