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

View File

@@ -0,0 +1,60 @@
{
"name": "@eslint/object-schema",
"version": "2.1.6",
"description": "An object schema merger/validator",
"type": "module",
"main": "dist/esm/index.js",
"types": "dist/esm/index.d.ts",
"exports": {
"require": {
"types": "./dist/cjs/index.d.cts",
"default": "./dist/cjs/index.cjs"
},
"import": {
"types": "./dist/esm/index.d.ts",
"default": "./dist/esm/index.js"
}
},
"files": [
"dist"
],
"publishConfig": {
"access": "public"
},
"directories": {
"test": "tests"
},
"scripts": {
"build:cts": "node ../../tools/build-cts.js dist/esm/index.d.ts dist/cjs/index.d.cts",
"build": "rollup -c && tsc -p tsconfig.esm.json && npm run build:cts",
"test:jsr": "npx jsr@latest publish --dry-run",
"test": "mocha tests/",
"test:coverage": "c8 npm test"
},
"repository": {
"type": "git",
"url": "git+https://github.com/eslint/rewrite.git"
},
"keywords": [
"object",
"validation",
"schema",
"merge"
],
"author": "Nicholas C. Zakas",
"license": "Apache-2.0",
"bugs": {
"url": "https://github.com/eslint/rewrite/issues"
},
"homepage": "https://github.com/eslint/rewrite#readme",
"devDependencies": {
"c8": "^9.1.0",
"mocha": "^10.4.0",
"rollup": "^4.16.2",
"rollup-plugin-copy": "^3.5.0",
"typescript": "^5.4.5"
},
"engines": {
"node": "^18.18.0 || ^20.9.0 || >=21.1.0"
}
}

View File

