@eslint-react/ast 5.30.0-beta.15 → 5.30.0-beta.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +5 -38
- package/dist/index.js +4 -55
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -28,7 +28,7 @@ type TSESTreeTypeExpression = TSESTree.TSAsExpression | TSESTree.TSInstantiation
|
|
|
28
28
|
/** Union of expression node types that wrap another expression (TypeScript type expressions and chain expressions) — the nodes `Extract.unwrap` strips. */
|
|
29
29
|
type TSESTreeTypeOrChainExpression = TSESTree.ChainExpression | TSESTreeTypeExpression;
|
|
30
30
|
declare namespace check_d_exports {
|
|
31
|
-
export { is, isArrayPatternElementDefault, isCallExpression, isClass,
|
|
31
|
+
export { is, isArrayPatternElementDefault, isCallExpression, isClass, isConditionalOrLoop, isDirective, isExpression, isFunction, isFunctionOrClass, isIdentifier, isJSX, isJSXElement, isJSXElementOrFragment, isJSXExpressionContainer, isJSXFragment, isJSXSpreadAttribute, isJSXTagNameExpression, isLoopStatement, isMemberExpression, isObjectExpression, isObjectPatternElementDefault, isOneOf, isProperty, isPropertyOrMethod, isReturnStatement, isTypeAssertionExpression, isTypeExpression, isTypeOrChainExpression };
|
|
32
32
|
}
|
|
33
33
|
/** Check if a node is of the given type. */
|
|
34
34
|
declare const is: <NodeType extends AST_NODE_TYPES>(nodeType: NodeType) => (node: TSESTree.Node | null | undefined) => node is Extract<TSESTree.Node, {
|
|
@@ -67,8 +67,8 @@ declare const isLoopStatement: (node: TSESTree.Node | null | undefined) => node
|
|
|
67
67
|
declare const isReturnStatement: (node: TSESTree.Node | null | undefined) => node is TSESTree.ReturnStatement;
|
|
68
68
|
/** Check if a node is a class declaration or class expression. */
|
|
69
69
|
declare const isClass: (node: TSESTree.Node | null | undefined) => node is TSESTree.ClassDeclarationWithName | TSESTree.ClassDeclarationWithOptionalName | TSESTree.ClassExpression;
|
|
70
|
-
/** Check if a node is a conditional or logical expression, or a
|
|
71
|
-
declare const
|
|
70
|
+
/** Check if a node is a conditional or logical expression, a conditional statement, or a loop statement. */
|
|
71
|
+
declare const isConditionalOrLoop: (node: TSESTree.Node | null | undefined) => node is TSESTree.ConditionalExpression | TSESTree.DoWhileStatement | TSESTree.ForInStatement | TSESTree.ForOfStatement | TSESTree.ForStatement | TSESTree.IfStatement | TSESTree.LogicalExpression | TSESTree.SwitchStatement | TSESTree.WhileStatement;
|
|
72
72
|
/** Check if a node is a function declaration, function expression, or arrow function expression. */
|
|
73
73
|
declare const isFunction: (node: TSESTree.Node | null | undefined) => node is TSESTree.ArrowFunctionExpressionWithBlockBody | TSESTree.ArrowFunctionExpressionWithExpressionBody | TSESTree.FunctionDeclarationWithName | TSESTree.FunctionDeclarationWithOptionalName | TSESTree.FunctionExpression;
|
|
74
74
|
/** Check if a node is a function declaration, function expression, arrow function expression, class declaration, or class expression. */
|
|
@@ -128,7 +128,7 @@ declare namespace compare_d_exports {
|
|
|
128
128
|
/**
|
|
129
129
|
* Check if two nodes are structurally equal.
|
|
130
130
|
*
|
|
131
|
-
* - Supports identifiers, literals, template literals/elements, member/call/chain expressions, JSX identifiers/namespaced names/member expressions/attributes, and `this`.
|
|
131
|
+
* - Supports identifiers, private identifiers, literals, template literals/elements, member/call/chain expressions, JSX identifiers/namespaced names/member expressions/attributes, and `this`.
|
|
132
132
|
* - Node types outside that list (including functions and classes) are equal only when they are the same node.
|
|
133
133
|
* - Compares chain expressions through their inner expression, so optional segments remain significant (`a?.b` equals `a?.b` but not `a.b`).
|
|
134
134
|
* - Compares literals by value and regex literals by `pattern` and `flags`.
|
|
@@ -198,7 +198,7 @@ declare function getReturnStatements(node: TSESTree.Node): readonly TSESTree.Ret
|
|
|
198
198
|
*/
|
|
199
199
|
declare function getReturnExpressions(node: TSESTreeFunction): readonly TSESTree.Expression[];
|
|
200
200
|
declare namespace extract_d_exports {
|
|
201
|
-
export {
|
|
201
|
+
export { getCalleeName, getFullyQualifiedName, getJSXName, unwrap };
|
|
202
202
|
}
|
|
203
203
|
/**
|
|
204
204
|
* Recursively unwrap TypeScript type expressions and chain expressions to get the underlying expression.
|
|
@@ -226,39 +226,6 @@ declare function getFullyQualifiedName(node: TSESTree.Node, getText: (node: TSES
|
|
|
226
226
|
* @returns The callee name (ex: `"useState"`), or `null` for computed member expressions and other unsupported callee forms.
|
|
227
227
|
*/
|
|
228
228
|
declare function getCalleeName(node: TSESTree.CallExpression): string | null;
|
|
229
|
-
/**
|
|
230
|
-
* Get the member chain of an expression (ex: `[a, b, c]` for `a.b.c`), starting from the base object.
|
|
231
|
-
* Type expressions and chain expressions are unwrapped along the way.
|
|
232
|
-
* @param node The expression to inspect.
|
|
233
|
-
* @returns The base node followed by each member property in access order.
|
|
234
|
-
*/
|
|
235
|
-
declare function getMemberChain(node: TSESTree.Expression | TSESTree.PrivateIdentifier): (TSESTree.AccessorProperty | TSESTree.ArrayExpression | TSESTree.ArrayPattern | TSESTree.ArrowFunctionExpression | TSESTree.AssignmentExpression | TSESTree.AssignmentPattern | TSESTree.AwaitExpression | TSESTree.BinaryExpression | TSESTree.BlockStatement | TSESTree.BreakStatement | TSESTree.CallExpression | TSESTree.CatchClause | TSESTree.ClassBody | TSESTree.ClassDeclaration | TSESTree.ClassExpression | TSESTree.ConditionalExpression | TSESTree.ContinueStatement | TSESTree.DebuggerStatement | TSESTree.Decorator | TSESTree.DoWhileStatement | TSESTree.EmptyStatement | TSESTree.ExportAllDeclaration | TSESTree.ExportDefaultDeclaration | TSESTree.ExportNamedDeclaration | TSESTree.ExportSpecifier | TSESTree.ExpressionStatement | TSESTree.ForInStatement | TSESTree.ForOfStatement | TSESTree.ForStatement | TSESTree.FunctionDeclaration | TSESTree.FunctionExpression | TSESTree.Identifier | TSESTree.IfStatement | TSESTree.ImportAttribute | TSESTree.ImportDeclaration | TSESTree.ImportDefaultSpecifier | TSESTree.ImportExpression | TSESTree.ImportNamespaceSpecifier | TSESTree.ImportSpecifier | TSESTree.JSXAttribute | TSESTree.JSXClosingElement | TSESTree.JSXClosingFragment | TSESTree.JSXElement | TSESTree.JSXEmptyExpression | TSESTree.JSXExpressionContainer | TSESTree.JSXFragment | TSESTree.JSXIdentifier | TSESTree.JSXMemberExpression | TSESTree.JSXNamespacedName | TSESTree.JSXOpeningElement | TSESTree.JSXOpeningFragment | TSESTree.JSXSpreadAttribute | TSESTree.JSXSpreadChild | TSESTree.JSXText | TSESTree.LabeledStatement | TSESTree.Literal | TSESTree.LogicalExpression | TSESTree.MemberExpression | TSESTree.MetaProperty | TSESTree.MethodDefinition | TSESTree.NewExpression | TSESTree.ObjectExpression | TSESTree.ObjectPattern | TSESTree.PrivateIdentifier | TSESTree.Program | TSESTree.Property | TSESTree.PropertyDefinition | TSESTree.RestElement | TSESTree.ReturnStatement | TSESTree.SequenceExpression | TSESTree.SpreadElement | TSESTree.StaticBlock | TSESTree.Super | TSESTree.SwitchCase | TSESTree.SwitchStatement | TSESTree.TaggedTemplateExpression | TSESTree.TemplateElement | TSESTree.TemplateLiteral | TSESTree.ThisExpression | TSESTree.ThrowStatement | TSESTree.TryStatement | TSESTree.TSAbstractAccessorProperty | TSESTree.TSAbstractKeyword | TSESTree.TSAbstractMethodDefinition | TSESTree.TSAbstractPropertyDefinition | TSESTree.TSAnyKeyword | TSESTree.TSArrayType | TSESTree.TSAsyncKeyword | TSESTree.TSBigIntKeyword | TSESTree.TSBooleanKeyword | TSESTree.TSCallSignatureDeclaration | TSESTree.TSClassImplements | TSESTree.TSConditionalType | TSESTree.TSConstructorType | TSESTree.TSConstructSignatureDeclaration | TSESTree.TSDeclareFunction | TSESTree.TSDeclareKeyword | TSESTree.TSEmptyBodyFunctionExpression | TSESTree.TSEnumBody | TSESTree.TSEnumDeclaration | TSESTree.TSEnumMember | TSESTree.TSExportAssignment | TSESTree.TSExportKeyword | TSESTree.TSExternalModuleReference | TSESTree.TSFunctionType | TSESTree.TSImportEqualsDeclaration | TSESTree.TSImportType | TSESTree.TSIndexedAccessType | TSESTree.TSIndexSignature | TSESTree.TSInferType | TSESTree.TSInterfaceBody | TSESTree.TSInterfaceDeclaration | TSESTree.TSInterfaceHeritage | TSESTree.TSIntersectionType | TSESTree.TSIntrinsicKeyword | TSESTree.TSLiteralType | TSESTree.TSMappedType | TSESTree.TSMethodSignature | TSESTree.TSModuleBlock | TSESTree.TSModuleDeclaration | TSESTree.TSNamedTupleMember | TSESTree.TSNamespaceExportDeclaration | TSESTree.TSNeverKeyword | TSESTree.TSNullKeyword | TSESTree.TSNumberKeyword | TSESTree.TSObjectKeyword | TSESTree.TSOptionalType | TSESTree.TSParameterProperty | TSESTree.TSPrivateKeyword | TSESTree.TSPropertySignature | TSESTree.TSProtectedKeyword | TSESTree.TSPublicKeyword | TSESTree.TSQualifiedName | TSESTree.TSReadonlyKeyword | TSESTree.TSRestType | TSESTree.TSStaticKeyword | TSESTree.TSStringKeyword | TSESTree.TSSymbolKeyword | TSESTree.TSTemplateLiteralType | TSESTree.TSThisType | TSESTree.TSTupleType | TSESTree.TSTypeAliasDeclaration | TSESTree.TSTypeAnnotation | TSESTree.TSTypeLiteral | TSESTree.TSTypeOperator | TSESTree.TSTypeParameter | TSESTree.TSTypeParameterDeclaration | TSESTree.TSTypeParameterInstantiation | TSESTree.TSTypePredicate | TSESTree.TSTypeQuery | TSESTree.TSTypeReference | TSESTree.TSUndefinedKeyword | TSESTree.TSUnionType | TSESTree.TSUnknownKeyword | TSESTree.TSVoidKeyword | TSESTree.UnaryExpression | TSESTree.UpdateExpression | TSESTree.VariableDeclaration | TSESTree.VariableDeclarator | TSESTree.WhileStatement | TSESTree.WithStatement | TSESTree.YieldExpression)[];
|
|
236
|
-
/**
|
|
237
|
-
* Get the static name of an object property's key.
|
|
238
|
-
* @param property The property to inspect.
|
|
239
|
-
* @param effort `"min"` only matches plain identifiers; `"max"` also resolves string literals and simple template literals.
|
|
240
|
-
* @returns The property name, or `null` when it cannot be statically determined.
|
|
241
|
-
*/
|
|
242
|
-
declare function getPropertyName(property: TSESTree.Property, effort?: "min" | "max"): string | null;
|
|
243
|
-
/**
|
|
244
|
-
* Find a property by name in a list of object literal properties, recursing into spread object expressions.
|
|
245
|
-
*
|
|
246
|
-
* Names are resolved with maximum effort: in addition to non-computed identifiers, string-literal keys
|
|
247
|
-
* (computed or not) and template literals without expressions are matched.
|
|
248
|
-
* @param properties The object literal properties to search.
|
|
249
|
-
* @param name The property name to look for.
|
|
250
|
-
* @returns The matching `Property` node, or `null` when not found.
|
|
251
|
-
*/
|
|
252
|
-
declare function findProperty(properties: TSESTree.ObjectLiteralElement[], name: string): TSESTree.Property | null;
|
|
253
|
-
/**
|
|
254
|
-
* Collect every write target of an assignment or loop target, expanding
|
|
255
|
-
* destructuring patterns such as `[local, globalValue] = source` or
|
|
256
|
-
* `({ a: obj.x } = source)`. Defaults (`{ a = source }`) are not targets;
|
|
257
|
-
* their left side is.
|
|
258
|
-
* @param node The assignment left side or for-in/of loop target to inspect. Declaration-form loop targets are not expanded and return an empty array.
|
|
259
|
-
* @returns The identifier and member expression targets being written.
|
|
260
|
-
*/
|
|
261
|
-
declare function getAssignmentTargets(node: TSESTree.Node): (TSESTree.Identifier | TSESTree.MemberExpression)[];
|
|
262
229
|
declare namespace analyze_d_exports {
|
|
263
230
|
export { isTerminatingStatement, isUnconditionallyTerminating };
|
|
264
231
|
}
|
package/dist/index.js
CHANGED
|
@@ -8,7 +8,7 @@ var check_exports = /* @__PURE__ */ __exportAll({
|
|
|
8
8
|
isArrayPatternElementDefault: () => isArrayPatternElementDefault,
|
|
9
9
|
isCallExpression: () => isCallExpression,
|
|
10
10
|
isClass: () => isClass,
|
|
11
|
-
|
|
11
|
+
isConditionalOrLoop: () => isConditionalOrLoop,
|
|
12
12
|
isDirective: () => isDirective,
|
|
13
13
|
isExpression: () => isExpression,
|
|
14
14
|
isFunction: () => isFunction$1,
|
|
@@ -90,7 +90,7 @@ const isLoopStatement = isOneOf([
|
|
|
90
90
|
]);
|
|
91
91
|
const isReturnStatement = is(AST_NODE_TYPES.ReturnStatement);
|
|
92
92
|
const isClass = isOneOf([AST_NODE_TYPES.ClassDeclaration, AST_NODE_TYPES.ClassExpression]);
|
|
93
|
-
const
|
|
93
|
+
const isConditionalOrLoop = isOneOf([
|
|
94
94
|
AST_NODE_TYPES.IfStatement,
|
|
95
95
|
AST_NODE_TYPES.LogicalExpression,
|
|
96
96
|
AST_NODE_TYPES.ConditionalExpression,
|
|
@@ -244,9 +244,6 @@ dual(2, (a, b) => (data) => a(data) === b(data));
|
|
|
244
244
|
dual(2, (antecedent, consequent) => (data) => !antecedent(data) || consequent(data));
|
|
245
245
|
dual(2, (a, b) => (data) => !a(data) && !b(data));
|
|
246
246
|
dual(2, (a, b) => (data) => !a(data) || !b(data));
|
|
247
|
-
function isString(input) {
|
|
248
|
-
return typeof input === "string";
|
|
249
|
-
}
|
|
250
247
|
function isFunction(input) {
|
|
251
248
|
return typeof input === "function";
|
|
252
249
|
}
|
|
@@ -270,13 +267,9 @@ dual(2, (self, predicate) => {
|
|
|
270
267
|
});
|
|
271
268
|
// src/extract.ts
|
|
272
269
|
var extract_exports = /* @__PURE__ */ __exportAll({
|
|
273
|
-
findProperty: () => findProperty,
|
|
274
|
-
getAssignmentTargets: () => getAssignmentTargets,
|
|
275
270
|
getCalleeName: () => getCalleeName,
|
|
276
271
|
getFullyQualifiedName: () => getFullyQualifiedName,
|
|
277
272
|
getJSXName: () => getJSXName,
|
|
278
|
-
getMemberChain: () => getMemberChain,
|
|
279
|
-
getPropertyName: () => getPropertyName,
|
|
280
273
|
unwrap: () => unwrap
|
|
281
274
|
});
|
|
282
275
|
function unwrap(node) {
|
|
@@ -293,8 +286,8 @@ function getJSXName(node) {
|
|
|
293
286
|
function getFullyQualifiedName(node, getText) {
|
|
294
287
|
const expr = unwrap(node);
|
|
295
288
|
switch (expr.type) {
|
|
296
|
-
case AST_NODE_TYPES.Identifier:
|
|
297
|
-
case AST_NODE_TYPES.PrivateIdentifier: return expr.name
|
|
289
|
+
case AST_NODE_TYPES.Identifier: return expr.name;
|
|
290
|
+
case AST_NODE_TYPES.PrivateIdentifier: return `#${expr.name}`;
|
|
298
291
|
case AST_NODE_TYPES.JSXIdentifier:
|
|
299
292
|
case AST_NODE_TYPES.JSXMemberExpression:
|
|
300
293
|
case AST_NODE_TYPES.JSXNamespacedName: return getJSXName(expr);
|
|
@@ -312,50 +305,6 @@ function getCalleeName(node) {
|
|
|
312
305
|
if (callee.type === AST_NODE_TYPES.MemberExpression && !callee.computed && isIdentifier(callee.property)) return callee.property.name;
|
|
313
306
|
return null;
|
|
314
307
|
}
|
|
315
|
-
function getMemberChain(node) {
|
|
316
|
-
const members = [];
|
|
317
|
-
let current = unwrap(node);
|
|
318
|
-
while (current.type === AST_NODE_TYPES.MemberExpression) {
|
|
319
|
-
const property = unwrap(current.property);
|
|
320
|
-
members.unshift(property);
|
|
321
|
-
current = unwrap(current.object);
|
|
322
|
-
}
|
|
323
|
-
members.unshift(current);
|
|
324
|
-
return members;
|
|
325
|
-
}
|
|
326
|
-
function getPropertyName(property, effort = "min") {
|
|
327
|
-
const key = unwrap(property.key);
|
|
328
|
-
if (isIdentifier(key) && !property.computed) return key.name;
|
|
329
|
-
if (effort === "min") return null;
|
|
330
|
-
if (key.type === AST_NODE_TYPES.Literal && isString(key.value)) return key.value;
|
|
331
|
-
if (key.type === AST_NODE_TYPES.TemplateLiteral && key.expressions.length === 0) return key.quasis[0]?.value.cooked ?? key.quasis[0]?.value.raw ?? null;
|
|
332
|
-
return null;
|
|
333
|
-
}
|
|
334
|
-
function findProperty(properties, name) {
|
|
335
|
-
for (const property of properties) {
|
|
336
|
-
if (property.type === AST_NODE_TYPES.Property && getPropertyName(property, "max") === name) return property;
|
|
337
|
-
if (property.type === AST_NODE_TYPES.SpreadElement && property.argument.type === AST_NODE_TYPES.ObjectExpression) {
|
|
338
|
-
const found = findProperty(property.argument.properties, name);
|
|
339
|
-
if (found != null) return found;
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
return null;
|
|
343
|
-
}
|
|
344
|
-
function getAssignmentTargets(node) {
|
|
345
|
-
const target = unwrap(node);
|
|
346
|
-
switch (target.type) {
|
|
347
|
-
case AST_NODE_TYPES.Identifier:
|
|
348
|
-
case AST_NODE_TYPES.MemberExpression: return [target];
|
|
349
|
-
case AST_NODE_TYPES.ArrayPattern: return target.elements.flatMap((element) => element == null ? [] : getAssignmentTargets(element));
|
|
350
|
-
case AST_NODE_TYPES.AssignmentPattern: return getAssignmentTargets(target.left);
|
|
351
|
-
case AST_NODE_TYPES.ObjectPattern: return target.properties.flatMap((property) => {
|
|
352
|
-
if (property.type === AST_NODE_TYPES.RestElement) return getAssignmentTargets(property.argument);
|
|
353
|
-
return getAssignmentTargets(property.value);
|
|
354
|
-
});
|
|
355
|
-
case AST_NODE_TYPES.RestElement: return getAssignmentTargets(target.argument);
|
|
356
|
-
default: return [];
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
308
|
// src/compare.ts
|
|
360
309
|
var compare_exports = /* @__PURE__ */ __exportAll({ isEqual: () => isEqual });
|
|
361
310
|
const isEqual = dual(2, (a, b) => {
|