WIP: bootstrap and partial real Solana watcher implementation
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
import type { TypeOrValueSpecifier } from '../util';
|
||||
type MessageIds = 'deprecated' | 'deprecatedWithReason';
|
||||
type Options = [
|
||||
{
|
||||
allow?: TypeOrValueSpecifier[];
|
||||
}
|
||||
];
|
||||
declare const _default: import("@typescript-eslint/utils/ts-eslint").RuleModule<MessageIds, Options, import("../../rules").ESLintPluginDocs, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
|
||||
name: string;
|
||||
};
|
||||
export default _default;
|
||||
@@ -0,0 +1,6 @@
|
||||
function _interopRequireDefault(e) {
|
||||
return e && e.__esModule ? e : {
|
||||
"default": e
|
||||
};
|
||||
}
|
||||
export { _interopRequireDefault as default };
|
||||
@@ -0,0 +1,701 @@
|
||||
/**
|
||||
* @fileoverview Rule to enforce spacing before and after keywords.
|
||||
* @author Toru Nagashima
|
||||
* @deprecated in ESLint v8.53.0
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Requirements
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
const astUtils = require("./utils/ast-utils"),
|
||||
keywords = require("./utils/keywords");
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Constants
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
const PREV_TOKEN = /^[)\]}>]$/u;
|
||||
const NEXT_TOKEN = /^(?:[([{<~!]|\+\+?|--?)$/u;
|
||||
const PREV_TOKEN_M = /^[)\]}>*]$/u;
|
||||
const NEXT_TOKEN_M = /^[{*]$/u;
|
||||
const TEMPLATE_OPEN_PAREN = /\$\{$/u;
|
||||
const TEMPLATE_CLOSE_PAREN = /^\}/u;
|
||||
const CHECK_TYPE =
|
||||
/^(?:JSXElement|RegularExpression|String|Template|PrivateIdentifier)$/u;
|
||||
const KEYS = keywords.concat([
|
||||
"as",
|
||||
"async",
|
||||
"await",
|
||||
"from",
|
||||
"get",
|
||||
"let",
|
||||
"of",
|
||||
"set",
|
||||
"yield",
|
||||
]);
|
||||
|
||||
// check duplications.
|
||||
(function () {
|
||||
KEYS.sort();
|
||||
for (let i = 1; i < KEYS.length; ++i) {
|
||||
if (KEYS[i] === KEYS[i - 1]) {
|
||||
throw new Error(
|
||||
`Duplication was found in the keyword list: ${KEYS[i]}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
})();
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Helpers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Checks whether or not a given token is a "Template" token ends with "${".
|
||||
* @param {Token} token A token to check.
|
||||
* @returns {boolean} `true` if the token is a "Template" token ends with "${".
|
||||
*/
|
||||
function isOpenParenOfTemplate(token) {
|
||||
return token.type === "Template" && TEMPLATE_OPEN_PAREN.test(token.value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether or not a given token is a "Template" token starts with "}".
|
||||
* @param {Token} token A token to check.
|
||||
* @returns {boolean} `true` if the token is a "Template" token starts with "}".
|
||||
*/
|
||||
function isCloseParenOfTemplate(token) {
|
||||
return token.type === "Template" && TEMPLATE_CLOSE_PAREN.test(token.value);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Rule Definition
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/** @type {import('../types').Rule.RuleModule} */
|
||||
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: "11.0.0",
|
||||
replacedBy: [
|
||||
{
|
||||
message:
|
||||
"ESLint Stylistic now maintains deprecated stylistic core rules.",
|
||||
url: "https://eslint.style/guide/migration",
|
||||
plugin: {
|
||||
name: "@stylistic/eslint-plugin",
|
||||
url: "https://eslint.style",
|
||||
},
|
||||
rule: {
|
||||
name: "keyword-spacing",
|
||||
url: "https://eslint.style/rules/keyword-spacing",
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
type: "layout",
|
||||
|
||||
docs: {
|
||||
description: "Enforce consistent spacing before and after keywords",
|
||||
recommended: false,
|
||||
url: "https://eslint.org/docs/latest/rules/keyword-spacing",
|
||||
},
|
||||
|
||||
fixable: "whitespace",
|
||||
|
||||
schema: [
|
||||
{
|
||||
type: "object",
|
||||
properties: {
|
||||
before: { type: "boolean", default: true },
|
||||
after: { type: "boolean", default: true },
|
||||
overrides: {
|
||||
type: "object",
|
||||
properties: KEYS.reduce((retv, key) => {
|
||||
retv[key] = {
|
||||
type: "object",
|
||||
properties: {
|
||||
before: { type: "boolean" },
|
||||
after: { type: "boolean" },
|
||||
},
|
||||
additionalProperties: false,
|
||||
};
|
||||
return retv;
|
||||
}, {}),
|
||||
additionalProperties: false,
|
||||
},
|
||||
},
|
||||
additionalProperties: false,
|
||||
},
|
||||
],
|
||||
messages: {
|
||||
expectedBefore: 'Expected space(s) before "{{value}}".',
|
||||
expectedAfter: 'Expected space(s) after "{{value}}".',
|
||||
unexpectedBefore: 'Unexpected space(s) before "{{value}}".',
|
||||
unexpectedAfter: 'Unexpected space(s) after "{{value}}".',
|
||||
},
|
||||
},
|
||||
|
||||
create(context) {
|
||||
const sourceCode = context.sourceCode;
|
||||
|
||||
const tokensToIgnore = new WeakSet();
|
||||
|
||||
/**
|
||||
* Reports a given token if there are not space(s) before the token.
|
||||
* @param {Token} token A token to report.
|
||||
* @param {RegExp} pattern A pattern of the previous token to check.
|
||||
* @returns {void}
|
||||
*/
|
||||
function expectSpaceBefore(token, pattern) {
|
||||
const prevToken = sourceCode.getTokenBefore(token);
|
||||
|
||||
if (
|
||||
prevToken &&
|
||||
(CHECK_TYPE.test(prevToken.type) ||
|
||||
pattern.test(prevToken.value)) &&
|
||||
!isOpenParenOfTemplate(prevToken) &&
|
||||
!tokensToIgnore.has(prevToken) &&
|
||||
astUtils.isTokenOnSameLine(prevToken, token) &&
|
||||
!sourceCode.isSpaceBetween(prevToken, token)
|
||||
) {
|
||||
context.report({
|
||||
loc: token.loc,
|
||||
messageId: "expectedBefore",
|
||||
data: token,
|
||||
fix(fixer) {
|
||||
return fixer.insertTextBefore(token, " ");
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reports a given token if there are space(s) before the token.
|
||||
* @param {Token} token A token to report.
|
||||
* @param {RegExp} pattern A pattern of the previous token to check.
|
||||
* @returns {void}
|
||||
*/
|
||||
function unexpectSpaceBefore(token, pattern) {
|
||||
const prevToken = sourceCode.getTokenBefore(token);
|
||||
|
||||
if (
|
||||
prevToken &&
|
||||
(CHECK_TYPE.test(prevToken.type) ||
|
||||
pattern.test(prevToken.value)) &&
|
||||
!isOpenParenOfTemplate(prevToken) &&
|
||||
!tokensToIgnore.has(prevToken) &&
|
||||
astUtils.isTokenOnSameLine(prevToken, token) &&
|
||||
sourceCode.isSpaceBetween(prevToken, token)
|
||||
) {
|
||||
context.report({
|
||||
loc: { start: prevToken.loc.end, end: token.loc.start },
|
||||
messageId: "unexpectedBefore",
|
||||
data: token,
|
||||
fix(fixer) {
|
||||
return fixer.removeRange([
|
||||
prevToken.range[1],
|
||||
token.range[0],
|
||||
]);
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reports a given token if there are not space(s) after the token.
|
||||
* @param {Token} token A token to report.
|
||||
* @param {RegExp} pattern A pattern of the next token to check.
|
||||
* @returns {void}
|
||||
*/
|
||||
function expectSpaceAfter(token, pattern) {
|
||||
const nextToken = sourceCode.getTokenAfter(token);
|
||||
|
||||
if (
|
||||
nextToken &&
|
||||
(CHECK_TYPE.test(nextToken.type) ||
|
||||
pattern.test(nextToken.value)) &&
|
||||
!isCloseParenOfTemplate(nextToken) &&
|
||||
!tokensToIgnore.has(nextToken) &&
|
||||
astUtils.isTokenOnSameLine(token, nextToken) &&
|
||||
!sourceCode.isSpaceBetween(token, nextToken)
|
||||
) {
|
||||
context.report({
|
||||
loc: token.loc,
|
||||
messageId: "expectedAfter",
|
||||
data: token,
|
||||
fix(fixer) {
|
||||
return fixer.insertTextAfter(token, " ");
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reports a given token if there are space(s) after the token.
|
||||
* @param {Token} token A token to report.
|
||||
* @param {RegExp} pattern A pattern of the next token to check.
|
||||
* @returns {void}
|
||||
*/
|
||||
function unexpectSpaceAfter(token, pattern) {
|
||||
const nextToken = sourceCode.getTokenAfter(token);
|
||||
|
||||
if (
|
||||
nextToken &&
|
||||
(CHECK_TYPE.test(nextToken.type) ||
|
||||
pattern.test(nextToken.value)) &&
|
||||
!isCloseParenOfTemplate(nextToken) &&
|
||||
!tokensToIgnore.has(nextToken) &&
|
||||
astUtils.isTokenOnSameLine(token, nextToken) &&
|
||||
sourceCode.isSpaceBetween(token, nextToken)
|
||||
) {
|
||||
context.report({
|
||||
loc: { start: token.loc.end, end: nextToken.loc.start },
|
||||
messageId: "unexpectedAfter",
|
||||
data: token,
|
||||
fix(fixer) {
|
||||
return fixer.removeRange([
|
||||
token.range[1],
|
||||
nextToken.range[0],
|
||||
]);
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the option object and determines check methods for each keyword.
|
||||
* @param {Object|undefined} options The option object to parse.
|
||||
* @returns {Object} - Normalized option object.
|
||||
* Keys are keywords (there are for every keyword).
|
||||
* Values are instances of `{"before": function, "after": function}`.
|
||||
*/
|
||||
function parseOptions(options = {}) {
|
||||
const before = options.before !== false;
|
||||
const after = options.after !== false;
|
||||
const defaultValue = {
|
||||
before: before ? expectSpaceBefore : unexpectSpaceBefore,
|
||||
after: after ? expectSpaceAfter : unexpectSpaceAfter,
|
||||
};
|
||||
const overrides = (options && options.overrides) || {};
|
||||
const retv = Object.create(null);
|
||||
|
||||
for (let i = 0; i < KEYS.length; ++i) {
|
||||
const key = KEYS[i];
|
||||
const override = overrides[key];
|
||||
|
||||
if (override) {
|
||||
const thisBefore =
|
||||
"before" in override ? override.before : before;
|
||||
const thisAfter =
|
||||
"after" in override ? override.after : after;
|
||||
|
||||
retv[key] = {
|
||||
before: thisBefore
|
||||
? expectSpaceBefore
|
||||
: unexpectSpaceBefore,
|
||||
after: thisAfter
|
||||
? expectSpaceAfter
|
||||
: unexpectSpaceAfter,
|
||||
};
|
||||
} else {
|
||||
retv[key] = defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
return retv;
|
||||
}
|
||||
|
||||
const checkMethodMap = parseOptions(context.options[0]);
|
||||
|
||||
/**
|
||||
* Reports a given token if usage of spacing followed by the token is
|
||||
* invalid.
|
||||
* @param {Token} token A token to report.
|
||||
* @param {RegExp} [pattern] Optional. A pattern of the previous
|
||||
* token to check.
|
||||
* @returns {void}
|
||||
*/
|
||||
function checkSpacingBefore(token, pattern) {
|
||||
checkMethodMap[token.value].before(token, pattern || PREV_TOKEN);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reports a given token if usage of spacing preceded by the token is
|
||||
* invalid.
|
||||
* @param {Token} token A token to report.
|
||||
* @param {RegExp} [pattern] Optional. A pattern of the next
|
||||
* token to check.
|
||||
* @returns {void}
|
||||
*/
|
||||
function checkSpacingAfter(token, pattern) {
|
||||
checkMethodMap[token.value].after(token, pattern || NEXT_TOKEN);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reports a given token if usage of spacing around the token is invalid.
|
||||
* @param {Token} token A token to report.
|
||||
* @returns {void}
|
||||
*/
|
||||
function checkSpacingAround(token) {
|
||||
checkSpacingBefore(token);
|
||||
checkSpacingAfter(token);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reports the first token of a given node if the first token is a keyword
|
||||
* and usage of spacing around the token is invalid.
|
||||
* @param {ASTNode|null} node A node to report.
|
||||
* @returns {void}
|
||||
*/
|
||||
function checkSpacingAroundFirstToken(node) {
|
||||
const firstToken = node && sourceCode.getFirstToken(node);
|
||||
|
||||
if (firstToken && firstToken.type === "Keyword") {
|
||||
checkSpacingAround(firstToken);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reports the first token of a given node if the first token is a keyword
|
||||
* and usage of spacing followed by the token is invalid.
|
||||
*
|
||||
* This is used for unary operators (e.g. `typeof`), `function`, and `super`.
|
||||
* Other rules are handling usage of spacing preceded by those keywords.
|
||||
* @param {ASTNode|null} node A node to report.
|
||||
* @returns {void}
|
||||
*/
|
||||
function checkSpacingBeforeFirstToken(node) {
|
||||
const firstToken = node && sourceCode.getFirstToken(node);
|
||||
|
||||
if (firstToken && firstToken.type === "Keyword") {
|
||||
checkSpacingBefore(firstToken);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reports the previous token of a given node if the token is a keyword and
|
||||
* usage of spacing around the token is invalid.
|
||||
* @param {ASTNode|null} node A node to report.
|
||||
* @returns {void}
|
||||
*/
|
||||
function checkSpacingAroundTokenBefore(node) {
|
||||
if (node) {
|
||||
const token = sourceCode.getTokenBefore(
|
||||
node,
|
||||
astUtils.isKeywordToken,
|
||||
);
|
||||
|
||||
checkSpacingAround(token);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reports `async` or `function` keywords of a given node if usage of
|
||||
* spacing around those keywords is invalid.
|
||||
* @param {ASTNode} node A node to report.
|
||||
* @returns {void}
|
||||
*/
|
||||
function checkSpacingForFunction(node) {
|
||||
const firstToken = node && sourceCode.getFirstToken(node);
|
||||
|
||||
if (
|
||||
firstToken &&
|
||||
((firstToken.type === "Keyword" &&
|
||||
firstToken.value === "function") ||
|
||||
firstToken.value === "async")
|
||||
) {
|
||||
checkSpacingBefore(firstToken);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reports `class` and `extends` keywords of a given node if usage of
|
||||
* spacing around those keywords is invalid.
|
||||
* @param {ASTNode} node A node to report.
|
||||
* @returns {void}
|
||||
*/
|
||||
function checkSpacingForClass(node) {
|
||||
checkSpacingAroundFirstToken(node);
|
||||
checkSpacingAroundTokenBefore(node.superClass);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reports `if` and `else` keywords of a given node if usage of spacing
|
||||
* around those keywords is invalid.
|
||||
* @param {ASTNode} node A node to report.
|
||||
* @returns {void}
|
||||
*/
|
||||
function checkSpacingForIfStatement(node) {
|
||||
checkSpacingAroundFirstToken(node);
|
||||
checkSpacingAroundTokenBefore(node.alternate);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reports `try`, `catch`, and `finally` keywords of a given node if usage
|
||||
* of spacing around those keywords is invalid.
|
||||
* @param {ASTNode} node A node to report.
|
||||
* @returns {void}
|
||||
*/
|
||||
function checkSpacingForTryStatement(node) {
|
||||
checkSpacingAroundFirstToken(node);
|
||||
checkSpacingAroundFirstToken(node.handler);
|
||||
checkSpacingAroundTokenBefore(node.finalizer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reports `do` and `while` keywords of a given node if usage of spacing
|
||||
* around those keywords is invalid.
|
||||
* @param {ASTNode} node A node to report.
|
||||
* @returns {void}
|
||||
*/
|
||||
function checkSpacingForDoWhileStatement(node) {
|
||||
checkSpacingAroundFirstToken(node);
|
||||
checkSpacingAroundTokenBefore(node.test);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reports `for` and `in` keywords of a given node if usage of spacing
|
||||
* around those keywords is invalid.
|
||||
* @param {ASTNode} node A node to report.
|
||||
* @returns {void}
|
||||
*/
|
||||
function checkSpacingForForInStatement(node) {
|
||||
checkSpacingAroundFirstToken(node);
|
||||
|
||||
const inToken = sourceCode.getTokenBefore(
|
||||
node.right,
|
||||
astUtils.isNotOpeningParenToken,
|
||||
);
|
||||
const previousToken = sourceCode.getTokenBefore(inToken);
|
||||
|
||||
if (previousToken.type !== "PrivateIdentifier") {
|
||||
checkSpacingBefore(inToken);
|
||||
}
|
||||
|
||||
checkSpacingAfter(inToken);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reports `for` and `of` keywords of a given node if usage of spacing
|
||||
* around those keywords is invalid.
|
||||
* @param {ASTNode} node A node to report.
|
||||
* @returns {void}
|
||||
*/
|
||||
function checkSpacingForForOfStatement(node) {
|
||||
if (node.await) {
|
||||
checkSpacingBefore(sourceCode.getFirstToken(node, 0));
|
||||
checkSpacingAfter(sourceCode.getFirstToken(node, 1));
|
||||
} else {
|
||||
checkSpacingAroundFirstToken(node);
|
||||
}
|
||||
|
||||
const ofToken = sourceCode.getTokenBefore(
|
||||
node.right,
|
||||
astUtils.isNotOpeningParenToken,
|
||||
);
|
||||
const previousToken = sourceCode.getTokenBefore(ofToken);
|
||||
|
||||
if (previousToken.type !== "PrivateIdentifier") {
|
||||
checkSpacingBefore(ofToken);
|
||||
}
|
||||
|
||||
checkSpacingAfter(ofToken);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reports `import`, `export`, `as`, and `from` keywords of a given node if
|
||||
* usage of spacing around those keywords is invalid.
|
||||
*
|
||||
* This rule handles the `*` token in module declarations.
|
||||
*
|
||||
* import*as A from "./a"; /*error Expected space(s) after "import".
|
||||
* error Expected space(s) before "as".
|
||||
* @param {ASTNode} node A node to report.
|
||||
* @returns {void}
|
||||
*/
|
||||
function checkSpacingForModuleDeclaration(node) {
|
||||
const firstToken = sourceCode.getFirstToken(node);
|
||||
|
||||
checkSpacingBefore(firstToken, PREV_TOKEN_M);
|
||||
checkSpacingAfter(firstToken, NEXT_TOKEN_M);
|
||||
|
||||
if (node.type === "ExportDefaultDeclaration") {
|
||||
checkSpacingAround(sourceCode.getTokenAfter(firstToken));
|
||||
}
|
||||
|
||||
if (node.type === "ExportAllDeclaration" && node.exported) {
|
||||
const asToken = sourceCode.getTokenBefore(node.exported);
|
||||
|
||||
checkSpacingBefore(asToken, PREV_TOKEN_M);
|
||||
checkSpacingAfter(asToken, NEXT_TOKEN_M);
|
||||
}
|
||||
|
||||
if (node.source) {
|
||||
const fromToken = sourceCode.getTokenBefore(node.source);
|
||||
|
||||
checkSpacingBefore(fromToken, PREV_TOKEN_M);
|
||||
checkSpacingAfter(fromToken, NEXT_TOKEN_M);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reports `as` keyword of a given node if usage of spacing around this
|
||||
* keyword is invalid.
|
||||
* @param {ASTNode} node An `ImportSpecifier` node to check.
|
||||
* @returns {void}
|
||||
*/
|
||||
function checkSpacingForImportSpecifier(node) {
|
||||
if (node.imported.range[0] !== node.local.range[0]) {
|
||||
const asToken = sourceCode.getTokenBefore(node.local);
|
||||
|
||||
checkSpacingBefore(asToken, PREV_TOKEN_M);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reports `as` keyword of a given node if usage of spacing around this
|
||||
* keyword is invalid.
|
||||
* @param {ASTNode} node An `ExportSpecifier` node to check.
|
||||
* @returns {void}
|
||||
*/
|
||||
function checkSpacingForExportSpecifier(node) {
|
||||
if (node.local.range[0] !== node.exported.range[0]) {
|
||||
const asToken = sourceCode.getTokenBefore(node.exported);
|
||||
|
||||
checkSpacingBefore(asToken, PREV_TOKEN_M);
|
||||
checkSpacingAfter(asToken, NEXT_TOKEN_M);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reports `as` keyword of a given node if usage of spacing around this
|
||||
* keyword is invalid.
|
||||
* @param {ASTNode} node A node to report.
|
||||
* @returns {void}
|
||||
*/
|
||||
function checkSpacingForImportNamespaceSpecifier(node) {
|
||||
const asToken = sourceCode.getFirstToken(node, 1);
|
||||
|
||||
checkSpacingBefore(asToken, PREV_TOKEN_M);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reports `static`, `get`, and `set` keywords of a given node if usage of
|
||||
* spacing around those keywords is invalid.
|
||||
* @param {ASTNode} node A node to report.
|
||||
* @throws {Error} If unable to find token get, set, or async beside method name.
|
||||
* @returns {void}
|
||||
*/
|
||||
function checkSpacingForProperty(node) {
|
||||
if (node.static) {
|
||||
checkSpacingAroundFirstToken(node);
|
||||
}
|
||||
if (
|
||||
node.kind === "get" ||
|
||||
node.kind === "set" ||
|
||||
((node.method || node.type === "MethodDefinition") &&
|
||||
node.value.async)
|
||||
) {
|
||||
const token = sourceCode.getTokenBefore(node.key, tok => {
|
||||
switch (tok.value) {
|
||||
case "get":
|
||||
case "set":
|
||||
case "async":
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
if (!token) {
|
||||
throw new Error(
|
||||
"Failed to find token get, set, or async beside method name",
|
||||
);
|
||||
}
|
||||
|
||||
checkSpacingAround(token);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reports `await` keyword of a given node if usage of spacing before
|
||||
* this keyword is invalid.
|
||||
* @param {ASTNode} node A node to report.
|
||||
* @returns {void}
|
||||
*/
|
||||
function checkSpacingForAwaitExpression(node) {
|
||||
checkSpacingBefore(sourceCode.getFirstToken(node));
|
||||
}
|
||||
|
||||
return {
|
||||
// Statements
|
||||
DebuggerStatement: checkSpacingAroundFirstToken,
|
||||
WithStatement: checkSpacingAroundFirstToken,
|
||||
|
||||
// Statements - Control flow
|
||||
BreakStatement: checkSpacingAroundFirstToken,
|
||||
ContinueStatement: checkSpacingAroundFirstToken,
|
||||
ReturnStatement: checkSpacingAroundFirstToken,
|
||||
ThrowStatement: checkSpacingAroundFirstToken,
|
||||
TryStatement: checkSpacingForTryStatement,
|
||||
|
||||
// Statements - Choice
|
||||
IfStatement: checkSpacingForIfStatement,
|
||||
SwitchStatement: checkSpacingAroundFirstToken,
|
||||
SwitchCase: checkSpacingAroundFirstToken,
|
||||
|
||||
// Statements - Loops
|
||||
DoWhileStatement: checkSpacingForDoWhileStatement,
|
||||
ForInStatement: checkSpacingForForInStatement,
|
||||
ForOfStatement: checkSpacingForForOfStatement,
|
||||
ForStatement: checkSpacingAroundFirstToken,
|
||||
WhileStatement: checkSpacingAroundFirstToken,
|
||||
|
||||
// Statements - Declarations
|
||||
ClassDeclaration: checkSpacingForClass,
|
||||
ExportNamedDeclaration: checkSpacingForModuleDeclaration,
|
||||
ExportDefaultDeclaration: checkSpacingForModuleDeclaration,
|
||||
ExportAllDeclaration: checkSpacingForModuleDeclaration,
|
||||
FunctionDeclaration: checkSpacingForFunction,
|
||||
ImportDeclaration: checkSpacingForModuleDeclaration,
|
||||
VariableDeclaration: checkSpacingAroundFirstToken,
|
||||
|
||||
// Expressions
|
||||
ArrowFunctionExpression: checkSpacingForFunction,
|
||||
AwaitExpression: checkSpacingForAwaitExpression,
|
||||
ClassExpression: checkSpacingForClass,
|
||||
FunctionExpression: checkSpacingForFunction,
|
||||
NewExpression: checkSpacingBeforeFirstToken,
|
||||
Super: checkSpacingBeforeFirstToken,
|
||||
ThisExpression: checkSpacingBeforeFirstToken,
|
||||
UnaryExpression: checkSpacingBeforeFirstToken,
|
||||
YieldExpression: checkSpacingBeforeFirstToken,
|
||||
|
||||
// Others
|
||||
ImportSpecifier: checkSpacingForImportSpecifier,
|
||||
ExportSpecifier: checkSpacingForExportSpecifier,
|
||||
ImportNamespaceSpecifier: checkSpacingForImportNamespaceSpecifier,
|
||||
MethodDefinition: checkSpacingForProperty,
|
||||
PropertyDefinition: checkSpacingForProperty,
|
||||
StaticBlock: checkSpacingAroundFirstToken,
|
||||
Property: checkSpacingForProperty,
|
||||
|
||||
// To avoid conflicts with `space-infix-ops`, e.g. `a > this.b`
|
||||
"BinaryExpression[operator='>']"(node) {
|
||||
const operatorToken = sourceCode.getTokenBefore(
|
||||
node.right,
|
||||
astUtils.isNotOpeningParenToken,
|
||||
);
|
||||
|
||||
tokensToIgnore.add(operatorToken);
|
||||
},
|
||||
};
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,23 @@
|
||||
/**
|
||||
* @fileoverview Shared utilities for error messages.
|
||||
* @author Josh Goldberg
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
* Converts a value to a string that may be printed in errors.
|
||||
* @param {any} value The invalid value.
|
||||
* @param {number} indentation How many spaces to indent
|
||||
* @returns {string} The value, stringified.
|
||||
*/
|
||||
function stringifyValueForError(value, indentation) {
|
||||
return value
|
||||
? JSON.stringify(value, null, 4).replace(
|
||||
/\n/gu,
|
||||
`\n${" ".repeat(indentation)}`,
|
||||
)
|
||||
: `${value}`;
|
||||
}
|
||||
|
||||
module.exports = { stringifyValueForError };
|
||||
@@ -0,0 +1,4 @@
|
||||
import { URIRegExps } from "./uri";
|
||||
export declare function buildExps(isIRI: boolean): URIRegExps;
|
||||
declare const _default: URIRegExps;
|
||||
export default _default;
|
||||
@@ -0,0 +1,360 @@
|
||||
import { expect, expectTypeOf, test } from "vitest";
|
||||
import * as z from "zod/v4";
|
||||
|
||||
const args1 = z.tuple([z.string()]);
|
||||
const returns1 = z.number();
|
||||
const func1 = z.function({
|
||||
input: args1,
|
||||
|
||||
output: returns1,
|
||||
});
|
||||
|
||||
test("function parsing", () => {
|
||||
const parsed = func1.implement((arg: any) => arg.length);
|
||||
const result = parsed("asdf");
|
||||
expect(result).toBe(4);
|
||||
});
|
||||
|
||||
test("parsed function fail 1", () => {
|
||||
// @ts-expect-error
|
||||
const parsed = func1.implement((x: string) => x);
|
||||
expect(() => parsed("asdf")).toThrow();
|
||||
});
|
||||
|
||||
test("parsed function fail 2", () => {
|
||||
// @ts-expect-error
|
||||
const parsed = func1.implement((x: string) => x);
|
||||
expect(() => parsed(13 as any)).toThrow();
|
||||
});
|
||||
|
||||
test("function inference 1", () => {
|
||||
type func1 = (typeof func1)["_input"];
|
||||
expectTypeOf<func1>().toEqualTypeOf<(k: string) => number>();
|
||||
});
|
||||
|
||||
test("method parsing", () => {
|
||||
const methodObject = z.object({
|
||||
property: z.number(),
|
||||
method: z
|
||||
.function()
|
||||
.input(z.tuple([z.string()]))
|
||||
.output(z.number()),
|
||||
});
|
||||
const methodInstance = {
|
||||
property: 3,
|
||||
method: function (s: string) {
|
||||
return s.length + this.property;
|
||||
},
|
||||
};
|
||||
const parsed = methodObject.parse(methodInstance);
|
||||
expect(parsed.method("length=8")).toBe(11); // 8 length + 3 property
|
||||
});
|
||||
|
||||
test("async method parsing", async () => {
|
||||
const methodObject = z.object({
|
||||
property: z.number(),
|
||||
method: z.function().input([z.string()]).output(z.promise(z.number())),
|
||||
});
|
||||
const methodInstance = {
|
||||
property: 3,
|
||||
method: async function (s: string) {
|
||||
return s.length + this.property;
|
||||
},
|
||||
};
|
||||
const parsed = methodObject.parse(methodInstance);
|
||||
expect(await parsed.method("length=8")).toBe(11); // 8 length + 3 property
|
||||
});
|
||||
|
||||
test("args method", () => {
|
||||
const t1 = z.function();
|
||||
type t1 = (typeof t1)["_input"];
|
||||
expectTypeOf<t1>().toEqualTypeOf<(...args_1: never[]) => unknown>();
|
||||
t1._input;
|
||||
|
||||
const t2args = z.tuple([z.string()], z.unknown());
|
||||
|
||||
const t2 = t1.input(t2args);
|
||||
type t2 = (typeof t2)["_input"];
|
||||
expectTypeOf<t2>().toEqualTypeOf<(arg: string, ...args_1: unknown[]) => unknown>();
|
||||
|
||||
const t3 = t2.output(z.boolean());
|
||||
type t3 = (typeof t3)["_input"];
|
||||
expectTypeOf<t3>().toEqualTypeOf<(arg: string, ...args_1: unknown[]) => boolean>();
|
||||
});
|
||||
|
||||
// test("custom args", () => {
|
||||
// const fn = z.function().implement((_a: string, _b: number) => {
|
||||
// return new Date();
|
||||
// });
|
||||
|
||||
// expectTypeOf(fn).toEqualTypeOf<(a: string, b: number) => Date>();
|
||||
// });
|
||||
|
||||
const args2 = z.tuple([
|
||||
z.object({
|
||||
f1: z.number(),
|
||||
f2: z.string().nullable(),
|
||||
f3: z.array(z.boolean().optional()).optional(),
|
||||
}),
|
||||
]);
|
||||
const returns2 = z.union([z.string(), z.number()]);
|
||||
|
||||
const func2 = z.function({
|
||||
input: args2,
|
||||
output: returns2,
|
||||
});
|
||||
|
||||
test("function inference 2", () => {
|
||||
type func2 = (typeof func2)["_input"];
|
||||
|
||||
expectTypeOf<func2>().toEqualTypeOf<
|
||||
(arg: {
|
||||
f3?: (boolean | undefined)[] | undefined;
|
||||
f1: number;
|
||||
f2: string | null;
|
||||
}) => string | number
|
||||
>();
|
||||
});
|
||||
|
||||
test("valid function run", () => {
|
||||
const validFunc2Instance = func2.implement((_x) => {
|
||||
_x.f2;
|
||||
_x.f3![0];
|
||||
return "adf" as any;
|
||||
});
|
||||
|
||||
validFunc2Instance({
|
||||
f1: 21,
|
||||
f2: "asdf",
|
||||
f3: [true, false],
|
||||
});
|
||||
});
|
||||
|
||||
const args3 = [
|
||||
z.object({
|
||||
f1: z.number(),
|
||||
f2: z.string().nullable(),
|
||||
f3: z.array(z.boolean().optional()).optional(),
|
||||
}),
|
||||
] as const;
|
||||
const returns3 = z.union([z.string(), z.number()]);
|
||||
|
||||
const func3 = z.function({
|
||||
input: args3,
|
||||
output: returns3,
|
||||
});
|
||||
|
||||
test("function inference 3", () => {
|
||||
type func3 = (typeof func3)["_input"];
|
||||
|
||||
expectTypeOf<func3>().toEqualTypeOf<
|
||||
(arg: {
|
||||
f3?: (boolean | undefined)[] | undefined;
|
||||
f1: number;
|
||||
f2: string | null;
|
||||
}) => string | number
|
||||
>();
|
||||
});
|
||||
|
||||
test("valid function run", () => {
|
||||
const validFunc3Instance = func3.implement((_x) => {
|
||||
_x.f2;
|
||||
_x.f3![0];
|
||||
return "adf" as any;
|
||||
});
|
||||
|
||||
validFunc3Instance({
|
||||
f1: 21,
|
||||
f2: "asdf",
|
||||
f3: [true, false],
|
||||
});
|
||||
});
|
||||
|
||||
test("input validation error", () => {
|
||||
const schema = z.function({
|
||||
input: z.tuple([z.string()]),
|
||||
output: z.void(),
|
||||
});
|
||||
const fn = schema.implement(() => 1234 as any);
|
||||
|
||||
// @ts-expect-error
|
||||
const checker = () => fn();
|
||||
|
||||
try {
|
||||
checker();
|
||||
} catch (e: any) {
|
||||
expect(e.issues).toMatchInlineSnapshot(`
|
||||
[
|
||||
{
|
||||
"code": "too_small",
|
||||
"inclusive": true,
|
||||
"message": "Too small: expected array to have >=1 items",
|
||||
"minimum": 1,
|
||||
"origin": "array",
|
||||
"path": [],
|
||||
},
|
||||
]
|
||||
`);
|
||||
}
|
||||
});
|
||||
|
||||
test("array inputs", () => {
|
||||
const a = z.function({
|
||||
input: [
|
||||
z.object({
|
||||
name: z.string(),
|
||||
age: z.number().int(),
|
||||
}),
|
||||
],
|
||||
output: z.string(),
|
||||
});
|
||||
|
||||
a.implement((args) => {
|
||||
return `${args.age}`;
|
||||
});
|
||||
|
||||
const b = z.function({
|
||||
input: [
|
||||
z.object({
|
||||
name: z.string(),
|
||||
age: z.number().int(),
|
||||
}),
|
||||
],
|
||||
});
|
||||
b.implement((args) => {
|
||||
return `${args.age}`;
|
||||
});
|
||||
});
|
||||
|
||||
test("output validation error", () => {
|
||||
const schema = z.function({
|
||||
input: z.tuple([]),
|
||||
output: z.string(),
|
||||
});
|
||||
const fn = schema.implement(() => 1234 as any);
|
||||
try {
|
||||
fn();
|
||||
} catch (e: any) {
|
||||
expect(e.issues).toMatchInlineSnapshot(`
|
||||
[
|
||||
{
|
||||
"code": "invalid_type",
|
||||
"expected": "string",
|
||||
"message": "Invalid input: expected string, received number",
|
||||
"path": [],
|
||||
},
|
||||
]
|
||||
`);
|
||||
}
|
||||
});
|
||||
|
||||
test("function with async refinements", async () => {
|
||||
const schema = z
|
||||
.function()
|
||||
.input([z.string().refine(async (val) => val.length > 10)])
|
||||
.output(z.promise(z.number().refine(async (val) => val > 10)));
|
||||
|
||||
const func = schema.implementAsync(async (val) => {
|
||||
return val.length;
|
||||
});
|
||||
const results = [];
|
||||
try {
|
||||
await func("asdfasdf");
|
||||
results.push("success");
|
||||
} catch (_) {
|
||||
results.push("fail");
|
||||
}
|
||||
try {
|
||||
await func("asdflkjasdflkjsf");
|
||||
results.push("success");
|
||||
} catch (_) {
|
||||
results.push("fail");
|
||||
}
|
||||
|
||||
expect(results).toEqual(["fail", "success"]);
|
||||
});
|
||||
|
||||
test("implement async with transforms", async () => {
|
||||
const typeGuard = (data: string): data is "1234" => data === "1234";
|
||||
const codeSchema = z.string().transform((data, ctx) => {
|
||||
if (typeGuard(data)) {
|
||||
return data;
|
||||
} else {
|
||||
ctx.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
message: "Invalid code",
|
||||
});
|
||||
return z.NEVER;
|
||||
}
|
||||
});
|
||||
const inputSchema = z.object({
|
||||
code: codeSchema,
|
||||
});
|
||||
const outputSchema = z.object({
|
||||
data: z.array(z.string()).default([]),
|
||||
});
|
||||
const fnImplementation = async (data: z.infer<typeof inputSchema>): Promise<z.infer<typeof outputSchema>> => {
|
||||
return {
|
||||
data: [data.code],
|
||||
};
|
||||
};
|
||||
const schema = z.function().input([inputSchema]).output(outputSchema);
|
||||
|
||||
const func = schema.implementAsync(fnImplementation);
|
||||
type TheInterface = {
|
||||
myFunction: (data: z.infer<typeof inputSchema>) => Promise<z.infer<typeof outputSchema>>;
|
||||
};
|
||||
const theImplementation: TheInterface = {
|
||||
myFunction: func,
|
||||
};
|
||||
const results = [];
|
||||
try {
|
||||
await theImplementation.myFunction({
|
||||
code: "1234",
|
||||
});
|
||||
results.push("success");
|
||||
} catch (_) {
|
||||
results.push("fail");
|
||||
}
|
||||
try {
|
||||
await func({ data: "asdflkjasdflkjsf" } as any);
|
||||
results.push("success");
|
||||
} catch (_) {
|
||||
results.push("fail");
|
||||
}
|
||||
|
||||
expect(results).toEqual(["success", "fail"]);
|
||||
});
|
||||
|
||||
test("non async function with async refinements should fail", async () => {
|
||||
const func = z
|
||||
.function()
|
||||
.input([z.string().refine(async (val) => val.length > 10)])
|
||||
.output(z.number().refine(async (val) => val > 10))
|
||||
.implement((val) => {
|
||||
return val.length;
|
||||
});
|
||||
|
||||
const results = [];
|
||||
try {
|
||||
await func("asdasdfasdffasdf");
|
||||
results.push("success");
|
||||
} catch (_) {
|
||||
results.push("fail");
|
||||
}
|
||||
|
||||
expect(results).toEqual(["fail"]);
|
||||
});
|
||||
|
||||
test("extra parameters with rest", () => {
|
||||
const maxLength5 = z
|
||||
.function()
|
||||
.input([z.string()], z.unknown())
|
||||
.output(z.boolean())
|
||||
.implement((str, _arg, _qewr) => {
|
||||
return str.length <= 5;
|
||||
});
|
||||
|
||||
const filteredList = ["apple", "orange", "pear", "banana", "strawberry"].filter(maxLength5);
|
||||
expect(filteredList.length).toEqual(2);
|
||||
});
|
||||
@@ -0,0 +1,68 @@
|
||||
{
|
||||
"name": "balanced-match",
|
||||
"description": "Match balanced character pairs, like \"{\" and \"}\"",
|
||||
"version": "4.0.4",
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/juliangruber/balanced-match.git"
|
||||
},
|
||||
"exports": {
|
||||
"./package.json": "./package.json",
|
||||
".": {
|
||||
"import": {
|
||||
"types": "./dist/esm/index.d.ts",
|
||||
"default": "./dist/esm/index.js"
|
||||
},
|
||||
"require": {
|
||||
"types": "./dist/commonjs/index.d.ts",
|
||||
"default": "./dist/commonjs/index.js"
|
||||
}
|
||||
}
|
||||
},
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"preversion": "npm test",
|
||||
"postversion": "npm publish",
|
||||
"prepublishOnly": "git push origin --follow-tags",
|
||||
"prepare": "tshy",
|
||||
"pretest": "npm run prepare",
|
||||
"presnap": "npm run prepare",
|
||||
"test": "tap",
|
||||
"snap": "tap",
|
||||
"format": "prettier --write .",
|
||||
"benchmark": "node benchmark/index.js",
|
||||
"typedoc": "typedoc --tsconfig .tshy/esm.json ./src/*.ts"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/brace-expansion": "^1.1.2",
|
||||
"@types/node": "^25.2.1",
|
||||
"mkdirp": "^3.0.1",
|
||||
"prettier": "^3.3.2",
|
||||
"tap": "^21.6.2",
|
||||
"tshy": "^3.0.2",
|
||||
"typedoc": "^0.28.5"
|
||||
},
|
||||
"keywords": [
|
||||
"match",
|
||||
"regexp",
|
||||
"test",
|
||||
"balanced",
|
||||
"parse"
|
||||
],
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": "18 || 20 || >=22"
|
||||
},
|
||||
"tshy": {
|
||||
"exports": {
|
||||
"./package.json": "./package.json",
|
||||
".": "./src/index.ts"
|
||||
}
|
||||
},
|
||||
"main": "./dist/commonjs/index.js",
|
||||
"types": "./dist/commonjs/index.d.ts",
|
||||
"module": "./dist/esm/index.js"
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
'use strict';
|
||||
module.exports = /^#!(.*)/;
|
||||
@@ -0,0 +1 @@
|
||||
export * from './dist/diff.js'
|
||||
@@ -0,0 +1,28 @@
|
||||
function _class_apply_descriptor_update(receiver, descriptor) {
|
||||
if (descriptor.set) {
|
||||
if (!descriptor.get) throw new TypeError("attempted to read set only private field");
|
||||
|
||||
if (!("__destrWrapper" in descriptor)) {
|
||||
descriptor.__destrWrapper = {
|
||||
set value(v) {
|
||||
descriptor.set.call(receiver, v);
|
||||
},
|
||||
get value() {
|
||||
return descriptor.get.call(receiver);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return descriptor.__destrWrapper;
|
||||
} else {
|
||||
if (!descriptor.writable) {
|
||||
// This should only throw in strict mode, but class bodies are
|
||||
// always strict and private fields can only be used inside
|
||||
// class bodies.
|
||||
throw new TypeError("attempted to set read only private field");
|
||||
}
|
||||
|
||||
return descriptor;
|
||||
}
|
||||
}
|
||||
export { _class_apply_descriptor_update as _ };
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,124 @@
|
||||
import { n as __toESM, t as require_binding } from "./binding-Zhafd14U.mjs";
|
||||
import { a as bindingifySourcemap, n as normalizeBindingError } from "./error-CVc7IgvG.mjs";
|
||||
//#region src/utils/minify.ts
|
||||
var import_binding = /* @__PURE__ */ __toESM(require_binding(), 1);
|
||||
/**
|
||||
* Minify asynchronously.
|
||||
*
|
||||
* Note: This function can be slower than {@linkcode minifySync} due to the overhead of spawning a thread.
|
||||
*
|
||||
* @category Utilities
|
||||
* @experimental
|
||||
*/
|
||||
async function minify(filename, sourceText, options) {
|
||||
const inputMap = bindingifySourcemap(options?.inputMap);
|
||||
const result = await (0, import_binding.minify)(filename, sourceText, options);
|
||||
if (result.map && inputMap) result.map = {
|
||||
version: 3,
|
||||
...(0, import_binding.collapseSourcemaps)([inputMap, bindingifySourcemap(result.map)])
|
||||
};
|
||||
return result;
|
||||
}
|
||||
/**
|
||||
* Minify synchronously.
|
||||
*
|
||||
* @category Utilities
|
||||
* @experimental
|
||||
*/
|
||||
function minifySync(filename, sourceText, options) {
|
||||
const inputMap = bindingifySourcemap(options?.inputMap);
|
||||
const result = (0, import_binding.minifySync)(filename, sourceText, options);
|
||||
if (result.map && inputMap) result.map = {
|
||||
version: 3,
|
||||
...(0, import_binding.collapseSourcemaps)([inputMap, bindingifySourcemap(result.map)])
|
||||
};
|
||||
return result;
|
||||
}
|
||||
//#endregion
|
||||
//#region src/utils/transform.ts
|
||||
const yarnPnp$1 = typeof process === "object" && !!process.versions?.pnp;
|
||||
function normalizeBindingWarning(warning) {
|
||||
if (warning.type === "JsError") return warning.field0;
|
||||
return {
|
||||
code: warning.field0.kind,
|
||||
message: warning.field0.message,
|
||||
id: warning.field0.id,
|
||||
exporter: warning.field0.exporter,
|
||||
loc: warning.field0.loc,
|
||||
pos: warning.field0.pos
|
||||
};
|
||||
}
|
||||
/**
|
||||
* Transpile a JavaScript or TypeScript into a target ECMAScript version, asynchronously.
|
||||
*
|
||||
* Note: This function can be slower than `transformSync` due to the overhead of spawning a thread.
|
||||
*
|
||||
* @param filename The name of the file being transformed. If this is a
|
||||
* relative path, consider setting the {@linkcode TransformOptions#cwd} option.
|
||||
* @param sourceText The source code to transform.
|
||||
* @param options The transform options including tsconfig and inputMap. See {@linkcode TransformOptions} for more information.
|
||||
* @param cache Optional tsconfig cache for reusing resolved tsconfig across multiple transforms.
|
||||
* Only used when `options.tsconfig` is `true`.
|
||||
*
|
||||
* @returns a promise that resolves to an object containing the transformed code,
|
||||
* source maps, and any errors that occurred during parsing or transformation.
|
||||
*
|
||||
* @category Utilities
|
||||
* @experimental
|
||||
*/
|
||||
async function transform(filename, sourceText, options, cache) {
|
||||
const result = await (0, import_binding.enhancedTransform)(filename, sourceText, options, cache, yarnPnp$1);
|
||||
return {
|
||||
...result,
|
||||
errors: result.errors.map(normalizeBindingError),
|
||||
warnings: result.warnings.map(normalizeBindingWarning)
|
||||
};
|
||||
}
|
||||
/**
|
||||
* Transpile a JavaScript or TypeScript into a target ECMAScript version.
|
||||
*
|
||||
* @param filename The name of the file being transformed. If this is a
|
||||
* relative path, consider setting the {@linkcode TransformOptions#cwd} option.
|
||||
* @param sourceText The source code to transform.
|
||||
* @param options The transform options including tsconfig and inputMap. See {@linkcode TransformOptions} for more information.
|
||||
* @param cache Optional tsconfig cache for reusing resolved tsconfig across multiple transforms.
|
||||
* Only used when `options.tsconfig` is `true`.
|
||||
*
|
||||
* @returns an object containing the transformed code, source maps, and any errors
|
||||
* that occurred during parsing or transformation.
|
||||
*
|
||||
* @category Utilities
|
||||
* @experimental
|
||||
*/
|
||||
function transformSync(filename, sourceText, options, cache) {
|
||||
const result = (0, import_binding.enhancedTransformSync)(filename, sourceText, options, cache, yarnPnp$1);
|
||||
return {
|
||||
...result,
|
||||
errors: result.errors.map(normalizeBindingError),
|
||||
warnings: result.warnings.map(normalizeBindingWarning)
|
||||
};
|
||||
}
|
||||
//#endregion
|
||||
//#region src/utils/resolve-tsconfig.ts
|
||||
const yarnPnp = typeof process === "object" && !!process.versions?.pnp;
|
||||
/**
|
||||
* Cache for tsconfig resolution to avoid redundant file system operations.
|
||||
*
|
||||
* The cache stores resolved tsconfig configurations keyed by their file paths.
|
||||
* When transforming multiple files in the same project, tsconfig lookups are
|
||||
* deduplicated, improving performance.
|
||||
*
|
||||
* @category Utilities
|
||||
* @experimental
|
||||
*/
|
||||
var TsconfigCache = class extends import_binding.TsconfigCache {
|
||||
constructor() {
|
||||
super(yarnPnp);
|
||||
}
|
||||
};
|
||||
/** @hidden This is only expected to be used by Vite */
|
||||
function resolveTsconfig(filename, cache) {
|
||||
return (0, import_binding.resolveTsconfig)(filename, cache, yarnPnp);
|
||||
}
|
||||
//#endregion
|
||||
export { minify as a, transformSync as i, resolveTsconfig as n, minifySync as o, transform as r, TsconfigCache as t };
|
||||
@@ -0,0 +1,75 @@
|
||||
'use strict';
|
||||
|
||||
var isGlob = require('is-glob');
|
||||
var pathPosixDirname = require('path').posix.dirname;
|
||||
var isWin32 = require('os').platform() === 'win32';
|
||||
|
||||
var slash = '/';
|
||||
var backslash = /\\/g;
|
||||
var escaped = /\\([!*?|[\](){}])/g;
|
||||
|
||||
/**
|
||||
* @param {string} str
|
||||
* @param {Object} opts
|
||||
* @param {boolean} [opts.flipBackslashes=true]
|
||||
*/
|
||||
module.exports = function globParent(str, opts) {
|
||||
var options = Object.assign({ flipBackslashes: true }, opts);
|
||||
|
||||
// flip windows path separators
|
||||
if (options.flipBackslashes && isWin32 && str.indexOf(slash) < 0) {
|
||||
str = str.replace(backslash, slash);
|
||||
}
|
||||
|
||||
// special case for strings ending in enclosure containing path separator
|
||||
if (isEnclosure(str)) {
|
||||
str += slash;
|
||||
}
|
||||
|
||||
// preserves full path in case of trailing path separator
|
||||
str += 'a';
|
||||
|
||||
// remove path parts that are globby
|
||||
do {
|
||||
str = pathPosixDirname(str);
|
||||
} while (isGlobby(str));
|
||||
|
||||
// remove escape chars and return result
|
||||
return str.replace(escaped, '$1');
|
||||
};
|
||||
|
||||
function isEnclosure(str) {
|
||||
var lastChar = str.slice(-1);
|
||||
|
||||
var enclosureStart;
|
||||
switch (lastChar) {
|
||||
case '}':
|
||||
enclosureStart = '{';
|
||||
break;
|
||||
case ']':
|
||||
enclosureStart = '[';
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
var foundIndex = str.indexOf(enclosureStart);
|
||||
if (foundIndex < 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return str.slice(foundIndex + 1, -1).includes(slash);
|
||||
}
|
||||
|
||||
function isGlobby(str) {
|
||||
if (/\([^()]+$/.test(str)) {
|
||||
return true;
|
||||
}
|
||||
if (str[0] === '{' || str[0] === '[') {
|
||||
return true;
|
||||
}
|
||||
if (/[^\\][{[]/.test(str)) {
|
||||
return true;
|
||||
}
|
||||
return isGlob(str);
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
/*! *****************************************************************************
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
||||
this file except in compliance with the License. You may obtain a copy of the
|
||||
License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
|
||||
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
||||
MERCHANTABILITY OR NON-INFRINGEMENT.
|
||||
|
||||
See the Apache Version 2.0 License for specific language governing permissions
|
||||
and limitations under the License.
|
||||
***************************************************************************** */
|
||||
|
||||
|
||||
interface WeakKeyTypes {
|
||||
symbol: symbol;
|
||||
}
|
||||
@@ -0,0 +1,169 @@
|
||||
/**
|
||||
* @fileoverview Rule to disallow unnecessary labels
|
||||
* @author Toru Nagashima
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Requirements
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
const astUtils = require("./utils/ast-utils");
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Rule Definition
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/** @type {import('../types').Rule.RuleModule} */
|
||||
module.exports = {
|
||||
meta: {
|
||||
type: "suggestion",
|
||||
|
||||
docs: {
|
||||
description: "Disallow unnecessary labels",
|
||||
recommended: false,
|
||||
frozen: true,
|
||||
url: "https://eslint.org/docs/latest/rules/no-extra-label",
|
||||
},
|
||||
|
||||
schema: [],
|
||||
fixable: "code",
|
||||
|
||||
messages: {
|
||||
unexpected: "This label '{{name}}' is unnecessary.",
|
||||
},
|
||||
},
|
||||
|
||||
create(context) {
|
||||
const sourceCode = context.sourceCode;
|
||||
let scopeInfo = null;
|
||||
|
||||
/**
|
||||
* Creates a new scope with a breakable statement.
|
||||
* @param {ASTNode} node A node to create. This is a BreakableStatement.
|
||||
* @returns {void}
|
||||
*/
|
||||
function enterBreakableStatement(node) {
|
||||
scopeInfo = {
|
||||
label:
|
||||
node.parent.type === "LabeledStatement"
|
||||
? node.parent.label
|
||||
: null,
|
||||
breakable: true,
|
||||
upper: scopeInfo,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the top scope of the stack.
|
||||
* @returns {void}
|
||||
*/
|
||||
function exitBreakableStatement() {
|
||||
scopeInfo = scopeInfo.upper;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new scope with a labeled statement.
|
||||
*
|
||||
* This ignores it if the body is a breakable statement.
|
||||
* In this case it's handled in the `enterBreakableStatement` function.
|
||||
* @param {ASTNode} node A node to create. This is a LabeledStatement.
|
||||
* @returns {void}
|
||||
*/
|
||||
function enterLabeledStatement(node) {
|
||||
if (!astUtils.isBreakableStatement(node.body)) {
|
||||
scopeInfo = {
|
||||
label: node.label,
|
||||
breakable: false,
|
||||
upper: scopeInfo,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the top scope of the stack.
|
||||
*
|
||||
* This ignores it if the body is a breakable statement.
|
||||
* In this case it's handled in the `exitBreakableStatement` function.
|
||||
* @param {ASTNode} node A node. This is a LabeledStatement.
|
||||
* @returns {void}
|
||||
*/
|
||||
function exitLabeledStatement(node) {
|
||||
if (!astUtils.isBreakableStatement(node.body)) {
|
||||
scopeInfo = scopeInfo.upper;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reports a given control node if it's unnecessary.
|
||||
* @param {ASTNode} node A node. This is a BreakStatement or a
|
||||
* ContinueStatement.
|
||||
* @returns {void}
|
||||
*/
|
||||
function reportIfUnnecessary(node) {
|
||||
if (!node.label) {
|
||||
return;
|
||||
}
|
||||
|
||||
const labelNode = node.label;
|
||||
|
||||
for (let info = scopeInfo; info !== null; info = info.upper) {
|
||||
if (
|
||||
info.breakable ||
|
||||
(info.label && info.label.name === labelNode.name)
|
||||
) {
|
||||
if (
|
||||
info.breakable &&
|
||||
info.label &&
|
||||
info.label.name === labelNode.name
|
||||
) {
|
||||
context.report({
|
||||
node: labelNode,
|
||||
messageId: "unexpected",
|
||||
data: labelNode,
|
||||
fix(fixer) {
|
||||
const breakOrContinueToken =
|
||||
sourceCode.getFirstToken(node);
|
||||
|
||||
if (
|
||||
sourceCode.commentsExistBetween(
|
||||
breakOrContinueToken,
|
||||
labelNode,
|
||||
)
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return fixer.removeRange([
|
||||
breakOrContinueToken.range[1],
|
||||
labelNode.range[1],
|
||||
]);
|
||||
},
|
||||
});
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
WhileStatement: enterBreakableStatement,
|
||||
"WhileStatement:exit": exitBreakableStatement,
|
||||
DoWhileStatement: enterBreakableStatement,
|
||||
"DoWhileStatement:exit": exitBreakableStatement,
|
||||
ForStatement: enterBreakableStatement,
|
||||
"ForStatement:exit": exitBreakableStatement,
|
||||
ForInStatement: enterBreakableStatement,
|
||||
"ForInStatement:exit": exitBreakableStatement,
|
||||
ForOfStatement: enterBreakableStatement,
|
||||
"ForOfStatement:exit": exitBreakableStatement,
|
||||
SwitchStatement: enterBreakableStatement,
|
||||
"SwitchStatement:exit": exitBreakableStatement,
|
||||
LabeledStatement: enterLabeledStatement,
|
||||
"LabeledStatement:exit": exitLabeledStatement,
|
||||
BreakStatement: reportIfUnnecessary,
|
||||
ContinueStatement: reportIfUnnecessary,
|
||||
};
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,39 @@
|
||||
import Client from './client'
|
||||
import TPoolStats from './pool-stats'
|
||||
import { URL } from 'node:url'
|
||||
import Dispatcher from './dispatcher'
|
||||
|
||||
export default Pool
|
||||
|
||||
type PoolConnectOptions = Omit<Dispatcher.ConnectOptions, 'origin'>
|
||||
|
||||
declare class Pool extends Dispatcher {
|
||||
constructor (url: string | URL, options?: Pool.Options)
|
||||
/** `true` after `pool.close()` has been called. */
|
||||
closed: boolean
|
||||
/** `true` after `pool.destroyed()` has been called or `pool.close()` has been called and the pool shutdown has completed. */
|
||||
destroyed: boolean
|
||||
/** Aggregate stats for a Pool. */
|
||||
readonly stats: TPoolStats
|
||||
|
||||
// Override dispatcher APIs.
|
||||
override connect (
|
||||
options: PoolConnectOptions
|
||||
): Promise<Dispatcher.ConnectData>
|
||||
override connect (
|
||||
options: PoolConnectOptions,
|
||||
callback: (err: Error | null, data: Dispatcher.ConnectData) => void
|
||||
): void
|
||||
}
|
||||
|
||||
declare namespace Pool {
|
||||
export type PoolStats = TPoolStats
|
||||
export interface Options extends Client.Options {
|
||||
/** Default: `(origin, opts) => new Client(origin, opts)`. */
|
||||
factory?(origin: URL, opts: object): Dispatcher;
|
||||
/** The max number of clients to create. `null` if no limit. Default `null`. */
|
||||
connections?: number | null;
|
||||
/** The amount of time before a client is removed from the pool and closed. `null` if no time limit. Default `null` */
|
||||
clientTtl?: number | null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
import type { UUIDTypes } from './types.js';
|
||||
export { DNS, URL } from './v35.js';
|
||||
declare function v3(value: string | Uint8Array, namespace: UUIDTypes, buf?: undefined, offset?: number): string;
|
||||
declare function v3<TBuf extends Uint8Array = Uint8Array>(value: string | Uint8Array, namespace: UUIDTypes, buf: TBuf, offset?: number): TBuf;
|
||||
declare namespace v3 {
|
||||
var DNS: string;
|
||||
var URL: string;
|
||||
}
|
||||
export default v3;
|
||||
@@ -0,0 +1,133 @@
|
||||
// @ts-ignore TS6133
|
||||
import { expect, test } from "vitest";
|
||||
|
||||
import * as z from "zod/v3";
|
||||
|
||||
test("array min", async () => {
|
||||
try {
|
||||
await z.array(z.string()).min(4).parseAsync([]);
|
||||
} catch (err) {
|
||||
expect((err as z.ZodError).issues[0].message).toEqual("Array must contain at least 4 element(s)");
|
||||
}
|
||||
});
|
||||
|
||||
test("array max", async () => {
|
||||
try {
|
||||
await z.array(z.string()).max(2).parseAsync(["asdf", "asdf", "asdf"]);
|
||||
} catch (err) {
|
||||
expect((err as z.ZodError).issues[0].message).toEqual("Array must contain at most 2 element(s)");
|
||||
}
|
||||
});
|
||||
|
||||
test("array length", async () => {
|
||||
try {
|
||||
await z.array(z.string()).length(2).parseAsync(["asdf", "asdf", "asdf"]);
|
||||
} catch (err) {
|
||||
expect((err as z.ZodError).issues[0].message).toEqual("Array must contain exactly 2 element(s)");
|
||||
}
|
||||
|
||||
try {
|
||||
await z.array(z.string()).length(2).parseAsync(["asdf"]);
|
||||
} catch (err) {
|
||||
expect((err as z.ZodError).issues[0].message).toEqual("Array must contain exactly 2 element(s)");
|
||||
}
|
||||
});
|
||||
|
||||
test("string length", async () => {
|
||||
try {
|
||||
await z.string().length(4).parseAsync("asd");
|
||||
} catch (err) {
|
||||
expect((err as z.ZodError).issues[0].message).toEqual("String must contain exactly 4 character(s)");
|
||||
}
|
||||
|
||||
try {
|
||||
await z.string().length(4).parseAsync("asdaa");
|
||||
} catch (err) {
|
||||
expect((err as z.ZodError).issues[0].message).toEqual("String must contain exactly 4 character(s)");
|
||||
}
|
||||
});
|
||||
|
||||
test("string min", async () => {
|
||||
try {
|
||||
await z.string().min(4).parseAsync("asd");
|
||||
} catch (err) {
|
||||
expect((err as z.ZodError).issues[0].message).toEqual("String must contain at least 4 character(s)");
|
||||
}
|
||||
});
|
||||
|
||||
test("string max", async () => {
|
||||
try {
|
||||
await z.string().max(4).parseAsync("aasdfsdfsd");
|
||||
} catch (err) {
|
||||
expect((err as z.ZodError).issues[0].message).toEqual("String must contain at most 4 character(s)");
|
||||
}
|
||||
});
|
||||
|
||||
test("number min", async () => {
|
||||
try {
|
||||
await z.number().gte(3).parseAsync(2);
|
||||
} catch (err) {
|
||||
expect((err as z.ZodError).issues[0].message).toEqual("Number must be greater than or equal to 3");
|
||||
}
|
||||
});
|
||||
|
||||
test("number max", async () => {
|
||||
try {
|
||||
await z.number().lte(3).parseAsync(4);
|
||||
} catch (err) {
|
||||
expect((err as z.ZodError).issues[0].message).toEqual("Number must be less than or equal to 3");
|
||||
}
|
||||
});
|
||||
|
||||
test("number nonnegative", async () => {
|
||||
try {
|
||||
await z.number().nonnegative().parseAsync(-1);
|
||||
} catch (err) {
|
||||
expect((err as z.ZodError).issues[0].message).toEqual("Number must be greater than or equal to 0");
|
||||
}
|
||||
});
|
||||
|
||||
test("number nonpositive", async () => {
|
||||
try {
|
||||
await z.number().nonpositive().parseAsync(1);
|
||||
} catch (err) {
|
||||
expect((err as z.ZodError).issues[0].message).toEqual("Number must be less than or equal to 0");
|
||||
}
|
||||
});
|
||||
|
||||
test("number negative", async () => {
|
||||
try {
|
||||
await z.number().negative().parseAsync(1);
|
||||
} catch (err) {
|
||||
expect((err as z.ZodError).issues[0].message).toEqual("Number must be less than 0");
|
||||
}
|
||||
});
|
||||
|
||||
test("number positive", async () => {
|
||||
try {
|
||||
await z.number().positive().parseAsync(-1);
|
||||
} catch (err) {
|
||||
expect((err as z.ZodError).issues[0].message).toEqual("Number must be greater than 0");
|
||||
}
|
||||
});
|
||||
|
||||
test("instantiation", () => {
|
||||
z.string().min(5);
|
||||
z.string().max(5);
|
||||
z.string().length(5);
|
||||
z.string().email();
|
||||
z.string().url();
|
||||
z.string().uuid();
|
||||
z.string().min(5, { message: "Must be 5 or more characters long" });
|
||||
z.string().max(5, { message: "Must be 5 or fewer characters long" });
|
||||
z.string().length(5, { message: "Must be exactly 5 characters long" });
|
||||
z.string().email({ message: "Invalid email address." });
|
||||
z.string().url({ message: "Invalid url" });
|
||||
z.string().uuid({ message: "Invalid UUID" });
|
||||
});
|
||||
|
||||
test("int", async () => {
|
||||
const int = z.number().int();
|
||||
int.parse(4);
|
||||
expect(() => int.parse(3.5)).toThrow();
|
||||
});
|
||||
@@ -0,0 +1,73 @@
|
||||
// Code generated by Herebyfile.mjs generate:enums from internal/ast/symbolflags.go. DO NOT EDIT.
|
||||
export var SymbolFlags;
|
||||
(function (SymbolFlags) {
|
||||
SymbolFlags[SymbolFlags["None"] = 0] = "None";
|
||||
SymbolFlags[SymbolFlags["FunctionScopedVariable"] = 1] = "FunctionScopedVariable";
|
||||
SymbolFlags[SymbolFlags["BlockScopedVariable"] = 2] = "BlockScopedVariable";
|
||||
SymbolFlags[SymbolFlags["Property"] = 4] = "Property";
|
||||
SymbolFlags[SymbolFlags["EnumMember"] = 8] = "EnumMember";
|
||||
SymbolFlags[SymbolFlags["Function"] = 16] = "Function";
|
||||
SymbolFlags[SymbolFlags["Class"] = 32] = "Class";
|
||||
SymbolFlags[SymbolFlags["Interface"] = 64] = "Interface";
|
||||
SymbolFlags[SymbolFlags["ConstEnum"] = 128] = "ConstEnum";
|
||||
SymbolFlags[SymbolFlags["RegularEnum"] = 256] = "RegularEnum";
|
||||
SymbolFlags[SymbolFlags["ValueModule"] = 512] = "ValueModule";
|
||||
SymbolFlags[SymbolFlags["NamespaceModule"] = 1024] = "NamespaceModule";
|
||||
SymbolFlags[SymbolFlags["TypeLiteral"] = 2048] = "TypeLiteral";
|
||||
SymbolFlags[SymbolFlags["ObjectLiteral"] = 4096] = "ObjectLiteral";
|
||||
SymbolFlags[SymbolFlags["Method"] = 8192] = "Method";
|
||||
SymbolFlags[SymbolFlags["Constructor"] = 16384] = "Constructor";
|
||||
SymbolFlags[SymbolFlags["GetAccessor"] = 32768] = "GetAccessor";
|
||||
SymbolFlags[SymbolFlags["SetAccessor"] = 65536] = "SetAccessor";
|
||||
SymbolFlags[SymbolFlags["Signature"] = 131072] = "Signature";
|
||||
SymbolFlags[SymbolFlags["TypeParameter"] = 262144] = "TypeParameter";
|
||||
SymbolFlags[SymbolFlags["TypeAlias"] = 524288] = "TypeAlias";
|
||||
SymbolFlags[SymbolFlags["ExportValue"] = 1048576] = "ExportValue";
|
||||
SymbolFlags[SymbolFlags["Alias"] = 2097152] = "Alias";
|
||||
SymbolFlags[SymbolFlags["Prototype"] = 4194304] = "Prototype";
|
||||
SymbolFlags[SymbolFlags["ExportStar"] = 8388608] = "ExportStar";
|
||||
SymbolFlags[SymbolFlags["Optional"] = 16777216] = "Optional";
|
||||
SymbolFlags[SymbolFlags["Transient"] = 33554432] = "Transient";
|
||||
SymbolFlags[SymbolFlags["Assignment"] = 67108864] = "Assignment";
|
||||
SymbolFlags[SymbolFlags["ModuleExports"] = 134217728] = "ModuleExports";
|
||||
SymbolFlags[SymbolFlags["ConstEnumOnlyModule"] = 268435456] = "ConstEnumOnlyModule";
|
||||
SymbolFlags[SymbolFlags["ReplaceableByMethod"] = 536870912] = "ReplaceableByMethod";
|
||||
SymbolFlags[SymbolFlags["GlobalLookup"] = 1073741824] = "GlobalLookup";
|
||||
SymbolFlags[SymbolFlags["All"] = 536870912] = "All";
|
||||
SymbolFlags[SymbolFlags["Enum"] = 384] = "Enum";
|
||||
SymbolFlags[SymbolFlags["Variable"] = 3] = "Variable";
|
||||
SymbolFlags[SymbolFlags["Value"] = 111551] = "Value";
|
||||
SymbolFlags[SymbolFlags["Type"] = 788968] = "Type";
|
||||
SymbolFlags[SymbolFlags["Namespace"] = 1920] = "Namespace";
|
||||
SymbolFlags[SymbolFlags["Module"] = 1536] = "Module";
|
||||
SymbolFlags[SymbolFlags["Accessor"] = 98304] = "Accessor";
|
||||
SymbolFlags[SymbolFlags["FunctionScopedVariableExcludes"] = 111550] = "FunctionScopedVariableExcludes";
|
||||
SymbolFlags[SymbolFlags["BlockScopedVariableExcludes"] = 111551] = "BlockScopedVariableExcludes";
|
||||
SymbolFlags[SymbolFlags["ParameterExcludes"] = 111551] = "ParameterExcludes";
|
||||
SymbolFlags[SymbolFlags["PropertyExcludes"] = 13243] = "PropertyExcludes";
|
||||
SymbolFlags[SymbolFlags["EnumMemberExcludes"] = 900095] = "EnumMemberExcludes";
|
||||
SymbolFlags[SymbolFlags["FunctionExcludes"] = 110991] = "FunctionExcludes";
|
||||
SymbolFlags[SymbolFlags["ClassExcludes"] = 899503] = "ClassExcludes";
|
||||
SymbolFlags[SymbolFlags["InterfaceExcludes"] = 788872] = "InterfaceExcludes";
|
||||
SymbolFlags[SymbolFlags["RegularEnumExcludes"] = 899327] = "RegularEnumExcludes";
|
||||
SymbolFlags[SymbolFlags["ConstEnumExcludes"] = 899967] = "ConstEnumExcludes";
|
||||
SymbolFlags[SymbolFlags["ValueModuleExcludes"] = 110735] = "ValueModuleExcludes";
|
||||
SymbolFlags[SymbolFlags["NamespaceModuleExcludes"] = 0] = "NamespaceModuleExcludes";
|
||||
SymbolFlags[SymbolFlags["MethodExcludes"] = 103359] = "MethodExcludes";
|
||||
SymbolFlags[SymbolFlags["GetAccessorExcludes"] = 46011] = "GetAccessorExcludes";
|
||||
SymbolFlags[SymbolFlags["SetAccessorExcludes"] = 78779] = "SetAccessorExcludes";
|
||||
SymbolFlags[SymbolFlags["AccessorExcludes"] = 111547] = "AccessorExcludes";
|
||||
SymbolFlags[SymbolFlags["TypeParameterExcludes"] = 526824] = "TypeParameterExcludes";
|
||||
SymbolFlags[SymbolFlags["TypeAliasExcludes"] = 788968] = "TypeAliasExcludes";
|
||||
SymbolFlags[SymbolFlags["AliasExcludes"] = 2097152] = "AliasExcludes";
|
||||
SymbolFlags[SymbolFlags["ModuleMember"] = 2623475] = "ModuleMember";
|
||||
SymbolFlags[SymbolFlags["ExportHasLocal"] = 944] = "ExportHasLocal";
|
||||
SymbolFlags[SymbolFlags["BlockScoped"] = 418] = "BlockScoped";
|
||||
SymbolFlags[SymbolFlags["PropertyOrAccessor"] = 98308] = "PropertyOrAccessor";
|
||||
SymbolFlags[SymbolFlags["ClassMember"] = 106500] = "ClassMember";
|
||||
SymbolFlags[SymbolFlags["ExportSupportsDefaultModifier"] = 112] = "ExportSupportsDefaultModifier";
|
||||
SymbolFlags[SymbolFlags["ExportDoesNotSupportDefaultModifier"] = -113] = "ExportDoesNotSupportDefaultModifier";
|
||||
SymbolFlags[SymbolFlags["Classifiable"] = 2885600] = "Classifiable";
|
||||
SymbolFlags[SymbolFlags["LateBindingContainer"] = 6256] = "LateBindingContainer";
|
||||
})(SymbolFlags || (SymbolFlags = {}));
|
||||
//# sourceMappingURL=symbolFlags.js.map
|
||||
@@ -0,0 +1,6 @@
|
||||
declare const _default: import("@typescript-eslint/utils/ts-eslint").RuleModule<"notLiteral" | "notLiteralOrBitwiseExpression", [{
|
||||
allowBitwiseExpressions: boolean;
|
||||
}], import("../../rules").ESLintPluginDocs, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
|
||||
name: string;
|
||||
};
|
||||
export default _default;
|
||||
@@ -0,0 +1,38 @@
|
||||
/**
|
||||
* @fileoverview Define the abstract class about cursors which manipulate another cursor.
|
||||
* @author Toru Nagashima
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Requirements
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
const Cursor = require("./cursor");
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exports
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* The abstract class about cursors which manipulate another cursor.
|
||||
*/
|
||||
module.exports = class DecorativeCursor extends Cursor {
|
||||
/**
|
||||
* Initializes this cursor.
|
||||
* @param {Cursor} cursor The cursor to be decorated.
|
||||
*/
|
||||
constructor(cursor) {
|
||||
super();
|
||||
this.cursor = cursor;
|
||||
}
|
||||
|
||||
/** @inheritdoc */
|
||||
moveNext() {
|
||||
const retv = this.cursor.moveNext();
|
||||
|
||||
this.current = this.cursor.current;
|
||||
|
||||
return retv;
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,388 @@
|
||||
// @ts-ignore TS6133
|
||||
import { expect, test } from "vitest";
|
||||
|
||||
import * as z from "zod/v3";
|
||||
|
||||
/// string
|
||||
const stringSchema = z.string();
|
||||
|
||||
test("string async parse", async () => {
|
||||
const goodData = "XXX";
|
||||
const badData = 12;
|
||||
|
||||
const goodResult = await stringSchema.safeParseAsync(goodData);
|
||||
expect(goodResult.success).toBe(true);
|
||||
if (goodResult.success) expect(goodResult.data).toEqual(goodData);
|
||||
|
||||
const badResult = await stringSchema.safeParseAsync(badData);
|
||||
expect(badResult.success).toBe(false);
|
||||
if (!badResult.success) expect(badResult.error).toBeInstanceOf(z.ZodError);
|
||||
});
|
||||
|
||||
/// number
|
||||
const numberSchema = z.number();
|
||||
test("number async parse", async () => {
|
||||
const goodData = 1234.2353;
|
||||
const badData = "1234";
|
||||
|
||||
const goodResult = await numberSchema.safeParseAsync(goodData);
|
||||
expect(goodResult.success).toBe(true);
|
||||
if (goodResult.success) expect(goodResult.data).toEqual(goodData);
|
||||
|
||||
const badResult = await numberSchema.safeParseAsync(badData);
|
||||
expect(badResult.success).toBe(false);
|
||||
if (!badResult.success) expect(badResult.error).toBeInstanceOf(z.ZodError);
|
||||
});
|
||||
|
||||
/// bigInt
|
||||
const bigIntSchema = z.bigint();
|
||||
test("bigInt async parse", async () => {
|
||||
const goodData = BigInt(145);
|
||||
const badData = 134;
|
||||
|
||||
const goodResult = await bigIntSchema.safeParseAsync(goodData);
|
||||
expect(goodResult.success).toBe(true);
|
||||
if (goodResult.success) expect(goodResult.data).toEqual(goodData);
|
||||
|
||||
const badResult = await bigIntSchema.safeParseAsync(badData);
|
||||
expect(badResult.success).toBe(false);
|
||||
if (!badResult.success) expect(badResult.error).toBeInstanceOf(z.ZodError);
|
||||
});
|
||||
|
||||
/// boolean
|
||||
const booleanSchema = z.boolean();
|
||||
test("boolean async parse", async () => {
|
||||
const goodData = true;
|
||||
const badData = 1;
|
||||
|
||||
const goodResult = await booleanSchema.safeParseAsync(goodData);
|
||||
expect(goodResult.success).toBe(true);
|
||||
if (goodResult.success) expect(goodResult.data).toEqual(goodData);
|
||||
|
||||
const badResult = await booleanSchema.safeParseAsync(badData);
|
||||
expect(badResult.success).toBe(false);
|
||||
if (!badResult.success) expect(badResult.error).toBeInstanceOf(z.ZodError);
|
||||
});
|
||||
|
||||
/// date
|
||||
const dateSchema = z.date();
|
||||
test("date async parse", async () => {
|
||||
const goodData = new Date();
|
||||
const badData = new Date().toISOString();
|
||||
|
||||
const goodResult = await dateSchema.safeParseAsync(goodData);
|
||||
expect(goodResult.success).toBe(true);
|
||||
if (goodResult.success) expect(goodResult.data).toEqual(goodData);
|
||||
|
||||
const badResult = await dateSchema.safeParseAsync(badData);
|
||||
expect(badResult.success).toBe(false);
|
||||
if (!badResult.success) expect(badResult.error).toBeInstanceOf(z.ZodError);
|
||||
});
|
||||
|
||||
/// undefined
|
||||
const undefinedSchema = z.undefined();
|
||||
test("undefined async parse", async () => {
|
||||
const goodData = undefined;
|
||||
const badData = "XXX";
|
||||
|
||||
const goodResult = await undefinedSchema.safeParseAsync(goodData);
|
||||
expect(goodResult.success).toBe(true);
|
||||
if (goodResult.success) expect(goodResult.data).toEqual(undefined);
|
||||
|
||||
const badResult = await undefinedSchema.safeParseAsync(badData);
|
||||
expect(badResult.success).toBe(false);
|
||||
if (!badResult.success) expect(badResult.error).toBeInstanceOf(z.ZodError);
|
||||
});
|
||||
|
||||
/// null
|
||||
const nullSchema = z.null();
|
||||
test("null async parse", async () => {
|
||||
const goodData = null;
|
||||
const badData = undefined;
|
||||
|
||||
const goodResult = await nullSchema.safeParseAsync(goodData);
|
||||
expect(goodResult.success).toBe(true);
|
||||
if (goodResult.success) expect(goodResult.data).toEqual(goodData);
|
||||
|
||||
const badResult = await nullSchema.safeParseAsync(badData);
|
||||
expect(badResult.success).toBe(false);
|
||||
if (!badResult.success) expect(badResult.error).toBeInstanceOf(z.ZodError);
|
||||
});
|
||||
|
||||
/// any
|
||||
const anySchema = z.any();
|
||||
test("any async parse", async () => {
|
||||
const goodData = [{}];
|
||||
// const badData = 'XXX';
|
||||
|
||||
const goodResult = await anySchema.safeParseAsync(goodData);
|
||||
expect(goodResult.success).toBe(true);
|
||||
if (goodResult.success) expect(goodResult.data).toEqual(goodData);
|
||||
|
||||
// const badResult = await anySchema.safeParseAsync(badData);
|
||||
// expect(badResult.success).toBe(false);
|
||||
// if (!badResult.success) expect(badResult.error).toBeInstanceOf(z.ZodError);
|
||||
});
|
||||
|
||||
/// unknown
|
||||
const unknownSchema = z.unknown();
|
||||
test("unknown async parse", async () => {
|
||||
const goodData = ["asdf", 124, () => {}];
|
||||
// const badData = 'XXX';
|
||||
|
||||
const goodResult = await unknownSchema.safeParseAsync(goodData);
|
||||
expect(goodResult.success).toBe(true);
|
||||
if (goodResult.success) expect(goodResult.data).toEqual(goodData);
|
||||
|
||||
// const badResult = await unknownSchema.safeParseAsync(badData);
|
||||
// expect(badResult.success).toBe(false);
|
||||
// if (!badResult.success) expect(badResult.error).toBeInstanceOf(z.ZodError);
|
||||
});
|
||||
|
||||
/// void
|
||||
const voidSchema = z.void();
|
||||
test("void async parse", async () => {
|
||||
const goodData = undefined;
|
||||
const badData = 0;
|
||||
|
||||
const goodResult = await voidSchema.safeParseAsync(goodData);
|
||||
expect(goodResult.success).toBe(true);
|
||||
if (goodResult.success) expect(goodResult.data).toEqual(goodData);
|
||||
|
||||
const badResult = await voidSchema.safeParseAsync(badData);
|
||||
expect(badResult.success).toBe(false);
|
||||
if (!badResult.success) expect(badResult.error).toBeInstanceOf(z.ZodError);
|
||||
});
|
||||
|
||||
/// array
|
||||
const arraySchema = z.array(z.string());
|
||||
test("array async parse", async () => {
|
||||
const goodData = ["XXX"];
|
||||
const badData = "XXX";
|
||||
|
||||
const goodResult = await arraySchema.safeParseAsync(goodData);
|
||||
expect(goodResult.success).toBe(true);
|
||||
if (goodResult.success) expect(goodResult.data).toEqual(goodData);
|
||||
|
||||
const badResult = await arraySchema.safeParseAsync(badData);
|
||||
expect(badResult.success).toBe(false);
|
||||
if (!badResult.success) expect(badResult.error).toBeInstanceOf(z.ZodError);
|
||||
});
|
||||
|
||||
/// object
|
||||
const objectSchema = z.object({ string: z.string() });
|
||||
test("object async parse", async () => {
|
||||
const goodData = { string: "XXX" };
|
||||
const badData = { string: 12 };
|
||||
|
||||
const goodResult = await objectSchema.safeParseAsync(goodData);
|
||||
expect(goodResult.success).toBe(true);
|
||||
if (goodResult.success) expect(goodResult.data).toEqual(goodData);
|
||||
|
||||
const badResult = await objectSchema.safeParseAsync(badData);
|
||||
expect(badResult.success).toBe(false);
|
||||
if (!badResult.success) expect(badResult.error).toBeInstanceOf(z.ZodError);
|
||||
});
|
||||
|
||||
/// union
|
||||
const unionSchema = z.union([z.string(), z.undefined()]);
|
||||
test("union async parse", async () => {
|
||||
const goodData = undefined;
|
||||
const badData = null;
|
||||
|
||||
const goodResult = await unionSchema.safeParseAsync(goodData);
|
||||
expect(goodResult.success).toBe(true);
|
||||
if (goodResult.success) expect(goodResult.data).toEqual(goodData);
|
||||
|
||||
const badResult = await unionSchema.safeParseAsync(badData);
|
||||
expect(badResult.success).toBe(false);
|
||||
if (!badResult.success) expect(badResult.error).toBeInstanceOf(z.ZodError);
|
||||
});
|
||||
|
||||
/// record
|
||||
const recordSchema = z.record(z.object({}));
|
||||
test("record async parse", async () => {
|
||||
const goodData = { adsf: {}, asdf: {} };
|
||||
const badData = [{}];
|
||||
|
||||
const goodResult = await recordSchema.safeParseAsync(goodData);
|
||||
expect(goodResult.success).toBe(true);
|
||||
if (goodResult.success) expect(goodResult.data).toEqual(goodData);
|
||||
|
||||
const badResult = await recordSchema.safeParseAsync(badData);
|
||||
expect(badResult.success).toBe(false);
|
||||
if (!badResult.success) expect(badResult.error).toBeInstanceOf(z.ZodError);
|
||||
});
|
||||
|
||||
/// function
|
||||
const functionSchema = z.function();
|
||||
test("function async parse", async () => {
|
||||
const goodData = () => {};
|
||||
const badData = "XXX";
|
||||
|
||||
const goodResult = await functionSchema.safeParseAsync(goodData);
|
||||
expect(goodResult.success).toBe(true);
|
||||
if (goodResult.success) expect(typeof goodResult.data).toEqual("function");
|
||||
|
||||
const badResult = await functionSchema.safeParseAsync(badData);
|
||||
expect(badResult.success).toBe(false);
|
||||
if (!badResult.success) expect(badResult.error).toBeInstanceOf(z.ZodError);
|
||||
});
|
||||
|
||||
/// literal
|
||||
const literalSchema = z.literal("asdf");
|
||||
test("literal async parse", async () => {
|
||||
const goodData = "asdf";
|
||||
const badData = "asdff";
|
||||
|
||||
const goodResult = await literalSchema.safeParseAsync(goodData);
|
||||
expect(goodResult.success).toBe(true);
|
||||
if (goodResult.success) expect(goodResult.data).toEqual(goodData);
|
||||
|
||||
const badResult = await literalSchema.safeParseAsync(badData);
|
||||
expect(badResult.success).toBe(false);
|
||||
if (!badResult.success) expect(badResult.error).toBeInstanceOf(z.ZodError);
|
||||
});
|
||||
|
||||
/// enum
|
||||
const enumSchema = z.enum(["fish", "whale"]);
|
||||
test("enum async parse", async () => {
|
||||
const goodData = "whale";
|
||||
const badData = "leopard";
|
||||
|
||||
const goodResult = await enumSchema.safeParseAsync(goodData);
|
||||
expect(goodResult.success).toBe(true);
|
||||
if (goodResult.success) expect(goodResult.data).toEqual(goodData);
|
||||
|
||||
const badResult = await enumSchema.safeParseAsync(badData);
|
||||
expect(badResult.success).toBe(false);
|
||||
if (!badResult.success) expect(badResult.error).toBeInstanceOf(z.ZodError);
|
||||
});
|
||||
|
||||
/// nativeEnum
|
||||
enum nativeEnumTest {
|
||||
asdf = "qwer",
|
||||
}
|
||||
// @ts-ignore
|
||||
const nativeEnumSchema = z.nativeEnum(nativeEnumTest);
|
||||
test("nativeEnum async parse", async () => {
|
||||
const goodData = nativeEnumTest.asdf;
|
||||
const badData = "asdf";
|
||||
|
||||
const goodResult = await nativeEnumSchema.safeParseAsync(goodData);
|
||||
expect(goodResult.success).toBe(true);
|
||||
if (goodResult.success) expect(goodResult.data).toEqual(goodData);
|
||||
|
||||
const badResult = await nativeEnumSchema.safeParseAsync(badData);
|
||||
expect(badResult.success).toBe(false);
|
||||
if (!badResult.success) expect(badResult.error).toBeInstanceOf(z.ZodError);
|
||||
});
|
||||
|
||||
/// promise
|
||||
const promiseSchema = z.promise(z.number());
|
||||
test("promise async parse good", async () => {
|
||||
const goodData = Promise.resolve(123);
|
||||
|
||||
const goodResult = await promiseSchema.safeParseAsync(goodData);
|
||||
expect(goodResult.success).toBe(true);
|
||||
if (goodResult.success) {
|
||||
expect(goodResult.data).toBeInstanceOf(Promise);
|
||||
const data = await goodResult.data;
|
||||
expect(data).toEqual(123);
|
||||
// expect(goodResult.data).resolves.toEqual(124);
|
||||
// return goodResult.data;
|
||||
} else {
|
||||
throw new Error("success should be true");
|
||||
}
|
||||
});
|
||||
|
||||
test("promise async parse bad", async () => {
|
||||
const badData = Promise.resolve("XXX");
|
||||
const badResult = await promiseSchema.safeParseAsync(badData);
|
||||
expect(badResult.success).toBe(true);
|
||||
if (badResult.success) {
|
||||
await expect(badResult.data).rejects.toBeInstanceOf(z.ZodError);
|
||||
} else {
|
||||
throw new Error("success should be true");
|
||||
}
|
||||
});
|
||||
|
||||
test("async validation non-empty strings", async () => {
|
||||
const base = z.object({
|
||||
hello: z.string().refine((x) => x && x.length > 0),
|
||||
foo: z.string().refine((x) => x && x.length > 0),
|
||||
});
|
||||
|
||||
const testval = { hello: "", foo: "" };
|
||||
const result1 = base.safeParse(testval);
|
||||
const result2 = base.safeParseAsync(testval);
|
||||
|
||||
const r1 = result1;
|
||||
await result2.then((r2) => {
|
||||
if (r1.success === false && r2.success === false) expect(r1.error.issues.length).toBe(r2.error.issues.length); // <--- r1 has length 2, r2 has length 1
|
||||
});
|
||||
});
|
||||
|
||||
test("async validation multiple errors 1", async () => {
|
||||
const base = z.object({
|
||||
hello: z.string(),
|
||||
foo: z.number(),
|
||||
});
|
||||
|
||||
const testval = { hello: 3, foo: "hello" };
|
||||
const result1 = base.safeParse(testval);
|
||||
const result2 = base.safeParseAsync(testval);
|
||||
|
||||
const r1 = result1;
|
||||
await result2.then((r2) => {
|
||||
if (r1.success === false && r2.success === false) expect(r2.error.issues.length).toBe(r1.error.issues.length);
|
||||
});
|
||||
});
|
||||
|
||||
test("async validation multiple errors 2", async () => {
|
||||
const base = (is_async?: boolean) =>
|
||||
z.object({
|
||||
hello: z.string(),
|
||||
foo: z.object({
|
||||
bar: z.number().refine(is_async ? async () => false : () => false),
|
||||
}),
|
||||
});
|
||||
|
||||
const testval = { hello: 3, foo: { bar: 4 } };
|
||||
const result1 = base().safeParse(testval);
|
||||
const result2 = base(true).safeParseAsync(testval);
|
||||
|
||||
const r1 = result1;
|
||||
await result2.then((r2) => {
|
||||
if (r1.success === false && r2.success === false) expect(r2.error.issues.length).toBe(r1.error.issues.length);
|
||||
});
|
||||
});
|
||||
|
||||
test("ensure early async failure prevents follow-up refinement checks", async () => {
|
||||
let count = 0;
|
||||
const base = z.object({
|
||||
hello: z.string(),
|
||||
foo: z
|
||||
.number()
|
||||
.refine(async () => {
|
||||
count++;
|
||||
return true;
|
||||
})
|
||||
.refine(async () => {
|
||||
count++;
|
||||
return true;
|
||||
}, "Good"),
|
||||
});
|
||||
|
||||
const testval = { hello: "bye", foo: 3 };
|
||||
const result = await base.safeParseAsync(testval);
|
||||
if (result.success === false) {
|
||||
expect(result.error.issues.length).toBe(1);
|
||||
expect(count).toBe(1);
|
||||
}
|
||||
|
||||
// await result.then((r) => {
|
||||
// if (r.success === false) expect(r.error.issues.length).toBe(1);
|
||||
// expect(count).toBe(2);
|
||||
// });
|
||||
});
|
||||
@@ -0,0 +1,47 @@
|
||||
import {PublicKey} from '../publickey';
|
||||
|
||||
export * from './account-keys';
|
||||
// note: compiled-keys is internal and doesn't need to be exported
|
||||
export * from './legacy';
|
||||
export * from './versioned';
|
||||
export * from './v0';
|
||||
|
||||
/**
|
||||
* The message header, identifying signed and read-only account
|
||||
*/
|
||||
export type MessageHeader = {
|
||||
/**
|
||||
* The number of signatures required for this message to be considered valid. The
|
||||
* signatures must match the first `numRequiredSignatures` of `accountKeys`.
|
||||
*/
|
||||
numRequiredSignatures: number;
|
||||
/** The last `numReadonlySignedAccounts` of the signed keys are read-only accounts */
|
||||
numReadonlySignedAccounts: number;
|
||||
/** The last `numReadonlySignedAccounts` of the unsigned keys are read-only accounts */
|
||||
numReadonlyUnsignedAccounts: number;
|
||||
};
|
||||
|
||||
/**
|
||||
* An address table lookup used to load additional accounts
|
||||
*/
|
||||
export type MessageAddressTableLookup = {
|
||||
accountKey: PublicKey;
|
||||
writableIndexes: Array<number>;
|
||||
readonlyIndexes: Array<number>;
|
||||
};
|
||||
|
||||
/**
|
||||
* An instruction to execute by a program
|
||||
*
|
||||
* @property {number} programIdIndex
|
||||
* @property {number[]} accountKeyIndexes
|
||||
* @property {Uint8Array} data
|
||||
*/
|
||||
export type MessageCompiledInstruction = {
|
||||
/** Index into the transaction keys array indicating the program account that executes this instruction */
|
||||
programIdIndex: number;
|
||||
/** Ordered indices into the transaction keys array indicating which accounts to pass to the program */
|
||||
accountKeyIndexes: number[];
|
||||
/** The program input data */
|
||||
data: Uint8Array;
|
||||
};
|
||||
@@ -0,0 +1,3 @@
|
||||
import type { ParserServicesWithTypeInformation, TSESTree } from '@typescript-eslint/utils';
|
||||
import type { RuleContext } from '@typescript-eslint/utils/ts-eslint';
|
||||
export declare function isArrayMethodCallWithPredicate(context: RuleContext<string, unknown[]>, services: ParserServicesWithTypeInformation, node: TSESTree.CallExpression): boolean;
|
||||
@@ -0,0 +1,6 @@
|
||||
"use strict";
|
||||
|
||||
function _write_only_error(name) {
|
||||
throw new TypeError("\"" + name + "\" is write-only");
|
||||
}
|
||||
exports._ = _write_only_error;
|
||||
@@ -0,0 +1,138 @@
|
||||
/**
|
||||
* @preserve
|
||||
* JS Implementation of incremental MurmurHash3 (r150) (as of May 10, 2013)
|
||||
*
|
||||
* @author <a href="mailto:jensyt@gmail.com">Jens Taylor</a>
|
||||
* @see http://github.com/homebrewing/brauhaus-diff
|
||||
* @author <a href="mailto:gary.court@gmail.com">Gary Court</a>
|
||||
* @see http://github.com/garycourt/murmurhash-js
|
||||
* @author <a href="mailto:aappleby@gmail.com">Austin Appleby</a>
|
||||
* @see http://sites.google.com/site/murmurhash/
|
||||
*/
|
||||
(function(){
|
||||
var cache;
|
||||
|
||||
// Call this function without `new` to use the cached object (good for
|
||||
// single-threaded environments), or with `new` to create a new object.
|
||||
//
|
||||
// @param {string} key A UTF-16 or ASCII string
|
||||
// @param {number} seed An optional positive integer
|
||||
// @return {object} A MurmurHash3 object for incremental hashing
|
||||
function MurmurHash3(key, seed) {
|
||||
var m = this instanceof MurmurHash3 ? this : cache;
|
||||
m.reset(seed)
|
||||
if (typeof key === 'string' && key.length > 0) {
|
||||
m.hash(key);
|
||||
}
|
||||
|
||||
if (m !== this) {
|
||||
return m;
|
||||
}
|
||||
};
|
||||
|
||||
// Incrementally add a string to this hash
|
||||
//
|
||||
// @param {string} key A UTF-16 or ASCII string
|
||||
// @return {object} this
|
||||
MurmurHash3.prototype.hash = function(key) {
|
||||
var h1, k1, i, top, len;
|
||||
|
||||
len = key.length;
|
||||
this.len += len;
|
||||
|
||||
k1 = this.k1;
|
||||
i = 0;
|
||||
switch (this.rem) {
|
||||
case 0: k1 ^= len > i ? (key.charCodeAt(i++) & 0xffff) : 0;
|
||||
case 1: k1 ^= len > i ? (key.charCodeAt(i++) & 0xffff) << 8 : 0;
|
||||
case 2: k1 ^= len > i ? (key.charCodeAt(i++) & 0xffff) << 16 : 0;
|
||||
case 3:
|
||||
k1 ^= len > i ? (key.charCodeAt(i) & 0xff) << 24 : 0;
|
||||
k1 ^= len > i ? (key.charCodeAt(i++) & 0xff00) >> 8 : 0;
|
||||
}
|
||||
|
||||
this.rem = (len + this.rem) & 3; // & 3 is same as % 4
|
||||
len -= this.rem;
|
||||
if (len > 0) {
|
||||
h1 = this.h1;
|
||||
while (1) {
|
||||
k1 = (k1 * 0x2d51 + (k1 & 0xffff) * 0xcc9e0000) & 0xffffffff;
|
||||
k1 = (k1 << 15) | (k1 >>> 17);
|
||||
k1 = (k1 * 0x3593 + (k1 & 0xffff) * 0x1b870000) & 0xffffffff;
|
||||
|
||||
h1 ^= k1;
|
||||
h1 = (h1 << 13) | (h1 >>> 19);
|
||||
h1 = (h1 * 5 + 0xe6546b64) & 0xffffffff;
|
||||
|
||||
if (i >= len) {
|
||||
break;
|
||||
}
|
||||
|
||||
k1 = ((key.charCodeAt(i++) & 0xffff)) ^
|
||||
((key.charCodeAt(i++) & 0xffff) << 8) ^
|
||||
((key.charCodeAt(i++) & 0xffff) << 16);
|
||||
top = key.charCodeAt(i++);
|
||||
k1 ^= ((top & 0xff) << 24) ^
|
||||
((top & 0xff00) >> 8);
|
||||
}
|
||||
|
||||
k1 = 0;
|
||||
switch (this.rem) {
|
||||
case 3: k1 ^= (key.charCodeAt(i + 2) & 0xffff) << 16;
|
||||
case 2: k1 ^= (key.charCodeAt(i + 1) & 0xffff) << 8;
|
||||
case 1: k1 ^= (key.charCodeAt(i) & 0xffff);
|
||||
}
|
||||
|
||||
this.h1 = h1;
|
||||
}
|
||||
|
||||
this.k1 = k1;
|
||||
return this;
|
||||
};
|
||||
|
||||
// Get the result of this hash
|
||||
//
|
||||
// @return {number} The 32-bit hash
|
||||
MurmurHash3.prototype.result = function() {
|
||||
var k1, h1;
|
||||
|
||||
k1 = this.k1;
|
||||
h1 = this.h1;
|
||||
|
||||
if (k1 > 0) {
|
||||
k1 = (k1 * 0x2d51 + (k1 & 0xffff) * 0xcc9e0000) & 0xffffffff;
|
||||
k1 = (k1 << 15) | (k1 >>> 17);
|
||||
k1 = (k1 * 0x3593 + (k1 & 0xffff) * 0x1b870000) & 0xffffffff;
|
||||
h1 ^= k1;
|
||||
}
|
||||
|
||||
h1 ^= this.len;
|
||||
|
||||
h1 ^= h1 >>> 16;
|
||||
h1 = (h1 * 0xca6b + (h1 & 0xffff) * 0x85eb0000) & 0xffffffff;
|
||||
h1 ^= h1 >>> 13;
|
||||
h1 = (h1 * 0xae35 + (h1 & 0xffff) * 0xc2b20000) & 0xffffffff;
|
||||
h1 ^= h1 >>> 16;
|
||||
|
||||
return h1 >>> 0;
|
||||
};
|
||||
|
||||
// Reset the hash object for reuse
|
||||
//
|
||||
// @param {number} seed An optional positive integer
|
||||
MurmurHash3.prototype.reset = function(seed) {
|
||||
this.h1 = typeof seed === 'number' ? seed : 0;
|
||||
this.rem = this.k1 = this.len = 0;
|
||||
return this;
|
||||
};
|
||||
|
||||
// A cached object to use. This can be safely used if you're in a single-
|
||||
// threaded environment, otherwise you need to create new hashes to use.
|
||||
cache = new MurmurHash3();
|
||||
|
||||
if (typeof(module) != 'undefined') {
|
||||
module.exports = MurmurHash3;
|
||||
} else {
|
||||
this.MurmurHash3 = MurmurHash3;
|
||||
}
|
||||
}());
|
||||
@@ -0,0 +1,149 @@
|
||||
declare module "node:timers" {
|
||||
import { Abortable } from "node:events";
|
||||
import * as promises from "node:timers/promises";
|
||||
export interface TimerOptions extends Abortable {
|
||||
/**
|
||||
* Set to `false` to indicate that the scheduled `Timeout`
|
||||
* should not require the Node.js event loop to remain active.
|
||||
* @default true
|
||||
*/
|
||||
ref?: boolean | undefined;
|
||||
}
|
||||
global {
|
||||
namespace NodeJS {
|
||||
/**
|
||||
* This object is created internally and is returned from `setImmediate()`. It
|
||||
* can be passed to `clearImmediate()` in order to cancel the scheduled
|
||||
* actions.
|
||||
*
|
||||
* By default, when an immediate is scheduled, the Node.js event loop will continue
|
||||
* running as long as the immediate is active. The `Immediate` object returned by
|
||||
* `setImmediate()` exports both `immediate.ref()` and `immediate.unref()`
|
||||
* functions that can be used to control this default behavior.
|
||||
*/
|
||||
interface Immediate extends RefCounted, Disposable {
|
||||
/**
|
||||
* If true, the `Immediate` object will keep the Node.js event loop active.
|
||||
* @since v11.0.0
|
||||
*/
|
||||
hasRef(): boolean;
|
||||
/**
|
||||
* When called, requests that the Node.js event loop _not_ exit so long as the
|
||||
* `Immediate` is active. Calling `immediate.ref()` multiple times will have no
|
||||
* effect.
|
||||
*
|
||||
* By default, all `Immediate` objects are "ref'ed", making it normally unnecessary
|
||||
* to call `immediate.ref()` unless `immediate.unref()` had been called previously.
|
||||
* @since v9.7.0
|
||||
* @returns a reference to `immediate`
|
||||
*/
|
||||
ref(): this;
|
||||
/**
|
||||
* When called, the active `Immediate` object will not require the Node.js event
|
||||
* loop to remain active. If there is no other activity keeping the event loop
|
||||
* running, the process may exit before the `Immediate` object's callback is
|
||||
* invoked. Calling `immediate.unref()` multiple times will have no effect.
|
||||
* @since v9.7.0
|
||||
* @returns a reference to `immediate`
|
||||
*/
|
||||
unref(): this;
|
||||
/**
|
||||
* Cancels the immediate. This is similar to calling `clearImmediate()`.
|
||||
* @since v20.5.0, v18.18.0
|
||||
*/
|
||||
[Symbol.dispose](): void;
|
||||
_onImmediate(...args: any[]): void;
|
||||
}
|
||||
// Legacy interface used in Node.js v9 and prior
|
||||
// TODO: remove in a future major version bump
|
||||
/** @deprecated Use `NodeJS.Timeout` instead. */
|
||||
interface Timer extends RefCounted {
|
||||
hasRef(): boolean;
|
||||
refresh(): this;
|
||||
[Symbol.toPrimitive](): number;
|
||||
}
|
||||
/**
|
||||
* This object is created internally and is returned from `setTimeout()` and
|
||||
* `setInterval()`. It can be passed to either `clearTimeout()` or
|
||||
* `clearInterval()` in order to cancel the scheduled actions.
|
||||
*
|
||||
* By default, when a timer is scheduled using either `setTimeout()` or
|
||||
* `setInterval()`, the Node.js event loop will continue running as long as the
|
||||
* timer is active. Each of the `Timeout` objects returned by these functions
|
||||
* export both `timeout.ref()` and `timeout.unref()` functions that can be used to
|
||||
* control this default behavior.
|
||||
*/
|
||||
interface Timeout extends RefCounted, Disposable, Timer {
|
||||
/**
|
||||
* Cancels the timeout.
|
||||
* @since v0.9.1
|
||||
* @legacy Use `clearTimeout()` instead.
|
||||
* @returns a reference to `timeout`
|
||||
*/
|
||||
close(): this;
|
||||
/**
|
||||
* If true, the `Timeout` object will keep the Node.js event loop active.
|
||||
* @since v11.0.0
|
||||
*/
|
||||
hasRef(): boolean;
|
||||
/**
|
||||
* When called, requests that the Node.js event loop _not_ exit so long as the
|
||||
* `Timeout` is active. Calling `timeout.ref()` multiple times will have no effect.
|
||||
*
|
||||
* By default, all `Timeout` objects are "ref'ed", making it normally unnecessary
|
||||
* to call `timeout.ref()` unless `timeout.unref()` had been called previously.
|
||||
* @since v0.9.1
|
||||
* @returns a reference to `timeout`
|
||||
*/
|
||||
ref(): this;
|
||||
/**
|
||||
* Sets the timer's start time to the current time, and reschedules the timer to
|
||||
* call its callback at the previously specified duration adjusted to the current
|
||||
* time. This is useful for refreshing a timer without allocating a new
|
||||
* JavaScript object.
|
||||
*
|
||||
* Using this on a timer that has already called its callback will reactivate the
|
||||
* timer.
|
||||
* @since v10.2.0
|
||||
* @returns a reference to `timeout`
|
||||
*/
|
||||
refresh(): this;
|
||||
/**
|
||||
* When called, the active `Timeout` object will not require the Node.js event loop
|
||||
* to remain active. If there is no other activity keeping the event loop running,
|
||||
* the process may exit before the `Timeout` object's callback is invoked. Calling
|
||||
* `timeout.unref()` multiple times will have no effect.
|
||||
* @since v0.9.1
|
||||
* @returns a reference to `timeout`
|
||||
*/
|
||||
unref(): this;
|
||||
/**
|
||||
* Coerce a `Timeout` to a primitive. The primitive can be used to
|
||||
* clear the `Timeout`. The primitive can only be used in the
|
||||
* same thread where the timeout was created. Therefore, to use it
|
||||
* across `worker_threads` it must first be passed to the correct
|
||||
* thread. This allows enhanced compatibility with browser
|
||||
* `setTimeout()` and `setInterval()` implementations.
|
||||
* @since v14.9.0, v12.19.0
|
||||
*/
|
||||
[Symbol.toPrimitive](): number;
|
||||
/**
|
||||
* Cancels the timeout.
|
||||
* @since v20.5.0, v18.18.0
|
||||
*/
|
||||
[Symbol.dispose](): void;
|
||||
_onTimeout(...args: any[]): void;
|
||||
}
|
||||
}
|
||||
}
|
||||
import clearImmediate = globalThis.clearImmediate;
|
||||
import clearInterval = globalThis.clearInterval;
|
||||
import clearTimeout = globalThis.clearTimeout;
|
||||
import setImmediate = globalThis.setImmediate;
|
||||
import setInterval = globalThis.setInterval;
|
||||
import setTimeout = globalThis.setTimeout;
|
||||
export { clearImmediate, clearInterval, clearTimeout, promises, setImmediate, setInterval, setTimeout };
|
||||
}
|
||||
declare module "timers" {
|
||||
export * from "node:timers";
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.createProjectProgram = createProjectProgram;
|
||||
const debug_1 = __importDefault(require("debug"));
|
||||
const node_utils_1 = require("../node-utils");
|
||||
const createProjectProgramError_1 = require("./createProjectProgramError");
|
||||
const shared_1 = require("./shared");
|
||||
const log = (0, debug_1.default)('typescript-eslint:typescript-estree:create-program:createProjectProgram');
|
||||
/**
|
||||
* @param parseSettings Internal settings for parsing the file
|
||||
* @returns If found, the source file corresponding to the code and the containing program
|
||||
*/
|
||||
function createProjectProgram(parseSettings, programsForProjects) {
|
||||
log('Creating project program for: %s', parseSettings.filePath);
|
||||
const astAndProgram = (0, node_utils_1.firstDefined)(programsForProjects, currentProgram => (0, shared_1.getAstFromProgram)(currentProgram, parseSettings.filePath));
|
||||
if (!astAndProgram) {
|
||||
throw new Error((0, createProjectProgramError_1.createProjectProgramError)(parseSettings, programsForProjects).join('\n'));
|
||||
}
|
||||
return astAndProgram;
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
let urlAlphabet =
|
||||
'useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict'
|
||||
|
||||
export { urlAlphabet }
|
||||
@@ -0,0 +1,35 @@
|
||||
{
|
||||
"keys-while": {
|
||||
"name": "keys-while",
|
||||
"browser": "IE 11.0.0 (Windows 7 0.0.0)",
|
||||
"suite": "iter",
|
||||
"hz": 41364.6571228128,
|
||||
"success": true,
|
||||
"fastest": true,
|
||||
"rme": 0.019812279223258095,
|
||||
"rhz": 1,
|
||||
"sampleSize": 168
|
||||
},
|
||||
"keys-for": {
|
||||
"name": "keys-for",
|
||||
"browser": "IE 11.0.0 (Windows 7 0.0.0)",
|
||||
"suite": "iter",
|
||||
"hz": 39608.00547823607,
|
||||
"success": true,
|
||||
"fastest": false,
|
||||
"rme": 0.017923341293839844,
|
||||
"rhz": 0.9575325467013739,
|
||||
"sampleSize": 169
|
||||
},
|
||||
"incr-for": {
|
||||
"name": "incr-for",
|
||||
"browser": "IE 11.0.0 (Windows 7 0.0.0)",
|
||||
"suite": "iter",
|
||||
"hz": 15804.911836102421,
|
||||
"success": true,
|
||||
"fastest": false,
|
||||
"rme": 0.019576578880425893,
|
||||
"rhz": 0.3820873406293978,
|
||||
"sampleSize": 170
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,5 @@
|
||||
var assertClassBrand = require("./assertClassBrand.js");
|
||||
function _classStaticPrivateMethodGet(s, a, t) {
|
||||
return assertClassBrand(a, s), t;
|
||||
}
|
||||
module.exports = _classStaticPrivateMethodGet, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
||||
@@ -0,0 +1,359 @@
|
||||
/**
|
||||
* @fileoverview HTML reporter
|
||||
* @author Julian Laval
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Helpers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
const encodeHTML = (function () {
|
||||
const encodeHTMLRules = {
|
||||
"&": "&",
|
||||
"<": "<",
|
||||
">": ">",
|
||||
'"': """,
|
||||
"'": "'",
|
||||
};
|
||||
const matchHTML = /[&<>"']/gu;
|
||||
|
||||
return function (code) {
|
||||
return code
|
||||
? code.toString().replace(matchHTML, m => encodeHTMLRules[m] || m)
|
||||
: "";
|
||||
};
|
||||
})();
|
||||
|
||||
/**
|
||||
* Get the final HTML document.
|
||||
* @param {Object} it data for the document.
|
||||
* @returns {string} HTML document.
|
||||
*/
|
||||
function pageTemplate(it) {
|
||||
const { reportColor, reportSummary, date, results } = it;
|
||||
|
||||
return `
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>ESLint Report</title>
|
||||
<link rel="icon" type="image/png" sizes="any" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAACXBIWXMAAAHaAAAB2gGFomX7AAAAGXRFWHRTb2Z0d2FyZQB3d3cuaW5rc2NhcGUub3Jnm+48GgAABD1JREFUWMPFl11sk2UUx3/nbYtjxS1MF7MLMTECMgSTtSSyrQkLhAj7UBPnDSEGoxegGzMwojhXVpmTAA5iYpSoMQa8GBhFOrMFk03buei6yRAlcmOM0SEmU9d90b19jxcM1o5+sGnsc/e+z/l6ztf/HFFVMnns6QieeOCHBePGsHM+wrOtvLG2C4WRVDSSygNV7sCjlspxwDnPB44aols/DXk+mbMBmx/6OseITF1CuOtfevkPh2Uu+/jbdX8lujSScRlT5r7/QDlAfsRmfzmpnkQ/H3H13gf6bBrBn1uqK8WylgEnU8eZmk1repbfchJG1TyKyIKEwuBHFd3lD3naY3O1siiwXsVoBV2VgM1ht/QQUJk2ByqKghsQziYQ8ifKgexIXmuyzC4r67Y7R+xPAfuB/Nn3Cpva+0s7khpQVtZtd4bt51BWxtBYAiciprG7c7D4SixzU9PYalDL6110Ifb/w8W9eY7JqFeFHbO8fPGyLHwwFHJNJTSgwtVTB9oaw9BlQ+tO93vOxypoaQnfEYlI43SeCHDC4TDq9+51/h5fxr33q0ZfV9g04wat9Q943rjJgCp3952W2i8Bi6eDvdsfKj0cK/DYMRyXL4/sUJUmIHd2zYMezsvLaamp4WpcWN3BXSiHpuMwbGbZlnZ8tXY4rgosy+G7oRwQ0cAsd28YGgqfU5UjCZQDLALxDg+Hv/P5Rqvj4hwrS8izXzWb4spwc1GgENFnkpWRzxeuB+ssUHgLdb9UVdt8vpGdKQpze7n7y1U3DBChNRUuqOo9c+0+qpKKxyZqtAIYla7gY4JszAAQri93BSsMRZoyBcUC+w3Q3AyOA4sNhAOZ0q7Iq0b2vUNvK5zPgP+/H8+Zetdoa6uOikhdGurxebwvJY8Iz3V1rTMNAH+opEuQj5KTT/qA1yC+wyUjBm12OidaUtCcPNNX2h0Hx2JG69VulANZAJZJwfU7rzd/FHixuXniTdM0m4GtSQT7bTartqEh9yfImUEzkwKZmTwmo5a5JwkYBfcDL01/RkR5y8iWhtPBknB8ZxwtU9UjwOrrKCeizzc25nTGg1F/turEHoU9wMLpDvWKf8DTmNCAKnd/tqUTF4ElMXJ+A5rWDJS+41WsGWzALhJ+ErBWrLj9g+pqojHxlXJX8HGUg0BsR/x1yhxf3jm4cSzpQFLp6tmi6PEE7g1ZhtZ91ufpSZUAFa6gC+UoQslNaSmypT1U8mHKiUgEKS8KfgF4EpYunFI16tsHin+OG0LcgQK7yj7g6cSzpva2D3hKVNG0Y3mVO1BkqfSlmJrHBQ4uvM12gJHc6ETW8HZVfMRmXvyxxNC1Z/o839zyXlDuCr4nsC11J+MXueaVJWn6yPv+/pJtc9oLTNN4AeTvNGByd3rlhE2x9s5pLwDoHCy+grDzWmOZ95lUtLYj5Bma126Y8eX0/zj/ADxGyViSg4BXAAAAAElFTkSuQmCC">
|
||||
<link rel="icon" type="image/svg+xml" href="data:image/svg+xml;base64,PHN2ZyB2aWV3Qm94PScwIDAgMjk0LjgyNSAyNTguOTgyJyB4bWxucz0naHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmcnPg0KPHBhdGggZmlsbD0nIzgwODBGMicgZD0nTTk3LjAyMSw5OS4wMTZsNDguNDMyLTI3Ljk2MmMxLjIxMi0wLjcsMi43MDYtMC43LDMuOTE4LDBsNDguNDMzLDI3Ljk2MiBjMS4yMTEsMC43LDEuOTU5LDEuOTkzLDEuOTU5LDMuMzkzdjU1LjkyNGMwLDEuMzk5LTAuNzQ4LDIuNjkzLTEuOTU5LDMuMzk0bC00OC40MzMsMjcuOTYyYy0xLjIxMiwwLjctMi43MDYsMC43LTMuOTE4LDAgbC00OC40MzItMjcuOTYyYy0xLjIxMi0wLjctMS45NTktMS45OTQtMS45NTktMy4zOTR2LTU1LjkyNEM5NS4wNjMsMTAxLjAwOSw5NS44MSw5OS43MTYsOTcuMDIxLDk5LjAxNicvPg0KPHBhdGggZmlsbD0nIzRCMzJDMycgZD0nTTI3My4zMzYsMTI0LjQ4OEwyMTUuNDY5LDIzLjgxNmMtMi4xMDItMy42NC01Ljk4NS02LjMyNS0xMC4xODgtNi4zMjVIODkuNTQ1IGMtNC4yMDQsMC04LjA4OCwyLjY4NS0xMC4xOSw2LjMyNWwtNTcuODY3LDEwMC40NWMtMi4xMDIsMy42NDEtMi4xMDIsOC4yMzYsMCwxMS44NzdsNTcuODY3LDk5Ljg0NyBjMi4xMDIsMy42NCw1Ljk4Niw1LjUwMSwxMC4xOSw1LjUwMWgxMTUuNzM1YzQuMjAzLDAsOC4wODctMS44MDUsMTAuMTg4LTUuNDQ2bDU3Ljg2Ny0xMDAuMDEgQzI3NS40MzksMTMyLjM5NiwyNzUuNDM5LDEyOC4xMjgsMjczLjMzNiwxMjQuNDg4IE0yMjUuNDE5LDE3Mi44OThjMCwxLjQ4LTAuODkxLDIuODQ5LTIuMTc0LDMuNTlsLTczLjcxLDQyLjUyNyBjLTEuMjgyLDAuNzQtMi44ODgsMC43NC00LjE3LDBsLTczLjc2Ny00Mi41MjdjLTEuMjgyLTAuNzQxLTIuMTc5LTIuMTA5LTIuMTc5LTMuNTlWODcuODQzYzAtMS40ODEsMC44ODQtMi44NDksMi4xNjctMy41OSBsNzMuNzA3LTQyLjUyN2MxLjI4Mi0wLjc0MSwyLjg4Ni0wLjc0MSw0LjE2OCwwbDczLjc3Miw0Mi41MjdjMS4yODMsMC43NDEsMi4xODYsMi4xMDksMi4xODYsMy41OVYxNzIuODk4eicvPg0KPC9zdmc+">
|
||||
<style>
|
||||
body {
|
||||
font-family: Arial, "Helvetica Neue", Helvetica, sans-serif;
|
||||
font-size: 16px;
|
||||
font-weight: normal;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
#overview {
|
||||
padding: 20px 30px;
|
||||
}
|
||||
|
||||
td,
|
||||
th {
|
||||
padding: 5px 10px;
|
||||
}
|
||||
|
||||
h1 {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
table {
|
||||
margin: 30px;
|
||||
width: calc(100% - 60px);
|
||||
max-width: 1000px;
|
||||
border-radius: 5px;
|
||||
border: 1px solid #ddd;
|
||||
border-spacing: 0;
|
||||
}
|
||||
|
||||
th {
|
||||
font-weight: 400;
|
||||
font-size: medium;
|
||||
text-align: left;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
td.clr-1,
|
||||
td.clr-2,
|
||||
th span {
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
th span {
|
||||
float: right;
|
||||
margin-left: 20px;
|
||||
}
|
||||
|
||||
th span::after {
|
||||
content: "";
|
||||
clear: both;
|
||||
display: block;
|
||||
}
|
||||
|
||||
tr:last-child td {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
tr td:first-child,
|
||||
tr td:last-child {
|
||||
color: #9da0a4;
|
||||
}
|
||||
|
||||
#overview.bg-0,
|
||||
tr.bg-0 th {
|
||||
color: #468847;
|
||||
background: #dff0d8;
|
||||
border-bottom: 1px solid #d6e9c6;
|
||||
}
|
||||
|
||||
#overview.bg-1,
|
||||
tr.bg-1 th {
|
||||
color: #f0ad4e;
|
||||
background: #fcf8e3;
|
||||
border-bottom: 1px solid #fbeed5;
|
||||
}
|
||||
|
||||
#overview.bg-2,
|
||||
tr.bg-2 th {
|
||||
color: #b94a48;
|
||||
background: #f2dede;
|
||||
border-bottom: 1px solid #eed3d7;
|
||||
}
|
||||
|
||||
td {
|
||||
border-bottom: 1px solid #ddd;
|
||||
}
|
||||
|
||||
td.clr-1 {
|
||||
color: #f0ad4e;
|
||||
}
|
||||
|
||||
td.clr-2 {
|
||||
color: #b94a48;
|
||||
}
|
||||
|
||||
td a {
|
||||
color: #3a33d1;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
td a:hover {
|
||||
color: #272296;
|
||||
text-decoration: underline;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="overview" class="bg-${reportColor}">
|
||||
<h1>ESLint Report</h1>
|
||||
<div>
|
||||
<span>${reportSummary}</span> - Generated on ${date}
|
||||
</div>
|
||||
</div>
|
||||
<table>
|
||||
<tbody>
|
||||
${results}
|
||||
</tbody>
|
||||
</table>
|
||||
<script type="text/javascript">
|
||||
var groups = document.querySelectorAll("tr[data-group]");
|
||||
for (i = 0; i < groups.length; i++) {
|
||||
groups[i].addEventListener("click", function() {
|
||||
var inGroup = document.getElementsByClassName(this.getAttribute("data-group"));
|
||||
this.innerHTML = (this.innerHTML.indexOf("+") > -1) ? this.innerHTML.replace("+", "-") : this.innerHTML.replace("-", "+");
|
||||
for (var j = 0; j < inGroup.length; j++) {
|
||||
inGroup[j].style.display = (inGroup[j].style.display !== "none") ? "none" : "table-row";
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
`.trimStart();
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a word and a count, append an s if count is not one.
|
||||
* @param {string} word A word in its singular form.
|
||||
* @param {number} count A number controlling whether word should be pluralized.
|
||||
* @returns {string} The original word with an s on the end if count is not one.
|
||||
*/
|
||||
function pluralize(word, count) {
|
||||
return count === 1 ? word : `${word}s`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders text along the template of x problems (x errors, x warnings)
|
||||
* @param {number} totalErrors Total errors
|
||||
* @param {number} totalWarnings Total warnings
|
||||
* @returns {string} The formatted string, pluralized where necessary
|
||||
*/
|
||||
function renderSummary(totalErrors, totalWarnings) {
|
||||
const totalProblems = totalErrors + totalWarnings;
|
||||
let renderedText = `${totalProblems} ${pluralize("problem", totalProblems)}`;
|
||||
|
||||
if (totalProblems !== 0) {
|
||||
renderedText += ` (${totalErrors} ${pluralize("error", totalErrors)}, ${totalWarnings} ${pluralize("warning", totalWarnings)})`;
|
||||
}
|
||||
return renderedText;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the color based on whether there are errors/warnings...
|
||||
* @param {number} totalErrors Total errors
|
||||
* @param {number} totalWarnings Total warnings
|
||||
* @returns {number} The color code (0 = green, 1 = yellow, 2 = red)
|
||||
*/
|
||||
function renderColor(totalErrors, totalWarnings) {
|
||||
if (totalErrors !== 0) {
|
||||
return 2;
|
||||
}
|
||||
if (totalWarnings !== 0) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get HTML (table row) describing a single message.
|
||||
* @param {Object} it data for the message.
|
||||
* @returns {string} HTML (table row) describing the message.
|
||||
*/
|
||||
function messageTemplate(it) {
|
||||
const {
|
||||
parentIndex,
|
||||
lineNumber,
|
||||
columnNumber,
|
||||
severityNumber,
|
||||
severityName,
|
||||
message,
|
||||
ruleUrl,
|
||||
ruleId,
|
||||
} = it;
|
||||
|
||||
return `
|
||||
<tr style="display: none;" class="f-${parentIndex}">
|
||||
<td>${lineNumber}:${columnNumber}</td>
|
||||
<td class="clr-${severityNumber}">${severityName}</td>
|
||||
<td>${encodeHTML(message)}</td>
|
||||
<td>
|
||||
<a href="${ruleUrl ? ruleUrl : ""}" target="_blank" rel="noopener noreferrer">${encodeHTML(ruleId)}</a>
|
||||
</td>
|
||||
</tr>
|
||||
`.trimStart();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get HTML (table rows) describing the messages.
|
||||
* @param {Array} messages Messages.
|
||||
* @param {number} parentIndex Index of the parent HTML row.
|
||||
* @param {Object} rulesMeta Dictionary containing metadata for each rule executed by the analysis.
|
||||
* @returns {string} HTML (table rows) describing the messages.
|
||||
*/
|
||||
function renderMessages(messages, parentIndex, rulesMeta) {
|
||||
/**
|
||||
* Get HTML (table row) describing a message.
|
||||
* @param {Object} message Message.
|
||||
* @returns {string} HTML (table row) describing a message.
|
||||
*/
|
||||
return messages
|
||||
.map(message => {
|
||||
const lineNumber = message.line || 0;
|
||||
const columnNumber = message.column || 0;
|
||||
let ruleUrl;
|
||||
|
||||
if (rulesMeta) {
|
||||
const meta = rulesMeta[message.ruleId];
|
||||
|
||||
if (meta && meta.docs && meta.docs.url) {
|
||||
ruleUrl = meta.docs.url;
|
||||
}
|
||||
}
|
||||
|
||||
return messageTemplate({
|
||||
parentIndex,
|
||||
lineNumber,
|
||||
columnNumber,
|
||||
severityNumber: message.severity,
|
||||
severityName: message.severity === 1 ? "Warning" : "Error",
|
||||
message: message.message,
|
||||
ruleId: message.ruleId,
|
||||
ruleUrl,
|
||||
});
|
||||
})
|
||||
.join("\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get HTML (table row) describing the result for a single file.
|
||||
* @param {Object} it data for the file.
|
||||
* @returns {string} HTML (table row) describing the result for the file.
|
||||
*/
|
||||
function resultTemplate(it) {
|
||||
const { color, index, filePath, summary } = it;
|
||||
|
||||
return `
|
||||
<tr class="bg-${color}" data-group="f-${index}">
|
||||
<th colspan="4">
|
||||
[+] ${encodeHTML(filePath)}
|
||||
<span>${encodeHTML(summary)}</span>
|
||||
</th>
|
||||
</tr>
|
||||
`.trimStart();
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the results.
|
||||
* @param {Array} results Test results.
|
||||
* @param {Object} rulesMeta Dictionary containing metadata for each rule executed by the analysis.
|
||||
* @returns {string} HTML string describing the results.
|
||||
*/
|
||||
function renderResults(results, rulesMeta) {
|
||||
return results
|
||||
.map(
|
||||
(result, index) =>
|
||||
resultTemplate({
|
||||
index,
|
||||
color: renderColor(result.errorCount, result.warningCount),
|
||||
filePath: result.filePath,
|
||||
summary: renderSummary(
|
||||
result.errorCount,
|
||||
result.warningCount,
|
||||
),
|
||||
}) + renderMessages(result.messages, index, rulesMeta),
|
||||
)
|
||||
.join("\n");
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Public Interface
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
module.exports = function (results, data) {
|
||||
let totalErrors, totalWarnings;
|
||||
|
||||
const metaData = data ? data.rulesMeta : {};
|
||||
|
||||
totalErrors = 0;
|
||||
totalWarnings = 0;
|
||||
|
||||
// Iterate over results to get totals
|
||||
results.forEach(result => {
|
||||
totalErrors += result.errorCount;
|
||||
totalWarnings += result.warningCount;
|
||||
});
|
||||
|
||||
return pageTemplate({
|
||||
date: new Date(),
|
||||
reportColor: renderColor(totalErrors, totalWarnings),
|
||||
reportSummary: renderSummary(totalErrors, totalWarnings),
|
||||
results: renderResults(results, metaData),
|
||||
});
|
||||
};
|
||||
@@ -0,0 +1,24 @@
|
||||
// @ts-ignore TS6133
|
||||
import { expect, test } from "vitest";
|
||||
|
||||
import * as z from "zod/v3";
|
||||
|
||||
const schema = z.nan();
|
||||
|
||||
test("passing validations", () => {
|
||||
const result1 = schema.parse(Number.NaN);
|
||||
expect(Number.isNaN(result1)).toBe(true);
|
||||
|
||||
const result2 = schema.parse(Number("Not a number"));
|
||||
expect(Number.isNaN(result2)).toBe(true);
|
||||
});
|
||||
|
||||
test("failing validations", () => {
|
||||
expect(() => schema.parse(5)).toThrow();
|
||||
expect(() => schema.parse("John")).toThrow();
|
||||
expect(() => schema.parse(true)).toThrow();
|
||||
expect(() => schema.parse(null)).toThrow();
|
||||
expect(() => schema.parse(undefined)).toThrow();
|
||||
expect(() => schema.parse({})).toThrow();
|
||||
expect(() => schema.parse([])).toThrow();
|
||||
});
|
||||
Reference in New Issue
Block a user