@eslint-react/jsx 1.10.1 → 1.10.2-beta.2
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 +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +15 -15
- package/dist/index.mjs +15 -15
- package/package.json +5 -5
package/dist/index.d.mts
CHANGED
|
@@ -10,7 +10,7 @@ import { TSESTree as TSESTree$1 } from '@typescript-eslint/utils';
|
|
|
10
10
|
*/
|
|
11
11
|
declare function getElementName(node: TSESTree.JSXOpeningElement | TSESTree.JSXOpeningFragment): string;
|
|
12
12
|
|
|
13
|
-
declare function getElementType(
|
|
13
|
+
declare function getElementType(jsxCtx: {
|
|
14
14
|
getScope: (node: TSESTree.Node) => Scope;
|
|
15
15
|
}, components?: Map<string, string>, polymorphicPropName?: string): (node: TSESTree.JSXOpeningElement) => string;
|
|
16
16
|
|
|
@@ -102,12 +102,12 @@ declare const DEFAULT_JSX_VALUE_HINT: bigint;
|
|
|
102
102
|
/**
|
|
103
103
|
* Check if a node is a JSX value
|
|
104
104
|
* @param node The AST node to check
|
|
105
|
-
* @param
|
|
106
|
-
* @param
|
|
105
|
+
* @param jsxCtx The requirements for the check
|
|
106
|
+
* @param jsxCtx.getScope The function to get the scope of a node
|
|
107
107
|
* @param hint The `JSXValueHint` to use
|
|
108
108
|
* @returns boolean
|
|
109
109
|
*/
|
|
110
|
-
declare function isJSXValue(node: TSESTree$1.Node | null | undefined,
|
|
110
|
+
declare function isJSXValue(node: TSESTree$1.Node | null | undefined, jsxCtx: {
|
|
111
111
|
getScope: (node: TSESTree$1.Node) => Scope;
|
|
112
112
|
}, hint?: bigint): boolean;
|
|
113
113
|
|
package/dist/index.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ import { TSESTree as TSESTree$1 } from '@typescript-eslint/utils';
|
|
|
10
10
|
*/
|
|
11
11
|
declare function getElementName(node: TSESTree.JSXOpeningElement | TSESTree.JSXOpeningFragment): string;
|
|
12
12
|
|
|
13
|
-
declare function getElementType(
|
|
13
|
+
declare function getElementType(jsxCtx: {
|
|
14
14
|
getScope: (node: TSESTree.Node) => Scope;
|
|
15
15
|
}, components?: Map<string, string>, polymorphicPropName?: string): (node: TSESTree.JSXOpeningElement) => string;
|
|
16
16
|
|
|
@@ -102,12 +102,12 @@ declare const DEFAULT_JSX_VALUE_HINT: bigint;
|
|
|
102
102
|
/**
|
|
103
103
|
* Check if a node is a JSX value
|
|
104
104
|
* @param node The AST node to check
|
|
105
|
-
* @param
|
|
106
|
-
* @param
|
|
105
|
+
* @param jsxCtx The requirements for the check
|
|
106
|
+
* @param jsxCtx.getScope The function to get the scope of a node
|
|
107
107
|
* @param hint The `JSXValueHint` to use
|
|
108
108
|
* @returns boolean
|
|
109
109
|
*/
|
|
110
|
-
declare function isJSXValue(node: TSESTree$1.Node | null | undefined,
|
|
110
|
+
declare function isJSXValue(node: TSESTree$1.Node | null | undefined, jsxCtx: {
|
|
111
111
|
getScope: (node: TSESTree$1.Node) => Scope;
|
|
112
112
|
}, hint?: bigint): boolean;
|
|
113
113
|
|
package/dist/index.js
CHANGED
|
@@ -134,17 +134,17 @@ function findPropInAttributes(attributes, initialScope) {
|
|
|
134
134
|
}
|
|
135
135
|
|
|
136
136
|
// src/get-element-type.ts
|
|
137
|
-
function getElementType(
|
|
137
|
+
function getElementType(jsxCtx, components, polymorphicPropName) {
|
|
138
138
|
return (node) => {
|
|
139
139
|
const elementName = getElementName(node);
|
|
140
140
|
if (elementName === elementName.toLowerCase()) return elementName;
|
|
141
141
|
const asElementName = components?.get(elementName);
|
|
142
142
|
if (tools.isString(asElementName)) return asElementName;
|
|
143
|
-
const initialScope =
|
|
143
|
+
const initialScope = jsxCtx.getScope(node);
|
|
144
144
|
return tools.F.pipe(
|
|
145
145
|
tools.O.fromNullable(polymorphicPropName),
|
|
146
146
|
tools.O.flatMap(findPropInAttributes(node.attributes, initialScope)),
|
|
147
|
-
tools.O.flatMap((attr) => getPropValue(attr,
|
|
147
|
+
tools.O.flatMap((attr) => getPropValue(attr, jsxCtx.getScope(attr))),
|
|
148
148
|
tools.O.flatMapNullable((v) => v?.value),
|
|
149
149
|
tools.O.filter(tools.isString),
|
|
150
150
|
tools.O.getOrElse(() => elementName)
|
|
@@ -183,26 +183,26 @@ var JSXValueHint = {
|
|
|
183
183
|
StrictConditional: 1n << 9n
|
|
184
184
|
};
|
|
185
185
|
var DEFAULT_JSX_VALUE_HINT = 0n | JSXValueHint.SkipUndefinedLiteral | JSXValueHint.SkipBooleanLiteral;
|
|
186
|
-
function isJSXValue(node,
|
|
186
|
+
function isJSXValue(node, jsxCtx, hint = DEFAULT_JSX_VALUE_HINT) {
|
|
187
187
|
if (!node) return false;
|
|
188
188
|
return tsPattern.match(node).with({ type: types.AST_NODE_TYPES.JSXElement }, tools.F.constTrue).with({ type: types.AST_NODE_TYPES.JSXFragment }, tools.F.constTrue).with({ type: types.AST_NODE_TYPES.JSXMemberExpression }, tools.F.constTrue).with({ type: types.AST_NODE_TYPES.JSXNamespacedName }, tools.F.constTrue).with({ type: types.AST_NODE_TYPES.Literal }, (node2) => {
|
|
189
189
|
return tsPattern.match(node2.value).with(null, () => !(hint & JSXValueHint.SkipNullLiteral)).with(tsPattern.P.boolean, () => !(hint & JSXValueHint.SkipBooleanLiteral)).with(tsPattern.P.string, () => !(hint & JSXValueHint.SkipStringLiteral)).with(tsPattern.P.number, () => !(hint & JSXValueHint.SkipNumberLiteral)).otherwise(tools.F.constFalse);
|
|
190
190
|
}).with({ type: types.AST_NODE_TYPES.TemplateLiteral }, () => !(hint & JSXValueHint.SkipStringLiteral)).with({ type: types.AST_NODE_TYPES.ArrayExpression }, (node2) => {
|
|
191
|
-
if (hint & JSXValueHint.StrictArray) return node2.elements.every((n) => isJSXValue(n,
|
|
192
|
-
return node2.elements.some((n) => isJSXValue(n,
|
|
191
|
+
if (hint & JSXValueHint.StrictArray) return node2.elements.every((n) => isJSXValue(n, jsxCtx, hint));
|
|
192
|
+
return node2.elements.some((n) => isJSXValue(n, jsxCtx, hint));
|
|
193
193
|
}).with({ type: types.AST_NODE_TYPES.ConditionalExpression }, (node2) => {
|
|
194
194
|
function leftHasJSX(node3) {
|
|
195
195
|
if (Array.isArray(node3.consequent)) {
|
|
196
196
|
if (node3.consequent.length === 0) return !(hint & JSXValueHint.SkipEmptyArray);
|
|
197
197
|
if (hint & JSXValueHint.StrictArray) {
|
|
198
|
-
return node3.consequent.every((n) => isJSXValue(n,
|
|
198
|
+
return node3.consequent.every((n) => isJSXValue(n, jsxCtx, hint));
|
|
199
199
|
}
|
|
200
|
-
return node3.consequent.some((n) => isJSXValue(n,
|
|
200
|
+
return node3.consequent.some((n) => isJSXValue(n, jsxCtx, hint));
|
|
201
201
|
}
|
|
202
|
-
return isJSXValue(node3.consequent,
|
|
202
|
+
return isJSXValue(node3.consequent, jsxCtx, hint);
|
|
203
203
|
}
|
|
204
204
|
function rightHasJSX(node3) {
|
|
205
|
-
return isJSXValue(node3.alternate,
|
|
205
|
+
return isJSXValue(node3.alternate, jsxCtx, hint);
|
|
206
206
|
}
|
|
207
207
|
if (hint & JSXValueHint.StrictConditional) {
|
|
208
208
|
return leftHasJSX(node2) && rightHasJSX(node2);
|
|
@@ -210,12 +210,12 @@ function isJSXValue(node, ctx, hint = DEFAULT_JSX_VALUE_HINT) {
|
|
|
210
210
|
return leftHasJSX(node2) || rightHasJSX(node2);
|
|
211
211
|
}).with({ type: types.AST_NODE_TYPES.LogicalExpression }, (node2) => {
|
|
212
212
|
if (hint & JSXValueHint.StrictLogical) {
|
|
213
|
-
return isJSXValue(node2.left,
|
|
213
|
+
return isJSXValue(node2.left, jsxCtx, hint) && isJSXValue(node2.right, jsxCtx, hint);
|
|
214
214
|
}
|
|
215
|
-
return isJSXValue(node2.left,
|
|
215
|
+
return isJSXValue(node2.left, jsxCtx, hint) || isJSXValue(node2.right, jsxCtx, hint);
|
|
216
216
|
}).with({ type: types.AST_NODE_TYPES.SequenceExpression }, (node2) => {
|
|
217
217
|
const exp = node2.expressions.at(-1);
|
|
218
|
-
return isJSXValue(exp,
|
|
218
|
+
return isJSXValue(exp, jsxCtx, hint);
|
|
219
219
|
}).with({ type: types.AST_NODE_TYPES.CallExpression }, (node2) => {
|
|
220
220
|
if (hint & JSXValueHint.SkipCreateElement) return false;
|
|
221
221
|
return tsPattern.match(node2.callee).with({ type: types.AST_NODE_TYPES.Identifier, name: "createElement" }, tools.F.constTrue).with({ type: types.AST_NODE_TYPES.MemberExpression, property: { name: "createElement" } }, tools.F.constTrue).otherwise(tools.F.constFalse);
|
|
@@ -223,11 +223,11 @@ function isJSXValue(node, ctx, hint = DEFAULT_JSX_VALUE_HINT) {
|
|
|
223
223
|
const { name } = node2;
|
|
224
224
|
if (name === "undefined") return !(hint & JSXValueHint.SkipUndefinedLiteral);
|
|
225
225
|
if (ast.isJSXTagNameExpression(node2)) return true;
|
|
226
|
-
const initialScope =
|
|
226
|
+
const initialScope = jsxCtx.getScope(node2);
|
|
227
227
|
return tools.F.pipe(
|
|
228
228
|
_var.findVariable(name, initialScope),
|
|
229
229
|
tools.O.flatMap(_var.getVariableNode(0)),
|
|
230
|
-
tools.O.exists((n) => isJSXValue(n,
|
|
230
|
+
tools.O.exists((n) => isJSXValue(n, jsxCtx, hint))
|
|
231
231
|
);
|
|
232
232
|
}).otherwise(tools.F.constFalse);
|
|
233
233
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -132,17 +132,17 @@ function findPropInAttributes(attributes, initialScope) {
|
|
|
132
132
|
}
|
|
133
133
|
|
|
134
134
|
// src/get-element-type.ts
|
|
135
|
-
function getElementType(
|
|
135
|
+
function getElementType(jsxCtx, components, polymorphicPropName) {
|
|
136
136
|
return (node) => {
|
|
137
137
|
const elementName = getElementName(node);
|
|
138
138
|
if (elementName === elementName.toLowerCase()) return elementName;
|
|
139
139
|
const asElementName = components?.get(elementName);
|
|
140
140
|
if (isString(asElementName)) return asElementName;
|
|
141
|
-
const initialScope =
|
|
141
|
+
const initialScope = jsxCtx.getScope(node);
|
|
142
142
|
return F.pipe(
|
|
143
143
|
O.fromNullable(polymorphicPropName),
|
|
144
144
|
O.flatMap(findPropInAttributes(node.attributes, initialScope)),
|
|
145
|
-
O.flatMap((attr) => getPropValue(attr,
|
|
145
|
+
O.flatMap((attr) => getPropValue(attr, jsxCtx.getScope(attr))),
|
|
146
146
|
O.flatMapNullable((v) => v?.value),
|
|
147
147
|
O.filter(isString),
|
|
148
148
|
O.getOrElse(() => elementName)
|
|
@@ -181,26 +181,26 @@ var JSXValueHint = {
|
|
|
181
181
|
StrictConditional: 1n << 9n
|
|
182
182
|
};
|
|
183
183
|
var DEFAULT_JSX_VALUE_HINT = 0n | JSXValueHint.SkipUndefinedLiteral | JSXValueHint.SkipBooleanLiteral;
|
|
184
|
-
function isJSXValue(node,
|
|
184
|
+
function isJSXValue(node, jsxCtx, hint = DEFAULT_JSX_VALUE_HINT) {
|
|
185
185
|
if (!node) return false;
|
|
186
186
|
return match(node).with({ type: AST_NODE_TYPES.JSXElement }, F.constTrue).with({ type: AST_NODE_TYPES.JSXFragment }, F.constTrue).with({ type: AST_NODE_TYPES.JSXMemberExpression }, F.constTrue).with({ type: AST_NODE_TYPES.JSXNamespacedName }, F.constTrue).with({ type: AST_NODE_TYPES.Literal }, (node2) => {
|
|
187
187
|
return match(node2.value).with(null, () => !(hint & JSXValueHint.SkipNullLiteral)).with(P.boolean, () => !(hint & JSXValueHint.SkipBooleanLiteral)).with(P.string, () => !(hint & JSXValueHint.SkipStringLiteral)).with(P.number, () => !(hint & JSXValueHint.SkipNumberLiteral)).otherwise(F.constFalse);
|
|
188
188
|
}).with({ type: AST_NODE_TYPES.TemplateLiteral }, () => !(hint & JSXValueHint.SkipStringLiteral)).with({ type: AST_NODE_TYPES.ArrayExpression }, (node2) => {
|
|
189
|
-
if (hint & JSXValueHint.StrictArray) return node2.elements.every((n) => isJSXValue(n,
|
|
190
|
-
return node2.elements.some((n) => isJSXValue(n,
|
|
189
|
+
if (hint & JSXValueHint.StrictArray) return node2.elements.every((n) => isJSXValue(n, jsxCtx, hint));
|
|
190
|
+
return node2.elements.some((n) => isJSXValue(n, jsxCtx, hint));
|
|
191
191
|
}).with({ type: AST_NODE_TYPES.ConditionalExpression }, (node2) => {
|
|
192
192
|
function leftHasJSX(node3) {
|
|
193
193
|
if (Array.isArray(node3.consequent)) {
|
|
194
194
|
if (node3.consequent.length === 0) return !(hint & JSXValueHint.SkipEmptyArray);
|
|
195
195
|
if (hint & JSXValueHint.StrictArray) {
|
|
196
|
-
return node3.consequent.every((n) => isJSXValue(n,
|
|
196
|
+
return node3.consequent.every((n) => isJSXValue(n, jsxCtx, hint));
|
|
197
197
|
}
|
|
198
|
-
return node3.consequent.some((n) => isJSXValue(n,
|
|
198
|
+
return node3.consequent.some((n) => isJSXValue(n, jsxCtx, hint));
|
|
199
199
|
}
|
|
200
|
-
return isJSXValue(node3.consequent,
|
|
200
|
+
return isJSXValue(node3.consequent, jsxCtx, hint);
|
|
201
201
|
}
|
|
202
202
|
function rightHasJSX(node3) {
|
|
203
|
-
return isJSXValue(node3.alternate,
|
|
203
|
+
return isJSXValue(node3.alternate, jsxCtx, hint);
|
|
204
204
|
}
|
|
205
205
|
if (hint & JSXValueHint.StrictConditional) {
|
|
206
206
|
return leftHasJSX(node2) && rightHasJSX(node2);
|
|
@@ -208,12 +208,12 @@ function isJSXValue(node, ctx, hint = DEFAULT_JSX_VALUE_HINT) {
|
|
|
208
208
|
return leftHasJSX(node2) || rightHasJSX(node2);
|
|
209
209
|
}).with({ type: AST_NODE_TYPES.LogicalExpression }, (node2) => {
|
|
210
210
|
if (hint & JSXValueHint.StrictLogical) {
|
|
211
|
-
return isJSXValue(node2.left,
|
|
211
|
+
return isJSXValue(node2.left, jsxCtx, hint) && isJSXValue(node2.right, jsxCtx, hint);
|
|
212
212
|
}
|
|
213
|
-
return isJSXValue(node2.left,
|
|
213
|
+
return isJSXValue(node2.left, jsxCtx, hint) || isJSXValue(node2.right, jsxCtx, hint);
|
|
214
214
|
}).with({ type: AST_NODE_TYPES.SequenceExpression }, (node2) => {
|
|
215
215
|
const exp = node2.expressions.at(-1);
|
|
216
|
-
return isJSXValue(exp,
|
|
216
|
+
return isJSXValue(exp, jsxCtx, hint);
|
|
217
217
|
}).with({ type: AST_NODE_TYPES.CallExpression }, (node2) => {
|
|
218
218
|
if (hint & JSXValueHint.SkipCreateElement) return false;
|
|
219
219
|
return match(node2.callee).with({ type: AST_NODE_TYPES.Identifier, name: "createElement" }, F.constTrue).with({ type: AST_NODE_TYPES.MemberExpression, property: { name: "createElement" } }, F.constTrue).otherwise(F.constFalse);
|
|
@@ -221,11 +221,11 @@ function isJSXValue(node, ctx, hint = DEFAULT_JSX_VALUE_HINT) {
|
|
|
221
221
|
const { name } = node2;
|
|
222
222
|
if (name === "undefined") return !(hint & JSXValueHint.SkipUndefinedLiteral);
|
|
223
223
|
if (isJSXTagNameExpression(node2)) return true;
|
|
224
|
-
const initialScope =
|
|
224
|
+
const initialScope = jsxCtx.getScope(node2);
|
|
225
225
|
return F.pipe(
|
|
226
226
|
findVariable(name, initialScope),
|
|
227
227
|
O.flatMap(getVariableNode(0)),
|
|
228
|
-
O.exists((n) => isJSXValue(n,
|
|
228
|
+
O.exists((n) => isJSXValue(n, jsxCtx, hint))
|
|
229
229
|
);
|
|
230
230
|
}).otherwise(F.constFalse);
|
|
231
231
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eslint-react/jsx",
|
|
3
|
-
"version": "1.10.
|
|
3
|
+
"version": "1.10.2-beta.2",
|
|
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,10 +39,10 @@
|
|
|
39
39
|
"@typescript-eslint/types": "^8.1.0",
|
|
40
40
|
"@typescript-eslint/utils": "^8.1.0",
|
|
41
41
|
"ts-pattern": "^5.3.1",
|
|
42
|
-
"@eslint-react/ast": "1.10.
|
|
43
|
-
"@eslint-react/tools": "1.10.
|
|
44
|
-
"@eslint-react/types": "1.10.
|
|
45
|
-
"@eslint-react/var": "1.10.
|
|
42
|
+
"@eslint-react/ast": "1.10.2-beta.2",
|
|
43
|
+
"@eslint-react/tools": "1.10.2-beta.2",
|
|
44
|
+
"@eslint-react/types": "1.10.2-beta.2",
|
|
45
|
+
"@eslint-react/var": "1.10.2-beta.2"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
48
|
"tsup": "^8.2.4"
|