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,541 @@
/**
* @fileoverview `FileEnumerator` class.
*
* `FileEnumerator` class has two responsibilities:
*
* 1. Find target files by processing glob patterns.
* 2. Tie each target file and appropriate configuration.
*
* It provides a method:
*
* - `iterateFiles(patterns)`
* Iterate files which are matched by given patterns together with the
* corresponded configuration. This is for `CLIEngine#executeOnFiles()`.
* While iterating files, it loads the configuration file of each directory
* before iterate files on the directory, so we can use the configuration
* files to determine target files.
*
* @example
* const enumerator = new FileEnumerator();
* const linter = new Linter();
*
* for (const { config, filePath } of enumerator.iterateFiles(["*.js"])) {
* const code = fs.readFileSync(filePath, "utf8");
* const messages = linter.verify(code, config, filePath);
*
* console.log(messages);
* }
*
* @author Toru Nagashima <https://github.com/mysticatea>
*/
"use strict";
//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------
const fs = require("node:fs");
const path = require("node:path");
const getGlobParent = require("glob-parent");
const isGlob = require("is-glob");
const escapeRegExp = require("escape-string-regexp");
const { Minimatch } = require("minimatch");
const {
Legacy: { IgnorePattern, CascadingConfigArrayFactory },
} = require("@eslint/eslintrc");
const debug = require("debug")("eslint:file-enumerator");
//------------------------------------------------------------------------------
// Helpers
//------------------------------------------------------------------------------
const minimatchOpts = { dot: true, matchBase: true };
const dotfilesPattern = /(?:(?:^\.)|(?:[/\\]\.))[^/\\.].*/u;
const NONE = 0;
const IGNORED_SILENTLY = 1;
const IGNORED = 2;
// For VSCode intellisense
/** @typedef {ReturnType<CascadingConfigArrayFactory.getConfigArrayForFile>} ConfigArray */
/**
* @typedef {Object} FileEnumeratorOptions
* @property {CascadingConfigArrayFactory} [configArrayFactory] The factory for config arrays.
* @property {string} [cwd] The base directory to start lookup.
* @property {string[]} [extensions] The extensions to match files for directory patterns.
* @property {boolean} [globInputPaths] Set to false to skip glob resolution of input file paths to lint (default: true). If false, each input file paths is assumed to be a non-glob path to an existing file.
* @property {boolean} [ignore] The flag to check ignored files.
* @property {string[]} [rulePaths] The value of `--rulesdir` option.
*/
/**
* @typedef {Object} FileAndConfig
* @property {string} filePath The path to a target file.
* @property {ConfigArray} config The config entries of that file.
* @property {boolean} ignored If `true` then this file should be ignored and warned because it was directly specified.
*/
/**
* @typedef {Object} FileEntry
* @property {string} filePath The path to a target file.
* @property {ConfigArray} config The config entries of that file.
* @property {NONE|IGNORED_SILENTLY|IGNORED} flag The flag.
* - `NONE` means the file is a target file.
* - `IGNORED_SILENTLY` means the file should be ignored silently.
* - `IGNORED` means the file should be ignored and warned because it was directly specified.
*/
/**
* @typedef {Object} FileEnumeratorInternalSlots
* @property {CascadingConfigArrayFactory} configArrayFactory The factory for config arrays.
* @property {string} cwd The base directory to start lookup.
* @property {RegExp|null} extensionRegExp The RegExp to test if a string ends with specific file extensions.
* @property {boolean} globInputPaths Set to false to skip glob resolution of input file paths to lint (default: true). If false, each input file paths is assumed to be a non-glob path to an existing file.
* @property {boolean} ignoreFlag The flag to check ignored files.
* @property {(filePath:string, dot:boolean) => boolean} defaultIgnores The default predicate function to ignore files.
*/
/** @type {WeakMap<FileEnumerator, FileEnumeratorInternalSlots>} */
const internalSlotsMap = new WeakMap();
/**
* Check if a string is a glob pattern or not.
* @param {string} pattern A glob pattern.
* @returns {boolean} `true` if the string is a glob pattern.
*/
function isGlobPattern(pattern) {
return isGlob(path.sep === "\\" ? pattern.replace(/\\/gu, "/") : pattern);
}
/**
* Get stats of a given path.
* @param {string} filePath The path to target file.
* @throws {Error} As may be thrown by `fs.statSync`.
* @returns {fs.Stats|null} The stats.
* @private
*/
function statSafeSync(filePath) {
try {
return fs.statSync(filePath);
} catch (error) {
/* c8 ignore next */
if (error.code !== "ENOENT") {
throw error;
}
return null;
}
}
/**
* Get filenames in a given path to a directory.
* @param {string} directoryPath The path to target directory.
* @throws {Error} As may be thrown by `fs.readdirSync`.
* @returns {import("fs").Dirent[]} The filenames.
* @private
*/
function readdirSafeSync(directoryPath) {
try {
return fs.readdirSync(directoryPath, { withFileTypes: true });
} catch (error) {
/* c8 ignore next */
if (error.code !== "ENOENT") {
throw error;
}
return [];
}
}
/**
* Create a `RegExp` object to detect extensions.
* @param {string[] | null} extensions The extensions to create.
* @returns {RegExp | null} The created `RegExp` object or null.
*/
function createExtensionRegExp(extensions) {
if (extensions) {
const normalizedExts = extensions.map(ext =>
escapeRegExp(ext.startsWith(".") ? ext.slice(1) : ext),
);
return new RegExp(`.\\.(?:${normalizedExts.join("|")})$`, "u");
}
return null;
}
/**
* The error type when no files match a glob.
*/
class NoFilesFoundError extends Error {
/**
* @param {string} pattern The glob pattern which was not found.
* @param {boolean} globDisabled If `true` then the pattern was a glob pattern, but glob was disabled.
*/
constructor(pattern, globDisabled) {
super(
`No files matching '${pattern}' were found${globDisabled ? " (glob was disabled)" : ""}.`,
);
this.messageTemplate = "file-not-found";
this.messageData = { pattern, globDisabled };
}
}
/**
* The error type when there are files matched by a glob, but all of them have been ignored.
*/
class AllFilesIgnoredError extends Error {
/**
* @param {string} pattern The glob pattern which was not found.
*/
constructor(pattern) {
super(`All files matched by '${pattern}' are ignored.`);
this.messageTemplate = "all-files-ignored";
this.messageData = { pattern };
}
}
/**
* This class provides the functionality that enumerates every file which is
* matched by given glob patterns and that configuration.
*/
class FileEnumerator {
/**
* Initialize this enumerator.
* @param {FileEnumeratorOptions} options The options.
*/
constructor({
cwd = process.cwd(),
configArrayFactory = new CascadingConfigArrayFactory({
cwd,
getEslintRecommendedConfig: () =>
require("@eslint/js").configs.recommended,
getEslintAllConfig: () => require("@eslint/js").configs.all,
}),
extensions = null,
globInputPaths = true,
errorOnUnmatchedPattern = true,
ignore = true,
} = {}) {
internalSlotsMap.set(this, {
configArrayFactory,
cwd,
defaultIgnores: IgnorePattern.createDefaultIgnore(cwd),
extensionRegExp: createExtensionRegExp(extensions),
globInputPaths,
errorOnUnmatchedPattern,
ignoreFlag: ignore,
});
}
/**
* Check if a given file is target or not.
* @param {string} filePath The path to a candidate file.
* @param {ConfigArray} [providedConfig] Optional. The configuration for the file.
* @returns {boolean} `true` if the file is a target.
*/
isTargetPath(filePath, providedConfig) {
const { configArrayFactory, extensionRegExp } =
internalSlotsMap.get(this);
// If `--ext` option is present, use it.
if (extensionRegExp) {
return extensionRegExp.test(filePath);
}
// `.js` file is target by default.
if (filePath.endsWith(".js")) {
return true;
}
// use `overrides[].files` to check additional targets.
const config =
providedConfig ||
configArrayFactory.getConfigArrayForFile(filePath, {
ignoreNotFoundError: true,
});
return config.isAdditionalTargetPath(filePath);
}
/**
* Iterate files which are matched by given glob patterns.
* @param {string|string[]} patternOrPatterns The glob patterns to iterate files.
* @throws {NoFilesFoundError|AllFilesIgnoredError} On an unmatched pattern.
* @returns {IterableIterator<FileAndConfig>} The found files.
*/
*iterateFiles(patternOrPatterns) {
const { globInputPaths, errorOnUnmatchedPattern } =
internalSlotsMap.get(this);
const patterns = Array.isArray(patternOrPatterns)
? patternOrPatterns
: [patternOrPatterns];
debug("Start to iterate files: %o", patterns);
// The set of paths to remove duplicate.
const set = new Set();
for (const pattern of patterns) {
let foundRegardlessOfIgnored = false;
let found = false;
// Skip empty string.
if (!pattern) {
continue;
}
// Iterate files of this pattern.
for (const { config, filePath, flag } of this._iterateFiles(
pattern,
)) {
foundRegardlessOfIgnored = true;
if (flag === IGNORED_SILENTLY) {
continue;
}
found = true;
// Remove duplicate paths while yielding paths.
if (!set.has(filePath)) {
set.add(filePath);
yield {
config,
filePath,
ignored: flag === IGNORED,
};
}
}
// Raise an error if any files were not found.
if (errorOnUnmatchedPattern) {
if (!foundRegardlessOfIgnored) {
throw new NoFilesFoundError(
pattern,
!globInputPaths && isGlob(pattern),
);
}
if (!found) {
throw new AllFilesIgnoredError(pattern);
}
}
}
debug(`Complete iterating files: ${JSON.stringify(patterns)}`);
}
/**
* Iterate files which are matched by a given glob pattern.
* @param {string} pattern The glob pattern to iterate files.
* @returns {IterableIterator<FileEntry>} The found files.
*/
_iterateFiles(pattern) {
const { cwd, globInputPaths } = internalSlotsMap.get(this);
const absolutePath = path.resolve(cwd, pattern);
const isDot = dotfilesPattern.test(pattern);
const stat = statSafeSync(absolutePath);
if (stat && stat.isDirectory()) {
return this._iterateFilesWithDirectory(absolutePath, isDot);
}
if (stat && stat.isFile()) {
return this._iterateFilesWithFile(absolutePath);
}
if (globInputPaths && isGlobPattern(pattern)) {
return this._iterateFilesWithGlob(pattern, isDot);
}
return [];
}
/**
* Iterate a file which is matched by a given path.
* @param {string} filePath The path to the target file.
* @returns {IterableIterator<FileEntry>} The found files.
* @private
*/
_iterateFilesWithFile(filePath) {
debug(`File: ${filePath}`);
const { configArrayFactory } = internalSlotsMap.get(this);
const config = configArrayFactory.getConfigArrayForFile(filePath);
const ignored = this._isIgnoredFile(filePath, { config, direct: true });
const flag = ignored ? IGNORED : NONE;
return [{ config, filePath, flag }];
}
/**
* Iterate files in a given path.
* @param {string} directoryPath The path to the target directory.
* @param {boolean} dotfiles If `true` then it doesn't skip dot files by default.
* @returns {IterableIterator<FileEntry>} The found files.
* @private
*/
_iterateFilesWithDirectory(directoryPath, dotfiles) {
debug(`Directory: ${directoryPath}`);
return this._iterateFilesRecursive(directoryPath, {
dotfiles,
recursive: true,
selector: null,
});
}
/**
* Iterate files which are matched by a given glob pattern.
* @param {string} pattern The glob pattern to iterate files.
* @param {boolean} dotfiles If `true` then it doesn't skip dot files by default.
* @returns {IterableIterator<FileEntry>} The found files.
* @private
*/
_iterateFilesWithGlob(pattern, dotfiles) {
debug(`Glob: ${pattern}`);
const { cwd } = internalSlotsMap.get(this);
const directoryPath = path.resolve(cwd, getGlobParent(pattern));
const absolutePath = path.resolve(cwd, pattern);
const globPart = absolutePath.slice(directoryPath.length + 1);
/*
* recursive if there are `**` or path separators in the glob part.
* Otherwise, patterns such as `src/*.js`, it doesn't need recursive.
*/
const recursive = /\*\*|\/|\\/u.test(globPart);
const selector = new Minimatch(absolutePath, minimatchOpts);
debug(`recursive? ${recursive}`);
return this._iterateFilesRecursive(directoryPath, {
dotfiles,
recursive,
selector,
});
}
/**
* Iterate files in a given path.
* @param {string} directoryPath The path to the target directory.
* @param {Object} options The options to iterate files.
* @param {boolean} [options.dotfiles] If `true` then it doesn't skip dot files by default.
* @param {boolean} [options.recursive] If `true` then it dives into sub directories.
* @param {InstanceType<Minimatch>} [options.selector] The matcher to choose files.
* @returns {IterableIterator<FileEntry>} The found files.
* @private
*/
*_iterateFilesRecursive(directoryPath, options) {
debug(`Enter the directory: ${directoryPath}`);
const { configArrayFactory } = internalSlotsMap.get(this);
/** @type {ConfigArray|null} */
let config = null;
// Enumerate the files of this directory.
for (const entry of readdirSafeSync(directoryPath)) {
const filePath = path.join(directoryPath, entry.name);
const fileInfo = entry.isSymbolicLink()
? statSafeSync(filePath)
: entry;
if (!fileInfo) {
continue;
}
// Check if the file is matched.
if (fileInfo.isFile()) {
if (!config) {
config = configArrayFactory.getConfigArrayForFile(
filePath,
/*
* We must ignore `ConfigurationNotFoundError` at this
* point because we don't know if target files exist in
* this directory.
*/
{ ignoreNotFoundError: true },
);
}
const matched = options.selector
? // Started with a glob pattern; choose by the pattern.
options.selector.match(filePath)
: // Started with a directory path; choose by file extensions.
this.isTargetPath(filePath, config);
if (matched) {
const ignored = this._isIgnoredFile(filePath, {
...options,
config,
});
const flag = ignored ? IGNORED_SILENTLY : NONE;
debug(
`Yield: ${entry.name}${ignored ? " but ignored" : ""}`,
);
yield {
config: configArrayFactory.getConfigArrayForFile(
filePath,
),
filePath,
flag,
};
} else {
debug(`Didn't match: ${entry.name}`);
}
// Dive into the sub directory.
} else if (options.recursive && fileInfo.isDirectory()) {
if (!config) {
config = configArrayFactory.getConfigArrayForFile(
filePath,
{ ignoreNotFoundError: true },
);
}
const ignored = this._isIgnoredFile(filePath + path.sep, {
...options,
config,
});
if (!ignored) {
yield* this._iterateFilesRecursive(filePath, options);
}
}
}
debug(`Leave the directory: ${directoryPath}`);
}
/**
* Check if a given file should be ignored.
* @param {string} filePath The path to a file to check.
* @param {Object} options Options
* @param {ConfigArray} [options.config] The config for this file.
* @param {boolean} [options.dotfiles] If `true` then this is not ignore dot files by default.
* @param {boolean} [options.direct] If `true` then this is a direct specified file.
* @returns {boolean} `true` if the file should be ignored.
* @private
*/
_isIgnoredFile(
filePath,
{ config: providedConfig, dotfiles = false, direct = false },
) {
const { configArrayFactory, defaultIgnores, ignoreFlag } =
internalSlotsMap.get(this);
if (ignoreFlag) {
const config =
providedConfig ||
configArrayFactory.getConfigArrayForFile(filePath, {
ignoreNotFoundError: true,
});
const ignores =
config.extractConfig(filePath).ignores || defaultIgnores;
return ignores(filePath, dotfiles);
}
return !direct && defaultIgnores(filePath, dotfiles);
}
}
//------------------------------------------------------------------------------
// Public Interface
//------------------------------------------------------------------------------
module.exports = { FileEnumerator };

