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

View File

@@ -0,0 +1,46 @@
'use strict';
var test = require('tape');
var stringify = require('../');
test('simple object', function (t) {
t.plan(1);
var obj = { c: 6, b: [4,5], a: 3, z: null };
t.equal(stringify(obj), '{"a":3,"b":[4,5],"c":6,"z":null}');
});
test('object with undefined', function (t) {
t.plan(1);
var obj = { a: 3, z: undefined };
t.equal(stringify(obj), '{"a":3}');
});
test('object with null', function (t) {
t.plan(1);
var obj = { a: 3, z: null };
t.equal(stringify(obj), '{"a":3,"z":null}');
});
test('object with NaN and Infinity', function (t) {
t.plan(1);
var obj = { a: 3, b: NaN, c: Infinity };
t.equal(stringify(obj), '{"a":3,"b":null,"c":null}');
});
test('array with undefined', function (t) {
t.plan(1);
var obj = [4, undefined, 6];
t.equal(stringify(obj), '[4,null,6]');
});
test('object with empty string', function (t) {
t.plan(1);
var obj = { a: 3, z: '' };
t.equal(stringify(obj), '{"a":3,"z":""}');
});
test('array with empty string', function (t) {
t.plan(1);
var obj = [4, '', 6];
t.equal(stringify(obj), '[4,"",6]');
});

View File

@@ -0,0 +1,363 @@
/**
* @fileoverview Rule to flag non-matching identifiers
* @author Matthieu Larcher
*/
"use strict";
//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------
const astUtils = require("./utils/ast-utils");
//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------
/** @type {import('../shared/types').Rule} */
module.exports = {
meta: {
type: "suggestion",
defaultOptions: [
"^.+$",
{
classFields: false,
ignoreDestructuring: false,
onlyDeclarations: false,
properties: false,
},
],
docs: {
description:
"Require identifiers to match a specified regular expression",
recommended: false,
frozen: true,
url: "https://eslint.org/docs/latest/rules/id-match",
},
schema: [
{
type: "string",
},
{
type: "object",
properties: {
properties: {
type: "boolean",
},
classFields: {
type: "boolean",
},
onlyDeclarations: {
type: "boolean",
},
ignoreDestructuring: {
type: "boolean",
},
},
additionalProperties: false,
},
],
messages: {
notMatch:
"Identifier '{{name}}' does not match the pattern '{{pattern}}'.",
notMatchPrivate:
"Identifier '#{{name}}' does not match the pattern '{{pattern}}'.",
},
},
create(context) {
//--------------------------------------------------------------------------
// Options
//--------------------------------------------------------------------------
const [
pattern,
{
classFields: checkClassFields,
ignoreDestructuring,
onlyDeclarations,
properties: checkProperties,
},
] = context.options;
const regexp = new RegExp(pattern, "u");
const sourceCode = context.sourceCode;
let globalScope;
//--------------------------------------------------------------------------
// Helpers
//--------------------------------------------------------------------------
// contains reported nodes to avoid reporting twice on destructuring with shorthand notation
const reportedNodes = new Set();
const ALLOWED_PARENT_TYPES = new Set([
"CallExpression",
"NewExpression",
]);
const DECLARATION_TYPES = new Set([
"FunctionDeclaration",
"VariableDeclarator",
]);
const IMPORT_TYPES = new Set([
"ImportSpecifier",
"ImportNamespaceSpecifier",
"ImportDefaultSpecifier",
]);
/**
* Checks whether the given node represents a reference to a global variable that is not declared in the source code.
* These identifiers will be allowed, as it is assumed that user has no control over the names of external global variables.
* @param {ASTNode} node `Identifier` node to check.
* @returns {boolean} `true` if the node is a reference to a global variable.
*/
function isReferenceToGlobalVariable(node) {
const variable = globalScope.set.get(node.name);
return (
variable &&
variable.defs.length === 0 &&
variable.references.some(ref => ref.identifier === node)
);
}
/**
* Checks if a string matches the provided pattern
* @param {string} name The string to check.
* @returns {boolean} if the string is a match
* @private
*/
function isInvalid(name) {
return !regexp.test(name);
}
/**
* Checks if a parent of a node is an ObjectPattern.
* @param {ASTNode} node The node to check.
* @returns {boolean} if the node is inside an ObjectPattern
* @private
*/
function isInsideObjectPattern(node) {
let { parent } = node;
while (parent) {
if (parent.type === "ObjectPattern") {
return true;
}
parent = parent.parent;
}
return false;
}
/**
* Verifies if we should report an error or not based on the effective
* parent node and the identifier name.
* @param {ASTNode} effectiveParent The effective parent node of the node to be reported
* @param {string} name The identifier name of the identifier node
* @returns {boolean} whether an error should be reported or not
*/
function shouldReport(effectiveParent, name) {
return (
(!onlyDeclarations ||
DECLARATION_TYPES.has(effectiveParent.type)) &&
!ALLOWED_PARENT_TYPES.has(effectiveParent.type) &&
isInvalid(name)
);
}
/**
* Reports an AST node as a rule violation.
* @param {ASTNode} node The node to report.
* @returns {void}
* @private
*/
function report(node) {
/*
* We used the range instead of the node because it's possible
* for the same identifier to be represented by two different
* nodes, with the most clear example being shorthand properties:
* { foo }
* In this case, "foo" is represented by one node for the name
* and one for the value. The only way to know they are the same
* is to look at the range.
*/
if (!reportedNodes.has(node.range.toString())) {
const messageId =
node.type === "PrivateIdentifier"
? "notMatchPrivate"
: "notMatch";
context.report({
node,
messageId,
data: {
name: node.name,
pattern,
},
});
reportedNodes.add(node.range.toString());
}
}
return {
Program(node) {
globalScope = sourceCode.getScope(node);
},
Identifier(node) {
const name = node.name,
parent = node.parent,
effectiveParent =
parent.type === "MemberExpression"
? parent.parent
: parent;
if (
isReferenceToGlobalVariable(node) ||
astUtils.isImportAttributeKey(node)
) {
return;
}
if (parent.type === "MemberExpression") {
if (!checkProperties) {
return;
}
// Always check object names
if (
parent.object.type === "Identifier" &&
parent.object.name === name
) {
if (isInvalid(name)) {
report(node);
}
// Report AssignmentExpressions left side's assigned variable id
} else if (
effectiveParent.type === "AssignmentExpression" &&
effectiveParent.left.type === "MemberExpression" &&
effectiveParent.left.property.name === node.name
) {
if (isInvalid(name)) {
report(node);
}
// Report AssignmentExpressions only if they are the left side of the assignment
} else if (
effectiveParent.type === "AssignmentExpression" &&
effectiveParent.right.type !== "MemberExpression"
) {
if (isInvalid(name)) {
report(node);
}
}
// For https://github.com/eslint/eslint/issues/15123
} else if (
parent.type === "Property" &&
parent.parent.type === "ObjectExpression" &&
parent.key === node &&
!parent.computed
) {
if (checkProperties && isInvalid(name)) {
report(node);
}
/*
* Properties have their own rules, and
* AssignmentPattern nodes can be treated like Properties:
* e.g.: const { no_camelcased = false } = bar;
*/
} else if (
parent.type === "Property" ||
parent.type === "AssignmentPattern"
) {
if (
parent.parent &&
parent.parent.type === "ObjectPattern"
) {
if (
!ignoreDestructuring &&
parent.shorthand &&
parent.value.left &&
isInvalid(name)
) {
report(node);
}
const assignmentKeyEqualsValue =
parent.key.name === parent.value.name;
// prevent checking righthand side of destructured object
if (!assignmentKeyEqualsValue && parent.key === node) {
return;
}
const valueIsInvalid =
parent.value.name && isInvalid(name);
// ignore destructuring if the option is set, unless a new identifier is created
if (
valueIsInvalid &&
!(assignmentKeyEqualsValue && ignoreDestructuring)
) {
report(node);
}
}
// never check properties or always ignore destructuring
if (
(!checkProperties && !parent.computed) ||
(ignoreDestructuring && isInsideObjectPattern(node))
) {
return;
}
// don't check right hand side of AssignmentExpression to prevent duplicate warnings
if (
parent.right !== node &&
shouldReport(effectiveParent, name)
) {
report(node);
}
// Check if it's an import specifier
} else if (IMPORT_TYPES.has(parent.type)) {
// Report only if the local imported identifier is invalid
if (
parent.local &&
parent.local.name === node.name &&
isInvalid(name)
) {
report(node);
}
} else if (parent.type === "PropertyDefinition") {
if (checkClassFields && isInvalid(name)) {
report(node);
}
// Report anything that is invalid that isn't a CallExpression
} else if (shouldReport(effectiveParent, name)) {
report(node);
}
},
PrivateIdentifier(node) {
const isClassField = node.parent.type === "PropertyDefinition";
if (isClassField && !checkClassFields) {
return;
}
if (isInvalid(node.name)) {
report(node);
}
},
};
},
};

View File

@@ -0,0 +1,9 @@
import { StructuralSharingOption, ValidateSelected } from './structuralSharing.cjs';
import { AnyRouter, RegisteredRouter, ResolveUseSearch, StrictOrFrom, ThrowConstraint, ThrowOrOptional, UseSearchResult } from '@tanstack/router-core';
export interface UseSearchBaseOptions<TRouter extends AnyRouter, TFrom, TStrict extends boolean, TThrow extends boolean, TSelected, TStructuralSharing> {
select?: (state: ResolveUseSearch<TRouter, TFrom, TStrict>) => ValidateSelected<TRouter, TSelected, TStructuralSharing>;
shouldThrow?: TThrow;
}
export type UseSearchOptions<TRouter extends AnyRouter, TFrom, TStrict extends boolean, TThrow extends boolean, TSelected, TStructuralSharing> = StrictOrFrom<TRouter, TFrom, TStrict> & UseSearchBaseOptions<TRouter, TFrom, TStrict, TThrow, TSelected, TStructuralSharing> & StructuralSharingOption<TRouter, TSelected, TStructuralSharing>;
export type UseSearchRoute<out TFrom> = <TRouter extends AnyRouter = RegisteredRouter, TSelected = unknown, TStructuralSharing extends boolean = boolean>(opts?: UseSearchBaseOptions<TRouter, TFrom, true, true, TSelected, TStructuralSharing> & StructuralSharingOption<TRouter, TSelected, TStructuralSharing>) => UseSearchResult<TRouter, TFrom, true, TSelected>;
export declare function useSearch<TRouter extends AnyRouter = RegisteredRouter, const TFrom extends string | undefined = undefined, TStrict extends boolean = true, TThrow extends boolean = true, TSelected = unknown, TStructuralSharing extends boolean = boolean>(opts: UseSearchOptions<TRouter, TFrom, TStrict, ThrowConstraint<TStrict, TThrow>, TSelected, TStructuralSharing>): ThrowOrOptional<UseSearchResult<TRouter, TFrom, TStrict, TSelected>, TThrow>;

