@eslint-react/jsx 1.7.1-beta.0 → 1.7.1-beta.1

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.js CHANGED
@@ -52,7 +52,12 @@ function getElementName(node) {
52
52
  return name.name;
53
53
  }
54
54
  function getPropName(node) {
55
- return tsPattern.match(node.name).when(ast.is(ast.NodeType.JSXIdentifier), (n) => n.name).when(ast.is(ast.NodeType.JSXNamespacedName), (n) => `${n.namespace.name}:${n.name.name}`).exhaustive();
55
+ switch (node.name.type) {
56
+ case ast.NodeType.JSXIdentifier:
57
+ return node.name.name;
58
+ case ast.NodeType.JSXNamespacedName:
59
+ return `${node.name.namespace.name}:${node.name.name.name}`;
60
+ }
56
61
  }
57
62
  function getProp(props, propName, context, initialScope) {
58
63
  return findPropInAttributes(props, context, initialScope)(propName);
@@ -73,30 +78,39 @@ function findPropInProperties(properties, context, initialScope, seenProps = [])
73
78
  return (propName) => {
74
79
  return tools.O.fromNullable(
75
80
  properties.findLast((prop) => {
76
- return tsPattern.match(prop).when(ast.is(ast.NodeType.Property), (prop2) => {
77
- return "name" in prop2.key && prop2.key.name === propName;
78
- }).when(ast.is(ast.NodeType.SpreadElement), (prop2) => {
79
- return tsPattern.match(prop2.argument).when(ast.is(ast.NodeType.Identifier), (argument) => {
80
- const { name } = argument;
81
- const maybeInit = tools.O.flatMap(
82
- _var.findVariable(name, initialScope),
83
- _var.getVariableNode(0)
84
- );
85
- if (tools.O.isNone(maybeInit)) return false;
86
- const init = maybeInit.value;
87
- if (!ast.is(ast.NodeType.ObjectExpression)(init)) return false;
88
- if (seenProps.includes(name)) return false;
89
- return tools.O.isSome(
90
- findPropInProperties(init.properties, context, initialScope, [...seenProps, name])(propName)
91
- );
92
- }).when(ast.is(ast.NodeType.ObjectExpression), (argument) => {
93
- return tools.O.isSome(findPropInProperties(argument.properties, context, initialScope, seenProps)(propName));
94
- }).when(ast.is(ast.NodeType.MemberExpression), () => {
95
- }).when(ast.is(ast.NodeType.CallExpression), () => {
96
- }).otherwise(tools.F.constFalse);
97
- }).when(ast.is(ast.NodeType.RestElement), () => {
98
- return false;
99
- }).otherwise(tools.F.constFalse);
81
+ switch (true) {
82
+ case (prop.type === ast.NodeType.Property && "name" in prop.key && prop.key.name === propName):
83
+ return true;
84
+ case prop.type === ast.NodeType.SpreadElement:
85
+ switch (true) {
86
+ case prop.argument.type === ast.NodeType.Identifier: {
87
+ const { name } = prop.argument;
88
+ const maybeInit = tools.O.flatMap(
89
+ _var.findVariable(name, initialScope),
90
+ _var.getVariableNode(0)
91
+ );
92
+ if (tools.O.isNone(maybeInit)) return false;
93
+ const init = maybeInit.value;
94
+ if (!ast.is(ast.NodeType.ObjectExpression)(init)) return false;
95
+ if (seenProps.includes(name)) return false;
96
+ return tools.O.isSome(
97
+ findPropInProperties(init.properties, context, initialScope, [...seenProps, name])(propName)
98
+ );
99
+ }
100
+ case prop.argument.type === ast.NodeType.ObjectExpression: {
101
+ return tools.O.isSome(
102
+ findPropInProperties(prop.argument.properties, context, initialScope, seenProps)(propName)
103
+ );
104
+ }
105
+ default: {
106
+ return false;
107
+ }
108
+ }
109
+ case prop.type === ast.NodeType.RestElement:
110
+ return false;
111
+ default:
112
+ return false;
113
+ }
100
114
  })
101
115
  );
102
116
  };
@@ -105,25 +119,34 @@ function findPropInAttributes(attributes, context, initialScope) {
105
119
  return (propName) => {
106
120
  return tools.O.fromNullable(
107
121
  attributes.findLast((attr) => {
108
- return tsPattern.match(attr).when(ast.is(ast.NodeType.JSXAttribute), (attr2) => getPropName(attr2) === propName).when(ast.is(ast.NodeType.JSXSpreadAttribute), (attr2) => {
109
- return tsPattern.match(attr2.argument).with({ type: ast.NodeType.Identifier }, (argument) => {
110
- const { name } = argument;
111
- const maybeInit = tools.O.flatMap(
112
- _var.findVariable(name, initialScope),
113
- _var.getVariableNode(0)
114
- );
115
- if (tools.O.isNone(maybeInit)) return false;
116
- const init = maybeInit.value;
117
- if (!("properties" in init)) return false;
118
- return tools.O.isSome(findPropInProperties(init.properties, context, initialScope)(propName));
119
- }).when(ast.is(ast.NodeType.ObjectExpression), (argument) => {
120
- return tools.O.isSome(findPropInProperties(argument.properties, context, initialScope)(propName));
121
- }).when(ast.is(ast.NodeType.MemberExpression), () => {
122
- return false;
123
- }).when(ast.is(ast.NodeType.CallExpression), () => {
122
+ switch (attr.type) {
123
+ case ast.NodeType.JSXAttribute:
124
+ return getPropName(attr) === propName;
125
+ case ast.NodeType.JSXSpreadAttribute:
126
+ switch (attr.argument.type) {
127
+ case ast.NodeType.Identifier: {
128
+ const { name } = attr.argument;
129
+ const maybeInit = tools.O.flatMap(
130
+ _var.findVariable(name, initialScope),
131
+ _var.getVariableNode(0)
132
+ );
133
+ if (tools.O.isNone(maybeInit)) return false;
134
+ const init = maybeInit.value;
135
+ if (!ast.is(ast.NodeType.ObjectExpression)(init)) return false;
136
+ return tools.O.isSome(findPropInProperties(init.properties, context, initialScope)(propName));
137
+ }
138
+ case ast.NodeType.ObjectExpression:
139
+ return tools.O.isSome(findPropInProperties(attr.argument.properties, context, initialScope)(propName));
140
+ case ast.NodeType.MemberExpression:
141
+ return false;
142
+ case ast.NodeType.CallExpression:
143
+ return false;
144
+ default:
145
+ return false;
146
+ }
147
+ default:
124
148
  return false;
125
- }).otherwise(tools.F.constFalse);
126
- }).otherwise(tools.F.constFalse);
149
+ }
127
150
  })
128
151
  );
129
152
  };
package/dist/index.mjs CHANGED
@@ -30,7 +30,12 @@ function getElementName(node) {
30
30
  return name.name;
31
31
  }
32
32
  function getPropName(node) {
33
- return match(node.name).when(is(NodeType.JSXIdentifier), (n) => n.name).when(is(NodeType.JSXNamespacedName), (n) => `${n.namespace.name}:${n.name.name}`).exhaustive();
33
+ switch (node.name.type) {
34
+ case NodeType.JSXIdentifier:
35
+ return node.name.name;
36
+ case NodeType.JSXNamespacedName:
37
+ return `${node.name.namespace.name}:${node.name.name.name}`;
38
+ }
34
39
  }
35
40
  function getProp(props, propName, context, initialScope) {
36
41
  return findPropInAttributes(props, context, initialScope)(propName);
@@ -51,30 +56,39 @@ function findPropInProperties(properties, context, initialScope, seenProps = [])
51
56
  return (propName) => {
52
57
  return O.fromNullable(
53
58
  properties.findLast((prop) => {
54
- return match(prop).when(is(NodeType.Property), (prop2) => {
55
- return "name" in prop2.key && prop2.key.name === propName;
56
- }).when(is(NodeType.SpreadElement), (prop2) => {
57
- return match(prop2.argument).when(is(NodeType.Identifier), (argument) => {
58
- const { name } = argument;
59
- const maybeInit = O.flatMap(
60
- findVariable(name, initialScope),
61
- getVariableNode(0)
62
- );
63
- if (O.isNone(maybeInit)) return false;
64
- const init = maybeInit.value;
65
- if (!is(NodeType.ObjectExpression)(init)) return false;
66
- if (seenProps.includes(name)) return false;
67
- return O.isSome(
68
- findPropInProperties(init.properties, context, initialScope, [...seenProps, name])(propName)
69
- );
70
- }).when(is(NodeType.ObjectExpression), (argument) => {
71
- return O.isSome(findPropInProperties(argument.properties, context, initialScope, seenProps)(propName));
72
- }).when(is(NodeType.MemberExpression), () => {
73
- }).when(is(NodeType.CallExpression), () => {
74
- }).otherwise(F.constFalse);
75
- }).when(is(NodeType.RestElement), () => {
76
- return false;
77
- }).otherwise(F.constFalse);
59
+ switch (true) {
60
+ case (prop.type === NodeType.Property && "name" in prop.key && prop.key.name === propName):
61
+ return true;
62
+ case prop.type === NodeType.SpreadElement:
63
+ switch (true) {
64
+ case prop.argument.type === NodeType.Identifier: {
65
+ const { name } = prop.argument;
66
+ const maybeInit = O.flatMap(
67
+ findVariable(name, initialScope),
68
+ getVariableNode(0)
69
+ );
70
+ if (O.isNone(maybeInit)) return false;
71
+ const init = maybeInit.value;
72
+ if (!is(NodeType.ObjectExpression)(init)) return false;
73
+ if (seenProps.includes(name)) return false;
74
+ return O.isSome(
75
+ findPropInProperties(init.properties, context, initialScope, [...seenProps, name])(propName)
76
+ );
77
+ }
78
+ case prop.argument.type === NodeType.ObjectExpression: {
79
+ return O.isSome(
80
+ findPropInProperties(prop.argument.properties, context, initialScope, seenProps)(propName)
81
+ );
82
+ }
83
+ default: {
84
+ return false;
85
+ }
86
+ }
87
+ case prop.type === NodeType.RestElement:
88
+ return false;
89
+ default:
90
+ return false;
91
+ }
78
92
  })
79
93
  );
80
94
  };
@@ -83,25 +97,34 @@ function findPropInAttributes(attributes, context, initialScope) {
83
97
  return (propName) => {
84
98
  return O.fromNullable(
85
99
  attributes.findLast((attr) => {
86
- return match(attr).when(is(NodeType.JSXAttribute), (attr2) => getPropName(attr2) === propName).when(is(NodeType.JSXSpreadAttribute), (attr2) => {
87
- return match(attr2.argument).with({ type: NodeType.Identifier }, (argument) => {
88
- const { name } = argument;
89
- const maybeInit = O.flatMap(
90
- findVariable(name, initialScope),
91
- getVariableNode(0)
92
- );
93
- if (O.isNone(maybeInit)) return false;
94
- const init = maybeInit.value;
95
- if (!("properties" in init)) return false;
96
- return O.isSome(findPropInProperties(init.properties, context, initialScope)(propName));
97
- }).when(is(NodeType.ObjectExpression), (argument) => {
98
- return O.isSome(findPropInProperties(argument.properties, context, initialScope)(propName));
99
- }).when(is(NodeType.MemberExpression), () => {
100
- return false;
101
- }).when(is(NodeType.CallExpression), () => {
100
+ switch (attr.type) {
101
+ case NodeType.JSXAttribute:
102
+ return getPropName(attr) === propName;
103
+ case NodeType.JSXSpreadAttribute:
104
+ switch (attr.argument.type) {
105
+ case NodeType.Identifier: {
106
+ const { name } = attr.argument;
107
+ const maybeInit = O.flatMap(
108
+ findVariable(name, initialScope),
109
+ getVariableNode(0)
110
+ );
111
+ if (O.isNone(maybeInit)) return false;
112
+ const init = maybeInit.value;
113
+ if (!is(NodeType.ObjectExpression)(init)) return false;
114
+ return O.isSome(findPropInProperties(init.properties, context, initialScope)(propName));
115
+ }
116
+ case NodeType.ObjectExpression:
117
+ return O.isSome(findPropInProperties(attr.argument.properties, context, initialScope)(propName));
118
+ case NodeType.MemberExpression:
119
+ return false;
120
+ case NodeType.CallExpression:
121
+ return false;
122
+ default:
123
+ return false;
124
+ }
125
+ default:
102
126
  return false;
103
- }).otherwise(F.constFalse);
104
- }).otherwise(F.constFalse);
127
+ }
105
128
  })
106
129
  );
107
130
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eslint-react/jsx",
3
- "version": "1.7.1-beta.0",
3
+ "version": "1.7.1-beta.1",
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": "^7.18.0",
41
41
  "remeda": "^2.6.0",
42
42
  "ts-pattern": "^5.2.0",
43
- "@eslint-react/ast": "1.7.1-beta.0",
44
- "@eslint-react/var": "1.7.1-beta.0",
45
- "@eslint-react/tools": "1.7.1-beta.0",
46
- "@eslint-react/types": "1.7.1-beta.0"
43
+ "@eslint-react/tools": "1.7.1-beta.1",
44
+ "@eslint-react/ast": "1.7.1-beta.1",
45
+ "@eslint-react/types": "1.7.1-beta.1",
46
+ "@eslint-react/var": "1.7.1-beta.1"
47
47
  },
48
48
  "devDependencies": {
49
49
  "tsup": "8.2.3"