update
This commit is contained in:
@@ -0,0 +1 @@
|
||||
module.exports={C:{"115":0.08543,"127":0.06383,"128":0.10704,"134":0.2563,"135":0.06383,"136":0.29951,_:"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 116 117 118 119 120 121 122 123 124 125 126 129 130 131 132 133 137 138 139 140 3.5 3.6"},D:{"44":0.0216,"109":1.21964,"120":0.0216,"121":0.04321,"123":0.08543,"132":0.08543,"133":0.36334,"134":0.89853,_:"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 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 110 111 112 113 114 115 116 117 118 119 122 124 125 126 127 128 129 130 131 135 136 137 138"},F:{"111":0.06383,"117":0.21408,_:"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 112 113 114 115 116 9.5-9.6 10.0-10.1 10.5 10.6 11.1 11.5 11.6 12.1"},B:{"127":0.0216,"131":0.04321,"132":0.0216,"133":0.44976,"134":0.89853,_:"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 128 129 130"},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 15.2-15.3 15.4 15.5 15.6 16.0 16.1 16.3 16.4 16.5 16.6 17.0 17.2 17.3 18.0 18.1","14.1":0.21408,"15.1":0.29951,"16.2":0.0216,"17.1":0.34272,"17.4":0.29951,"17.5":0.38494,"17.6":0.04321,"18.2":0.19247,"18.3":1.9257,"18.4":0.04321},G:{"8":0,"3.2":0,"4.0-4.1":0,"4.2-4.3":0.00253,"5.0-5.1":0,"6.0-6.1":0.00759,"7.0-7.1":0.00506,"8.1-8.4":0,"9.0-9.2":0.0038,"9.3":0.01771,"10.0-10.2":0.00127,"10.3":0.0291,"11.0-11.2":0.1341,"11.3-11.4":0.00886,"12.0-12.1":0.00506,"12.2-12.5":0.12524,"13.0-13.1":0.00253,"13.2":0.0038,"13.3":0.00506,"13.4-13.7":0.01771,"14.0-14.4":0.04428,"14.5-14.8":0.05313,"15.0-15.1":0.0291,"15.2-15.3":0.0291,"15.4":0.03542,"15.5":0.04048,"15.6-15.8":0.49844,"16.0":0.07084,"16.1":0.14548,"16.2":0.07591,"16.3":0.13157,"16.4":0.0291,"16.5":0.0544,"16.6-16.7":0.59079,"17.0":0.03542,"17.1":0.06325,"17.2":0.04807,"17.3":0.06705,"17.4":0.1341,"17.5":0.29856,"17.6-17.7":0.86658,"18.0":0.2429,"18.1":0.79447,"18.2":0.35549,"18.3":7.42984,"18.4":0.11006},P:{"21":0.02254,"26":0.04509,"27":0.02254,_:"4 20 22 23 24 25 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":0.01803},Q:{_:"14.9"},O:{_:"0"},H:{"0":0},L:{"0":77.77429}};
|
||||
@@ -0,0 +1,8 @@
|
||||
declare module '@tanstack/history' {
|
||||
interface HistoryState {
|
||||
__tempLocation?: HistoryLocation;
|
||||
__tempKey?: string;
|
||||
__hashScrollIntoViewOptions?: boolean | ScrollIntoViewOptions;
|
||||
}
|
||||
}
|
||||
export {};
|
||||
@@ -0,0 +1,157 @@
|
||||
/**
|
||||
* @fileoverview Rule to disallow `parseInt()` in favor of binary, octal, and hexadecimal literals
|
||||
* @author Annie Zhang, Henry Zhu
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Requirements
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
const astUtils = require("./utils/ast-utils");
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Helpers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
const radixMap = new Map([
|
||||
[2, { system: "binary", literalPrefix: "0b" }],
|
||||
[8, { system: "octal", literalPrefix: "0o" }],
|
||||
[16, { system: "hexadecimal", literalPrefix: "0x" }],
|
||||
]);
|
||||
|
||||
/**
|
||||
* Checks to see if a CallExpression's callee node is `parseInt` or
|
||||
* `Number.parseInt`.
|
||||
* @param {ASTNode} calleeNode The callee node to evaluate.
|
||||
* @returns {boolean} True if the callee is `parseInt` or `Number.parseInt`,
|
||||
* false otherwise.
|
||||
*/
|
||||
function isParseInt(calleeNode) {
|
||||
return (
|
||||
astUtils.isSpecificId(calleeNode, "parseInt") ||
|
||||
astUtils.isSpecificMemberAccess(calleeNode, "Number", "parseInt")
|
||||
);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Rule Definition
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/** @type {import('../shared/types').Rule} */
|
||||
module.exports = {
|
||||
meta: {
|
||||
type: "suggestion",
|
||||
|
||||
docs: {
|
||||
description:
|
||||
"Disallow `parseInt()` and `Number.parseInt()` in favor of binary, octal, and hexadecimal literals",
|
||||
recommended: false,
|
||||
frozen: true,
|
||||
url: "https://eslint.org/docs/latest/rules/prefer-numeric-literals",
|
||||
},
|
||||
|
||||
schema: [],
|
||||
|
||||
messages: {
|
||||
useLiteral:
|
||||
"Use {{system}} literals instead of {{functionName}}().",
|
||||
},
|
||||
|
||||
fixable: "code",
|
||||
},
|
||||
|
||||
create(context) {
|
||||
const sourceCode = context.sourceCode;
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Public
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
return {
|
||||
"CallExpression[arguments.length=2]"(node) {
|
||||
const [strNode, radixNode] = node.arguments,
|
||||
str = astUtils.getStaticStringValue(strNode),
|
||||
radix = radixNode.value;
|
||||
|
||||
if (
|
||||
str !== null &&
|
||||
astUtils.isStringLiteral(strNode) &&
|
||||
radixNode.type === "Literal" &&
|
||||
typeof radix === "number" &&
|
||||
radixMap.has(radix) &&
|
||||
isParseInt(node.callee)
|
||||
) {
|
||||
const { system, literalPrefix } = radixMap.get(radix);
|
||||
|
||||
context.report({
|
||||
node,
|
||||
messageId: "useLiteral",
|
||||
data: {
|
||||
system,
|
||||
functionName: sourceCode.getText(node.callee),
|
||||
},
|
||||
fix(fixer) {
|
||||
if (sourceCode.getCommentsInside(node).length) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const replacement = `${literalPrefix}${str}`;
|
||||
|
||||
if (+replacement !== parseInt(str, radix)) {
|
||||
/*
|
||||
* If the newly-produced literal would be invalid, (e.g. 0b1234),
|
||||
* or it would yield an incorrect parseInt result for some other reason, don't make a fix.
|
||||
*
|
||||
* If `str` had numeric separators, `+replacement` will evaluate to `NaN` because unary `+`
|
||||
* per the specification doesn't support numeric separators. Thus, the above condition will be `true`
|
||||
* (`NaN !== anything` is always `true`) regardless of the `parseInt(str, radix)` value.
|
||||
* Consequently, no autofixes will be made. This is correct behavior because `parseInt` also
|
||||
* doesn't support numeric separators, but it does parse part of the string before the first `_`,
|
||||
* so the autofix would be invalid:
|
||||
*
|
||||
* parseInt("1_1", 2) // === 1
|
||||
* 0b1_1 // === 3
|
||||
*/
|
||||
return null;
|
||||
}
|
||||
|
||||
const tokenBefore = sourceCode.getTokenBefore(node),
|
||||
tokenAfter = sourceCode.getTokenAfter(node);
|
||||
let prefix = "",
|
||||
suffix = "";
|
||||
|
||||
if (
|
||||
tokenBefore &&
|
||||
tokenBefore.range[1] === node.range[0] &&
|
||||
!astUtils.canTokensBeAdjacent(
|
||||
tokenBefore,
|
||||
replacement,
|
||||
)
|
||||
) {
|
||||
prefix = " ";
|
||||
}
|
||||
|
||||
if (
|
||||
tokenAfter &&
|
||||
node.range[1] === tokenAfter.range[0] &&
|
||||
!astUtils.canTokensBeAdjacent(
|
||||
replacement,
|
||||
tokenAfter,
|
||||
)
|
||||
) {
|
||||
suffix = " ";
|
||||
}
|
||||
|
||||
return fixer.replaceText(
|
||||
node,
|
||||
`${prefix}${replacement}${suffix}`,
|
||||
);
|
||||
},
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,28 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.unreleasedLabels = exports.browserNameMap = void 0;
|
||||
const unreleasedLabels = exports.unreleasedLabels = {
|
||||
safari: "tp"
|
||||
};
|
||||
const browserNameMap = exports.browserNameMap = {
|
||||
and_chr: "chrome",
|
||||
and_ff: "firefox",
|
||||
android: "android",
|
||||
chrome: "chrome",
|
||||
edge: "edge",
|
||||
firefox: "firefox",
|
||||
ie: "ie",
|
||||
ie_mob: "ie",
|
||||
ios_saf: "ios",
|
||||
node: "node",
|
||||
deno: "deno",
|
||||
op_mob: "opera_mobile",
|
||||
opera: "opera",
|
||||
safari: "safari",
|
||||
samsung: "samsung"
|
||||
};
|
||||
|
||||
//# sourceMappingURL=targets.js.map
|
||||
@@ -0,0 +1,69 @@
|
||||
import Container, { ContainerProps } from './container.js'
|
||||
import { ProcessOptions } from './postcss.js'
|
||||
import Result from './result.js'
|
||||
import Root from './root.js'
|
||||
|
||||
declare namespace Document {
|
||||
export interface DocumentProps extends ContainerProps {
|
||||
nodes?: readonly Root[]
|
||||
|
||||
/**
|
||||
* Information to generate byte-to-byte equal node string as it was
|
||||
* in the origin input.
|
||||
*
|
||||
* Every parser saves its own properties.
|
||||
*/
|
||||
raws?: Record<string, any>
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
||||
export { Document_ as default }
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a file and contains all its parsed nodes.
|
||||
*
|
||||
* **Experimental:** some aspects of this node could change within minor
|
||||
* or patch version releases.
|
||||
*
|
||||
* ```js
|
||||
* const document = htmlParser(
|
||||
* '<html><style>a{color:black}</style><style>b{z-index:2}</style>'
|
||||
* )
|
||||
* document.type //=> 'document'
|
||||
* document.nodes.length //=> 2
|
||||
* ```
|
||||
*/
|
||||
declare class Document_ extends Container<Root> {
|
||||
nodes: Root[]
|
||||
parent: undefined
|
||||
type: 'document'
|
||||
|
||||
constructor(defaults?: Document.DocumentProps)
|
||||
|
||||
assign(overrides: Document.DocumentProps | object): this
|
||||
clone(overrides?: Partial<Document.DocumentProps>): this
|
||||
cloneAfter(overrides?: Partial<Document.DocumentProps>): this
|
||||
cloneBefore(overrides?: Partial<Document.DocumentProps>): this
|
||||
|
||||
/**
|
||||
* Returns a `Result` instance representing the document’s CSS roots.
|
||||
*
|
||||
* ```js
|
||||
* const root1 = postcss.parse(css1, { from: 'a.css' })
|
||||
* const root2 = postcss.parse(css2, { from: 'b.css' })
|
||||
* const document = postcss.document()
|
||||
* document.append(root1)
|
||||
* document.append(root2)
|
||||
* const result = document.toResult({ to: 'all.css', map: true })
|
||||
* ```
|
||||
*
|
||||
* @param opts Options.
|
||||
* @return Result with current document’s CSS.
|
||||
*/
|
||||
toResult(options?: ProcessOptions): Result
|
||||
}
|
||||
|
||||
declare class Document extends Document_ {}
|
||||
|
||||
export = Document
|
||||
@@ -0,0 +1,195 @@
|
||||
import { HistoryState, ParsedHistoryState } from '@tanstack/history';
|
||||
import { AllParams, CatchAllPaths, CurrentPath, FullSearchSchema, FullSearchSchemaInput, ParentPath, RouteByPath, RouteByToPath, RoutePaths, RouteToPath, ToPath } from './routeInfo.js';
|
||||
import { AnyRouter, RegisteredRouter, ViewTransitionOptions } from './router.js';
|
||||
import { ConstrainLiteral, Expand, MakeDifferenceOptional, NoInfer, NonNullableUpdater, PickRequired, Updater, WithoutEmpty } from './utils.js';
|
||||
import { ParsedLocation } from './location.js';
|
||||
export type IsRequiredParams<TParams> = Record<never, never> extends TParams ? never : true;
|
||||
export type ParsePathParams<T extends string, TAcc = never> = T & `${string}$${string}` extends never ? TAcc : T extends `${string}$${infer TPossiblyParam}` ? TPossiblyParam extends '' ? TAcc : TPossiblyParam & `${string}/${string}` extends never ? TPossiblyParam | TAcc : TPossiblyParam extends `${infer TParam}/${infer TRest}` ? ParsePathParams<TRest, TParam extends '' ? TAcc : TParam | TAcc> : never : TAcc;
|
||||
export type AddTrailingSlash<T> = T extends `${string}/` ? T : `${T & string}/`;
|
||||
export type RemoveTrailingSlashes<T> = T & `${string}/` extends never ? T : T extends `${infer R}/` ? R : T;
|
||||
export type AddLeadingSlash<T> = T & `/${string}` extends never ? `/${T & string}` : T;
|
||||
export type RemoveLeadingSlashes<T> = T & `/${string}` extends never ? T : T extends `/${infer R}` ? R : T;
|
||||
type JoinPath<TLeft extends string, TRight extends string> = TRight extends '' ? TLeft : TLeft extends '' ? TRight : `${RemoveTrailingSlashes<TLeft>}/${RemoveLeadingSlashes<TRight>}`;
|
||||
type RemoveLastSegment<T extends string, TAcc extends string = ''> = T extends `${infer TSegment}/${infer TRest}` ? TRest & `${string}/${string}` extends never ? TRest extends '' ? TAcc : `${TAcc}${TSegment}` : RemoveLastSegment<TRest, `${TAcc}${TSegment}/`> : TAcc;
|
||||
export type ResolveCurrentPath<TFrom extends string, TTo extends string> = TTo extends '.' ? TFrom : TTo extends './' ? AddTrailingSlash<TFrom> : TTo & `./${string}` extends never ? never : TTo extends `./${infer TRest}` ? AddLeadingSlash<JoinPath<TFrom, TRest>> : never;
|
||||
export type ResolveParentPath<TFrom extends string, TTo extends string> = TTo extends '../' | '..' ? TFrom extends '' | '/' ? never : AddLeadingSlash<RemoveLastSegment<TFrom>> : TTo & `../${string}` extends never ? AddLeadingSlash<JoinPath<TFrom, TTo>> : TFrom extends '' | '/' ? never : TTo extends `../${infer ToRest}` ? ResolveParentPath<RemoveLastSegment<TFrom>, ToRest> : AddLeadingSlash<JoinPath<TFrom, TTo>>;
|
||||
export type ResolveRelativePath<TFrom, TTo = '.'> = string extends TFrom ? TTo : string extends TTo ? TFrom : undefined extends TTo ? TFrom : TTo extends string ? TFrom extends string ? TTo extends `/${string}` ? TTo : TTo extends `..${string}` ? ResolveParentPath<TFrom, TTo> : TTo extends `.${string}` ? ResolveCurrentPath<TFrom, TTo> : AddLeadingSlash<JoinPath<TFrom, TTo>> : never : never;
|
||||
export type FindDescendantToPaths<TRouter extends AnyRouter, TPrefix extends string> = `${TPrefix}/${string}` & RouteToPath<TRouter>;
|
||||
export type InferDescendantToPaths<TRouter extends AnyRouter, TPrefix extends string, TPaths = FindDescendantToPaths<TRouter, TPrefix>> = TPaths extends `${TPrefix}/` ? never : TPaths extends `${TPrefix}/${infer TRest}` ? TRest : never;
|
||||
export type RelativeToPath<TRouter extends AnyRouter, TTo extends string, TResolvedPath extends string> = (TResolvedPath & RouteToPath<TRouter> extends never ? never : ToPath<TRouter, TTo>) | `${RemoveTrailingSlashes<TTo>}/${InferDescendantToPaths<TRouter, RemoveTrailingSlashes<TResolvedPath>>}`;
|
||||
export type RelativeToParentPath<TRouter extends AnyRouter, TFrom extends string, TTo extends string, TResolvedPath extends string = ResolveRelativePath<TFrom, TTo>> = RelativeToPath<TRouter, TTo, TResolvedPath> | (TTo extends `${string}..` | `${string}../` ? TResolvedPath extends '/' | '' ? never : FindDescendantToPaths<TRouter, RemoveTrailingSlashes<TResolvedPath>> extends never ? never : `${RemoveTrailingSlashes<TTo>}/${ParentPath<TRouter>}` : never);
|
||||
export type RelativeToCurrentPath<TRouter extends AnyRouter, TFrom extends string, TTo extends string, TResolvedPath extends string = ResolveRelativePath<TFrom, TTo>> = RelativeToPath<TRouter, TTo, TResolvedPath> | CurrentPath<TRouter>;
|
||||
export type AbsoluteToPath<TRouter extends AnyRouter, TFrom extends string> = (string extends TFrom ? CurrentPath<TRouter> : TFrom extends `/` ? never : CurrentPath<TRouter>) | (string extends TFrom ? ParentPath<TRouter> : TFrom extends `/` ? never : ParentPath<TRouter>) | RouteToPath<TRouter> | (TFrom extends '/' ? never : string extends TFrom ? never : InferDescendantToPaths<TRouter, RemoveTrailingSlashes<TFrom>>);
|
||||
export type RelativeToPathAutoComplete<TRouter extends AnyRouter, TFrom extends string, TTo extends string> = string extends TTo ? string : string extends TFrom ? AbsoluteToPath<TRouter, TFrom> : TTo & `..${string}` extends never ? TTo & `.${string}` extends never ? AbsoluteToPath<TRouter, TFrom> : RelativeToCurrentPath<TRouter, TFrom, TTo> : RelativeToParentPath<TRouter, TFrom, TTo>;
|
||||
export type NavigateOptions<TRouter extends AnyRouter = RegisteredRouter, TFrom extends string = string, TTo extends string | undefined = '.', TMaskFrom extends string = TFrom, TMaskTo extends string = '.'> = ToOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo> & NavigateOptionProps;
|
||||
/**
|
||||
* The NavigateOptions type is used to describe the options that can be used when describing a navigation action in TanStack Router.
|
||||
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/NavigateOptionsType)
|
||||
*/
|
||||
export interface NavigateOptionProps {
|
||||
/**
|
||||
* If set to `true`, the router will scroll the element with an id matching the hash into view with default `ScrollIntoViewOptions`.
|
||||
* If set to `false`, the router will not scroll the element with an id matching the hash into view.
|
||||
* If set to `ScrollIntoViewOptions`, the router will scroll the element with an id matching the hash into view with the provided options.
|
||||
* @default true
|
||||
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/NavigateOptionsType#hashscrollintoview)
|
||||
* @see [MDN](https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView)
|
||||
*/
|
||||
hashScrollIntoView?: boolean | ScrollIntoViewOptions;
|
||||
/**
|
||||
* `replace` is a boolean that determines whether the navigation should replace the current history entry or push a new one.
|
||||
* @default false
|
||||
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/NavigateOptionsType#replace)
|
||||
*/
|
||||
replace?: boolean;
|
||||
/**
|
||||
* Defaults to `true` so that the scroll position will be reset to 0,0 after the location is committed to the browser history.
|
||||
* If `false`, the scroll position will not be reset to 0,0 after the location is committed to history.
|
||||
* @default true
|
||||
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/NavigateOptionsType#resetscroll)
|
||||
*/
|
||||
resetScroll?: boolean;
|
||||
/** @deprecated All navigations now use startTransition under the hood */
|
||||
startTransition?: boolean;
|
||||
/**
|
||||
* If set to `true`, the router will wrap the resulting navigation in a `document.startViewTransition()` call.
|
||||
* If `ViewTransitionOptions`, route navigations will be called using `document.startViewTransition({update, types})`
|
||||
* where `types` will be the strings array passed with `ViewTransitionOptions["types"]`.
|
||||
* If the browser does not support viewTransition types, the navigation will fall back to normal `document.startTransition()`, same as if `true` was passed.
|
||||
*
|
||||
* If the browser does not support this api, this option will be ignored.
|
||||
* @default false
|
||||
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/NavigateOptionsType#viewtransition)
|
||||
* @see [MDN](https://developer.mozilla.org/en-US/docs/Web/API/Document/startViewTransition)
|
||||
* @see [Google](https://developer.chrome.com/docs/web-platform/view-transitions/same-document#view-transition-types)
|
||||
*/
|
||||
viewTransition?: boolean | ViewTransitionOptions;
|
||||
/**
|
||||
* If `true`, navigation will ignore any blockers that might prevent it.
|
||||
* @default false
|
||||
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/NavigateOptionsType#ignoreblocker)
|
||||
*/
|
||||
ignoreBlocker?: boolean;
|
||||
/**
|
||||
* If `true`, navigation to a route inside of router will trigger a full page load instead of the traditional SPA navigation.
|
||||
* @default false
|
||||
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/NavigateOptionsType#reloaddocument)
|
||||
*/
|
||||
reloadDocument?: boolean;
|
||||
/**
|
||||
* This can be used instead of `to` to navigate to a fully built href, e.g. pointing to an external target.
|
||||
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/NavigateOptionsType#href)
|
||||
*/
|
||||
href?: string;
|
||||
}
|
||||
export type ToOptions<TRouter extends AnyRouter = RegisteredRouter, TFrom extends string = string, TTo extends string | undefined = '.', TMaskFrom extends string = TFrom, TMaskTo extends string = '.'> = ToSubOptions<TRouter, TFrom, TTo> & MaskOptions<TRouter, TMaskFrom, TMaskTo>;
|
||||
export interface MaskOptions<in out TRouter extends AnyRouter, in out TMaskFrom extends string, in out TMaskTo extends string> {
|
||||
_fromLocation?: ParsedLocation;
|
||||
mask?: ToMaskOptions<TRouter, TMaskFrom, TMaskTo>;
|
||||
}
|
||||
export type ToMaskOptions<TRouter extends AnyRouter = RegisteredRouter, TMaskFrom extends string = string, TMaskTo extends string = '.'> = ToSubOptions<TRouter, TMaskFrom, TMaskTo> & {
|
||||
unmaskOnReload?: boolean;
|
||||
};
|
||||
export type ToSubOptions<TRouter extends AnyRouter = RegisteredRouter, TFrom extends string = string, TTo extends string | undefined = '.'> = ToSubOptionsProps<TRouter, TFrom, TTo> & SearchParamOptions<TRouter, TFrom, TTo> & PathParamOptions<TRouter, TFrom, TTo>;
|
||||
export interface RequiredToOptions<in out TRouter extends AnyRouter, in out TFrom extends string, in out TTo extends string | undefined> {
|
||||
to: ToPathOption<TRouter, TFrom, TTo> & {};
|
||||
}
|
||||
export interface OptionalToOptions<in out TRouter extends AnyRouter, in out TFrom extends string, in out TTo extends string | undefined> {
|
||||
to?: ToPathOption<TRouter, TFrom, TTo> & {};
|
||||
}
|
||||
export type MakeToRequired<TRouter extends AnyRouter, TFrom extends string, TTo extends string | undefined> = string extends TFrom ? string extends TTo ? OptionalToOptions<TRouter, TFrom, TTo> : TTo & CatchAllPaths<TRouter> extends never ? RequiredToOptions<TRouter, TFrom, TTo> : OptionalToOptions<TRouter, TFrom, TTo> : OptionalToOptions<TRouter, TFrom, TTo>;
|
||||
export type ToSubOptionsProps<TRouter extends AnyRouter = RegisteredRouter, TFrom extends RoutePaths<TRouter['routeTree']> | string = string, TTo extends string | undefined = '.'> = MakeToRequired<TRouter, TFrom, TTo> & {
|
||||
hash?: true | Updater<string>;
|
||||
state?: true | NonNullableUpdater<ParsedHistoryState, HistoryState>;
|
||||
from?: FromPathOption<TRouter, TFrom> & {};
|
||||
};
|
||||
export type ParamsReducerFn<in out TRouter extends AnyRouter, in out TParamVariant extends ParamVariant, in out TFrom, in out TTo> = (current: Expand<ResolveFromParams<TRouter, TParamVariant, TFrom>>) => Expand<ResolveRelativeToParams<TRouter, TParamVariant, TFrom, TTo>>;
|
||||
type ParamsReducer<TRouter extends AnyRouter, TParamVariant extends ParamVariant, TFrom, TTo> = Expand<ResolveRelativeToParams<TRouter, TParamVariant, TFrom, TTo>> | (ParamsReducerFn<TRouter, TParamVariant, TFrom, TTo> & {});
|
||||
type ParamVariant = 'PATH' | 'SEARCH';
|
||||
export type ResolveRoute<TRouter extends AnyRouter, TFrom, TTo, TPath = ResolveRelativePath<TFrom, TTo>> = TPath extends string ? TFrom extends TPath ? RouteByPath<TRouter['routeTree'], TPath> : RouteByToPath<TRouter, TPath> : never;
|
||||
type ResolveFromParamType<TParamVariant extends ParamVariant> = TParamVariant extends 'PATH' ? 'allParams' : 'fullSearchSchema';
|
||||
type ResolveFromAllParams<TRouter extends AnyRouter, TParamVariant extends ParamVariant> = TParamVariant extends 'PATH' ? AllParams<TRouter['routeTree']> : FullSearchSchema<TRouter['routeTree']>;
|
||||
type ResolveFromParams<TRouter extends AnyRouter, TParamVariant extends ParamVariant, TFrom> = string extends TFrom ? ResolveFromAllParams<TRouter, TParamVariant> : RouteByPath<TRouter['routeTree'], TFrom>['types'][ResolveFromParamType<TParamVariant>];
|
||||
type ResolveToParamType<TParamVariant extends ParamVariant> = TParamVariant extends 'PATH' ? 'allParams' : 'fullSearchSchemaInput';
|
||||
type ResolveAllToParams<TRouter extends AnyRouter, TParamVariant extends ParamVariant> = TParamVariant extends 'PATH' ? AllParams<TRouter['routeTree']> : FullSearchSchemaInput<TRouter['routeTree']>;
|
||||
export type ResolveToParams<TRouter extends AnyRouter, TParamVariant extends ParamVariant, TFrom, TTo> = ResolveRelativePath<TFrom, TTo> extends infer TPath ? undefined extends TPath ? never : string extends TPath ? ResolveAllToParams<TRouter, TParamVariant> : TPath extends CatchAllPaths<TRouter> ? ResolveAllToParams<TRouter, TParamVariant> : ResolveRoute<TRouter, TFrom, TTo>['types'][ResolveToParamType<TParamVariant>] : never;
|
||||
type ResolveRelativeToParams<TRouter extends AnyRouter, TParamVariant extends ParamVariant, TFrom, TTo, TToParams = ResolveToParams<TRouter, TParamVariant, TFrom, TTo>> = TParamVariant extends 'SEARCH' ? TToParams : string extends TFrom ? TToParams : MakeDifferenceOptional<ResolveFromParams<TRouter, TParamVariant, TFrom>, TToParams>;
|
||||
export interface MakeOptionalSearchParams<in out TRouter extends AnyRouter, in out TFrom, in out TTo> {
|
||||
search?: true | (ParamsReducer<TRouter, 'SEARCH', TFrom, TTo> & {});
|
||||
}
|
||||
export interface MakeOptionalPathParams<in out TRouter extends AnyRouter, in out TFrom, in out TTo> {
|
||||
params?: true | (ParamsReducer<TRouter, 'PATH', TFrom, TTo> & {});
|
||||
}
|
||||
type MakeRequiredParamsReducer<TRouter extends AnyRouter, TParamVariant extends ParamVariant, TFrom, TTo> = (string extends TFrom ? never : ResolveFromParams<TRouter, TParamVariant, TFrom> extends WithoutEmpty<PickRequired<ResolveRelativeToParams<TRouter, TParamVariant, TFrom, TTo>>> ? true : never) | (ParamsReducer<TRouter, TParamVariant, TFrom, TTo> & {});
|
||||
export interface MakeRequiredPathParams<in out TRouter extends AnyRouter, in out TFrom, in out TTo> {
|
||||
params: MakeRequiredParamsReducer<TRouter, 'PATH', TFrom, TTo> & {};
|
||||
}
|
||||
export interface MakeRequiredSearchParams<in out TRouter extends AnyRouter, in out TFrom, in out TTo> {
|
||||
search: MakeRequiredParamsReducer<TRouter, 'SEARCH', TFrom, TTo> & {};
|
||||
}
|
||||
export type IsRequired<TRouter extends AnyRouter, TParamVariant extends ParamVariant, TFrom, TTo> = ResolveRelativePath<TFrom, TTo> extends infer TPath ? undefined extends TPath ? never : TPath extends CatchAllPaths<TRouter> ? never : IsRequiredParams<ResolveRelativeToParams<TRouter, TParamVariant, TFrom, TTo>> : never;
|
||||
export type SearchParamOptions<TRouter extends AnyRouter, TFrom, TTo> = IsRequired<TRouter, 'SEARCH', TFrom, TTo> extends never ? MakeOptionalSearchParams<TRouter, TFrom, TTo> : MakeRequiredSearchParams<TRouter, TFrom, TTo>;
|
||||
export type PathParamOptions<TRouter extends AnyRouter, TFrom, TTo> = IsRequired<TRouter, 'PATH', TFrom, TTo> extends never ? MakeOptionalPathParams<TRouter, TFrom, TTo> : MakeRequiredPathParams<TRouter, TFrom, TTo>;
|
||||
export type ToPathOption<TRouter extends AnyRouter = AnyRouter, TFrom extends string = string, TTo extends string | undefined = string> = ConstrainLiteral<TTo, RelativeToPathAutoComplete<TRouter, NoInfer<TFrom> extends string ? NoInfer<TFrom> : '', NoInfer<TTo> & string>>;
|
||||
export type FromPathOption<TRouter extends AnyRouter, TFrom> = ConstrainLiteral<TFrom, RoutePaths<TRouter['routeTree']>>;
|
||||
/**
|
||||
* @link [Guide](https://tanstack.com/router/latest/docs/framework/react/guide/navigation#active-options)
|
||||
*/
|
||||
export interface ActiveOptions {
|
||||
/**
|
||||
* If true, the link will be active if the current route matches the `to` route path exactly (no children routes)
|
||||
* @default false
|
||||
*/
|
||||
exact?: boolean;
|
||||
/**
|
||||
* If true, the link will only be active if the current URL hash matches the `hash` prop
|
||||
* @default false
|
||||
*/
|
||||
includeHash?: boolean;
|
||||
/**
|
||||
* If true, the link will only be active if the current URL search params inclusively match the `search` prop
|
||||
* @default true
|
||||
*/
|
||||
includeSearch?: boolean;
|
||||
/**
|
||||
* This modifies the `includeSearch` behavior.
|
||||
* If true, properties in `search` that are explicitly `undefined` must NOT be present in the current URL search params for the link to be active.
|
||||
* @default false
|
||||
*/
|
||||
explicitUndefined?: boolean;
|
||||
}
|
||||
export interface LinkOptionsProps {
|
||||
/**
|
||||
* The standard anchor tag target attribute
|
||||
*/
|
||||
target?: HTMLAnchorElement['target'];
|
||||
/**
|
||||
* Configurable options to determine if the link should be considered active or not
|
||||
* @default {exact:true,includeHash:true}
|
||||
*/
|
||||
activeOptions?: ActiveOptions;
|
||||
/**
|
||||
* The preloading strategy for this link
|
||||
* - `false` - No preloading
|
||||
* - `'intent'` - Preload the linked route on hover and cache it for this many milliseconds in hopes that the user will eventually navigate there.
|
||||
* - `'viewport'` - Preload the linked route when it enters the viewport
|
||||
*/
|
||||
preload?: false | 'intent' | 'viewport' | 'render';
|
||||
/**
|
||||
* When a preload strategy is set, this delays the preload by this many milliseconds.
|
||||
* If the user exits the link before this delay, the preload will be cancelled.
|
||||
*/
|
||||
preloadDelay?: number;
|
||||
/**
|
||||
* Control whether the link should be disabled or not
|
||||
* If set to `true`, the link will be rendered without an `href` attribute
|
||||
* @default false
|
||||
*/
|
||||
disabled?: boolean;
|
||||
}
|
||||
export type LinkOptions<TRouter extends AnyRouter = RegisteredRouter, TFrom extends string = string, TTo extends string | undefined = '.', TMaskFrom extends string = TFrom, TMaskTo extends string = '.'> = NavigateOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo> & LinkOptionsProps;
|
||||
export type LinkCurrentTargetElement = {
|
||||
preloadTimeout?: null | ReturnType<typeof setTimeout>;
|
||||
};
|
||||
export declare const preloadWarning = "Error preloading route! \u261D\uFE0F";
|
||||
export {};
|
||||
@@ -0,0 +1,83 @@
|
||||
(function (global, factory) {
|
||||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
||||
typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
||||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.setArray = {}));
|
||||
})(this, (function (exports) { 'use strict';
|
||||
|
||||
/**
|
||||
* SetArray acts like a `Set` (allowing only one occurrence of a string `key`), but provides the
|
||||
* index of the `key` in the backing array.
|
||||
*
|
||||
* This is designed to allow synchronizing a second array with the contents of the backing array,
|
||||
* like how in a sourcemap `sourcesContent[i]` is the source content associated with `source[i]`,
|
||||
* and there are never duplicates.
|
||||
*/
|
||||
class SetArray {
|
||||
constructor() {
|
||||
this._indexes = { __proto__: null };
|
||||
this.array = [];
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Typescript doesn't allow friend access to private fields, so this just casts the set into a type
|
||||
* with public access modifiers.
|
||||
*/
|
||||
function cast(set) {
|
||||
return set;
|
||||
}
|
||||
/**
|
||||
* Gets the index associated with `key` in the backing array, if it is already present.
|
||||
*/
|
||||
function get(setarr, key) {
|
||||
return cast(setarr)._indexes[key];
|
||||
}
|
||||
/**
|
||||
* Puts `key` into the backing array, if it is not already present. Returns
|
||||
* the index of the `key` in the backing array.
|
||||
*/
|
||||
function put(setarr, key) {
|
||||
// The key may or may not be present. If it is present, it's a number.
|
||||
const index = get(setarr, key);
|
||||
if (index !== undefined)
|
||||
return index;
|
||||
const { array, _indexes: indexes } = cast(setarr);
|
||||
const length = array.push(key);
|
||||
return (indexes[key] = length - 1);
|
||||
}
|
||||
/**
|
||||
* Pops the last added item out of the SetArray.
|
||||
*/
|
||||
function pop(setarr) {
|
||||
const { array, _indexes: indexes } = cast(setarr);
|
||||
if (array.length === 0)
|
||||
return;
|
||||
const last = array.pop();
|
||||
indexes[last] = undefined;
|
||||
}
|
||||
/**
|
||||
* Removes the key, if it exists in the set.
|
||||
*/
|
||||
function remove(setarr, key) {
|
||||
const index = get(setarr, key);
|
||||
if (index === undefined)
|
||||
return;
|
||||
const { array, _indexes: indexes } = cast(setarr);
|
||||
for (let i = index + 1; i < array.length; i++) {
|
||||
const k = array[i];
|
||||
array[i - 1] = k;
|
||||
indexes[k]--;
|
||||
}
|
||||
indexes[key] = undefined;
|
||||
array.pop();
|
||||
}
|
||||
|
||||
exports.SetArray = SetArray;
|
||||
exports.get = get;
|
||||
exports.pop = pop;
|
||||
exports.put = put;
|
||||
exports.remove = remove;
|
||||
|
||||
Object.defineProperty(exports, '__esModule', { value: true });
|
||||
|
||||
}));
|
||||
//# sourceMappingURL=set-array.umd.js.map
|
||||
@@ -0,0 +1,22 @@
|
||||
'use strict';
|
||||
|
||||
var test = require('tape');
|
||||
var stringify = require('../');
|
||||
|
||||
test('toJSON function', function (t) {
|
||||
t.plan(1);
|
||||
var obj = { one: 1, two: 2, toJSON: function() { return { one: 1 }; } };
|
||||
t.equal(stringify(obj), '{"one":1}' );
|
||||
});
|
||||
|
||||
test('toJSON returns string', function (t) {
|
||||
t.plan(1);
|
||||
var obj = { one: 1, two: 2, toJSON: function() { return 'one'; } };
|
||||
t.equal(stringify(obj), '"one"');
|
||||
});
|
||||
|
||||
test('toJSON returns array', function (t) {
|
||||
t.plan(1);
|
||||
var obj = { one: 1, two: 2, toJSON: function() { return ['one']; } };
|
||||
t.equal(stringify(obj), '["one"]');
|
||||
});
|
||||
@@ -0,0 +1,654 @@
|
||||
/**
|
||||
* @fileoverview A rule to disallow unnecessary assignments`.
|
||||
* @author Yosuke Ota
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
const { findVariable } = require("@eslint-community/eslint-utils");
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Types
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/** @typedef {import("estree").Node} ASTNode */
|
||||
/** @typedef {import("estree").Pattern} Pattern */
|
||||
/** @typedef {import("estree").Identifier} Identifier */
|
||||
/** @typedef {import("estree").VariableDeclarator} VariableDeclarator */
|
||||
/** @typedef {import("estree").AssignmentExpression} AssignmentExpression */
|
||||
/** @typedef {import("estree").UpdateExpression} UpdateExpression */
|
||||
/** @typedef {import("estree").Expression} Expression */
|
||||
/** @typedef {import("eslint-scope").Scope} Scope */
|
||||
/** @typedef {import("eslint-scope").Variable} Variable */
|
||||
/** @typedef {import("../linter/code-path-analysis/code-path")} CodePath */
|
||||
/** @typedef {import("../linter/code-path-analysis/code-path-segment")} CodePathSegment */
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Helpers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Extract identifier from the given pattern node used on the left-hand side of the assignment.
|
||||
* @param {Pattern} pattern The pattern node to extract identifier
|
||||
* @returns {Iterable<Identifier>} The extracted identifier
|
||||
*/
|
||||
function* extractIdentifiersFromPattern(pattern) {
|
||||
switch (pattern.type) {
|
||||
case "Identifier":
|
||||
yield pattern;
|
||||
return;
|
||||
case "ObjectPattern":
|
||||
for (const property of pattern.properties) {
|
||||
yield* extractIdentifiersFromPattern(
|
||||
property.type === "Property" ? property.value : property,
|
||||
);
|
||||
}
|
||||
return;
|
||||
case "ArrayPattern":
|
||||
for (const element of pattern.elements) {
|
||||
if (!element) {
|
||||
continue;
|
||||
}
|
||||
yield* extractIdentifiersFromPattern(element);
|
||||
}
|
||||
return;
|
||||
case "RestElement":
|
||||
yield* extractIdentifiersFromPattern(pattern.argument);
|
||||
return;
|
||||
case "AssignmentPattern":
|
||||
yield* extractIdentifiersFromPattern(pattern.left);
|
||||
|
||||
// no default
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the given identifier node is evaluated after the assignment identifier.
|
||||
* @param {AssignmentInfo} assignment The assignment info.
|
||||
* @param {Identifier} identifier The identifier to check.
|
||||
* @returns {boolean} `true` if the given identifier node is evaluated after the assignment identifier.
|
||||
*/
|
||||
function isIdentifierEvaluatedAfterAssignment(assignment, identifier) {
|
||||
if (identifier.range[0] < assignment.identifier.range[1]) {
|
||||
return false;
|
||||
}
|
||||
if (
|
||||
assignment.expression &&
|
||||
assignment.expression.range[0] <= identifier.range[0] &&
|
||||
identifier.range[1] <= assignment.expression.range[1]
|
||||
) {
|
||||
/*
|
||||
* The identifier node is in an expression that is evaluated before the assignment.
|
||||
* e.g. x = id;
|
||||
* ^^ identifier to check
|
||||
* ^ assignment identifier
|
||||
*/
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* e.g.
|
||||
* x = 42; id;
|
||||
* ^^ identifier to check
|
||||
* ^ assignment identifier
|
||||
* let { x, y = id } = obj;
|
||||
* ^^ identifier to check
|
||||
* ^ assignment identifier
|
||||
*/
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the given identifier node is used between the assigned identifier and the equal sign.
|
||||
*
|
||||
* e.g. let { x, y = x } = obj;
|
||||
* ^ identifier to check
|
||||
* ^ assigned identifier
|
||||
* @param {AssignmentInfo} assignment The assignment info.
|
||||
* @param {Identifier} identifier The identifier to check.
|
||||
* @returns {boolean} `true` if the given identifier node is used between the assigned identifier and the equal sign.
|
||||
*/
|
||||
function isIdentifierUsedBetweenAssignedAndEqualSign(assignment, identifier) {
|
||||
if (!assignment.expression) {
|
||||
return false;
|
||||
}
|
||||
return (
|
||||
assignment.identifier.range[1] <= identifier.range[0] &&
|
||||
identifier.range[1] <= assignment.expression.range[0]
|
||||
);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Rule Definition
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/** @type {import('../shared/types').Rule} */
|
||||
module.exports = {
|
||||
meta: {
|
||||
type: "problem",
|
||||
|
||||
docs: {
|
||||
description:
|
||||
"Disallow variable assignments when the value is not used",
|
||||
recommended: false,
|
||||
url: "https://eslint.org/docs/latest/rules/no-useless-assignment",
|
||||
},
|
||||
|
||||
schema: [],
|
||||
|
||||
messages: {
|
||||
unnecessaryAssignment:
|
||||
"This assigned value is not used in subsequent statements.",
|
||||
},
|
||||
},
|
||||
|
||||
create(context) {
|
||||
const sourceCode = context.sourceCode;
|
||||
|
||||
/**
|
||||
* @typedef {Object} ScopeStack
|
||||
* @property {CodePath} codePath The code path of this scope stack.
|
||||
* @property {Scope} scope The scope of this scope stack.
|
||||
* @property {ScopeStack} upper The upper scope stack.
|
||||
* @property {Record<string, ScopeStackSegmentInfo>} segments The map of ScopeStackSegmentInfo.
|
||||
* @property {Set<CodePathSegment>} currentSegments The current CodePathSegments.
|
||||
* @property {Map<Variable, AssignmentInfo[]>} assignments The map of list of AssignmentInfo for each variable.
|
||||
* @property {Array} tryStatementBlocks The array of TryStatement block nodes in this scope stack.
|
||||
*/
|
||||
/**
|
||||
* @typedef {Object} ScopeStackSegmentInfo
|
||||
* @property {CodePathSegment} segment The code path segment.
|
||||
* @property {Identifier|null} first The first identifier that appears within the segment.
|
||||
* @property {Identifier|null} last The last identifier that appears within the segment.
|
||||
* `first` and `last` are used to determine whether an identifier exists within the segment position range.
|
||||
* Since it is used as a range of segments, we should originally hold all nodes, not just identifiers,
|
||||
* but since the only nodes to be judged are identifiers, it is sufficient to have a range of identifiers.
|
||||
*/
|
||||
/**
|
||||
* @typedef {Object} AssignmentInfo
|
||||
* @property {Variable} variable The variable that is assigned.
|
||||
* @property {Identifier} identifier The identifier that is assigned.
|
||||
* @property {VariableDeclarator|AssignmentExpression|UpdateExpression} node The node where the variable was updated.
|
||||
* @property {Expression|null} expression The expression that is evaluated before the assignment.
|
||||
* @property {CodePathSegment[]} segments The code path segments where the assignment was made.
|
||||
*/
|
||||
|
||||
/** @type {ScopeStack} */
|
||||
let scopeStack = null;
|
||||
|
||||
/** @type {Set<Scope>} */
|
||||
const codePathStartScopes = new Set();
|
||||
|
||||
/**
|
||||
* Gets the scope of code path start from given scope
|
||||
* @param {Scope} scope The initial scope
|
||||
* @returns {Scope} The scope of code path start
|
||||
* @throws {Error} Unexpected error
|
||||
*/
|
||||
function getCodePathStartScope(scope) {
|
||||
let target = scope;
|
||||
|
||||
while (target) {
|
||||
if (codePathStartScopes.has(target)) {
|
||||
return target;
|
||||
}
|
||||
target = target.upper;
|
||||
}
|
||||
|
||||
// Should be unreachable
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify the given scope stack.
|
||||
* @param {ScopeStack} target The scope stack to verify.
|
||||
* @returns {void}
|
||||
*/
|
||||
function verify(target) {
|
||||
/**
|
||||
* Checks whether the given identifier is used in the segment.
|
||||
* @param {CodePathSegment} segment The code path segment.
|
||||
* @param {Identifier} identifier The identifier to check.
|
||||
* @returns {boolean} `true` if the identifier is used in the segment.
|
||||
*/
|
||||
function isIdentifierUsedInSegment(segment, identifier) {
|
||||
const segmentInfo = target.segments[segment.id];
|
||||
|
||||
return (
|
||||
segmentInfo.first &&
|
||||
segmentInfo.last &&
|
||||
segmentInfo.first.range[0] <= identifier.range[0] &&
|
||||
identifier.range[1] <= segmentInfo.last.range[1]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies whether the given assignment info is an used assignment.
|
||||
* Report if it is an unused assignment.
|
||||
* @param {AssignmentInfo} targetAssignment The assignment info to verify.
|
||||
* @param {AssignmentInfo[]} allAssignments The list of all assignment info for variables.
|
||||
* @returns {void}
|
||||
*/
|
||||
function verifyAssignmentIsUsed(targetAssignment, allAssignments) {
|
||||
// Skip assignment if it is in a try block.
|
||||
const isAssignmentInTryBlock = target.tryStatementBlocks.some(
|
||||
tryBlock =>
|
||||
tryBlock.range[0] <=
|
||||
targetAssignment.identifier.range[0] &&
|
||||
targetAssignment.identifier.range[1] <=
|
||||
tryBlock.range[1],
|
||||
);
|
||||
|
||||
if (isAssignmentInTryBlock) {
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @typedef {Object} SubsequentSegmentData
|
||||
* @property {CodePathSegment} segment The code path segment
|
||||
* @property {AssignmentInfo} [assignment] The first occurrence of the assignment within the segment.
|
||||
* There is no need to check if the variable is used after this assignment,
|
||||
* as the value it was assigned will be used.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Information used in `getSubsequentSegments()`.
|
||||
* To avoid unnecessary iterations, cache information that has already been iterated over,
|
||||
* and if additional iterations are needed, start iterating from the retained position.
|
||||
*/
|
||||
const subsequentSegmentData = {
|
||||
/**
|
||||
* Cache of subsequent segment information list that have already been iterated.
|
||||
* @type {SubsequentSegmentData[]}
|
||||
*/
|
||||
results: [],
|
||||
|
||||
/**
|
||||
* Subsequent segments that have already been iterated on. Used to avoid infinite loops.
|
||||
* @type {Set<CodePathSegment>}
|
||||
*/
|
||||
subsequentSegments: new Set(),
|
||||
|
||||
/**
|
||||
* Unexplored code path segment.
|
||||
* If additional iterations are needed, consume this information and iterate.
|
||||
* @type {CodePathSegment[]}
|
||||
*/
|
||||
queueSegments: targetAssignment.segments.flatMap(
|
||||
segment => segment.nextSegments,
|
||||
),
|
||||
};
|
||||
|
||||
/**
|
||||
* Gets the subsequent segments from the segment of
|
||||
* the assignment currently being validated (targetAssignment).
|
||||
* @returns {Iterable<SubsequentSegmentData>} the subsequent segments
|
||||
*/
|
||||
function* getSubsequentSegments() {
|
||||
yield* subsequentSegmentData.results;
|
||||
|
||||
while (subsequentSegmentData.queueSegments.length > 0) {
|
||||
const nextSegment =
|
||||
subsequentSegmentData.queueSegments.shift();
|
||||
|
||||
if (
|
||||
subsequentSegmentData.subsequentSegments.has(
|
||||
nextSegment,
|
||||
)
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
subsequentSegmentData.subsequentSegments.add(
|
||||
nextSegment,
|
||||
);
|
||||
|
||||
const assignmentInSegment = allAssignments.find(
|
||||
otherAssignment =>
|
||||
otherAssignment.segments.includes(
|
||||
nextSegment,
|
||||
) &&
|
||||
!isIdentifierUsedBetweenAssignedAndEqualSign(
|
||||
otherAssignment,
|
||||
targetAssignment.identifier,
|
||||
),
|
||||
);
|
||||
|
||||
if (!assignmentInSegment) {
|
||||
/*
|
||||
* Stores the next segment to explore.
|
||||
* If `assignmentInSegment` exists,
|
||||
* we are guarding it because we don't need to explore the next segment.
|
||||
*/
|
||||
subsequentSegmentData.queueSegments.push(
|
||||
...nextSegment.nextSegments,
|
||||
);
|
||||
}
|
||||
|
||||
/** @type {SubsequentSegmentData} */
|
||||
const result = {
|
||||
segment: nextSegment,
|
||||
assignment: assignmentInSegment,
|
||||
};
|
||||
|
||||
subsequentSegmentData.results.push(result);
|
||||
yield result;
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
targetAssignment.variable.references.some(
|
||||
ref => ref.identifier.type !== "Identifier",
|
||||
)
|
||||
) {
|
||||
/**
|
||||
* Skip checking for a variable that has at least one non-identifier reference.
|
||||
* It's generated by plugins and cannot be handled reliably in the core rule.
|
||||
*/
|
||||
return;
|
||||
}
|
||||
|
||||
const readReferences =
|
||||
targetAssignment.variable.references.filter(reference =>
|
||||
reference.isRead(),
|
||||
);
|
||||
|
||||
if (!readReferences.length) {
|
||||
/*
|
||||
* It is not just an unnecessary assignment, but an unnecessary (unused) variable
|
||||
* and thus should not be reported by this rule because it is reported by `no-unused-vars`.
|
||||
*/
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Other assignment on the current segment and after current assignment.
|
||||
*/
|
||||
const otherAssignmentAfterTargetAssignment =
|
||||
allAssignments.find(assignment => {
|
||||
if (
|
||||
assignment === targetAssignment ||
|
||||
(assignment.segments.length &&
|
||||
assignment.segments.every(
|
||||
segment =>
|
||||
!targetAssignment.segments.includes(
|
||||
segment,
|
||||
),
|
||||
))
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
if (
|
||||
isIdentifierEvaluatedAfterAssignment(
|
||||
targetAssignment,
|
||||
assignment.identifier,
|
||||
)
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
if (
|
||||
assignment.expression &&
|
||||
assignment.expression.range[0] <=
|
||||
targetAssignment.identifier.range[0] &&
|
||||
targetAssignment.identifier.range[1] <=
|
||||
assignment.expression.range[1]
|
||||
) {
|
||||
/*
|
||||
* The target assignment is in an expression that is evaluated before the assignment.
|
||||
* e.g. x=(x=1);
|
||||
* ^^^ targetAssignment
|
||||
* ^^^^^^^ assignment
|
||||
*/
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
for (const reference of readReferences) {
|
||||
/*
|
||||
* If the scope of the reference is outside the current code path scope,
|
||||
* we cannot track whether this assignment is not used.
|
||||
* For example, it can also be called asynchronously.
|
||||
*/
|
||||
if (
|
||||
target.scope !== getCodePathStartScope(reference.from)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Checks if it is used in the same segment as the target assignment.
|
||||
if (
|
||||
isIdentifierEvaluatedAfterAssignment(
|
||||
targetAssignment,
|
||||
reference.identifier,
|
||||
) &&
|
||||
(isIdentifierUsedBetweenAssignedAndEqualSign(
|
||||
targetAssignment,
|
||||
reference.identifier,
|
||||
) ||
|
||||
targetAssignment.segments.some(segment =>
|
||||
isIdentifierUsedInSegment(
|
||||
segment,
|
||||
reference.identifier,
|
||||
),
|
||||
))
|
||||
) {
|
||||
if (
|
||||
otherAssignmentAfterTargetAssignment &&
|
||||
isIdentifierEvaluatedAfterAssignment(
|
||||
otherAssignmentAfterTargetAssignment,
|
||||
reference.identifier,
|
||||
)
|
||||
) {
|
||||
// There was another assignment before the reference. Therefore, it has not been used yet.
|
||||
continue;
|
||||
}
|
||||
|
||||
// Uses in statements after the written identifier.
|
||||
return;
|
||||
}
|
||||
|
||||
if (otherAssignmentAfterTargetAssignment) {
|
||||
/*
|
||||
* The assignment was followed by another assignment in the same segment.
|
||||
* Therefore, there is no need to check the next segment.
|
||||
*/
|
||||
continue;
|
||||
}
|
||||
|
||||
// Check subsequent segments.
|
||||
for (const subsequentSegment of getSubsequentSegments()) {
|
||||
if (
|
||||
isIdentifierUsedInSegment(
|
||||
subsequentSegment.segment,
|
||||
reference.identifier,
|
||||
)
|
||||
) {
|
||||
if (
|
||||
subsequentSegment.assignment &&
|
||||
isIdentifierEvaluatedAfterAssignment(
|
||||
subsequentSegment.assignment,
|
||||
reference.identifier,
|
||||
)
|
||||
) {
|
||||
// There was another assignment before the reference. Therefore, it has not been used yet.
|
||||
continue;
|
||||
}
|
||||
|
||||
// It is used
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
context.report({
|
||||
node: targetAssignment.identifier,
|
||||
messageId: "unnecessaryAssignment",
|
||||
});
|
||||
}
|
||||
|
||||
// Verify that each assignment in the code path is used.
|
||||
for (const assignments of target.assignments.values()) {
|
||||
assignments.sort(
|
||||
(a, b) => a.identifier.range[0] - b.identifier.range[0],
|
||||
);
|
||||
for (const assignment of assignments) {
|
||||
verifyAssignmentIsUsed(assignment, assignments);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
onCodePathStart(codePath, node) {
|
||||
const scope = sourceCode.getScope(node);
|
||||
|
||||
scopeStack = {
|
||||
upper: scopeStack,
|
||||
codePath,
|
||||
scope,
|
||||
segments: Object.create(null),
|
||||
currentSegments: new Set(),
|
||||
assignments: new Map(),
|
||||
tryStatementBlocks: [],
|
||||
};
|
||||
codePathStartScopes.add(scopeStack.scope);
|
||||
},
|
||||
onCodePathEnd() {
|
||||
verify(scopeStack);
|
||||
|
||||
scopeStack = scopeStack.upper;
|
||||
},
|
||||
onCodePathSegmentStart(segment) {
|
||||
const segmentInfo = { segment, first: null, last: null };
|
||||
|
||||
scopeStack.segments[segment.id] = segmentInfo;
|
||||
scopeStack.currentSegments.add(segment);
|
||||
},
|
||||
onCodePathSegmentEnd(segment) {
|
||||
scopeStack.currentSegments.delete(segment);
|
||||
},
|
||||
TryStatement(node) {
|
||||
scopeStack.tryStatementBlocks.push(node.block);
|
||||
},
|
||||
Identifier(node) {
|
||||
for (const segment of scopeStack.currentSegments) {
|
||||
const segmentInfo = scopeStack.segments[segment.id];
|
||||
|
||||
if (!segmentInfo.first) {
|
||||
segmentInfo.first = node;
|
||||
}
|
||||
segmentInfo.last = node;
|
||||
}
|
||||
},
|
||||
":matches(VariableDeclarator[init!=null], AssignmentExpression, UpdateExpression):exit"(
|
||||
node,
|
||||
) {
|
||||
if (scopeStack.currentSegments.size === 0) {
|
||||
// Ignore unreachable segments
|
||||
return;
|
||||
}
|
||||
|
||||
const assignments = scopeStack.assignments;
|
||||
|
||||
let pattern;
|
||||
let expression = null;
|
||||
|
||||
if (node.type === "VariableDeclarator") {
|
||||
pattern = node.id;
|
||||
expression = node.init;
|
||||
} else if (node.type === "AssignmentExpression") {
|
||||
pattern = node.left;
|
||||
expression = node.right;
|
||||
} else {
|
||||
// UpdateExpression
|
||||
pattern = node.argument;
|
||||
}
|
||||
|
||||
for (const identifier of extractIdentifiersFromPattern(
|
||||
pattern,
|
||||
)) {
|
||||
const scope = sourceCode.getScope(identifier);
|
||||
|
||||
/** @type {Variable} */
|
||||
const variable = findVariable(scope, identifier);
|
||||
|
||||
if (!variable) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// We don't know where global variables are used.
|
||||
if (
|
||||
variable.scope.type === "global" &&
|
||||
variable.defs.length === 0
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/*
|
||||
* If the scope of the variable is outside the current code path scope,
|
||||
* we cannot track whether this assignment is not used.
|
||||
*/
|
||||
if (
|
||||
scopeStack.scope !==
|
||||
getCodePathStartScope(variable.scope)
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Variables marked by `markVariableAsUsed()` or
|
||||
// exported by "exported" block comment.
|
||||
if (variable.eslintUsed) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Variables exported by ESM export syntax
|
||||
if (variable.scope.type === "module") {
|
||||
if (
|
||||
variable.defs.some(
|
||||
def =>
|
||||
(def.type === "Variable" &&
|
||||
def.parent.parent.type ===
|
||||
"ExportNamedDeclaration") ||
|
||||
(def.type === "FunctionName" &&
|
||||
(def.node.parent.type ===
|
||||
"ExportNamedDeclaration" ||
|
||||
def.node.parent.type ===
|
||||
"ExportDefaultDeclaration")) ||
|
||||
(def.type === "ClassName" &&
|
||||
(def.node.parent.type ===
|
||||
"ExportNamedDeclaration" ||
|
||||
def.node.parent.type ===
|
||||
"ExportDefaultDeclaration")),
|
||||
)
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
if (
|
||||
variable.references.some(
|
||||
reference =>
|
||||
reference.identifier.parent.type ===
|
||||
"ExportSpecifier",
|
||||
)
|
||||
) {
|
||||
// It have `export { ... }` reference.
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
let list = assignments.get(variable);
|
||||
|
||||
if (!list) {
|
||||
list = [];
|
||||
assignments.set(variable, list);
|
||||
}
|
||||
list.push({
|
||||
variable,
|
||||
identifier,
|
||||
node,
|
||||
expression,
|
||||
segments: [...scopeStack.currentSegments],
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,239 @@
|
||||
/**
|
||||
* @fileoverview `IgnorePattern` class.
|
||||
*
|
||||
* `IgnorePattern` class has the set of glob patterns and the base path.
|
||||
*
|
||||
* It provides two static methods.
|
||||
*
|
||||
* - `IgnorePattern.createDefaultIgnore(cwd)`
|
||||
* Create the default predicate function.
|
||||
* - `IgnorePattern.createIgnore(ignorePatterns)`
|
||||
* Create the predicate function from multiple `IgnorePattern` objects.
|
||||
*
|
||||
* It provides two properties and a method.
|
||||
*
|
||||
* - `patterns`
|
||||
* The glob patterns that ignore to lint.
|
||||
* - `basePath`
|
||||
* The base path of the glob patterns. If absolute paths existed in the
|
||||
* glob patterns, those are handled as relative paths to the base path.
|
||||
* - `getPatternsRelativeTo(basePath)`
|
||||
* Get `patterns` as modified for a given base path. It modifies the
|
||||
* absolute paths in the patterns as prepending the difference of two base
|
||||
* paths.
|
||||
*
|
||||
* `ConfigArrayFactory` creates `IgnorePattern` objects when it processes
|
||||
* `ignorePatterns` properties.
|
||||
*
|
||||
* @author Toru Nagashima <https://github.com/mysticatea>
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Requirements
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
import assert from "node:assert";
|
||||
import path from "node:path";
|
||||
import ignore from "ignore";
|
||||
import debugOrig from "debug";
|
||||
|
||||
const debug = debugOrig("eslintrc:ignore-pattern");
|
||||
|
||||
/** @typedef {ReturnType<import("ignore").default>} Ignore */
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Helpers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Get the path to the common ancestor directory of given paths.
|
||||
* @param {string[]} sourcePaths The paths to calculate the common ancestor.
|
||||
* @returns {string} The path to the common ancestor directory.
|
||||
*/
|
||||
function getCommonAncestorPath(sourcePaths) {
|
||||
let result = sourcePaths[0];
|
||||
|
||||
for (let i = 1; i < sourcePaths.length; ++i) {
|
||||
const a = result;
|
||||
const b = sourcePaths[i];
|
||||
|
||||
// Set the shorter one (it's the common ancestor if one includes the other).
|
||||
result = a.length < b.length ? a : b;
|
||||
|
||||
// Set the common ancestor.
|
||||
for (let j = 0, lastSepPos = 0; j < a.length && j < b.length; ++j) {
|
||||
if (a[j] !== b[j]) {
|
||||
result = a.slice(0, lastSepPos);
|
||||
break;
|
||||
}
|
||||
if (a[j] === path.sep) {
|
||||
lastSepPos = j;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let resolvedResult = result || path.sep;
|
||||
|
||||
// if Windows common ancestor is root of drive must have trailing slash to be absolute.
|
||||
if (resolvedResult && resolvedResult.endsWith(":") && process.platform === "win32") {
|
||||
resolvedResult += path.sep;
|
||||
}
|
||||
return resolvedResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make relative path.
|
||||
* @param {string} from The source path to get relative path.
|
||||
* @param {string} to The destination path to get relative path.
|
||||
* @returns {string} The relative path.
|
||||
*/
|
||||
function relative(from, to) {
|
||||
const relPath = path.relative(from, to);
|
||||
|
||||
if (path.sep === "/") {
|
||||
return relPath;
|
||||
}
|
||||
return relPath.split(path.sep).join("/");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the trailing slash if existed.
|
||||
* @param {string} filePath The path to check.
|
||||
* @returns {string} The trailing slash if existed.
|
||||
*/
|
||||
function dirSuffix(filePath) {
|
||||
const isDir = (
|
||||
filePath.endsWith(path.sep) ||
|
||||
(process.platform === "win32" && filePath.endsWith("/"))
|
||||
);
|
||||
|
||||
return isDir ? "/" : "";
|
||||
}
|
||||
|
||||
const DefaultPatterns = Object.freeze(["/**/node_modules/*"]);
|
||||
const DotPatterns = Object.freeze([".*", "!.eslintrc.*", "!../"]);
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Public
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Represents a set of glob patterns to ignore against a base path.
|
||||
*/
|
||||
class IgnorePattern {
|
||||
|
||||
/**
|
||||
* The default patterns.
|
||||
* @type {string[]}
|
||||
*/
|
||||
static get DefaultPatterns() {
|
||||
return DefaultPatterns;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the default predicate function.
|
||||
* @param {string} cwd The current working directory.
|
||||
* @returns {((filePath:string, dot:boolean) => boolean) & {basePath:string; patterns:string[]}}
|
||||
* The preficate function.
|
||||
* The first argument is an absolute path that is checked.
|
||||
* The second argument is the flag to not ignore dotfiles.
|
||||
* If the predicate function returned `true`, it means the path should be ignored.
|
||||
*/
|
||||
static createDefaultIgnore(cwd) {
|
||||
return this.createIgnore([new IgnorePattern(DefaultPatterns, cwd)]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the predicate function from multiple `IgnorePattern` objects.
|
||||
* @param {IgnorePattern[]} ignorePatterns The list of ignore patterns.
|
||||
* @returns {((filePath:string, dot?:boolean) => boolean) & {basePath:string; patterns:string[]}}
|
||||
* The preficate function.
|
||||
* The first argument is an absolute path that is checked.
|
||||
* The second argument is the flag to not ignore dotfiles.
|
||||
* If the predicate function returned `true`, it means the path should be ignored.
|
||||
*/
|
||||
static createIgnore(ignorePatterns) {
|
||||
debug("Create with: %o", ignorePatterns);
|
||||
|
||||
const basePath = getCommonAncestorPath(ignorePatterns.map(p => p.basePath));
|
||||
const patterns = ignorePatterns.flatMap(p => p.getPatternsRelativeTo(basePath));
|
||||
const ig = ignore({ allowRelativePaths: true }).add([...DotPatterns, ...patterns]);
|
||||
const dotIg = ignore({ allowRelativePaths: true }).add(patterns);
|
||||
|
||||
debug(" processed: %o", { basePath, patterns });
|
||||
|
||||
return Object.assign(
|
||||
(filePath, dot = false) => {
|
||||
assert(path.isAbsolute(filePath), "'filePath' should be an absolute path.");
|
||||
const relPathRaw = relative(basePath, filePath);
|
||||
const relPath = relPathRaw && (relPathRaw + dirSuffix(filePath));
|
||||
const adoptedIg = dot ? dotIg : ig;
|
||||
const result = relPath !== "" && adoptedIg.ignores(relPath);
|
||||
|
||||
debug("Check", { filePath, dot, relativePath: relPath, result });
|
||||
return result;
|
||||
},
|
||||
{ basePath, patterns }
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize a new `IgnorePattern` instance.
|
||||
* @param {string[]} patterns The glob patterns that ignore to lint.
|
||||
* @param {string} basePath The base path of `patterns`.
|
||||
*/
|
||||
constructor(patterns, basePath) {
|
||||
assert(path.isAbsolute(basePath), "'basePath' should be an absolute path.");
|
||||
|
||||
/**
|
||||
* The glob patterns that ignore to lint.
|
||||
* @type {string[]}
|
||||
*/
|
||||
this.patterns = patterns;
|
||||
|
||||
/**
|
||||
* The base path of `patterns`.
|
||||
* @type {string}
|
||||
*/
|
||||
this.basePath = basePath;
|
||||
|
||||
/**
|
||||
* If `true` then patterns which don't start with `/` will match the paths to the outside of `basePath`. Defaults to `false`.
|
||||
*
|
||||
* It's set `true` for `.eslintignore`, `package.json`, and `--ignore-path` for backward compatibility.
|
||||
* It's `false` as-is for `ignorePatterns` property in config files.
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.loose = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get `patterns` as modified for a given base path. It modifies the
|
||||
* absolute paths in the patterns as prepending the difference of two base
|
||||
* paths.
|
||||
* @param {string} newBasePath The base path.
|
||||
* @returns {string[]} Modifired patterns.
|
||||
*/
|
||||
getPatternsRelativeTo(newBasePath) {
|
||||
assert(path.isAbsolute(newBasePath), "'newBasePath' should be an absolute path.");
|
||||
const { basePath, loose, patterns } = this;
|
||||
|
||||
if (newBasePath === basePath) {
|
||||
return patterns;
|
||||
}
|
||||
const prefix = `/${relative(newBasePath, basePath)}`;
|
||||
|
||||
return patterns.map(pattern => {
|
||||
const negative = pattern.startsWith("!");
|
||||
const head = negative ? "!" : "";
|
||||
const body = negative ? pattern.slice(1) : pattern;
|
||||
|
||||
if (body.startsWith("/") || body.startsWith("../")) {
|
||||
return `${head}${prefix}${body}`;
|
||||
}
|
||||
return loose ? pattern : `${head}${prefix}/**/${body}`;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export { IgnorePattern };
|
||||
@@ -0,0 +1,177 @@
|
||||
/**
|
||||
* @fileoverview Utility to get information about the execution environment.
|
||||
* @author Kai Cataldo
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Requirements
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
const path = require("node:path");
|
||||
const spawn = require("cross-spawn");
|
||||
const os = require("node:os");
|
||||
const log = require("../shared/logging");
|
||||
const packageJson = require("../../package.json");
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Helpers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Generates and returns execution environment information.
|
||||
* @returns {string} A string that contains execution environment information.
|
||||
*/
|
||||
function environment() {
|
||||
const cache = new Map();
|
||||
|
||||
/**
|
||||
* Checks if a path is a child of a directory.
|
||||
* @param {string} parentPath The parent path to check.
|
||||
* @param {string} childPath The path to check.
|
||||
* @returns {boolean} Whether or not the given path is a child of a directory.
|
||||
*/
|
||||
function isChildOfDirectory(parentPath, childPath) {
|
||||
return !path.relative(parentPath, childPath).startsWith("..");
|
||||
}
|
||||
|
||||
/**
|
||||
* Synchronously executes a shell command and formats the result.
|
||||
* @param {string} cmd The command to execute.
|
||||
* @param {Array} args The arguments to be executed with the command.
|
||||
* @throws {Error} As may be collected by `cross-spawn.sync`.
|
||||
* @returns {string} The version returned by the command.
|
||||
*/
|
||||
function execCommand(cmd, args) {
|
||||
const key = [cmd, ...args].join(" ");
|
||||
|
||||
if (cache.has(key)) {
|
||||
return cache.get(key);
|
||||
}
|
||||
|
||||
const process = spawn.sync(cmd, args, { encoding: "utf8" });
|
||||
|
||||
if (process.error) {
|
||||
throw process.error;
|
||||
}
|
||||
|
||||
const result = process.stdout.trim();
|
||||
|
||||
cache.set(key, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalizes a version number.
|
||||
* @param {string} versionStr The string to normalize.
|
||||
* @returns {string} The normalized version number.
|
||||
*/
|
||||
function normalizeVersionStr(versionStr) {
|
||||
return versionStr.startsWith("v") ? versionStr : `v${versionStr}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets bin version.
|
||||
* @param {string} bin The bin to check.
|
||||
* @throws {Error} As may be collected by `cross-spawn.sync`.
|
||||
* @returns {string} The normalized version returned by the command.
|
||||
*/
|
||||
function getBinVersion(bin) {
|
||||
const binArgs = ["--version"];
|
||||
|
||||
try {
|
||||
return normalizeVersionStr(execCommand(bin, binArgs));
|
||||
} catch (e) {
|
||||
log.error(
|
||||
`Error finding ${bin} version running the command \`${bin} ${binArgs.join(" ")}\``,
|
||||
);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets installed npm package version.
|
||||
* @param {string} pkg The package to check.
|
||||
* @param {boolean} global Whether to check globally or not.
|
||||
* @throws {Error} As may be collected by `cross-spawn.sync`.
|
||||
* @returns {string} The normalized version returned by the command.
|
||||
*/
|
||||
function getNpmPackageVersion(pkg, { global = false } = {}) {
|
||||
const npmBinArgs = ["bin", "-g"];
|
||||
const npmLsArgs = ["ls", "--depth=0", "--json", pkg];
|
||||
|
||||
if (global) {
|
||||
npmLsArgs.push("-g");
|
||||
}
|
||||
|
||||
try {
|
||||
const parsedStdout = JSON.parse(execCommand("npm", npmLsArgs));
|
||||
|
||||
/*
|
||||
* Checking globally returns an empty JSON object, while local checks
|
||||
* include the name and version of the local project.
|
||||
*/
|
||||
if (
|
||||
Object.keys(parsedStdout).length === 0 ||
|
||||
!(parsedStdout.dependencies && parsedStdout.dependencies.eslint)
|
||||
) {
|
||||
return "Not found";
|
||||
}
|
||||
|
||||
const [, processBinPath] = process.argv;
|
||||
let npmBinPath;
|
||||
|
||||
try {
|
||||
npmBinPath = execCommand("npm", npmBinArgs);
|
||||
} catch (e) {
|
||||
log.error(
|
||||
`Error finding npm binary path when running command \`npm ${npmBinArgs.join(" ")}\``,
|
||||
);
|
||||
throw e;
|
||||
}
|
||||
|
||||
const isGlobal = isChildOfDirectory(npmBinPath, processBinPath);
|
||||
let pkgVersion = parsedStdout.dependencies.eslint.version;
|
||||
|
||||
if ((global && isGlobal) || (!global && !isGlobal)) {
|
||||
pkgVersion += " (Currently used)";
|
||||
}
|
||||
|
||||
return normalizeVersionStr(pkgVersion);
|
||||
} catch (e) {
|
||||
log.error(
|
||||
`Error finding ${pkg} version running the command \`npm ${npmLsArgs.join(" ")}\``,
|
||||
);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
"Environment Info:",
|
||||
"",
|
||||
`Node version: ${getBinVersion("node")}`,
|
||||
`npm version: ${getBinVersion("npm")}`,
|
||||
`Local ESLint version: ${getNpmPackageVersion("eslint", { global: false })}`,
|
||||
`Global ESLint version: ${getNpmPackageVersion("eslint", { global: true })}`,
|
||||
`Operating System: ${os.platform()} ${os.release()}`,
|
||||
].join("\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns version of currently executing ESLint.
|
||||
* @returns {string} The version from the currently executing ESLint's package.json.
|
||||
*/
|
||||
function version() {
|
||||
return `v${packageJson.version}`;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Public Interface
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
module.exports = {
|
||||
__esModule: true, // Indicate intent for imports, remove ambiguity for Knip (see: https://github.com/eslint/eslint/pull/18005#discussion_r1484422616)
|
||||
environment,
|
||||
version,
|
||||
};
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"names":["TaggedTemplateExpression","node","print","tag","typeParameters","quasi","TemplateElement","Error","_printTemplate","substitutions","quasis","partRaw","i","length","value","raw","token","tokenMap","findMatching","_catchUpTo","loc","start","TemplateLiteral","expressions"],"sources":["../../src/generators/template-literals.ts"],"sourcesContent":["import type Printer from \"../printer.ts\";\nimport type * as t from \"@babel/types\";\n\nexport function TaggedTemplateExpression(\n this: Printer,\n node: t.TaggedTemplateExpression,\n) {\n this.print(node.tag);\n if (process.env.BABEL_8_BREAKING) {\n // @ts-ignore(Babel 7 vs Babel 8) Babel 8 AST\n this.print(node.typeArguments);\n } else {\n // @ts-ignore(Babel 7 vs Babel 8) Babel 7 AST\n this.print(node.typeParameters);\n }\n this.print(node.quasi);\n}\n\nexport function TemplateElement(this: Printer) {\n throw new Error(\"TemplateElement printing is handled in TemplateLiteral\");\n}\n\nexport type TemplateLiteralBase = t.Node & {\n quasis: t.TemplateElement[];\n};\n\nexport function _printTemplate<T extends t.Node>(\n this: Printer,\n node: TemplateLiteralBase,\n substitutions: T[],\n) {\n const quasis = node.quasis;\n let partRaw = \"`\";\n for (let i = 0; i < quasis.length - 1; i++) {\n partRaw += quasis[i].value.raw;\n this.token(partRaw + \"${\", true);\n this.print(substitutions[i]);\n partRaw = \"}\";\n\n // In Babel 7 we have individual tokens for ${ and }, so the automatic\n // catchup logic does not work. Manually look for those tokens.\n if (!process.env.BABEL_8_BREAKING && this.tokenMap) {\n const token = this.tokenMap.findMatching(node, \"}\", i);\n if (token) this._catchUpTo(token.loc.start);\n }\n }\n partRaw += quasis[quasis.length - 1].value.raw;\n this.token(partRaw + \"`\", true);\n}\n\nexport function TemplateLiteral(this: Printer, node: t.TemplateLiteral) {\n this._printTemplate(node, node.expressions);\n}\n"],"mappings":";;;;;;;;;AAGO,SAASA,wBAAwBA,CAEtCC,IAAgC,EAChC;EACA,IAAI,CAACC,KAAK,CAACD,IAAI,CAACE,GAAG,CAAC;EAIb;IAEL,IAAI,CAACD,KAAK,CAACD,IAAI,CAACG,cAAc,CAAC;EACjC;EACA,IAAI,CAACF,KAAK,CAACD,IAAI,CAACI,KAAK,CAAC;AACxB;AAEO,SAASC,eAAeA,CAAA,EAAgB;EAC7C,MAAM,IAAIC,KAAK,CAAC,wDAAwD,CAAC;AAC3E;AAMO,SAASC,cAAcA,CAE5BP,IAAyB,EACzBQ,aAAkB,EAClB;EACA,MAAMC,MAAM,GAAGT,IAAI,CAACS,MAAM;EAC1B,IAAIC,OAAO,GAAG,GAAG;EACjB,KAAK,IAAIC,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGF,MAAM,CAACG,MAAM,GAAG,CAAC,EAAED,CAAC,EAAE,EAAE;IAC1CD,OAAO,IAAID,MAAM,CAACE,CAAC,CAAC,CAACE,KAAK,CAACC,GAAG;IAC9B,IAAI,CAACC,KAAK,CAACL,OAAO,GAAG,IAAI,EAAE,IAAI,CAAC;IAChC,IAAI,CAACT,KAAK,CAACO,aAAa,CAACG,CAAC,CAAC,CAAC;IAC5BD,OAAO,GAAG,GAAG;IAIb,IAAqC,IAAI,CAACM,QAAQ,EAAE;MAClD,MAAMD,KAAK,GAAG,IAAI,CAACC,QAAQ,CAACC,YAAY,CAACjB,IAAI,EAAE,GAAG,EAAEW,CAAC,CAAC;MACtD,IAAII,KAAK,EAAE,IAAI,CAACG,UAAU,CAACH,KAAK,CAACI,GAAG,CAACC,KAAK,CAAC;IAC7C;EACF;EACAV,OAAO,IAAID,MAAM,CAACA,MAAM,CAACG,MAAM,GAAG,CAAC,CAAC,CAACC,KAAK,CAACC,GAAG;EAC9C,IAAI,CAACC,KAAK,CAACL,OAAO,GAAG,GAAG,EAAE,IAAI,CAAC;AACjC;AAEO,SAASW,eAAeA,CAAgBrB,IAAuB,EAAE;EACtE,IAAI,CAACO,cAAc,CAACP,IAAI,EAAEA,IAAI,CAACsB,WAAW,CAAC;AAC7C","ignoreList":[]}
|
||||
@@ -0,0 +1,48 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
||||
const jsxRuntime = require("react/jsx-runtime");
|
||||
const React = require("react");
|
||||
const routerCore = require("@tanstack/router-core");
|
||||
function _interopNamespaceDefault(e) {
|
||||
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
||||
if (e) {
|
||||
for (const k in e) {
|
||||
if (k !== "default") {
|
||||
const d = Object.getOwnPropertyDescriptor(e, k);
|
||||
Object.defineProperty(n, k, d.get ? d : {
|
||||
enumerable: true,
|
||||
get: () => e[k]
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
n.default = e;
|
||||
return Object.freeze(n);
|
||||
}
|
||||
const React__namespace = /* @__PURE__ */ _interopNamespaceDefault(React);
|
||||
function useAwaited({
|
||||
promise: _promise
|
||||
}) {
|
||||
const promise = routerCore.defer(_promise);
|
||||
if (promise[routerCore.TSR_DEFERRED_PROMISE].status === "pending") {
|
||||
throw promise;
|
||||
}
|
||||
if (promise[routerCore.TSR_DEFERRED_PROMISE].status === "error") {
|
||||
throw promise[routerCore.TSR_DEFERRED_PROMISE].error;
|
||||
}
|
||||
return [promise[routerCore.TSR_DEFERRED_PROMISE].data, promise];
|
||||
}
|
||||
function Await(props) {
|
||||
const inner = /* @__PURE__ */ jsxRuntime.jsx(AwaitInner, { ...props });
|
||||
if (props.fallback) {
|
||||
return /* @__PURE__ */ jsxRuntime.jsx(React__namespace.Suspense, { fallback: props.fallback, children: inner });
|
||||
}
|
||||
return inner;
|
||||
}
|
||||
function AwaitInner(props) {
|
||||
const [data] = useAwaited(props);
|
||||
return props.children(data);
|
||||
}
|
||||
exports.Await = Await;
|
||||
exports.useAwaited = useAwaited;
|
||||
//# sourceMappingURL=awaited.cjs.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"names":["_assertClassBrand","require","_classCheckPrivateStaticAccess","receiver","classConstructor","returnValue","assertClassBrand"],"sources":["../../src/helpers/classCheckPrivateStaticAccess.js"],"sourcesContent":["/* @minVersion 7.13.10 */\n/* @onlyBabel7 */\n\nimport assertClassBrand from \"assertClassBrand\";\nexport default function _classCheckPrivateStaticAccess(\n receiver,\n classConstructor,\n returnValue,\n) {\n return assertClassBrand(classConstructor, receiver, returnValue);\n}\n"],"mappings":";;;;;;AAGA,IAAAA,iBAAA,GAAAC,OAAA;AACe,SAASC,8BAA8BA,CACpDC,QAAQ,EACRC,gBAAgB,EAChBC,WAAW,EACX;EACA,OAAOC,iBAAgB,CAACF,gBAAgB,EAAED,QAAQ,EAAEE,WAAW,CAAC;AAClE","ignoreList":[]}
|
||||
Binary file not shown.
@@ -0,0 +1,340 @@
|
||||
/**
|
||||
* @license React
|
||||
* react-dom.react-server.development.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";
|
||||
"production" !== process.env.NODE_ENV &&
|
||||
(function () {
|
||||
function noop() {}
|
||||
function getCrossOriginStringAs(as, input) {
|
||||
if ("font" === as) return "";
|
||||
if ("string" === typeof input)
|
||||
return "use-credentials" === input ? input : "";
|
||||
}
|
||||
function getValueDescriptorExpectingObjectForWarning(thing) {
|
||||
return null === thing
|
||||
? "`null`"
|
||||
: void 0 === thing
|
||||
? "`undefined`"
|
||||
: "" === thing
|
||||
? "an empty string"
|
||||
: 'something with type "' + typeof thing + '"';
|
||||
}
|
||||
function getValueDescriptorExpectingEnumForWarning(thing) {
|
||||
return null === thing
|
||||
? "`null`"
|
||||
: void 0 === thing
|
||||
? "`undefined`"
|
||||
: "" === thing
|
||||
? "an empty string"
|
||||
: "string" === typeof thing
|
||||
? JSON.stringify(thing)
|
||||
: "number" === typeof thing
|
||||
? "`" + thing + "`"
|
||||
: 'something with type "' + typeof thing + '"';
|
||||
}
|
||||
var React = require("react"),
|
||||
Internals = {
|
||||
d: {
|
||||
f: noop,
|
||||
r: function () {
|
||||
throw Error(
|
||||
"Invalid form element. requestFormReset must be passed a form that was rendered by React."
|
||||
);
|
||||
},
|
||||
D: noop,
|
||||
C: noop,
|
||||
L: noop,
|
||||
m: noop,
|
||||
X: noop,
|
||||
S: noop,
|
||||
M: noop
|
||||
},
|
||||
p: 0,
|
||||
findDOMNode: null
|
||||
};
|
||||
if (!React.__SERVER_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE)
|
||||
throw Error(
|
||||
'The "react" package in this environment is not configured correctly. The "react-server" condition must be enabled in any environment that runs React Server Components.'
|
||||
);
|
||||
("function" === typeof Map &&
|
||||
null != Map.prototype &&
|
||||
"function" === typeof Map.prototype.forEach &&
|
||||
"function" === typeof Set &&
|
||||
null != Set.prototype &&
|
||||
"function" === typeof Set.prototype.clear &&
|
||||
"function" === typeof Set.prototype.forEach) ||
|
||||
console.error(
|
||||
"React depends on Map and Set built-in types. Make sure that you load a polyfill in older browsers. https://reactjs.org/link/react-polyfills"
|
||||
);
|
||||
exports.__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE =
|
||||
Internals;
|
||||
exports.preconnect = function (href, options) {
|
||||
"string" === typeof href && href
|
||||
? null != options && "object" !== typeof options
|
||||
? console.error(
|
||||
"ReactDOM.preconnect(): Expected the `options` argument (second) to be an object but encountered %s instead. The only supported option at this time is `crossOrigin` which accepts a string.",
|
||||
getValueDescriptorExpectingEnumForWarning(options)
|
||||
)
|
||||
: null != options &&
|
||||
"string" !== typeof options.crossOrigin &&
|
||||
console.error(
|
||||
"ReactDOM.preconnect(): Expected the `crossOrigin` option (second argument) to be a string but encountered %s instead. Try removing this option or passing a string value instead.",
|
||||
getValueDescriptorExpectingObjectForWarning(options.crossOrigin)
|
||||
)
|
||||
: console.error(
|
||||
"ReactDOM.preconnect(): Expected the `href` argument (first) to be a non-empty string but encountered %s instead.",
|
||||
getValueDescriptorExpectingObjectForWarning(href)
|
||||
);
|
||||
"string" === typeof href &&
|
||||
(options
|
||||
? ((options = options.crossOrigin),
|
||||
(options =
|
||||
"string" === typeof options
|
||||
? "use-credentials" === options
|
||||
? options
|
||||
: ""
|
||||
: void 0))
|
||||
: (options = null),
|
||||
Internals.d.C(href, options));
|
||||
};
|
||||
exports.prefetchDNS = function (href) {
|
||||
if ("string" !== typeof href || !href)
|
||||
console.error(
|
||||
"ReactDOM.prefetchDNS(): Expected the `href` argument (first) to be a non-empty string but encountered %s instead.",
|
||||
getValueDescriptorExpectingObjectForWarning(href)
|
||||
);
|
||||
else if (1 < arguments.length) {
|
||||
var options = arguments[1];
|
||||
"object" === typeof options && options.hasOwnProperty("crossOrigin")
|
||||
? console.error(
|
||||
"ReactDOM.prefetchDNS(): Expected only one argument, `href`, but encountered %s as a second argument instead. This argument is reserved for future options and is currently disallowed. It looks like the you are attempting to set a crossOrigin property for this DNS lookup hint. Browsers do not perform DNS queries using CORS and setting this attribute on the resource hint has no effect. Try calling ReactDOM.prefetchDNS() with just a single string argument, `href`.",
|
||||
getValueDescriptorExpectingEnumForWarning(options)
|
||||
)
|
||||
: console.error(
|
||||
"ReactDOM.prefetchDNS(): Expected only one argument, `href`, but encountered %s as a second argument instead. This argument is reserved for future options and is currently disallowed. Try calling ReactDOM.prefetchDNS() with just a single string argument, `href`.",
|
||||
getValueDescriptorExpectingEnumForWarning(options)
|
||||
);
|
||||
}
|
||||
"string" === typeof href && Internals.d.D(href);
|
||||
};
|
||||
exports.preinit = function (href, options) {
|
||||
"string" === typeof href && href
|
||||
? null == options || "object" !== typeof options
|
||||
? console.error(
|
||||
"ReactDOM.preinit(): Expected the `options` argument (second) to be an object with an `as` property describing the type of resource to be preinitialized but encountered %s instead.",
|
||||
getValueDescriptorExpectingEnumForWarning(options)
|
||||
)
|
||||
: "style" !== options.as &&
|
||||
"script" !== options.as &&
|
||||
console.error(
|
||||
'ReactDOM.preinit(): Expected the `as` property in the `options` argument (second) to contain a valid value describing the type of resource to be preinitialized but encountered %s instead. Valid values for `as` are "style" and "script".',
|
||||
getValueDescriptorExpectingEnumForWarning(options.as)
|
||||
)
|
||||
: console.error(
|
||||
"ReactDOM.preinit(): Expected the `href` argument (first) to be a non-empty string but encountered %s instead.",
|
||||
getValueDescriptorExpectingObjectForWarning(href)
|
||||
);
|
||||
if (
|
||||
"string" === typeof href &&
|
||||
options &&
|
||||
"string" === typeof options.as
|
||||
) {
|
||||
var as = options.as,
|
||||
crossOrigin = getCrossOriginStringAs(as, options.crossOrigin),
|
||||
integrity =
|
||||
"string" === typeof options.integrity ? options.integrity : void 0,
|
||||
fetchPriority =
|
||||
"string" === typeof options.fetchPriority
|
||||
? options.fetchPriority
|
||||
: void 0;
|
||||
"style" === as
|
||||
? Internals.d.S(
|
||||
href,
|
||||
"string" === typeof options.precedence
|
||||
? options.precedence
|
||||
: void 0,
|
||||
{
|
||||
crossOrigin: crossOrigin,
|
||||
integrity: integrity,
|
||||
fetchPriority: fetchPriority
|
||||
}
|
||||
)
|
||||
: "script" === as &&
|
||||
Internals.d.X(href, {
|
||||
crossOrigin: crossOrigin,
|
||||
integrity: integrity,
|
||||
fetchPriority: fetchPriority,
|
||||
nonce: "string" === typeof options.nonce ? options.nonce : void 0
|
||||
});
|
||||
}
|
||||
};
|
||||
exports.preinitModule = function (href, options) {
|
||||
var encountered = "";
|
||||
("string" === typeof href && href) ||
|
||||
(encountered +=
|
||||
" The `href` argument encountered was " +
|
||||
getValueDescriptorExpectingObjectForWarning(href) +
|
||||
".");
|
||||
void 0 !== options && "object" !== typeof options
|
||||
? (encountered +=
|
||||
" The `options` argument encountered was " +
|
||||
getValueDescriptorExpectingObjectForWarning(options) +
|
||||
".")
|
||||
: options &&
|
||||
"as" in options &&
|
||||
"script" !== options.as &&
|
||||
(encountered +=
|
||||
" The `as` option encountered was " +
|
||||
getValueDescriptorExpectingEnumForWarning(options.as) +
|
||||
".");
|
||||
if (encountered)
|
||||
console.error(
|
||||
"ReactDOM.preinitModule(): Expected up to two arguments, a non-empty `href` string and, optionally, an `options` object with a valid `as` property.%s",
|
||||
encountered
|
||||
);
|
||||
else
|
||||
switch (
|
||||
((encountered =
|
||||
options && "string" === typeof options.as ? options.as : "script"),
|
||||
encountered)
|
||||
) {
|
||||
case "script":
|
||||
break;
|
||||
default:
|
||||
(encountered =
|
||||
getValueDescriptorExpectingEnumForWarning(encountered)),
|
||||
console.error(
|
||||
'ReactDOM.preinitModule(): Currently the only supported "as" type for this function is "script" but received "%s" instead. This warning was generated for `href` "%s". In the future other module types will be supported, aligning with the import-attributes proposal. Learn more here: (https://github.com/tc39/proposal-import-attributes)',
|
||||
encountered,
|
||||
href
|
||||
);
|
||||
}
|
||||
if ("string" === typeof href)
|
||||
if ("object" === typeof options && null !== options) {
|
||||
if (null == options.as || "script" === options.as)
|
||||
(encountered = getCrossOriginStringAs(
|
||||
options.as,
|
||||
options.crossOrigin
|
||||
)),
|
||||
Internals.d.M(href, {
|
||||
crossOrigin: encountered,
|
||||
integrity:
|
||||
"string" === typeof options.integrity
|
||||
? options.integrity
|
||||
: void 0,
|
||||
nonce:
|
||||
"string" === typeof options.nonce ? options.nonce : void 0
|
||||
});
|
||||
} else null == options && Internals.d.M(href);
|
||||
};
|
||||
exports.preload = function (href, options) {
|
||||
var encountered = "";
|
||||
("string" === typeof href && href) ||
|
||||
(encountered +=
|
||||
" The `href` argument encountered was " +
|
||||
getValueDescriptorExpectingObjectForWarning(href) +
|
||||
".");
|
||||
null == options || "object" !== typeof options
|
||||
? (encountered +=
|
||||
" The `options` argument encountered was " +
|
||||
getValueDescriptorExpectingObjectForWarning(options) +
|
||||
".")
|
||||
: ("string" === typeof options.as && options.as) ||
|
||||
(encountered +=
|
||||
" The `as` option encountered was " +
|
||||
getValueDescriptorExpectingObjectForWarning(options.as) +
|
||||
".");
|
||||
encountered &&
|
||||
console.error(
|
||||
'ReactDOM.preload(): Expected two arguments, a non-empty `href` string and an `options` object with an `as` property valid for a `<link rel="preload" as="..." />` tag.%s',
|
||||
encountered
|
||||
);
|
||||
if (
|
||||
"string" === typeof href &&
|
||||
"object" === typeof options &&
|
||||
null !== options &&
|
||||
"string" === typeof options.as
|
||||
) {
|
||||
encountered = options.as;
|
||||
var crossOrigin = getCrossOriginStringAs(
|
||||
encountered,
|
||||
options.crossOrigin
|
||||
);
|
||||
Internals.d.L(href, encountered, {
|
||||
crossOrigin: crossOrigin,
|
||||
integrity:
|
||||
"string" === typeof options.integrity ? options.integrity : void 0,
|
||||
nonce: "string" === typeof options.nonce ? options.nonce : void 0,
|
||||
type: "string" === typeof options.type ? options.type : void 0,
|
||||
fetchPriority:
|
||||
"string" === typeof options.fetchPriority
|
||||
? options.fetchPriority
|
||||
: void 0,
|
||||
referrerPolicy:
|
||||
"string" === typeof options.referrerPolicy
|
||||
? options.referrerPolicy
|
||||
: void 0,
|
||||
imageSrcSet:
|
||||
"string" === typeof options.imageSrcSet
|
||||
? options.imageSrcSet
|
||||
: void 0,
|
||||
imageSizes:
|
||||
"string" === typeof options.imageSizes
|
||||
? options.imageSizes
|
||||
: void 0,
|
||||
media: "string" === typeof options.media ? options.media : void 0
|
||||
});
|
||||
}
|
||||
};
|
||||
exports.preloadModule = function (href, options) {
|
||||
var encountered = "";
|
||||
("string" === typeof href && href) ||
|
||||
(encountered +=
|
||||
" The `href` argument encountered was " +
|
||||
getValueDescriptorExpectingObjectForWarning(href) +
|
||||
".");
|
||||
void 0 !== options && "object" !== typeof options
|
||||
? (encountered +=
|
||||
" The `options` argument encountered was " +
|
||||
getValueDescriptorExpectingObjectForWarning(options) +
|
||||
".")
|
||||
: options &&
|
||||
"as" in options &&
|
||||
"string" !== typeof options.as &&
|
||||
(encountered +=
|
||||
" The `as` option encountered was " +
|
||||
getValueDescriptorExpectingObjectForWarning(options.as) +
|
||||
".");
|
||||
encountered &&
|
||||
console.error(
|
||||
'ReactDOM.preloadModule(): Expected two arguments, a non-empty `href` string and, optionally, an `options` object with an `as` property valid for a `<link rel="modulepreload" as="..." />` tag.%s',
|
||||
encountered
|
||||
);
|
||||
"string" === typeof href &&
|
||||
(options
|
||||
? ((encountered = getCrossOriginStringAs(
|
||||
options.as,
|
||||
options.crossOrigin
|
||||
)),
|
||||
Internals.d.m(href, {
|
||||
as:
|
||||
"string" === typeof options.as && "script" !== options.as
|
||||
? options.as
|
||||
: void 0,
|
||||
crossOrigin: encountered,
|
||||
integrity:
|
||||
"string" === typeof options.integrity
|
||||
? options.integrity
|
||||
: void 0
|
||||
}))
|
||||
: Internals.d.m(href));
|
||||
};
|
||||
exports.version = "19.1.0";
|
||||
})();
|
||||
Reference in New Issue
Block a user