View File

@@ -0,0 +1,140 @@
export type EventBus = import("./event_utils").EventBus;
export type IPDFLinkService = import("./interfaces").IPDFLinkService;
export type PDFLinkServiceOptions = {
/**
* - The application event bus.
*/
eventBus: EventBus;
/**
* - Specifies the `target` attribute
* for external links. Must use one of the values from {LinkTarget}.
* Defaults to using no target.
*/
externalLinkTarget?: number | undefined;
/**
* - Specifies the `rel` attribute for
* external links. Defaults to stripping the referrer.
*/
externalLinkRel?: string | undefined;
/**
* - Ignores the zoom argument,
* thus preserving the current zoom level in the viewer, when navigating
* to internal destinations. The default value is `false`.
*/
ignoreDestinationZoom?: boolean | undefined;
};
export namespace LinkTarget {
let NONE: number;
let SELF: number;
let BLANK: number;
let PARENT: number;
let TOP: number;
}
/**
* @typedef {Object} PDFLinkServiceOptions
* @property {EventBus} eventBus - The application event bus.
* @property {number} [externalLinkTarget] - Specifies the `target` attribute
* for external links. Must use one of the values from {LinkTarget}.
* Defaults to using no target.
* @property {string} [externalLinkRel] - Specifies the `rel` attribute for
* external links. Defaults to stripping the referrer.
* @property {boolean} [ignoreDestinationZoom] - Ignores the zoom argument,
* thus preserving the current zoom level in the viewer, when navigating
* to internal destinations. The default value is `false`.
*/
/**
* Performs navigation functions inside PDF, such as opening specified page,
* or destination.
* @implements {IPDFLinkService}
*/
export class PDFLinkService implements IPDFLinkService {
static "__#59@#isValidExplicitDest"(dest: any): boolean;
/**
* @param {PDFLinkServiceOptions} options
*/
constructor({ eventBus, externalLinkTarget, externalLinkRel, ignoreDestinationZoom, }?: PDFLinkServiceOptions);
externalLinkEnabled: boolean;
eventBus: import("./event_utils").EventBus;
externalLinkTarget: number;
externalLinkRel: string;
_ignoreDestinationZoom: boolean;
baseUrl: any;
pdfDocument: any;
pdfViewer: any;
pdfHistory: any;
setDocument(pdfDocument: any, baseUrl?: null): void;
setViewer(pdfViewer: any): void;
setHistory(pdfHistory: any): void;
/**
* @type {number}
*/
get pagesCount(): number;
/**
* @param {number} value
*/
set page(value: number);
/**
* @type {number}
*/
get page(): number;
/**
* @param {number} value
*/
set rotation(value: number);
/**
* @type {number}
*/
get rotation(): number;
/**
* @type {boolean}
*/
get isInPresentationMode(): boolean;
/**
* This method will, when available, also update the browser history.
*
* @param {string|Array} dest - The named, or explicit, PDF destination.
*/
goToDestination(dest: string | any[]): Promise<void>;
/**
* This method will, when available, also update the browser history.
*
* @param {number|string} val - The page number, or page label.
*/
goToPage(val: number | string): void;
/**
* Adds various attributes (href, title, target, rel) to hyperlinks.
* @param {HTMLAnchorElement} link
* @param {string} url
* @param {boolean} [newWindow]
*/
addLinkAttributes(link: HTMLAnchorElement, url: string, newWindow?: boolean | undefined): void;
/**
* @param {string|Array} dest - The PDF destination object.
* @returns {string} The hyperlink to the PDF object.
*/
getDestinationHash(dest: string | any[]): string;
/**
* Prefix the full url on anchor links to make sure that links are resolved
* relative to the current URL instead of the one defined in <base href>.
* @param {string} anchor - The anchor hash, including the #.
* @returns {string} The hyperlink to the PDF object.
*/
getAnchorUrl(anchor: string): string;
/**
* @param {string} hash
*/
setHash(hash: string): void;
/**
* @param {string} action
*/
executeNamedAction(action: string): void;
/**
* @param {Object} action
*/
executeSetOCGState(action: Object): Promise<void>;
}
/**
* @implements {IPDFLinkService}
*/
export class SimpleLinkService extends PDFLinkService implements IPDFLinkService {
}

View File

@@ -0,0 +1,121 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
exports.get = get;
exports.getDependencies = getDependencies;
exports.list = void 0;
exports.minVersion = minVersion;
var _t = require("@babel/types");
var _helpersGenerated = require("./helpers-generated.js");
const {
cloneNode,
identifier
} = _t;
function deep(obj, path, value) {
try {
const parts = path.split(".");
let last = parts.shift();
while (parts.length > 0) {
obj = obj[last];
last = parts.shift();
}
if (arguments.length > 2) {
obj[last] = value;
} else {
return obj[last];
}
} catch (e) {
e.message += ` (when accessing ${path})`;
throw e;
}
}
function permuteHelperAST(ast, metadata, bindingName, localBindings, getDependency, adjustAst) {
const {
locals,
dependencies,
exportBindingAssignments,
exportName
} = metadata;
const bindings = new Set(localBindings || []);
if (bindingName) bindings.add(bindingName);
for (const [name, paths] of (Object.entries || (o => Object.keys(o).map(k => [k, o[k]])))(locals)) {
let newName = name;
if (bindingName && name === exportName) {
newName = bindingName;
} else {
while (bindings.has(newName)) newName = "_" + newName;
}
if (newName !== name) {
for (const path of paths) {
deep(ast, path, identifier(newName));
}
}
}
for (const [name, paths] of (Object.entries || (o => Object.keys(o).map(k => [k, o[k]])))(dependencies)) {
const ref = typeof getDependency === "function" && getDependency(name) || identifier(name);
for (const path of paths) {
deep(ast, path, cloneNode(ref));
}
}
adjustAst == null || adjustAst(ast, exportName, map => {
exportBindingAssignments.forEach(p => deep(ast, p, map(deep(ast, p))));
});
}
const helperData = Object.create(null);
function loadHelper(name) {
if (!helperData[name]) {
const helper = _helpersGenerated.default[name];
if (!helper) {
throw Object.assign(new ReferenceError(`Unknown helper ${name}`), {
code: "BABEL_HELPER_UNKNOWN",
helper: name
});
}
helperData[name] = {
minVersion: helper.minVersion,
build(getDependency, bindingName, localBindings, adjustAst) {
const ast = helper.ast();
permuteHelperAST(ast, helper.metadata, bindingName, localBindings, getDependency, adjustAst);
return {
nodes: ast.body,
globals: helper.metadata.globals
};
},
getDependencies() {
return Object.keys(helper.metadata.dependencies);
}
};
}
return helperData[name];
}
function get(name, getDependency, bindingName, localBindings, adjustAst) {
{
if (typeof bindingName === "object") {
const id = bindingName;
if ((id == null ? void 0 : id.type) === "Identifier") {
bindingName = id.name;
} else {
bindingName = undefined;
}
}
}
return loadHelper(name).build(getDependency, bindingName, localBindings, adjustAst);
}
function minVersion(name) {
return loadHelper(name).minVersion;
}
function getDependencies(name) {
return loadHelper(name).getDependencies();
}
{
exports.ensure = name => {
loadHelper(name);
};
}
const list = exports.list = Object.keys(_helpersGenerated.default).map(name => name.replace(/^_/, ""));
var _default = exports.default = get;
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1,127 @@
// NOTE: Users of the `experimental` builds of React should add a reference
// to 'react-dom/experimental' in their project. See experimental.d.ts's top comment
// for reference and documentation on how exactly to do it.
export as namespace ReactDOM;
import { Key, ReactNode, ReactPortal } from "react";
export function createPortal(
children: ReactNode,
container: Element | DocumentFragment,
key?: Key | null,
): ReactPortal;
export const version: string;
export function flushSync<R>(fn: () => R): R;
export function unstable_batchedUpdates<A, R>(callback: (a: A) => R, a: A): R;
export function unstable_batchedUpdates<R>(callback: () => R): R;
export interface FormStatusNotPending {
pending: false;
data: null;
method: null;
action: null;
}
export interface FormStatusPending {
pending: true;
data: FormData;
method: string;
action: string | ((formData: FormData) => void | Promise<void>);
}
export type FormStatus = FormStatusPending | FormStatusNotPending;
export function useFormStatus(): FormStatus;
export function useFormState<State>(
action: (state: Awaited<State>) => State | Promise<State>,
initialState: Awaited<State>,
permalink?: string,
): [state: Awaited<State>, dispatch: () => void, isPending: boolean];
export function useFormState<State, Payload>(
action: (state: Awaited<State>, payload: Payload) => State | Promise<State>,
initialState: Awaited<State>,
permalink?: string,
): [state: Awaited<State>, dispatch: (payload: Payload) => void, isPending: boolean];
export function prefetchDNS(href: string): void;
export interface PreconnectOptions {
// Don't create a helper type.
// It would have to be in module scope to be inlined in TS tooltips.
// But then it becomes part of the public API.
// TODO: Upstream to microsoft/TypeScript-DOM-lib-generator -> w3c/webref
// since the spec has a notion of a dedicated type: https://html.spec.whatwg.org/multipage/urls-and-fetching.html#cors-settings-attribute
crossOrigin?: "anonymous" | "use-credentials" | "" | undefined;
}
export function preconnect(href: string, options?: PreconnectOptions): void;
export type PreloadAs =
| "audio"
| "document"
| "embed"
| "fetch"
| "font"
| "image"
| "object"
| "track"
| "script"
| "style"
| "video"
| "worker";
export interface PreloadOptions {
as: PreloadAs;
crossOrigin?: "anonymous" | "use-credentials" | "" | undefined;
fetchPriority?: "high" | "low" | "auto" | undefined;
// TODO: These should only be allowed with `as: 'image'` but it's not trivial to write tests against the full TS support matrix.
imageSizes?: string | undefined;
imageSrcSet?: string | undefined;
integrity?: string | undefined;
type?: string | undefined;
nonce?: string | undefined;
referrerPolicy?: ReferrerPolicy | undefined;
}
export function preload(href: string, options?: PreloadOptions): void;
// https://html.spec.whatwg.org/multipage/links.html#link-type-modulepreload
export type PreloadModuleAs = RequestDestination;
export interface PreloadModuleOptions {
/**
* @default "script"
*/
as: PreloadModuleAs;
crossOrigin?: "anonymous" | "use-credentials" | "" | undefined;
integrity?: string | undefined;
nonce?: string | undefined;
}
export function preloadModule(href: string, options?: PreloadModuleOptions): void;
export type PreinitAs = "script" | "style";
export interface PreinitOptions {
as: PreinitAs;
crossOrigin?: "anonymous" | "use-credentials" | "" | undefined;
fetchPriority?: "high" | "low" | "auto" | undefined;
precedence?: string | undefined;
integrity?: string | undefined;
nonce?: string | undefined;
}
export function preinit(href: string, options?: PreinitOptions): void;
// Will be expanded to include all of https://github.com/tc39/proposal-import-attributes
export type PreinitModuleAs = "script";
export interface PreinitModuleOptions {
/**
* @default "script"
*/
as?: PreinitModuleAs;
crossOrigin?: "anonymous" | "use-credentials" | "" | undefined;
integrity?: string | undefined;
nonce?: string | undefined;
}
export function preinitModule(href: string, options?: PreinitModuleOptions): void;
export function requestFormReset(form: HTMLFormElement): void;

