@eslint-react/jsx 1.20.2-next.2 → 1.20.2-next.3
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 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +23 -23
- package/dist/index.mjs +1 -1
- package/package.json +5 -5
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TSESTree } from '@typescript-eslint/types';
|
|
2
|
-
import { O } from '@eslint-react/
|
|
2
|
+
import { O } from '@eslint-react/eff';
|
|
3
3
|
import { Scope } from '@typescript-eslint/scope-manager';
|
|
4
4
|
import { TSESTree as TSESTree$1 } from '@typescript-eslint/utils';
|
|
5
5
|
import * as birecord from 'birecord';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TSESTree } from '@typescript-eslint/types';
|
|
2
|
-
import { O } from '@eslint-react/
|
|
2
|
+
import { O } from '@eslint-react/eff';
|
|
3
3
|
import { Scope } from '@typescript-eslint/scope-manager';
|
|
4
4
|
import { TSESTree as TSESTree$1 } from '@typescript-eslint/utils';
|
|
5
5
|
import * as birecord from 'birecord';
|
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
var types = require('@typescript-eslint/types');
|
|
4
4
|
var AST = require('@eslint-react/ast');
|
|
5
|
-
var
|
|
5
|
+
var eff = require('@eslint-react/eff');
|
|
6
6
|
var VAR = require('@eslint-react/var');
|
|
7
7
|
var tsPattern = require('ts-pattern');
|
|
8
8
|
var birecord = require('birecord');
|
|
@@ -69,19 +69,19 @@ function getProp(props, propName, initialScope) {
|
|
|
69
69
|
function getPropValue(attribute, initialScope) {
|
|
70
70
|
if (attribute.type === types.AST_NODE_TYPES.JSXAttribute && "value" in attribute) {
|
|
71
71
|
const { value } = attribute;
|
|
72
|
-
if (value === null) return
|
|
72
|
+
if (value === null) return eff.O.none();
|
|
73
73
|
if (value.type === types.AST_NODE_TYPES.Literal) return VAR__namespace.getStaticValue(value, initialScope);
|
|
74
74
|
if (value.type === types.AST_NODE_TYPES.JSXExpressionContainer) {
|
|
75
75
|
return VAR__namespace.getStaticValue(value.expression, initialScope);
|
|
76
76
|
}
|
|
77
|
-
return
|
|
77
|
+
return eff.O.none();
|
|
78
78
|
}
|
|
79
79
|
const { argument } = attribute;
|
|
80
80
|
return VAR__namespace.getStaticValue(argument, initialScope);
|
|
81
81
|
}
|
|
82
82
|
function findPropInProperties(properties, initialScope, seenProps = []) {
|
|
83
83
|
return (propName) => {
|
|
84
|
-
return
|
|
84
|
+
return eff.O.fromNullable(
|
|
85
85
|
properties.findLast((prop) => {
|
|
86
86
|
switch (true) {
|
|
87
87
|
case (prop.type === types.AST_NODE_TYPES.Property && "name" in prop.key && prop.key.name === propName):
|
|
@@ -90,20 +90,20 @@ function findPropInProperties(properties, initialScope, seenProps = []) {
|
|
|
90
90
|
switch (true) {
|
|
91
91
|
case prop.argument.type === types.AST_NODE_TYPES.Identifier: {
|
|
92
92
|
const { name } = prop.argument;
|
|
93
|
-
const maybeInit =
|
|
93
|
+
const maybeInit = eff.O.flatMap(
|
|
94
94
|
VAR__namespace.findVariable(name, initialScope),
|
|
95
95
|
VAR__namespace.getVariableNode(0)
|
|
96
96
|
);
|
|
97
|
-
if (
|
|
97
|
+
if (eff.O.isNone(maybeInit)) return false;
|
|
98
98
|
const init = maybeInit.value;
|
|
99
99
|
if (!AST__namespace.is(types.AST_NODE_TYPES.ObjectExpression)(init)) return false;
|
|
100
100
|
if (seenProps.includes(name)) return false;
|
|
101
|
-
return
|
|
101
|
+
return eff.O.isSome(
|
|
102
102
|
findPropInProperties(init.properties, initialScope, [...seenProps, name])(propName)
|
|
103
103
|
);
|
|
104
104
|
}
|
|
105
105
|
case prop.argument.type === types.AST_NODE_TYPES.ObjectExpression: {
|
|
106
|
-
return
|
|
106
|
+
return eff.O.isSome(
|
|
107
107
|
findPropInProperties(prop.argument.properties, initialScope, seenProps)(propName)
|
|
108
108
|
);
|
|
109
109
|
}
|
|
@@ -122,7 +122,7 @@ function findPropInProperties(properties, initialScope, seenProps = []) {
|
|
|
122
122
|
}
|
|
123
123
|
function findPropInAttributes(attributes, initialScope) {
|
|
124
124
|
return (propName) => {
|
|
125
|
-
return
|
|
125
|
+
return eff.O.fromNullable(
|
|
126
126
|
attributes.findLast((attr) => {
|
|
127
127
|
switch (attr.type) {
|
|
128
128
|
case types.AST_NODE_TYPES.JSXAttribute:
|
|
@@ -133,19 +133,19 @@ function findPropInAttributes(attributes, initialScope) {
|
|
|
133
133
|
return false;
|
|
134
134
|
case types.AST_NODE_TYPES.Identifier: {
|
|
135
135
|
const { name } = attr.argument;
|
|
136
|
-
const maybeInit =
|
|
136
|
+
const maybeInit = eff.O.flatMap(
|
|
137
137
|
VAR__namespace.findVariable(name, initialScope),
|
|
138
138
|
VAR__namespace.getVariableNode(0)
|
|
139
139
|
);
|
|
140
|
-
if (
|
|
140
|
+
if (eff.O.isNone(maybeInit)) return false;
|
|
141
141
|
const init = maybeInit.value;
|
|
142
142
|
if (!AST__namespace.is(types.AST_NODE_TYPES.ObjectExpression)(init)) return false;
|
|
143
|
-
return
|
|
143
|
+
return eff.O.isSome(findPropInProperties(init.properties, initialScope)(propName));
|
|
144
144
|
}
|
|
145
145
|
case types.AST_NODE_TYPES.MemberExpression:
|
|
146
146
|
return false;
|
|
147
147
|
case types.AST_NODE_TYPES.ObjectExpression:
|
|
148
|
-
return
|
|
148
|
+
return eff.O.isSome(findPropInProperties(attr.argument.properties, initialScope)(propName));
|
|
149
149
|
default:
|
|
150
150
|
return false;
|
|
151
151
|
}
|
|
@@ -157,7 +157,7 @@ function findPropInAttributes(attributes, initialScope) {
|
|
|
157
157
|
};
|
|
158
158
|
}
|
|
159
159
|
function hasProp(attributes, propName, initialScope) {
|
|
160
|
-
return
|
|
160
|
+
return eff.O.isSome(findPropInAttributes(attributes, initialScope)(propName));
|
|
161
161
|
}
|
|
162
162
|
function hasAnyProp(attributes, propNames, initialScope) {
|
|
163
163
|
return propNames.some((propName) => hasProp(attributes, propName, initialScope));
|
|
@@ -190,8 +190,8 @@ var JSXValueHint = {
|
|
|
190
190
|
var DEFAULT_JSX_VALUE_HINT = 0n | JSXValueHint.SkipUndefinedLiteral | JSXValueHint.SkipBooleanLiteral;
|
|
191
191
|
function isJSXValue(node, jsxCtx, hint = DEFAULT_JSX_VALUE_HINT) {
|
|
192
192
|
if (!node) return false;
|
|
193
|
-
return tsPattern.match(node).with({ type: types.AST_NODE_TYPES.JSXElement },
|
|
194
|
-
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(
|
|
193
|
+
return tsPattern.match(node).with({ type: types.AST_NODE_TYPES.JSXElement }, eff.F.constTrue).with({ type: types.AST_NODE_TYPES.JSXFragment }, eff.F.constTrue).with({ type: types.AST_NODE_TYPES.JSXMemberExpression }, eff.F.constTrue).with({ type: types.AST_NODE_TYPES.JSXNamespacedName }, eff.F.constTrue).with({ type: types.AST_NODE_TYPES.Literal }, (node2) => {
|
|
194
|
+
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(eff.F.constFalse);
|
|
195
195
|
}).with({ type: types.AST_NODE_TYPES.TemplateLiteral }, () => !(hint & JSXValueHint.SkipStringLiteral)).with({ type: types.AST_NODE_TYPES.ArrayExpression }, (node2) => {
|
|
196
196
|
if (hint & JSXValueHint.StrictArray) return node2.elements.every((n) => isJSXValue(n, jsxCtx, hint));
|
|
197
197
|
return node2.elements.some((n) => isJSXValue(n, jsxCtx, hint));
|
|
@@ -223,22 +223,22 @@ function isJSXValue(node, jsxCtx, hint = DEFAULT_JSX_VALUE_HINT) {
|
|
|
223
223
|
return isJSXValue(exp, jsxCtx, hint);
|
|
224
224
|
}).with({ type: types.AST_NODE_TYPES.CallExpression }, (node2) => {
|
|
225
225
|
if (hint & JSXValueHint.SkipCreateElement) return false;
|
|
226
|
-
return tsPattern.match(node2.callee).with({ type: types.AST_NODE_TYPES.Identifier, name: "createElement" },
|
|
226
|
+
return tsPattern.match(node2.callee).with({ type: types.AST_NODE_TYPES.Identifier, name: "createElement" }, eff.F.constTrue).with({ type: types.AST_NODE_TYPES.MemberExpression, property: { name: "createElement" } }, eff.F.constTrue).otherwise(eff.F.constFalse);
|
|
227
227
|
}).with({ type: types.AST_NODE_TYPES.Identifier }, (node2) => {
|
|
228
228
|
const { name } = node2;
|
|
229
229
|
if (name === "undefined") return !(hint & JSXValueHint.SkipUndefinedLiteral);
|
|
230
230
|
if (AST__namespace.isJSXTagNameExpression(node2)) return true;
|
|
231
231
|
const initialScope = jsxCtx.getScope(node2);
|
|
232
|
-
return
|
|
232
|
+
return eff.F.pipe(
|
|
233
233
|
VAR__namespace.findVariable(name, initialScope),
|
|
234
|
-
|
|
235
|
-
|
|
234
|
+
eff.O.flatMap(VAR__namespace.getVariableNode(0)),
|
|
235
|
+
eff.O.exists((n) => isJSXValue(n, jsxCtx, hint))
|
|
236
236
|
);
|
|
237
|
-
}).otherwise(
|
|
237
|
+
}).otherwise(eff.F.constFalse);
|
|
238
238
|
}
|
|
239
239
|
var isLiteral = AST__namespace.isOneOf([types.AST_NODE_TYPES.Literal, types.AST_NODE_TYPES.JSXText]);
|
|
240
240
|
function isWhiteSpace(node) {
|
|
241
|
-
return
|
|
241
|
+
return eff.isString(node.value) && node.value.trim() === "";
|
|
242
242
|
}
|
|
243
243
|
function isLineBreak(node) {
|
|
244
244
|
return isLiteral(node) && isWhiteSpace(node) && AST__namespace.isMultiLine(node);
|
|
@@ -246,7 +246,7 @@ function isLineBreak(node) {
|
|
|
246
246
|
function isPaddingSpaces(node) {
|
|
247
247
|
return isLiteral(node) && isWhiteSpace(node) && node.raw.includes("\n");
|
|
248
248
|
}
|
|
249
|
-
function traverseUpProp(node, predicate =
|
|
249
|
+
function traverseUpProp(node, predicate = eff.F.constTrue) {
|
|
250
250
|
const guard = (node2) => {
|
|
251
251
|
return node2.type === types.AST_NODE_TYPES.JSXAttribute && predicate(node2);
|
|
252
252
|
};
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AST_NODE_TYPES } from '@typescript-eslint/types';
|
|
2
2
|
import * as AST from '@eslint-react/ast';
|
|
3
|
-
import { O, F, isString } from '@eslint-react/
|
|
3
|
+
import { O, F, isString } from '@eslint-react/eff';
|
|
4
4
|
import * as VAR from '@eslint-react/var';
|
|
5
5
|
import { match, P } from 'ts-pattern';
|
|
6
6
|
import birecord from 'birecord';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eslint-react/jsx",
|
|
3
|
-
"version": "1.20.2-next.
|
|
3
|
+
"version": "1.20.2-next.3",
|
|
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": {
|
|
@@ -40,10 +40,10 @@
|
|
|
40
40
|
"@typescript-eslint/utils": "^8.18.1",
|
|
41
41
|
"birecord": "^0.1.1",
|
|
42
42
|
"ts-pattern": "^5.6.0",
|
|
43
|
-
"@eslint-react/ast": "1.20.2-next.
|
|
44
|
-
"@eslint-react/
|
|
45
|
-
"@eslint-react/var": "1.20.2-next.
|
|
46
|
-
"@eslint-react/types": "1.20.2-next.
|
|
43
|
+
"@eslint-react/ast": "1.20.2-next.3",
|
|
44
|
+
"@eslint-react/eff": "1.20.2-next.3",
|
|
45
|
+
"@eslint-react/var": "1.20.2-next.3",
|
|
46
|
+
"@eslint-react/types": "1.20.2-next.3"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"tsup": "^8.3.5",
|