@eslint-react/jsx 1.5.11-next.10 → 1.5.11-next.12
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.mts +1 -11
- package/dist/index.d.ts +1 -11
- package/dist/index.js +77 -87
- package/dist/index.mjs +79 -88
- package/package.json +6 -6
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { TSESTree } from '@typescript-eslint/types';
|
|
2
|
-
import { TSESTreeFunction } from '@eslint-react/ast';
|
|
3
2
|
import { RuleContext } from '@eslint-react/types';
|
|
4
3
|
import { Option } from 'effect';
|
|
5
4
|
import { Scope } from '@typescript-eslint/scope-manager';
|
|
@@ -25,15 +24,6 @@ declare function isJSXElementOfUserDefinedComponent(node: TSESTree.JSXElement):
|
|
|
25
24
|
*/
|
|
26
25
|
declare function isJSXElementOfBuiltinComponent(node: TSESTree.JSXElement): boolean;
|
|
27
26
|
|
|
28
|
-
/**
|
|
29
|
-
* Check if function is returning JSX
|
|
30
|
-
* @param node The return statement node to check
|
|
31
|
-
* @param context The rule context
|
|
32
|
-
* @param hint The `JSXValueHint` to use
|
|
33
|
-
* @returns boolean
|
|
34
|
-
*/
|
|
35
|
-
declare function isFunctionReturningJSXValue(node: TSESTreeFunction, context: RuleContext, hint?: bigint): boolean;
|
|
36
|
-
|
|
37
27
|
declare function getJSXPragmaFromContext(context: RuleContext): Option.Option<string>;
|
|
38
28
|
|
|
39
29
|
/**
|
|
@@ -160,4 +150,4 @@ declare const DEFAULT_JSX_VALUE_HINT: bigint;
|
|
|
160
150
|
*/
|
|
161
151
|
declare function isJSXValue(node: TSESTree$1.Node | null | undefined, context: RuleContext, hint?: bigint): boolean;
|
|
162
152
|
|
|
163
|
-
export { DEFAULT_JSX_VALUE_HINT, JSXValueHint, elementType, findPropInAttributes, findPropInProperties, getJSXPragmaFromContext, getProp, getPropName, getPropValue, hasAnyProp, hasEveryProp, hasProp,
|
|
153
|
+
export { DEFAULT_JSX_VALUE_HINT, JSXValueHint, elementType, findPropInAttributes, findPropInProperties, getJSXPragmaFromContext, getProp, getPropName, getPropValue, hasAnyProp, hasEveryProp, hasProp, isInsidePropValue, isJSXElementOfBuiltinComponent, isJSXElementOfUserDefinedComponent, isJSXValue, isLineBreak, isLiteral, isPaddingSpaces, isWhiteSpace, traverseUpProp };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { TSESTree } from '@typescript-eslint/types';
|
|
2
|
-
import { TSESTreeFunction } from '@eslint-react/ast';
|
|
3
2
|
import { RuleContext } from '@eslint-react/types';
|
|
4
3
|
import { Option } from 'effect';
|
|
5
4
|
import { Scope } from '@typescript-eslint/scope-manager';
|
|
@@ -25,15 +24,6 @@ declare function isJSXElementOfUserDefinedComponent(node: TSESTree.JSXElement):
|
|
|
25
24
|
*/
|
|
26
25
|
declare function isJSXElementOfBuiltinComponent(node: TSESTree.JSXElement): boolean;
|
|
27
26
|
|
|
28
|
-
/**
|
|
29
|
-
* Check if function is returning JSX
|
|
30
|
-
* @param node The return statement node to check
|
|
31
|
-
* @param context The rule context
|
|
32
|
-
* @param hint The `JSXValueHint` to use
|
|
33
|
-
* @returns boolean
|
|
34
|
-
*/
|
|
35
|
-
declare function isFunctionReturningJSXValue(node: TSESTreeFunction, context: RuleContext, hint?: bigint): boolean;
|
|
36
|
-
|
|
37
27
|
declare function getJSXPragmaFromContext(context: RuleContext): Option.Option<string>;
|
|
38
28
|
|
|
39
29
|
/**
|
|
@@ -160,4 +150,4 @@ declare const DEFAULT_JSX_VALUE_HINT: bigint;
|
|
|
160
150
|
*/
|
|
161
151
|
declare function isJSXValue(node: TSESTree$1.Node | null | undefined, context: RuleContext, hint?: bigint): boolean;
|
|
162
152
|
|
|
163
|
-
export { DEFAULT_JSX_VALUE_HINT, JSXValueHint, elementType, findPropInAttributes, findPropInProperties, getJSXPragmaFromContext, getProp, getPropName, getPropValue, hasAnyProp, hasEveryProp, hasProp,
|
|
153
|
+
export { DEFAULT_JSX_VALUE_HINT, JSXValueHint, elementType, findPropInAttributes, findPropInProperties, getJSXPragmaFromContext, getProp, getPropName, getPropValue, hasAnyProp, hasEveryProp, hasProp, isInsidePropValue, isJSXElementOfBuiltinComponent, isJSXElementOfUserDefinedComponent, isJSXValue, isLineBreak, isLiteral, isPaddingSpaces, isWhiteSpace, traverseUpProp };
|
package/dist/index.js
CHANGED
|
@@ -1992,6 +1992,19 @@ var mapAccum = /* @__PURE__ */ dual(3, (self, s2, f2) => {
|
|
|
1992
1992
|
var cartesianWith = /* @__PURE__ */ dual(3, (self, that, f2) => flatMap2(self, (a2) => map2(that, (b2) => f2(a2, b2))));
|
|
1993
1993
|
var cartesian = /* @__PURE__ */ dual(2, (self, that) => cartesianWith(self, that, (a2, b2) => [a2, b2]));
|
|
1994
1994
|
|
|
1995
|
+
// src/pragma.ts
|
|
1996
|
+
var RE_JSX_ANNOTATION_REGEX = /@jsx\s+(\S+)/u;
|
|
1997
|
+
var RE_JS_IDENTIFIER_REGEX = /^[$A-Z_a-z][\w$]*$/u;
|
|
1998
|
+
function getJSXPragmaFromContext(context) {
|
|
1999
|
+
const { sourceCode } = context;
|
|
2000
|
+
return Function_exports.pipe(
|
|
2001
|
+
Array_exports.findFirst(sourceCode.getAllComments(), (node) => RE_JSX_ANNOTATION_REGEX.test(node.value)),
|
|
2002
|
+
Option_exports.map(({ value }) => RE_JSX_ANNOTATION_REGEX.exec(value)),
|
|
2003
|
+
Option_exports.flatMapNullable((matches) => matches?.[1]),
|
|
2004
|
+
Option_exports.filter((pragma) => RE_JS_IDENTIFIER_REGEX.test(pragma))
|
|
2005
|
+
);
|
|
2006
|
+
}
|
|
2007
|
+
|
|
1995
2008
|
// ../../../node_modules/.pnpm/ts-pattern@5.1.1/node_modules/ts-pattern/dist/index.js
|
|
1996
2009
|
var t = Symbol.for("@ts-pattern/matcher");
|
|
1997
2010
|
var e = Symbol.for("@ts-pattern/isVariadic");
|
|
@@ -2267,92 +2280,7 @@ var z = class _z {
|
|
|
2267
2280
|
}
|
|
2268
2281
|
};
|
|
2269
2282
|
|
|
2270
|
-
// src/
|
|
2271
|
-
var JSXValueHint = {
|
|
2272
|
-
None: 0n,
|
|
2273
|
-
SkipNullLiteral: 1n << 0n,
|
|
2274
|
-
SkipUndefinedLiteral: 1n << 1n,
|
|
2275
|
-
SkipBooleanLiteral: 1n << 2n,
|
|
2276
|
-
SkipStringLiteral: 1n << 3n,
|
|
2277
|
-
SkipNumberLiteral: 1n << 4n,
|
|
2278
|
-
SkipCreateElement: 1n << 5n,
|
|
2279
|
-
StrictArray: 1n << 6n,
|
|
2280
|
-
StrictLogical: 1n << 7n,
|
|
2281
|
-
StrictConditional: 1n << 8n
|
|
2282
|
-
};
|
|
2283
|
-
var DEFAULT_JSX_VALUE_HINT = JSXValueHint.SkipUndefinedLiteral | JSXValueHint.SkipBooleanLiteral;
|
|
2284
|
-
function isJSXValue(node, context, hint = DEFAULT_JSX_VALUE_HINT) {
|
|
2285
|
-
if (!node)
|
|
2286
|
-
return false;
|
|
2287
|
-
return $(node).with({ type: ast.NodeType.JSXElement }, Function_exports.constTrue).with({ type: ast.NodeType.JSXFragment }, Function_exports.constTrue).with({ type: ast.NodeType.JSXMemberExpression }, Function_exports.constTrue).with({ type: ast.NodeType.JSXNamespacedName }, Function_exports.constTrue).with({ type: ast.NodeType.Literal }, (node2) => {
|
|
2288
|
-
return $(node2.value).with(null, () => !(hint & JSXValueHint.SkipNullLiteral)).with(N.boolean, () => !(hint & JSXValueHint.SkipBooleanLiteral)).with(N.string, () => !(hint & JSXValueHint.SkipStringLiteral)).with(N.number, () => !(hint & JSXValueHint.SkipNumberLiteral)).otherwise(Function_exports.constFalse);
|
|
2289
|
-
}).with({ type: ast.NodeType.TemplateLiteral }, () => !(hint & JSXValueHint.SkipStringLiteral)).with({ type: ast.NodeType.ArrayExpression }, (node2) => {
|
|
2290
|
-
if (hint & JSXValueHint.StrictArray)
|
|
2291
|
-
return node2.elements.every((n2) => isJSXValue(n2, context, hint));
|
|
2292
|
-
return node2.elements.some((n2) => isJSXValue(n2, context, hint));
|
|
2293
|
-
}).with({ type: ast.NodeType.ConditionalExpression }, (node2) => {
|
|
2294
|
-
function leftHasJSX(node3) {
|
|
2295
|
-
if (Array.isArray(node3.consequent)) {
|
|
2296
|
-
if (hint & JSXValueHint.StrictArray) {
|
|
2297
|
-
return node3.consequent.every((n2) => isJSXValue(n2, context, hint));
|
|
2298
|
-
}
|
|
2299
|
-
return node3.consequent.some((n2) => isJSXValue(n2, context, hint));
|
|
2300
|
-
}
|
|
2301
|
-
return isJSXValue(node3.consequent, context, hint);
|
|
2302
|
-
}
|
|
2303
|
-
function rightHasJSX(node3) {
|
|
2304
|
-
return isJSXValue(node3.alternate, context, hint);
|
|
2305
|
-
}
|
|
2306
|
-
if (hint & JSXValueHint.StrictConditional) {
|
|
2307
|
-
return leftHasJSX(node2) && rightHasJSX(node2);
|
|
2308
|
-
}
|
|
2309
|
-
return leftHasJSX(node2) || rightHasJSX(node2);
|
|
2310
|
-
}).with({ type: ast.NodeType.LogicalExpression }, (node2) => {
|
|
2311
|
-
return isJSXValue(node2.left, context, hint) || isJSXValue(node2.right, context, hint);
|
|
2312
|
-
}).with({ type: ast.NodeType.SequenceExpression }, (node2) => {
|
|
2313
|
-
const exp = node2.expressions.at(-1);
|
|
2314
|
-
return isJSXValue(exp, context, hint);
|
|
2315
|
-
}).with({ type: ast.NodeType.CallExpression }, (node2) => {
|
|
2316
|
-
if (hint & JSXValueHint.SkipCreateElement)
|
|
2317
|
-
return false;
|
|
2318
|
-
return $(node2.callee).with({ type: ast.NodeType.Identifier, name: "createElement" }, Function_exports.constTrue).with({ type: ast.NodeType.MemberExpression, property: { name: "createElement" } }, Function_exports.constTrue).otherwise(Function_exports.constFalse);
|
|
2319
|
-
}).with({ type: ast.NodeType.Identifier }, (node2) => {
|
|
2320
|
-
const { name } = node2;
|
|
2321
|
-
if (name === "undefined")
|
|
2322
|
-
return !(hint & JSXValueHint.SkipUndefinedLiteral);
|
|
2323
|
-
if (ast.isJSXTagNameExpression(node2))
|
|
2324
|
-
return true;
|
|
2325
|
-
const initialScope = context.sourceCode.getScope(node2);
|
|
2326
|
-
const maybeVariable = _var.findVariable(name, initialScope);
|
|
2327
|
-
return Function_exports.pipe(
|
|
2328
|
-
maybeVariable,
|
|
2329
|
-
Option_exports.flatMap(_var.getVariableInit(0)),
|
|
2330
|
-
Option_exports.exists((n2) => isJSXValue(n2, context, hint))
|
|
2331
|
-
);
|
|
2332
|
-
}).otherwise(Function_exports.constFalse);
|
|
2333
|
-
}
|
|
2334
|
-
|
|
2335
|
-
// src/misc.ts
|
|
2336
|
-
function isFunctionReturningJSXValue(node, context, hint = DEFAULT_JSX_VALUE_HINT) {
|
|
2337
|
-
if (node.body.type !== ast.NodeType.BlockStatement) {
|
|
2338
|
-
return isJSXValue(node.body, context, hint);
|
|
2339
|
-
}
|
|
2340
|
-
const statements = ast.getNestedReturnStatements(node.body);
|
|
2341
|
-
return statements.some((statement) => isJSXValue(statement.argument, context, hint));
|
|
2342
|
-
}
|
|
2343
|
-
|
|
2344
|
-
// src/pragma.ts
|
|
2345
|
-
var RE_JSX_ANNOTATION_REGEX = /@jsx\s+(\S+)/u;
|
|
2346
|
-
var RE_JS_IDENTIFIER_REGEX = /^[$A-Z_a-z][\w$]*$/u;
|
|
2347
|
-
function getJSXPragmaFromContext(context) {
|
|
2348
|
-
const { sourceCode } = context;
|
|
2349
|
-
return Function_exports.pipe(
|
|
2350
|
-
Array_exports.findFirst(sourceCode.getAllComments(), (node) => RE_JSX_ANNOTATION_REGEX.test(node.value)),
|
|
2351
|
-
Option_exports.map(({ value }) => RE_JSX_ANNOTATION_REGEX.exec(value)),
|
|
2352
|
-
Option_exports.flatMapNullable((matches) => matches?.[1]),
|
|
2353
|
-
Option_exports.filter((pragma) => RE_JS_IDENTIFIER_REGEX.test(pragma))
|
|
2354
|
-
);
|
|
2355
|
-
}
|
|
2283
|
+
// src/prop/get-prop.ts
|
|
2356
2284
|
var { getStaticValue } = ast.ESLintCommunityESLintUtils;
|
|
2357
2285
|
function getPropName(node) {
|
|
2358
2286
|
return $(node.name).when(ast.is(ast.NodeType.JSXIdentifier), (n2) => n2.name).when(ast.is(ast.NodeType.JSXNamespacedName), (n2) => `${n2.namespace.name}:${n2.name.name}`).exhaustive();
|
|
@@ -2473,6 +2401,69 @@ function isLineBreak(node) {
|
|
|
2473
2401
|
function isPaddingSpaces(node) {
|
|
2474
2402
|
return isLiteral(node) && isWhiteSpace(node) && node.raw.includes("\n");
|
|
2475
2403
|
}
|
|
2404
|
+
var JSXValueHint = {
|
|
2405
|
+
None: 0n,
|
|
2406
|
+
SkipNullLiteral: 1n << 0n,
|
|
2407
|
+
SkipUndefinedLiteral: 1n << 1n,
|
|
2408
|
+
SkipBooleanLiteral: 1n << 2n,
|
|
2409
|
+
SkipStringLiteral: 1n << 3n,
|
|
2410
|
+
SkipNumberLiteral: 1n << 4n,
|
|
2411
|
+
SkipCreateElement: 1n << 5n,
|
|
2412
|
+
StrictArray: 1n << 6n,
|
|
2413
|
+
StrictLogical: 1n << 7n,
|
|
2414
|
+
StrictConditional: 1n << 8n
|
|
2415
|
+
};
|
|
2416
|
+
var DEFAULT_JSX_VALUE_HINT = JSXValueHint.SkipUndefinedLiteral | JSXValueHint.SkipBooleanLiteral;
|
|
2417
|
+
function isJSXValue(node, context, hint = DEFAULT_JSX_VALUE_HINT) {
|
|
2418
|
+
if (!node)
|
|
2419
|
+
return false;
|
|
2420
|
+
return $(node).with({ type: ast.NodeType.JSXElement }, Function_exports.constTrue).with({ type: ast.NodeType.JSXFragment }, Function_exports.constTrue).with({ type: ast.NodeType.JSXMemberExpression }, Function_exports.constTrue).with({ type: ast.NodeType.JSXNamespacedName }, Function_exports.constTrue).with({ type: ast.NodeType.Literal }, (node2) => {
|
|
2421
|
+
return $(node2.value).with(null, () => !(hint & JSXValueHint.SkipNullLiteral)).with(N.boolean, () => !(hint & JSXValueHint.SkipBooleanLiteral)).with(N.string, () => !(hint & JSXValueHint.SkipStringLiteral)).with(N.number, () => !(hint & JSXValueHint.SkipNumberLiteral)).otherwise(Function_exports.constFalse);
|
|
2422
|
+
}).with({ type: ast.NodeType.TemplateLiteral }, () => !(hint & JSXValueHint.SkipStringLiteral)).with({ type: ast.NodeType.ArrayExpression }, (node2) => {
|
|
2423
|
+
if (hint & JSXValueHint.StrictArray)
|
|
2424
|
+
return node2.elements.every((n2) => isJSXValue(n2, context, hint));
|
|
2425
|
+
return node2.elements.some((n2) => isJSXValue(n2, context, hint));
|
|
2426
|
+
}).with({ type: ast.NodeType.ConditionalExpression }, (node2) => {
|
|
2427
|
+
function leftHasJSX(node3) {
|
|
2428
|
+
if (Array.isArray(node3.consequent)) {
|
|
2429
|
+
if (hint & JSXValueHint.StrictArray) {
|
|
2430
|
+
return node3.consequent.every((n2) => isJSXValue(n2, context, hint));
|
|
2431
|
+
}
|
|
2432
|
+
return node3.consequent.some((n2) => isJSXValue(n2, context, hint));
|
|
2433
|
+
}
|
|
2434
|
+
return isJSXValue(node3.consequent, context, hint);
|
|
2435
|
+
}
|
|
2436
|
+
function rightHasJSX(node3) {
|
|
2437
|
+
return isJSXValue(node3.alternate, context, hint);
|
|
2438
|
+
}
|
|
2439
|
+
if (hint & JSXValueHint.StrictConditional) {
|
|
2440
|
+
return leftHasJSX(node2) && rightHasJSX(node2);
|
|
2441
|
+
}
|
|
2442
|
+
return leftHasJSX(node2) || rightHasJSX(node2);
|
|
2443
|
+
}).with({ type: ast.NodeType.LogicalExpression }, (node2) => {
|
|
2444
|
+
return isJSXValue(node2.left, context, hint) || isJSXValue(node2.right, context, hint);
|
|
2445
|
+
}).with({ type: ast.NodeType.SequenceExpression }, (node2) => {
|
|
2446
|
+
const exp = node2.expressions.at(-1);
|
|
2447
|
+
return isJSXValue(exp, context, hint);
|
|
2448
|
+
}).with({ type: ast.NodeType.CallExpression }, (node2) => {
|
|
2449
|
+
if (hint & JSXValueHint.SkipCreateElement)
|
|
2450
|
+
return false;
|
|
2451
|
+
return $(node2.callee).with({ type: ast.NodeType.Identifier, name: "createElement" }, Function_exports.constTrue).with({ type: ast.NodeType.MemberExpression, property: { name: "createElement" } }, Function_exports.constTrue).otherwise(Function_exports.constFalse);
|
|
2452
|
+
}).with({ type: ast.NodeType.Identifier }, (node2) => {
|
|
2453
|
+
const { name } = node2;
|
|
2454
|
+
if (name === "undefined")
|
|
2455
|
+
return !(hint & JSXValueHint.SkipUndefinedLiteral);
|
|
2456
|
+
if (ast.isJSXTagNameExpression(node2))
|
|
2457
|
+
return true;
|
|
2458
|
+
const initialScope = context.sourceCode.getScope(node2);
|
|
2459
|
+
const maybeVariable = _var.findVariable(name, initialScope);
|
|
2460
|
+
return Function_exports.pipe(
|
|
2461
|
+
maybeVariable,
|
|
2462
|
+
Option_exports.flatMap(_var.getVariableInit(0)),
|
|
2463
|
+
Option_exports.exists((n2) => isJSXValue(n2, context, hint))
|
|
2464
|
+
);
|
|
2465
|
+
}).otherwise(Function_exports.constFalse);
|
|
2466
|
+
}
|
|
2476
2467
|
|
|
2477
2468
|
exports.DEFAULT_JSX_VALUE_HINT = DEFAULT_JSX_VALUE_HINT;
|
|
2478
2469
|
exports.JSXValueHint = JSXValueHint;
|
|
@@ -2486,7 +2477,6 @@ exports.getPropValue = getPropValue;
|
|
|
2486
2477
|
exports.hasAnyProp = hasAnyProp;
|
|
2487
2478
|
exports.hasEveryProp = hasEveryProp;
|
|
2488
2479
|
exports.hasProp = hasProp;
|
|
2489
|
-
exports.isFunctionReturningJSXValue = isFunctionReturningJSXValue;
|
|
2490
2480
|
exports.isInsidePropValue = isInsidePropValue;
|
|
2491
2481
|
exports.isJSXElementOfBuiltinComponent = isJSXElementOfBuiltinComponent;
|
|
2492
2482
|
exports.isJSXElementOfUserDefinedComponent = isJSXElementOfUserDefinedComponent;
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AST_NODE_TYPES } from '@typescript-eslint/types';
|
|
2
|
-
import { isOneOf, NodeType,
|
|
2
|
+
import { isOneOf, NodeType, is, traverseUpGuard, isStringLiteral, isMultiLine, isJSXTagNameExpression, ESLintCommunityESLintUtils } from '@eslint-react/ast';
|
|
3
3
|
import { findVariable, getVariableInit } from '@eslint-react/var';
|
|
4
4
|
import '@typescript-eslint/utils';
|
|
5
5
|
|
|
@@ -1990,6 +1990,19 @@ var mapAccum = /* @__PURE__ */ dual(3, (self, s2, f2) => {
|
|
|
1990
1990
|
var cartesianWith = /* @__PURE__ */ dual(3, (self, that, f2) => flatMap2(self, (a2) => map2(that, (b2) => f2(a2, b2))));
|
|
1991
1991
|
var cartesian = /* @__PURE__ */ dual(2, (self, that) => cartesianWith(self, that, (a2, b2) => [a2, b2]));
|
|
1992
1992
|
|
|
1993
|
+
// src/pragma.ts
|
|
1994
|
+
var RE_JSX_ANNOTATION_REGEX = /@jsx\s+(\S+)/u;
|
|
1995
|
+
var RE_JS_IDENTIFIER_REGEX = /^[$A-Z_a-z][\w$]*$/u;
|
|
1996
|
+
function getJSXPragmaFromContext(context) {
|
|
1997
|
+
const { sourceCode } = context;
|
|
1998
|
+
return Function_exports.pipe(
|
|
1999
|
+
Array_exports.findFirst(sourceCode.getAllComments(), (node) => RE_JSX_ANNOTATION_REGEX.test(node.value)),
|
|
2000
|
+
Option_exports.map(({ value }) => RE_JSX_ANNOTATION_REGEX.exec(value)),
|
|
2001
|
+
Option_exports.flatMapNullable((matches) => matches?.[1]),
|
|
2002
|
+
Option_exports.filter((pragma) => RE_JS_IDENTIFIER_REGEX.test(pragma))
|
|
2003
|
+
);
|
|
2004
|
+
}
|
|
2005
|
+
|
|
1993
2006
|
// ../../../node_modules/.pnpm/ts-pattern@5.1.1/node_modules/ts-pattern/dist/index.js
|
|
1994
2007
|
var t = Symbol.for("@ts-pattern/matcher");
|
|
1995
2008
|
var e = Symbol.for("@ts-pattern/isVariadic");
|
|
@@ -2265,92 +2278,7 @@ var z = class _z {
|
|
|
2265
2278
|
}
|
|
2266
2279
|
};
|
|
2267
2280
|
|
|
2268
|
-
// src/
|
|
2269
|
-
var JSXValueHint = {
|
|
2270
|
-
None: 0n,
|
|
2271
|
-
SkipNullLiteral: 1n << 0n,
|
|
2272
|
-
SkipUndefinedLiteral: 1n << 1n,
|
|
2273
|
-
SkipBooleanLiteral: 1n << 2n,
|
|
2274
|
-
SkipStringLiteral: 1n << 3n,
|
|
2275
|
-
SkipNumberLiteral: 1n << 4n,
|
|
2276
|
-
SkipCreateElement: 1n << 5n,
|
|
2277
|
-
StrictArray: 1n << 6n,
|
|
2278
|
-
StrictLogical: 1n << 7n,
|
|
2279
|
-
StrictConditional: 1n << 8n
|
|
2280
|
-
};
|
|
2281
|
-
var DEFAULT_JSX_VALUE_HINT = JSXValueHint.SkipUndefinedLiteral | JSXValueHint.SkipBooleanLiteral;
|
|
2282
|
-
function isJSXValue(node, context, hint = DEFAULT_JSX_VALUE_HINT) {
|
|
2283
|
-
if (!node)
|
|
2284
|
-
return false;
|
|
2285
|
-
return $(node).with({ type: NodeType.JSXElement }, Function_exports.constTrue).with({ type: NodeType.JSXFragment }, Function_exports.constTrue).with({ type: NodeType.JSXMemberExpression }, Function_exports.constTrue).with({ type: NodeType.JSXNamespacedName }, Function_exports.constTrue).with({ type: NodeType.Literal }, (node2) => {
|
|
2286
|
-
return $(node2.value).with(null, () => !(hint & JSXValueHint.SkipNullLiteral)).with(N.boolean, () => !(hint & JSXValueHint.SkipBooleanLiteral)).with(N.string, () => !(hint & JSXValueHint.SkipStringLiteral)).with(N.number, () => !(hint & JSXValueHint.SkipNumberLiteral)).otherwise(Function_exports.constFalse);
|
|
2287
|
-
}).with({ type: NodeType.TemplateLiteral }, () => !(hint & JSXValueHint.SkipStringLiteral)).with({ type: NodeType.ArrayExpression }, (node2) => {
|
|
2288
|
-
if (hint & JSXValueHint.StrictArray)
|
|
2289
|
-
return node2.elements.every((n2) => isJSXValue(n2, context, hint));
|
|
2290
|
-
return node2.elements.some((n2) => isJSXValue(n2, context, hint));
|
|
2291
|
-
}).with({ type: NodeType.ConditionalExpression }, (node2) => {
|
|
2292
|
-
function leftHasJSX(node3) {
|
|
2293
|
-
if (Array.isArray(node3.consequent)) {
|
|
2294
|
-
if (hint & JSXValueHint.StrictArray) {
|
|
2295
|
-
return node3.consequent.every((n2) => isJSXValue(n2, context, hint));
|
|
2296
|
-
}
|
|
2297
|
-
return node3.consequent.some((n2) => isJSXValue(n2, context, hint));
|
|
2298
|
-
}
|
|
2299
|
-
return isJSXValue(node3.consequent, context, hint);
|
|
2300
|
-
}
|
|
2301
|
-
function rightHasJSX(node3) {
|
|
2302
|
-
return isJSXValue(node3.alternate, context, hint);
|
|
2303
|
-
}
|
|
2304
|
-
if (hint & JSXValueHint.StrictConditional) {
|
|
2305
|
-
return leftHasJSX(node2) && rightHasJSX(node2);
|
|
2306
|
-
}
|
|
2307
|
-
return leftHasJSX(node2) || rightHasJSX(node2);
|
|
2308
|
-
}).with({ type: NodeType.LogicalExpression }, (node2) => {
|
|
2309
|
-
return isJSXValue(node2.left, context, hint) || isJSXValue(node2.right, context, hint);
|
|
2310
|
-
}).with({ type: NodeType.SequenceExpression }, (node2) => {
|
|
2311
|
-
const exp = node2.expressions.at(-1);
|
|
2312
|
-
return isJSXValue(exp, context, hint);
|
|
2313
|
-
}).with({ type: NodeType.CallExpression }, (node2) => {
|
|
2314
|
-
if (hint & JSXValueHint.SkipCreateElement)
|
|
2315
|
-
return false;
|
|
2316
|
-
return $(node2.callee).with({ type: NodeType.Identifier, name: "createElement" }, Function_exports.constTrue).with({ type: NodeType.MemberExpression, property: { name: "createElement" } }, Function_exports.constTrue).otherwise(Function_exports.constFalse);
|
|
2317
|
-
}).with({ type: NodeType.Identifier }, (node2) => {
|
|
2318
|
-
const { name } = node2;
|
|
2319
|
-
if (name === "undefined")
|
|
2320
|
-
return !(hint & JSXValueHint.SkipUndefinedLiteral);
|
|
2321
|
-
if (isJSXTagNameExpression(node2))
|
|
2322
|
-
return true;
|
|
2323
|
-
const initialScope = context.sourceCode.getScope(node2);
|
|
2324
|
-
const maybeVariable = findVariable(name, initialScope);
|
|
2325
|
-
return Function_exports.pipe(
|
|
2326
|
-
maybeVariable,
|
|
2327
|
-
Option_exports.flatMap(getVariableInit(0)),
|
|
2328
|
-
Option_exports.exists((n2) => isJSXValue(n2, context, hint))
|
|
2329
|
-
);
|
|
2330
|
-
}).otherwise(Function_exports.constFalse);
|
|
2331
|
-
}
|
|
2332
|
-
|
|
2333
|
-
// src/misc.ts
|
|
2334
|
-
function isFunctionReturningJSXValue(node, context, hint = DEFAULT_JSX_VALUE_HINT) {
|
|
2335
|
-
if (node.body.type !== NodeType.BlockStatement) {
|
|
2336
|
-
return isJSXValue(node.body, context, hint);
|
|
2337
|
-
}
|
|
2338
|
-
const statements = getNestedReturnStatements(node.body);
|
|
2339
|
-
return statements.some((statement) => isJSXValue(statement.argument, context, hint));
|
|
2340
|
-
}
|
|
2341
|
-
|
|
2342
|
-
// src/pragma.ts
|
|
2343
|
-
var RE_JSX_ANNOTATION_REGEX = /@jsx\s+(\S+)/u;
|
|
2344
|
-
var RE_JS_IDENTIFIER_REGEX = /^[$A-Z_a-z][\w$]*$/u;
|
|
2345
|
-
function getJSXPragmaFromContext(context) {
|
|
2346
|
-
const { sourceCode } = context;
|
|
2347
|
-
return Function_exports.pipe(
|
|
2348
|
-
Array_exports.findFirst(sourceCode.getAllComments(), (node) => RE_JSX_ANNOTATION_REGEX.test(node.value)),
|
|
2349
|
-
Option_exports.map(({ value }) => RE_JSX_ANNOTATION_REGEX.exec(value)),
|
|
2350
|
-
Option_exports.flatMapNullable((matches) => matches?.[1]),
|
|
2351
|
-
Option_exports.filter((pragma) => RE_JS_IDENTIFIER_REGEX.test(pragma))
|
|
2352
|
-
);
|
|
2353
|
-
}
|
|
2281
|
+
// src/prop/get-prop.ts
|
|
2354
2282
|
var { getStaticValue } = ESLintCommunityESLintUtils;
|
|
2355
2283
|
function getPropName(node) {
|
|
2356
2284
|
return $(node.name).when(is(NodeType.JSXIdentifier), (n2) => n2.name).when(is(NodeType.JSXNamespacedName), (n2) => `${n2.namespace.name}:${n2.name.name}`).exhaustive();
|
|
@@ -2471,5 +2399,68 @@ function isLineBreak(node) {
|
|
|
2471
2399
|
function isPaddingSpaces(node) {
|
|
2472
2400
|
return isLiteral(node) && isWhiteSpace(node) && node.raw.includes("\n");
|
|
2473
2401
|
}
|
|
2402
|
+
var JSXValueHint = {
|
|
2403
|
+
None: 0n,
|
|
2404
|
+
SkipNullLiteral: 1n << 0n,
|
|
2405
|
+
SkipUndefinedLiteral: 1n << 1n,
|
|
2406
|
+
SkipBooleanLiteral: 1n << 2n,
|
|
2407
|
+
SkipStringLiteral: 1n << 3n,
|
|
2408
|
+
SkipNumberLiteral: 1n << 4n,
|
|
2409
|
+
SkipCreateElement: 1n << 5n,
|
|
2410
|
+
StrictArray: 1n << 6n,
|
|
2411
|
+
StrictLogical: 1n << 7n,
|
|
2412
|
+
StrictConditional: 1n << 8n
|
|
2413
|
+
};
|
|
2414
|
+
var DEFAULT_JSX_VALUE_HINT = JSXValueHint.SkipUndefinedLiteral | JSXValueHint.SkipBooleanLiteral;
|
|
2415
|
+
function isJSXValue(node, context, hint = DEFAULT_JSX_VALUE_HINT) {
|
|
2416
|
+
if (!node)
|
|
2417
|
+
return false;
|
|
2418
|
+
return $(node).with({ type: NodeType.JSXElement }, Function_exports.constTrue).with({ type: NodeType.JSXFragment }, Function_exports.constTrue).with({ type: NodeType.JSXMemberExpression }, Function_exports.constTrue).with({ type: NodeType.JSXNamespacedName }, Function_exports.constTrue).with({ type: NodeType.Literal }, (node2) => {
|
|
2419
|
+
return $(node2.value).with(null, () => !(hint & JSXValueHint.SkipNullLiteral)).with(N.boolean, () => !(hint & JSXValueHint.SkipBooleanLiteral)).with(N.string, () => !(hint & JSXValueHint.SkipStringLiteral)).with(N.number, () => !(hint & JSXValueHint.SkipNumberLiteral)).otherwise(Function_exports.constFalse);
|
|
2420
|
+
}).with({ type: NodeType.TemplateLiteral }, () => !(hint & JSXValueHint.SkipStringLiteral)).with({ type: NodeType.ArrayExpression }, (node2) => {
|
|
2421
|
+
if (hint & JSXValueHint.StrictArray)
|
|
2422
|
+
return node2.elements.every((n2) => isJSXValue(n2, context, hint));
|
|
2423
|
+
return node2.elements.some((n2) => isJSXValue(n2, context, hint));
|
|
2424
|
+
}).with({ type: NodeType.ConditionalExpression }, (node2) => {
|
|
2425
|
+
function leftHasJSX(node3) {
|
|
2426
|
+
if (Array.isArray(node3.consequent)) {
|
|
2427
|
+
if (hint & JSXValueHint.StrictArray) {
|
|
2428
|
+
return node3.consequent.every((n2) => isJSXValue(n2, context, hint));
|
|
2429
|
+
}
|
|
2430
|
+
return node3.consequent.some((n2) => isJSXValue(n2, context, hint));
|
|
2431
|
+
}
|
|
2432
|
+
return isJSXValue(node3.consequent, context, hint);
|
|
2433
|
+
}
|
|
2434
|
+
function rightHasJSX(node3) {
|
|
2435
|
+
return isJSXValue(node3.alternate, context, hint);
|
|
2436
|
+
}
|
|
2437
|
+
if (hint & JSXValueHint.StrictConditional) {
|
|
2438
|
+
return leftHasJSX(node2) && rightHasJSX(node2);
|
|
2439
|
+
}
|
|
2440
|
+
return leftHasJSX(node2) || rightHasJSX(node2);
|
|
2441
|
+
}).with({ type: NodeType.LogicalExpression }, (node2) => {
|
|
2442
|
+
return isJSXValue(node2.left, context, hint) || isJSXValue(node2.right, context, hint);
|
|
2443
|
+
}).with({ type: NodeType.SequenceExpression }, (node2) => {
|
|
2444
|
+
const exp = node2.expressions.at(-1);
|
|
2445
|
+
return isJSXValue(exp, context, hint);
|
|
2446
|
+
}).with({ type: NodeType.CallExpression }, (node2) => {
|
|
2447
|
+
if (hint & JSXValueHint.SkipCreateElement)
|
|
2448
|
+
return false;
|
|
2449
|
+
return $(node2.callee).with({ type: NodeType.Identifier, name: "createElement" }, Function_exports.constTrue).with({ type: NodeType.MemberExpression, property: { name: "createElement" } }, Function_exports.constTrue).otherwise(Function_exports.constFalse);
|
|
2450
|
+
}).with({ type: NodeType.Identifier }, (node2) => {
|
|
2451
|
+
const { name } = node2;
|
|
2452
|
+
if (name === "undefined")
|
|
2453
|
+
return !(hint & JSXValueHint.SkipUndefinedLiteral);
|
|
2454
|
+
if (isJSXTagNameExpression(node2))
|
|
2455
|
+
return true;
|
|
2456
|
+
const initialScope = context.sourceCode.getScope(node2);
|
|
2457
|
+
const maybeVariable = findVariable(name, initialScope);
|
|
2458
|
+
return Function_exports.pipe(
|
|
2459
|
+
maybeVariable,
|
|
2460
|
+
Option_exports.flatMap(getVariableInit(0)),
|
|
2461
|
+
Option_exports.exists((n2) => isJSXValue(n2, context, hint))
|
|
2462
|
+
);
|
|
2463
|
+
}).otherwise(Function_exports.constFalse);
|
|
2464
|
+
}
|
|
2474
2465
|
|
|
2475
|
-
export { DEFAULT_JSX_VALUE_HINT, JSXValueHint, elementType, findPropInAttributes, findPropInProperties, getJSXPragmaFromContext, getProp, getPropName, getPropValue, hasAnyProp, hasEveryProp, hasProp,
|
|
2466
|
+
export { DEFAULT_JSX_VALUE_HINT, JSXValueHint, elementType, findPropInAttributes, findPropInProperties, getJSXPragmaFromContext, getProp, getPropName, getPropValue, hasAnyProp, hasEveryProp, hasProp, isInsidePropValue, isJSXElementOfBuiltinComponent, isJSXElementOfUserDefinedComponent, isJSXValue, isLineBreak, isLiteral, isPaddingSpaces, isWhiteSpace, traverseUpProp };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eslint-react/jsx",
|
|
3
|
-
"version": "1.5.11-next.
|
|
3
|
+
"version": "1.5.11-next.12",
|
|
4
4
|
"description": "ESLint React's TSESTree AST utility module for static analysis of JSX.",
|
|
5
5
|
"homepage": "https://github.com/rel1cx/eslint-react",
|
|
6
6
|
"bugs": {
|
|
@@ -39,11 +39,11 @@
|
|
|
39
39
|
"@typescript-eslint/types": "^7.8.0",
|
|
40
40
|
"@typescript-eslint/utils": "^7.8.0",
|
|
41
41
|
"micro-memoize": "4.1.2",
|
|
42
|
-
"@eslint-react/ast": "1.5.11-next.
|
|
43
|
-
"@eslint-react/shared": "1.5.11-next.
|
|
44
|
-
"@eslint-react/
|
|
45
|
-
"@eslint-react/
|
|
46
|
-
"@eslint-react/
|
|
42
|
+
"@eslint-react/ast": "1.5.11-next.12",
|
|
43
|
+
"@eslint-react/shared": "1.5.11-next.12",
|
|
44
|
+
"@eslint-react/types": "1.5.11-next.12",
|
|
45
|
+
"@eslint-react/var": "1.5.11-next.12",
|
|
46
|
+
"@eslint-react/tools": "1.5.11-next.12"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"effect": "3.1.2"
|