View File

@@ -0,0 +1,15 @@
The ISC License
Copyright (c) 2015, 2019 Elan Shanker, 2021 Blaine Bublitz <blaine.bublitz@gmail.com>, Eric Schoffstall <yo@contra.io> and other contributors
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

View File

@@ -0,0 +1,29 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.traverseNode = traverseNode;
var _context = require("./context.js");
var _t = require("@babel/types");
const {
VISITOR_KEYS
} = _t;
function traverseNode(node, opts, scope, state, path, skipKeys, visitSelf) {
const keys = VISITOR_KEYS[node.type];
if (!keys) return false;
const context = new _context.default(scope, opts, state, path);
if (visitSelf) {
if (skipKeys != null && skipKeys[path.parentKey]) return false;
return context.visitQueue([path]);
}
for (const key of keys) {
if (skipKeys != null && skipKeys[key]) continue;
if (context.visit(node, key)) {
return true;
}
}
return false;
}
//# sourceMappingURL=traverse-node.js.map

View File

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

View File

@@ -0,0 +1,94 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "https://raw.githubusercontent.com/ajv-validator/ajv/master/lib/refs/json-schema-secure.json#",
"title": "Meta-schema for the security assessment of JSON Schemas",
"description": "If a JSON Schema fails validation against this meta-schema, it may be unsafe to validate untrusted data",
"definitions": {
"schemaArray": {
"type": "array",
"minItems": 1,
"items": {"$ref": "#"}
}
},
"dependencies": {
"patternProperties": {
"description": "prevent slow validation of large property names",
"required": ["propertyNames"],
"properties": {
"propertyNames": {
"required": ["maxLength"]
}
}
},
"uniqueItems": {
"description": "prevent slow validation of large non-scalar arrays",
"if": {
"properties": {
"uniqueItems": {"const": true},
"items": {
"properties": {
"type": {
"anyOf": [
{
"enum": ["object", "array"]
},
{
"type": "array",
"contains": {"enum": ["object", "array"]}
}
]
}
}
}
}
},
"then": {
"required": ["maxItems"]
}
},
"pattern": {
"description": "prevent slow pattern matching of large strings",
"required": ["maxLength"]
},
"format": {
"description": "prevent slow format validation of large strings",
"required": ["maxLength"]
}
},
"properties": {
"additionalItems": {"$ref": "#"},
"additionalProperties": {"$ref": "#"},
"dependencies": {
"additionalProperties": {
"anyOf": [
{"type": "array"},
{"$ref": "#"}
]
}
},
"items": {
"anyOf": [
{"$ref": "#"},
{"$ref": "#/definitions/schemaArray"}
]
},
"definitions": {
"additionalProperties": {"$ref": "#"}
},
"patternProperties": {
"additionalProperties": {"$ref": "#"}
},
"properties": {
"additionalProperties": {"$ref": "#"}
},
"if": {"$ref": "#"},
"then": {"$ref": "#"},
"else": {"$ref": "#"},
"allOf": {"$ref": "#/definitions/schemaArray"},
"anyOf": {"$ref": "#/definitions/schemaArray"},
"oneOf": {"$ref": "#/definitions/schemaArray"},
"not": {"$ref": "#"},
"contains": {"$ref": "#"},
"propertyNames": {"$ref": "#"}
}
}

View File

@@ -0,0 +1,24 @@
/**
* @fileoverview Types for the config-array package.
* @author Nicholas C. Zakas
*/
export interface ConfigObject {
/**
* The files to include.
*/
files?: string[];
/**
* The files to exclude.
*/
ignores?: string[];
/**
* The name of the config object.
*/
name?: string;
// may also have any number of other properties
[key: string]: unknown;
}

View File