View File

@@ -0,0 +1 @@
module.exports={C:{"38":0.00102,"52":0.00102,"68":0.00102,"78":0.00102,"81":0.00102,"108":0.00102,"115":0.02864,"116":0.00102,"118":0.00205,"123":0.00102,"124":0.00102,"125":0.00102,"127":0.00307,"128":0.00102,"133":0.00307,"134":0.00512,"135":0.08082,"136":0.24347,"137":0.00102,_:"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 39 40 41 42 43 44 45 46 47 48 49 50 51 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 69 70 71 72 73 74 75 76 77 79 80 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 109 110 111 112 113 114 117 119 120 121 122 126 129 130 131 132 138 139 140 3.5 3.6"},D:{"11":0.00102,"34":0.00102,"38":0.00102,"39":0.00102,"40":0.00102,"41":0.00102,"42":0.00102,"43":0.00102,"44":0.00102,"45":0.00102,"46":0.00307,"47":0.00102,"48":0.00102,"49":0.00102,"50":0.00102,"51":0.00102,"52":0.00102,"53":0.00102,"54":0.00102,"55":0.00102,"56":0.00102,"57":0.00102,"58":0.00307,"60":0.00102,"63":0.00205,"66":0.00205,"69":0.00205,"71":0.00205,"73":0.00205,"74":0.00205,"76":0.00102,"77":0.06752,"78":0.00102,"79":0.01125,"80":0.00205,"81":0.00205,"83":0.00716,"85":0.00102,"86":0.00102,"87":0.0133,"88":0.00102,"89":0.01023,"90":0.00102,"91":0.00102,"92":0.00307,"94":0.00409,"95":0.00921,"97":0.00818,"98":0.00512,"100":0.00818,"101":0.00205,"102":0.00102,"103":0.00307,"104":0.00307,"105":0.00307,"106":0.00409,"107":0.00921,"108":0.00921,"109":0.3202,"110":0.00307,"111":0.00307,"112":0.00512,"113":0.00102,"114":0.00614,"115":0.00614,"116":0.01535,"117":0.04808,"118":0.01739,"119":0.02148,"120":0.00614,"121":0.00409,"122":0.01432,"123":0.04706,"124":0.01125,"125":0.06445,"126":0.01637,"127":0.02046,"128":0.03274,"129":0.01228,"130":0.03376,"131":0.17493,"132":0.1688,"133":2.41326,"134":3.71349,"135":0.00512,"136":0.00102,_:"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 35 36 37 59 61 62 64 65 67 68 70 72 75 84 93 96 99 137 138"},F:{"46":0.00205,"79":0.00102,"87":0.00102,"95":0.00102,"102":0.00205,"112":0.00102,"113":0.00102,"114":0.00614,"115":0.00102,"116":0.05831,"117":0.23427,_:"9 11 12 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 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 80 81 82 83 84 85 86 88 89 90 91 92 93 94 96 97 98 99 100 101 103 104 105 106 107 108 109 110 111 9.5-9.6 10.0-10.1 10.5 10.6 11.1 11.5 11.6 12.1"},B:{"13":0.00102,"18":0.00307,"84":0.00205,"89":0.00102,"90":0.00205,"92":0.01432,"100":0.00102,"102":0.00102,"108":0.00205,"109":0.00205,"112":0.00102,"114":0.00307,"116":0.00102,"117":0.00921,"118":0.00102,"120":0.00102,"122":0.00205,"123":0.00205,"124":0.00102,"125":0.00102,"126":0.00307,"127":0.00102,"128":0.00102,"129":0.00409,"130":0.00307,"131":0.02455,"132":0.07059,"133":0.37237,"134":0.58925,_:"12 14 15 16 17 79 80 81 83 85 86 87 88 91 93 94 95 96 97 98 99 101 103 104 105 106 107 110 111 113 115 119 121"},E:{"14":0.00102,_:"0 4 5 6 7 8 9 10 11 12 13 15 3.1 3.2 6.1 7.1 9.1 10.1 11.1 12.1 13.1 15.1 15.2-15.3","5.1":0.03683,"14.1":0.00307,"15.4":0.00205,"15.5":0.00102,"15.6":0.00818,"16.0":0.00102,"16.1":0.00205,"16.2":0.00307,"16.3":0.00921,"16.4":0.00102,"16.5":0.00512,"16.6":0.02558,"17.0":0.00409,"17.1":0.00409,"17.2":0.00205,"17.3":0.00307,"17.4":0.00818,"17.5":0.00716,"17.6":0.01841,"18.0":0.00818,"18.1":0.04092,"18.2":0.00921,"18.3":0.13606,"18.4":0.00205},G:{"8":0,"3.2":0,"4.0-4.1":0,"4.2-4.3":0.00129,"5.0-5.1":0,"6.0-6.1":0.00388,"7.0-7.1":0.00259,"8.1-8.4":0,"9.0-9.2":0.00194,"9.3":0.00906,"10.0-10.2":0.00065,"10.3":0.01489,"11.0-11.2":0.06861,"11.3-11.4":0.00453,"12.0-12.1":0.00259,"12.2-12.5":0.06408,"13.0-13.1":0.00129,"13.2":0.00194,"13.3":0.00259,"13.4-13.7":0.00906,"14.0-14.4":0.02265,"14.5-14.8":0.02718,"15.0-15.1":0.01489,"15.2-15.3":0.01489,"15.4":0.01812,"15.5":0.02071,"15.6-15.8":0.25501,"16.0":0.03625,"16.1":0.07443,"16.2":0.03883,"16.3":0.06731,"16.4":0.01489,"16.5":0.02783,"16.6-16.7":0.30226,"17.0":0.01812,"17.1":0.03236,"17.2":0.0246,"17.3":0.0343,"17.4":0.06861,"17.5":0.15275,"17.6-17.7":0.44336,"18.0":0.12427,"18.1":0.40647,"18.2":0.18187,"18.3":3.80125,"18.4":0.05631},P:{"4":0.03099,"20":0.02066,"21":0.0723,"22":0.2169,"23":0.11361,"24":0.08263,"25":0.13427,"26":0.26854,"27":1.65254,_:"5.0-5.4 9.2 10.1 12.0","6.2-6.4":0.01033,"7.2-7.4":0.05164,"8.2":0.01033,"11.1-11.2":0.02066,"13.0":0.02066,"14.0":0.02066,"15.0":0.01033,"16.0":0.03099,"17.0":0.04131,"18.0":0.02066,"19.0":0.05164},I:{"0":0.04479,"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.41192,_:"10 11 12 11.1 11.5 12.1"},A:{"11":0.00205,_:"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.07182},Q:{_:"14.9"},O:{"0":0.04489},H:{"0":0.01},L:{"0":80.21273}};

