update
This commit is contained in:
@@ -0,0 +1,142 @@
|
||||
export { ObjectSchema } from "@eslint/object-schema";
|
||||
export type PropertyDefinition = import("@eslint/object-schema").PropertyDefinition;
|
||||
export type ObjectDefinition = import("@eslint/object-schema").ObjectDefinition;
|
||||
export type ConfigObject = import("./types.ts").ConfigObject;
|
||||
export type IMinimatchStatic = import("minimatch").IMinimatchStatic;
|
||||
export type IMinimatch = import("minimatch").IMinimatch;
|
||||
export type PathImpl = typeof import("@jsr/std__path");
|
||||
export type ObjectSchemaInstance = import("@eslint/object-schema").ObjectSchema;
|
||||
/**
|
||||
* Represents an array of config objects and provides method for working with
|
||||
* those config objects.
|
||||
*/
|
||||
export class ConfigArray extends Array<any> {
|
||||
[x: symbol]: (config: any) => any;
|
||||
/**
|
||||
* Creates a new instance of ConfigArray.
|
||||
* @param {Iterable|Function|Object} configs An iterable yielding config
|
||||
* objects, or a config function, or a config object.
|
||||
* @param {Object} options The options for the ConfigArray.
|
||||
* @param {string} [options.basePath="/"] The absolute path of the config file directory.
|
||||
* Defaults to `"/"`.
|
||||
* @param {boolean} [options.normalized=false] Flag indicating if the
|
||||
* configs have already been normalized.
|
||||
* @param {Object} [options.schema] The additional schema
|
||||
* definitions to use for the ConfigArray schema.
|
||||
* @param {Array<string>} [options.extraConfigTypes] List of config types supported.
|
||||
*/
|
||||
constructor(configs: Iterable<any> | Function | any, { basePath, normalized, schema: customSchema, extraConfigTypes, }?: {
|
||||
basePath?: string;
|
||||
normalized?: boolean;
|
||||
schema?: any;
|
||||
extraConfigTypes?: Array<string>;
|
||||
});
|
||||
/**
|
||||
* The path of the config file that this array was loaded from.
|
||||
* This is used to calculate filename matches.
|
||||
* @property basePath
|
||||
* @type {string}
|
||||
*/
|
||||
basePath: string;
|
||||
/**
|
||||
* The supported config types.
|
||||
* @type {Array<string>}
|
||||
*/
|
||||
extraConfigTypes: Array<string>;
|
||||
/**
|
||||
* Returns the `files` globs from every config object in the array.
|
||||
* This can be used to determine which files will be matched by a
|
||||
* config array or to use as a glob pattern when no patterns are provided
|
||||
* for a command line interface.
|
||||
* @returns {Array<string|Function>} An array of matchers.
|
||||
*/
|
||||
get files(): Array<string | Function>;
|
||||
/**
|
||||
* Returns ignore matchers that should always be ignored regardless of
|
||||
* the matching `files` fields in any configs. This is necessary to mimic
|
||||
* the behavior of things like .gitignore and .eslintignore, allowing a
|
||||
* globbing operation to be faster.
|
||||
* @returns {string[]} An array of string patterns and functions to be ignored.
|
||||
*/
|
||||
get ignores(): string[];
|
||||
/**
|
||||
* Indicates if the config array has been normalized.
|
||||
* @returns {boolean} True if the config array is normalized, false if not.
|
||||
*/
|
||||
isNormalized(): boolean;
|
||||
/**
|
||||
* Normalizes a config array by flattening embedded arrays and executing
|
||||
* config functions.
|
||||
* @param {Object} [context] The context object for config functions.
|
||||
* @returns {Promise<ConfigArray>} The current ConfigArray instance.
|
||||
*/
|
||||
normalize(context?: any): Promise<ConfigArray>;
|
||||
/**
|
||||
* Normalizes a config array by flattening embedded arrays and executing
|
||||
* config functions.
|
||||
* @param {Object} [context] The context object for config functions.
|
||||
* @returns {ConfigArray} The current ConfigArray instance.
|
||||
*/
|
||||
normalizeSync(context?: any): ConfigArray;
|
||||
/**
|
||||
* Returns the config object for a given file path and a status that can be used to determine why a file has no config.
|
||||
* @param {string} filePath The path of a file to get a config for.
|
||||
* @returns {{ config?: Object, status: "ignored"|"external"|"unconfigured"|"matched" }}
|
||||
* An object with an optional property `config` and property `status`.
|
||||
* `config` is the config object for the specified file as returned by {@linkcode ConfigArray.getConfig},
|
||||
* `status` a is one of the constants returned by {@linkcode ConfigArray.getConfigStatus}.
|
||||
*/
|
||||
getConfigWithStatus(filePath: string): {
|
||||
config?: any;
|
||||
status: "ignored" | "external" | "unconfigured" | "matched";
|
||||
};
|
||||
/**
|
||||
* Returns the config object for a given file path.
|
||||
* @param {string} filePath The path of a file to get a config for.
|
||||
* @returns {Object|undefined} The config object for this file or `undefined`.
|
||||
*/
|
||||
getConfig(filePath: string): any | undefined;
|
||||
/**
|
||||
* Determines whether a file has a config or why it doesn't.
|
||||
* @param {string} filePath The path of the file to check.
|
||||
* @returns {"ignored"|"external"|"unconfigured"|"matched"} One of the following values:
|
||||
* * `"ignored"`: the file is ignored
|
||||
* * `"external"`: the file is outside the base path
|
||||
* * `"unconfigured"`: the file is not matched by any config
|
||||
* * `"matched"`: the file has a matching config
|
||||
*/
|
||||
getConfigStatus(filePath: string): "ignored" | "external" | "unconfigured" | "matched";
|
||||
/**
|
||||
* Determines if the given filepath is ignored based on the configs.
|
||||
* @param {string} filePath The path of a file to check.
|
||||
* @returns {boolean} True if the path is ignored, false if not.
|
||||
* @deprecated Use `isFileIgnored` instead.
|
||||
*/
|
||||
isIgnored(filePath: string): boolean;
|
||||
/**
|
||||
* Determines if the given filepath is ignored based on the configs.
|
||||
* @param {string} filePath The path of a file to check.
|
||||
* @returns {boolean} True if the path is ignored, false if not.
|
||||
*/
|
||||
isFileIgnored(filePath: string): boolean;
|
||||
/**
|
||||
* Determines if the given directory is ignored based on the configs.
|
||||
* This checks only default `ignores` that don't have `files` in the
|
||||
* same config. A pattern such as `/foo` be considered to ignore the directory
|
||||
* while a pattern such as `/foo/**` is not considered to ignore the
|
||||
* directory because it is matching files.
|
||||
* @param {string} directoryPath The path of a directory to check.
|
||||
* @returns {boolean} True if the directory is ignored, false if not. Will
|
||||
* return true for any directory that is not inside of `basePath`.
|
||||
* @throws {Error} When the `ConfigArray` is not normalized.
|
||||
*/
|
||||
isDirectoryIgnored(directoryPath: string): boolean;
|
||||
#private;
|
||||
}
|
||||
export namespace ConfigArraySymbol {
|
||||
let isNormalized: symbol;
|
||||
let configCache: symbol;
|
||||
let schema: symbol;
|
||||
let finalizeConfig: symbol;
|
||||
let preprocessConfig: symbol;
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
'use strict';
|
||||
|
||||
// do not edit .js files directly - edit src/index.jst
|
||||
|
||||
|
||||
var envHasBigInt64Array = typeof BigInt64Array !== 'undefined';
|
||||
|
||||
|
||||
module.exports = function equal(a, b) {
|
||||
if (a === b) return true;
|
||||
|
||||
if (a && b && typeof a == 'object' && typeof b == 'object') {
|
||||
if (a.constructor !== b.constructor) return false;
|
||||
|
||||
var length, i, keys;
|
||||
if (Array.isArray(a)) {
|
||||
length = a.length;
|
||||
if (length != b.length) return false;
|
||||
for (i = length; i-- !== 0;)
|
||||
if (!equal(a[i], b[i])) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
if ((a instanceof Map) && (b instanceof Map)) {
|
||||
if (a.size !== b.size) return false;
|
||||
for (i of a.entries())
|
||||
if (!b.has(i[0])) return false;
|
||||
for (i of a.entries())
|
||||
if (!equal(i[1], b.get(i[0]))) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
if ((a instanceof Set) && (b instanceof Set)) {
|
||||
if (a.size !== b.size) return false;
|
||||
for (i of a.entries())
|
||||
if (!b.has(i[0])) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (ArrayBuffer.isView(a) && ArrayBuffer.isView(b)) {
|
||||
length = a.length;
|
||||
if (length != b.length) return false;
|
||||
for (i = length; i-- !== 0;)
|
||||
if (a[i] !== b[i]) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
if (a.constructor === RegExp) return a.source === b.source && a.flags === b.flags;
|
||||
if (a.valueOf !== Object.prototype.valueOf) return a.valueOf() === b.valueOf();
|
||||
if (a.toString !== Object.prototype.toString) return a.toString() === b.toString();
|
||||
|
||||
keys = Object.keys(a);
|
||||
length = keys.length;
|
||||
if (length !== Object.keys(b).length) return false;
|
||||
|
||||
for (i = length; i-- !== 0;)
|
||||
if (!Object.prototype.hasOwnProperty.call(b, keys[i])) return false;
|
||||
|
||||
for (i = length; i-- !== 0;) {
|
||||
var key = keys[i];
|
||||
|
||||
if (key === '_owner' && a.$$typeof) {
|
||||
// React-specific: avoid traversing React elements' _owner.
|
||||
// _owner contains circular references
|
||||
// and is not needed when comparing the actual elements (and not their owners)
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!equal(a[key], b[key])) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// true if both NaN, false otherwise
|
||||
return a!==a && b!==b;
|
||||
};
|
||||
@@ -0,0 +1 @@
|
||||
module.exports={A:{A:{"2":"K D E F A B mC"},B:{"1":"L M G N O P","2":"0 9 C 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":"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:{"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":"0 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 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"},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 I XD YD ZD aD lC bD cD"},J:{"2":"D A"},K:{"2":"A B C H FC kC GC"},L:{"2":"I"},M:{"2":"EC"},N:{"2":"A B"},O:{"2":"HC"},P:{"2":"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:{"2":"oD"},R:{"2":"pD"},S:{"2":"qD rD"}},B:6,C:"Object RTC (ORTC) API for WebRTC",D:true};
|
||||
@@ -0,0 +1,43 @@
|
||||
{
|
||||
"name": "optionator",
|
||||
"version": "0.9.4",
|
||||
"author": "George Zahariev <z@georgezahariev.com>",
|
||||
"description": "option parsing and help generation",
|
||||
"homepage": "https://github.com/gkz/optionator",
|
||||
"keywords": [
|
||||
"options",
|
||||
"flags",
|
||||
"option parsing",
|
||||
"cli"
|
||||
],
|
||||
"files": [
|
||||
"lib",
|
||||
"README.md",
|
||||
"LICENSE"
|
||||
],
|
||||
"main": "./lib/",
|
||||
"bugs": "https://github.com/gkz/optionator/issues",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.8.0"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/gkz/optionator.git"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "make test"
|
||||
},
|
||||
"dependencies": {
|
||||
"prelude-ls": "^1.2.1",
|
||||
"deep-is": "^0.1.3",
|
||||
"word-wrap": "^1.2.5",
|
||||
"type-check": "^0.4.0",
|
||||
"levn": "^0.4.1",
|
||||
"fast-levenshtein": "^2.0.6"
|
||||
},
|
||||
"devDependencies": {
|
||||
"livescript": "^1.6.0",
|
||||
"mocha": "^10.4.0"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
import { useMatch } from './useMatch'
|
||||
import type {
|
||||
StructuralSharingOption,
|
||||
ValidateSelected,
|
||||
} from './structuralSharing'
|
||||
import type {
|
||||
AnyRouter,
|
||||
RegisteredRouter,
|
||||
ResolveUseSearch,
|
||||
StrictOrFrom,
|
||||
ThrowConstraint,
|
||||
ThrowOrOptional,
|
||||
UseSearchResult,
|
||||
} from '@tanstack/router-core'
|
||||
|
||||
export interface UseSearchBaseOptions<
|
||||
TRouter extends AnyRouter,
|
||||
TFrom,
|
||||
TStrict extends boolean,
|
||||
TThrow extends boolean,
|
||||
TSelected,
|
||||
TStructuralSharing,
|
||||
> {
|
||||
select?: (
|
||||
state: ResolveUseSearch<TRouter, TFrom, TStrict>,
|
||||
) => ValidateSelected<TRouter, TSelected, TStructuralSharing>
|
||||
shouldThrow?: TThrow
|
||||
}
|
||||
|
||||
export type UseSearchOptions<
|
||||
TRouter extends AnyRouter,
|
||||
TFrom,
|
||||
TStrict extends boolean,
|
||||
TThrow extends boolean,
|
||||
TSelected,
|
||||
TStructuralSharing,
|
||||
> = StrictOrFrom<TRouter, TFrom, TStrict> &
|
||||
UseSearchBaseOptions<
|
||||
TRouter,
|
||||
TFrom,
|
||||
TStrict,
|
||||
TThrow,
|
||||
TSelected,
|
||||
TStructuralSharing
|
||||
> &
|
||||
StructuralSharingOption<TRouter, TSelected, TStructuralSharing>
|
||||
|
||||
export type UseSearchRoute<out TFrom> = <
|
||||
TRouter extends AnyRouter = RegisteredRouter,
|
||||
TSelected = unknown,
|
||||
TStructuralSharing extends boolean = boolean,
|
||||
>(
|
||||
opts?: UseSearchBaseOptions<
|
||||
TRouter,
|
||||
TFrom,
|
||||
/* TStrict */ true,
|
||||
/* TThrow */ true,
|
||||
TSelected,
|
||||
TStructuralSharing
|
||||
> &
|
||||
StructuralSharingOption<TRouter, TSelected, TStructuralSharing>,
|
||||
) => UseSearchResult<TRouter, TFrom, true, TSelected>
|
||||
|
||||
export function useSearch<
|
||||
TRouter extends AnyRouter = RegisteredRouter,
|
||||
const TFrom extends string | undefined = undefined,
|
||||
TStrict extends boolean = true,
|
||||
TThrow extends boolean = true,
|
||||
TSelected = unknown,
|
||||
TStructuralSharing extends boolean = boolean,
|
||||
>(
|
||||
opts: UseSearchOptions<
|
||||
TRouter,
|
||||
TFrom,
|
||||
TStrict,
|
||||
ThrowConstraint<TStrict, TThrow>,
|
||||
TSelected,
|
||||
TStructuralSharing
|
||||
>,
|
||||
): ThrowOrOptional<
|
||||
UseSearchResult<TRouter, TFrom, TStrict, TSelected>,
|
||||
TThrow
|
||||
> {
|
||||
return useMatch({
|
||||
from: opts.from!,
|
||||
strict: opts.strict,
|
||||
shouldThrow: opts.shouldThrow,
|
||||
structuralSharing: opts.structuralSharing,
|
||||
select: (match: any) => {
|
||||
return opts.select ? opts.select(match.search) : match.search
|
||||
},
|
||||
}) as any
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
{
|
||||
"name": "resolve-from",
|
||||
"version": "4.0.0",
|
||||
"description": "Resolve the path of a module like `require.resolve()` but from a given path",
|
||||
"license": "MIT",
|
||||
"repository": "sindresorhus/resolve-from",
|
||||
"author": {
|
||||
"name": "Sindre Sorhus",
|
||||
"email": "sindresorhus@gmail.com",
|
||||
"url": "sindresorhus.com"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=4"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "xo && ava"
|
||||
},
|
||||
"files": [
|
||||
"index.js"
|
||||
],
|
||||
"keywords": [
|
||||
"require",
|
||||
"resolve",
|
||||
"path",
|
||||
"module",
|
||||
"from",
|
||||
"like",
|
||||
"import"
|
||||
],
|
||||
"devDependencies": {
|
||||
"ava": "*",
|
||||
"xo": "*"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = _asyncIterator;
|
||||
function _asyncIterator(iterable) {
|
||||
var method,
|
||||
async,
|
||||
sync,
|
||||
retry = 2;
|
||||
if (typeof Symbol !== "undefined") {
|
||||
async = Symbol.asyncIterator;
|
||||
sync = Symbol.iterator;
|
||||
}
|
||||
while (retry--) {
|
||||
if (async && (method = iterable[async]) != null) {
|
||||
return method.call(iterable);
|
||||
}
|
||||
if (sync && (method = iterable[sync]) != null) {
|
||||
return new AsyncFromSyncIterator(method.call(iterable));
|
||||
}
|
||||
async = "@@asyncIterator";
|
||||
sync = "@@iterator";
|
||||
}
|
||||
throw new TypeError("Object is not async iterable");
|
||||
}
|
||||
function AsyncFromSyncIterator(s) {
|
||||
AsyncFromSyncIterator = function (s) {
|
||||
this.s = s;
|
||||
this.n = s.next;
|
||||
};
|
||||
AsyncFromSyncIterator.prototype = {
|
||||
s: null,
|
||||
n: null,
|
||||
next: function () {
|
||||
return AsyncFromSyncIteratorContinuation(this.n.apply(this.s, arguments));
|
||||
},
|
||||
return: function (value) {
|
||||
var ret = this.s.return;
|
||||
if (ret === undefined) {
|
||||
return Promise.resolve({
|
||||
value: value,
|
||||
done: true
|
||||
});
|
||||
}
|
||||
return AsyncFromSyncIteratorContinuation(ret.apply(this.s, arguments));
|
||||
},
|
||||
throw: function (maybeError) {
|
||||
var thr = this.s.return;
|
||||
if (thr === undefined) {
|
||||
return Promise.reject(maybeError);
|
||||
}
|
||||
return AsyncFromSyncIteratorContinuation(thr.apply(this.s, arguments));
|
||||
}
|
||||
};
|
||||
function AsyncFromSyncIteratorContinuation(r) {
|
||||
if (Object(r) !== r) {
|
||||
return Promise.reject(new TypeError(r + " is not an object."));
|
||||
}
|
||||
var done = r.done;
|
||||
return Promise.resolve(r.value).then(function (value) {
|
||||
return {
|
||||
value: value,
|
||||
done: done
|
||||
};
|
||||
});
|
||||
}
|
||||
return new AsyncFromSyncIterator(s);
|
||||
}
|
||||
|
||||
//# sourceMappingURL=asyncIterator.js.map
|
||||
@@ -0,0 +1 @@
|
||||
module.exports={A:{A:{"2":"K D E F mC","132":"A B"},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 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":"nC LC qC rC","129":"1 2 3 J PB K D E F A B C L M G N O P QB"},D:{"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 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","257":"1 2 3 4 5 M G N O P QB"},E:{"1":"D E F A B C L M G 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":"J PB sC SC","257":"K uC","260":"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 C 4C 5C 6C 7C FC kC 8C GC"},G:{"1":"E CD DD ED FD GD HD ID JD KD LD MD ND OD PD QD RD SD UC VC HC TD IC WC XC YC ZC aC UD JC bC cC dC eC fC VD KC gC hC iC jC","2":"SC 9C lC","257":"BD","260":"AD"},H:{"2":"WD"},I:{"1":"I bD cD","2":"LC J XD YD ZD aD lC"},J:{"2":"D","257":"A"},K:{"1":"H","2":"A B C FC kC GC"},L:{"1":"I"},M:{"1":"EC"},N:{"132":"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:4,C:"Content Security Policy 1.0",D:true};
|
||||
@@ -0,0 +1 @@
|
||||
module.exports={A:{A:{"1":"A B","2":"K D E F mC"},B:{"1":"0 9 C L M G N O P Q H R S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z AB BB CB DB EB FB GB HB IB JB KB LB MB NB OB I"},C:{"1":"0 1 2 3 4 5 6 7 8 9 J PB K D E F A B C L M G N O P QB RB SB TB UB VB WB XB YB ZB aB bB cB dB eB fB gB hB iB jB kB lB mB nB oB pB qB rB sB tB uB vB MC wB NC xB yB zB 0B 1B 2B 3B 4B 5B 6B 7B 8B 9B AC BC CC DC Q H R OC S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z AB BB CB DB EB FB GB HB IB JB KB LB MB NB OB I PC EC QC RC oC pC","2":"nC LC 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":"PB K D E F A B C L M G tC uC vC wC TC FC GC xC yC zC UC VC HC 0C IC WC XC YC ZC aC 1C JC bC cC dC eC fC 2C KC gC hC iC jC 3C","132":"J sC SC"},F:{"1":"0 1 2 3 4 5 6 7 8 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 kC 8C GC","2":"F 4C 5C 6C 7C","132":"B FC"},G:{"1":"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:{"1":"WD"},I:{"1":"LC I XD YD ZD lC bD cD","4":"J aD"},J:{"1":"D A"},K:{"1":"B C H FC kC GC","2":"A"},L:{"1":"I"},M:{"1":"EC"},N:{"1":"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:"input placeholder attribute",D:true};
|
||||
@@ -0,0 +1,31 @@
|
||||
{
|
||||
"name": "@babel/helper-string-parser",
|
||||
"version": "7.25.9",
|
||||
"description": "A utility package to parse strings",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/babel/babel.git",
|
||||
"directory": "packages/babel-helper-string-parser"
|
||||
},
|
||||
"homepage": "https://babel.dev/docs/en/next/babel-helper-string-parser",
|
||||
"license": "MIT",
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"main": "./lib/index.js",
|
||||
"devDependencies": {
|
||||
"charcodes": "^0.2.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=6.9.0"
|
||||
},
|
||||
"author": "The Babel Team (https://babel.dev/team)",
|
||||
"exports": {
|
||||
".": {
|
||||
"types": "./lib/index.d.ts",
|
||||
"default": "./lib/index.js"
|
||||
},
|
||||
"./package.json": "./package.json"
|
||||
},
|
||||
"type": "commonjs"
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,77 @@
|
||||
# flat-cache
|
||||
|
||||
> A stupidly simple key/value storage using files to persist the data
|
||||
|
||||
[](https://npmjs.org/package/flat-cache)
|
||||
[](https://github.com/jaredwray/flat-cache/actions/workflows/tests.yaml)
|
||||
[](https://codecov.io/github/jaredwray/flat-cache)
|
||||
[](https://npmjs.com/package/flat-cache)
|
||||
|
||||
## install
|
||||
|
||||
```bash
|
||||
npm i --save flat-cache
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
const flatCache = require('flat-cache');
|
||||
// loads the cache, if one does not exists for the given
|
||||
// Id a new one will be prepared to be created
|
||||
const cache = flatCache.load('cacheId');
|
||||
|
||||
// sets a key on the cache
|
||||
cache.setKey('key', { foo: 'var' });
|
||||
|
||||
// get a key from the cache
|
||||
cache.getKey('key'); // { foo: 'var' }
|
||||
|
||||
// fetch the entire persisted object
|
||||
cache.all(); // { 'key': { foo: 'var' } }
|
||||
|
||||
// remove a key
|
||||
cache.removeKey('key'); // removes a key from the cache
|
||||
|
||||
// save it to disk
|
||||
cache.save(); // very important, if you don't save no changes will be persisted.
|
||||
// cache.save( true /* noPrune */) // can be used to prevent the removal of non visited keys
|
||||
|
||||
// loads the cache from a given directory, if one does
|
||||
// not exists for the given Id a new one will be prepared to be created
|
||||
const cache = flatCache.load('cacheId', path.resolve('./path/to/folder'));
|
||||
|
||||
// The following methods are useful to clear the cache
|
||||
// delete a given cache
|
||||
flatCache.clearCacheById('cacheId'); // removes the cacheId document if one exists.
|
||||
|
||||
// delete all cache
|
||||
flatCache.clearAll(); // remove the cache directory
|
||||
```
|
||||
|
||||
## Motivation for this module
|
||||
|
||||
I needed a super simple and dumb **in-memory cache** with optional disk persistance in order to make
|
||||
a script that will beutify files with `esformatter` only execute on the files that were changed since the last run.
|
||||
To make that possible we need to store the `fileSize` and `modificationTime` of the files. So a simple `key/value`
|
||||
storage was needed and Bam! this module was born.
|
||||
|
||||
## Important notes
|
||||
|
||||
- If no directory is especified when the `load` method is called, a folder named `.cache` will be created
|
||||
inside the module directory when `cache.save` is called. If you're committing your `node_modules` to any vcs, you
|
||||
might want to ignore the default `.cache` folder, or specify a custom directory.
|
||||
- The values set on the keys of the cache should be `stringify-able` ones, meaning no circular references
|
||||
- All the changes to the cache state are done to memory
|
||||
- I could have used a timer or `Object.observe` to deliver the changes to disk, but I wanted to keep this module
|
||||
intentionally dumb and simple
|
||||
- Non visited keys are removed when `cache.save()` is called. If this is not desired, you can pass `true` to the save call
|
||||
like: `cache.save( true /* noPrune */ )`.
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
||||
|
||||
## Changelog
|
||||
|
||||
[changelog](./changelog.md)
|
||||
@@ -0,0 +1,163 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.isBindingIdentifier = isBindingIdentifier;
|
||||
exports.isBlockScoped = isBlockScoped;
|
||||
exports.isExpression = isExpression;
|
||||
exports.isFlow = isFlow;
|
||||
exports.isForAwaitStatement = isForAwaitStatement;
|
||||
exports.isGenerated = isGenerated;
|
||||
exports.isPure = isPure;
|
||||
exports.isReferenced = isReferenced;
|
||||
exports.isReferencedIdentifier = isReferencedIdentifier;
|
||||
exports.isReferencedMemberExpression = isReferencedMemberExpression;
|
||||
exports.isRestProperty = isRestProperty;
|
||||
exports.isScope = isScope;
|
||||
exports.isSpreadProperty = isSpreadProperty;
|
||||
exports.isStatement = isStatement;
|
||||
exports.isUser = isUser;
|
||||
exports.isVar = isVar;
|
||||
var _t = require("@babel/types");
|
||||
const {
|
||||
isBinding,
|
||||
isBlockScoped: nodeIsBlockScoped,
|
||||
isExportDeclaration,
|
||||
isExpression: nodeIsExpression,
|
||||
isFlow: nodeIsFlow,
|
||||
isForStatement,
|
||||
isForXStatement,
|
||||
isIdentifier,
|
||||
isImportDeclaration,
|
||||
isImportSpecifier,
|
||||
isJSXIdentifier,
|
||||
isJSXMemberExpression,
|
||||
isMemberExpression,
|
||||
isRestElement: nodeIsRestElement,
|
||||
isReferenced: nodeIsReferenced,
|
||||
isScope: nodeIsScope,
|
||||
isStatement: nodeIsStatement,
|
||||
isVar: nodeIsVar,
|
||||
isVariableDeclaration,
|
||||
react,
|
||||
isForOfStatement
|
||||
} = _t;
|
||||
const {
|
||||
isCompatTag
|
||||
} = react;
|
||||
function isReferencedIdentifier(opts) {
|
||||
const {
|
||||
node,
|
||||
parent
|
||||
} = this;
|
||||
if (!isIdentifier(node, opts) && !isJSXMemberExpression(parent, opts)) {
|
||||
if (isJSXIdentifier(node, opts)) {
|
||||
if (isCompatTag(node.name)) return false;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return nodeIsReferenced(node, parent, this.parentPath.parent);
|
||||
}
|
||||
function isReferencedMemberExpression() {
|
||||
const {
|
||||
node,
|
||||
parent
|
||||
} = this;
|
||||
return isMemberExpression(node) && nodeIsReferenced(node, parent);
|
||||
}
|
||||
function isBindingIdentifier() {
|
||||
const {
|
||||
node,
|
||||
parent
|
||||
} = this;
|
||||
const grandparent = this.parentPath.parent;
|
||||
return isIdentifier(node) && isBinding(node, parent, grandparent);
|
||||
}
|
||||
function isStatement() {
|
||||
const {
|
||||
node,
|
||||
parent
|
||||
} = this;
|
||||
if (nodeIsStatement(node)) {
|
||||
if (isVariableDeclaration(node)) {
|
||||
if (isForXStatement(parent, {
|
||||
left: node
|
||||
})) return false;
|
||||
if (isForStatement(parent, {
|
||||
init: node
|
||||
})) return false;
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
function isExpression() {
|
||||
if (this.isIdentifier()) {
|
||||
return this.isReferencedIdentifier();
|
||||
} else {
|
||||
return nodeIsExpression(this.node);
|
||||
}
|
||||
}
|
||||
function isScope() {
|
||||
return nodeIsScope(this.node, this.parent);
|
||||
}
|
||||
function isReferenced() {
|
||||
return nodeIsReferenced(this.node, this.parent);
|
||||
}
|
||||
function isBlockScoped() {
|
||||
return nodeIsBlockScoped(this.node);
|
||||
}
|
||||
function isVar() {
|
||||
return nodeIsVar(this.node);
|
||||
}
|
||||
function isUser() {
|
||||
return this.node && !!this.node.loc;
|
||||
}
|
||||
function isGenerated() {
|
||||
return !this.isUser();
|
||||
}
|
||||
function isPure(constantsOnly) {
|
||||
return this.scope.isPure(this.node, constantsOnly);
|
||||
}
|
||||
function isFlow() {
|
||||
const {
|
||||
node
|
||||
} = this;
|
||||
if (nodeIsFlow(node)) {
|
||||
return true;
|
||||
} else if (isImportDeclaration(node)) {
|
||||
return node.importKind === "type" || node.importKind === "typeof";
|
||||
} else if (isExportDeclaration(node)) {
|
||||
return node.exportKind === "type";
|
||||
} else if (isImportSpecifier(node)) {
|
||||
return node.importKind === "type" || node.importKind === "typeof";
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
function isRestProperty() {
|
||||
var _this$parentPath;
|
||||
return nodeIsRestElement(this.node) && ((_this$parentPath = this.parentPath) == null ? void 0 : _this$parentPath.isObjectPattern());
|
||||
}
|
||||
function isSpreadProperty() {
|
||||
var _this$parentPath2;
|
||||
return nodeIsRestElement(this.node) && ((_this$parentPath2 = this.parentPath) == null ? void 0 : _this$parentPath2.isObjectExpression());
|
||||
}
|
||||
function isForAwaitStatement() {
|
||||
return isForOfStatement(this.node, {
|
||||
await: true
|
||||
});
|
||||
}
|
||||
{
|
||||
exports.isExistentialTypeParam = function isExistentialTypeParam() {
|
||||
throw new Error("`path.isExistentialTypeParam` has been renamed to `path.isExistsTypeAnnotation()` in Babel 7.");
|
||||
};
|
||||
exports.isNumericLiteralTypeAnnotation = function isNumericLiteralTypeAnnotation() {
|
||||
throw new Error("`path.isNumericLiteralTypeAnnotation()` has been renamed to `path.isNumberLiteralTypeAnnotation()` in Babel 7.");
|
||||
};
|
||||
}
|
||||
|
||||
//# sourceMappingURL=virtual-types-validator.js.map
|
||||
@@ -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 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 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 qC rC"},D:{"1":"0 9 pB qB rB sB tB uB vB MC wB NC xB yB zB 0B 1B 2B 3B 4B 5B 6B 7B 8B 9B AC BC CC DC Q H R S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z AB BB CB DB EB FB GB HB IB JB KB LB MB NB OB I PC EC QC RC","2":"1 2 3 4 5 6 7 8 J PB K D E F A B C L M G N O P QB RB SB TB UB VB WB XB YB ZB aB bB cB dB eB fB gB hB iB jB kB lB mB nB oB"},E:{"1":"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 E F sC SC tC uC vC"},F:{"1":"0 cB dB eB fB gB hB iB jB kB lB mB nB oB pB qB rB sB tB uB vB wB xB yB zB 0B 1B 2B 3B 4B 5B 6B 7B 8B 9B AC BC CC DC Q H R OC S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z","2":"1 2 3 4 5 6 7 8 F B C G N O P QB RB SB TB UB VB WB XB YB ZB aB bB 4C 5C 6C 7C FC kC 8C GC"},G:{"1":"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":"E SC 9C lC AD BD CD DD ED"},H:{"2":"WD"},I:{"1":"I","2":"LC J XD YD ZD aD lC bD cD"},J:{"2":"D","16":"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 eD fD gD hD TC iD jD kD lD mD IC JC KC nD","2":"J dD"},Q:{"1":"oD"},R:{"1":"pD"},S:{"1":"qD rD"}},B:2,C:"CSS font-variant-numeric",D:true};
|
||||
@@ -0,0 +1 @@
|
||||
module.exports={A:{A:{"2":"K D E F A B mC"},B:{"2":"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:{"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:{"1":"ZB aB bB cB dB eB fB gB hB iB jB kB lB mB","2":"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 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:{"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:{"1":"4 5 6 7 8 RB SB TB UB VB WB XB YB ZB","2":"0 1 2 3 F B C G N O P QB 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"},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 I XD YD ZD aD lC bD cD"},J:{"2":"D A"},K:{"2":"A B C H FC kC GC"},L:{"2":"I"},M:{"2":"EC"},N:{"2":"A B"},O:{"2":"HC"},P:{"1":"J","2":"1 2 3 4 5 6 7 8 dD eD fD gD hD TC iD jD kD lD mD IC JC KC nD"},Q:{"2":"oD"},R:{"2":"pD"},S:{"2":"qD rD"}},B:7,C:"Object.observe data binding",D:true};
|
||||
@@ -0,0 +1,86 @@
|
||||
var has = Object.prototype.hasOwnProperty;
|
||||
|
||||
function find(iter, tar, key) {
|
||||
for (key of iter.keys()) {
|
||||
if (dequal(key, tar)) return key;
|
||||
}
|
||||
}
|
||||
|
||||
function dequal(foo, bar) {
|
||||
var ctor, len, tmp;
|
||||
if (foo === bar) return true;
|
||||
|
||||
if (foo && bar && (ctor=foo.constructor) === bar.constructor) {
|
||||
if (ctor === Date) return foo.getTime() === bar.getTime();
|
||||
if (ctor === RegExp) return foo.toString() === bar.toString();
|
||||
|
||||
if (ctor === Array) {
|
||||
if ((len=foo.length) === bar.length) {
|
||||
while (len-- && dequal(foo[len], bar[len]));
|
||||
}
|
||||
return len === -1;
|
||||
}
|
||||
|
||||
if (ctor === Set) {
|
||||
if (foo.size !== bar.size) {
|
||||
return false;
|
||||
}
|
||||
for (len of foo) {
|
||||
tmp = len;
|
||||
if (tmp && typeof tmp === 'object') {
|
||||
tmp = find(bar, tmp);
|
||||
if (!tmp) return false;
|
||||
}
|
||||
if (!bar.has(tmp)) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if (ctor === Map) {
|
||||
if (foo.size !== bar.size) {
|
||||
return false;
|
||||
}
|
||||
for (len of foo) {
|
||||
tmp = len[0];
|
||||
if (tmp && typeof tmp === 'object') {
|
||||
tmp = find(bar, tmp);
|
||||
if (!tmp) return false;
|
||||
}
|
||||
if (!dequal(len[1], bar.get(tmp))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if (ctor === ArrayBuffer) {
|
||||
foo = new Uint8Array(foo);
|
||||
bar = new Uint8Array(bar);
|
||||
} else if (ctor === DataView) {
|
||||
if ((len=foo.byteLength) === bar.byteLength) {
|
||||
while (len-- && foo.getInt8(len) === bar.getInt8(len));
|
||||
}
|
||||
return len === -1;
|
||||
}
|
||||
|
||||
if (ArrayBuffer.isView(foo)) {
|
||||
if ((len=foo.byteLength) === bar.byteLength) {
|
||||
while (len-- && foo[len] === bar[len]);
|
||||
}
|
||||
return len === -1;
|
||||
}
|
||||
|
||||
if (!ctor || typeof foo === 'object') {
|
||||
len = 0;
|
||||
for (ctor in foo) {
|
||||
if (has.call(foo, ctor) && ++len && !has.call(bar, ctor)) return false;
|
||||
if (!(ctor in bar) || !dequal(foo[ctor], bar[ctor])) return false;
|
||||
}
|
||||
return Object.keys(bar).length === len;
|
||||
}
|
||||
}
|
||||
|
||||
return foo !== foo && bar !== bar;
|
||||
}
|
||||
|
||||
exports.dequal = dequal;
|
||||
@@ -0,0 +1,411 @@
|
||||
/**
|
||||
* @fileoverview The event generator for AST nodes.
|
||||
* @author Toru Nagashima
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Requirements
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
const esquery = require("esquery");
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Typedefs
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* An object describing an AST selector
|
||||
* @typedef {Object} ASTSelector
|
||||
* @property {string} rawSelector The string that was parsed into this selector
|
||||
* @property {boolean} isExit `true` if this should be emitted when exiting the node rather than when entering
|
||||
* @property {Object} parsedSelector An object (from esquery) describing the matching behavior of the selector
|
||||
* @property {string[]|null} listenerTypes A list of node types that could possibly cause the selector to match,
|
||||
* or `null` if all node types could cause a match
|
||||
* @property {number} attributeCount The total number of classes, pseudo-classes, and attribute queries in this selector
|
||||
* @property {number} identifierCount The total number of identifier queries in this selector
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Helpers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Computes the union of one or more arrays
|
||||
* @param {...any[]} arrays One or more arrays to union
|
||||
* @returns {any[]} The union of the input arrays
|
||||
*/
|
||||
function union(...arrays) {
|
||||
return [...new Set(arrays.flat())];
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes the intersection of one or more arrays
|
||||
* @param {...any[]} arrays One or more arrays to intersect
|
||||
* @returns {any[]} The intersection of the input arrays
|
||||
*/
|
||||
function intersection(...arrays) {
|
||||
if (arrays.length === 0) {
|
||||
return [];
|
||||
}
|
||||
|
||||
let result = [...new Set(arrays[0])];
|
||||
|
||||
for (const array of arrays.slice(1)) {
|
||||
result = result.filter(x => array.includes(x));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the possible types of a selector
|
||||
* @param {Object} parsedSelector An object (from esquery) describing the matching behavior of the selector
|
||||
* @returns {string[]|null} The node types that could possibly trigger this selector, or `null` if all node types could trigger it
|
||||
*/
|
||||
function getPossibleTypes(parsedSelector) {
|
||||
switch (parsedSelector.type) {
|
||||
case "identifier":
|
||||
return [parsedSelector.value];
|
||||
|
||||
case "matches": {
|
||||
const typesForComponents =
|
||||
parsedSelector.selectors.map(getPossibleTypes);
|
||||
|
||||
if (typesForComponents.every(Boolean)) {
|
||||
return union(...typesForComponents);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
case "compound": {
|
||||
const typesForComponents = parsedSelector.selectors
|
||||
.map(getPossibleTypes)
|
||||
.filter(typesForComponent => typesForComponent);
|
||||
|
||||
// If all of the components could match any type, then the compound could also match any type.
|
||||
if (!typesForComponents.length) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/*
|
||||
* If at least one of the components could only match a particular type, the compound could only match
|
||||
* the intersection of those types.
|
||||
*/
|
||||
return intersection(...typesForComponents);
|
||||
}
|
||||
|
||||
case "child":
|
||||
case "descendant":
|
||||
case "sibling":
|
||||
case "adjacent":
|
||||
return getPossibleTypes(parsedSelector.right);
|
||||
|
||||
case "class":
|
||||
if (parsedSelector.name === "function") {
|
||||
return [
|
||||
"FunctionDeclaration",
|
||||
"FunctionExpression",
|
||||
"ArrowFunctionExpression",
|
||||
];
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Counts the number of class, pseudo-class, and attribute queries in this selector
|
||||
* @param {Object} parsedSelector An object (from esquery) describing the selector's matching behavior
|
||||
* @returns {number} The number of class, pseudo-class, and attribute queries in this selector
|
||||
*/
|
||||
function countClassAttributes(parsedSelector) {
|
||||
switch (parsedSelector.type) {
|
||||
case "child":
|
||||
case "descendant":
|
||||
case "sibling":
|
||||
case "adjacent":
|
||||
return (
|
||||
countClassAttributes(parsedSelector.left) +
|
||||
countClassAttributes(parsedSelector.right)
|
||||
);
|
||||
|
||||
case "compound":
|
||||
case "not":
|
||||
case "matches":
|
||||
return parsedSelector.selectors.reduce(
|
||||
(sum, childSelector) =>
|
||||
sum + countClassAttributes(childSelector),
|
||||
0,
|
||||
);
|
||||
|
||||
case "attribute":
|
||||
case "field":
|
||||
case "nth-child":
|
||||
case "nth-last-child":
|
||||
return 1;
|
||||
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Counts the number of identifier queries in this selector
|
||||
* @param {Object} parsedSelector An object (from esquery) describing the selector's matching behavior
|
||||
* @returns {number} The number of identifier queries
|
||||
*/
|
||||
function countIdentifiers(parsedSelector) {
|
||||
switch (parsedSelector.type) {
|
||||
case "child":
|
||||
case "descendant":
|
||||
case "sibling":
|
||||
case "adjacent":
|
||||
return (
|
||||
countIdentifiers(parsedSelector.left) +
|
||||
countIdentifiers(parsedSelector.right)
|
||||
);
|
||||
|
||||
case "compound":
|
||||
case "not":
|
||||
case "matches":
|
||||
return parsedSelector.selectors.reduce(
|
||||
(sum, childSelector) => sum + countIdentifiers(childSelector),
|
||||
0,
|
||||
);
|
||||
|
||||
case "identifier":
|
||||
return 1;
|
||||
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares the specificity of two selector objects, with CSS-like rules.
|
||||
* @param {ASTSelector} selectorA An AST selector descriptor
|
||||
* @param {ASTSelector} selectorB Another AST selector descriptor
|
||||
* @returns {number}
|
||||
* a value less than 0 if selectorA is less specific than selectorB
|
||||
* a value greater than 0 if selectorA is more specific than selectorB
|
||||
* a value less than 0 if selectorA and selectorB have the same specificity, and selectorA <= selectorB alphabetically
|
||||
* a value greater than 0 if selectorA and selectorB have the same specificity, and selectorA > selectorB alphabetically
|
||||
*/
|
||||
function compareSpecificity(selectorA, selectorB) {
|
||||
return (
|
||||
selectorA.attributeCount - selectorB.attributeCount ||
|
||||
selectorA.identifierCount - selectorB.identifierCount ||
|
||||
(selectorA.rawSelector <= selectorB.rawSelector ? -1 : 1)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a raw selector string, and throws a useful error if parsing fails.
|
||||
* @param {string} rawSelector A raw AST selector
|
||||
* @returns {Object} An object (from esquery) describing the matching behavior of this selector
|
||||
* @throws {Error} An error if the selector is invalid
|
||||
*/
|
||||
function tryParseSelector(rawSelector) {
|
||||
try {
|
||||
return esquery.parse(rawSelector.replace(/:exit$/u, ""));
|
||||
} catch (err) {
|
||||
if (
|
||||
err.location &&
|
||||
err.location.start &&
|
||||
typeof err.location.start.offset === "number"
|
||||
) {
|
||||
throw new SyntaxError(
|
||||
`Syntax error in selector "${rawSelector}" at position ${err.location.start.offset}: ${err.message}`,
|
||||
);
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
const selectorCache = new Map();
|
||||
|
||||
/**
|
||||
* Parses a raw selector string, and returns the parsed selector along with specificity and type information.
|
||||
* @param {string} rawSelector A raw AST selector
|
||||
* @returns {ASTSelector} A selector descriptor
|
||||
*/
|
||||
function parseSelector(rawSelector) {
|
||||
if (selectorCache.has(rawSelector)) {
|
||||
return selectorCache.get(rawSelector);
|
||||
}
|
||||
|
||||
const parsedSelector = tryParseSelector(rawSelector);
|
||||
|
||||
const result = {
|
||||
rawSelector,
|
||||
isExit: rawSelector.endsWith(":exit"),
|
||||
parsedSelector,
|
||||
listenerTypes: getPossibleTypes(parsedSelector),
|
||||
attributeCount: countClassAttributes(parsedSelector),
|
||||
identifierCount: countIdentifiers(parsedSelector),
|
||||
};
|
||||
|
||||
selectorCache.set(rawSelector, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Public Interface
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* The event generator for AST nodes.
|
||||
* This implements below interface.
|
||||
*
|
||||
* ```ts
|
||||
* interface EventGenerator {
|
||||
* emitter: SafeEmitter;
|
||||
* enterNode(node: ASTNode): void;
|
||||
* leaveNode(node: ASTNode): void;
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
class NodeEventGenerator {
|
||||
/**
|
||||
* @param {SafeEmitter} emitter
|
||||
* An SafeEmitter which is the destination of events. This emitter must already
|
||||
* have registered listeners for all of the events that it needs to listen for.
|
||||
* (See lib/linter/safe-emitter.js for more details on `SafeEmitter`.)
|
||||
* @param {ESQueryOptions} esqueryOptions `esquery` options for traversing custom nodes.
|
||||
* @returns {NodeEventGenerator} new instance
|
||||
*/
|
||||
constructor(emitter, esqueryOptions) {
|
||||
this.emitter = emitter;
|
||||
this.esqueryOptions = esqueryOptions;
|
||||
this.currentAncestry = [];
|
||||
this.enterSelectorsByNodeType = new Map();
|
||||
this.exitSelectorsByNodeType = new Map();
|
||||
this.anyTypeEnterSelectors = [];
|
||||
this.anyTypeExitSelectors = [];
|
||||
|
||||
emitter.eventNames().forEach(rawSelector => {
|
||||
const selector = parseSelector(rawSelector);
|
||||
|
||||
if (selector.listenerTypes) {
|
||||
const typeMap = selector.isExit
|
||||
? this.exitSelectorsByNodeType
|
||||
: this.enterSelectorsByNodeType;
|
||||
|
||||
selector.listenerTypes.forEach(nodeType => {
|
||||
if (!typeMap.has(nodeType)) {
|
||||
typeMap.set(nodeType, []);
|
||||
}
|
||||
typeMap.get(nodeType).push(selector);
|
||||
});
|
||||
return;
|
||||
}
|
||||
const selectors = selector.isExit
|
||||
? this.anyTypeExitSelectors
|
||||
: this.anyTypeEnterSelectors;
|
||||
|
||||
selectors.push(selector);
|
||||
});
|
||||
|
||||
this.anyTypeEnterSelectors.sort(compareSpecificity);
|
||||
this.anyTypeExitSelectors.sort(compareSpecificity);
|
||||
this.enterSelectorsByNodeType.forEach(selectorList =>
|
||||
selectorList.sort(compareSpecificity),
|
||||
);
|
||||
this.exitSelectorsByNodeType.forEach(selectorList =>
|
||||
selectorList.sort(compareSpecificity),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks a selector against a node, and emits it if it matches
|
||||
* @param {ASTNode} node The node to check
|
||||
* @param {ASTSelector} selector An AST selector descriptor
|
||||
* @returns {void}
|
||||
*/
|
||||
applySelector(node, selector) {
|
||||
if (
|
||||
esquery.matches(
|
||||
node,
|
||||
selector.parsedSelector,
|
||||
this.currentAncestry,
|
||||
this.esqueryOptions,
|
||||
)
|
||||
) {
|
||||
this.emitter.emit(selector.rawSelector, node);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies all appropriate selectors to a node, in specificity order
|
||||
* @param {ASTNode} node The node to check
|
||||
* @param {boolean} isExit `false` if the node is currently being entered, `true` if it's currently being exited
|
||||
* @returns {void}
|
||||
*/
|
||||
applySelectors(node, isExit) {
|
||||
const selectorsByNodeType =
|
||||
(isExit
|
||||
? this.exitSelectorsByNodeType
|
||||
: this.enterSelectorsByNodeType
|
||||
).get(node.type) || [];
|
||||
const anyTypeSelectors = isExit
|
||||
? this.anyTypeExitSelectors
|
||||
: this.anyTypeEnterSelectors;
|
||||
|
||||
/*
|
||||
* selectorsByNodeType and anyTypeSelectors were already sorted by specificity in the constructor.
|
||||
* Iterate through each of them, applying selectors in the right order.
|
||||
*/
|
||||
let selectorsByTypeIndex = 0;
|
||||
let anyTypeSelectorsIndex = 0;
|
||||
|
||||
while (
|
||||
selectorsByTypeIndex < selectorsByNodeType.length ||
|
||||
anyTypeSelectorsIndex < anyTypeSelectors.length
|
||||
) {
|
||||
if (
|
||||
selectorsByTypeIndex >= selectorsByNodeType.length ||
|
||||
(anyTypeSelectorsIndex < anyTypeSelectors.length &&
|
||||
compareSpecificity(
|
||||
anyTypeSelectors[anyTypeSelectorsIndex],
|
||||
selectorsByNodeType[selectorsByTypeIndex],
|
||||
) < 0)
|
||||
) {
|
||||
this.applySelector(
|
||||
node,
|
||||
anyTypeSelectors[anyTypeSelectorsIndex++],
|
||||
);
|
||||
} else {
|
||||
this.applySelector(
|
||||
node,
|
||||
selectorsByNodeType[selectorsByTypeIndex++],
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Emits an event of entering AST node.
|
||||
* @param {ASTNode} node A node which was entered.
|
||||
* @returns {void}
|
||||
*/
|
||||
enterNode(node) {
|
||||
this.applySelectors(node, false);
|
||||
this.currentAncestry.unshift(node);
|
||||
}
|
||||
|
||||
/**
|
||||
* Emits an event of leaving AST node.
|
||||
* @param {ASTNode} node A node which was left.
|
||||
* @returns {void}
|
||||
*/
|
||||
leaveNode(node) {
|
||||
this.currentAncestry.shift();
|
||||
this.applySelectors(node, true);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = NodeEventGenerator;
|
||||
@@ -0,0 +1 @@
|
||||
module.exports={A:{A:{"2":"K D E F A B mC"},B:{"2":"0 9 C L M G N O P Q H R S T U V W X Y Z t u v w x y z AB BB CB DB EB FB GB HB IB JB KB LB MB NB OB I","578":"a b c d e f g h i j k l m n o p q r s"},C:{"2":"1 2 3 4 5 6 7 8 nC LC J PB K D E F A B C L M G N O P QB RB SB TB UB VB WB XB YB ZB aB bB cB dB eB fB 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 qC rC","322":"0 9 Z a b c d e f g h i j k l m n o p q r s t u v w x y z AB BB CB DB EB FB GB HB IB JB KB LB MB NB OB I PC EC QC RC oC pC"},D:{"2":"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 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","194":"a b c d e f g h i j k l m n o p q r s"},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","1025":"JC bC cC dC eC fC 2C KC gC hC iC jC 3C"},F:{"2":"0 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 qB rB sB tB uB vB wB xB yB zB 0B 1B 2B 3B 4B 5B 6B 7B 8B 9B AC BC 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","194":"CC DC Q H R OC S T U V W X Y Z a b c d e"},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","1025":"JC bC cC dC eC fC VD KC gC hC iC jC"},H:{"2":"WD"},I:{"2":"LC J I XD YD ZD aD lC bD cD"},J:{"2":"D A"},K:{"2":"A B C H FC kC GC"},L:{"2":"I"},M:{"2":"EC"},N:{"2":"A B"},O:{"2":"HC"},P:{"2":"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:{"2":"oD"},R:{"2":"pD"},S:{"2":"qD rD"}},B:6,C:"JPEG XL image format",D:true};
|
||||
@@ -0,0 +1,292 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = exports.SHOULD_STOP = exports.SHOULD_SKIP = exports.REMOVED = void 0;
|
||||
var virtualTypes = require("./lib/virtual-types.js");
|
||||
var _debug = require("debug");
|
||||
var _index = require("../index.js");
|
||||
var _index2 = require("../scope/index.js");
|
||||
var _t = require("@babel/types");
|
||||
var t = _t;
|
||||
var cache = require("../cache.js");
|
||||
var _generator = require("@babel/generator");
|
||||
var NodePath_ancestry = require("./ancestry.js");
|
||||
var NodePath_inference = require("./inference/index.js");
|
||||
var NodePath_replacement = require("./replacement.js");
|
||||
var NodePath_evaluation = require("./evaluation.js");
|
||||
var NodePath_conversion = require("./conversion.js");
|
||||
var NodePath_introspection = require("./introspection.js");
|
||||
var _context = require("./context.js");
|
||||
var NodePath_context = _context;
|
||||
var NodePath_removal = require("./removal.js");
|
||||
var NodePath_modification = require("./modification.js");
|
||||
var NodePath_family = require("./family.js");
|
||||
var NodePath_comments = require("./comments.js");
|
||||
var NodePath_virtual_types_validator = require("./lib/virtual-types-validator.js");
|
||||
const {
|
||||
validate
|
||||
} = _t;
|
||||
const debug = _debug("babel");
|
||||
const REMOVED = exports.REMOVED = 1 << 0;
|
||||
const SHOULD_STOP = exports.SHOULD_STOP = 1 << 1;
|
||||
const SHOULD_SKIP = exports.SHOULD_SKIP = 1 << 2;
|
||||
const NodePath_Final = exports.default = class NodePath {
|
||||
constructor(hub, parent) {
|
||||
this.contexts = [];
|
||||
this.state = null;
|
||||
this.opts = null;
|
||||
this._traverseFlags = 0;
|
||||
this.skipKeys = null;
|
||||
this.parentPath = null;
|
||||
this.container = null;
|
||||
this.listKey = null;
|
||||
this.key = null;
|
||||
this.node = null;
|
||||
this.type = null;
|
||||
this.parent = parent;
|
||||
this.hub = hub;
|
||||
this.data = null;
|
||||
this.context = null;
|
||||
this.scope = null;
|
||||
}
|
||||
get removed() {
|
||||
return (this._traverseFlags & 1) > 0;
|
||||
}
|
||||
set removed(v) {
|
||||
if (v) this._traverseFlags |= 1;else this._traverseFlags &= -2;
|
||||
}
|
||||
get shouldStop() {
|
||||
return (this._traverseFlags & 2) > 0;
|
||||
}
|
||||
set shouldStop(v) {
|
||||
if (v) this._traverseFlags |= 2;else this._traverseFlags &= -3;
|
||||
}
|
||||
get shouldSkip() {
|
||||
return (this._traverseFlags & 4) > 0;
|
||||
}
|
||||
set shouldSkip(v) {
|
||||
if (v) this._traverseFlags |= 4;else this._traverseFlags &= -5;
|
||||
}
|
||||
static get({
|
||||
hub,
|
||||
parentPath,
|
||||
parent,
|
||||
container,
|
||||
listKey,
|
||||
key
|
||||
}) {
|
||||
if (!hub && parentPath) {
|
||||
hub = parentPath.hub;
|
||||
}
|
||||
if (!parent) {
|
||||
throw new Error("To get a node path the parent needs to exist");
|
||||
}
|
||||
const targetNode = container[key];
|
||||
const paths = cache.getOrCreateCachedPaths(hub, parent);
|
||||
let path = paths.get(targetNode);
|
||||
if (!path) {
|
||||
path = new NodePath(hub, parent);
|
||||
if (targetNode) paths.set(targetNode, path);
|
||||
}
|
||||
_context.setup.call(path, parentPath, container, listKey, key);
|
||||
return path;
|
||||
}
|
||||
getScope(scope) {
|
||||
return this.isScope() ? new _index2.default(this) : scope;
|
||||
}
|
||||
setData(key, val) {
|
||||
if (this.data == null) {
|
||||
this.data = Object.create(null);
|
||||
}
|
||||
return this.data[key] = val;
|
||||
}
|
||||
getData(key, def) {
|
||||
if (this.data == null) {
|
||||
this.data = Object.create(null);
|
||||
}
|
||||
let val = this.data[key];
|
||||
if (val === undefined && def !== undefined) val = this.data[key] = def;
|
||||
return val;
|
||||
}
|
||||
hasNode() {
|
||||
return this.node != null;
|
||||
}
|
||||
buildCodeFrameError(msg, Error = SyntaxError) {
|
||||
return this.hub.buildError(this.node, msg, Error);
|
||||
}
|
||||
traverse(visitor, state) {
|
||||
(0, _index.default)(this.node, visitor, this.scope, state, this);
|
||||
}
|
||||
set(key, node) {
|
||||
validate(this.node, key, node);
|
||||
this.node[key] = node;
|
||||
}
|
||||
getPathLocation() {
|
||||
const parts = [];
|
||||
let path = this;
|
||||
do {
|
||||
let key = path.key;
|
||||
if (path.inList) key = `${path.listKey}[${key}]`;
|
||||
parts.unshift(key);
|
||||
} while (path = path.parentPath);
|
||||
return parts.join(".");
|
||||
}
|
||||
debug(message) {
|
||||
if (!debug.enabled) return;
|
||||
debug(`${this.getPathLocation()} ${this.type}: ${message}`);
|
||||
}
|
||||
toString() {
|
||||
return (0, _generator.default)(this.node).code;
|
||||
}
|
||||
get inList() {
|
||||
return !!this.listKey;
|
||||
}
|
||||
set inList(inList) {
|
||||
if (!inList) {
|
||||
this.listKey = null;
|
||||
}
|
||||
}
|
||||
get parentKey() {
|
||||
return this.listKey || this.key;
|
||||
}
|
||||
};
|
||||
const methods = {
|
||||
findParent: NodePath_ancestry.findParent,
|
||||
find: NodePath_ancestry.find,
|
||||
getFunctionParent: NodePath_ancestry.getFunctionParent,
|
||||
getStatementParent: NodePath_ancestry.getStatementParent,
|
||||
getEarliestCommonAncestorFrom: NodePath_ancestry.getEarliestCommonAncestorFrom,
|
||||
getDeepestCommonAncestorFrom: NodePath_ancestry.getDeepestCommonAncestorFrom,
|
||||
getAncestry: NodePath_ancestry.getAncestry,
|
||||
isAncestor: NodePath_ancestry.isAncestor,
|
||||
isDescendant: NodePath_ancestry.isDescendant,
|
||||
inType: NodePath_ancestry.inType,
|
||||
getTypeAnnotation: NodePath_inference.getTypeAnnotation,
|
||||
isBaseType: NodePath_inference.isBaseType,
|
||||
couldBeBaseType: NodePath_inference.couldBeBaseType,
|
||||
baseTypeStrictlyMatches: NodePath_inference.baseTypeStrictlyMatches,
|
||||
isGenericType: NodePath_inference.isGenericType,
|
||||
replaceWithMultiple: NodePath_replacement.replaceWithMultiple,
|
||||
replaceWithSourceString: NodePath_replacement.replaceWithSourceString,
|
||||
replaceWith: NodePath_replacement.replaceWith,
|
||||
replaceExpressionWithStatements: NodePath_replacement.replaceExpressionWithStatements,
|
||||
replaceInline: NodePath_replacement.replaceInline,
|
||||
evaluateTruthy: NodePath_evaluation.evaluateTruthy,
|
||||
evaluate: NodePath_evaluation.evaluate,
|
||||
toComputedKey: NodePath_conversion.toComputedKey,
|
||||
ensureBlock: NodePath_conversion.ensureBlock,
|
||||
unwrapFunctionEnvironment: NodePath_conversion.unwrapFunctionEnvironment,
|
||||
arrowFunctionToExpression: NodePath_conversion.arrowFunctionToExpression,
|
||||
splitExportDeclaration: NodePath_conversion.splitExportDeclaration,
|
||||
ensureFunctionName: NodePath_conversion.ensureFunctionName,
|
||||
matchesPattern: NodePath_introspection.matchesPattern,
|
||||
isStatic: NodePath_introspection.isStatic,
|
||||
isNodeType: NodePath_introspection.isNodeType,
|
||||
canHaveVariableDeclarationOrExpression: NodePath_introspection.canHaveVariableDeclarationOrExpression,
|
||||
canSwapBetweenExpressionAndStatement: NodePath_introspection.canSwapBetweenExpressionAndStatement,
|
||||
isCompletionRecord: NodePath_introspection.isCompletionRecord,
|
||||
isStatementOrBlock: NodePath_introspection.isStatementOrBlock,
|
||||
referencesImport: NodePath_introspection.referencesImport,
|
||||
getSource: NodePath_introspection.getSource,
|
||||
willIMaybeExecuteBefore: NodePath_introspection.willIMaybeExecuteBefore,
|
||||
_guessExecutionStatusRelativeTo: NodePath_introspection._guessExecutionStatusRelativeTo,
|
||||
resolve: NodePath_introspection.resolve,
|
||||
isConstantExpression: NodePath_introspection.isConstantExpression,
|
||||
isInStrictMode: NodePath_introspection.isInStrictMode,
|
||||
isDenylisted: NodePath_context.isDenylisted,
|
||||
visit: NodePath_context.visit,
|
||||
skip: NodePath_context.skip,
|
||||
skipKey: NodePath_context.skipKey,
|
||||
stop: NodePath_context.stop,
|
||||
setContext: NodePath_context.setContext,
|
||||
requeue: NodePath_context.requeue,
|
||||
requeueComputedKeyAndDecorators: NodePath_context.requeueComputedKeyAndDecorators,
|
||||
remove: NodePath_removal.remove,
|
||||
insertBefore: NodePath_modification.insertBefore,
|
||||
insertAfter: NodePath_modification.insertAfter,
|
||||
unshiftContainer: NodePath_modification.unshiftContainer,
|
||||
pushContainer: NodePath_modification.pushContainer,
|
||||
getOpposite: NodePath_family.getOpposite,
|
||||
getCompletionRecords: NodePath_family.getCompletionRecords,
|
||||
getSibling: NodePath_family.getSibling,
|
||||
getPrevSibling: NodePath_family.getPrevSibling,
|
||||
getNextSibling: NodePath_family.getNextSibling,
|
||||
getAllNextSiblings: NodePath_family.getAllNextSiblings,
|
||||
getAllPrevSiblings: NodePath_family.getAllPrevSiblings,
|
||||
get: NodePath_family.get,
|
||||
getAssignmentIdentifiers: NodePath_family.getAssignmentIdentifiers,
|
||||
getBindingIdentifiers: NodePath_family.getBindingIdentifiers,
|
||||
getOuterBindingIdentifiers: NodePath_family.getOuterBindingIdentifiers,
|
||||
getBindingIdentifierPaths: NodePath_family.getBindingIdentifierPaths,
|
||||
getOuterBindingIdentifierPaths: NodePath_family.getOuterBindingIdentifierPaths,
|
||||
shareCommentsWithSiblings: NodePath_comments.shareCommentsWithSiblings,
|
||||
addComment: NodePath_comments.addComment,
|
||||
addComments: NodePath_comments.addComments
|
||||
};
|
||||
Object.assign(NodePath_Final.prototype, methods);
|
||||
{
|
||||
NodePath_Final.prototype.arrowFunctionToShadowed = NodePath_conversion[String("arrowFunctionToShadowed")];
|
||||
Object.assign(NodePath_Final.prototype, {
|
||||
has: NodePath_introspection[String("has")],
|
||||
is: NodePath_introspection[String("is")],
|
||||
isnt: NodePath_introspection[String("isnt")],
|
||||
equals: NodePath_introspection[String("equals")],
|
||||
hoist: NodePath_modification[String("hoist")],
|
||||
updateSiblingKeys: NodePath_modification.updateSiblingKeys,
|
||||
call: NodePath_context.call,
|
||||
isBlacklisted: NodePath_context[String("isBlacklisted")],
|
||||
setScope: NodePath_context.setScope,
|
||||
resync: NodePath_context.resync,
|
||||
popContext: NodePath_context.popContext,
|
||||
pushContext: NodePath_context.pushContext,
|
||||
setup: NodePath_context.setup,
|
||||
setKey: NodePath_context.setKey
|
||||
});
|
||||
}
|
||||
{
|
||||
NodePath_Final.prototype._guessExecutionStatusRelativeToDifferentFunctions = NodePath_introspection._guessExecutionStatusRelativeTo;
|
||||
NodePath_Final.prototype._guessExecutionStatusRelativeToDifferentFunctions = NodePath_introspection._guessExecutionStatusRelativeTo;
|
||||
Object.assign(NodePath_Final.prototype, {
|
||||
_getTypeAnnotation: NodePath_inference._getTypeAnnotation,
|
||||
_replaceWith: NodePath_replacement._replaceWith,
|
||||
_resolve: NodePath_introspection._resolve,
|
||||
_call: NodePath_context._call,
|
||||
_resyncParent: NodePath_context._resyncParent,
|
||||
_resyncKey: NodePath_context._resyncKey,
|
||||
_resyncList: NodePath_context._resyncList,
|
||||
_resyncRemoved: NodePath_context._resyncRemoved,
|
||||
_getQueueContexts: NodePath_context._getQueueContexts,
|
||||
_removeFromScope: NodePath_removal._removeFromScope,
|
||||
_callRemovalHooks: NodePath_removal._callRemovalHooks,
|
||||
_remove: NodePath_removal._remove,
|
||||
_markRemoved: NodePath_removal._markRemoved,
|
||||
_assertUnremoved: NodePath_removal._assertUnremoved,
|
||||
_containerInsert: NodePath_modification._containerInsert,
|
||||
_containerInsertBefore: NodePath_modification._containerInsertBefore,
|
||||
_containerInsertAfter: NodePath_modification._containerInsertAfter,
|
||||
_verifyNodeList: NodePath_modification._verifyNodeList,
|
||||
_getKey: NodePath_family._getKey,
|
||||
_getPattern: NodePath_family._getPattern
|
||||
});
|
||||
}
|
||||
for (const type of t.TYPES) {
|
||||
const typeKey = `is${type}`;
|
||||
const fn = t[typeKey];
|
||||
NodePath_Final.prototype[typeKey] = function (opts) {
|
||||
return fn(this.node, opts);
|
||||
};
|
||||
NodePath_Final.prototype[`assert${type}`] = function (opts) {
|
||||
if (!fn(this.node, opts)) {
|
||||
throw new TypeError(`Expected node path of type ${type}`);
|
||||
}
|
||||
};
|
||||
}
|
||||
Object.assign(NodePath_Final.prototype, NodePath_virtual_types_validator);
|
||||
for (const type of Object.keys(virtualTypes)) {
|
||||
if (type[0] === "_") continue;
|
||||
if (!t.TYPES.includes(type)) t.TYPES.push(type);
|
||||
}
|
||||
|
||||
//# sourceMappingURL=index.js.map
|
||||
@@ -0,0 +1,301 @@
|
||||
#! /usr/bin/env node
|
||||
|
||||
'use strict';
|
||||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
const args = process.argv.slice(2);
|
||||
const dir = args[0];
|
||||
if (!dir) {
|
||||
console.log('Usage: node ' + path.basename(__filename) + ' <target-dir>');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const NodeApiVersion = require('../package.json').version;
|
||||
|
||||
const disable = args[1];
|
||||
let ConfigFileOperations;
|
||||
if (disable !== '--disable' && dir !== '--disable') {
|
||||
ConfigFileOperations = {
|
||||
'package.json': [
|
||||
[/([ ]*)"dependencies": {/g, '$1"dependencies": {\n$1 "node-addon-api": "' + NodeApiVersion + '",'],
|
||||
[/[ ]*"nan": *"[^"]+"(,|)[\n\r]/g, '']
|
||||
],
|
||||
'binding.gyp': [
|
||||
[/([ ]*)'include_dirs': \[/g, '$1\'include_dirs\': [\n$1 \'<!(node -p "require(\\\'node-addon-api\\\').include_dir")\','],
|
||||
[/([ ]*)"include_dirs": \[/g, '$1"include_dirs": [\n$1 "<!(node -p \\"require(\'node-addon-api\').include_dir\\")",'],
|
||||
[/[ ]*("|')<!\(node -e ("|'|\\"|\\')require\(("|'|\\"|\\')nan("|'|\\"|\\')\)("|'|\\"|\\')\)("|')(,|)[\r\n]/g, ''],
|
||||
[/([ ]*)("|')target_name("|'): ("|')(.+?)("|'),/g, '$1$2target_name$2: $4$5$6,\n $2cflags!$2: [ $2-fno-exceptions$2 ],\n $2cflags_cc!$2: [ $2-fno-exceptions$2 ],\n $2xcode_settings$2: { $2GCC_ENABLE_CPP_EXCEPTIONS$2: $2YES$2,\n $2CLANG_CXX_LIBRARY$2: $2libc++$2,\n $2MACOSX_DEPLOYMENT_TARGET$2: $210.7$2,\n },\n $2msvs_settings$2: {\n $2VCCLCompilerTool$2: { $2ExceptionHandling$2: 1 },\n },']
|
||||
]
|
||||
};
|
||||
} else {
|
||||
ConfigFileOperations = {
|
||||
'package.json': [
|
||||
[/([ ]*)"dependencies": {/g, '$1"dependencies": {\n$1 "node-addon-api": "' + NodeApiVersion + '",'],
|
||||
[/[ ]*"nan": *"[^"]+"(,|)[\n\r]/g, '']
|
||||
],
|
||||
'binding.gyp': [
|
||||
[/([ ]*)'include_dirs': \[/g, '$1\'include_dirs\': [\n$1 \'<!(node -p "require(\\\'node-addon-api\\\').include_dir")\','],
|
||||
[/([ ]*)"include_dirs": \[/g, '$1"include_dirs": [\n$1 "<!(node -p \'require(\\"node-addon-api\\").include_dir\')",'],
|
||||
[/[ ]*("|')<!\(node -e ("|'|\\"|\\')require\(("|'|\\"|\\')nan("|'|\\"|\\')\)("|'|\\"|\\')\)("|')(,|)[\r\n]/g, ''],
|
||||
[/([ ]*)("|')target_name("|'): ("|')(.+?)("|'),/g, '$1$2target_name$2: $4$5$6,\n $2cflags!$2: [ $2-fno-exceptions$2 ],\n $2cflags_cc!$2: [ $2-fno-exceptions$2 ],\n $2defines$2: [ $2NAPI_DISABLE_CPP_EXCEPTIONS$2 ],\n $2conditions$2: [\n [\'OS=="win"\', { $2defines$2: [ $2_HAS_EXCEPTIONS=1$2 ] }]\n ]']
|
||||
]
|
||||
};
|
||||
}
|
||||
|
||||
const SourceFileOperations = [
|
||||
[/Nan::SetMethod\(target,[\s]*"(.*)"[\s]*,[\s]*([^)]+)\)/g, 'exports.Set(Napi::String::New(env, "$1"), Napi::Function::New(env, $2))'],
|
||||
|
||||
[/v8::Local<v8::FunctionTemplate>\s+(\w+)\s*=\s*Nan::New<FunctionTemplate>\([\w\d:]+\);(?:\w+->Reset\(\1\))?\s+\1->SetClassName\(Nan::String::New\("(\w+)"\)\);/g, 'Napi::Function $1 = DefineClass(env, "$2", {'],
|
||||
[/Local<FunctionTemplate>\s+(\w+)\s*=\s*Nan::New<FunctionTemplate>\([\w\d:]+\);\s+(\w+)\.Reset\((\1)\);\s+\1->SetClassName\((Nan::String::New|Nan::New<(v8::)*String>)\("(.+?)"\)\);/g, 'Napi::Function $1 = DefineClass(env, "$6", {'],
|
||||
[/Local<FunctionTemplate>\s+(\w+)\s*=\s*Nan::New<FunctionTemplate>\([\w\d:]+\);(?:\w+->Reset\(\1\))?\s+\1->SetClassName\(Nan::String::New\("(\w+)"\)\);/g, 'Napi::Function $1 = DefineClass(env, "$2", {'],
|
||||
[/Nan::New<v8::FunctionTemplate>\(([\w\d:]+)\)->GetFunction\(\)/g, 'Napi::Function::New(env, $1)'],
|
||||
[/Nan::New<FunctionTemplate>\(([\w\d:]+)\)->GetFunction()/g, 'Napi::Function::New(env, $1);'],
|
||||
[/Nan::New<v8::FunctionTemplate>\(([\w\d:]+)\)/g, 'Napi::Function::New(env, $1)'],
|
||||
[/Nan::New<FunctionTemplate>\(([\w\d:]+)\)/g, 'Napi::Function::New(env, $1)'],
|
||||
|
||||
// FunctionTemplate to FunctionReference
|
||||
[/Nan::Persistent<(v8::)*FunctionTemplate>/g, 'Napi::FunctionReference'],
|
||||
[/Nan::Persistent<(v8::)*Function>/g, 'Napi::FunctionReference'],
|
||||
[/v8::Local<v8::FunctionTemplate>/g, 'Napi::FunctionReference'],
|
||||
[/Local<FunctionTemplate>/g, 'Napi::FunctionReference'],
|
||||
[/v8::FunctionTemplate/g, 'Napi::FunctionReference'],
|
||||
[/FunctionTemplate/g, 'Napi::FunctionReference'],
|
||||
|
||||
[/([ ]*)Nan::SetPrototypeMethod\(\w+, "(\w+)", (\w+)\);/g, '$1InstanceMethod("$2", &$3),'],
|
||||
[/([ ]*)(?:\w+\.Reset\(\w+\);\s+)?\(target\)\.Set\("(\w+)",\s*Nan::GetFunction\((\w+)\)\);/gm,
|
||||
'});\n\n' +
|
||||
'$1constructor = Napi::Persistent($3);\n' +
|
||||
'$1constructor.SuppressDestruct();\n' +
|
||||
'$1target.Set("$2", $3);'],
|
||||
|
||||
// TODO: Other attribute combinations
|
||||
[/static_cast<PropertyAttribute>\(ReadOnly\s*\|\s*DontDelete\)/gm,
|
||||
'static_cast<napi_property_attributes>(napi_enumerable | napi_configurable)'],
|
||||
|
||||
[/([\w\d:<>]+?)::Cast\((.+?)\)/g, '$2.As<$1>()'],
|
||||
|
||||
[/\*Nan::Utf8String\(([^)]+)\)/g, '$1->As<Napi::String>().Utf8Value().c_str()'],
|
||||
[/Nan::Utf8String +(\w+)\(([^)]+)\)/g, 'std::string $1 = $2.As<Napi::String>()'],
|
||||
[/Nan::Utf8String/g, 'std::string'],
|
||||
|
||||
[/v8::String::Utf8Value (.+?)\((.+?)\)/g, 'Napi::String $1(env, $2)'],
|
||||
[/String::Utf8Value (.+?)\((.+?)\)/g, 'Napi::String $1(env, $2)'],
|
||||
[/\.length\(\)/g, '.Length()'],
|
||||
|
||||
[/Nan::MakeCallback\(([^,]+),[\s\\]+([^,]+),/gm, '$2.MakeCallback($1,'],
|
||||
|
||||
[/class\s+(\w+)\s*:\s*public\s+Nan::ObjectWrap/g, 'class $1 : public Napi::ObjectWrap<$1>'],
|
||||
[/(\w+)\(([^)]*)\)\s*:\s*Nan::ObjectWrap\(\)\s*(,)?/gm, '$1($2) : Napi::ObjectWrap<$1>()$3'],
|
||||
|
||||
// HandleOKCallback to OnOK
|
||||
[/HandleOKCallback/g, 'OnOK'],
|
||||
// HandleErrorCallback to OnError
|
||||
[/HandleErrorCallback/g, 'OnError'],
|
||||
|
||||
// ex. .As<Function>() to .As<Napi::Object>()
|
||||
[/\.As<v8::(Value|Boolean|String|Number|Object|Array|Symbol|External|Function)>\(\)/g, '.As<Napi::$1>()'],
|
||||
[/\.As<(Value|Boolean|String|Number|Object|Array|Symbol|External|Function)>\(\)/g, '.As<Napi::$1>()'],
|
||||
|
||||
// ex. Nan::New<Number>(info[0]) to Napi::Number::New(info[0])
|
||||
[/Nan::New<(v8::)*Integer>\((.+?)\)/g, 'Napi::Number::New(env, $2)'],
|
||||
[/Nan::New\(([0-9.]+)\)/g, 'Napi::Number::New(env, $1)'],
|
||||
[/Nan::New<(v8::)*String>\("(.+?)"\)/g, 'Napi::String::New(env, "$2")'],
|
||||
[/Nan::New\("(.+?)"\)/g, 'Napi::String::New(env, "$1")'],
|
||||
[/Nan::New<(v8::)*(.+?)>\(\)/g, 'Napi::$2::New(env)'],
|
||||
[/Nan::New<(.+?)>\(\)/g, 'Napi::$1::New(env)'],
|
||||
[/Nan::New<(v8::)*(.+?)>\(/g, 'Napi::$2::New(env, '],
|
||||
[/Nan::New<(.+?)>\(/g, 'Napi::$1::New(env, '],
|
||||
[/Nan::NewBuffer\(/g, 'Napi::Buffer<char>::New(env, '],
|
||||
// TODO: Properly handle this
|
||||
[/Nan::New\(/g, 'Napi::New(env, '],
|
||||
|
||||
[/\.IsInt32\(\)/g, '.IsNumber()'],
|
||||
[/->IsInt32\(\)/g, '.IsNumber()'],
|
||||
|
||||
[/(.+?)->BooleanValue\(\)/g, '$1.As<Napi::Boolean>().Value()'],
|
||||
[/(.+?)->Int32Value\(\)/g, '$1.As<Napi::Number>().Int32Value()'],
|
||||
[/(.+?)->Uint32Value\(\)/g, '$1.As<Napi::Number>().Uint32Value()'],
|
||||
[/(.+?)->IntegerValue\(\)/g, '$1.As<Napi::Number>().Int64Value()'],
|
||||
[/(.+?)->NumberValue\(\)/g, '$1.As<Napi::Number>().DoubleValue()'],
|
||||
|
||||
// ex. Nan::To<bool>(info[0]) to info[0].Value()
|
||||
[/Nan::To<v8::(Boolean|String|Number|Object|Array|Symbol|Function)>\((.+?)\)/g, '$2.To<Napi::$1>()'],
|
||||
[/Nan::To<(Boolean|String|Number|Object|Array|Symbol|Function)>\((.+?)\)/g, '$2.To<Napi::$1>()'],
|
||||
// ex. Nan::To<bool>(info[0]) to info[0].As<Napi::Boolean>().Value()
|
||||
[/Nan::To<bool>\((.+?)\)/g, '$1.As<Napi::Boolean>().Value()'],
|
||||
// ex. Nan::To<int>(info[0]) to info[0].As<Napi::Number>().Int32Value()
|
||||
[/Nan::To<int>\((.+?)\)/g, '$1.As<Napi::Number>().Int32Value()'],
|
||||
// ex. Nan::To<int32_t>(info[0]) to info[0].As<Napi::Number>().Int32Value()
|
||||
[/Nan::To<int32_t>\((.+?)\)/g, '$1.As<Napi::Number>().Int32Value()'],
|
||||
// ex. Nan::To<uint32_t>(info[0]) to info[0].As<Napi::Number>().Uint32Value()
|
||||
[/Nan::To<uint32_t>\((.+?)\)/g, '$1.As<Napi::Number>().Uint32Value()'],
|
||||
// ex. Nan::To<int64_t>(info[0]) to info[0].As<Napi::Number>().Int64Value()
|
||||
[/Nan::To<int64_t>\((.+?)\)/g, '$1.As<Napi::Number>().Int64Value()'],
|
||||
// ex. Nan::To<float>(info[0]) to info[0].As<Napi::Number>().FloatValue()
|
||||
[/Nan::To<float>\((.+?)\)/g, '$1.As<Napi::Number>().FloatValue()'],
|
||||
// ex. Nan::To<double>(info[0]) to info[0].As<Napi::Number>().DoubleValue()
|
||||
[/Nan::To<double>\((.+?)\)/g, '$1.As<Napi::Number>().DoubleValue()'],
|
||||
|
||||
[/Nan::New\((\w+)\)->HasInstance\((\w+)\)/g, '$2.InstanceOf($1.Value())'],
|
||||
|
||||
[/Nan::Has\(([^,]+),\s*/gm, '($1).Has('],
|
||||
[/\.Has\([\s|\\]*Nan::New<(v8::)*String>\(([^)]+)\)\)/gm, '.Has($1)'],
|
||||
[/\.Has\([\s|\\]*Nan::New\(([^)]+)\)\)/gm, '.Has($1)'],
|
||||
|
||||
[/Nan::Get\(([^,]+),\s*/gm, '($1).Get('],
|
||||
[/\.Get\([\s|\\]*Nan::New<(v8::)*String>\(([^)]+)\)\)/gm, '.Get($1)'],
|
||||
[/\.Get\([\s|\\]*Nan::New\(([^)]+)\)\)/gm, '.Get($1)'],
|
||||
|
||||
[/Nan::Set\(([^,]+),\s*/gm, '($1).Set('],
|
||||
[/\.Set\([\s|\\]*Nan::New<(v8::)*String>\(([^)]+)\)\s*,/gm, '.Set($1,'],
|
||||
[/\.Set\([\s|\\]*Nan::New\(([^)]+)\)\s*,/gm, '.Set($1,'],
|
||||
|
||||
// ex. node::Buffer::HasInstance(info[0]) to info[0].IsBuffer()
|
||||
[/node::Buffer::HasInstance\((.+?)\)/g, '$1.IsBuffer()'],
|
||||
// ex. node::Buffer::Length(info[0]) to info[0].Length()
|
||||
[/node::Buffer::Length\((.+?)\)/g, '$1.As<Napi::Buffer<char>>().Length()'],
|
||||
// ex. node::Buffer::Data(info[0]) to info[0].Data()
|
||||
[/node::Buffer::Data\((.+?)\)/g, '$1.As<Napi::Buffer<char>>().Data()'],
|
||||
[/Nan::CopyBuffer\(/g, 'Napi::Buffer::Copy(env, '],
|
||||
|
||||
// Nan::AsyncQueueWorker(worker)
|
||||
[/Nan::AsyncQueueWorker\((.+)\);/g, '$1.Queue();'],
|
||||
[/Nan::(Undefined|Null|True|False)\(\)/g, 'env.$1()'],
|
||||
|
||||
// Nan::ThrowError(error) to Napi::Error::New(env, error).ThrowAsJavaScriptException()
|
||||
[/([ ]*)return Nan::Throw(\w*?)Error\((.+?)\);/g, '$1Napi::$2Error::New(env, $3).ThrowAsJavaScriptException();\n$1return env.Null();'],
|
||||
[/Nan::Throw(\w*?)Error\((.+?)\);\n(\s*)return;/g, 'Napi::$1Error::New(env, $2).ThrowAsJavaScriptException();\n$3return env.Null();'],
|
||||
[/Nan::Throw(\w*?)Error\((.+?)\);/g, 'Napi::$1Error::New(env, $2).ThrowAsJavaScriptException();\n'],
|
||||
// Nan::RangeError(error) to Napi::RangeError::New(env, error)
|
||||
[/Nan::(\w*?)Error\((.+)\)/g, 'Napi::$1Error::New(env, $2)'],
|
||||
|
||||
[/Nan::Set\((.+?),\n* *(.+?),\n* *(.+?),\n* *(.+?)\)/g, '$1.Set($2, $3, $4)'],
|
||||
|
||||
[/Nan::(Escapable)?HandleScope\s+(\w+)\s*;/g, 'Napi::$1HandleScope $2(env);'],
|
||||
[/Nan::(Escapable)?HandleScope/g, 'Napi::$1HandleScope'],
|
||||
[/Nan::ForceSet\(([^,]+), ?/g, '$1->DefineProperty('],
|
||||
[/\.ForceSet\(Napi::String::New\(env, "(\w+)"\),\s*?/g, '.DefineProperty("$1", '],
|
||||
// [ /Nan::GetPropertyNames\(([^,]+)\)/, '$1->GetPropertyNames()' ],
|
||||
[/Nan::Equals\(([^,]+),/g, '$1.StrictEquals('],
|
||||
|
||||
[/(.+)->Set\(/g, '$1.Set('],
|
||||
|
||||
[/Nan::Callback/g, 'Napi::FunctionReference'],
|
||||
|
||||
[/Nan::Persistent<Object>/g, 'Napi::ObjectReference'],
|
||||
[/Nan::ADDON_REGISTER_FUNCTION_ARGS_TYPE target/g, 'Napi::Env& env, Napi::Object& target'],
|
||||
|
||||
[/(\w+)\*\s+(\w+)\s*=\s*Nan::ObjectWrap::Unwrap<\w+>\(info\.This\(\)\);/g, '$1* $2 = this;'],
|
||||
[/Nan::ObjectWrap::Unwrap<(\w+)>\((.*)\);/g, '$2.Unwrap<$1>();'],
|
||||
|
||||
[/Nan::NAN_METHOD_RETURN_TYPE/g, 'void'],
|
||||
[/NAN_INLINE/g, 'inline'],
|
||||
|
||||
[/Nan::NAN_METHOD_ARGS_TYPE/g, 'const Napi::CallbackInfo&'],
|
||||
[/NAN_METHOD\(([\w\d:]+?)\)/g, 'Napi::Value $1(const Napi::CallbackInfo& info)'],
|
||||
[/static\s*NAN_GETTER\(([\w\d:]+?)\)/g, 'Napi::Value $1(const Napi::CallbackInfo& info)'],
|
||||
[/NAN_GETTER\(([\w\d:]+?)\)/g, 'Napi::Value $1(const Napi::CallbackInfo& info)'],
|
||||
[/static\s*NAN_SETTER\(([\w\d:]+?)\)/g, 'void $1(const Napi::CallbackInfo& info, const Napi::Value& value)'],
|
||||
[/NAN_SETTER\(([\w\d:]+?)\)/g, 'void $1(const Napi::CallbackInfo& info, const Napi::Value& value)'],
|
||||
[/void Init\((v8::)*Local<(v8::)*Object> exports\)/g, 'Napi::Object Init(Napi::Env env, Napi::Object exports)'],
|
||||
[/NAN_MODULE_INIT\(([\w\d:]+?)\);/g, 'Napi::Object $1(Napi::Env env, Napi::Object exports);'],
|
||||
[/NAN_MODULE_INIT\(([\w\d:]+?)\)/g, 'Napi::Object $1(Napi::Env env, Napi::Object exports)'],
|
||||
|
||||
[/::(Init(?:ialize)?)\(target\)/g, '::$1(env, target, module)'],
|
||||
[/constructor_template/g, 'constructor'],
|
||||
|
||||
[/Nan::FunctionCallbackInfo<(v8::)?Value>[ ]*& [ ]*info\)[ ]*{\n*([ ]*)/gm, 'Napi::CallbackInfo& info) {\n$2Napi::Env env = info.Env();\n$2'],
|
||||
[/Nan::FunctionCallbackInfo<(v8::)*Value>\s*&\s*info\);/g, 'Napi::CallbackInfo& info);'],
|
||||
[/Nan::FunctionCallbackInfo<(v8::)*Value>\s*&/g, 'Napi::CallbackInfo&'],
|
||||
|
||||
[/Buffer::HasInstance\(([^)]+)\)/g, '$1.IsBuffer()'],
|
||||
|
||||
[/info\[(\d+)\]->/g, 'info[$1].'],
|
||||
[/info\[([\w\d]+)\]->/g, 'info[$1].'],
|
||||
[/info\.This\(\)->/g, 'info.This().'],
|
||||
[/->Is(Object|String|Int32|Number)\(\)/g, '.Is$1()'],
|
||||
[/info.GetReturnValue\(\).SetUndefined\(\)/g, 'return env.Undefined()'],
|
||||
[/info\.GetReturnValue\(\)\.Set\(((\n|.)+?)\);/g, 'return $1;'],
|
||||
|
||||
// ex. Local<Value> to Napi::Value
|
||||
[/v8::Local<v8::(Value|Boolean|String|Number|Object|Array|Symbol|External|Function)>/g, 'Napi::$1'],
|
||||
[/Local<(Value|Boolean|String|Number|Object|Array|Symbol|External|Function)>/g, 'Napi::$1'],
|
||||
|
||||
// Declare an env in helper functions that take a Napi::Value
|
||||
[/(\w+)\(Napi::Value (\w+)(,\s*[^()]+)?\)\s*{\n*([ ]*)/gm, '$1(Napi::Value $2$3) {\n$4Napi::Env env = $2.Env();\n$4'],
|
||||
|
||||
// delete #include <node.h> and/or <v8.h>
|
||||
[/#include +(<|")(?:node|nan).h("|>)/g, '#include $1napi.h$2\n#include $1uv.h$2'],
|
||||
// NODE_MODULE to NODE_API_MODULE
|
||||
[/NODE_MODULE/g, 'NODE_API_MODULE'],
|
||||
[/Nan::/g, 'Napi::'],
|
||||
[/nan.h/g, 'napi.h'],
|
||||
|
||||
// delete .FromJust()
|
||||
[/\.FromJust\(\)/g, ''],
|
||||
// delete .ToLocalCheck()
|
||||
[/\.ToLocalChecked\(\)/g, ''],
|
||||
[/^.*->SetInternalFieldCount\(.*$/gm, ''],
|
||||
|
||||
// replace using node; and/or using v8; to using Napi;
|
||||
[/using (node|v8);/g, 'using Napi;'],
|
||||
[/using namespace (node|Nan|v8);/g, 'using namespace Napi;'],
|
||||
// delete using v8::Local;
|
||||
[/using v8::Local;\n/g, ''],
|
||||
// replace using v8::XXX; with using Napi::XXX
|
||||
[/using v8::([A-Za-z]+);/g, 'using Napi::$1;']
|
||||
|
||||
];
|
||||
|
||||
const paths = listFiles(dir);
|
||||
paths.forEach(function (dirEntry) {
|
||||
const filename = dirEntry.split('\\').pop().split('/').pop();
|
||||
|
||||
// Check whether the file is a source file or a config file
|
||||
// then execute function accordingly
|
||||
const sourcePattern = /.+\.h|.+\.cc|.+\.cpp/;
|
||||
if (sourcePattern.test(filename)) {
|
||||
convertFile(dirEntry, SourceFileOperations);
|
||||
} else if (ConfigFileOperations[filename] != null) {
|
||||
convertFile(dirEntry, ConfigFileOperations[filename]);
|
||||
}
|
||||
});
|
||||
|
||||
function listFiles (dir, filelist) {
|
||||
const files = fs.readdirSync(dir);
|
||||
filelist = filelist || [];
|
||||
files.forEach(function (file) {
|
||||
if (file === 'node_modules') {
|
||||
return;
|
||||
}
|
||||
|
||||
if (fs.statSync(path.join(dir, file)).isDirectory()) {
|
||||
filelist = listFiles(path.join(dir, file), filelist);
|
||||
} else {
|
||||
filelist.push(path.join(dir, file));
|
||||
}
|
||||
});
|
||||
return filelist;
|
||||
}
|
||||
|
||||
function convert (content, operations) {
|
||||
for (let i = 0; i < operations.length; i++) {
|
||||
const operation = operations[i];
|
||||
content = content.replace(operation[0], operation[1]);
|
||||
}
|
||||
return content;
|
||||
}
|
||||
|
||||
function convertFile (fileName, operations) {
|
||||
fs.readFile(fileName, 'utf-8', function (err, file) {
|
||||
if (err) throw err;
|
||||
|
||||
file = convert(file, operations);
|
||||
|
||||
fs.writeFile(fileName, file, function (err) {
|
||||
if (err) throw err;
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user