@eslint-react/var 5.5.6-next.0 → 5.6.0-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.
Files changed (2) hide show
  1. package/dist/index.js +20 -150
  2. package/package.json +3 -3
package/dist/index.js CHANGED
@@ -2,7 +2,6 @@ import { Check, Compare, Extract, Traverse, isOneOf } from "@eslint-react/ast";
2
2
  import { DefinitionType } from "@typescript-eslint/scope-manager";
3
3
  import { AST_NODE_TYPES } from "@typescript-eslint/types";
4
4
  import { findVariable, getStaticValue } from "@typescript-eslint/utils/ast-utils";
5
- import { P, match } from "ts-pattern";
6
5
 
7
6
  //#region src/resolve.ts
8
7
  /**
@@ -125,27 +124,28 @@ function computeObjectType(context, node) {
125
124
  case AST_NODE_TYPES.SequenceExpression:
126
125
  if (node.expressions.length === 0) return null;
127
126
  return computeObjectType(context, node.expressions[node.expressions.length - 1] ?? null);
128
- case AST_NODE_TYPES.CallExpression:
127
+ case AST_NODE_TYPES.CallExpression: {
128
+ const callee = Extract.unwrap(node.callee);
129
129
  switch (true) {
130
- case Check.isIdentifier("Boolean")(node.callee): return null;
131
- case Check.isIdentifier("String")(node.callee): return null;
132
- case Check.isIdentifier("Number")(node.callee): return null;
133
- case Check.isIdentifier("Object")(node.callee): return {
130
+ case Check.isIdentifier("Boolean")(callee): return null;
131
+ case Check.isIdentifier("String")(callee): return null;
132
+ case Check.isIdentifier("Number")(callee): return null;
133
+ case Check.isIdentifier("Object")(callee): return {
134
134
  kind: "plain",
135
135
  node
136
136
  };
137
- case Check.isIdentifier("Array")(node.callee): return {
137
+ case Check.isIdentifier("Array")(callee): return {
138
138
  kind: "array",
139
139
  node
140
140
  };
141
- case Check.isIdentifier("RegExp")(node.callee): return {
141
+ case Check.isIdentifier("RegExp")(callee): return {
142
142
  kind: "regexp",
143
143
  node
144
144
  };
145
145
  }
146
- if (node.callee.type === AST_NODE_TYPES.MemberExpression && node.callee.object.type === AST_NODE_TYPES.Identifier && node.callee.property.type === AST_NODE_TYPES.Identifier) {
147
- const objName = node.callee.object.name;
148
- const methodName = node.callee.property.name;
146
+ if (callee.type === AST_NODE_TYPES.MemberExpression && callee.object.type === AST_NODE_TYPES.Identifier && callee.property.type === AST_NODE_TYPES.Identifier) {
147
+ const objName = callee.object.name;
148
+ const methodName = callee.property.name;
149
149
  switch (objName) {
150
150
  case "Array":
151
151
  if (methodName === "from" || methodName === "of") return {
@@ -166,139 +166,13 @@ function computeObjectType(context, node) {
166
166
  node,
167
167
  reason: "call-expression"
168
168
  };
169
+ }
169
170
  default:
170
171
  if (!("expression" in node) || typeof node.expression !== "object") return null;
171
172
  return computeObjectType(context, node.expression);
172
173
  }
173
174
  }
174
175
 
175
- //#endregion
176
- //#region ../../.pkgs/eff/dist/index.js
177
- /**
178
- * Returns its argument.
179
- *
180
- * @param x - The value to return.
181
- * @returns The input value unchanged.
182
- */
183
- function identity(x) {
184
- return x;
185
- }
186
- /**
187
- * Creates a function that can be used in a data-last (aka `pipe`able) or
188
- * data-first style.
189
- *
190
- * The first parameter to `dual` is either the arity of the uncurried function
191
- * or a predicate that determines if the function is being used in a data-first
192
- * or data-last style.
193
- *
194
- * Using the arity is the most common use case, but there are some cases where
195
- * you may want to use a predicate. For example, if you have a function that
196
- * takes an optional argument, you can use a predicate to determine if the
197
- * function is being used in a data-first or data-last style.
198
- *
199
- * You can pass either the arity of the uncurried function or a predicate
200
- * which determines if the function is being used in a data-first or
201
- * data-last style.
202
- *
203
- * **Example** (Using arity to determine data-first or data-last style)
204
- *
205
- * ```ts
206
- * import { dual, pipe } from "effect/Function"
207
- *
208
- * const sum = dual<
209
- * (that: number) => (self: number) => number,
210
- * (self: number, that: number) => number
211
- * >(2, (self, that) => self + that)
212
- *
213
- * console.log(sum(2, 3)) // 5
214
- * console.log(pipe(2, sum(3))) // 5
215
- * ```
216
- *
217
- * **Example** (Using call signatures to define the overloads)
218
- *
219
- * ```ts
220
- * import { dual, pipe } from "effect/Function"
221
- *
222
- * const sum: {
223
- * (that: number): (self: number) => number
224
- * (self: number, that: number): number
225
- * } = dual(2, (self: number, that: number): number => self + that)
226
- *
227
- * console.log(sum(2, 3)) // 5
228
- * console.log(pipe(2, sum(3))) // 5
229
- * ```
230
- *
231
- * **Example** (Using a predicate to determine data-first or data-last style)
232
- *
233
- * ```ts
234
- * import { dual, pipe } from "effect/Function"
235
- *
236
- * const sum = dual<
237
- * (that: number) => (self: number) => number,
238
- * (self: number, that: number) => number
239
- * >(
240
- * (args) => args.length === 2,
241
- * (self, that) => self + that
242
- * )
243
- *
244
- * console.log(sum(2, 3)) // 5
245
- * console.log(pipe(2, sum(3))) // 5
246
- * ```
247
- *
248
- * @param arity - The arity of the uncurried function or a predicate that determines if the function is being used in a data-first or data-last style.
249
- * @param body - The function to be curried.
250
- * @since 1.0.0
251
- */
252
- const dual = function(arity, body) {
253
- if (typeof arity === "function") return function() {
254
- return arity(arguments) ? body.apply(this, arguments) : ((self) => body(self, ...arguments));
255
- };
256
- switch (arity) {
257
- case 0:
258
- case 1: throw new RangeError(`Invalid arity ${arity}`);
259
- case 2: return function(a, b) {
260
- if (arguments.length >= 2) return body(a, b);
261
- return function(self) {
262
- return body(self, a);
263
- };
264
- };
265
- case 3: return function(a, b, c) {
266
- if (arguments.length >= 3) return body(a, b, c);
267
- return function(self) {
268
- return body(self, a, b);
269
- };
270
- };
271
- default: return function() {
272
- if (arguments.length >= arity) return body.apply(this, arguments);
273
- const args = arguments;
274
- return function(self) {
275
- return body(self, ...args);
276
- };
277
- };
278
- }
279
- };
280
- /**
281
- * Composes two functions, `ab` and `bc` into a single function that takes in an argument `a` of type `A` and returns a result of type `C`.
282
- * The result is obtained by first applying the `ab` function to `a` and then applying the `bc` function to the result of `ab`.
283
- *
284
- * @param self - The first function to apply (or the composed function in data-last style).
285
- * @param bc - The second function to apply.
286
- * @returns A composed function that applies both functions in sequence.
287
- * @example
288
- * ```ts
289
- * import * as assert from "node:assert"
290
- * import { compose } from "effect/Function"
291
- *
292
- * const increment = (n: number) => n + 1;
293
- * const square = (n: number) => n * n;
294
- *
295
- * assert.strictEqual(compose(increment, square)(2), 9);
296
- * ```
297
- *
298
- * @since 1.0.0
299
- */
300
- const compose = dual(2, (ab, bc) => (a) => bc(ab(a)));
301
-
302
176
  //#endregion