View File

@@ -0,0 +1,447 @@
'use strict'
let Comment = require('./comment')
let Declaration = require('./declaration')
let Node = require('./node')
let { isClean, my } = require('./symbols')
let AtRule, parse, Root, Rule
function cleanSource(nodes) {
return nodes.map(i => {
if (i.nodes) i.nodes = cleanSource(i.nodes)
delete i.source
return i
})
}
function markTreeDirty(node) {
node[isClean] = false
if (node.proxyOf.nodes) {
for (let i of node.proxyOf.nodes) {
markTreeDirty(i)
}
}
}
class Container extends Node {
get first() {
if (!this.proxyOf.nodes) return undefined
return this.proxyOf.nodes[0]
}
get last() {
if (!this.proxyOf.nodes) return undefined
return this.proxyOf.nodes[this.proxyOf.nodes.length - 1]
}
append(...children) {
for (let child of children) {
let nodes = this.normalize(child, this.last)
for (let node of nodes) this.proxyOf.nodes.push(node)
}
this.markDirty()
return this
}
cleanRaws(keepBetween) {
super.cleanRaws(keepBetween)
if (this.nodes) {
for (let node of this.nodes) node.cleanRaws(keepBetween)
}
}
each(callback) {
if (!this.proxyOf.nodes) return undefined
let iterator = this.getIterator()
let index, result
while (this.indexes[iterator] < this.proxyOf.nodes.length) {
index = this.indexes[iterator]
result = callback(this.proxyOf.nodes[index], index)
if (result === false) break
this.indexes[iterator] += 1
}
delete this.indexes[iterator]
return result
}
every(condition) {
return this.nodes.every(condition)
}
getIterator() {
if (!this.lastEach) this.lastEach = 0
if (!this.indexes) this.indexes = {}
this.lastEach += 1
let iterator = this.lastEach
this.indexes[iterator] = 0
return iterator
}
getProxyProcessor() {
return {
get(node, prop) {
if (prop === 'proxyOf') {
return node
} else if (!node[prop]) {
return node[prop]
} else if (
prop === 'each' ||
(typeof prop === 'string' && prop.startsWith('walk'))
) {
return (...args) => {
return node[prop](
...args.map(i => {
if (typeof i === 'function') {
return (child, index) => i(child.toProxy(), index)
} else {
return i
}
})
)
}
} else if (prop === 'every' || prop === 'some') {
return cb => {
return node[prop]((child, ...other) =>
cb(child.toProxy(), ...other)
)
}
} else if (prop === 'root') {
return () => node.root().toProxy()
} else if (prop === 'nodes') {
return node.nodes.map(i => i.toProxy())
} else if (prop === 'first' || prop === 'last') {
return node[prop].toProxy()
} else {
return node[prop]
}
},
set(node, prop, value) {
if (node[prop] === value) return true
node[prop] = value
if (prop === 'name' || prop === 'params' || prop === 'selector') {
node.markDirty()
}
return true
}
}
}
index(child) {
if (typeof child === 'number') return child
if (child.proxyOf) child = child.proxyOf
return this.proxyOf.nodes.indexOf(child)
}
insertAfter(exist, add) {
let existIndex = this.index(exist)
let nodes = this.normalize(add, this.proxyOf.nodes[existIndex]).reverse()
existIndex = this.index(exist)
for (let node of nodes) this.proxyOf.nodes.splice(existIndex + 1, 0, node)
let index
for (let id in this.indexes) {
index = this.indexes[id]
if (existIndex < index) {
this.indexes[id] = index + nodes.length
}
}
this.markDirty()
return this
}
insertBefore(exist, add) {
let existIndex = this.index(exist)
let type = existIndex === 0 ? 'prepend' : false
let nodes = this.normalize(
add,
this.proxyOf.nodes[existIndex],
type
).reverse()
existIndex = this.index(exist)
for (let node of nodes) this.proxyOf.nodes.splice(existIndex, 0, node)
let index
for (let id in this.indexes) {
index = this.indexes[id]
if (existIndex <= index) {
this.indexes[id] = index + nodes.length
}
}
this.markDirty()
return this
}
normalize(nodes, sample) {
if (typeof nodes === 'string') {
nodes = cleanSource(parse(nodes).nodes)
} else if (typeof nodes === 'undefined') {
nodes = []
} else if (Array.isArray(nodes)) {
nodes = nodes.slice(0)
for (let i of nodes) {
if (i.parent) i.parent.removeChild(i, 'ignore')
}
} else if (nodes.type === 'root' && this.type !== 'document') {
nodes = nodes.nodes.slice(0)
for (let i of nodes) {
if (i.parent) i.parent.removeChild(i, 'ignore')
}
} else if (nodes.type) {
nodes = [nodes]
} else if (nodes.prop) {
if (typeof nodes.value === 'undefined') {
throw new Error('Value field is missed in node creation')
} else if (typeof nodes.value !== 'string') {
nodes.value = String(nodes.value)
}
nodes = [new Declaration(nodes)]
} else if (nodes.selector || nodes.selectors) {
nodes = [new Rule(nodes)]
} else if (nodes.name) {
nodes = [new AtRule(nodes)]
} else if (nodes.text) {
nodes = [new Comment(nodes)]
} else {
throw new Error('Unknown node type in node creation')
}
let processed = nodes.map(i => {
/* c8 ignore next */
if (!i[my]) Container.rebuild(i)
i = i.proxyOf
if (i.parent) i.parent.removeChild(i)
if (i[isClean]) markTreeDirty(i)
if (!i.raws) i.raws = {}
if (typeof i.raws.before === 'undefined') {
if (sample && typeof sample.raws.before !== 'undefined') {
i.raws.before = sample.raws.before.replace(/\S/g, '')
}
}
i.parent = this.proxyOf
return i
})
return processed
}
prepend(...children) {
children = children.reverse()
for (let child of children) {
let nodes = this.normalize(child, this.first, 'prepend').reverse()
for (let node of nodes) this.proxyOf.nodes.unshift(node)
for (let id in this.indexes) {
this.indexes[id] = this.indexes[id] + nodes.length
}
}
this.markDirty()
return this
}
push(child) {
child.parent = this
this.proxyOf.nodes.push(child)
return this
}
removeAll() {
for (let node of this.proxyOf.nodes) node.parent = undefined
this.proxyOf.nodes = []
this.markDirty()
return this
}
removeChild(child) {
child = this.index(child)
this.proxyOf.nodes[child].parent = undefined
this.proxyOf.nodes.splice(child, 1)
let index
for (let id in this.indexes) {
index = this.indexes[id]
if (index >= child) {
this.indexes[id] = index - 1
}
}
this.markDirty()
return this
}
replaceValues(pattern, opts, callback) {
if (!callback) {
callback = opts
opts = {}
}
this.walkDecls(decl => {
if (opts.props && !opts.props.includes(decl.prop)) return
if (opts.fast && !decl.value.includes(opts.fast)) return
decl.value = decl.value.replace(pattern, callback)
})
this.markDirty()
return this
}
some(condition) {
return this.nodes.some(condition)
}
walk(callback) {
return this.each((child, i) => {
let result
try {
result = callback(child, i)
} catch (e) {
throw child.addToError(e)
}
if (result !== false && child.walk) {
result = child.walk(callback)
}
return result
})
}
walkAtRules(name, callback) {
if (!callback) {
callback = name
return this.walk((child, i) => {
if (child.type === 'atrule') {
return callback(child, i)
}
})
}
if (name instanceof RegExp) {
return this.walk((child, i) => {
if (child.type === 'atrule' && name.test(child.name)) {
return callback(child, i)
}
})
}
return this.walk((child, i) => {
if (child.type === 'atrule' && child.name === name) {
return callback(child, i)
}
})
}
walkComments(callback) {
return this.walk((child, i) => {
if (child.type === 'comment') {
return callback(child, i)
}
})
}
walkDecls(prop, callback) {
if (!callback) {
callback = prop
return this.walk((child, i) => {
if (child.type === 'decl') {
return callback(child, i)
}
})
}
if (prop instanceof RegExp) {
return this.walk((child, i) => {
if (child.type === 'decl' && prop.test(child.prop)) {
return callback(child, i)
}
})
}
return this.walk((child, i) => {
if (child.type === 'decl' && child.prop === prop) {
return callback(child, i)
}
})
}
walkRules(selector, callback) {
if (!callback) {
callback = selector
return this.walk((child, i) => {
if (child.type === 'rule') {
return callback(child, i)
}
})
}
if (selector instanceof RegExp) {
return this.walk((child, i) => {
if (child.type === 'rule' && selector.test(child.selector)) {
return callback(child, i)
}
})
}
return this.walk((child, i) => {
if (child.type === 'rule' && child.selector === selector) {
return callback(child, i)
}
})
}
}
Container.registerParse = dependant => {
parse = dependant
}
Container.registerRule = dependant => {
Rule = dependant
}
Container.registerAtRule = dependant => {
AtRule = dependant
}
Container.registerRoot = dependant => {
Root = dependant
}
module.exports = Container
Container.default = Container
/* c8 ignore start */
Container.rebuild = node => {
if (node.type === 'atrule') {
Object.setPrototypeOf(node, AtRule.prototype)
} else if (node.type === 'rule') {
Object.setPrototypeOf(node, Rule.prototype)
} else if (node.type === 'decl') {
Object.setPrototypeOf(node, Declaration.prototype)
} else if (node.type === 'comment') {
Object.setPrototypeOf(node, Comment.prototype)
} else if (node.type === 'root') {
Object.setPrototypeOf(node, Root.prototype)
}
node[my] = true
if (node.nodes) {
node.nodes.forEach(child => {
Container.rebuild(child)
})
}
}
/* c8 ignore stop */

