update
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -0,0 +1,68 @@
|
||||
class Node {
|
||||
/// value;
|
||||
/// next;
|
||||
|
||||
constructor(value) {
|
||||
this.value = value;
|
||||
|
||||
// TODO: Remove this when targeting Node.js 12.
|
||||
this.next = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
class Queue {
|
||||
// TODO: Use private class fields when targeting Node.js 12.
|
||||
// #_head;
|
||||
// #_tail;
|
||||
// #_size;
|
||||
|
||||
constructor() {
|
||||
this.clear();
|
||||
}
|
||||
|
||||
enqueue(value) {
|
||||
const node = new Node(value);
|
||||
|
||||
if (this._head) {
|
||||
this._tail.next = node;
|
||||
this._tail = node;
|
||||
} else {
|
||||
this._head = node;
|
||||
this._tail = node;
|
||||
}
|
||||
|
||||
this._size++;
|
||||
}
|
||||
|
||||
dequeue() {
|
||||
const current = this._head;
|
||||
if (!current) {
|
||||
return;
|
||||
}
|
||||
|
||||
this._head = this._head.next;
|
||||
this._size--;
|
||||
return current.value;
|
||||
}
|
||||
|
||||
clear() {
|
||||
this._head = undefined;
|
||||
this._tail = undefined;
|
||||
this._size = 0;
|
||||
}
|
||||
|
||||
get size() {
|
||||
return this._size;
|
||||
}
|
||||
|
||||
* [Symbol.iterator]() {
|
||||
let current = this._head;
|
||||
|
||||
while (current) {
|
||||
yield current.value;
|
||||
current = current.next;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Queue;
|
||||
@@ -0,0 +1,105 @@
|
||||
# eslint-visitor-keys
|
||||
|
||||
[](https://www.npmjs.com/package/eslint-visitor-keys)
|
||||
[](http://www.npmtrends.com/eslint-visitor-keys)
|
||||
[](https://github.com/eslint/eslint-visitor-keys/actions)
|
||||
|
||||
Constants and utilities about visitor keys to traverse AST.
|
||||
|
||||
## 💿 Installation
|
||||
|
||||
Use [npm] to install.
|
||||
|
||||
```bash
|
||||
$ npm install eslint-visitor-keys
|
||||
```
|
||||
|
||||
### Requirements
|
||||
|
||||
- [Node.js] `^12.22.0`, `^14.17.0`, or `>=16.0.0`
|
||||
|
||||
|
||||
## 📖 Usage
|
||||
|
||||
To use in an ESM file:
|
||||
|
||||
```js
|
||||
import * as evk from "eslint-visitor-keys"
|
||||
```
|
||||
|
||||
To use in a CommonJS file:
|
||||
|
||||
```js
|
||||
const evk = require("eslint-visitor-keys")
|
||||
```
|
||||
|
||||
### evk.KEYS
|
||||
|
||||
> type: `{ [type: string]: string[] | undefined }`
|
||||
|
||||
Visitor keys. This keys are frozen.
|
||||
|
||||
This is an object. Keys are the type of [ESTree] nodes. Their values are an array of property names which have child nodes.
|
||||
|
||||
For example:
|
||||
|
||||
```
|
||||
console.log(evk.KEYS.AssignmentExpression) // → ["left", "right"]
|
||||
```
|
||||
|
||||
### evk.getKeys(node)
|
||||
|
||||
> type: `(node: object) => string[]`
|
||||
|
||||
Get the visitor keys of a given AST node.
|
||||
|
||||
This is similar to `Object.keys(node)` of ES Standard, but some keys are excluded: `parent`, `leadingComments`, `trailingComments`, and names which start with `_`.
|
||||
|
||||
This will be used to traverse unknown nodes.
|
||||
|
||||
For example:
|
||||
|
||||
```js
|
||||
const node = {
|
||||
type: "AssignmentExpression",
|
||||
left: { type: "Identifier", name: "foo" },
|
||||
right: { type: "Literal", value: 0 }
|
||||
}
|
||||
console.log(evk.getKeys(node)) // → ["type", "left", "right"]
|
||||
```
|
||||
|
||||
### evk.unionWith(additionalKeys)
|
||||
|
||||
> type: `(additionalKeys: object) => { [type: string]: string[] | undefined }`
|
||||
|
||||
Make the union set with `evk.KEYS` and the given keys.
|
||||
|
||||
- The order of keys is, `additionalKeys` is at first, then `evk.KEYS` is concatenated after that.
|
||||
- It removes duplicated keys as keeping the first one.
|
||||
|
||||
For example:
|
||||
|
||||
```js
|
||||
console.log(evk.unionWith({
|
||||
MethodDefinition: ["decorators"]
|
||||
})) // → { ..., MethodDefinition: ["decorators", "key", "value"], ... }
|
||||
```
|
||||
|
||||
## 📰 Change log
|
||||
|
||||
See [GitHub releases](https://github.com/eslint/eslint-visitor-keys/releases).
|
||||
|
||||
## 🍻 Contributing
|
||||
|
||||
Welcome. See [ESLint contribution guidelines](https://eslint.org/docs/developer-guide/contributing/).
|
||||
|
||||
### Development commands
|
||||
|
||||
- `npm test` runs tests and measures code coverage.
|
||||
- `npm run lint` checks source codes with ESLint.
|
||||
- `npm run test:open-coverage` opens the code coverage report of the previous test with your default browser.
|
||||
|
||||
|
||||
[npm]: https://www.npmjs.com/
|
||||
[Node.js]: https://nodejs.org/
|
||||
[ESTree]: https://github.com/estree/estree
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"names":["_extends","exports","default","Object","assign","bind","target","i","arguments","length","source","key","prototype","hasOwnProperty","call","apply"],"sources":["../../src/helpers/extends.ts"],"sourcesContent":["/* @minVersion 7.0.0-beta.0 */\n\ntype Intersection<R extends any[]> = R extends [infer H, ...infer S]\n ? H & Intersection<S>\n : unknown;\n\nexport default function _extends<T extends object, U extends unknown[]>(\n target: T,\n ...sources: U\n): T & Intersection<U>;\nexport default function _extends() {\n // @ts-expect-error explicitly assign to function\n _extends = Object.assign\n ? // need a bind because https://github.com/babel/babel/issues/14527\n // @ts-expect-error -- intentionally omitting the argument\n Object.assign.bind(/* undefined */)\n : function (target: any) {\n for (var i = 1; i < arguments.length; i++) {\n var source = arguments[i];\n for (var key in source) {\n if (Object.prototype.hasOwnProperty.call(source, key)) {\n target[key] = source[key];\n }\n }\n }\n return target;\n };\n\n return _extends.apply(\n null,\n arguments as any as [source: object, ...target: any[]],\n );\n}\n"],"mappings":";;;;;;AAUe,SAASA,QAAQA,CAAA,EAAG;EAEjCC,OAAA,CAAAC,OAAA,GAAAF,QAAQ,GAAGG,MAAM,CAACC,MAAM,GAGpBD,MAAM,CAACC,MAAM,CAACC,IAAI,CAAgB,CAAC,GACnC,UAAUC,MAAW,EAAE;IACrB,KAAK,IAAIC,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGC,SAAS,CAACC,MAAM,EAAEF,CAAC,EAAE,EAAE;MACzC,IAAIG,MAAM,GAAGF,SAAS,CAACD,CAAC,CAAC;MACzB,KAAK,IAAII,GAAG,IAAID,MAAM,EAAE;QACtB,IAAIP,MAAM,CAACS,SAAS,CAACC,cAAc,CAACC,IAAI,CAACJ,MAAM,EAAEC,GAAG,CAAC,EAAE;UACrDL,MAAM,CAACK,GAAG,CAAC,GAAGD,MAAM,CAACC,GAAG,CAAC;QAC3B;MACF;IACF;IACA,OAAOL,MAAM;EACf,CAAC;EAEL,OAAON,QAAQ,CAACe,KAAK,CACnB,IAAI,EACJP,SACF,CAAC;AACH","ignoreList":[]}
|
||||
@@ -0,0 +1,90 @@
|
||||
/**
|
||||
* Basic draw editor in order to generate an Ink annotation.
|
||||
*/
|
||||
export class InkEditor extends AnnotationEditor {
|
||||
static _defaultColor: null;
|
||||
static _defaultOpacity: number;
|
||||
static _defaultThickness: number;
|
||||
static _type: string;
|
||||
static _editorType: number;
|
||||
/** @inheritdoc */
|
||||
static initialize(l10n: any, uiManager: any): void;
|
||||
/** @inheritdoc */
|
||||
static updateDefaultParams(type: any, value: any): void;
|
||||
/** @inheritdoc */
|
||||
static get defaultPropertiesToUpdate(): any[][];
|
||||
/**
|
||||
* Convert into a Path2D.
|
||||
* @param {Array<Array<number>>} bezier
|
||||
* @returns {Path2D}
|
||||
*/
|
||||
static "__#25@#buildPath2D"(bezier: Array<Array<number>>): Path2D;
|
||||
static "__#25@#toPDFCoordinates"(points: any, rect: any, rotation: any): any;
|
||||
static "__#25@#fromPDFCoordinates"(points: any, rect: any, rotation: any): any;
|
||||
/** @inheritdoc */
|
||||
static deserialize(data: any, parent: any, uiManager: any): Promise<AnnotationEditor | null>;
|
||||
constructor(params: any);
|
||||
color: any;
|
||||
thickness: any;
|
||||
opacity: any;
|
||||
paths: any[];
|
||||
bezierPath2D: any[];
|
||||
allRawPaths: any[];
|
||||
currentPath: any[];
|
||||
scaleFactor: number;
|
||||
translationX: number;
|
||||
translationY: number;
|
||||
/** @inheritdoc */
|
||||
updateParams(type: any, value: any): void;
|
||||
/** @inheritdoc */
|
||||
get propertiesToUpdate(): any[][];
|
||||
canvas: HTMLCanvasElement | null | undefined;
|
||||
onScaleChanging(): void;
|
||||
pointerdownAC: any;
|
||||
/**
|
||||
* onpointerdown callback for the canvas we're drawing on.
|
||||
* @param {PointerEvent} event
|
||||
*/
|
||||
canvasPointerdown(event: PointerEvent): void;
|
||||
/**
|
||||
* onpointermove callback for the canvas we're drawing on.
|
||||
* @param {PointerEvent} event
|
||||
*/
|
||||
canvasPointermove(event: PointerEvent): void;
|
||||
/**
|
||||
* onpointerup callback for the canvas we're drawing on.
|
||||
* @param {PointerEvent} event
|
||||
*/
|
||||
canvasPointerup(event: PointerEvent): void;
|
||||
/**
|
||||
* onpointerleave callback for the canvas we're drawing on.
|
||||
* @param {PointerEvent} event
|
||||
*/
|
||||
canvasPointerleave(event: PointerEvent): void;
|
||||
ctx: CanvasRenderingContext2D | null | undefined;
|
||||
/**
|
||||
* When the dimensions of the div change the inner canvas must
|
||||
* renew its dimensions, hence it must redraw its own contents.
|
||||
* @param {number} width - the new width of the div
|
||||
* @param {number} height - the new height of the div
|
||||
* @returns
|
||||
*/
|
||||
setDimensions(width: number, height: number): void;
|
||||
/** @inheritdoc */
|
||||
serialize(): {
|
||||
annotationType: number;
|
||||
color: number[];
|
||||
thickness: any;
|
||||
opacity: any;
|
||||
paths: {
|
||||
bezier: any;
|
||||
points: any;
|
||||
}[];
|
||||
pageIndex: number;
|
||||
rect: any[];
|
||||
rotation: number;
|
||||
structTreeParentId: any;
|
||||
} | null;
|
||||
#private;
|
||||
}
|
||||
import { AnnotationEditor } from "./editor.js";
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"names":["_index","require","appendToMemberExpression","member","append","computed","object","memberExpression","property"],"sources":["../../src/modifications/appendToMemberExpression.ts"],"sourcesContent":["import { memberExpression } from \"../builders/generated/index.ts\";\nimport type * as t from \"../index.ts\";\n\n/**\n * Append a node to a member expression.\n */\nexport default function appendToMemberExpression(\n member: t.MemberExpression,\n append: t.MemberExpression[\"property\"],\n computed: boolean = false,\n): t.MemberExpression {\n member.object = memberExpression(\n member.object,\n member.property,\n member.computed,\n );\n member.property = append;\n member.computed = !!computed;\n\n return member;\n}\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAMe,SAASC,wBAAwBA,CAC9CC,MAA0B,EAC1BC,MAAsC,EACtCC,QAAiB,GAAG,KAAK,EACL;EACpBF,MAAM,CAACG,MAAM,GAAG,IAAAC,uBAAgB,EAC9BJ,MAAM,CAACG,MAAM,EACbH,MAAM,CAACK,QAAQ,EACfL,MAAM,CAACE,QACT,CAAC;EACDF,MAAM,CAACK,QAAQ,GAAGJ,MAAM;EACxBD,MAAM,CAACE,QAAQ,GAAG,CAAC,CAACA,QAAQ;EAE5B,OAAOF,MAAM;AACf","ignoreList":[]}
|
||||
@@ -0,0 +1,36 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.makeStaticFileCache = makeStaticFileCache;
|
||||
var _caching = require("../caching.js");
|
||||
var fs = require("../../gensync-utils/fs.js");
|
||||
function _fs2() {
|
||||
const data = require("fs");
|
||||
_fs2 = function () {
|
||||
return data;
|
||||
};
|
||||
return data;
|
||||
}
|
||||
function makeStaticFileCache(fn) {
|
||||
return (0, _caching.makeStrongCache)(function* (filepath, cache) {
|
||||
const cached = cache.invalidate(() => fileMtime(filepath));
|
||||
if (cached === null) {
|
||||
return null;
|
||||
}
|
||||
return fn(filepath, yield* fs.readFile(filepath, "utf8"));
|
||||
});
|
||||
}
|
||||
function fileMtime(filepath) {
|
||||
if (!_fs2().existsSync(filepath)) return null;
|
||||
try {
|
||||
return +_fs2().statSync(filepath).mtime;
|
||||
} catch (e) {
|
||||
if (e.code !== "ENOENT" && e.code !== "ENOTDIR") throw e;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
0 && 0;
|
||||
|
||||
//# sourceMappingURL=utils.js.map
|
||||
@@ -0,0 +1,93 @@
|
||||
import type { StateCreator, StoreMutatorIdentifier } from 'zustand/vanilla';
|
||||
export interface StateStorage {
|
||||
getItem: (name: string) => string | null | Promise<string | null>;
|
||||
setItem: (name: string, value: string) => unknown | Promise<unknown>;
|
||||
removeItem: (name: string) => unknown | Promise<unknown>;
|
||||
}
|
||||
export type StorageValue<S> = {
|
||||
state: S;
|
||||
version?: number;
|
||||
};
|
||||
export interface PersistStorage<S> {
|
||||
getItem: (name: string) => StorageValue<S> | null | Promise<StorageValue<S> | null>;
|
||||
setItem: (name: string, value: StorageValue<S>) => unknown | Promise<unknown>;
|
||||
removeItem: (name: string) => unknown | Promise<unknown>;
|
||||
}
|
||||
type JsonStorageOptions = {
|
||||
reviver?: (key: string, value: unknown) => unknown;
|
||||
replacer?: (key: string, value: unknown) => unknown;
|
||||
};
|
||||
export declare function createJSONStorage<S>(getStorage: () => StateStorage, options?: JsonStorageOptions): PersistStorage<S> | undefined;
|
||||
export interface PersistOptions<S, PersistedState = S> {
|
||||
/** Name of the storage (must be unique) */
|
||||
name: string;
|
||||
/**
|
||||
* Use a custom persist storage.
|
||||
*
|
||||
* Combining `createJSONStorage` helps creating a persist storage
|
||||
* with JSON.parse and JSON.stringify.
|
||||
*
|
||||
* @default createJSONStorage(() => localStorage)
|
||||
*/
|
||||
storage?: PersistStorage<PersistedState> | undefined;
|
||||
/**
|
||||
* Filter the persisted value.
|
||||
*
|
||||
* @params state The state's value
|
||||
*/
|
||||
partialize?: (state: S) => PersistedState;
|
||||
/**
|
||||
* A function returning another (optional) function.
|
||||
* The main function will be called before the state rehydration.
|
||||
* The returned function will be called after the state rehydration or when an error occurred.
|
||||
*/
|
||||
onRehydrateStorage?: (state: S) => ((state?: S, error?: unknown) => void) | void;
|
||||
/**
|
||||
* If the stored state's version mismatch the one specified here, the storage will not be used.
|
||||
* This is useful when adding a breaking change to your store.
|
||||
*/
|
||||
version?: number;
|
||||
/**
|
||||
* A function to perform persisted state migration.
|
||||
* This function will be called when persisted state versions mismatch with the one specified here.
|
||||
*/
|
||||
migrate?: (persistedState: unknown, version: number) => PersistedState | Promise<PersistedState>;
|
||||
/**
|
||||
* A function to perform custom hydration merges when combining the stored state with the current one.
|
||||
* By default, this function does a shallow merge.
|
||||
*/
|
||||
merge?: (persistedState: unknown, currentState: S) => S;
|
||||
/**
|
||||
* An optional boolean that will prevent the persist middleware from triggering hydration on initialization,
|
||||
* This allows you to call `rehydrate()` at a specific point in your apps rendering life-cycle.
|
||||
*
|
||||
* This is useful in SSR application.
|
||||
*
|
||||
* @default false
|
||||
*/
|
||||
skipHydration?: boolean;
|
||||
}
|
||||
type PersistListener<S> = (state: S) => void;
|
||||
type StorePersist<S, Ps> = {
|
||||
persist: {
|
||||
setOptions: (options: Partial<PersistOptions<S, Ps>>) => void;
|
||||
clearStorage: () => void;
|
||||
rehydrate: () => Promise<void> | void;
|
||||
hasHydrated: () => boolean;
|
||||
onHydrate: (fn: PersistListener<S>) => () => void;
|
||||
onFinishHydration: (fn: PersistListener<S>) => () => void;
|
||||
getOptions: () => Partial<PersistOptions<S, Ps>>;
|
||||
};
|
||||
};
|
||||
type Persist = <T, Mps extends [StoreMutatorIdentifier, unknown][] = [], Mcs extends [StoreMutatorIdentifier, unknown][] = [], U = T>(initializer: StateCreator<T, [...Mps, ['zustand/persist', unknown]], Mcs>, options: PersistOptions<T, U>) => StateCreator<T, Mps, [['zustand/persist', U], ...Mcs]>;
|
||||
declare module '../vanilla.mjs' {
|
||||
interface StoreMutators<S, A> {
|
||||
'zustand/persist': WithPersist<S, A>;
|
||||
}
|
||||
}
|
||||
type Write<T, U> = Omit<T, keyof U> & U;
|
||||
type WithPersist<S, A> = S extends {
|
||||
getState: () => infer T;
|
||||
} ? Write<S, StorePersist<T, A>> : never;
|
||||
export declare const persist: Persist;
|
||||
export {};
|
||||
@@ -0,0 +1,110 @@
|
||||
/**
|
||||
* @fileoverview Define utility functions for token store.
|
||||
* @author Toru Nagashima
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exports
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Finds the index of the first token which is after the given location.
|
||||
* If it was not found, this returns `tokens.length`.
|
||||
* @param {(Token|Comment)[]} tokens It searches the token in this list.
|
||||
* @param {number} location The location to search.
|
||||
* @returns {number} The found index or `tokens.length`.
|
||||
*/
|
||||
exports.search = function search(tokens, location) {
|
||||
for (
|
||||
let minIndex = 0, maxIndex = tokens.length - 1;
|
||||
minIndex <= maxIndex;
|
||||
|
||||
) {
|
||||
/*
|
||||
* Calculate the index in the middle between minIndex and maxIndex.
|
||||
* `| 0` is used to round a fractional value down to the nearest integer: this is similar to
|
||||
* using `Math.trunc()` or `Math.floor()`, but performance tests have shown this method to
|
||||
* be faster.
|
||||
*/
|
||||
const index = ((minIndex + maxIndex) / 2) | 0;
|
||||
const token = tokens[index];
|
||||
const tokenStartLocation = token.range[0];
|
||||
|
||||
if (location <= tokenStartLocation) {
|
||||
if (index === minIndex) {
|
||||
return index;
|
||||
}
|
||||
maxIndex = index;
|
||||
} else {
|
||||
minIndex = index + 1;
|
||||
}
|
||||
}
|
||||
return tokens.length;
|
||||
};
|
||||
|
||||
/**
|
||||
* Gets the index of the `startLoc` in `tokens`.
|
||||
* `startLoc` can be the value of `node.range[1]`, so this checks about `startLoc - 1` as well.
|
||||
* @param {(Token|Comment)[]} tokens The tokens to find an index.
|
||||
* @param {Object} indexMap The map from locations to indices.
|
||||
* @param {number} startLoc The location to get an index.
|
||||
* @returns {number} The index.
|
||||
*/
|
||||
exports.getFirstIndex = function getFirstIndex(tokens, indexMap, startLoc) {
|
||||
if (startLoc in indexMap) {
|
||||
return indexMap[startLoc];
|
||||
}
|
||||
if (startLoc - 1 in indexMap) {
|
||||
const index = indexMap[startLoc - 1];
|
||||
const token = tokens[index];
|
||||
|
||||
// If the mapped index is out of bounds, the returned cursor index will point after the end of the tokens array.
|
||||
if (!token) {
|
||||
return tokens.length;
|
||||
}
|
||||
|
||||
/*
|
||||
* For the map of "comment's location -> token's index", it points the next token of a comment.
|
||||
* In that case, +1 is unnecessary.
|
||||
*/
|
||||
if (token.range[0] >= startLoc) {
|
||||
return index;
|
||||
}
|
||||
return index + 1;
|
||||
}
|
||||
return 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* Gets the index of the `endLoc` in `tokens`.
|
||||
* The information of end locations are recorded at `endLoc - 1` in `indexMap`, so this checks about `endLoc - 1` as well.
|
||||
* @param {(Token|Comment)[]} tokens The tokens to find an index.
|
||||
* @param {Object} indexMap The map from locations to indices.
|
||||
* @param {number} endLoc The location to get an index.
|
||||
* @returns {number} The index.
|
||||
*/
|
||||
exports.getLastIndex = function getLastIndex(tokens, indexMap, endLoc) {
|
||||
if (endLoc in indexMap) {
|
||||
return indexMap[endLoc] - 1;
|
||||
}
|
||||
if (endLoc - 1 in indexMap) {
|
||||
const index = indexMap[endLoc - 1];
|
||||
const token = tokens[index];
|
||||
|
||||
// If the mapped index is out of bounds, the returned cursor index will point before the end of the tokens array.
|
||||
if (!token) {
|
||||
return tokens.length - 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* For the map of "comment's location -> token's index", it points the next token of a comment.
|
||||
* In that case, -1 is necessary.
|
||||
*/
|
||||
if (token.range[1] > endLoc) {
|
||||
return index - 1;
|
||||
}
|
||||
return index;
|
||||
}
|
||||
return tokens.length - 1;
|
||||
};
|
||||
@@ -0,0 +1,127 @@
|
||||
/**
|
||||
* @fileoverview Rule to enforce a single linebreak style.
|
||||
* @author Erik Mueller
|
||||
* @deprecated in ESLint v8.53.0
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Requirements
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
const astUtils = require("./utils/ast-utils");
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Rule Definition
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/** @type {import('../shared/types').Rule} */
|
||||
module.exports = {
|
||||
meta: {
|
||||
deprecated: {
|
||||
message: "Formatting rules are being moved out of ESLint core.",
|
||||
url: "https://eslint.org/blog/2023/10/deprecating-formatting-rules/",
|
||||
deprecatedSince: "8.53.0",
|
||||
availableUntil: "10.0.0",
|
||||
replacedBy: [
|
||||
{
|
||||
message:
|
||||
"ESLint Stylistic now maintains deprecated stylistic core rules.",
|
||||
url: "https://eslint.style/guide/migration",
|
||||
plugin: {
|
||||
name: "@stylistic/eslint-plugin-js",
|
||||
url: "https://eslint.style/packages/js",
|
||||
},
|
||||
rule: {
|
||||
name: "linebreak-style",
|
||||
url: "https://eslint.style/rules/js/linebreak-style",
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
type: "layout",
|
||||
|
||||
docs: {
|
||||
description: "Enforce consistent linebreak style",
|
||||
recommended: false,
|
||||
url: "https://eslint.org/docs/latest/rules/linebreak-style",
|
||||
},
|
||||
|
||||
fixable: "whitespace",
|
||||
|
||||
schema: [
|
||||
{
|
||||
enum: ["unix", "windows"],
|
||||
},
|
||||
],
|
||||
messages: {
|
||||
expectedLF: "Expected linebreaks to be 'LF' but found 'CRLF'.",
|
||||
expectedCRLF: "Expected linebreaks to be 'CRLF' but found 'LF'.",
|
||||
},
|
||||
},
|
||||
|
||||
create(context) {
|
||||
const sourceCode = context.sourceCode;
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Helpers
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Builds a fix function that replaces text at the specified range in the source text.
|
||||
* @param {int[]} range The range to replace
|
||||
* @param {string} text The text to insert.
|
||||
* @returns {Function} Fixer function
|
||||
* @private
|
||||
*/
|
||||
function createFix(range, text) {
|
||||
return function (fixer) {
|
||||
return fixer.replaceTextRange(range, text);
|
||||
};
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Public
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
return {
|
||||
Program: function checkForLinebreakStyle(node) {
|
||||
const linebreakStyle = context.options[0] || "unix",
|
||||
expectedLF = linebreakStyle === "unix",
|
||||
expectedLFChars = expectedLF ? "\n" : "\r\n",
|
||||
source = sourceCode.getText(),
|
||||
pattern = astUtils.createGlobalLinebreakMatcher();
|
||||
let match;
|
||||
|
||||
let i = 0;
|
||||
|
||||
while ((match = pattern.exec(source)) !== null) {
|
||||
i++;
|
||||
if (match[0] === expectedLFChars) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const index = match.index;
|
||||
const range = [index, index + match[0].length];
|
||||
|
||||
context.report({
|
||||
node,
|
||||
loc: {
|
||||
start: {
|
||||
line: i,
|
||||
column: sourceCode.lines[i - 1].length,
|
||||
},
|
||||
end: {
|
||||
line: i + 1,
|
||||
column: 0,
|
||||
},
|
||||
},
|
||||
messageId: expectedLF ? "expectedLF" : "expectedCRLF",
|
||||
fix: createFix(range, expectedLFChars),
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,19 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = useResolver;
|
||||
const react_1 = require("react");
|
||||
function reducer(state, action) {
|
||||
switch (action.type) {
|
||||
case 'RESOLVE':
|
||||
return { value: action.value, error: undefined };
|
||||
case 'REJECT':
|
||||
return { value: false, error: action.error };
|
||||
case 'RESET':
|
||||
return { value: undefined, error: undefined };
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
}
|
||||
function useResolver() {
|
||||
return (0, react_1.useReducer)((reducer), { value: undefined, error: undefined });
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
{
|
||||
"name": "buffer",
|
||||
"description": "Node.js Buffer API, for the browser",
|
||||
"version": "5.7.1",
|
||||
"author": {
|
||||
"name": "Feross Aboukhadijeh",
|
||||
"email": "feross@feross.org",
|
||||
"url": "https://feross.org"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/feross/buffer/issues"
|
||||
},
|
||||
"contributors": [
|
||||
"Romain Beauxis <toots@rastageeks.org>",
|
||||
"James Halliday <mail@substack.net>"
|
||||
],
|
||||
"dependencies": {
|
||||
"base64-js": "^1.3.1",
|
||||
"ieee754": "^1.1.13"
|
||||
},
|
||||
"devDependencies": {
|
||||
"airtap": "^3.0.0",
|
||||
"benchmark": "^2.1.4",
|
||||
"browserify": "^17.0.0",
|
||||
"concat-stream": "^2.0.0",
|
||||
"hyperquest": "^2.1.3",
|
||||
"is-buffer": "^2.0.4",
|
||||
"is-nan": "^1.3.0",
|
||||
"split": "^1.0.1",
|
||||
"standard": "*",
|
||||
"tape": "^5.0.1",
|
||||
"through2": "^4.0.2",
|
||||
"uglify-js": "^3.11.3"
|
||||
},
|
||||
"homepage": "https://github.com/feross/buffer",
|
||||
"jspm": {
|
||||
"map": {
|
||||
"./index.js": {
|
||||
"node": "@node/buffer"
|
||||
}
|
||||
}
|
||||
},
|
||||
"keywords": [
|
||||
"arraybuffer",
|
||||
"browser",
|
||||
"browserify",
|
||||
"buffer",
|
||||
"compatible",
|
||||
"dataview",
|
||||
"uint8array"
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "index.js",
|
||||
"types": "index.d.ts",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/feross/buffer.git"
|
||||
},
|
||||
"scripts": {
|
||||
"perf": "browserify --debug perf/bracket-notation.js > perf/bundle.js && open perf/index.html",
|
||||
"perf-node": "node perf/bracket-notation.js && node perf/concat.js && node perf/copy-big.js && node perf/copy.js && node perf/new-big.js && node perf/new.js && node perf/readDoubleBE.js && node perf/readFloatBE.js && node perf/readUInt32LE.js && node perf/slice.js && node perf/writeFloatBE.js",
|
||||
"size": "browserify -r ./ | uglifyjs -c -m | gzip | wc -c",
|
||||
"test": "standard && node ./bin/test.js",
|
||||
"test-browser-es5": "airtap -- test/*.js",
|
||||
"test-browser-es5-local": "airtap --local -- test/*.js",
|
||||
"test-browser-es6": "airtap -- test/*.js test/node/*.js",
|
||||
"test-browser-es6-local": "airtap --local -- test/*.js test/node/*.js",
|
||||
"test-node": "tape test/*.js test/node/*.js",
|
||||
"update-authors": "./bin/update-authors.sh"
|
||||
},
|
||||
"standard": {
|
||||
"ignore": [
|
||||
"test/node/**/*.js",
|
||||
"test/common.js",
|
||||
"test/_polyfill.js",
|
||||
"perf/**/*.js"
|
||||
],
|
||||
"globals": [
|
||||
"SharedArrayBuffer"
|
||||
]
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/feross"
|
||||
},
|
||||
{
|
||||
"type": "patreon",
|
||||
"url": "https://www.patreon.com/feross"
|
||||
},
|
||||
{
|
||||
"type": "consulting",
|
||||
"url": "https://feross.org/support"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,603 @@
|
||||
/**
|
||||
* @fileoverview Rule to flag constant comparisons and logical expressions that always/never short circuit
|
||||
* @author Jordan Eldredge <https://jordaneldredge.com>
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
const {
|
||||
isNullLiteral,
|
||||
isConstant,
|
||||
isReferenceToGlobalVariable,
|
||||
isLogicalAssignmentOperator,
|
||||
ECMASCRIPT_GLOBALS,
|
||||
} = require("./utils/ast-utils");
|
||||
|
||||
const NUMERIC_OR_STRING_BINARY_OPERATORS = new Set([
|
||||
"+",
|
||||
"-",
|
||||
"*",
|
||||
"/",
|
||||
"%",
|
||||
"|",
|
||||
"^",
|
||||
"&",
|
||||
"**",
|
||||
"<<",
|
||||
">>",
|
||||
">>>",
|
||||
]);
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Helpers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Checks whether or not a node is `null` or `undefined`. Similar to the one
|
||||
* found in ast-utils.js, but this one correctly handles the edge case that
|
||||
* `undefined` has been redefined.
|
||||
* @param {Scope} scope Scope in which the expression was found.
|
||||
* @param {ASTNode} node A node to check.
|
||||
* @returns {boolean} Whether or not the node is a `null` or `undefined`.
|
||||
* @public
|
||||
*/
|
||||
function isNullOrUndefined(scope, node) {
|
||||
return (
|
||||
isNullLiteral(node) ||
|
||||
(node.type === "Identifier" &&
|
||||
node.name === "undefined" &&
|
||||
isReferenceToGlobalVariable(scope, node)) ||
|
||||
(node.type === "UnaryExpression" && node.operator === "void")
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if an AST node has a statically knowable constant nullishness. Meaning,
|
||||
* it will always resolve to a constant value of either: `null`, `undefined`
|
||||
* or not `null` _or_ `undefined`. An expression that can vary between those
|
||||
* three states at runtime would return `false`.
|
||||
* @param {Scope} scope The scope in which the node was found.
|
||||
* @param {ASTNode} node The AST node being tested.
|
||||
* @param {boolean} nonNullish if `true` then nullish values are not considered constant.
|
||||
* @returns {boolean} Does `node` have constant nullishness?
|
||||
*/
|
||||
function hasConstantNullishness(scope, node, nonNullish) {
|
||||
if (nonNullish && isNullOrUndefined(scope, node)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (node.type) {
|
||||
case "ObjectExpression": // Objects are never nullish
|
||||
case "ArrayExpression": // Arrays are never nullish
|
||||
case "ArrowFunctionExpression": // Functions never nullish
|
||||
case "FunctionExpression": // Functions are never nullish
|
||||
case "ClassExpression": // Classes are never nullish
|
||||
case "NewExpression": // Objects are never nullish
|
||||
case "Literal": // Nullish, or non-nullish, literals never change
|
||||
case "TemplateLiteral": // A string is never nullish
|
||||
case "UpdateExpression": // Numbers are never nullish
|
||||
case "BinaryExpression": // Numbers, strings, or booleans are never nullish
|
||||
return true;
|
||||
case "CallExpression": {
|
||||
if (node.callee.type !== "Identifier") {
|
||||
return false;
|
||||
}
|
||||
const functionName = node.callee.name;
|
||||
|
||||
return (
|
||||
(functionName === "Boolean" ||
|
||||
functionName === "String" ||
|
||||
functionName === "Number") &&
|
||||
isReferenceToGlobalVariable(scope, node.callee)
|
||||
);
|
||||
}
|
||||
case "LogicalExpression": {
|
||||
return (
|
||||
node.operator === "??" &&
|
||||
hasConstantNullishness(scope, node.right, true)
|
||||
);
|
||||
}
|
||||
case "AssignmentExpression":
|
||||
if (node.operator === "=") {
|
||||
return hasConstantNullishness(scope, node.right, nonNullish);
|
||||
}
|
||||
|
||||
/*
|
||||
* Handling short-circuiting assignment operators would require
|
||||
* walking the scope. We won't attempt that (for now...) /
|
||||
*/
|
||||
if (isLogicalAssignmentOperator(node.operator)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* The remaining assignment expressions all result in a numeric or
|
||||
* string (non-nullish) value:
|
||||
* "+=", "-=", "*=", "/=", "%=", "<<=", ">>=", ">>>=", "|=", "^=", "&="
|
||||
*/
|
||||
|
||||
return true;
|
||||
case "UnaryExpression":
|
||||
/*
|
||||
* "void" Always returns `undefined`
|
||||
* "typeof" All types are strings, and thus non-nullish
|
||||
* "!" Boolean is never nullish
|
||||
* "delete" Returns a boolean, which is never nullish
|
||||
* Math operators always return numbers or strings, neither of which
|
||||
* are non-nullish "+", "-", "~"
|
||||
*/
|
||||
|
||||
return true;
|
||||
case "SequenceExpression": {
|
||||
const last = node.expressions.at(-1);
|
||||
|
||||
return hasConstantNullishness(scope, last, nonNullish);
|
||||
}
|
||||
case "Identifier":
|
||||
return (
|
||||
node.name === "undefined" &&
|
||||
isReferenceToGlobalVariable(scope, node)
|
||||
);
|
||||
case "JSXElement": // ESLint has a policy of not assuming any specific JSX behavior.
|
||||
case "JSXFragment":
|
||||
return false;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if an AST node is a boolean value that never changes. Specifically we
|
||||
* test for:
|
||||
* 1. Literal booleans (`true` or `false`)
|
||||
* 2. Unary `!` expressions with a constant value
|
||||
* 3. Constant booleans created via the `Boolean` global function
|
||||
* @param {Scope} scope The scope in which the node was found.
|
||||
* @param {ASTNode} node The node to test
|
||||
* @returns {boolean} Is `node` guaranteed to be a boolean?
|
||||
*/
|
||||
function isStaticBoolean(scope, node) {
|
||||
switch (node.type) {
|
||||
case "Literal":
|
||||
return typeof node.value === "boolean";
|
||||
case "CallExpression":
|
||||
return (
|
||||
node.callee.type === "Identifier" &&
|
||||
node.callee.name === "Boolean" &&
|
||||
isReferenceToGlobalVariable(scope, node.callee) &&
|
||||
(node.arguments.length === 0 ||
|
||||
isConstant(scope, node.arguments[0], true))
|
||||
);
|
||||
case "UnaryExpression":
|
||||
return (
|
||||
node.operator === "!" && isConstant(scope, node.argument, true)
|
||||
);
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if an AST node will always give the same result when compared to a
|
||||
* boolean value. Note that comparison to boolean values is different than
|
||||
* truthiness.
|
||||
* https://262.ecma-international.org/5.1/#sec-11.9.3
|
||||
*
|
||||
* JavaScript `==` operator works by converting the boolean to `1` (true) or
|
||||
* `+0` (false) and then checks the values `==` equality to that number.
|
||||
* @param {Scope} scope The scope in which node was found.
|
||||
* @param {ASTNode} node The node to test.
|
||||
* @returns {boolean} Will `node` always coerce to the same boolean value?
|
||||
*/
|
||||
function hasConstantLooseBooleanComparison(scope, node) {
|
||||
switch (node.type) {
|
||||
case "ObjectExpression":
|
||||
case "ClassExpression":
|
||||
/**
|
||||
* In theory objects like:
|
||||
*
|
||||
* `{toString: () => a}`
|
||||
* `{valueOf: () => a}`
|
||||
*
|
||||
* Or a classes like:
|
||||
*
|
||||
* `class { static toString() { return a } }`
|
||||
* `class { static valueOf() { return a } }`
|
||||
*
|
||||
* Are not constant verifiably when `inBooleanPosition` is
|
||||
* false, but it's an edge case we've opted not to handle.
|
||||
*/
|
||||
return true;
|
||||
case "ArrayExpression": {
|
||||
const nonSpreadElements = node.elements.filter(
|
||||
e =>
|
||||
// Elements can be `null` in sparse arrays: `[,,]`;
|
||||
e !== null && e.type !== "SpreadElement",
|
||||
);
|
||||
|
||||
/*
|
||||
* Possible future direction if needed: We could check if the
|
||||
* single value would result in variable boolean comparison.
|
||||
* For now we will err on the side of caution since `[x]` could
|
||||
* evaluate to `[0]` or `[1]`.
|
||||
*/
|
||||
return node.elements.length === 0 || nonSpreadElements.length > 1;
|
||||
}
|
||||
case "ArrowFunctionExpression":
|
||||
case "FunctionExpression":
|
||||
return true;
|
||||
case "UnaryExpression":
|
||||
if (
|
||||
node.operator === "void" || // Always returns `undefined`
|
||||
node.operator === "typeof" // All `typeof` strings, when coerced to number, are not 0 or 1.
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
if (node.operator === "!") {
|
||||
return isConstant(scope, node.argument, true);
|
||||
}
|
||||
|
||||
/*
|
||||
* We won't try to reason about +, -, ~, or delete
|
||||
* In theory, for the mathematical operators, we could look at the
|
||||
* argument and try to determine if it coerces to a constant numeric
|
||||
* value.
|
||||
*/
|
||||
return false;
|
||||
case "NewExpression": // Objects might have custom `.valueOf` or `.toString`.
|
||||
return false;
|
||||
case "CallExpression": {
|
||||
if (
|
||||
node.callee.type === "Identifier" &&
|
||||
node.callee.name === "Boolean" &&
|
||||
isReferenceToGlobalVariable(scope, node.callee)
|
||||
) {
|
||||
return (
|
||||
node.arguments.length === 0 ||
|
||||
isConstant(scope, node.arguments[0], true)
|
||||
);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
case "Literal": // True or false, literals never change
|
||||
return true;
|
||||
case "Identifier":
|
||||
return (
|
||||
node.name === "undefined" &&
|
||||
isReferenceToGlobalVariable(scope, node)
|
||||
);
|
||||
case "TemplateLiteral":
|
||||
/*
|
||||
* In theory we could try to check if the quasi are sufficient to
|
||||
* prove that the expression will always be true, but it would be
|
||||
* tricky to get right. For example: `000.${foo}000`
|
||||
*/
|
||||
return node.expressions.length === 0;
|
||||
case "AssignmentExpression":
|
||||
if (node.operator === "=") {
|
||||
return hasConstantLooseBooleanComparison(scope, node.right);
|
||||
}
|
||||
|
||||
/*
|
||||
* Handling short-circuiting assignment operators would require
|
||||
* walking the scope. We won't attempt that (for now...)
|
||||
*
|
||||
* The remaining assignment expressions all result in a numeric or
|
||||
* string (non-nullish) values which could be truthy or falsy:
|
||||
* "+=", "-=", "*=", "/=", "%=", "<<=", ">>=", ">>>=", "|=", "^=", "&="
|
||||
*/
|
||||
return false;
|
||||
case "SequenceExpression": {
|
||||
const last = node.expressions.at(-1);
|
||||
|
||||
return hasConstantLooseBooleanComparison(scope, last);
|
||||
}
|
||||
case "JSXElement": // ESLint has a policy of not assuming any specific JSX behavior.
|
||||
case "JSXFragment":
|
||||
return false;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if an AST node will always give the same result when _strictly_ compared
|
||||
* to a boolean value. This can happen if the expression can never be boolean, or
|
||||
* if it is always the same boolean value.
|
||||
* @param {Scope} scope The scope in which the node was found.
|
||||
* @param {ASTNode} node The node to test
|
||||
* @returns {boolean} Will `node` always give the same result when compared to a
|
||||
* static boolean value?
|
||||
*/
|
||||
function hasConstantStrictBooleanComparison(scope, node) {
|
||||
switch (node.type) {
|
||||
case "ObjectExpression": // Objects are not booleans
|
||||
case "ArrayExpression": // Arrays are not booleans
|
||||
case "ArrowFunctionExpression": // Functions are not booleans
|
||||
case "FunctionExpression":
|
||||
case "ClassExpression": // Classes are not booleans
|
||||
case "NewExpression": // Objects are not booleans
|
||||
case "TemplateLiteral": // Strings are not booleans
|
||||
case "Literal": // True, false, or not boolean, literals never change.
|
||||
case "UpdateExpression": // Numbers are not booleans
|
||||
return true;
|
||||
case "BinaryExpression":
|
||||
return NUMERIC_OR_STRING_BINARY_OPERATORS.has(node.operator);
|
||||
case "UnaryExpression": {
|
||||
if (node.operator === "delete") {
|
||||
return false;
|
||||
}
|
||||
if (node.operator === "!") {
|
||||
return isConstant(scope, node.argument, true);
|
||||
}
|
||||
|
||||
/*
|
||||
* The remaining operators return either strings or numbers, neither
|
||||
* of which are boolean.
|
||||
*/
|
||||
return true;
|
||||
}
|
||||
case "SequenceExpression": {
|
||||
const last = node.expressions.at(-1);
|
||||
|
||||
return hasConstantStrictBooleanComparison(scope, last);
|
||||
}
|
||||
case "Identifier":
|
||||
return (
|
||||
node.name === "undefined" &&
|
||||
isReferenceToGlobalVariable(scope, node)
|
||||
);
|
||||
case "AssignmentExpression":
|
||||
if (node.operator === "=") {
|
||||
return hasConstantStrictBooleanComparison(scope, node.right);
|
||||
}
|
||||
|
||||
/*
|
||||
* Handling short-circuiting assignment operators would require
|
||||
* walking the scope. We won't attempt that (for now...)
|
||||
*/
|
||||
if (isLogicalAssignmentOperator(node.operator)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* The remaining assignment expressions all result in either a number
|
||||
* or a string, neither of which can ever be boolean.
|
||||
*/
|
||||
return true;
|
||||
case "CallExpression": {
|
||||
if (node.callee.type !== "Identifier") {
|
||||
return false;
|
||||
}
|
||||
const functionName = node.callee.name;
|
||||
|
||||
if (
|
||||
(functionName === "String" || functionName === "Number") &&
|
||||
isReferenceToGlobalVariable(scope, node.callee)
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
if (
|
||||
functionName === "Boolean" &&
|
||||
isReferenceToGlobalVariable(scope, node.callee)
|
||||
) {
|
||||
return (
|
||||
node.arguments.length === 0 ||
|
||||
isConstant(scope, node.arguments[0], true)
|
||||
);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
case "JSXElement": // ESLint has a policy of not assuming any specific JSX behavior.
|
||||
case "JSXFragment":
|
||||
return false;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if an AST node will always result in a newly constructed object
|
||||
* @param {Scope} scope The scope in which the node was found.
|
||||
* @param {ASTNode} node The node to test
|
||||
* @returns {boolean} Will `node` always be new?
|
||||
*/
|
||||
function isAlwaysNew(scope, node) {
|
||||
switch (node.type) {
|
||||
case "ObjectExpression":
|
||||
case "ArrayExpression":
|
||||
case "ArrowFunctionExpression":
|
||||
case "FunctionExpression":
|
||||
case "ClassExpression":
|
||||
return true;
|
||||
case "NewExpression": {
|
||||
if (node.callee.type !== "Identifier") {
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* All the built-in constructors are always new, but
|
||||
* user-defined constructors could return a sentinel
|
||||
* object.
|
||||
*
|
||||
* Catching these is especially useful for primitive constructors
|
||||
* which return boxed values, a surprising gotcha' in JavaScript.
|
||||
*/
|
||||
return (
|
||||
Object.hasOwn(ECMASCRIPT_GLOBALS, node.callee.name) &&
|
||||
isReferenceToGlobalVariable(scope, node.callee)
|
||||
);
|
||||
}
|
||||
case "Literal":
|
||||
// Regular expressions are objects, and thus always new
|
||||
return typeof node.regex === "object";
|
||||
case "SequenceExpression": {
|
||||
const last = node.expressions.at(-1);
|
||||
|
||||
return isAlwaysNew(scope, last);
|
||||
}
|
||||
case "AssignmentExpression":
|
||||
if (node.operator === "=") {
|
||||
return isAlwaysNew(scope, node.right);
|
||||
}
|
||||
return false;
|
||||
case "ConditionalExpression":
|
||||
return (
|
||||
isAlwaysNew(scope, node.consequent) &&
|
||||
isAlwaysNew(scope, node.alternate)
|
||||
);
|
||||
case "JSXElement": // ESLint has a policy of not assuming any specific JSX behavior.
|
||||
case "JSXFragment":
|
||||
return false;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if one operand will cause the result to be constant.
|
||||
* @param {Scope} scope Scope in which the expression was found.
|
||||
* @param {ASTNode} a One side of the expression
|
||||
* @param {ASTNode} b The other side of the expression
|
||||
* @param {string} operator The binary expression operator
|
||||
* @returns {ASTNode | null} The node which will cause the expression to have a constant result.
|
||||
*/
|
||||
function findBinaryExpressionConstantOperand(scope, a, b, operator) {
|
||||
if (operator === "==" || operator === "!=") {
|
||||
if (
|
||||
(isNullOrUndefined(scope, a) &&
|
||||
hasConstantNullishness(scope, b, false)) ||
|
||||
(isStaticBoolean(scope, a) &&
|
||||
hasConstantLooseBooleanComparison(scope, b))
|
||||
) {
|
||||
return b;
|
||||
}
|
||||
} else if (operator === "===" || operator === "!==") {
|
||||
if (
|
||||
(isNullOrUndefined(scope, a) &&
|
||||
hasConstantNullishness(scope, b, false)) ||
|
||||
(isStaticBoolean(scope, a) &&
|
||||
hasConstantStrictBooleanComparison(scope, b))
|
||||
) {
|
||||
return b;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Rule Definition
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/** @type {import('../shared/types').Rule} */
|
||||
module.exports = {
|
||||
meta: {
|
||||
type: "problem",
|
||||
docs: {
|
||||
description:
|
||||
"Disallow expressions where the operation doesn't affect the value",
|
||||
recommended: true,
|
||||
url: "https://eslint.org/docs/latest/rules/no-constant-binary-expression",
|
||||
},
|
||||
schema: [],
|
||||
messages: {
|
||||
constantBinaryOperand:
|
||||
"Unexpected constant binary expression. Compares constantly with the {{otherSide}}-hand side of the `{{operator}}`.",
|
||||
constantShortCircuit:
|
||||
"Unexpected constant {{property}} on the left-hand side of a `{{operator}}` expression.",
|
||||
alwaysNew:
|
||||
"Unexpected comparison to newly constructed object. These two values can never be equal.",
|
||||
bothAlwaysNew:
|
||||
"Unexpected comparison of two newly constructed objects. These two values can never be equal.",
|
||||
},
|
||||
},
|
||||
|
||||
create(context) {
|
||||
const sourceCode = context.sourceCode;
|
||||
|
||||
return {
|
||||
LogicalExpression(node) {
|
||||
const { operator, left } = node;
|
||||
const scope = sourceCode.getScope(node);
|
||||
|
||||
if (
|
||||
(operator === "&&" || operator === "||") &&
|
||||
isConstant(scope, left, true)
|
||||
) {
|
||||
context.report({
|
||||
node: left,
|
||||
messageId: "constantShortCircuit",
|
||||
data: { property: "truthiness", operator },
|
||||
});
|
||||
} else if (
|
||||
operator === "??" &&
|
||||
hasConstantNullishness(scope, left, false)
|
||||
) {
|
||||
context.report({
|
||||
node: left,
|
||||
messageId: "constantShortCircuit",
|
||||
data: { property: "nullishness", operator },
|
||||
});
|
||||
}
|
||||
},
|
||||
BinaryExpression(node) {
|
||||
const scope = sourceCode.getScope(node);
|
||||
const { right, left, operator } = node;
|
||||
const rightConstantOperand =
|
||||
findBinaryExpressionConstantOperand(
|
||||
scope,
|
||||
left,
|
||||
right,
|
||||
operator,
|
||||
);
|
||||
const leftConstantOperand = findBinaryExpressionConstantOperand(
|
||||
scope,
|
||||
right,
|
||||
left,
|
||||
operator,
|
||||
);
|
||||
|
||||
if (rightConstantOperand) {
|
||||
context.report({
|
||||
node: rightConstantOperand,
|
||||
messageId: "constantBinaryOperand",
|
||||
data: { operator, otherSide: "left" },
|
||||
});
|
||||
} else if (leftConstantOperand) {
|
||||
context.report({
|
||||
node: leftConstantOperand,
|
||||
messageId: "constantBinaryOperand",
|
||||
data: { operator, otherSide: "right" },
|
||||
});
|
||||
} else if (operator === "===" || operator === "!==") {
|
||||
if (isAlwaysNew(scope, left)) {
|
||||
context.report({ node: left, messageId: "alwaysNew" });
|
||||
} else if (isAlwaysNew(scope, right)) {
|
||||
context.report({ node: right, messageId: "alwaysNew" });
|
||||
}
|
||||
} else if (operator === "==" || operator === "!=") {
|
||||
/*
|
||||
* If both sides are "new", then both sides are objects and
|
||||
* therefore they will be compared by reference even with `==`
|
||||
* equality.
|
||||
*/
|
||||
if (isAlwaysNew(scope, left) && isAlwaysNew(scope, right)) {
|
||||
context.report({
|
||||
node: left,
|
||||
messageId: "bothAlwaysNew",
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
/*
|
||||
* In theory we could handle short-circuiting assignment operators,
|
||||
* for some constant values, but that would require walking the
|
||||
* scope to find the value of the variable being assigned. This is
|
||||
* dependant on https://github.com/eslint/eslint/issues/13776
|
||||
*
|
||||
* AssignmentExpression() {},
|
||||
*/
|
||||
};
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,31 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = _applyDecoratedDescriptor;
|
||||
function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) {
|
||||
var desc = {};
|
||||
Object.keys(descriptor).forEach(function (key) {
|
||||
desc[key] = descriptor[key];
|
||||
});
|
||||
desc.enumerable = !!desc.enumerable;
|
||||
desc.configurable = !!desc.configurable;
|
||||
if ("value" in desc || desc.initializer) {
|
||||
desc.writable = true;
|
||||
}
|
||||
desc = decorators.slice().reverse().reduce(function (desc, decorator) {
|
||||
return decorator(target, property, desc) || desc;
|
||||
}, desc);
|
||||
if (context && desc.initializer !== void 0) {
|
||||
desc.value = desc.initializer ? desc.initializer.call(context) : void 0;
|
||||
desc.initializer = void 0;
|
||||
}
|
||||
if (desc.initializer === void 0) {
|
||||
Object.defineProperty(target, property, desc);
|
||||
return null;
|
||||
}
|
||||
return desc;
|
||||
}
|
||||
|
||||
//# sourceMappingURL=applyDecoratedDescriptor.js.map
|
||||
@@ -0,0 +1,542 @@
|
||||
/*
|
||||
@license
|
||||
Rollup.js v4.39.0
|
||||
Wed, 02 Apr 2025 04:49:00 GMT - commit 5c001245779063abac3899aa9d25294ab003581b
|
||||
|
||||
https://github.com/rollup/rollup
|
||||
|
||||
Released under the MIT License.
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
||||
|
||||
const index = require('./index.js');
|
||||
const promises = require('node:fs/promises');
|
||||
const process$2 = require('node:process');
|
||||
const cli = require('../bin/rollup');
|
||||
const rollup = require('./rollup.js');
|
||||
const parseAst_js = require('./parseAst.js');
|
||||
const loadConfigFile_js = require('./loadConfigFile.js');
|
||||
const node_child_process = require('node:child_process');
|
||||
const rollup_js = require('../rollup.js');
|
||||
require('path');
|
||||
require('util');
|
||||
require('fs');
|
||||
require('stream');
|
||||
require('os');
|
||||
require('./fsevents-importer.js');
|
||||
require('events');
|
||||
require('node:path');
|
||||
require('../native.js');
|
||||
require('node:perf_hooks');
|
||||
require('node:url');
|
||||
require('../getLogFilter.js');
|
||||
|
||||
function timeZone(date = new Date()) {
|
||||
const offset = date.getTimezoneOffset();
|
||||
const absOffset = Math.abs(offset);
|
||||
const hours = Math.floor(absOffset / 60);
|
||||
const minutes = absOffset % 60;
|
||||
const minutesOut = minutes > 0 ? ':' + ('0' + minutes).slice(-2) : '';
|
||||
return (offset < 0 ? '+' : '-') + hours + minutesOut;
|
||||
}
|
||||
|
||||
function dateTime(options = {}) {
|
||||
let {
|
||||
date = new Date(),
|
||||
local = true,
|
||||
showTimeZone = false,
|
||||
showMilliseconds = false
|
||||
} = options;
|
||||
|
||||
if (local) {
|
||||
// Offset the date so it will return the correct value when getting the ISO string.
|
||||
date = new Date(date.getTime() - (date.getTimezoneOffset() * 60000));
|
||||
}
|
||||
|
||||
let end = '';
|
||||
|
||||
if (showTimeZone) {
|
||||
end = ' UTC' + (local ? timeZone(date) : '');
|
||||
}
|
||||
|
||||
if (showMilliseconds && date.getUTCMilliseconds() > 0) {
|
||||
end = ` ${date.getUTCMilliseconds()}ms${end}`;
|
||||
}
|
||||
|
||||
return date
|
||||
.toISOString()
|
||||
.replace(/T/, ' ')
|
||||
.replace(/\..+/, end);
|
||||
}
|
||||
|
||||
/**
|
||||
* This is not the set of all possible signals.
|
||||
*
|
||||
* It IS, however, the set of all signals that trigger
|
||||
* an exit on either Linux or BSD systems. Linux is a
|
||||
* superset of the signal names supported on BSD, and
|
||||
* the unknown signals just fail to register, so we can
|
||||
* catch that easily enough.
|
||||
*
|
||||
* Windows signals are a different set, since there are
|
||||
* signals that terminate Windows processes, but don't
|
||||
* terminate (or don't even exist) on Posix systems.
|
||||
*
|
||||
* Don't bother with SIGKILL. It's uncatchable, which
|
||||
* means that we can't fire any callbacks anyway.
|
||||
*
|
||||
* If a user does happen to register a handler on a non-
|
||||
* fatal signal like SIGWINCH or something, and then
|
||||
* exit, it'll end up firing `process.emit('exit')`, so
|
||||
* the handler will be fired anyway.
|
||||
*
|
||||
* SIGBUS, SIGFPE, SIGSEGV and SIGILL, when not raised
|
||||
* artificially, inherently leave the process in a
|
||||
* state from which it is not safe to try and enter JS
|
||||
* listeners.
|
||||
*/
|
||||
const signals = [];
|
||||
signals.push('SIGHUP', 'SIGINT', 'SIGTERM');
|
||||
if (process.platform !== 'win32') {
|
||||
signals.push('SIGALRM', 'SIGABRT', 'SIGVTALRM', 'SIGXCPU', 'SIGXFSZ', 'SIGUSR2', 'SIGTRAP', 'SIGSYS', 'SIGQUIT', 'SIGIOT'
|
||||
// should detect profiler and enable/disable accordingly.
|
||||
// see #21
|
||||
// 'SIGPROF'
|
||||
);
|
||||
}
|
||||
if (process.platform === 'linux') {
|
||||
signals.push('SIGIO', 'SIGPOLL', 'SIGPWR', 'SIGSTKFLT');
|
||||
}
|
||||
|
||||
// Note: since nyc uses this module to output coverage, any lines
|
||||
// that are in the direct sync flow of nyc's outputCoverage are
|
||||
// ignored, since we can never get coverage for them.
|
||||
// grab a reference to node's real process object right away
|
||||
const processOk = (process) => !!process &&
|
||||
typeof process === 'object' &&
|
||||
typeof process.removeListener === 'function' &&
|
||||
typeof process.emit === 'function' &&
|
||||
typeof process.reallyExit === 'function' &&
|
||||
typeof process.listeners === 'function' &&
|
||||
typeof process.kill === 'function' &&
|
||||
typeof process.pid === 'number' &&
|
||||
typeof process.on === 'function';
|
||||
const kExitEmitter = Symbol.for('signal-exit emitter');
|
||||
const global = globalThis;
|
||||
const ObjectDefineProperty = Object.defineProperty.bind(Object);
|
||||
// teeny special purpose ee
|
||||
class Emitter {
|
||||
emitted = {
|
||||
afterExit: false,
|
||||
exit: false,
|
||||
};
|
||||
listeners = {
|
||||
afterExit: [],
|
||||
exit: [],
|
||||
};
|
||||
count = 0;
|
||||
id = Math.random();
|
||||
constructor() {
|
||||
if (global[kExitEmitter]) {
|
||||
return global[kExitEmitter];
|
||||
}
|
||||
ObjectDefineProperty(global, kExitEmitter, {
|
||||
value: this,
|
||||
writable: false,
|
||||
enumerable: false,
|
||||
configurable: false,
|
||||
});
|
||||
}
|
||||
on(ev, fn) {
|
||||
this.listeners[ev].push(fn);
|
||||
}
|
||||
removeListener(ev, fn) {
|
||||
const list = this.listeners[ev];
|
||||
const i = list.indexOf(fn);
|
||||
/* c8 ignore start */
|
||||
if (i === -1) {
|
||||
return;
|
||||
}
|
||||
/* c8 ignore stop */
|
||||
if (i === 0 && list.length === 1) {
|
||||
list.length = 0;
|
||||
}
|
||||
else {
|
||||
list.splice(i, 1);
|
||||
}
|
||||
}
|
||||
emit(ev, code, signal) {
|
||||
if (this.emitted[ev]) {
|
||||
return false;
|
||||
}
|
||||
this.emitted[ev] = true;
|
||||
let ret = false;
|
||||
for (const fn of this.listeners[ev]) {
|
||||
ret = fn(code, signal) === true || ret;
|
||||
}
|
||||
if (ev === 'exit') {
|
||||
ret = this.emit('afterExit', code, signal) || ret;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
class SignalExitBase {
|
||||
}
|
||||
const signalExitWrap = (handler) => {
|
||||
return {
|
||||
onExit(cb, opts) {
|
||||
return handler.onExit(cb, opts);
|
||||
},
|
||||
load() {
|
||||
return handler.load();
|
||||
},
|
||||
unload() {
|
||||
return handler.unload();
|
||||
},
|
||||
};
|
||||
};
|
||||
class SignalExitFallback extends SignalExitBase {
|
||||
onExit() {
|
||||
return () => { };
|
||||
}
|
||||
load() { }
|
||||
unload() { }
|
||||
}
|
||||
class SignalExit extends SignalExitBase {
|
||||
// "SIGHUP" throws an `ENOSYS` error on Windows,
|
||||
// so use a supported signal instead
|
||||
/* c8 ignore start */
|
||||
#hupSig = process$1.platform === 'win32' ? 'SIGINT' : 'SIGHUP';
|
||||
/* c8 ignore stop */
|
||||
#emitter = new Emitter();
|
||||
#process;
|
||||
#originalProcessEmit;
|
||||
#originalProcessReallyExit;
|
||||
#sigListeners = {};
|
||||
#loaded = false;
|
||||
constructor(process) {
|
||||
super();
|
||||
this.#process = process;
|
||||
// { <signal>: <listener fn>, ... }
|
||||
this.#sigListeners = {};
|
||||
for (const sig of signals) {
|
||||
this.#sigListeners[sig] = () => {
|
||||
// If there are no other listeners, an exit is coming!
|
||||
// Simplest way: remove us and then re-send the signal.
|
||||
// We know that this will kill the process, so we can
|
||||
// safely emit now.
|
||||
const listeners = this.#process.listeners(sig);
|
||||
let { count } = this.#emitter;
|
||||
// This is a workaround for the fact that signal-exit v3 and signal
|
||||
// exit v4 are not aware of each other, and each will attempt to let
|
||||
// the other handle it, so neither of them do. To correct this, we
|
||||
// detect if we're the only handler *except* for previous versions
|
||||
// of signal-exit, and increment by the count of listeners it has
|
||||
// created.
|
||||
/* c8 ignore start */
|
||||
const p = process;
|
||||
if (typeof p.__signal_exit_emitter__ === 'object' &&
|
||||
typeof p.__signal_exit_emitter__.count === 'number') {
|
||||
count += p.__signal_exit_emitter__.count;
|
||||
}
|
||||
/* c8 ignore stop */
|
||||
if (listeners.length === count) {
|
||||
this.unload();
|
||||
const ret = this.#emitter.emit('exit', null, sig);
|
||||
/* c8 ignore start */
|
||||
const s = sig === 'SIGHUP' ? this.#hupSig : sig;
|
||||
if (!ret)
|
||||
process.kill(process.pid, s);
|
||||
/* c8 ignore stop */
|
||||
}
|
||||
};
|
||||
}
|
||||
this.#originalProcessReallyExit = process.reallyExit;
|
||||
this.#originalProcessEmit = process.emit;
|
||||
}
|
||||
onExit(cb, opts) {
|
||||
/* c8 ignore start */
|
||||
if (!processOk(this.#process)) {
|
||||
return () => { };
|
||||
}
|
||||
/* c8 ignore stop */
|
||||
if (this.#loaded === false) {
|
||||
this.load();
|
||||
}
|
||||
const ev = opts?.alwaysLast ? 'afterExit' : 'exit';
|
||||
this.#emitter.on(ev, cb);
|
||||
return () => {
|
||||
this.#emitter.removeListener(ev, cb);
|
||||
if (this.#emitter.listeners['exit'].length === 0 &&
|
||||
this.#emitter.listeners['afterExit'].length === 0) {
|
||||
this.unload();
|
||||
}
|
||||
};
|
||||
}
|
||||
load() {
|
||||
if (this.#loaded) {
|
||||
return;
|
||||
}
|
||||
this.#loaded = true;
|
||||
// This is the number of onSignalExit's that are in play.
|
||||
// It's important so that we can count the correct number of
|
||||
// listeners on signals, and don't wait for the other one to
|
||||
// handle it instead of us.
|
||||
this.#emitter.count += 1;
|
||||
for (const sig of signals) {
|
||||
try {
|
||||
const fn = this.#sigListeners[sig];
|
||||
if (fn)
|
||||
this.#process.on(sig, fn);
|
||||
}
|
||||
catch (_) { }
|
||||
}
|
||||
this.#process.emit = (ev, ...a) => {
|
||||
return this.#processEmit(ev, ...a);
|
||||
};
|
||||
this.#process.reallyExit = (code) => {
|
||||
return this.#processReallyExit(code);
|
||||
};
|
||||
}
|
||||
unload() {
|
||||
if (!this.#loaded) {
|
||||
return;
|
||||
}
|
||||
this.#loaded = false;
|
||||
signals.forEach(sig => {
|
||||
const listener = this.#sigListeners[sig];
|
||||
/* c8 ignore start */
|
||||
if (!listener) {
|
||||
throw new Error('Listener not defined for signal: ' + sig);
|
||||
}
|
||||
/* c8 ignore stop */
|
||||
try {
|
||||
this.#process.removeListener(sig, listener);
|
||||
/* c8 ignore start */
|
||||
}
|
||||
catch (_) { }
|
||||
/* c8 ignore stop */
|
||||
});
|
||||
this.#process.emit = this.#originalProcessEmit;
|
||||
this.#process.reallyExit = this.#originalProcessReallyExit;
|
||||
this.#emitter.count -= 1;
|
||||
}
|
||||
#processReallyExit(code) {
|
||||
/* c8 ignore start */
|
||||
if (!processOk(this.#process)) {
|
||||
return 0;
|
||||
}
|
||||
this.#process.exitCode = code || 0;
|
||||
/* c8 ignore stop */
|
||||
this.#emitter.emit('exit', this.#process.exitCode, null);
|
||||
return this.#originalProcessReallyExit.call(this.#process, this.#process.exitCode);
|
||||
}
|
||||
#processEmit(ev, ...args) {
|
||||
const og = this.#originalProcessEmit;
|
||||
if (ev === 'exit' && processOk(this.#process)) {
|
||||
if (typeof args[0] === 'number') {
|
||||
this.#process.exitCode = args[0];
|
||||
/* c8 ignore start */
|
||||
}
|
||||
/* c8 ignore start */
|
||||
const ret = og.call(this.#process, ev, ...args);
|
||||
/* c8 ignore start */
|
||||
this.#emitter.emit('exit', this.#process.exitCode, null);
|
||||
/* c8 ignore stop */
|
||||
return ret;
|
||||
}
|
||||
else {
|
||||
return og.call(this.#process, ev, ...args);
|
||||
}
|
||||
}
|
||||
}
|
||||
const process$1 = globalThis.process;
|
||||
// wrap so that we call the method on the actual handler, without
|
||||
// exporting it directly.
|
||||
const {
|
||||
/**
|
||||
* Called when the process is exiting, whether via signal, explicit
|
||||
* exit, or running out of stuff to do.
|
||||
*
|
||||
* If the global process object is not suitable for instrumentation,
|
||||
* then this will be a no-op.
|
||||
*
|
||||
* Returns a function that may be used to unload signal-exit.
|
||||
*/
|
||||
onExit} = signalExitWrap(processOk(process$1) ? new SignalExit(process$1) : new SignalExitFallback());
|
||||
|
||||
const CLEAR_SCREEN = '\u001Bc';
|
||||
function getResetScreen(configs, allowClearScreen) {
|
||||
let clearScreen = allowClearScreen;
|
||||
for (const config of configs) {
|
||||
if (config.watch && config.watch.clearScreen === false) {
|
||||
clearScreen = false;
|
||||
}
|
||||
}
|
||||
if (clearScreen) {
|
||||
return (heading) => rollup.stderr(CLEAR_SCREEN + heading);
|
||||
}
|
||||
let firstRun = true;
|
||||
return (heading) => {
|
||||
if (firstRun) {
|
||||
rollup.stderr(heading);
|
||||
firstRun = false;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function extractWatchHooks(command) {
|
||||
if (!Array.isArray(command.watch))
|
||||
return {};
|
||||
return command.watch
|
||||
.filter(value => typeof value === 'object')
|
||||
.reduce((accumulator, keyValueOption) => ({ ...accumulator, ...keyValueOption }), {});
|
||||
}
|
||||
function createWatchHooks(command) {
|
||||
const watchHooks = extractWatchHooks(command);
|
||||
return function (hook) {
|
||||
if (watchHooks[hook]) {
|
||||
const cmd = watchHooks[hook];
|
||||
if (!command.silent) {
|
||||
rollup.stderr(rollup.cyan(`watch.${hook} ${rollup.bold(`$ ${cmd}`)}`));
|
||||
}
|
||||
try {
|
||||
// !! important - use stderr for all writes from execSync
|
||||
const stdio = [process.stdin, process.stderr, process.stderr];
|
||||
node_child_process.execSync(cmd, { stdio: command.silent ? 'ignore' : stdio });
|
||||
}
|
||||
catch (error) {
|
||||
rollup.stderr(error.message);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
async function watch(command) {
|
||||
process$2.env.ROLLUP_WATCH = 'true';
|
||||
const isTTY = process$2.stderr.isTTY;
|
||||
const silent = command.silent;
|
||||
let watcher;
|
||||
let configWatcher;
|
||||
let resetScreen;
|
||||
const configFile = command.config ? await cli.getConfigPath(command.config) : null;
|
||||
const runWatchHook = createWatchHooks(command);
|
||||
onExit(close);
|
||||
process$2.on('uncaughtException', closeWithError);
|
||||
async function loadConfigFromFileAndTrack(configFile) {
|
||||
let configFileData = null;
|
||||
let configFileRevision = 0;
|
||||
configWatcher = index.chokidar.watch(configFile).on('change', reloadConfigFile);
|
||||
await reloadConfigFile();
|
||||
async function reloadConfigFile() {
|
||||
try {
|
||||
const newConfigFileData = await promises.readFile(configFile, 'utf8');
|
||||
if (newConfigFileData === configFileData) {
|
||||
return;
|
||||
}
|
||||
configFileRevision++;
|
||||
const currentConfigFileRevision = configFileRevision;
|
||||
if (configFileData) {
|
||||
rollup.stderr(`\nReloading updated config...`);
|
||||
}
|
||||
configFileData = newConfigFileData;
|
||||
const { options, warnings } = await loadConfigFile_js.loadConfigFile(configFile, command, true);
|
||||
if (currentConfigFileRevision !== configFileRevision) {
|
||||
return;
|
||||
}
|
||||
if (watcher) {
|
||||
await watcher.close();
|
||||
}
|
||||
start(options, warnings);
|
||||
}
|
||||
catch (error) {
|
||||
rollup.handleError(error, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (configFile) {
|
||||
await loadConfigFromFileAndTrack(configFile);
|
||||
}
|
||||
else {
|
||||
const { options, warnings } = await cli.loadConfigFromCommand(command, true);
|
||||
await start(options, warnings);
|
||||
}
|
||||
async function start(configs, warnings) {
|
||||
watcher = rollup_js.watch(configs);
|
||||
watcher.on('event', event => {
|
||||
switch (event.code) {
|
||||
case 'ERROR': {
|
||||
warnings.flush();
|
||||
rollup.handleError(event.error, true);
|
||||
runWatchHook('onError');
|
||||
break;
|
||||
}
|
||||
case 'START': {
|
||||
if (!silent) {
|
||||
if (!resetScreen) {
|
||||
resetScreen = getResetScreen(configs, isTTY);
|
||||
}
|
||||
resetScreen(rollup.underline(`rollup v${rollup.version}`));
|
||||
}
|
||||
runWatchHook('onStart');
|
||||
break;
|
||||
}
|
||||
case 'BUNDLE_START': {
|
||||
if (!silent) {
|
||||
let input = event.input;
|
||||
if (typeof input !== 'string') {
|
||||
input = Array.isArray(input)
|
||||
? input.join(', ')
|
||||
: Object.values(input).join(', ');
|
||||
}
|
||||
rollup.stderr(rollup.cyan(`bundles ${rollup.bold(input)} → ${rollup.bold(event.output.map(parseAst_js.relativeId).join(', '))}...`));
|
||||
}
|
||||
runWatchHook('onBundleStart');
|
||||
break;
|
||||
}
|
||||
case 'BUNDLE_END': {
|
||||
warnings.flush();
|
||||
if (!silent)
|
||||
rollup.stderr(rollup.green(`created ${rollup.bold(event.output.map(parseAst_js.relativeId).join(', '))} in ${rollup.bold(cli.prettyMilliseconds(event.duration))}`));
|
||||
runWatchHook('onBundleEnd');
|
||||
if (event.result && event.result.getTimings) {
|
||||
cli.printTimings(event.result.getTimings());
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'END': {
|
||||
runWatchHook('onEnd');
|
||||
if (!silent) {
|
||||
rollup.stderr(`\n[${dateTime()}] waiting for changes...`);
|
||||
}
|
||||
}
|
||||
}
|
||||
if ('result' in event && event.result) {
|
||||
event.result.close().catch(error => rollup.handleError(error, true));
|
||||
}
|
||||
});
|
||||
}
|
||||
function close(code) {
|
||||
process$2.removeListener('uncaughtException', closeWithError);
|
||||
// removing a non-existent listener is a no-op
|
||||
process$2.stdin.removeListener('end', close);
|
||||
if (configWatcher)
|
||||
configWatcher.close();
|
||||
Promise.resolve(watcher?.close()).finally(() => {
|
||||
process$2.exit(typeof code === 'number' ? code : 0);
|
||||
});
|
||||
// Tell signal-exit that we are handling this gracefully
|
||||
return true;
|
||||
}
|
||||
// return a promise that never resolves to keep the process running
|
||||
return new Promise(() => { });
|
||||
}
|
||||
function closeWithError(error) {
|
||||
error.name = `Uncaught ${error.name}`;
|
||||
rollup.handleError(error);
|
||||
}
|
||||
|
||||
exports.watch = watch;
|
||||
//# sourceMappingURL=watch-cli.js.map
|
||||
@@ -0,0 +1,63 @@
|
||||
/**
|
||||
* @fileoverview Provide the function that emits deprecation warnings.
|
||||
* @author Toru Nagashima <http://github.com/mysticatea>
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Requirements
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
import path from "node:path";
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Private
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// Defitions for deprecation warnings.
|
||||
const deprecationWarningMessages = {
|
||||
ESLINT_LEGACY_ECMAFEATURES:
|
||||
"The 'ecmaFeatures' config file property is deprecated and has no effect.",
|
||||
ESLINT_PERSONAL_CONFIG_LOAD:
|
||||
"'~/.eslintrc.*' config files have been deprecated. " +
|
||||
"Please use a config file per project or the '--config' option.",
|
||||
ESLINT_PERSONAL_CONFIG_SUPPRESS:
|
||||
"'~/.eslintrc.*' config files have been deprecated. " +
|
||||
"Please remove it or add 'root:true' to the config files in your " +
|
||||
"projects in order to avoid loading '~/.eslintrc.*' accidentally."
|
||||
};
|
||||
|
||||
const sourceFileErrorCache = new Set();
|
||||
|
||||
/**
|
||||
* Emits a deprecation warning containing a given filepath. A new deprecation warning is emitted
|
||||
* for each unique file path, but repeated invocations with the same file path have no effect.
|
||||
* No warnings are emitted if the `--no-deprecation` or `--no-warnings` Node runtime flags are active.
|
||||
* @param {string} source The name of the configuration source to report the warning for.
|
||||
* @param {string} errorCode The warning message to show.
|
||||
* @returns {void}
|
||||
*/
|
||||
function emitDeprecationWarning(source, errorCode) {
|
||||
const cacheKey = JSON.stringify({ source, errorCode });
|
||||
|
||||
if (sourceFileErrorCache.has(cacheKey)) {
|
||||
return;
|
||||
}
|
||||
sourceFileErrorCache.add(cacheKey);
|
||||
|
||||
const rel = path.relative(process.cwd(), source);
|
||||
const message = deprecationWarningMessages[errorCode];
|
||||
|
||||
process.emitWarning(
|
||||
`${message} (found in "${rel}")`,
|
||||
"DeprecationWarning",
|
||||
errorCode
|
||||
);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Public Interface
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
export {
|
||||
emitDeprecationWarning
|
||||
};
|
||||
@@ -0,0 +1 @@
|
||||
module.exports={A:{A:{"2":"mC","8":"K D E F A 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","8":"C L M G N O P"},C:{"1":"0 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":"nC","8":"1 2 3 4 5 LC J PB K D E F A B C L M G N O P QB qC rC"},D:{"1":"0 1 2 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 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","8":"M G N O P QB"},E:{"1":"K D E F A B C L M G 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","8":"J PB tC"},F:{"1":"0 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 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 4C 5C 6C 7C","8":"C FC kC 8C GC"},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","8":"9C lC AD"},H:{"2":"WD"},I:{"1":"I bD cD","8":"LC J XD YD ZD aD lC"},J:{"1":"A","8":"D"},K:{"1":"H","2":"A B","8":"C FC kC GC"},L:{"1":"I"},M:{"1":"EC"},N:{"8":"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:"srcdoc attribute for iframes",D:true};
|
||||
@@ -0,0 +1,33 @@
|
||||
'use strict';
|
||||
|
||||
var test = require('tape');
|
||||
var parse = require('../');
|
||||
|
||||
test('long opts', function (t) {
|
||||
t.deepEqual(
|
||||
parse(['--bool']),
|
||||
{ bool: true, _: [] },
|
||||
'long boolean'
|
||||
);
|
||||
t.deepEqual(
|
||||
parse(['--pow', 'xixxle']),
|
||||
{ pow: 'xixxle', _: [] },
|
||||
'long capture sp'
|
||||
);
|
||||
t.deepEqual(
|
||||
parse(['--pow=xixxle']),
|
||||
{ pow: 'xixxle', _: [] },
|
||||
'long capture eq'
|
||||
);
|
||||
t.deepEqual(
|
||||
parse(['--host', 'localhost', '--port', '555']),
|
||||
{ host: 'localhost', port: 555, _: [] },
|
||||
'long captures sp'
|
||||
);
|
||||
t.deepEqual(
|
||||
parse(['--host=localhost', '--port=555']),
|
||||
{ host: 'localhost', port: 555, _: [] },
|
||||
'long captures eq'
|
||||
);
|
||||
t.end();
|
||||
});
|
||||
@@ -0,0 +1,14 @@
|
||||
/**
|
||||
* @license React
|
||||
* react-jsx-dev-runtime.profiling.js
|
||||
*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
var REACT_FRAGMENT_TYPE = Symbol.for("react.fragment");
|
||||
exports.Fragment = REACT_FRAGMENT_TYPE;
|
||||
exports.jsxDEV = void 0;
|
||||
@@ -0,0 +1 @@
|
||||
module.exports={A:{A:{"2":"K D E F A B mC"},B:{"2":"C L M G N O P","1025":"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"},C:{"2":"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:{"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","194":"iB jB kB lB mB nB oB pB","706":"qB rB sB","1025":"0 9 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:{"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 JC bC cC dC eC fC 2C KC gC hC iC jC 3C"},F:{"2":"1 2 3 4 5 6 7 8 F B C G N O P QB RB SB TB UB VB WB XB YB 4C 5C 6C 7C FC kC 8C GC","450":"ZB aB bB cB","706":"dB eB fB","1025":"0 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"},G:{"2":"E SC 9C lC AD BD CD DD ED FD GD HD ID JD KD LD MD ND OD PD QD RD SD UC VC HC TD IC WC XC YC ZC aC UD JC bC cC dC eC fC VD KC gC hC iC jC"},H:{"2":"WD"},I:{"2":"LC J XD YD ZD aD lC bD cD","1025":"I"},J:{"2":"D A"},K:{"2":"A B C FC kC GC","1025":"H"},L:{"1025":"I"},M:{"2":"EC"},N:{"2":"A B"},O:{"1025":"HC"},P:{"1":"1 2 3 4 5 6 7 8 eD fD gD hD TC iD jD kD lD mD IC JC KC nD","2":"J dD"},Q:{"2":"oD"},R:{"1025":"pD"},S:{"2":"qD rD"}},B:7,C:"Web Bluetooth",D:true};
|
||||
Reference in New Issue
Block a user