@@ -0,0 +1,143 @@
const path = require('path')
const github = require('github-from-package')
const home = require('os').homedir
const crypto = require('crypto')
const expandTemplate = require('expand-template')()
function getDownloadUrl (opts) {
const pkgName = opts.pkg.name.replace(/^@[a-zA-Z0-9_\-.~]+\//, '')
return expandTemplate(urlTemplate(opts), {
name: pkgName,
package_name: pkgName,
version: opts.pkg.version,
major: opts.pkg.version.split('.')[0],
minor: opts.pkg.version.split('.')[1],
patch: opts.pkg.version.split('.')[2],
prerelease: opts.pkg.version.split('-')[1],
build: opts.pkg.version.split('+')[1],
abi: opts.abi || process.versions.modules,
node_abi: process.versions.modules,
runtime: opts.runtime || 'node',
platform: opts.platform,
arch: opts.arch,
libc: opts.libc || '',
configuration: (opts.debug ? 'Debug' : 'Release'),
module_name: opts.pkg.binary && opts.pkg.binary.module_name,
tag_prefix: opts['tag-prefix']
})
}
function getApiUrl (opts) {
return github(opts.pkg).replace('github.com', 'api.github.com/repos') + '/releases'
}
function getAssetUrl (opts, assetId) {
return getApiUrl(opts) + '/assets/' + assetId
}
function urlTemplate (opts) {
if (typeof opts.download === 'string') {
return opts.download
}
const packageName = '{name}-v{version}-{runtime}-v{abi}-{platform}{libc}-{arch}.tar.gz'
const hostMirrorUrl = getHostMirrorUrl(opts)
if (hostMirrorUrl) {
return hostMirrorUrl + '/{tag_prefix}{version}/' + packageName
}
if (opts.pkg.binary && opts.pkg.binary.host) {
return [
opts.pkg.binary.host,
opts.pkg.binary.remote_path,
opts.pkg.binary.package_name || packageName
].map(function (path) {
return trimSlashes(path)
}).filter(Boolean).join('/')
}
return github(opts.pkg) + '/releases/download/{tag_prefix}{version}/' + packageName
}
function getEnvPrefix (pkgName) {
return 'npm_config_' + (pkgName || '').replace(/[^a-zA-Z0-9]/g, '_').replace(/^_/, '')
}
function getHostMirrorUrl (opts) {
const propName = getEnvPrefix(opts.pkg.name) + '_binary_host'
return process.env[propName] || process.env[propName + '_mirror']
}
function trimSlashes (str) {
if (str) return str.replace(/^\.\/|^\/|\/$/g, '')
}
function cachedPrebuild (url) {
const digest = crypto.createHash('sha512').update(url).digest('hex').slice(0, 6)
return path.join(prebuildCache(), digest + '-' + path.basename(url).replace(/[^a-zA-Z0-9.]+/g, '-'))
}
function npmCache () {
const env = process.env
return env.npm_config_cache || (env.APPDATA ? path.join(env.APPDATA, 'npm-cache') : path.join(home(), '.npm'))
}
function prebuildCache () {
return path.join(npmCache(), '_prebuilds')
}
function tempFile (cached) {
return cached + '.' + process.pid + '-' + Math.random().toString(16).slice(2) + '.tmp'
}
function packageOrigin (env, pkg) {
// npm <= 6: metadata is stored on disk in node_modules
if (pkg._from) {
return pkg._from
}
// npm 7: metadata is exposed to environment by arborist
if (env.npm_package_from) {
// NOTE: seems undefined atm (npm 7.0.2)
return env.npm_package_from
}
if (env.npm_package_resolved) {
// NOTE: not sure about the difference with _from, but it's all we have
return env.npm_package_resolved
}
}
function localPrebuild (url, opts) {
const propName = getEnvPrefix(opts.pkg.name) + '_local_prebuilds'
const prefix = process.env[propName] || opts['local-prebuilds'] || 'prebuilds'
return path.join(prefix, path.basename(url))
}
const noopLogger = {
http: function () {},
silly: function () {},
debug: function () {},
info: function () {},
warn: function () {},
error: function () {},
critical: function () {},
alert: function () {},
emergency: function () {},
notice: function () {},
verbose: function () {},
fatal: function () {}
}
exports.getDownloadUrl = getDownloadUrl
exports.getApiUrl = getApiUrl
exports.getAssetUrl = getAssetUrl
exports.urlTemplate = urlTemplate
exports.cachedPrebuild = cachedPrebuild
exports.localPrebuild = localPrebuild
exports.prebuildCache = prebuildCache
exports.npmCache = npmCache
exports.tempFile = tempFile
exports.packageOrigin = packageOrigin
exports.noopLogger = noopLogger

View File

@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2014, 2015, 2016, 2017, 2018 Simon Lydell
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View File

@@ -0,0 +1,38 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = toKeyAlias;
var _index = require("../validators/generated/index.js");
var _cloneNode = require("../clone/cloneNode.js");
var _removePropertiesDeep = require("../modifications/removePropertiesDeep.js");
function toKeyAlias(node, key = node.key) {
let alias;
if (node.kind === "method") {
return toKeyAlias.increment() + "";
} else if ((0, _index.isIdentifier)(key)) {
alias = key.name;
} else if ((0, _index.isStringLiteral)(key)) {
alias = JSON.stringify(key.value);
} else {
alias = JSON.stringify((0, _removePropertiesDeep.default)((0, _cloneNode.default)(key)));
}
if (node.computed) {
alias = `[${alias}]`;
}
if (node.static) {
alias = `static:${alias}`;
}
return alias;
}
toKeyAlias.uid = 0;
toKeyAlias.increment = function () {
if (toKeyAlias.uid >= Number.MAX_SAFE_INTEGER) {
return toKeyAlias.uid = 0;
} else {
return toKeyAlias.uid++;
}
};
//# sourceMappingURL=toKeyAlias.js.map

View File

@@ -0,0 +1,15 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = removeComments;
var _index = require("../constants/index.js");
function removeComments(node) {
_index.COMMENT_KEYS.forEach(key => {
node[key] = null;
});
return node;
}
//# sourceMappingURL=removeComments.js.map

View File

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

View File

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

View File

@@ -0,0 +1,60 @@
const SemVer = require('../classes/semver')
const parse = require('./parse')
const { safeRe: re, t } = require('../internal/re')
const coerce = (version, options) => {
if (version instanceof SemVer) {
return version
}
if (typeof version === 'number') {
version = String(version)
}
if (typeof version !== 'string') {
return null
}
options = options || {}
let match = null
if (!options.rtl) {
match = version.match(options.includePrerelease ? re[t.COERCEFULL] : re[t.COERCE])
} else {
// Find the right-most coercible string that does not share
// a terminus with a more left-ward coercible string.
// Eg, '1.2.3.4' wants to coerce '2.3.4', not '3.4' or '4'
// With includePrerelease option set, '1.2.3.4-rc' wants to coerce '2.3.4-rc', not '2.3.4'
//
// Walk through the string checking with a /g regexp
// Manually set the index so as to pick up overlapping matches.
// Stop when we get a match that ends at the string end, since no
// coercible string can be more right-ward without the same terminus.
const coerceRtlRegex = options.includePrerelease ? re[t.COERCERTLFULL] : re[t.COERCERTL]
let next
while ((next = coerceRtlRegex.exec(version)) &&
(!match || match.index + match[0].length !== version.length)
) {
if (!match ||
next.index + next[0].length !== match.index + match[0].length) {
match = next
}
coerceRtlRegex.lastIndex = next.index + next[1].length + next[2].length
}
// leave it in a clean state
coerceRtlRegex.lastIndex = -1
}
if (match === null) {
return null
}
const major = match[2]
const minor = match[3] || '0'
const patch = match[4] || '0'
const prerelease = options.includePrerelease && match[5] ? `-${match[5]}` : ''
const build = options.includePrerelease && match[6] ? `+${match[6]}` : ''
return parse(`${major}.${minor}.${patch}${prerelease}${build}`, options)
}
module.exports = coerce

View File

@@ -0,0 +1,12 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = _classExtractFieldDescriptor;
var _classPrivateFieldGet = require("classPrivateFieldGet2");
function _classExtractFieldDescriptor(receiver, privateMap) {
return _classPrivateFieldGet(privateMap, receiver);
}
//# sourceMappingURL=classExtractFieldDescriptor.js.map

View File

@@ -0,0 +1,232 @@
/**
* @fileoverview Rule to flag no-unneeded-ternary
* @author Gyandeep Singh
*/
"use strict";
const astUtils = require("./utils/ast-utils");
// Operators that always result in a boolean value
const BOOLEAN_OPERATORS = new Set([
"==",
"===",
"!=",
"!==",
">",
">=",
"<",
"<=",
"in",
"instanceof",
]);
const OPERATOR_INVERSES = {
"==": "!=",
"!=": "==",
"===": "!==",
"!==": "===",
// Operators like < and >= are not true inverses, since both will return false with NaN.
};
const OR_PRECEDENCE = astUtils.getPrecedence({
type: "LogicalExpression",
operator: "||",
});
//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------
/** @type {import('../shared/types').Rule} */
module.exports = {
meta: {
type: "suggestion",
defaultOptions: [{ defaultAssignment: true }],
docs: {
description:
"Disallow ternary operators when simpler alternatives exist",
recommended: false,
frozen: true,
url: "https://eslint.org/docs/latest/rules/no-unneeded-ternary",
},
schema: [
{
type: "object",
properties: {
defaultAssignment: {
type: "boolean",
},
},
additionalProperties: false,
},
],
fixable: "code",
messages: {
unnecessaryConditionalExpression:
"Unnecessary use of boolean literals in conditional expression.",
unnecessaryConditionalAssignment:
"Unnecessary use of conditional expression for default assignment.",
},
},
create(context) {
const [{ defaultAssignment }] = context.options;
const sourceCode = context.sourceCode;
/**
* Test if the node is a boolean literal
* @param {ASTNode} node The node to report.
* @returns {boolean} True if the its a boolean literal
* @private
*/
function isBooleanLiteral(node) {
return node.type === "Literal" && typeof node.value === "boolean";
}
/**
* Creates an expression that represents the boolean inverse of the expression represented by the original node
* @param {ASTNode} node A node representing an expression
* @returns {string} A string representing an inverted expression
*/
function invertExpression(node) {
if (
node.type === "BinaryExpression" &&
Object.hasOwn(OPERATOR_INVERSES, node.operator)
) {
const operatorToken = sourceCode.getFirstTokenBetween(
node.left,
node.right,
token => token.value === node.operator,
);
const text = sourceCode.getText();
return (
text.slice(node.range[0], operatorToken.range[0]) +
OPERATOR_INVERSES[node.operator] +
text.slice(operatorToken.range[1], node.range[1])
);
}
if (
astUtils.getPrecedence(node) <
astUtils.getPrecedence({ type: "UnaryExpression" })
) {
return `!(${astUtils.getParenthesisedText(sourceCode, node)})`;
}
return `!${astUtils.getParenthesisedText(sourceCode, node)}`;
}
/**
* Tests if a given node always evaluates to a boolean value
* @param {ASTNode} node An expression node
* @returns {boolean} True if it is determined that the node will always evaluate to a boolean value
*/
function isBooleanExpression(node) {
return (
(node.type === "BinaryExpression" &&
BOOLEAN_OPERATORS.has(node.operator)) ||
(node.type === "UnaryExpression" && node.operator === "!")
);
}
/**
* Test if the node matches the pattern id ? id : expression
* @param {ASTNode} node The ConditionalExpression to check.
* @returns {boolean} True if the pattern is matched, and false otherwise
* @private
*/
function matchesDefaultAssignment(node) {
return (
node.test.type === "Identifier" &&
node.consequent.type === "Identifier" &&
node.test.name === node.consequent.name
);
}
return {
ConditionalExpression(node) {
if (
isBooleanLiteral(node.alternate) &&
isBooleanLiteral(node.consequent)
) {
context.report({
node,
messageId: "unnecessaryConditionalExpression",
fix(fixer) {
if (
node.consequent.value === node.alternate.value
) {
// Replace `foo ? true : true` with just `true`, but don't replace `foo() ? true : true`
return node.test.type === "Identifier"
? fixer.replaceText(
node,
node.consequent.value.toString(),
)
: null;
}
if (node.alternate.value) {
// Replace `foo() ? false : true` with `!(foo())`
return fixer.replaceText(
node,
invertExpression(node.test),
);
}
// Replace `foo ? true : false` with `foo` if `foo` is guaranteed to be a boolean, or `!!foo` otherwise.
return fixer.replaceText(
node,
isBooleanExpression(node.test)
? astUtils.getParenthesisedText(
sourceCode,
node.test,
)
: `!${invertExpression(node.test)}`,
);
},
});
} else if (
!defaultAssignment &&
matchesDefaultAssignment(node)
) {
context.report({
node,
messageId: "unnecessaryConditionalAssignment",
fix(fixer) {
const shouldParenthesizeAlternate =
(astUtils.getPrecedence(node.alternate) <
OR_PRECEDENCE ||
astUtils.isCoalesceExpression(
node.alternate,
)) &&
!astUtils.isParenthesised(
sourceCode,
node.alternate,
);
const alternateText = shouldParenthesizeAlternate
? `(${sourceCode.getText(node.alternate)})`
: astUtils.getParenthesisedText(
sourceCode,
node.alternate,
);
const testText = astUtils.getParenthesisedText(
sourceCode,
node.test,
);
return fixer.replaceText(
node,
`${testText} || ${alternateText}`,
);
},
});
}
},
};
},
};

View File

@@ -0,0 +1,61 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.statements = exports.statement = exports.smart = exports.program = exports.expression = void 0;
var _t = require("@babel/types");
const {
assertExpressionStatement
} = _t;
function makeStatementFormatter(fn) {
return {
code: str => `/* @babel/template */;\n${str}`,
validate: () => {},
unwrap: ast => {
return fn(ast.program.body.slice(1));
}
};
}
const smart = exports.smart = makeStatementFormatter(body => {
if (body.length > 1) {
return body;
} else {
return body[0];
}
});
const statements = exports.statements = makeStatementFormatter(body => body);
const statement = exports.statement = makeStatementFormatter(body => {
if (body.length === 0) {
throw new Error("Found nothing to return.");
}
if (body.length > 1) {
throw new Error("Found multiple statements but wanted one");
}
return body[0];
});
const expression = exports.expression = {
code: str => `(\n${str}\n)`,
validate: ast => {
if (ast.program.body.length > 1) {
throw new Error("Found multiple statements but wanted one");
}
if (expression.unwrap(ast).start === 0) {
throw new Error("Parse result included parens.");
}
},
unwrap: ({
program
}) => {
const [stmt] = program.body;
assertExpressionStatement(stmt);
return stmt.expression;
}
};
const program = exports.program = {
code: str => str,
validate: () => {},
unwrap: ast => ast.program
};
//# sourceMappingURL=formatters.js.map

View File

@@ -0,0 +1,22 @@
MIT License
Copyright (c) 2014-present Sebastian McKenzie and other contributors
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View File

@@ -0,0 +1,6 @@
type MessageProps = {
children?: React.ReactNode;
type: 'error' | 'loading' | 'no-data';
};
export default function Message({ children, type }: MessageProps): React.ReactElement;
export {};

View File

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

View File

@@ -0,0 +1,42 @@
export class MessageHandler {
constructor(sourceName: any, targetName: any, comObj: any);
sourceName: any;
targetName: any;
comObj: any;
callbackId: number;
streamId: number;
streamSinks: any;
streamControllers: any;
callbackCapabilities: any;
actionHandler: any;
on(actionName: any, handler: any): void;
/**
* Sends a message to the comObj to invoke the action with the supplied data.
* @param {string} actionName - Action to call.
* @param {JSON} data - JSON data to send.
* @param {Array} [transfers] - List of transfers/ArrayBuffers.
*/
send(actionName: string, data: JSON, transfers?: any[] | undefined): void;
/**
* Sends a message to the comObj to invoke the action with the supplied data.
* Expects that the other side will callback with the response.
* @param {string} actionName - Action to call.
* @param {JSON} data - JSON data to send.
* @param {Array} [transfers] - List of transfers/ArrayBuffers.
* @returns {Promise} Promise to be resolved with response data.
*/
sendWithPromise(actionName: string, data: JSON, transfers?: any[] | undefined): Promise<any>;
/**
* Sends a message to the comObj to invoke the action with the supplied data.
* Expect that the other side will callback to signal 'start_complete'.
* @param {string} actionName - Action to call.
* @param {JSON} data - JSON data to send.
* @param {Object} queueingStrategy - Strategy to signal backpressure based on
* internal queue.
* @param {Array} [transfers] - List of transfers/ArrayBuffers.
* @returns {ReadableStream} ReadableStream to read data in chunks.
*/
sendWithStream(actionName: string, data: JSON, queueingStrategy: Object, transfers?: any[] | undefined): ReadableStream;
destroy(): void;
#private;
}

View File

@@ -0,0 +1,55 @@
"use strict";
'use client';
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = Thumbnail;
const jsx_runtime_1 = require("react/jsx-runtime");
const clsx_1 = __importDefault(require("clsx"));
const tiny_invariant_1 = __importDefault(require("tiny-invariant"));
const Page_js_1 = __importDefault(require("./Page.js"));
const utils_js_1 = require("./shared/utils.js");
const useDocumentContext_js_1 = __importDefault(require("./shared/hooks/useDocumentContext.js"));
/**
* Displays a thumbnail of a page. Does not render the annotation layer or the text layer. Does not register itself as a link target, so the user will not be scrolled to a Thumbnail component when clicked on an internal link (e.g. in Table of Contents). When clicked, attempts to navigate to the page clicked (similarly to a link in Outline).
*
* Should be placed inside `<Document />`. Alternatively, it can have `pdf` prop passed, which can be obtained from `<Document />`'s `onLoadSuccess` callback function.
*/
function Thumbnail(props) {
const documentContext = (0, useDocumentContext_js_1.default)();
const mergedProps = Object.assign(Object.assign({}, documentContext), props);
const { className, linkService, onItemClick, pageIndex: pageIndexProps, pageNumber: pageNumberProps, pdf, } = mergedProps;
(0, tiny_invariant_1.default)(pdf, 'Attempted to load a thumbnail, but no document was specified. Wrap <Thumbnail /> in a <Document /> or pass explicit `pdf` prop.');
const pageIndex = (0, utils_js_1.isProvided)(pageNumberProps) ? pageNumberProps - 1 : (pageIndexProps !== null && pageIndexProps !== void 0 ? pageIndexProps : null);
const pageNumber = pageNumberProps !== null && pageNumberProps !== void 0 ? pageNumberProps : ((0, utils_js_1.isProvided)(pageIndexProps) ? pageIndexProps + 1 : null);
function onClick(event) {
event.preventDefault();
if (!(0, utils_js_1.isProvided)(pageIndex) || !pageNumber) {
return;
}
(0, tiny_invariant_1.default)(onItemClick || linkService, 'Either onItemClick callback or linkService must be defined in order to navigate to an outline item.');
if (onItemClick) {
onItemClick({
pageIndex,
pageNumber,
});
}
else if (linkService) {
linkService.goToPage(pageNumber);
}
}
const { className: classNameProps, onItemClick: onItemClickProps } = props, pageProps = __rest(props, ["className", "onItemClick"]);
return ((0, jsx_runtime_1.jsx)("a", { className: (0, clsx_1.default)('react-pdf__Thumbnail', className), href: pageNumber ? '#' : undefined, onClick: onClick, children: (0, jsx_runtime_1.jsx)(Page_js_1.default, Object.assign({}, pageProps, { _className: "react-pdf__Thumbnail__page", _enableRegisterUnregisterPage: false, renderAnnotationLayer: false, renderTextLayer: false })) }));
}

View File

@@ -0,0 +1,117 @@
/**
* @fileoverview Rule to check multiple var declarations per line
* @author Alberto Rodríguez
* @deprecated in ESLint v8.53.0
*/
"use strict";
//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------
/** @type {import('../shared/types').Rule} */
module.exports = {
meta: {
deprecated: {
message: "Formatting rules are being moved out of ESLint core.",
url: "https://eslint.org/blog/2023/10/deprecating-formatting-rules/",
deprecatedSince: "8.53.0",
availableUntil: "10.0.0",
replacedBy: [
{
message:
"ESLint Stylistic now maintains deprecated stylistic core rules.",
url: "https://eslint.style/guide/migration",
plugin: {
name: "@stylistic/eslint-plugin-js",
url: "https://eslint.style/packages/js",
},
rule: {
name: "one-var-declaration-per-line",
url: "https://eslint.style/rules/js/one-var-declaration-per-line",
},
},
],
},
type: "suggestion",
docs: {
description:
"Require or disallow newlines around variable declarations",
recommended: false,
url: "https://eslint.org/docs/latest/rules/one-var-declaration-per-line",
},
schema: [
{
enum: ["always", "initializations"],
},
],
fixable: "whitespace",
messages: {
expectVarOnNewline:
"Expected variable declaration to be on a new line.",
},
},
create(context) {
const always = context.options[0] === "always";
//--------------------------------------------------------------------------
// Helpers
//--------------------------------------------------------------------------
/**
* Determine if provided keyword is a variant of for specifiers
* @private
* @param {string} keyword keyword to test
* @returns {boolean} True if `keyword` is a variant of for specifier
*/
function isForTypeSpecifier(keyword) {
return (
keyword === "ForStatement" ||
keyword === "ForInStatement" ||
keyword === "ForOfStatement"
);
}
/**
* Checks newlines around variable declarations.
* @private
* @param {ASTNode} node `VariableDeclaration` node to test
* @returns {void}
*/
function checkForNewLine(node) {
if (isForTypeSpecifier(node.parent.type)) {
return;
}
const declarations = node.declarations;
let prev;
declarations.forEach(current => {
if (prev && prev.loc.end.line === current.loc.start.line) {
if (always || prev.init || current.init) {
context.report({
node,
messageId: "expectVarOnNewline",
loc: current.loc,
fix: fixer => fixer.insertTextBefore(current, "\n"),
});
}
}
prev = current;
});
}
//--------------------------------------------------------------------------
// Public
//--------------------------------------------------------------------------
return {
VariableDeclaration: checkForNewLine,
};
},
};

View File

@@ -0,0 +1,68 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _default = exports.default = {
auxiliaryComment: {
message: "Use `auxiliaryCommentBefore` or `auxiliaryCommentAfter`"
},
blacklist: {
message: "Put the specific transforms you want in the `plugins` option"
},
breakConfig: {
message: "This is not a necessary option in Babel 6"
},
experimental: {
message: "Put the specific transforms you want in the `plugins` option"
},
externalHelpers: {
message: "Use the `external-helpers` plugin instead. " + "Check out http://babeljs.io/docs/plugins/external-helpers/"
},
extra: {
message: ""
},
jsxPragma: {
message: "use the `pragma` option in the `react-jsx` plugin. " + "Check out http://babeljs.io/docs/plugins/transform-react-jsx/"
},
loose: {
message: "Specify the `loose` option for the relevant plugin you are using " + "or use a preset that sets the option."
},
metadataUsedHelpers: {
message: "Not required anymore as this is enabled by default"
},
modules: {
message: "Use the corresponding module transform plugin in the `plugins` option. " + "Check out http://babeljs.io/docs/plugins/#modules"
},
nonStandard: {
message: "Use the `react-jsx` and `flow-strip-types` plugins to support JSX and Flow. " + "Also check out the react preset http://babeljs.io/docs/plugins/preset-react/"
},
optional: {
message: "Put the specific transforms you want in the `plugins` option"
},
sourceMapName: {
message: "The `sourceMapName` option has been removed because it makes more sense for the " + "tooling that calls Babel to assign `map.file` themselves."
},
stage: {
message: "Check out the corresponding stage-x presets http://babeljs.io/docs/plugins/#presets"
},
whitelist: {
message: "Put the specific transforms you want in the `plugins` option"
},
resolveModuleSource: {
version: 6,
message: "Use `babel-plugin-module-resolver@3`'s 'resolvePath' options"
},
metadata: {
version: 6,
message: "Generated plugin metadata is always included in the output result"
},
sourceMapTarget: {
version: 6,
message: "The `sourceMapTarget` option has been removed because it makes more sense for the tooling " + "that calls Babel to assign `map.file` themselves."
}
};
0 && 0;
//# sourceMappingURL=removed.js.map

View File

@@ -0,0 +1 @@
module.exports={C:{"106":0.0026,"115":0.03633,"128":0.00519,"132":0.01557,"133":0.00519,"134":0.00779,"135":0.09861,"136":0.30362,"137":0.0026,_:"2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 107 108 109 110 111 112 113 114 116 117 118 119 120 121 122 123 124 125 126 127 129 130 131 138 139 140 3.5 3.6"},D:{"11":0.0026,"38":0.01298,"39":0.0026,"43":0.0026,"46":0.0026,"47":0.0026,"48":0.0026,"49":0.0026,"50":0.0026,"52":0.0026,"53":0.0026,"55":0.02336,"56":0.00519,"57":0.0026,"58":0.30102,"59":0.0026,"60":0.0026,"61":0.0026,"65":0.0026,"66":0.0026,"68":0.00779,"69":0.0026,"72":0.00519,"73":0.02336,"74":0.0026,"75":0.00779,"76":0.0026,"78":0.0026,"79":0.04931,"81":0.0026,"83":0.03633,"86":0.0026,"87":0.04152,"88":0.01038,"89":0.0026,"90":0.0026,"91":0.01298,"93":0.03374,"94":0.01038,"95":0.00779,"98":0.01557,"99":0.00519,"100":0.0026,"101":0.0026,"102":0.0026,"103":0.18425,"104":0.0026,"105":0.0026,"106":0.01298,"107":0.00779,"108":0.02855,"109":0.92901,"110":0.03893,"111":0.01557,"112":0.0026,"113":0.00519,"114":0.03633,"115":0.0026,"116":0.05709,"117":0.00519,"118":0.0026,"119":0.05969,"120":0.02076,"121":0.00519,"122":0.06488,"123":0.00779,"124":0.02336,"125":0.06747,"126":0.09083,"127":0.01038,"128":0.04671,"129":0.02336,"130":0.0519,"131":0.1557,"132":0.18425,"133":5.33792,"134":9.74682,"135":0.01557,"136":0.00519,_:"4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 40 41 42 44 45 51 54 62 63 64 67 70 71 77 80 84 85 92 96 97 137 138"},F:{"36":0.0026,"46":0.01817,"87":0.00779,"88":0.01038,"95":0.00779,"102":0.01557,"106":0.0026,"114":0.0026,"116":0.12456,"117":0.35552,_:"9 11 12 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 37 38 39 40 41 42 43 44 45 47 48 49 50 51 52 53 54 55 56 57 58 60 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 89 90 91 92 93 94 96 97 98 99 100 101 103 104 105 107 108 109 110 111 112 113 115 9.5-9.6 10.0-10.1 10.5 10.6 11.1 11.5 11.6 12.1"},B:{"18":0.0026,"92":0.00519,"107":0.0026,"109":0.02076,"112":0.0026,"114":0.00519,"119":0.00779,"121":0.0026,"122":0.00519,"126":0.0026,"128":0.0026,"129":0.0026,"130":0.0026,"131":0.02076,"132":0.04412,"133":0.74217,"134":1.53884,_:"12 13 14 15 16 17 79 80 81 83 84 85 86 87 88 89 90 91 93 94 95 96 97 98 99 100 101 102 103 104 105 106 108 110 111 113 115 116 117 118 120 123 124 125 127"},E:{"14":0.0026,_:"0 4 5 6 7 8 9 10 11 12 13 15 3.1 3.2 6.1 7.1 9.1 10.1 12.1 15.2-15.3","5.1":0.00519,"11.1":0.0026,"13.1":0.02076,"14.1":0.01557,"15.1":0.0026,"15.4":0.0026,"15.5":0.0026,"15.6":0.05709,"16.0":0.00519,"16.1":0.01038,"16.2":0.0026,"16.3":0.00779,"16.4":0.0026,"16.5":0.01817,"16.6":0.05969,"17.0":0.0026,"17.1":0.02336,"17.2":0.0026,"17.3":0.01298,"17.4":0.01817,"17.5":0.03114,"17.6":0.08564,"18.0":0.01038,"18.1":0.06228,"18.2":0.02076,"18.3":0.3633,"18.4":0.00519},G:{"8":0,"3.2":0,"4.0-4.1":0,"4.2-4.3":0.0031,"5.0-5.1":0,"6.0-6.1":0.0093,"7.0-7.1":0.0062,"8.1-8.4":0,"9.0-9.2":0.00465,"9.3":0.02171,"10.0-10.2":0.00155,"10.3":0.03566,"11.0-11.2":0.16436,"11.3-11.4":0.01085,"12.0-12.1":0.0062,"12.2-12.5":0.15351,"13.0-13.1":0.0031,"13.2":0.00465,"13.3":0.0062,"13.4-13.7":0.02171,"14.0-14.4":0.05427,"14.5-14.8":0.06513,"15.0-15.1":0.03566,"15.2-15.3":0.03566,"15.4":0.04342,"15.5":0.04962,"15.6-15.8":0.61094,"16.0":0.08683,"16.1":0.17832,"16.2":0.09304,"16.3":0.16126,"16.4":0.03566,"16.5":0.06668,"16.6-16.7":0.72413,"17.0":0.04342,"17.1":0.07753,"17.2":0.05892,"17.3":0.08218,"17.4":0.16436,"17.5":0.36594,"17.6-17.7":1.06217,"18.0":0.29772,"18.1":0.97378,"18.2":0.43572,"18.3":9.10671,"18.4":0.1349},P:{"4":0.08272,"20":0.01034,"21":0.03102,"22":0.03102,"23":0.04136,"24":0.0517,"25":0.07238,"26":0.09306,"27":2.16097,"5.0-5.4":0.02068,"6.2-6.4":0.04136,"7.2-7.4":0.06204,_:"8.2 9.2 10.1 12.0 14.0 15.0 18.0","11.1-11.2":0.01034,"13.0":0.01034,"16.0":0.02068,"17.0":0.02068,"19.0":0.01034},I:{"0":0.04434,"3":0,"4":0,"2.1":0,"2.2":0,"2.3":0,"4.1":0,"4.2-4.3":0.00001,"4.4":0,"4.4.3-4.4.4":0.00005},K:{"0":0.80715,_:"10 11 12 11.1 11.5 12.1"},A:{"11":0.02076,_:"6 7 8 9 10 5.5"},S:{_:"2.5 3.0-3.1"},J:{_:"7 10"},N:{_:"10 11"},R:{_:"0"},M:{"0":0.07405},Q:{_:"14.9"},O:{"0":0.59981},H:{"0":0},L:{"0":57.2719}};

View File

@@ -0,0 +1,223 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};
Object.defineProperty(exports, "__esModule", { value: true });
var jsx_runtime_1 = require("react/jsx-runtime");
var vitest_1 = require("vitest");
var index_js_1 = __importStar(require("./index.js"));
(0, vitest_1.describe)('makeEventProps()', function () {
var fakeEvent = {};
(0, vitest_1.it)('returns object with valid and only valid event callbacks', function () {
var props = {
onClick: vitest_1.vi.fn(),
someInvalidProp: vitest_1.vi.fn(),
};
var result = (0, index_js_1.default)(props);
(0, vitest_1.expect)(result).toMatchObject({ onClick: vitest_1.expect.any(Function) });
});
(0, vitest_1.it)('calls getArgs function on event invoke if given', function () {
var props = {
onClick: vitest_1.vi.fn(),
someInvalidProp: vitest_1.vi.fn(),
};
var getArgs = vitest_1.vi.fn();
var result = (0, index_js_1.default)(props, getArgs);
// getArgs shall not be invoked before a given event is fired
(0, vitest_1.expect)(getArgs).not.toHaveBeenCalled();
result.onClick(fakeEvent);
(0, vitest_1.expect)(getArgs).toHaveBeenCalledTimes(1);
(0, vitest_1.expect)(getArgs).toHaveBeenCalledWith('onClick');
});
(0, vitest_1.it)('properly calls callbacks given in props given no getArgs function', function () {
var props = {
onClick: vitest_1.vi.fn(),
};
var result = (0, index_js_1.default)(props);
result.onClick(fakeEvent);
(0, vitest_1.expect)(props.onClick).toHaveBeenCalledWith(fakeEvent);
});
(0, vitest_1.it)('properly calls callbacks given in props given getArgs function', function () {
var props = {
onClick: vitest_1.vi.fn(),
};
var getArgs = vitest_1.vi.fn();
var args = {};
getArgs.mockReturnValue(args);
var result = (0, index_js_1.default)(props, getArgs);
result.onClick(fakeEvent);
(0, vitest_1.expect)(props.onClick).toHaveBeenCalledWith(fakeEvent, args);
});
(0, vitest_1.it)('should not filter out valid event props', function () {
var props = {
onClick: vitest_1.vi.fn(),
};
var result = (0, index_js_1.default)(props);
// @ts-expect-no-error
result.onClick;
});
(0, vitest_1.it)('should filter out invalid event props', function () {
var props = {
someInvalidProp: vitest_1.vi.fn(),
};
var result = (0, index_js_1.default)(props);
// @ts-expect-error-next-line
result.someInvalidProp;
});
(0, vitest_1.it)('should allow valid onClick handler to be passed', function () {
var props = {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
onClick: function (event) {
// Intentionally empty
},
};
// @ts-expect-no-error
(0, index_js_1.default)(props);
});
(0, vitest_1.it)('should not allow invalid onClick handler to be passed', function () {
var props = {
onClick: 'potato',
};
// @ts-expect-error-next-line
(0, index_js_1.default)(props);
});
(0, vitest_1.it)('should allow onClick handler with extra args to be passed if getArgs is provided', function () {
var props = {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
onClick: function (event, args) {
// Intentionally empty
},
};
// @ts-expect-no-error
(0, index_js_1.default)(props, function () { return 'hello'; });
});
(0, vitest_1.it)('should not allow onClick handler with extra args to be passed if getArgs is not provided', function () {
var props = {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
onClick: function (event, args) {
// Intentionally empty
},
};
// @ts-expect-error-next-line
(0, index_js_1.default)(props);
});
(0, vitest_1.it)('should not allow onClick handler with extra args to be passed if getArgs is provided but returns different type', function () {
var props = {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
onClick: function (event, args) {
// Intentionally empty
},
};
// @ts-expect-error-next-line
(0, index_js_1.default)(props, function () { return 5; });
});
(0, vitest_1.it)('should allow div onClick handler to be passed to div', function () {
var props = {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
onClick: function (event) {
// Intentionally empty
},
};
var result = (0, index_js_1.default)(props);
// @ts-expect-no-error
(0, jsx_runtime_1.jsx)("div", { onClick: result.onClick });
});
(0, vitest_1.it)('should not allow div onClick handler to be passed to button', function () {
var props = {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
onClick: function (event) {
// Intentionally empty
},
};
var result = (0, index_js_1.default)(props);
// @ts-expect-error-next-line
(0, jsx_runtime_1.jsx)("button", { onClick: result.onClick });
});
(0, vitest_1.it)('should allow div onClick handler with extra args to be passed to div if getArgs is provided', function () {
var props = {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
onClick: function (event, args) {
// Intentionally empty
},
};
var result = (0, index_js_1.default)(props, function () { return 'hello'; });
// @ts-expect-no-error
(0, jsx_runtime_1.jsx)("div", { onClick: result.onClick });
});
(0, vitest_1.it)('should not allow div onClick handler with extra args to be passed to button if getArgs is provided', function () {
var props = {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
onClick: function (event, args) {
// Intentionally empty
},
};
var result = (0, index_js_1.default)(props, function () { return 'hello'; });
// @ts-expect-error-next-line
(0, jsx_runtime_1.jsx)("button", { onClick: result.onClick });
});
(0, vitest_1.it)('should allow onClick handler with valid extra args to be passed with args explicitly typed', function () {
var props = {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
onClick: function (event, args) {
// Intentionally empty
},
};
// @ts-expect-no-error
(0, index_js_1.default)(props, function () { return 'hello'; });
});
(0, vitest_1.it)('should not allow onClick handler with invalid extra args to be passed with args explicitly typed', function () {
var props = {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
onClick: function (event, args) {
// Intentionally empty
},
};
// @ts-expect-error-next-line
(0, index_js_1.default)(props, function () { return 'hello'; });
});
(0, vitest_1.it)('should allow getArgs returning valid type to be passed with args explicitly typed', function () {
var props = {};
// @ts-expect-no-error
(0, index_js_1.default)(props, function () { return 'hello'; });
});
(0, vitest_1.it)('should not allow getArgs returning invalid type to be passed with args explicitly typed', function () {
var props = {};
// @ts-expect-error-next-line
(0, index_js_1.default)(props, function () { return 5; });
});
});
(0, vitest_1.describe)('allEvents', function () {
(0, vitest_1.it)('should contain all events', function () {
var sortedAllEvents = new Set(__spreadArray([], index_js_1.allEvents, true).sort());
(0, vitest_1.expect)(sortedAllEvents).toMatchSnapshot();
});
});