View File

@@ -0,0 +1,9 @@
The MIT License (MIT)
Copyright (c) 2017 [Node.js API collaborators](https://github.com/nodejs/node-addon-api#collaborators)
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 @@
module.exports={A:{A:{"2":"K D E F A B mC"},B:{"1":"0 9 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","2":"C","388":"L M"},C:{"1":"0 3 4 5 6 7 8 9 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","2":"1 2 nC LC J PB K D E F A B C L M G N O P QB qC rC"},D:{"1":"0 9 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":"1 2 3 4 5 6 J PB K D E F A B C L M G N O P QB","132":"7 8 RB SB TB UB VB WB XB"},E:{"1":"F A B C L M G 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":"J PB K D sC SC tC","388":"E vC","514":"uC"},F:{"1":"0 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 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":"F B C 4C 5C 6C 7C FC kC 8C GC","132":"1 2 G N O P QB"},G:{"1":"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 BD CD","388":"E DD"},H:{"2":"WD"},I:{"1":"I bD cD","2":"LC J XD YD ZD aD lC"},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 J dD eD fD gD hD TC iD jD kD lD mD IC JC KC nD"},Q:{"1":"oD"},R:{"1":"pD"},S:{"1":"qD rD"}},B:1,C:"HTML templates",D:true};

View File

@@ -0,0 +1,15 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = _taggedTemplateLiteralLoose;
function _taggedTemplateLiteralLoose(strings, raw) {
if (!raw) {
raw = strings.slice(0);
}
strings.raw = raw;
return strings;
}
//# sourceMappingURL=taggedTemplateLiteralLoose.js.map

View File

@@ -0,0 +1,21 @@
MIT License
Copyright (c) Facebook, Inc. and its affiliates.
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,93 @@
import { useMatch } from './useMatch'
import type {
StructuralSharingOption,
ValidateSelected,
} from './structuralSharing'
import type {
AnyRouter,
RegisteredRouter,
ResolveUseParams,
StrictOrFrom,
ThrowConstraint,
ThrowOrOptional,
UseParamsResult,
} from '@tanstack/router-core'
export interface UseParamsBaseOptions<
TRouter extends AnyRouter,
TFrom,
TStrict extends boolean,
TThrow extends boolean,
TSelected,
TStructuralSharing,
> {
select?: (
params: ResolveUseParams<TRouter, TFrom, TStrict>,
) => ValidateSelected<TRouter, TSelected, TStructuralSharing>
shouldThrow?: TThrow
}
export type UseParamsOptions<
TRouter extends AnyRouter,
TFrom extends string | undefined,
TStrict extends boolean,
TThrow extends boolean,
TSelected,
TStructuralSharing,
> = StrictOrFrom<TRouter, TFrom, TStrict> &
UseParamsBaseOptions<
TRouter,
TFrom,
TStrict,
TThrow,
TSelected,
TStructuralSharing
> &
StructuralSharingOption<TRouter, TSelected, TStructuralSharing>
export type UseParamsRoute<out TFrom> = <
TRouter extends AnyRouter = RegisteredRouter,
TSelected = unknown,
TStructuralSharing extends boolean = boolean,
>(
opts?: UseParamsBaseOptions<
TRouter,
TFrom,
/* TStrict */ true,
/* TThrow */ true,
TSelected,
TStructuralSharing
> &
StructuralSharingOption<TRouter, TSelected, TStructuralSharing>,
) => UseParamsResult<TRouter, TFrom, true, TSelected>
export function useParams<
TRouter extends AnyRouter = RegisteredRouter,
const TFrom extends string | undefined = undefined,
TStrict extends boolean = true,
TThrow extends boolean = true,
TSelected = unknown,
TStructuralSharing extends boolean = boolean,
>(
opts: UseParamsOptions<
TRouter,
TFrom,
TStrict,
ThrowConstraint<TStrict, TThrow>,
TSelected,
TStructuralSharing
>,
): ThrowOrOptional<
UseParamsResult<TRouter, TFrom, TStrict, TSelected>,
TThrow
> {
return useMatch({
from: opts.from!,
strict: opts.strict,
shouldThrow: opts.shouldThrow,
structuralSharing: opts.structuralSharing,
select: (match: any) => {
return opts.select ? opts.select(match.params) : match.params
},
}) as any
}

View File

@@ -0,0 +1,37 @@
# @jridgewell/set-array
> Like a Set, but provides the index of the `key` in the backing array
This is designed to allow synchronizing a second array with the contents of the backing array, like
how in a sourcemap `sourcesContent[i]` is the source content associated with `source[i]`, and there
are never duplicates.
## Installation
```sh
npm install @jridgewell/set-array
```
## Usage
```js
import { SetArray, get, put, pop } from '@jridgewell/set-array';
const sa = new SetArray();
let index = put(sa, 'first');
assert.strictEqual(index, 0);
index = put(sa, 'second');
assert.strictEqual(index, 1);
assert.deepEqual(sa.array, [ 'first', 'second' ]);
index = get(sa, 'first');
assert.strictEqual(index, 0);
pop(sa);
index = get(sa, 'second');
assert.strictEqual(index, undefined);
assert.deepEqual(sa.array, [ 'first' ]);
```

View File

@@ -0,0 +1,30 @@
{{# def.definitions }}
{{# def.errors }}
{{# def.setupKeyword }}
{{# def.$data }}
{{
var $i = 'i' + $lvl
, $vSchema = 'schema' + $lvl;
}}
{{? !$isData }}
var {{=$vSchema}} = validate.schema{{=$schemaPath}};
{{?}}
var {{=$valid}};
{{?$isData}}{{# def.check$dataIsArray }}{{?}}
{{=$valid}} = false;
for (var {{=$i}}=0; {{=$i}}<{{=$vSchema}}.length; {{=$i}}++)
if (equal({{=$data}}, {{=$vSchema}}[{{=$i}}])) {
{{=$valid}} = true;
break;
}
{{? $isData }} } {{?}}
{{# def.checkError:'enum' }}
{{? $breakOnError }} else { {{?}}

View File

@@ -0,0 +1,14 @@
import { RouterCore } from "@tanstack/router-core";
const createRouter = (options) => {
return new Router(options);
};
class Router extends RouterCore {
constructor(options) {
super(options);
}
}
export {
Router,
createRouter
};
//# sourceMappingURL=router.js.map

View File

@@ -0,0 +1,68 @@
# tiny-warning 🔬⚠️
[![Build Status](https://travis-ci.org/alexreardon/tiny-warning.svg?branch=master)](https://travis-ci.org/alexreardon/tiny-warning)
[![npm](https://img.shields.io/npm/v/tiny-warning.svg)](https://www.npmjs.com/package/tiny-warning) [![Downloads per month](https://img.shields.io/npm/dm/tiny-warning.svg)](https://www.npmjs.com/package/tiny-warning) [![dependencies](https://david-dm.org/alexreardon/tiny-warning.svg)](https://david-dm.org/alexreardon/tiny-warning)
[![min](https://img.shields.io/bundlephobia/min/tiny-warning.svg)](https://www.npmjs.com/package/tiny-warning)
[![minzip](https://img.shields.io/bundlephobia/minzip/tiny-warning.svg)](https://www.npmjs.com/package/tiny-warning)
A tiny [`warning`](https://www.npmjs.com/package/warning) alternative.
```js
import warning from 'tiny-warning';
warning(truthyValue, 'This should not log a warning');
warning(falsyValue, 'This should log a warning');
// console.warn('Warning: This should log a warning');
```
## API: `(condition: mixed, message: string) => void`
- `condition` is required and can be anything
- `message` is an required string that will be passed onto `console.warn`
## Why `tiny-warning`?
The [`library: warning`](https://www.npmjs.com/package/warning) supports passing in arguments to the `warning` function in a sprintf style `(condition, format, a, b, c, d, e, f)`. It has internal logic to execute the sprintf substitutions. `tiny-warning` has dropped all of the sprintf logic. `tiny-warning` allows you to pass a single string message. With [template literals](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals) there is really no need for a custom message formatter to be built into the library. If you need a multi part message you can just do this: `warning(condition, 'Hello, ${name} - how are you today?')`
## Dropping your `warning` for kb savings!
We recommend using [`babel-plugin-dev-expression`](https://www.npmjs.com/package/babel-plugin-dev-expression) to remove `warning` calls from your production build. This saves you kb's as well as avoids logging warnings to the console for production.
What it does it turn your code that looks like this:
```js
warning(condition, 'My cool message that takes up a lot of kbs');
```
Into this
```js
if ('production' !== process.env.NODE_ENV) {
warning(condition, 'My cool message that takes up a lot of kbs');
}
```
Your bundler can then drop the code in the `"production" !== process.env.NODE_ENV` block for your production builds
Final result:
```js
// nothing to see here! 👍
```
> For `rollup` use [rollup-plugin-replace](https://github.com/rollup/rollup-plugin-replace) and set `NODE_ENV` to `production` and then `rollup` will treeshake out the unused code
>
> [`Webpack` instructions](https://webpack.js.org/guides/production/#specify-the-mode)
## Builds
- We have a `es` (EcmaScript module) build (because you _know_ you want to deduplicate this super heavy library)
- We have a `cjs` (CommonJS) build
- We have a `umd` (Universal module definition) build in case you needed it
We expect `process.env.NODE_ENV` to be available at module compilation. We cache this value
## That's it!
🤘

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 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 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 qC rC"},D:{"1":"0 9 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 uB vB MC wB NC xB yB zB 0B"},E:{"1":"JC bC cC dC eC fC 2C KC gC hC iC jC 3C","2":"J PB K D E F A B C L M G sC SC tC uC vC wC TC FC GC xC yC zC UC VC HC 0C IC WC XC YC ZC aC 1C"},F:{"1":"0 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 hB iB jB kB lB mB nB oB pB 4C 5C 6C 7C FC kC 8C GC"},G:{"1":"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 JD KD LD MD ND OD PD QD RD SD UC VC HC TD IC WC XC YC ZC aC UD"},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 hD TC iD jD kD lD mD IC JC KC nD","2":"J dD eD fD gD"},Q:{"1":"oD"},R:{"1":"pD"},S:{"2":"qD rD"}},B:1,C:"Resource Hints: modulepreload",D:true};

View File

@@ -0,0 +1,58 @@
{
"name": "globals",
"version": "14.0.0",
"description": "Global identifiers from different JavaScript environments",
"license": "MIT",
"repository": "sindresorhus/globals",
"funding": "https://github.com/sponsors/sindresorhus",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "https://sindresorhus.com"
},
"sideEffects": false,
"engines": {
"node": ">=18"
},
"scripts": {
"test": "xo && ava && tsd",
"prepare": "npm run --silent update-types",
"update-builtin-globals": "node scripts/get-builtin-globals.mjs",
"update-types": "node scripts/generate-types.mjs > index.d.ts"
},
"files": [
"index.js",
"index.d.ts",
"globals.json"
],
"keywords": [
"globals",
"global",
"identifiers",
"variables",
"vars",
"jshint",
"eslint",
"environments"
],
"devDependencies": {
"ava": "^2.4.0",
"cheerio": "^1.0.0-rc.12",
"tsd": "^0.30.4",
"type-fest": "^4.10.2",
"xo": "^0.36.1"
},
"xo": {
"ignores": [
"get-browser-globals.js"
],
"rules": {
"node/no-unsupported-features/es-syntax": "off"
}
},
"tsd": {
"compilerOptions": {
"resolveJsonModule": true
}
}
}

View File

@@ -0,0 +1,132 @@
/* -*- Mode: js; js-indent-level: 2; -*- */
/*
* Copyright 2011 Mozilla Foundation and contributors
* Licensed under the New BSD license. See LICENSE or:
* http://opensource.org/licenses/BSD-3-Clause
*/
// It turns out that some (most?) JavaScript engines don't self-host
// `Array.prototype.sort`. This makes sense because C++ will likely remain
// faster than JS when doing raw CPU-intensive sorting. However, when using a
// custom comparator function, calling back and forth between the VM's C++ and
// JIT'd JS is rather slow *and* loses JIT type information, resulting in
// worse generated code for the comparator function than would be optimal. In
// fact, when sorting with a comparator, these costs outweigh the benefits of
// sorting in C++. By using our own JS-implemented Quick Sort (below), we get
// a ~3500ms mean speed-up in `bench/bench.html`.
function SortTemplate(comparator) {
/**
* Swap the elements indexed by `x` and `y` in the array `ary`.
*
* @param {Array} ary
* The array.
* @param {Number} x
* The index of the first item.
* @param {Number} y
* The index of the second item.
*/
function swap(ary, x, y) {
var temp = ary[x];
ary[x] = ary[y];
ary[y] = temp;
}
/**
* Returns a random integer within the range `low .. high` inclusive.
*
* @param {Number} low
* The lower bound on the range.
* @param {Number} high
* The upper bound on the range.
*/
function randomIntInRange(low, high) {
return Math.round(low + (Math.random() * (high - low)));
}
/**
* The Quick Sort algorithm.
*
* @param {Array} ary
* An array to sort.
* @param {function} comparator
* Function to use to compare two items.
* @param {Number} p
* Start index of the array
* @param {Number} r
* End index of the array
*/
function doQuickSort(ary, comparator, p, r) {
// If our lower bound is less than our upper bound, we (1) partition the
// array into two pieces and (2) recurse on each half. If it is not, this is
// the empty array and our base case.
if (p < r) {
// (1) Partitioning.
//
// The partitioning chooses a pivot between `p` and `r` and moves all
// elements that are less than or equal to the pivot to the before it, and
// all the elements that are greater than it after it. The effect is that
// once partition is done, the pivot is in the exact place it will be when
// the array is put in sorted order, and it will not need to be moved
// again. This runs in O(n) time.
// Always choose a random pivot so that an input array which is reverse
// sorted does not cause O(n^2) running time.
var pivotIndex = randomIntInRange(p, r);
var i = p - 1;
swap(ary, pivotIndex, r);
var pivot = ary[r];
// Immediately after `j` is incremented in this loop, the following hold
// true:
//
// * Every element in `ary[p .. i]` is less than or equal to the pivot.
//
// * Every element in `ary[i+1 .. j-1]` is greater than the pivot.
for (var j = p; j < r; j++) {
if (comparator(ary[j], pivot, false) <= 0) {
i += 1;
swap(ary, i, j);
}
}
swap(ary, i + 1, j);
var q = i + 1;
// (2) Recurse on each half.
doQuickSort(ary, comparator, p, q - 1);
doQuickSort(ary, comparator, q + 1, r);
}
}
return doQuickSort;
}
function cloneSort(comparator) {
let template = SortTemplate.toString();
let templateFn = new Function(`return ${template}`)();
return templateFn(comparator);
}
/**
* Sort the given array in-place with the given comparator function.
*
* @param {Array} ary
* An array to sort.
* @param {function} comparator
* Function to use to compare two items.
*/
let sortCache = new WeakMap();
exports.quickSort = function (ary, comparator, start = 0) {
let doQuickSort = sortCache.get(comparator);
if (doQuickSort === void 0) {
doQuickSort = cloneSort(comparator);
sortCache.set(comparator, doQuickSort);
}
doQuickSort(ary, comparator, start, ary.length - 1);
};

View File

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