303
177
  //#region src/get-require-expression-arguments.ts
304
178
  /**
@@ -308,17 +182,13 @@ const compose = dual(2, (ab, bc) => (a) => bc(ab(a)));
308
182
  * @internal
309
183
  */
310
184
  function getRequireExpressionArguments(node) {
311
- return match(node).with({
312
- type: AST_NODE_TYPES.CallExpression,
313
- arguments: P.select(),
314
- callee: {
315
- type: AST_NODE_TYPES.Identifier,
316
- name: "require"
317
- }
318
- }, identity).with({
319
- type: AST_NODE_TYPES.MemberExpression,
320
- object: P.select()
321
- }, getRequireExpressionArguments).otherwise(() => null);
185
+ const unwrapped = Extract.unwrap(node);
186
+ if (unwrapped.type === AST_NODE_TYPES.CallExpression) {
187
+ const callee = Extract.unwrap(unwrapped.callee);
188
+ if (callee.type === AST_NODE_TYPES.Identifier && callee.name === "require") return unwrapped.arguments;
189
+ }
190
+ if (unwrapped.type === AST_NODE_TYPES.MemberExpression) return getRequireExpressionArguments(unwrapped.object);
191
+ return null;
322
192
  }
323
193
 
324
194
  //#endregion
@@ -432,7 +302,7 @@ function resolveImportSource(name, initialScope, visited = /* @__PURE__ */ new S
432
302
  if (latestDef == null) return null;
433
303
  const { node, parent } = latestDef;
434
304
  if (node.type === AST_NODE_TYPES.VariableDeclarator && node.init != null) {
435
- const { init } = node;
305
+ const init = Extract.unwrap(node.init);
436
306
  if (init.type === AST_NODE_TYPES.MemberExpression && init.object.type === AST_NODE_TYPES.Identifier) return resolveImportSource(init.object.name, initialScope, visited);
437
307
  if (init.type === AST_NODE_TYPES.Identifier) return resolveImportSource(init.name, initialScope, visited);
438
308
  const arg0 = getRequireExpressionArguments(init)?.[0];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eslint-react/var",
3
- "version": "5.5.6-next.0",
3
+ "version": "5.6.0-beta.2",
4
4
  "description": "ESLint React's TSESTree AST utility module for static analysis of variables.",
5
5
  "homepage": "https://github.com/Rel1cx/eslint-react",
6
6
  "bugs": {
@@ -33,8 +33,8 @@
33
33
  "@typescript-eslint/types": "^8.59.1",
34
34
  "@typescript-eslint/utils": "^8.59.1",
35
35
  "ts-pattern": "^5.9.0",
36
- "@eslint-react/ast": "5.5.6-next.0",
37
- "@eslint-react/eslint": "5.5.6-next.0"
36
+ "@eslint-react/ast": "5.6.0-beta.2",
37
+ "@eslint-react/eslint": "5.6.0-beta.2"
38
38
  },
39
39
  "devDependencies": {
40
40
  "@typescript-eslint/parser": "^8.59.1",