@@ -0,0 +1,383 @@
/**
* @fileoverview Validates configs.
* @author Brandon Mills
*/
/* eslint class-methods-use-this: "off" -- not needed in this file */
//------------------------------------------------------------------------------
// Typedefs
//------------------------------------------------------------------------------
/** @typedef {import("../shared/types").Rule} Rule */
//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------
import util from "node:util";
import * as ConfigOps from "./config-ops.js";
import { emitDeprecationWarning } from "./deprecation-warnings.js";
import ajvOrig from "./ajv.js";
import { deepMergeArrays } from "./deep-merge-arrays.js";
import configSchema from "../../conf/config-schema.js";
import BuiltInEnvironments from "../../conf/environments.js";
const ajv = ajvOrig();
const ruleValidators = new WeakMap();
const noop = Function.prototype;
//------------------------------------------------------------------------------
// Private
//------------------------------------------------------------------------------
let validateSchema;
const severityMap = {
error: 2,
warn: 1,
off: 0
};
const validated = new WeakSet();
// JSON schema that disallows passing any options
const noOptionsSchema = Object.freeze({
type: "array",
minItems: 0,
maxItems: 0
});
//-----------------------------------------------------------------------------
// Exports
//-----------------------------------------------------------------------------
/**
* Validator for configuration objects.
*/
export default class ConfigValidator {
constructor({ builtInRules = new Map() } = {}) {
this.builtInRules = builtInRules;
}
/**
* Gets a complete options schema for a rule.
* @param {Rule} rule A rule object
* @throws {TypeError} If `meta.schema` is specified but is not an array, object or `false`.
* @returns {Object|null} JSON Schema for the rule's options.
* `null` if rule wasn't passed or its `meta.schema` is `false`.
*/
getRuleOptionsSchema(rule) {
if (!rule) {
return null;
}
if (!rule.meta) {
return { ...noOptionsSchema }; // default if `meta.schema` is not specified
}
const schema = rule.meta.schema;
if (typeof schema === "undefined") {
return { ...noOptionsSchema }; // default if `meta.schema` is not specified
}
// `schema:false` is an allowed explicit opt-out of options validation for the rule
if (schema === false) {
return null;
}
if (typeof schema !== "object" || schema === null) {
throw new TypeError("Rule's `meta.schema` must be an array or object");
}
// ESLint-specific array form needs to be converted into a valid JSON Schema definition
if (Array.isArray(schema)) {
if (schema.length) {
return {
type: "array",
items: schema,
minItems: 0,
maxItems: schema.length
};
}
// `schema:[]` is an explicit way to specify that the rule does not accept any options
return { ...noOptionsSchema };
}
// `schema:<object>` is assumed to be a valid JSON Schema definition
return schema;
}
/**
* Validates a rule's severity and returns the severity value. Throws an error if the severity is invalid.
* @param {options} options The given options for the rule.
* @returns {number|string} The rule's severity value
* @throws {Error} If the severity is invalid.
*/
validateRuleSeverity(options) {
const severity = Array.isArray(options) ? options[0] : options;
const normSeverity = typeof severity === "string" ? severityMap[severity.toLowerCase()] : severity;
if (normSeverity === 0 || normSeverity === 1 || normSeverity === 2) {
return normSeverity;
}
throw new Error(`\tSeverity should be one of the following: 0 = off, 1 = warn, 2 = error (you passed '${util.inspect(severity).replace(/'/gu, "\"").replace(/\n/gu, "")}').\n`);
}
/**
* Validates the non-severity options passed to a rule, based on its schema.
* @param {{create: Function}} rule The rule to validate
* @param {Array} localOptions The options for the rule, excluding severity
* @returns {void}
* @throws {Error} If the options are invalid.
*/
validateRuleSchema(rule, localOptions) {
if (!ruleValidators.has(rule)) {
try {
const schema = this.getRuleOptionsSchema(rule);
if (schema) {
ruleValidators.set(rule, ajv.compile(schema));
}
} catch (err) {
const errorWithCode = new Error(err.message, { cause: err });
errorWithCode.code = "ESLINT_INVALID_RULE_OPTIONS_SCHEMA";
throw errorWithCode;
}
}
const validateRule = ruleValidators.get(rule);
if (validateRule) {
const mergedOptions = deepMergeArrays(rule.meta?.defaultOptions, localOptions);
validateRule(mergedOptions);
if (validateRule.errors) {
throw new Error(validateRule.errors.map(
error => `\tValue ${JSON.stringify(error.data)} ${error.message}.\n`
).join(""));
}
}
}
/**
* Validates a rule's options against its schema.
* @param {{create: Function}|null} rule The rule that the config is being validated for
* @param {string} ruleId The rule's unique name.
* @param {Array|number} options The given options for the rule.
* @param {string|null} source The name of the configuration source to report in any errors. If null or undefined,
* no source is prepended to the message.
* @returns {void}
* @throws {Error} If the options are invalid.
*/
validateRuleOptions(rule, ruleId, options, source = null) {
try {
const severity = this.validateRuleSeverity(options);
if (severity !== 0) {
this.validateRuleSchema(rule, Array.isArray(options) ? options.slice(1) : []);
}
} catch (err) {
let enhancedMessage = err.code === "ESLINT_INVALID_RULE_OPTIONS_SCHEMA"
? `Error while processing options validation schema of rule '${ruleId}': ${err.message}`
: `Configuration for rule "${ruleId}" is invalid:\n${err.message}`;
if (typeof source === "string") {
enhancedMessage = `${source}:\n\t${enhancedMessage}`;
}
const enhancedError = new Error(enhancedMessage, { cause: err });
if (err.code) {
enhancedError.code = err.code;
}
throw enhancedError;
}
}
/**
* Validates an environment object
* @param {Object} environment The environment config object to validate.
* @param {string} source The name of the configuration source to report in any errors.
* @param {(envId:string) => Object} [getAdditionalEnv] A map from strings to loaded environments.
* @returns {void}
* @throws {Error} If the environment is invalid.
*/
validateEnvironment(
environment,
source,
getAdditionalEnv = noop
) {
// not having an environment is ok
if (!environment) {
return;
}
Object.keys(environment).forEach(id => {
const env = getAdditionalEnv(id) || BuiltInEnvironments.get(id) || null;
if (!env) {
const message = `${source}:\n\tEnvironment key "${id}" is unknown\n`;
throw new Error(message);
}
});
}
/**
* Validates a rules config object
* @param {Object} rulesConfig The rules config object to validate.
* @param {string} source The name of the configuration source to report in any errors.
* @param {(ruleId:string) => Object} getAdditionalRule A map from strings to loaded rules
* @returns {void}
*/
validateRules(
rulesConfig,
source,
getAdditionalRule = noop
) {
if (!rulesConfig) {
return;
}
Object.keys(rulesConfig).forEach(id => {
const rule = getAdditionalRule(id) || this.builtInRules.get(id) || null;
this.validateRuleOptions(rule, id, rulesConfig[id], source);
});
}
/**
* Validates a `globals` section of a config file
* @param {Object} globalsConfig The `globals` section
* @param {string|null} source The name of the configuration source to report in the event of an error.
* @returns {void}
*/
validateGlobals(globalsConfig, source = null) {
if (!globalsConfig) {
return;
}
Object.entries(globalsConfig)
.forEach(([configuredGlobal, configuredValue]) => {
try {
ConfigOps.normalizeConfigGlobal(configuredValue);
} catch (err) {
throw new Error(`ESLint configuration of global '${configuredGlobal}' in ${source} is invalid:\n${err.message}`);
}
});
}
/**
* Validate `processor` configuration.
* @param {string|undefined} processorName The processor name.
* @param {string} source The name of config file.
* @param {(id:string) => Processor} getProcessor The getter of defined processors.
* @returns {void}
* @throws {Error} If the processor is invalid.
*/
validateProcessor(processorName, source, getProcessor) {
if (processorName && !getProcessor(processorName)) {
throw new Error(`ESLint configuration of processor in '${source}' is invalid: '${processorName}' was not found.`);
}
}
/**
* Formats an array of schema validation errors.
* @param {Array} errors An array of error messages to format.
* @returns {string} Formatted error message
*/
formatErrors(errors) {
return errors.map(error => {
if (error.keyword === "additionalProperties") {
const formattedPropertyPath = error.dataPath.length ? `${error.dataPath.slice(1)}.${error.params.additionalProperty}` : error.params.additionalProperty;
return `Unexpected top-level property "${formattedPropertyPath}"`;
}
if (error.keyword === "type") {
const formattedField = error.dataPath.slice(1);
const formattedExpectedType = Array.isArray(error.schema) ? error.schema.join("/") : error.schema;
const formattedValue = JSON.stringify(error.data);
return `Property "${formattedField}" is the wrong type (expected ${formattedExpectedType} but got \`${formattedValue}\`)`;
}
const field = error.dataPath[0] === "." ? error.dataPath.slice(1) : error.dataPath;
return `"${field}" ${error.message}. Value: ${JSON.stringify(error.data)}`;
}).map(message => `\t- ${message}.\n`).join("");
}
/**
* Validates the top level properties of the config object.
* @param {Object} config The config object to validate.
* @param {string} source The name of the configuration source to report in any errors.
* @returns {void}
* @throws {Error} If the config is invalid.
*/
validateConfigSchema(config, source = null) {
validateSchema = validateSchema || ajv.compile(configSchema);
if (!validateSchema(config)) {
throw new Error(`ESLint configuration in ${source} is invalid:\n${this.formatErrors(validateSchema.errors)}`);
}
if (Object.hasOwn(config, "ecmaFeatures")) {
emitDeprecationWarning(source, "ESLINT_LEGACY_ECMAFEATURES");
}
}
/**
* Validates an entire config object.
* @param {Object} config The config object to validate.
* @param {string} source The name of the configuration source to report in any errors.
* @param {(ruleId:string) => Object} [getAdditionalRule] A map from strings to loaded rules.
* @param {(envId:string) => Object} [getAdditionalEnv] A map from strings to loaded envs.
* @returns {void}
*/
validate(config, source, getAdditionalRule, getAdditionalEnv) {
this.validateConfigSchema(config, source);
this.validateRules(config.rules, source, getAdditionalRule);
this.validateEnvironment(config.env, source, getAdditionalEnv);
this.validateGlobals(config.globals, source);
for (const override of config.overrides || []) {
this.validateRules(override.rules, source, getAdditionalRule);
this.validateEnvironment(override.env, source, getAdditionalEnv);
this.validateGlobals(config.globals, source);
}
}
/**
* Validate config array object.
* @param {ConfigArray} configArray The config array to validate.
* @returns {void}
*/
validateConfigArray(configArray) {
const getPluginEnv = Map.prototype.get.bind(configArray.pluginEnvironments);
const getPluginProcessor = Map.prototype.get.bind(configArray.pluginProcessors);
const getPluginRule = Map.prototype.get.bind(configArray.pluginRules);
// Validate.
for (const element of configArray) {
if (validated.has(element)) {
continue;
}
validated.add(element);
this.validateEnvironment(element.env, element.name, getPluginEnv);
this.validateGlobals(element.globals, element.name);
this.validateProcessor(element.processor, element.name, getPluginProcessor);
this.validateRules(element.rules, element.name, getPluginRule);
}
}
}

View File

@@ -0,0 +1,15 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = _instanceof;
function _instanceof(left, right) {
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
return !!right[Symbol.hasInstance](left);
} else {
return left instanceof right;
}
}
//# sourceMappingURL=instanceof.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"root.js","sources":["../../src/root.ts"],"sourcesContent":["export const rootRouteId = '__root__'\nexport type RootRouteId = typeof rootRouteId\n"],"names":[],"mappings":"AAAO,MAAM,cAAc;"}

View File

@@ -0,0 +1,11 @@
'use strict'
let Stringifier = require('./stringifier')
function stringify(node, builder) {
let str = new Stringifier(builder)
str.stringify(node)
}
module.exports = stringify
stringify.default = stringify

View File

@@ -0,0 +1,205 @@
/**
* @fileoverview Rule to validate spacing before function paren.
* @author Mathias Schreck <https://github.com/lo1tuma>
* @deprecated in ESLint v8.53.0
*/
"use strict";
//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------
const astUtils = require("./utils/ast-utils");
//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------
/** @type {import('../shared/types').Rule} */
module.exports = {
meta: {
deprecated: {
message: "Formatting rules are being moved out of ESLint core.",
url: "https://eslint.org/blog/2023/10/deprecating-formatting-rules/",
deprecatedSince: "8.53.0",
availableUntil: "10.0.0",
replacedBy: [
{
message:
"ESLint Stylistic now maintains deprecated stylistic core rules.",
url: "https://eslint.style/guide/migration",
plugin: {
name: "@stylistic/eslint-plugin-js",
url: "https://eslint.style/packages/js",
},
rule: {
name: "space-before-function-paren",
url: "https://eslint.style/rules/js/space-before-function-paren",
},
},
],
},
type: "layout",
docs: {
description:
"Enforce consistent spacing before `function` definition opening parenthesis",
recommended: false,
url: "https://eslint.org/docs/latest/rules/space-before-function-paren",
},
fixable: "whitespace",
schema: [
{
oneOf: [
{
enum: ["always", "never"],
},
{
type: "object",
properties: {
anonymous: {
enum: ["always", "never", "ignore"],
},
named: {
enum: ["always", "never", "ignore"],
},
asyncArrow: {
enum: ["always", "never", "ignore"],
},
},
additionalProperties: false,
},
],
},
],
messages: {
unexpectedSpace: "Unexpected space before function parentheses.",
missingSpace: "Missing space before function parentheses.",
},
},
create(context) {
const sourceCode = context.sourceCode;
const baseConfig =
typeof context.options[0] === "string"
? context.options[0]
: "always";
const overrideConfig =
typeof context.options[0] === "object" ? context.options[0] : {};
/**
* Determines whether a function has a name.
* @param {ASTNode} node The function node.
* @returns {boolean} Whether the function has a name.
*/
function isNamedFunction(node) {
if (node.id) {
return true;
}
const parent = node.parent;
return (
parent.type === "MethodDefinition" ||
(parent.type === "Property" &&
(parent.kind === "get" ||
parent.kind === "set" ||
parent.method))
);
}
/**
* Gets the config for a given function
* @param {ASTNode} node The function node
* @returns {string} "always", "never", or "ignore"
*/
function getConfigForFunction(node) {
if (node.type === "ArrowFunctionExpression") {
// Always ignore non-async functions and arrow functions without parens, e.g. async foo => bar
if (
node.async &&
astUtils.isOpeningParenToken(
sourceCode.getFirstToken(node, { skip: 1 }),
)
) {
return overrideConfig.asyncArrow || baseConfig;
}
} else if (isNamedFunction(node)) {
return overrideConfig.named || baseConfig;
// `generator-star-spacing` should warn anonymous generators. E.g. `function* () {}`
} else if (!node.generator) {
return overrideConfig.anonymous || baseConfig;
}
return "ignore";
}
/**
* Checks the parens of a function node
* @param {ASTNode} node A function node
* @returns {void}
*/
function checkFunction(node) {
const functionConfig = getConfigForFunction(node);
if (functionConfig === "ignore") {
return;
}
const rightToken = sourceCode.getFirstToken(
node,
astUtils.isOpeningParenToken,
);
const leftToken = sourceCode.getTokenBefore(rightToken);
const hasSpacing = sourceCode.isSpaceBetweenTokens(
leftToken,
rightToken,
);
if (hasSpacing && functionConfig === "never") {
context.report({
node,
loc: {
start: leftToken.loc.end,
end: rightToken.loc.start,
},
messageId: "unexpectedSpace",
fix(fixer) {
const comments =
sourceCode.getCommentsBefore(rightToken);
// Don't fix anything if there's a single line comment between the left and the right token
if (comments.some(comment => comment.type === "Line")) {
return null;
}
return fixer.replaceTextRange(
[leftToken.range[1], rightToken.range[0]],
comments.reduce(
(text, comment) =>
text + sourceCode.getText(comment),
"",
),
);
},
});
} else if (!hasSpacing && functionConfig === "always") {
context.report({
node,
loc: rightToken.loc,
messageId: "missingSpace",
fix: fixer => fixer.insertTextAfter(leftToken, " "),
});
}
}
return {
ArrowFunctionExpression: checkFunction,
FunctionDeclaration: checkFunction,
FunctionExpression: checkFunction,
};
},
};

