update
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
/**
|
||||
* @license React
|
||||
* use-sync-external-store.production.js
|
||||
*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
var useSyncExternalStore = require("react").useSyncExternalStore;
|
||||
exports.useSyncExternalStore = useSyncExternalStore;
|
||||
@@ -0,0 +1,21 @@
|
||||
The MIT License
|
||||
|
||||
Copyright JS Foundation and other contributors
|
||||
|
||||
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.
|
||||
@@ -0,0 +1,22 @@
|
||||
import { dirname, resolve } from 'path';
|
||||
import { readdir, stat } from 'fs';
|
||||
import { promisify } from 'util';
|
||||
|
||||
const toStats = promisify(stat);
|
||||
const toRead = promisify(readdir);
|
||||
|
||||
export default async function (start, callback) {
|
||||
let dir = resolve('.', start);
|
||||
let tmp, stats = await toStats(dir);
|
||||
|
||||
if (!stats.isDirectory()) {
|
||||
dir = dirname(dir);
|
||||
}
|
||||
|
||||
while (true) {
|
||||
tmp = await callback(dir, await toRead(dir));
|
||||
if (tmp) return resolve(dir, tmp);
|
||||
dir = dirname(tmp = dir);
|
||||
if (tmp === dir) break;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
import { RouterCore } from '@tanstack/router-core'
|
||||
import type { RouterHistory } from '@tanstack/history'
|
||||
import type {
|
||||
AnyRoute,
|
||||
CreateRouterFn,
|
||||
RouterConstructorOptions,
|
||||
TrailingSlashOption,
|
||||
} from '@tanstack/router-core'
|
||||
|
||||
import type {
|
||||
ErrorRouteComponent,
|
||||
NotFoundRouteComponent,
|
||||
RouteComponent,
|
||||
} from './route'
|
||||
|
||||
declare module '@tanstack/router-core' {
|
||||
export interface RouterOptionsExtensions {
|
||||
/**
|
||||
* The default `component` a route should use if no component is provided.
|
||||
*
|
||||
* @default Outlet
|
||||
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#defaultcomponent-property)
|
||||
*/
|
||||
defaultComponent?: RouteComponent
|
||||
/**
|
||||
* The default `errorComponent` a route should use if no error component is provided.
|
||||
*
|
||||
* @default ErrorComponent
|
||||
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#defaulterrorcomponent-property)
|
||||
* @link [Guide](https://tanstack.com/router/latest/docs/framework/react/guide/data-loading#handling-errors-with-routeoptionserrorcomponent)
|
||||
*/
|
||||
defaultErrorComponent?: ErrorRouteComponent
|
||||
/**
|
||||
* The default `pendingComponent` a route should use if no pending component is provided.
|
||||
*
|
||||
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#defaultpendingcomponent-property)
|
||||
* @link [Guide](https://tanstack.com/router/latest/docs/framework/react/guide/data-loading#showing-a-pending-component)
|
||||
*/
|
||||
defaultPendingComponent?: RouteComponent
|
||||
/**
|
||||
* The default `notFoundComponent` a route should use if no notFound component is provided.
|
||||
*
|
||||
* @default NotFound
|
||||
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#defaultnotfoundcomponent-property)
|
||||
* @link [Guide](https://tanstack.com/router/latest/docs/framework/react/guide/not-found-errors#default-router-wide-not-found-handling)
|
||||
*/
|
||||
defaultNotFoundComponent?: NotFoundRouteComponent
|
||||
/**
|
||||
* A component that will be used to wrap the entire router.
|
||||
*
|
||||
* This is useful for providing a context to the entire router.
|
||||
*
|
||||
* Only non-DOM-rendering components like providers should be used, anything else will cause a hydration error.
|
||||
*
|
||||
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#wrap-property)
|
||||
*/
|
||||
Wrap?: (props: { children: any }) => React.JSX.Element
|
||||
/**
|
||||
* A component that will be used to wrap the inner contents of the router.
|
||||
*
|
||||
* This is useful for providing a context to the inner contents of the router where you also need access to the router context and hooks.
|
||||
*
|
||||
* Only non-DOM-rendering components like providers should be used, anything else will cause a hydration error.
|
||||
*
|
||||
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#innerwrap-property)
|
||||
*/
|
||||
InnerWrap?: (props: { children: any }) => React.JSX.Element
|
||||
|
||||
/**
|
||||
* The default `onCatch` handler for errors caught by the Router ErrorBoundary
|
||||
*
|
||||
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#defaultoncatch-property)
|
||||
* @link [Guide](https://tanstack.com/router/latest/docs/framework/react/guide/data-loading#handling-errors-with-routeoptionsoncatch)
|
||||
*/
|
||||
defaultOnCatch?: (error: Error, errorInfo: React.ErrorInfo) => void
|
||||
}
|
||||
}
|
||||
|
||||
export const createRouter: CreateRouterFn = (options) => {
|
||||
return new Router(options)
|
||||
}
|
||||
|
||||
export class Router<
|
||||
in out TRouteTree extends AnyRoute,
|
||||
in out TTrailingSlashOption extends TrailingSlashOption = 'never',
|
||||
in out TDefaultStructuralSharingOption extends boolean = false,
|
||||
in out TRouterHistory extends RouterHistory = RouterHistory,
|
||||
in out TDehydrated extends Record<string, any> = Record<string, any>,
|
||||
> extends RouterCore<
|
||||
TRouteTree,
|
||||
TTrailingSlashOption,
|
||||
TDefaultStructuralSharingOption,
|
||||
TRouterHistory,
|
||||
TDehydrated
|
||||
> {
|
||||
constructor(
|
||||
options: RouterConstructorOptions<
|
||||
TRouteTree,
|
||||
TTrailingSlashOption,
|
||||
TDefaultStructuralSharingOption,
|
||||
TRouterHistory,
|
||||
TDehydrated
|
||||
>,
|
||||
) {
|
||||
super(options)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
import { decode, encode } from "./qss.js";
|
||||
const defaultParseSearch = parseSearchWith(JSON.parse);
|
||||
const defaultStringifySearch = stringifySearchWith(
|
||||
JSON.stringify,
|
||||
JSON.parse
|
||||
);
|
||||
function parseSearchWith(parser) {
|
||||
return (searchStr) => {
|
||||
if (searchStr.substring(0, 1) === "?") {
|
||||
searchStr = searchStr.substring(1);
|
||||
}
|
||||
const query = decode(searchStr);
|
||||
for (const key in query) {
|
||||
const value = query[key];
|
||||
if (typeof value === "string") {
|
||||
try {
|
||||
query[key] = parser(value);
|
||||
} catch (err) {
|
||||
}
|
||||
}
|
||||
}
|
||||
return query;
|
||||
};
|
||||
}
|
||||
function stringifySearchWith(stringify, parser) {
|
||||
function stringifyValue(val) {
|
||||
if (typeof val === "object" && val !== null) {
|
||||
try {
|
||||
return stringify(val);
|
||||
} catch (err) {
|
||||
}
|
||||
} else if (typeof val === "string" && typeof parser === "function") {
|
||||
try {
|
||||
parser(val);
|
||||
return stringify(val);
|
||||
} catch (err) {
|
||||
}
|
||||
}
|
||||
return val;
|
||||
}
|
||||
return (search) => {
|
||||
search = { ...search };
|
||||
Object.keys(search).forEach((key) => {
|
||||
const val = search[key];
|
||||
if (typeof val === "undefined" || val === void 0) {
|
||||
delete search[key];
|
||||
} else {
|
||||
search[key] = stringifyValue(val);
|
||||
}
|
||||
});
|
||||
const searchStr = encode(search).toString();
|
||||
return searchStr ? `?${searchStr}` : "";
|
||||
};
|
||||
}
|
||||
export {
|
||||
defaultParseSearch,
|
||||
defaultStringifySearch,
|
||||
parseSearchWith,
|
||||
stringifySearchWith
|
||||
};
|
||||
//# sourceMappingURL=searchParams.js.map
|
||||
@@ -0,0 +1,49 @@
|
||||
declare type Line = number;
|
||||
declare type Column = number;
|
||||
declare type Kind = number;
|
||||
declare type Name = number;
|
||||
declare type Var = number;
|
||||
declare type SourcesIndex = number;
|
||||
declare type ScopesIndex = number;
|
||||
declare type Mix<A, B, O> = (A & O) | (B & O);
|
||||
export declare type OriginalScope = Mix<[
|
||||
Line,
|
||||
Column,
|
||||
Line,
|
||||
Column,
|
||||
Kind
|
||||
], [
|
||||
Line,
|
||||
Column,
|
||||
Line,
|
||||
Column,
|
||||
Kind,
|
||||
Name
|
||||
], {
|
||||
vars: Var[];
|
||||
}>;
|
||||
export declare type GeneratedRange = Mix<[
|
||||
Line,
|
||||
Column,
|
||||
Line,
|
||||
Column
|
||||
], [
|
||||
Line,
|
||||
Column,
|
||||
Line,
|
||||
Column,
|
||||
SourcesIndex,
|
||||
ScopesIndex
|
||||
], {
|
||||
callsite: CallSite | null;
|
||||
bindings: Binding[];
|
||||
isScope: boolean;
|
||||
}>;
|
||||
export declare type CallSite = [SourcesIndex, Line, Column];
|
||||
declare type Binding = BindingExpressionRange[];
|
||||
export declare type BindingExpressionRange = [Name] | [Name, Line, Column];
|
||||
export declare function decodeOriginalScopes(input: string): OriginalScope[];
|
||||
export declare function encodeOriginalScopes(scopes: OriginalScope[]): string;
|
||||
export declare function decodeGeneratedRanges(input: string): GeneratedRange[];
|
||||
export declare function encodeGeneratedRanges(ranges: GeneratedRange[]): string;
|
||||
export {};
|
||||
@@ -0,0 +1,546 @@
|
||||
/**
|
||||
* @fileoverview A rule to suggest using of const declaration for variables that are never reassigned after declared.
|
||||
* @author Toru Nagashima
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Requirements
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
const FixTracker = require("./utils/fix-tracker");
|
||||
const astUtils = require("./utils/ast-utils");
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Helpers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
const PATTERN_TYPE =
|
||||
/^(?:.+?Pattern|RestElement|SpreadProperty|ExperimentalRestProperty|Property)$/u;
|
||||
const DECLARATION_HOST_TYPE =
|
||||
/^(?:Program|BlockStatement|StaticBlock|SwitchCase)$/u;
|
||||
const DESTRUCTURING_HOST_TYPE =
|
||||
/^(?:VariableDeclarator|AssignmentExpression)$/u;
|
||||
|
||||
/**
|
||||
* Checks whether a given node is located at `ForStatement.init` or not.
|
||||
* @param {ASTNode} node A node to check.
|
||||
* @returns {boolean} `true` if the node is located at `ForStatement.init`.
|
||||
*/
|
||||
function isInitOfForStatement(node) {
|
||||
return node.parent.type === "ForStatement" && node.parent.init === node;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether a given Identifier node becomes a VariableDeclaration or not.
|
||||
* @param {ASTNode} identifier An Identifier node to check.
|
||||
* @returns {boolean} `true` if the node can become a VariableDeclaration.
|
||||
*/
|
||||
function canBecomeVariableDeclaration(identifier) {
|
||||
let node = identifier.parent;
|
||||
|
||||
while (PATTERN_TYPE.test(node.type)) {
|
||||
node = node.parent;
|
||||
}
|
||||
|
||||
return (
|
||||
node.type === "VariableDeclarator" ||
|
||||
(node.type === "AssignmentExpression" &&
|
||||
node.parent.type === "ExpressionStatement" &&
|
||||
DECLARATION_HOST_TYPE.test(node.parent.parent.type))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if an property or element is from outer scope or function parameters
|
||||
* in destructing pattern.
|
||||
* @param {string} name A variable name to be checked.
|
||||
* @param {eslint-scope.Scope} initScope A scope to start find.
|
||||
* @returns {boolean} Indicates if the variable is from outer scope or function parameters.
|
||||
*/
|
||||
function isOuterVariableInDestructing(name, initScope) {
|
||||
if (
|
||||
initScope.through.some(
|
||||
ref => ref.resolved && ref.resolved.name === name,
|
||||
)
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const variable = astUtils.getVariableByName(initScope, name);
|
||||
|
||||
if (variable !== null) {
|
||||
return variable.defs.some(def => def.type === "Parameter");
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the VariableDeclarator/AssignmentExpression node that a given reference
|
||||
* belongs to.
|
||||
* This is used to detect a mix of reassigned and never reassigned in a
|
||||
* destructuring.
|
||||
* @param {eslint-scope.Reference} reference A reference to get.
|
||||
* @returns {ASTNode|null} A VariableDeclarator/AssignmentExpression node or
|
||||
* null.
|
||||
*/
|
||||
function getDestructuringHost(reference) {
|
||||
if (!reference.isWrite()) {
|
||||
return null;
|
||||
}
|
||||
let node = reference.identifier.parent;
|
||||
|
||||
while (PATTERN_TYPE.test(node.type)) {
|
||||
node = node.parent;
|
||||
}
|
||||
|
||||
if (!DESTRUCTURING_HOST_TYPE.test(node.type)) {
|
||||
return null;
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if a destructuring assignment node contains
|
||||
* any MemberExpression nodes. This is used to determine if a
|
||||
* variable that is only written once using destructuring can be
|
||||
* safely converted into a const declaration.
|
||||
* @param {ASTNode} node The ObjectPattern or ArrayPattern node to check.
|
||||
* @returns {boolean} True if the destructuring pattern contains
|
||||
* a MemberExpression, false if not.
|
||||
*/
|
||||
function hasMemberExpressionAssignment(node) {
|
||||
switch (node.type) {
|
||||
case "ObjectPattern":
|
||||
return node.properties.some(prop => {
|
||||
if (prop) {
|
||||
/*
|
||||
* Spread elements have an argument property while
|
||||
* others have a value property. Because different
|
||||
* parsers use different node types for spread elements,
|
||||
* we just check if there is an argument property.
|
||||
*/
|
||||
return hasMemberExpressionAssignment(
|
||||
prop.argument || prop.value,
|
||||
);
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
case "ArrayPattern":
|
||||
return node.elements.some(element => {
|
||||
if (element) {
|
||||
return hasMemberExpressionAssignment(element);
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
case "AssignmentPattern":
|
||||
return hasMemberExpressionAssignment(node.left);
|
||||
|
||||
case "MemberExpression":
|
||||
return true;
|
||||
|
||||
// no default
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an identifier node of a given variable.
|
||||
*
|
||||
* If the initialization exists or one or more reading references exist before
|
||||
* the first assignment, the identifier node is the node of the declaration.
|
||||
* Otherwise, the identifier node is the node of the first assignment.
|
||||
*
|
||||
* If the variable should not change to const, this function returns null.
|
||||
* - If the variable is reassigned.
|
||||
* - If the variable is never initialized nor assigned.
|
||||
* - If the variable is initialized in a different scope from the declaration.
|
||||
* - If the unique assignment of the variable cannot change to a declaration.
|
||||
* e.g. `if (a) b = 1` / `return (b = 1)`
|
||||
* - If the variable is declared in the global scope and `eslintUsed` is `true`.
|
||||
* `/*exported foo` directive comment makes such variables. This rule does not
|
||||
* warn such variables because this rule cannot distinguish whether the
|
||||
* exported variables are reassigned or not.
|
||||
* @param {eslint-scope.Variable} variable A variable to get.
|
||||
* @param {boolean} ignoreReadBeforeAssign
|
||||
* The value of `ignoreReadBeforeAssign` option.
|
||||
* @returns {ASTNode|null}
|
||||
* An Identifier node if the variable should change to const.
|
||||
* Otherwise, null.
|
||||
*/
|
||||
function getIdentifierIfShouldBeConst(variable, ignoreReadBeforeAssign) {
|
||||
if (variable.eslintUsed && variable.scope.type === "global") {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Finds the unique WriteReference.
|
||||
let writer = null;
|
||||
let isReadBeforeInit = false;
|
||||
const references = variable.references;
|
||||
|
||||
for (let i = 0; i < references.length; ++i) {
|
||||
const reference = references[i];
|
||||
|
||||
if (reference.isWrite()) {
|
||||
const isReassigned =
|
||||
writer !== null && writer.identifier !== reference.identifier;
|
||||
|
||||
if (isReassigned) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const destructuringHost = getDestructuringHost(reference);
|
||||
|
||||
if (
|
||||
destructuringHost !== null &&
|
||||
destructuringHost.left !== void 0
|
||||
) {
|
||||
const leftNode = destructuringHost.left;
|
||||
let hasOuterVariables = false,
|
||||
hasNonIdentifiers = false;
|
||||
|
||||
if (leftNode.type === "ObjectPattern") {
|
||||
const properties = leftNode.properties;
|
||||
|
||||
hasOuterVariables = properties
|
||||
.filter(prop => prop.value)
|
||||
.map(prop => prop.value.name)
|
||||
.some(name =>
|
||||
isOuterVariableInDestructing(name, variable.scope),
|
||||
);
|
||||
|
||||
hasNonIdentifiers = hasMemberExpressionAssignment(leftNode);
|
||||
} else if (leftNode.type === "ArrayPattern") {
|
||||
const elements = leftNode.elements;
|
||||
|
||||
hasOuterVariables = elements
|
||||
.map(element => element && element.name)
|
||||
.some(name =>
|
||||
isOuterVariableInDestructing(name, variable.scope),
|
||||
);
|
||||
|
||||
hasNonIdentifiers = hasMemberExpressionAssignment(leftNode);
|
||||
}
|
||||
|
||||
if (hasOuterVariables || hasNonIdentifiers) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
writer = reference;
|
||||
} else if (reference.isRead() && writer === null) {
|
||||
if (ignoreReadBeforeAssign) {
|
||||
return null;
|
||||
}
|
||||
isReadBeforeInit = true;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* If the assignment is from a different scope, ignore it.
|
||||
* If the assignment cannot change to a declaration, ignore it.
|
||||
*/
|
||||
const shouldBeConst =
|
||||
writer !== null &&
|
||||
writer.from === variable.scope &&
|
||||
canBecomeVariableDeclaration(writer.identifier);
|
||||
|
||||
if (!shouldBeConst) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (isReadBeforeInit) {
|
||||
return variable.defs[0].name;
|
||||
}
|
||||
|
||||
return writer.identifier;
|
||||
}
|
||||
|
||||
/**
|
||||
* Groups by the VariableDeclarator/AssignmentExpression node that each
|
||||
* reference of given variables belongs to.
|
||||
* This is used to detect a mix of reassigned and never reassigned in a
|
||||
* destructuring.
|
||||
* @param {eslint-scope.Variable[]} variables Variables to group by destructuring.
|
||||
* @param {boolean} ignoreReadBeforeAssign
|
||||
* The value of `ignoreReadBeforeAssign` option.
|
||||
* @returns {Map<ASTNode, ASTNode[]>} Grouped identifier nodes.
|
||||
*/
|
||||
function groupByDestructuring(variables, ignoreReadBeforeAssign) {
|
||||
const identifierMap = new Map();
|
||||
|
||||
for (let i = 0; i < variables.length; ++i) {
|
||||
const variable = variables[i];
|
||||
const references = variable.references;
|
||||
const identifier = getIdentifierIfShouldBeConst(
|
||||
variable,
|
||||
ignoreReadBeforeAssign,
|
||||
);
|
||||
let prevId = null;
|
||||
|
||||
for (let j = 0; j < references.length; ++j) {
|
||||
const reference = references[j];
|
||||
const id = reference.identifier;
|
||||
|
||||
/*
|
||||
* Avoid counting a reference twice or more for default values of
|
||||
* destructuring.
|
||||
*/
|
||||
if (id === prevId) {
|
||||
continue;
|
||||
}
|
||||
prevId = id;
|
||||
|
||||
// Add the identifier node into the destructuring group.
|
||||
const group = getDestructuringHost(reference);
|
||||
|
||||
if (group) {
|
||||
if (identifierMap.has(group)) {
|
||||
identifierMap.get(group).push(identifier);
|
||||
} else {
|
||||
identifierMap.set(group, [identifier]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return identifierMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the nearest parent of node with a given type.
|
||||
* @param {ASTNode} node The node to search from.
|
||||
* @param {string} type The type field of the parent node.
|
||||
* @param {Function} shouldStop A predicate that returns true if the traversal should stop, and false otherwise.
|
||||
* @returns {ASTNode} The closest ancestor with the specified type; null if no such ancestor exists.
|
||||
*/
|
||||
function findUp(node, type, shouldStop) {
|
||||
if (!node || shouldStop(node)) {
|
||||
return null;
|
||||
}
|
||||
if (node.type === type) {
|
||||
return node;
|
||||
}
|
||||
return findUp(node.parent, type, shouldStop);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Rule Definition
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/** @type {import('../shared/types').Rule} */
|
||||
module.exports = {
|
||||
meta: {
|
||||
type: "suggestion",
|
||||
|
||||
defaultOptions: [
|
||||
{
|
||||
destructuring: "any",
|
||||
ignoreReadBeforeAssign: false,
|
||||
},
|
||||
],
|
||||
|
||||
docs: {
|
||||
description:
|
||||
"Require `const` declarations for variables that are never reassigned after declared",
|
||||
recommended: false,
|
||||
url: "https://eslint.org/docs/latest/rules/prefer-const",
|
||||
},
|
||||
|
||||
fixable: "code",
|
||||
|
||||
schema: [
|
||||
{
|
||||
type: "object",
|
||||
properties: {
|
||||
destructuring: { enum: ["any", "all"] },
|
||||
ignoreReadBeforeAssign: { type: "boolean" },
|
||||
},
|
||||
additionalProperties: false,
|
||||
},
|
||||
],
|
||||
messages: {
|
||||
useConst: "'{{name}}' is never reassigned. Use 'const' instead.",
|
||||
},
|
||||
},
|
||||
|
||||
create(context) {
|
||||
const [{ destructuring, ignoreReadBeforeAssign }] = context.options;
|
||||
const shouldMatchAnyDestructuredVariable = destructuring !== "all";
|
||||
const sourceCode = context.sourceCode;
|
||||
const variables = [];
|
||||
let reportCount = 0;
|
||||
let checkedId = null;
|
||||
let checkedName = "";
|
||||
|
||||
/**
|
||||
* Reports given identifier nodes if all of the nodes should be declared
|
||||
* as const.
|
||||
*
|
||||
* The argument 'nodes' is an array of Identifier nodes.
|
||||
* This node is the result of 'getIdentifierIfShouldBeConst()', so it's
|
||||
* nullable. In simple declaration or assignment cases, the length of
|
||||
* the array is 1. In destructuring cases, the length of the array can
|
||||
* be 2 or more.
|
||||
* @param {(eslint-scope.Reference|null)[]} nodes
|
||||
* References which are grouped by destructuring to report.
|
||||
* @returns {void}
|
||||
*/
|
||||
function checkGroup(nodes) {
|
||||
const nodesToReport = nodes.filter(Boolean);
|
||||
|
||||
if (
|
||||
nodes.length &&
|
||||
(shouldMatchAnyDestructuredVariable ||
|
||||
nodesToReport.length === nodes.length)
|
||||
) {
|
||||
const varDeclParent = findUp(
|
||||
nodes[0],
|
||||
"VariableDeclaration",
|
||||
parentNode => parentNode.type.endsWith("Statement"),
|
||||
);
|
||||
const isVarDecParentNull = varDeclParent === null;
|
||||
|
||||
if (
|
||||
!isVarDecParentNull &&
|
||||
varDeclParent.declarations.length > 0
|
||||
) {
|
||||
const firstDeclaration = varDeclParent.declarations[0];
|
||||
|
||||
if (firstDeclaration.init) {
|
||||
const firstDecParent = firstDeclaration.init.parent;
|
||||
|
||||
/*
|
||||
* First we check the declaration type and then depending on
|
||||
* if the type is a "VariableDeclarator" or its an "ObjectPattern"
|
||||
* we compare the name and id from the first identifier, if the names are different
|
||||
* we assign the new name, id and reset the count of reportCount and nodeCount in
|
||||
* order to check each block for the number of reported errors and base our fix
|
||||
* based on comparing nodes.length and nodesToReport.length.
|
||||
*/
|
||||
|
||||
if (firstDecParent.type === "VariableDeclarator") {
|
||||
if (firstDecParent.id.name !== checkedName) {
|
||||
checkedName = firstDecParent.id.name;
|
||||
reportCount = 0;
|
||||
}
|
||||
|
||||
if (firstDecParent.id.type === "ObjectPattern") {
|
||||
if (firstDecParent.init.name !== checkedName) {
|
||||
checkedName = firstDecParent.init.name;
|
||||
reportCount = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (firstDecParent.id !== checkedId) {
|
||||
checkedId = firstDecParent.id;
|
||||
reportCount = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let shouldFix =
|
||||
varDeclParent &&
|
||||
// Don't do a fix unless all variables in the declarations are initialized (or it's in a for-in or for-of loop)
|
||||
(varDeclParent.parent.type === "ForInStatement" ||
|
||||
varDeclParent.parent.type === "ForOfStatement" ||
|
||||
varDeclParent.declarations.every(
|
||||
declaration => declaration.init,
|
||||
)) &&
|
||||
/*
|
||||
* If options.destructuring is "all", then this warning will not occur unless
|
||||
* every assignment in the destructuring should be const. In that case, it's safe
|
||||
* to apply the fix.
|
||||
*/
|
||||
nodesToReport.length === nodes.length;
|
||||
|
||||
if (
|
||||
!isVarDecParentNull &&
|
||||
varDeclParent.declarations &&
|
||||
varDeclParent.declarations.length !== 1
|
||||
) {
|
||||
if (
|
||||
varDeclParent &&
|
||||
varDeclParent.declarations &&
|
||||
varDeclParent.declarations.length >= 1
|
||||
) {
|
||||
/*
|
||||
* Add nodesToReport.length to a count, then comparing the count to the length
|
||||
* of the declarations in the current block.
|
||||
*/
|
||||
|
||||
reportCount += nodesToReport.length;
|
||||
|
||||
let totalDeclarationsCount = 0;
|
||||
|
||||
varDeclParent.declarations.forEach(declaration => {
|
||||
if (declaration.id.type === "ObjectPattern") {
|
||||
totalDeclarationsCount +=
|
||||
declaration.id.properties.length;
|
||||
} else if (declaration.id.type === "ArrayPattern") {
|
||||
totalDeclarationsCount +=
|
||||
declaration.id.elements.length;
|
||||
} else {
|
||||
totalDeclarationsCount += 1;
|
||||
}
|
||||
});
|
||||
|
||||
shouldFix =
|
||||
shouldFix && reportCount === totalDeclarationsCount;
|
||||
}
|
||||
}
|
||||
|
||||
nodesToReport.forEach(node => {
|
||||
context.report({
|
||||
node,
|
||||
messageId: "useConst",
|
||||
data: node,
|
||||
fix: shouldFix
|
||||
? fixer => {
|
||||
const letKeywordToken =
|
||||
sourceCode.getFirstToken(
|
||||
varDeclParent,
|
||||
t => t.value === varDeclParent.kind,
|
||||
);
|
||||
|
||||
/**
|
||||
* Extend the replacement range to the whole declaration,
|
||||
* in order to prevent other fixes in the same pass
|
||||
* https://github.com/eslint/eslint/issues/13899
|
||||
*/
|
||||
return new FixTracker(fixer, sourceCode)
|
||||
.retainRange(varDeclParent.range)
|
||||
.replaceTextRange(
|
||||
letKeywordToken.range,
|
||||
"const",
|
||||
);
|
||||
}
|
||||
: null,
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
"Program:exit"() {
|
||||
groupByDestructuring(variables, ignoreReadBeforeAssign).forEach(
|
||||
checkGroup,
|
||||
);
|
||||
},
|
||||
|
||||
VariableDeclaration(node) {
|
||||
if (node.kind === "let" && !isInitOfForStatement(node)) {
|
||||
variables.push(...sourceCode.getDeclaredVariables(node));
|
||||
}
|
||||
},
|
||||
};
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1 @@
|
||||
module.exports={A:{A:{"2":"K D E F A B mC"},B:{"2":"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:{"2":"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:{"2":"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 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","2":"J sC SC KC gC hC iC jC 3C","129":"PB tC"},F:{"2":"0 1 2 3 4 5 6 7 8 F B C G N O P QB RB SB TB UB VB WB XB YB ZB aB bB cB dB eB fB gB hB iB jB kB lB mB nB oB pB qB rB sB tB uB vB wB xB yB zB 0B 1B 2B 3B 4B 5B 6B 7B 8B 9B AC BC CC DC Q H R OC S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z 4C 5C 6C 7C FC kC 8C GC"},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","2":"SC 9C lC KC gC hC iC jC"},H:{"2":"WD"},I:{"2":"LC J I XD YD ZD aD lC bD cD"},J:{"2":"D A"},K:{"2":"A B C H FC kC GC"},L:{"2":"I"},M:{"2":"EC"},N:{"2":"A B"},O:{"2":"HC"},P:{"2":"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:{"2":"oD"},R:{"2":"pD"},S:{"2":"qD rD"}},B:6,C:"JPEG 2000 image format",D:true};
|
||||
@@ -0,0 +1,29 @@
|
||||
{
|
||||
"name": "yallist",
|
||||
"version": "3.1.1",
|
||||
"description": "Yet Another Linked List",
|
||||
"main": "yallist.js",
|
||||
"directories": {
|
||||
"test": "test"
|
||||
},
|
||||
"files": [
|
||||
"yallist.js",
|
||||
"iterator.js"
|
||||
],
|
||||
"dependencies": {},
|
||||
"devDependencies": {
|
||||
"tap": "^12.1.0"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "tap test/*.js --100",
|
||||
"preversion": "npm test",
|
||||
"postversion": "npm publish",
|
||||
"postpublish": "git push origin --all; git push origin --tags"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/isaacs/yallist.git"
|
||||
},
|
||||
"author": "Isaac Z. Schlueter <i@izs.me> (http://blog.izs.me/)",
|
||||
"license": "ISC"
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
'use strict';
|
||||
module.exports = function generate_comment(it, $keyword, $ruleType) {
|
||||
var out = ' ';
|
||||
var $schema = it.schema[$keyword];
|
||||
var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
|
||||
var $breakOnError = !it.opts.allErrors;
|
||||
var $comment = it.util.toQuotedString($schema);
|
||||
if (it.opts.$comment === true) {
|
||||
out += ' console.log(' + ($comment) + ');';
|
||||
} else if (typeof it.opts.$comment == 'function') {
|
||||
out += ' self._opts.$comment(' + ($comment) + ', ' + (it.util.toQuotedString($errSchemaPath)) + ', validate.root.schema);';
|
||||
}
|
||||
return out;
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
module.exports={C:{_:"2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 3.5 3.6"},D:{"133":8.7,"134":91.3,_:"4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 135 136 137 138"},F:{_:"9 11 12 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 60 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 9.5-9.6 10.0-10.1 10.5 10.6 11.1 11.5 11.6 12.1"},B:{_:"12 13 14 15 16 17 18 79 80 81 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134"},E:{_:"0 4 5 6 7 8 9 10 11 12 13 14 15 3.1 3.2 5.1 6.1 7.1 9.1 10.1 11.1 12.1 13.1 14.1 15.1 15.2-15.3 15.4 15.5 15.6 16.0 16.1 16.2 16.3 16.4 16.5 16.6 17.0 17.1 17.2 17.3 17.4 17.5 17.6 18.0 18.1 18.2 18.3 18.4"},G:{"8":0,"3.2":0,"4.0-4.1":0,"4.2-4.3":0,"5.0-5.1":0,"6.0-6.1":0,"7.0-7.1":0,"8.1-8.4":0,"9.0-9.2":0,"9.3":0,"10.0-10.2":0,"10.3":0,"11.0-11.2":0,"11.3-11.4":0,"12.0-12.1":0,"12.2-12.5":0,"13.0-13.1":0,"13.2":0,"13.3":0,"13.4-13.7":0,"14.0-14.4":0,"14.5-14.8":0,"15.0-15.1":0,"15.2-15.3":0,"15.4":0,"15.5":0,"15.6-15.8":0,"16.0":0,"16.1":0,"16.2":0,"16.3":0,"16.4":0,"16.5":0,"16.6-16.7":0,"17.0":0,"17.1":0,"17.2":0,"17.3":0,"17.4":0,"17.5":0,"17.6-17.7":0,"18.0":0,"18.1":0,"18.2":0,"18.3":0,"18.4":0},P:{_:"4 20 21 22 23 24 25 26 27 5.0-5.4 6.2-6.4 7.2-7.4 8.2 9.2 10.1 11.1-11.2 12.0 13.0 14.0 15.0 16.0 17.0 18.0 19.0"},I:{"0":0,"3":0,"4":0,"2.1":0,"2.2":0,"2.3":0,"4.1":0,"4.2-4.3":0,"4.4":0,"4.4.3-4.4.4":0},K:{"0":0,_:"10 11 12 11.1 11.5 12.1"},A:{_:"6 7 8 9 10 11 5.5"},S:{_:"2.5 3.0-3.1"},J:{_:"7 10"},N:{_:"10 11"},R:{_:"0"},M:{_:"0"},Q:{_:"14.9"},O:{_:"0"},H:{"0":0},L:{_:"0"}};
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,87 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
Object.defineProperty(exports, "Hub", {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return _hub.default;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "NodePath", {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return _index.default;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "Scope", {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return _index2.default;
|
||||
}
|
||||
});
|
||||
exports.visitors = exports.default = void 0;
|
||||
require("./path/context.js");
|
||||
var visitors = require("./visitors.js");
|
||||
exports.visitors = visitors;
|
||||
var _t = require("@babel/types");
|
||||
var cache = require("./cache.js");
|
||||
var _traverseNode = require("./traverse-node.js");
|
||||
var _index = require("./path/index.js");
|
||||
var _index2 = require("./scope/index.js");
|
||||
var _hub = require("./hub.js");
|
||||
const {
|
||||
VISITOR_KEYS,
|
||||
removeProperties,
|
||||
traverseFast
|
||||
} = _t;
|
||||
function traverse(parent, opts = {}, scope, state, parentPath, visitSelf) {
|
||||
if (!parent) return;
|
||||
if (!opts.noScope && !scope) {
|
||||
if (parent.type !== "Program" && parent.type !== "File") {
|
||||
throw new Error("You must pass a scope and parentPath unless traversing a Program/File. " + `Instead of that you tried to traverse a ${parent.type} node without ` + "passing scope and parentPath.");
|
||||
}
|
||||
}
|
||||
if (!parentPath && visitSelf) {
|
||||
throw new Error("visitSelf can only be used when providing a NodePath.");
|
||||
}
|
||||
if (!VISITOR_KEYS[parent.type]) {
|
||||
return;
|
||||
}
|
||||
visitors.explode(opts);
|
||||
(0, _traverseNode.traverseNode)(parent, opts, scope, state, parentPath, null, visitSelf);
|
||||
}
|
||||
var _default = exports.default = traverse;
|
||||
traverse.visitors = visitors;
|
||||
traverse.verify = visitors.verify;
|
||||
traverse.explode = visitors.explode;
|
||||
traverse.cheap = function (node, enter) {
|
||||
traverseFast(node, enter);
|
||||
return;
|
||||
};
|
||||
traverse.node = function (node, opts, scope, state, path, skipKeys) {
|
||||
(0, _traverseNode.traverseNode)(node, opts, scope, state, path, skipKeys);
|
||||
};
|
||||
traverse.clearNode = function (node, opts) {
|
||||
removeProperties(node, opts);
|
||||
};
|
||||
traverse.removeProperties = function (tree, opts) {
|
||||
traverseFast(tree, traverse.clearNode, opts);
|
||||
return tree;
|
||||
};
|
||||
traverse.hasType = function (tree, type, denylistTypes) {
|
||||
if (denylistTypes != null && denylistTypes.includes(tree.type)) return false;
|
||||
if (tree.type === type) return true;
|
||||
return traverseFast(tree, function (node) {
|
||||
if (denylistTypes != null && denylistTypes.includes(node.type)) {
|
||||
return traverseFast.skip;
|
||||
}
|
||||
if (node.type === type) {
|
||||
return traverseFast.stop;
|
||||
}
|
||||
});
|
||||
};
|
||||
traverse.cache = cache;
|
||||
|
||||
//# sourceMappingURL=index.js.map
|
||||
@@ -0,0 +1,202 @@
|
||||
(function (global, factory) {
|
||||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('@jridgewell/trace-mapping'), require('@jridgewell/gen-mapping')) :
|
||||
typeof define === 'function' && define.amd ? define(['@jridgewell/trace-mapping', '@jridgewell/gen-mapping'], factory) :
|
||||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.remapping = factory(global.traceMapping, global.genMapping));
|
||||
})(this, (function (traceMapping, genMapping) { 'use strict';
|
||||
|
||||
const SOURCELESS_MAPPING = /* #__PURE__ */ SegmentObject('', -1, -1, '', null, false);
|
||||
const EMPTY_SOURCES = [];
|
||||
function SegmentObject(source, line, column, name, content, ignore) {
|
||||
return { source, line, column, name, content, ignore };
|
||||
}
|
||||
function Source(map, sources, source, content, ignore) {
|
||||
return {
|
||||
map,
|
||||
sources,
|
||||
source,
|
||||
content,
|
||||
ignore,
|
||||
};
|
||||
}
|
||||
/**
|
||||
* MapSource represents a single sourcemap, with the ability to trace mappings into its child nodes
|
||||
* (which may themselves be SourceMapTrees).
|
||||
*/
|
||||
function MapSource(map, sources) {
|
||||
return Source(map, sources, '', null, false);
|
||||
}
|
||||
/**
|
||||
* A "leaf" node in the sourcemap tree, representing an original, unmodified source file. Recursive
|
||||
* segment tracing ends at the `OriginalSource`.
|
||||
*/
|
||||
function OriginalSource(source, content, ignore) {
|
||||
return Source(null, EMPTY_SOURCES, source, content, ignore);
|
||||
}
|
||||
/**
|
||||
* traceMappings is only called on the root level SourceMapTree, and begins the process of
|
||||
* resolving each mapping in terms of the original source files.
|
||||
*/
|
||||
function traceMappings(tree) {
|
||||
// TODO: Eventually support sourceRoot, which has to be removed because the sources are already
|
||||
// fully resolved. We'll need to make sources relative to the sourceRoot before adding them.
|
||||
const gen = new genMapping.GenMapping({ file: tree.map.file });
|
||||
const { sources: rootSources, map } = tree;
|
||||
const rootNames = map.names;
|
||||
const rootMappings = traceMapping.decodedMappings(map);
|
||||
for (let i = 0; i < rootMappings.length; i++) {
|
||||
const segments = rootMappings[i];
|
||||
for (let j = 0; j < segments.length; j++) {
|
||||
const segment = segments[j];
|
||||
const genCol = segment[0];
|
||||
let traced = SOURCELESS_MAPPING;
|
||||
// 1-length segments only move the current generated column, there's no source information
|
||||
// to gather from it.
|
||||
if (segment.length !== 1) {
|
||||
const source = rootSources[segment[1]];
|
||||
traced = originalPositionFor(source, segment[2], segment[3], segment.length === 5 ? rootNames[segment[4]] : '');
|
||||
// If the trace is invalid, then the trace ran into a sourcemap that doesn't contain a
|
||||
// respective segment into an original source.
|
||||
if (traced == null)
|
||||
continue;
|
||||
}
|
||||
const { column, line, name, content, source, ignore } = traced;
|
||||
genMapping.maybeAddSegment(gen, i, genCol, source, line, column, name);
|
||||
if (source && content != null)
|
||||
genMapping.setSourceContent(gen, source, content);
|
||||
if (ignore)
|
||||
genMapping.setIgnore(gen, source, true);
|
||||
}
|
||||
}
|
||||
return gen;
|
||||
}
|
||||
/**
|
||||
* originalPositionFor is only called on children SourceMapTrees. It recurses down into its own
|
||||
* child SourceMapTrees, until we find the original source map.
|
||||
*/
|
||||
function originalPositionFor(source, line, column, name) {
|
||||
if (!source.map) {
|
||||
return SegmentObject(source.source, line, column, name, source.content, source.ignore);
|
||||
}
|
||||
const segment = traceMapping.traceSegment(source.map, line, column);
|
||||
// If we couldn't find a segment, then this doesn't exist in the sourcemap.
|
||||
if (segment == null)
|
||||
return null;
|
||||
// 1-length segments only move the current generated column, there's no source information
|
||||
// to gather from it.
|
||||
if (segment.length === 1)
|
||||
return SOURCELESS_MAPPING;
|
||||
return originalPositionFor(source.sources[segment[1]], segment[2], segment[3], segment.length === 5 ? source.map.names[segment[4]] : name);
|
||||
}
|
||||
|
||||
function asArray(value) {
|
||||
if (Array.isArray(value))
|
||||
return value;
|
||||
return [value];
|
||||
}
|
||||
/**
|
||||
* Recursively builds a tree structure out of sourcemap files, with each node
|
||||
* being either an `OriginalSource` "leaf" or a `SourceMapTree` composed of
|
||||
* `OriginalSource`s and `SourceMapTree`s.
|
||||
*
|
||||
* Every sourcemap is composed of a collection of source files and mappings
|
||||
* into locations of those source files. When we generate a `SourceMapTree` for
|
||||
* the sourcemap, we attempt to load each source file's own sourcemap. If it
|
||||
* does not have an associated sourcemap, it is considered an original,
|
||||
* unmodified source file.
|
||||
*/
|
||||
function buildSourceMapTree(input, loader) {
|
||||
const maps = asArray(input).map((m) => new traceMapping.TraceMap(m, ''));
|
||||
const map = maps.pop();
|
||||
for (let i = 0; i < maps.length; i++) {
|
||||
if (maps[i].sources.length > 1) {
|
||||
throw new Error(`Transformation map ${i} must have exactly one source file.\n` +
|
||||
'Did you specify these with the most recent transformation maps first?');
|
||||
}
|
||||
}
|
||||
let tree = build(map, loader, '', 0);
|
||||
for (let i = maps.length - 1; i >= 0; i--) {
|
||||
tree = MapSource(maps[i], [tree]);
|
||||
}
|
||||
return tree;
|
||||
}
|
||||
function build(map, loader, importer, importerDepth) {
|
||||
const { resolvedSources, sourcesContent, ignoreList } = map;
|
||||
const depth = importerDepth + 1;
|
||||
const children = resolvedSources.map((sourceFile, i) => {
|
||||
// The loading context gives the loader more information about why this file is being loaded
|
||||
// (eg, from which importer). It also allows the loader to override the location of the loaded
|
||||
// sourcemap/original source, or to override the content in the sourcesContent field if it's
|
||||
// an unmodified source file.
|
||||
const ctx = {
|
||||
importer,
|
||||
depth,
|
||||
source: sourceFile || '',
|
||||
content: undefined,
|
||||
ignore: undefined,
|
||||
};
|
||||
// Use the provided loader callback to retrieve the file's sourcemap.
|
||||
// TODO: We should eventually support async loading of sourcemap files.
|
||||
const sourceMap = loader(ctx.source, ctx);
|
||||
const { source, content, ignore } = ctx;
|
||||
// If there is a sourcemap, then we need to recurse into it to load its source files.
|
||||
if (sourceMap)
|
||||
return build(new traceMapping.TraceMap(sourceMap, source), loader, source, depth);
|
||||
// Else, it's an unmodified source file.
|
||||
// The contents of this unmodified source file can be overridden via the loader context,
|
||||
// allowing it to be explicitly null or a string. If it remains undefined, we fall back to
|
||||
// the importing sourcemap's `sourcesContent` field.
|
||||
const sourceContent = content !== undefined ? content : sourcesContent ? sourcesContent[i] : null;
|
||||
const ignored = ignore !== undefined ? ignore : ignoreList ? ignoreList.includes(i) : false;
|
||||
return OriginalSource(source, sourceContent, ignored);
|
||||
});
|
||||
return MapSource(map, children);
|
||||
}
|
||||
|
||||
/**
|
||||
* A SourceMap v3 compatible sourcemap, which only includes fields that were
|
||||
* provided to it.
|
||||
*/
|
||||
class SourceMap {
|
||||
constructor(map, options) {
|
||||
const out = options.decodedMappings ? genMapping.toDecodedMap(map) : genMapping.toEncodedMap(map);
|
||||
this.version = out.version; // SourceMap spec says this should be first.
|
||||
this.file = out.file;
|
||||
this.mappings = out.mappings;
|
||||
this.names = out.names;
|
||||
this.ignoreList = out.ignoreList;
|
||||
this.sourceRoot = out.sourceRoot;
|
||||
this.sources = out.sources;
|
||||
if (!options.excludeContent) {
|
||||
this.sourcesContent = out.sourcesContent;
|
||||
}
|
||||
}
|
||||
toString() {
|
||||
return JSON.stringify(this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Traces through all the mappings in the root sourcemap, through the sources
|
||||
* (and their sourcemaps), all the way back to the original source location.
|
||||
*
|
||||
* `loader` will be called every time we encounter a source file. If it returns
|
||||
* a sourcemap, we will recurse into that sourcemap to continue the trace. If
|
||||
* it returns a falsey value, that source file is treated as an original,
|
||||
* unmodified source file.
|
||||
*
|
||||
* Pass `excludeContent` to exclude any self-containing source file content
|
||||
* from the output sourcemap.
|
||||
*
|
||||
* Pass `decodedMappings` to receive a SourceMap with decoded (instead of
|
||||
* VLQ encoded) mappings.
|
||||
*/
|
||||
function remapping(input, loader, options) {
|
||||
const opts = typeof options === 'object' ? options : { excludeContent: !!options, decodedMappings: false };
|
||||
const tree = buildSourceMapTree(input, loader);
|
||||
return new SourceMap(traceMappings(tree), opts);
|
||||
}
|
||||
|
||||
return remapping;
|
||||
|
||||
}));
|
||||
//# sourceMappingURL=remapping.umd.js.map
|
||||
@@ -0,0 +1,5 @@
|
||||
const SemVer = require('../classes/semver')
|
||||
const compare = (a, b, loose) =>
|
||||
new SemVer(a, loose).compare(new SemVer(b, loose))
|
||||
|
||||
module.exports = compare
|
||||
@@ -0,0 +1,26 @@
|
||||
import { StructuralSharingOption, ValidateSelected } from './structuralSharing.cjs';
|
||||
import { ReactNode } from './route.cjs';
|
||||
import { AnyRouter, DeepPartial, MakeOptionalPathParams, MakeOptionalSearchParams, MakeRouteMatchUnion, MaskOptions, MatchRouteOptions, NoInfer, RegisteredRouter, ResolveRelativePath, ResolveRoute, RouteByPath, ToSubOptionsProps } from '@tanstack/router-core';
|
||||
import * as React from 'react';
|
||||
declare module '@tanstack/router-core' {
|
||||
interface RouteMatchExtensions {
|
||||
meta?: Array<React.JSX.IntrinsicElements['meta'] | undefined>;
|
||||
links?: Array<React.JSX.IntrinsicElements['link'] | undefined>;
|
||||
scripts?: Array<React.JSX.IntrinsicElements['script'] | undefined>;
|
||||
headScripts?: Array<React.JSX.IntrinsicElements['script'] | undefined>;
|
||||
}
|
||||
}
|
||||
export declare function Matches(): import("react/jsx-runtime").JSX.Element;
|
||||
export type UseMatchRouteOptions<TRouter extends AnyRouter = RegisteredRouter, TFrom extends string = string, TTo extends string | undefined = undefined, TMaskFrom extends string = TFrom, TMaskTo extends string = ''> = ToSubOptionsProps<TRouter, TFrom, TTo> & DeepPartial<MakeOptionalSearchParams<TRouter, TFrom, TTo>> & DeepPartial<MakeOptionalPathParams<TRouter, TFrom, TTo>> & MaskOptions<TRouter, TMaskFrom, TMaskTo> & MatchRouteOptions;
|
||||
export declare function useMatchRoute<TRouter extends AnyRouter = RegisteredRouter>(): <const TFrom extends string = string, const TTo extends string | undefined = undefined, const TMaskFrom extends string = TFrom, const TMaskTo extends string = "">(opts: UseMatchRouteOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>) => false | ResolveRoute<TRouter, TFrom, TTo>["types"]["allParams"];
|
||||
export type MakeMatchRouteOptions<TRouter extends AnyRouter = RegisteredRouter, TFrom extends string = string, TTo extends string | undefined = undefined, TMaskFrom extends string = TFrom, TMaskTo extends string = ''> = UseMatchRouteOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo> & {
|
||||
children?: ((params?: RouteByPath<TRouter['routeTree'], ResolveRelativePath<TFrom, NoInfer<TTo>>>['types']['allParams']) => ReactNode) | React.ReactNode;
|
||||
};
|
||||
export declare function MatchRoute<TRouter extends AnyRouter = RegisteredRouter, const TFrom extends string = string, const TTo extends string | undefined = undefined, const TMaskFrom extends string = TFrom, const TMaskTo extends string = ''>(props: MakeMatchRouteOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>): any;
|
||||
export interface UseMatchesBaseOptions<TRouter extends AnyRouter, TSelected, TStructuralSharing> {
|
||||
select?: (matches: Array<MakeRouteMatchUnion<TRouter>>) => ValidateSelected<TRouter, TSelected, TStructuralSharing>;
|
||||
}
|
||||
export type UseMatchesResult<TRouter extends AnyRouter, TSelected> = unknown extends TSelected ? Array<MakeRouteMatchUnion<TRouter>> : TSelected;
|
||||
export declare function useMatches<TRouter extends AnyRouter = RegisteredRouter, TSelected = unknown, TStructuralSharing extends boolean = boolean>(opts?: UseMatchesBaseOptions<TRouter, TSelected, TStructuralSharing> & StructuralSharingOption<TRouter, TSelected, TStructuralSharing>): UseMatchesResult<TRouter, TSelected>;
|
||||
export declare function useParentMatches<TRouter extends AnyRouter = RegisteredRouter, TSelected = unknown, TStructuralSharing extends boolean = boolean>(opts?: UseMatchesBaseOptions<TRouter, TSelected, TStructuralSharing> & StructuralSharingOption<TRouter, TSelected, TStructuralSharing>): UseMatchesResult<TRouter, TSelected>;
|
||||
export declare function useChildMatches<TRouter extends AnyRouter = RegisteredRouter, TSelected = unknown, TStructuralSharing extends boolean = boolean>(opts?: UseMatchesBaseOptions<TRouter, TSelected, TStructuralSharing> & StructuralSharingOption<TRouter, TSelected, TStructuralSharing>): UseMatchesResult<TRouter, TSelected>;
|
||||
@@ -0,0 +1 @@
|
||||
module.exports={A:{A:{"2":"K D mC","4":"E F A B"},B:{"4":"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:{"4":"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:{"4":"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:{"2":"sC SC","4":"J PB 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"},F:{"2":"F","4":"0 1 2 3 4 5 6 7 8 B C G N O P QB RB SB TB UB VB WB XB YB ZB aB bB cB dB eB fB gB hB iB jB kB lB mB nB oB pB qB rB sB tB uB vB wB xB yB zB 0B 1B 2B 3B 4B 5B 6B 7B 8B 9B AC BC CC DC Q H R OC S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z 4C 5C 6C 7C FC kC 8C GC"},G:{"4":"E SC 9C lC AD BD CD DD ED FD GD HD ID JD KD LD MD ND OD PD QD RD SD UC VC HC TD IC WC XC YC ZC aC UD JC bC cC dC eC fC VD KC gC hC iC jC"},H:{"4":"WD"},I:{"2":"LC J XD YD ZD aD lC","4":"I bD cD"},J:{"2":"D A"},K:{"4":"A B C H FC kC GC"},L:{"4":"I"},M:{"4":"EC"},N:{"4":"A B"},O:{"4":"HC"},P:{"4":"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:{"4":"oD"},R:{"4":"pD"},S:{"4":"qD rD"}},B:2,C:"WAI-ARIA Accessibility features",D:true};
|
||||
@@ -0,0 +1,201 @@
|
||||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
const forEachBail = require("./forEachBail");
|
||||
|
||||
/** @typedef {import("./Resolver")} Resolver */
|
||||
/** @typedef {import("./Resolver").JsonObject} JsonObject */
|
||||
/** @typedef {import("./Resolver").JsonValue} JsonValue */
|
||||
/** @typedef {import("./Resolver").ResolveContext} ResolveContext */
|
||||
/** @typedef {import("./Resolver").ResolveRequest} ResolveRequest */
|
||||
|
||||
/**
|
||||
* @typedef {Object} DescriptionFileInfo
|
||||
* @property {JsonObject=} content
|
||||
* @property {string} path
|
||||
* @property {string} directory
|
||||
*/
|
||||
|
||||
/**
|
||||
* @callback ErrorFirstCallback
|
||||
* @param {Error|null=} error
|
||||
* @param {DescriptionFileInfo=} result
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} Result
|
||||
* @property {string} path path to description file
|
||||
* @property {string} directory directory of description file
|
||||
* @property {JsonObject} content content of description file
|
||||
*/
|
||||
|
||||
/**
|
||||
* @param {Resolver} resolver resolver
|
||||
* @param {string} directory directory
|
||||
* @param {string[]} filenames filenames
|
||||
* @param {DescriptionFileInfo|undefined} oldInfo oldInfo
|
||||
* @param {ResolveContext} resolveContext resolveContext
|
||||
* @param {ErrorFirstCallback} callback callback
|
||||
*/
|
||||
function loadDescriptionFile(
|
||||
resolver,
|
||||
directory,
|
||||
filenames,
|
||||
oldInfo,
|
||||
resolveContext,
|
||||
callback
|
||||
) {
|
||||
(function findDescriptionFile() {
|
||||
if (oldInfo && oldInfo.directory === directory) {
|
||||
// We already have info for this directory and can reuse it
|
||||
return callback(null, oldInfo);
|
||||
}
|
||||
forEachBail(
|
||||
filenames,
|
||||
/**
|
||||
* @param {string} filename filename
|
||||
* @param {(err?: null|Error, result?: null|Result) => void} callback callback
|
||||
* @returns {void}
|
||||
*/
|
||||
(filename, callback) => {
|
||||
const descriptionFilePath = resolver.join(directory, filename);
|
||||
if (resolver.fileSystem.readJson) {
|
||||
resolver.fileSystem.readJson(descriptionFilePath, (err, content) => {
|
||||
if (err) {
|
||||
if (
|
||||
typeof (/** @type {NodeJS.ErrnoException} */ (err).code) !==
|
||||
"undefined"
|
||||
) {
|
||||
if (resolveContext.missingDependencies) {
|
||||
resolveContext.missingDependencies.add(descriptionFilePath);
|
||||
}
|
||||
return callback();
|
||||
}
|
||||
if (resolveContext.fileDependencies) {
|
||||
resolveContext.fileDependencies.add(descriptionFilePath);
|
||||
}
|
||||
return onJson(err);
|
||||
}
|
||||
if (resolveContext.fileDependencies) {
|
||||
resolveContext.fileDependencies.add(descriptionFilePath);
|
||||
}
|
||||
onJson(null, content);
|
||||
});
|
||||
} else {
|
||||
resolver.fileSystem.readFile(descriptionFilePath, (err, content) => {
|
||||
if (err) {
|
||||
if (resolveContext.missingDependencies) {
|
||||
resolveContext.missingDependencies.add(descriptionFilePath);
|
||||
}
|
||||
return callback();
|
||||
}
|
||||
if (resolveContext.fileDependencies) {
|
||||
resolveContext.fileDependencies.add(descriptionFilePath);
|
||||
}
|
||||
|
||||
/** @type {JsonObject | undefined} */
|
||||
let json;
|
||||
|
||||
if (content) {
|
||||
try {
|
||||
json = JSON.parse(content.toString());
|
||||
} catch (/** @type {unknown} */ e) {
|
||||
return onJson(/** @type {Error} */ (e));
|
||||
}
|
||||
} else {
|
||||
return onJson(new Error("No content in file"));
|
||||
}
|
||||
|
||||
onJson(null, json);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {null|Error} [err] error
|
||||
* @param {JsonObject} [content] content
|
||||
* @returns {void}
|
||||
*/
|
||||
function onJson(err, content) {
|
||||
if (err) {
|
||||
if (resolveContext.log)
|
||||
resolveContext.log(
|
||||
descriptionFilePath + " (directory description file): " + err
|
||||
);
|
||||
else
|
||||
err.message =
|
||||
descriptionFilePath + " (directory description file): " + err;
|
||||
return callback(err);
|
||||
}
|
||||
callback(null, {
|
||||
content: /** @type {JsonObject} */ (content),
|
||||
directory,
|
||||
path: descriptionFilePath
|
||||
});
|
||||
}
|
||||
},
|
||||
/**
|
||||
* @param {null|Error} [err] error
|
||||
* @param {null|Result} [result] result
|
||||
* @returns {void}
|
||||
*/
|
||||
(err, result) => {
|
||||
if (err) return callback(err);
|
||||
if (result) {
|
||||
return callback(null, result);
|
||||
} else {
|
||||
const dir = cdUp(directory);
|
||||
if (!dir) {
|
||||
return callback();
|
||||
} else {
|
||||
directory = dir;
|
||||
return findDescriptionFile();
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
})();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {JsonObject} content content
|
||||
* @param {string|string[]} field field
|
||||
* @returns {JsonValue | undefined} field data
|
||||
*/
|
||||
function getField(content, field) {
|
||||
if (!content) return undefined;
|
||||
if (Array.isArray(field)) {
|
||||
/** @type {JsonValue} */
|
||||
let current = content;
|
||||
for (let j = 0; j < field.length; j++) {
|
||||
if (current === null || typeof current !== "object") {
|
||||
current = null;
|
||||
break;
|
||||
}
|
||||
current = /** @type {JsonObject} */ (current)[field[j]];
|
||||
}
|
||||
return current;
|
||||
} else {
|
||||
return content[field];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} directory directory
|
||||
* @returns {string|null} parent directory or null
|
||||
*/
|
||||
function cdUp(directory) {
|
||||
if (directory === "/") return null;
|
||||
const i = directory.lastIndexOf("/"),
|
||||
j = directory.lastIndexOf("\\");
|
||||
const p = i < 0 ? j : j < 0 ? i : i < j ? j : i;
|
||||
if (p < 0) return null;
|
||||
return directory.slice(0, p || 1);
|
||||
}
|
||||
|
||||
exports.loadDescriptionFile = loadDescriptionFile;
|
||||
exports.getField = getField;
|
||||
exports.cdUp = cdUp;
|
||||
Reference in New Issue
Block a user