View File

@@ -0,0 +1,70 @@
'use strict'
let pico = require('picocolors')
let tokenizer = require('./tokenize')
let Input
function registerInput(dependant) {
Input = dependant
}
const HIGHLIGHT_THEME = {
';': pico.yellow,
':': pico.yellow,
'(': pico.cyan,
')': pico.cyan,
'[': pico.yellow,
']': pico.yellow,
'{': pico.yellow,
'}': pico.yellow,
'at-word': pico.cyan,
'brackets': pico.cyan,
'call': pico.cyan,
'class': pico.yellow,
'comment': pico.gray,
'hash': pico.magenta,
'string': pico.green
}
function getTokenType([type, value], processor) {
if (type === 'word') {
if (value[0] === '.') {
return 'class'
}
if (value[0] === '#') {
return 'hash'
}
}
if (!processor.endOfFile()) {
let next = processor.nextToken()
processor.back(next)
if (next[0] === 'brackets' || next[0] === '(') return 'call'
}
return type
}
function terminalHighlight(css) {
let processor = tokenizer(new Input(css), { ignoreErrors: true })
let result = ''
while (!processor.endOfFile()) {
let token = processor.nextToken()
let color = HIGHLIGHT_THEME[getTokenType(token, processor)]
if (color) {
result += token[1]
.split(/\r?\n/)
.map(i => color(i))
.join('\n')
} else {
result += token[1]
}
}
return result
}
terminalHighlight.registerInput = registerInput
module.exports = terminalHighlight

View File

@@ -0,0 +1,352 @@
#include "register_font.h"
#include <pango/pangocairo.h>
#include <pango/pango-fontmap.h>
#include <pango/pango.h>
#ifdef __APPLE__
#include <CoreText/CoreText.h>
#elif defined(_WIN32)
#include <windows.h>
#include <memory>
#else
#include <fontconfig/fontconfig.h>
#endif
#include <ft2build.h>
#include FT_FREETYPE_H
#include FT_TRUETYPE_TABLES_H
#include FT_SFNT_NAMES_H
#include FT_TRUETYPE_IDS_H
#ifndef FT_SFNT_OS2
#define FT_SFNT_OS2 ft_sfnt_os2
#endif
// OSX seems to read the strings in MacRoman encoding and ignore Unicode entries.
// You can verify this by opening a TTF with both Unicode and Macroman on OSX.
// It uses the MacRoman name, while Fontconfig and Windows use Unicode
#ifdef __APPLE__
#define PREFERRED_PLATFORM_ID TT_PLATFORM_MACINTOSH
#define PREFERRED_ENCODING_ID TT_MAC_ID_ROMAN
#else
#define PREFERRED_PLATFORM_ID TT_PLATFORM_MICROSOFT
#define PREFERRED_ENCODING_ID TT_MS_ID_UNICODE_CS
#endif
#define IS_PREFERRED_ENC(X) \
X.platform_id == PREFERRED_PLATFORM_ID && X.encoding_id == PREFERRED_ENCODING_ID
#define GET_NAME_RANK(X) \
(IS_PREFERRED_ENC(X) ? 1 : 0) + (X.name_id == TT_NAME_ID_PREFERRED_FAMILY ? 1 : 0)
/*
* Return a UTF-8 encoded string given a TrueType name buf+len
* and its platform and encoding
*/
char *
to_utf8(FT_Byte* buf, FT_UInt len, FT_UShort pid, FT_UShort eid) {
size_t ret_len = len * 4; // max chars in a utf8 string
char *ret = (char*)malloc(ret_len + 1); // utf8 string + null
if (!ret) return NULL;
// In my testing of hundreds of fonts from the Google Font repo, the two types
// of fonts are TT_PLATFORM_MICROSOFT with TT_MS_ID_UNICODE_CS encoding, or
// TT_PLATFORM_MACINTOSH with TT_MAC_ID_ROMAN encoding. Usually both, never neither
char const *fromcode;
if (pid == TT_PLATFORM_MACINTOSH && eid == TT_MAC_ID_ROMAN) {
fromcode = "MAC";
} else if (pid == TT_PLATFORM_MICROSOFT && eid == TT_MS_ID_UNICODE_CS) {
fromcode = "UTF-16BE";
} else {
free(ret);
return NULL;
}
GIConv cd = g_iconv_open("UTF-8", fromcode);
if (cd == (GIConv)-1) {
free(ret);
return NULL;
}
size_t inbytesleft = len;
size_t outbytesleft = ret_len;
size_t n_converted = g_iconv(cd, (char**)&buf, &inbytesleft, &ret, &outbytesleft);
ret -= ret_len - outbytesleft; // rewind the pointers to their
buf -= len - inbytesleft; // original starting positions
if (n_converted == (size_t)-1) {
free(ret);
return NULL;
} else {
ret[ret_len - outbytesleft] = '\0';
return ret;
}
}
/*
* Find a family name in the face's name table, preferring the one the
* system, fall back to the other
*/
char *
get_family_name(FT_Face face) {
FT_SfntName name;
int best_rank = -1;
char* best_buf = NULL;
for (unsigned i = 0; i < FT_Get_Sfnt_Name_Count(face); ++i) {
FT_Get_Sfnt_Name(face, i, &name);
if (name.name_id == TT_NAME_ID_FONT_FAMILY || name.name_id == TT_NAME_ID_PREFERRED_FAMILY) {
char *buf = to_utf8(name.string, name.string_len, name.platform_id, name.encoding_id);
if (buf) {
int rank = GET_NAME_RANK(name);
if (rank > best_rank) {
best_rank = rank;
if (best_buf) free(best_buf);
best_buf = buf;
} else {
free(buf);
}
}
}
}
return best_buf;
}
PangoWeight
get_pango_weight(FT_UShort weight) {
switch (weight) {
case 100: return PANGO_WEIGHT_THIN;
case 200: return PANGO_WEIGHT_ULTRALIGHT;
case 300: return PANGO_WEIGHT_LIGHT;
#if PANGO_VERSION >= PANGO_VERSION_ENCODE(1, 36, 7)
case 350: return PANGO_WEIGHT_SEMILIGHT;
#endif
case 380: return PANGO_WEIGHT_BOOK;
case 400: return PANGO_WEIGHT_NORMAL;
case 500: return PANGO_WEIGHT_MEDIUM;
case 600: return PANGO_WEIGHT_SEMIBOLD;
case 700: return PANGO_WEIGHT_BOLD;
case 800: return PANGO_WEIGHT_ULTRABOLD;
case 900: return PANGO_WEIGHT_HEAVY;
case 1000: return PANGO_WEIGHT_ULTRAHEAVY;
default: return PANGO_WEIGHT_NORMAL;
}
}
PangoStretch
get_pango_stretch(FT_UShort width) {
switch (width) {
case 1: return PANGO_STRETCH_ULTRA_CONDENSED;
case 2: return PANGO_STRETCH_EXTRA_CONDENSED;
case 3: return PANGO_STRETCH_CONDENSED;
case 4: return PANGO_STRETCH_SEMI_CONDENSED;
case 5: return PANGO_STRETCH_NORMAL;
case 6: return PANGO_STRETCH_SEMI_EXPANDED;
case 7: return PANGO_STRETCH_EXPANDED;
case 8: return PANGO_STRETCH_EXTRA_EXPANDED;
case 9: return PANGO_STRETCH_ULTRA_EXPANDED;
default: return PANGO_STRETCH_NORMAL;
}
}
PangoStyle
get_pango_style(FT_Long flags) {
if (flags & FT_STYLE_FLAG_ITALIC) {
return PANGO_STYLE_ITALIC;
} else {
return PANGO_STYLE_NORMAL;
}
}
#ifdef _WIN32
std::unique_ptr<wchar_t[]>
u8ToWide(const char* str) {
int iBufferSize = MultiByteToWideChar(CP_UTF8, 0, str, -1, (wchar_t*)NULL, 0);
if(!iBufferSize){
return nullptr;
}
std::unique_ptr<wchar_t[]> wpBufWString = std::unique_ptr<wchar_t[]>{ new wchar_t[static_cast<size_t>(iBufferSize)] };
if(!MultiByteToWideChar(CP_UTF8, 0, str, -1, wpBufWString.get(), iBufferSize)){
return nullptr;
}
return wpBufWString;
}
static unsigned long
stream_read_func(FT_Stream stream, unsigned long offset, unsigned char* buffer, unsigned long count){
HANDLE hFile = reinterpret_cast<HANDLE>(stream->descriptor.pointer);
DWORD numberOfBytesRead;
OVERLAPPED overlapped;
overlapped.Offset = offset;
overlapped.OffsetHigh = 0;
overlapped.hEvent = NULL;
if(!ReadFile(hFile, buffer, count, &numberOfBytesRead, &overlapped)){
return 0;
}
return numberOfBytesRead;
};
static void
stream_close_func(FT_Stream stream){
HANDLE hFile = reinterpret_cast<HANDLE>(stream->descriptor.pointer);
CloseHandle(hFile);
}
#endif
/*
* Return a PangoFontDescription that will resolve to the font file
*/
PangoFontDescription *
get_pango_font_description(unsigned char* filepath) {
FT_Library library;
FT_Face face;
PangoFontDescription *desc = pango_font_description_new();
#ifdef _WIN32
// FT_New_Face use fopen.
// Unable to find the file when supplied the multibyte string path on the Windows platform and throw error "Could not parse font file".
// This workaround fixes this by reading the font file uses win32 wide character API.
std::unique_ptr<wchar_t[]> wFilepath = u8ToWide((char*)filepath);
if(!wFilepath){
return NULL;
}
HANDLE hFile = CreateFileW(
wFilepath.get(),
GENERIC_READ,
FILE_SHARE_READ,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL
);
if(!hFile){
return NULL;
}
LARGE_INTEGER liSize;
if(!GetFileSizeEx(hFile, &liSize)) {
CloseHandle(hFile);
return NULL;
}
FT_Open_Args args;
args.flags = FT_OPEN_STREAM;
FT_StreamRec stream;
stream.base = NULL;
stream.size = liSize.QuadPart;
stream.pos = 0;
stream.descriptor.pointer = hFile;
stream.read = stream_read_func;
stream.close = stream_close_func;
args.stream = &stream;
if (
!FT_Init_FreeType(&library) &&
!FT_Open_Face(library, &args, 0, &face)) {
#else
if (!FT_Init_FreeType(&library) && !FT_New_Face(library, (const char*)filepath, 0, &face)) {
#endif
TT_OS2 *table = (TT_OS2*)FT_Get_Sfnt_Table(face, FT_SFNT_OS2);
if (table) {
char *family = get_family_name(face);
if (!family) {
pango_font_description_free(desc);
FT_Done_Face(face);
FT_Done_FreeType(library);
return NULL;
}
pango_font_description_set_family(desc, family);
free(family);
pango_font_description_set_weight(desc, get_pango_weight(table->usWeightClass));
pango_font_description_set_stretch(desc, get_pango_stretch(table->usWidthClass));
pango_font_description_set_style(desc, get_pango_style(face->style_flags));
FT_Done_Face(face);
FT_Done_FreeType(library);
return desc;
}
}
pango_font_description_free(desc);
return NULL;
}
/*
* Register font with the OS
*/
bool
register_font(unsigned char *filepath) {
bool success;
#ifdef __APPLE__
CFURLRef filepathUrl = CFURLCreateFromFileSystemRepresentation(NULL, filepath, strlen((char*)filepath), false);
success = CTFontManagerRegisterFontsForURL(filepathUrl, kCTFontManagerScopeProcess, NULL);
#elif defined(_WIN32)
std::unique_ptr<wchar_t[]> wFilepath = u8ToWide((char*)filepath);
if(wFilepath){
success = AddFontResourceExW(wFilepath.get(), FR_PRIVATE, 0) != 0;
}else{
success = false;
}
#else
success = FcConfigAppFontAddFile(FcConfigGetCurrent(), (FcChar8 *)(filepath));
#endif
if (!success) return false;
// Tell Pango to throw away the current FontMap and create a new one. This
// has the effect of registering the new font in Pango by re-looking up all
// font families.
pango_cairo_font_map_set_default(NULL);
return true;
}
/*
* Deregister font from the OS
* Note that Linux (FontConfig) can only dereregister ALL fonts at once.
*/
bool
deregister_font(unsigned char *filepath) {
bool success;
#ifdef __APPLE__
CFURLRef filepathUrl = CFURLCreateFromFileSystemRepresentation(NULL, filepath, strlen((char*)filepath), false);
success = CTFontManagerUnregisterFontsForURL(filepathUrl, kCTFontManagerScopeProcess, NULL);
#elif defined(_WIN32)
std::unique_ptr<wchar_t[]> wFilepath = u8ToWide((char*)filepath);
if(wFilepath){
success = RemoveFontResourceExW(wFilepath.get(), FR_PRIVATE, 0) != 0;
}else{
success = false;
}
#else
FcConfigAppFontClear(FcConfigGetCurrent());
success = true;
#endif
if (!success) return false;
// Tell Pango to throw away the current FontMap and create a new one. This
// has the effect of deregistering the font in Pango by re-looking up all
// font families.
pango_cairo_font_map_set_default(NULL);
return true;
}

View File

@@ -0,0 +1 @@
module.exports={A:{A:{"2":"K D E F A B mC"},B:{"1":"0 9 Q H R S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z AB BB CB DB EB FB GB HB IB JB KB LB MB NB OB I","2":"C L M G N O P"},C:{"2":"1 2 3 4 5 6 7 8 nC LC J PB K D E F A B C L M G N O P QB RB SB TB UB VB WB XB YB ZB aB bB cB dB eB fB qC rC","260":"0 9 gB hB iB jB kB lB mB nB oB pB qB rB sB tB uB vB MC wB NC xB yB zB 0B 1B 2B 3B 4B 5B 6B 7B 8B 9B AC BC CC DC Q H R 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"},D:{"1":"0 9 xB yB zB 0B 1B 2B 3B 4B 5B 6B 7B 8B 9B AC BC CC DC Q H R S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z AB BB CB DB EB FB GB HB IB JB KB LB MB NB OB I PC EC QC RC","2":"1 2 3 4 5 6 7 8 J PB K D E F A B C L M G N O P QB RB SB TB UB VB WB XB YB ZB aB bB cB dB eB fB gB hB iB jB kB lB mB nB","324":"oB pB qB rB sB tB uB vB MC wB NC"},E:{"2":"J PB K D E F A sC SC tC uC vC wC TC","132":"B C L M G 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:{"1":"0 lB mB nB oB pB qB rB sB tB uB vB wB xB yB zB 0B 1B 2B 3B 4B 5B 6B 7B 8B 9B AC BC CC DC Q H R OC S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z","2":"1 2 3 4 5 6 7 8 F B C G N O P QB RB SB TB UB VB WB XB YB 4C 5C 6C 7C FC kC 8C GC","324":"ZB aB bB cB dB eB fB gB hB iB jB kB"},G:{"2":"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:{"2":"WD"},I:{"1":"I","2":"LC J XD YD ZD aD lC bD cD"},J:{"2":"D A"},K:{"1":"H","2":"A B C FC kC GC"},L:{"1":"I"},M:{"260":"EC"},N:{"2":"A B"},O:{"1":"HC"},P:{"1":"1 2 3 4 5 6 7 8 gD hD TC iD jD kD lD mD IC JC KC nD","2":"J","132":"dD eD fD"},Q:{"1":"oD"},R:{"1":"pD"},S:{"260":"qD rD"}},B:5,C:"Media Capture from DOM Elements API",D:true};

View File

@@ -0,0 +1,133 @@
/**
* @fileoverview The FileContext class.
* @author Nicholas C. Zakas
*/
"use strict";
/**
* Represents a file context that the linter can use to lint a file.
*/
class FileContext {
/**
* The current working directory.
* @type {string}
*/
cwd;
/**
* The filename of the file being linted.
* @type {string}
*/
filename;
/**
* The physical filename of the file being linted.
* @type {string}
*/
physicalFilename;
/**
* The source code of the file being linted.
* @type {SourceCode}
*/
sourceCode;
/**
* The parser options for the file being linted.
* @type {Record<string, unknown>}
* @deprecated Use `languageOptions` instead.
*/
parserOptions;
/**
* The path to the parser used to parse this file.
* @type {string}
* @deprecated No longer supported.
*/
parserPath;
/**
* The language options used when parsing this file.
* @type {Record<string, unknown>}
*/
languageOptions;
/**
* The settings for the file being linted.
* @type {Record<string, unknown>}
*/
settings;
/**
* Creates a new instance.
* @param {Object} config The configuration object for the file context.
* @param {string} config.cwd The current working directory.
* @param {string} config.filename The filename of the file being linted.
* @param {string} config.physicalFilename The physical filename of the file being linted.
* @param {SourceCode} config.sourceCode The source code of the file being linted.
* @param {Record<string, unknown>} config.parserOptions The parser options for the file being linted.
* @param {string} config.parserPath The path to the parser used to parse this file.
* @param {Record<string, unknown>} config.languageOptions The language options used when parsing this file.
* @param {Record<string, unknown>} config.settings The settings for the file being linted.
*/
constructor({
cwd,
filename,
physicalFilename,
sourceCode,
parserOptions,
parserPath,
languageOptions,
settings,
}) {
this.cwd = cwd;
this.filename = filename;
this.physicalFilename = physicalFilename;
this.sourceCode = sourceCode;
this.parserOptions = parserOptions;
this.parserPath = parserPath;
this.languageOptions = languageOptions;
this.settings = settings;
Object.freeze(this);
}
/**
* Gets the current working directory.
* @returns {string} The current working directory.
* @deprecated Use `cwd` instead.
*/
getCwd() {
return this.cwd;
}
/**
* Gets the filename of the file being linted.
* @returns {string} The filename of the file being linted.
* @deprecated Use `filename` instead.
*/
getFilename() {
return this.filename;
}
/**
* Gets the physical filename of the file being linted.
* @returns {string} The physical filename of the file being linted.
* @deprecated Use `physicalFilename` instead.
*/
getPhysicalFilename() {
return this.physicalFilename;
}
/**
* Gets the source code of the file being linted.
* @returns {SourceCode} The source code of the file being linted.
* @deprecated Use `sourceCode` instead.
*/
getSourceCode() {
return this.sourceCode;
}
}
exports.FileContext = FileContext;

View File

@@ -0,0 +1,809 @@
/**
* @fileoverview Shared types for ESLint Core.
*/
import { JSONSchema4 } from "json-schema";
/**
* Represents an error inside of a file.
*/
export interface FileError {
message: string;
line: number;
column: number;
endLine?: number;
endColumn?: number;
}
/**
* Represents a problem found in a file.
*/
export interface FileProblem {
ruleId: string | null;
message: string;
loc: SourceLocation;
}
/**
* Represents the start and end coordinates of a node inside the source.
*/
export interface SourceLocation {
start: Position;
end: Position;
}
/**
* Represents the start and end coordinates of a node inside the source with an offset.
*/
export interface SourceLocationWithOffset {
start: PositionWithOffset;
end: PositionWithOffset;
}
/**
* Represents a location coordinate inside the source. ESLint-style formats
* have just `line` and `column` while others may have `offset` as well.
*/
export interface Position {
line: number;
column: number;
}
/**
* Represents a location coordinate inside the source with an offset.
*/
export interface PositionWithOffset extends Position {
offset: number;
}
/**
* Represents a range of characters in the source.
*/
export type SourceRange = [number, number];
/**
* What the rule is responsible for finding:
* - `problem` means the rule has noticed a potential error.
* - `suggestion` means the rule suggests an alternate or better approach.
* - `layout` means the rule is looking at spacing, indentation, etc.
*/
export type RuleType = "problem" | "suggestion" | "layout";
/**
* The type of fix the rule can provide:
* - `code` means the rule can fix syntax.
* - `whitespace` means the rule can fix spacing and indentation.
*/
export type RuleFixType = "code" | "whitespace";
/**
* An object containing visitor information for a rule. Each method is either the
* name of a node type or a selector, or is a method that will be called at specific
* times during the traversal.
*/
export type RuleVisitor = Record<string, ((...args: any[]) => void) | undefined>;
/**
* Rule meta information used for documentation.
*/
export interface RulesMetaDocs {
/**
* A short description of the rule.
*/
description?: string | undefined;
/**
* The URL to the documentation for the rule.
*/
url?: string | undefined;
/**
* The category the rule falls under.
* @deprecated No longer used.
*/
category?: string | undefined;
/**
* Indicates if the rule is generally recommended for all users.
*/
recommended?: boolean | undefined;
/**
* Indicates if the rule is frozen (no longer accepting feature requests).
*/
frozen?: boolean | undefined;
}
/**
* Meta information about a rule.
*/
export interface RulesMeta<MessageIds extends string = string, ExtRuleDocs = unknown> {
/**
* Properties that are used when documenting the rule.
*/
docs?: (RulesMetaDocs & ExtRuleDocs) | undefined;
/**
* The type of rule.
*/
type?: RuleType | undefined;
/**
* The schema for the rule options. Required if the rule has options.
*/
schema?: JSONSchema4 | JSONSchema4[] | false | undefined;
/** Any default options to be recursively merged on top of any user-provided options. */
defaultOptions?: unknown[];
/**
* The messages that the rule can report.
*/
messages?: Record<MessageIds, string>;
/**
* Indicates whether the rule has been deprecated or provides additional metadata about the deprecation. Omit if not deprecated.
*/
deprecated?: boolean | DeprecatedInfo | undefined;
/**
* @deprecated Use deprecated.replacedBy instead.
* The name of the rule(s) this rule was replaced by, if it was deprecated.
*/
replacedBy?: readonly string[] | undefined;
/**
* Indicates if the rule is fixable, and if so, what type of fix it provides.
*/
fixable?: RuleFixType | undefined;
/**
* Indicates if the rule may provide suggestions.
*/
hasSuggestions?: boolean | undefined;
/**
* The language the rule is intended to lint.
*/
language?: string;
/**
* The dialects of `language` that the rule is intended to lint.
*/
dialects?: string[];
}
/**
* Provides additional metadata about a deprecation.
*/
export interface DeprecatedInfo {
/**
* General message presented to the user, e.g. for the key rule why the rule
* is deprecated or for info how to replace the rule.
*/
message?: string;
/**
* URL to more information about this deprecation in general.
*/
url?: string;
/**
* An empty array explicitly states that there is no replacement.
*/
replacedBy?: ReplacedByInfo[];
/**
* The package version since when the rule is deprecated (should use full
* semver without a leading "v").
*/
deprecatedSince?: string;
/**
* The estimated version when the rule is removed (probably the next major
* version). null means the rule is "frozen" (will be available but will not
* be changed).
*/
availableUntil?: string | null;
}
/**
* Provides metadata about a replacement
*/
export interface ReplacedByInfo {
/**
* General message presented to the user, e.g. how to replace the rule
*/
message?: string;
/**
* URL to more information about this replacement in general
*/
url?: string;
/**
* Name should be "eslint" if the replacement is an ESLint core rule. Omit
* the property if the replacement is in the same plugin.
*/
plugin?: ExternalSpecifier;
/**
* Name and documentation of the replacement rule
*/
rule?: ExternalSpecifier;
}
/**
* Specifies the name and url of an external resource. At least one property
* should be set.
*/
export interface ExternalSpecifier {
/**
* Name of the referenced plugin / rule.
*/
name?: string;
/**
* URL pointing to documentation for the plugin / rule.
*/
url?: string;
}
/**
* Generic type for `RuleContext`.
*/
export interface RuleContextTypeOptions {
LangOptions: LanguageOptions;
Code: SourceCode;
RuleOptions: unknown[];
Node: unknown;
MessageIds: string;
}
/**
* Represents the context object that is passed to a rule. This object contains
* information about the current state of the linting process and is the rule's
* view into the outside world.
*/
export interface RuleContext<Options extends RuleContextTypeOptions = RuleContextTypeOptions> {
/**
* The current working directory for the session.
*/
cwd: string;
/**
* Returns the current working directory for the session.
* @deprecated Use `cwd` instead.
*/
getCwd(): string;
/**
* The filename of the file being linted.
*/
filename: string;
/**
* Returns the filename of the file being linted.
* @deprecated Use `filename` instead.
*/
getFilename(): string;
/**
* The physical filename of the file being linted.
*/
physicalFilename: string;
/**
* Returns the physical filename of the file being linted.
* @deprecated Use `physicalFilename` instead.
*/
getPhysicalFilename(): string;
/**
* The source code object that the rule is running on.
*/
sourceCode: Options["Code"];
/**
* Returns the source code object that the rule is running on.
* @deprecated Use `sourceCode` instead.
*/
getSourceCode(): Options["Code"];
/**
* Shared settings for the configuration.
*/
settings: SettingsConfig;
/**
* Parser-specific options for the configuration.
* @deprecated Use `languageOptions.parserOptions` instead.
*/
parserOptions: Record<string, unknown>;
/**
* The language options for the configuration.
*/
languageOptions: Options["LangOptions"];
/**
* The CommonJS path to the parser used while parsing this file.
* @deprecated No longer used.
*/
parserPath: string | undefined;
/**
* The rule ID.
*/
id: string;
/**
* The rule's configured options.
*/
options: Options["RuleOptions"];
/**
* The report function that the rule should use to report problems.
* @param violation The violation to report.
*/
report(violation: ViolationReport<Options["Node"], Options["MessageIds"]>): void;
}
/**
* Manager of text edits for a rule fix.
*/
export interface RuleTextEditor<EditableSyntaxElement = unknown> {
/**
* Inserts text after the specified node or token.
* @param syntaxElement The node or token to insert after.
* @param text The edit to insert after the node or token.
*/
insertTextAfter(syntaxElement: EditableSyntaxElement, text: string): RuleTextEdit;
/**
* Inserts text after the specified range.
* @param range The range to insert after.
* @param text The edit to insert after the range.
*/
insertTextAfterRange(range: SourceRange, text: string): RuleTextEdit;
/**
* Inserts text before the specified node or token.
* @param syntaxElement A syntax element with location information to insert before.
* @param text The edit to insert before the node or token.
*/
insertTextBefore(syntaxElement: EditableSyntaxElement, text: string): RuleTextEdit;
/**
* Inserts text before the specified range.
* @param range The range to insert before.
* @param text The edit to insert before the range.
*/
insertTextBeforeRange(range: SourceRange, text: string): RuleTextEdit;
/**
* Removes the specified node or token.
* @param syntaxElement A syntax element with location information to remove.
* @returns The edit to remove the node or token.
*/
remove(syntaxElement: EditableSyntaxElement): RuleTextEdit;
/**
* Removes the specified range.
* @param range The range to remove.
* @returns The edit to remove the range.
*/
removeRange(range: SourceRange): RuleTextEdit;
/**
* Replaces the specified node or token with the given text.
* @param syntaxElement A syntax element with location information to replace.
* @param text The text to replace the node or token with.
* @returns The edit to replace the node or token.
*/
replaceText(syntaxElement: EditableSyntaxElement, text: string): RuleTextEdit;
/**
* Replaces the specified range with the given text.
* @param range The range to replace.
* @param text The text to replace the range with.
* @returns The edit to replace the range.
*/
replaceTextRange(range: SourceRange, text: string): RuleTextEdit;
}
/**
* Represents a fix for a rule violation implemented as a text edit.
*/
export interface RuleTextEdit {
/**
* The range to replace.
*/
range: SourceRange;
/**
* The text to insert.
*/
text: string;
}
/**
* Fixes a violation.
* @param fixer The text editor to apply the fix.
* @returns The fix(es) for the violation.
*/
type RuleFixer = (fixer: RuleTextEditor) => RuleTextEdit | Iterable<RuleTextEdit> | null;
interface ViolationReportBase {
/**
* The type of node that the violation is for.
* @deprecated May be removed in the future.
*/
nodeType?: string | undefined;
/**
* The data to insert into the message.
*/
data?: Record<string, string> | undefined;
/**
* The fix to be applied for the violation.
*/
fix?: RuleFixer | null | undefined;
/**
* An array of suggested fixes for the problem. These fixes may change the
* behavior of the code, so they are not applied automatically.
*/
suggest?: SuggestedEdit[] | null | undefined;
}
type ViolationMessage<MessageIds = string> = {
message: string;
} | {
messageId: MessageIds;
};
type ViolationLocation<Node> = {
loc: SourceLocation | Position;
} | {
node: Node;
};
export type ViolationReport<Node = unknown, MessageIds = string> = ViolationReportBase & ViolationMessage<MessageIds> & ViolationLocation<Node>;
interface SuggestedEditBase {
/**
* The data to insert into the message.
*/
data?: Record<string, string> | undefined;
/**
* The fix to be applied for the suggestion.
*/
fix?: RuleFixer | null | undefined;
}
type SuggestionMessage = {
desc: string;
} | {
messageId: string;
};
/**
* A suggested edit for a rule violation.
*/
export type SuggestedEdit = SuggestedEditBase & SuggestionMessage;
/**
* Generic options for the `RuleDefinition` type.
*/
export interface RuleDefinitionTypeOptions {
LangOptions: LanguageOptions;
Code: SourceCode;
RuleOptions: unknown[];
Visitor: RuleVisitor;
Node: unknown;
MessageIds: string;
ExtRuleDocs: unknown;
}
/**
* The definition of an ESLint rule.
*/
export interface RuleDefinition<Options extends RuleDefinitionTypeOptions = RuleDefinitionTypeOptions> {
/**
* The meta information for the rule.
*/
meta?: RulesMeta<Options["MessageIds"], Options["ExtRuleDocs"]>;
/**
* Creates the visitor that ESLint uses to apply the rule during traversal.
* @param context The rule context.
* @returns The rule visitor.
*/
create(context: RuleContext<{
LangOptions: Options["LangOptions"];
Code: Options["Code"];
RuleOptions: Options["RuleOptions"];
Node: Options["Node"];
MessageIds: Options["MessageIds"];
}>): Options["Visitor"];
}
/**
* The human readable severity level used in a configuration.
*/
export type SeverityName = "off" | "warn" | "error";
/**
* The numeric severity level for a rule.
*
* - `0` means off.
* - `1` means warn.
* - `2` means error.
*/
export type SeverityLevel = 0 | 1 | 2;
/**
* The severity of a rule in a configuration.
*/
export type Severity = SeverityName | SeverityLevel;
/**
* Represents the configuration options for the core linter.
*/
export interface LinterOptionsConfig {
/**
* Indicates whether or not inline configuration is evaluated.
*/
noInlineConfig?: boolean;
/**
* Indicates what to do when an unused disable directive is found.
*/
reportUnusedDisableDirectives?: boolean | Severity;
}
/**
* Shared settings that are accessible from within plugins.
*/
export type SettingsConfig = Record<string, unknown>;
/**
* The configuration for a rule.
*/
export type RuleConfig = Severity | [Severity, ...unknown[]];
/**
* A collection of rules and their configurations.
*/
export type RulesConfig = Record<string, RuleConfig>;
/**
* Generic options for the `Language` type.
*/
export interface LanguageTypeOptions {
LangOptions: LanguageOptions;
Code: SourceCode;
RootNode: unknown;
Node: unknown;
}
/**
* Represents a plugin language.
*/
export interface Language<Options extends LanguageTypeOptions = {
LangOptions: LanguageOptions;
Code: SourceCode;
RootNode: unknown;
Node: unknown;
}> {
/**
* Indicates how ESLint should read the file.
*/
fileType: "text";
/**
* First line number returned from the parser (text mode only).
*/
lineStart: 0 | 1;
/**
* First column number returned from the parser (text mode only).
*/
columnStart: 0 | 1;
/**
* The property to read the node type from. Used in selector querying.
*/
nodeTypeKey: string;
/**
* The traversal path that tools should take when evaluating the AST
*/
visitorKeys?: Record<string, string[]>;
/**
* Default language options. User-defined options are merged with this object.
*/
defaultLanguageOptions?: LanguageOptions;
/**
* Validates languageOptions for this language.
*/
validateLanguageOptions(languageOptions: Options["LangOptions"]): void;
/**
* Normalizes languageOptions for this language.
*/
normalizeLanguageOptions?(languageOptions: Options["LangOptions"]): Options["LangOptions"];
/**
* Helper for esquery that allows languages to match nodes against
* class. esquery currently has classes like `function` that will
* match all the various function nodes. This method allows languages
* to implement similar shorthands.
*/
matchesSelectorClass?(className: string, node: Options["Node"], ancestry: Options["Node"][]): boolean;
/**
* Parses the given file input into its component parts. This file should not
* throws errors for parsing errors but rather should return any parsing
* errors as parse of the ParseResult object.
*/
parse(file: File, context: LanguageContext<Options["LangOptions"]>): ParseResult<Options["RootNode"]>;
/**
* Creates SourceCode object that ESLint uses to work with a file.
*/
createSourceCode(file: File, input: OkParseResult<Options["RootNode"]>, context: LanguageContext<Options["LangOptions"]>): Options["Code"];
}
/**
* Plugin-defined options for the language.
*/
export type LanguageOptions = Record<string, unknown>;
/**
* The context object that is passed to the language plugin methods.
*/
export interface LanguageContext<LangOptions = LanguageOptions> {
languageOptions: LangOptions;
}
/**
* Represents a file read by ESLint.
*/
export interface File {
/**
* The path that ESLint uses for this file. May be a virtual path
* if it was returned by a processor.
*/
path: string;
/**
* The path to the file on disk. This always maps directly to a file
* regardless of whether it was returned from a processor.
*/
physicalPath: string;
/**
* Indicates if the original source contained a byte-order marker.
* ESLint strips the BOM from the `body`, but this info is needed
* to correctly apply autofixing.
*/
bom: boolean;
/**
* The body of the file to parse.
*/
body: string | Uint8Array;
}
/**
* Represents the successful result of parsing a file.
*/
export interface OkParseResult<RootNode = unknown> {
/**
* Indicates if the parse was successful. If true, the parse was successful
* and ESLint should continue on to create a SourceCode object and run rules;
* if false, ESLint should just report the error(s) without doing anything
* else.
*/
ok: true;
/**
* The abstract syntax tree created by the parser. (only when ok: true)
*/
ast: RootNode;
/**
* Any additional data that the parser wants to provide.
*/
[key: string]: any;
}
/**
* Represents the unsuccessful result of parsing a file.
*/
export interface NotOkParseResult {
/**
* Indicates if the parse was successful. If true, the parse was successful
* and ESLint should continue on to create a SourceCode object and run rules;
* if false, ESLint should just report the error(s) without doing anything
* else.
*/
ok: false;
/**
* Any parsing errors, whether fatal or not. (only when ok: false)
*/
errors: FileError[];
/**
* Any additional data that the parser wants to provide.
*/
[key: string]: any;
}
export type ParseResult<RootNode = unknown> = OkParseResult<RootNode> | NotOkParseResult;
/**
* Represents inline configuration found in the source code.
*/
interface InlineConfigElement {
/**
* The location of the inline config element.
*/
loc: SourceLocation;
/**
* The interpreted configuration from the inline config element.
*/
config: {
rules: RulesConfig;
};
}
/**
* Generic options for the `SourceCodeBase` type.
*/
interface SourceCodeBaseTypeOptions {
LangOptions: LanguageOptions;
RootNode: unknown;
SyntaxElementWithLoc: unknown;
ConfigNode: unknown;
}
/**
* Represents the basic interface for a source code object.
*/
interface SourceCodeBase<Options extends SourceCodeBaseTypeOptions = {
LangOptions: LanguageOptions;
RootNode: unknown;
SyntaxElementWithLoc: unknown;
ConfigNode: unknown;
}> {
/**
* Root of the AST.
*/
ast: Options["RootNode"];
/**
* The traversal path that tools should take when evaluating the AST.
* When present, this overrides the `visitorKeys` on the language for
* just this source code object.
*/
visitorKeys?: Record<string, string[]>;
/**
* Retrieves the equivalent of `loc` for a given node or token.
* @param syntaxElement The node or token to get the location for.
* @returns The location of the node or token.
*/
getLoc(syntaxElement: Options["SyntaxElementWithLoc"]): SourceLocation;
/**
* Retrieves the equivalent of `range` for a given node or token.
* @param syntaxElement The node or token to get the range for.
* @returns The range of the node or token.
*/
getRange(syntaxElement: Options["SyntaxElementWithLoc"]): SourceRange;
/**
* Traversal of AST.
*/
traverse(): Iterable<TraversalStep>;
/**
* Applies language options passed in from the ESLint core.
*/
applyLanguageOptions?(languageOptions: Options["LangOptions"]): void;
/**
* Return all of the inline areas where ESLint should be disabled/enabled
* along with any problems found in evaluating the directives.
*/
getDisableDirectives?(): {
directives: Directive[];
problems: FileProblem[];
};
/**
* Returns an array of all inline configuration nodes found in the
* source code.
*/
getInlineConfigNodes?(): Options["ConfigNode"][];
/**
* Applies configuration found inside of the source code. This method is only
* called when ESLint is running with inline configuration allowed.
*/
applyInlineConfig?(): {
configs: InlineConfigElement[];
problems: FileProblem[];
};
/**
* Called by ESLint core to indicate that it has finished providing
* information. We now add in all the missing variables and ensure that
* state-changing methods cannot be called by rules.
* @returns {void}
*/
finalize?(): void;
}
/**
* Represents the source of a text file being linted.
*/
export interface TextSourceCode<Options extends SourceCodeBaseTypeOptions = {
LangOptions: LanguageOptions;
RootNode: unknown;
SyntaxElementWithLoc: unknown;
ConfigNode: unknown;
}> extends SourceCodeBase<Options> {
/**
* The body of the file that you'd like rule developers to access.
*/
text: string;
}
/**
* Represents the source of a binary file being linted.
*/
export interface BinarySourceCode<Options extends SourceCodeBaseTypeOptions = {
LangOptions: LanguageOptions;
RootNode: unknown;
SyntaxElementWithLoc: unknown;
ConfigNode: unknown;
}> extends SourceCodeBase<Options> {
/**
* The body of the file that you'd like rule developers to access.
*/
body: Uint8Array;
}
export type SourceCode<Options extends SourceCodeBaseTypeOptions = {
LangOptions: LanguageOptions;
RootNode: unknown;
SyntaxElementWithLoc: unknown;
ConfigNode: unknown;
}> = TextSourceCode<Options> | BinarySourceCode<Options>;
/**
* Represents a traversal step visiting the AST.
*/
export interface VisitTraversalStep {
kind: 1;
target: unknown;
phase: 1 | 2;
args: unknown[];
}
/**
* Represents a traversal step calling a function.
*/
export interface CallTraversalStep {
kind: 2;
target: string;
phase?: string;
args: unknown[];
}
export type TraversalStep = VisitTraversalStep | CallTraversalStep;
/**
* The type of disable directive. This determines how ESLint will disable rules.
*/
export type DirectiveType = "disable" | "enable" | "disable-line" | "disable-next-line";
/**
* Represents a disable directive.
*/
export interface Directive {
/**
* The type of directive.
*/
type: DirectiveType;
/**
* The node of the directive. May be in the AST or a comment/token.
*/
node: unknown;
/**
* The value of the directive.
*/
value: string;
/**
* The justification for the directive.
*/
justification?: string;
}
export {};

View File

@@ -0,0 +1,84 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = generateCode;
function _convertSourceMap() {
const data = require("convert-source-map");
_convertSourceMap = function () {
return data;
};
return data;
}
function _generator() {
const data = require("@babel/generator");
_generator = function () {
return data;
};
return data;
}
var _mergeMap = require("./merge-map.js");
function generateCode(pluginPasses, file) {
const {
opts,
ast,
code,
inputMap
} = file;
const {
generatorOpts
} = opts;
generatorOpts.inputSourceMap = inputMap == null ? void 0 : inputMap.toObject();
const results = [];
for (const plugins of pluginPasses) {
for (const plugin of plugins) {
const {
generatorOverride
} = plugin;
if (generatorOverride) {
const result = generatorOverride(ast, generatorOpts, code, _generator().default);
if (result !== undefined) results.push(result);
}
}
}
let result;
if (results.length === 0) {
result = (0, _generator().default)(ast, generatorOpts, code);
} else if (results.length === 1) {
result = results[0];
if (typeof result.then === "function") {
throw new Error(`You appear to be using an async codegen plugin, ` + `which your current version of Babel does not support. ` + `If you're using a published plugin, ` + `you may need to upgrade your @babel/core version.`);
}
} else {
throw new Error("More than one plugin attempted to override codegen.");
}
let {
code: outputCode,
decodedMap: outputMap = result.map
} = result;
if (result.__mergedMap) {
outputMap = Object.assign({}, result.map);
} else {
if (outputMap) {
if (inputMap) {
outputMap = (0, _mergeMap.default)(inputMap.toObject(), outputMap, generatorOpts.sourceFileName);
} else {
outputMap = result.map;
}
}
}
if (opts.sourceMaps === "inline" || opts.sourceMaps === "both") {
outputCode += "\n" + _convertSourceMap().fromObject(outputMap).toComment();
}
if (opts.sourceMaps === "inline") {
outputMap = null;
}
return {
outputCode,
outputMap
};
}
0 && 0;
//# sourceMappingURL=generate.js.map