pasika 0.10.90 → 0.10.92
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/eslint/pasika/index.js +155 -55
- package/package.json +1 -1
|
@@ -6200,6 +6200,7 @@ var nextjsPackageJsonRules = {
|
|
|
6200
6200
|
|
|
6201
6201
|
// eslint/rules/prefer-enum.ts
|
|
6202
6202
|
import path44 from "path";
|
|
6203
|
+
import ts8 from "typescript";
|
|
6203
6204
|
function isConstAssertion(node) {
|
|
6204
6205
|
const typeAnnotation = node.typeAnnotation;
|
|
6205
6206
|
return typeAnnotation?.type === "TSTypeReference" && typeAnnotation.typeName?.type === "Identifier" && typeAnnotation.typeName.name === "const";
|
|
@@ -6242,12 +6243,33 @@ function rawZodDiscriminantLiteral(schemaCall, discriminator) {
|
|
|
6242
6243
|
}
|
|
6243
6244
|
return void 0;
|
|
6244
6245
|
}
|
|
6246
|
+
function isLiteralTupleAssertion(node) {
|
|
6247
|
+
if (!isConstAssertion(node)) return false;
|
|
6248
|
+
const expression = node.expression;
|
|
6249
|
+
if (expression?.type !== "ArrayExpression" || expression.elements.length < 2) return false;
|
|
6250
|
+
const values = expression.elements.map((element) => {
|
|
6251
|
+
if (element?.type !== "Literal") return void 0;
|
|
6252
|
+
return typeof element.value === "string" || typeof element.value === "number" ? element.value : void 0;
|
|
6253
|
+
});
|
|
6254
|
+
return values.every((value) => value !== void 0) && new Set(values).size >= 2;
|
|
6255
|
+
}
|
|
6256
|
+
function isTsLiteralTupleDeclaration(declaration) {
|
|
6257
|
+
if (!ts8.isVariableDeclaration(declaration) || !declaration.initializer) return false;
|
|
6258
|
+
const init = declaration.initializer;
|
|
6259
|
+
if (!ts8.isAsExpression(init) || !ts8.isTypeReferenceNode(init.type) || !ts8.isIdentifier(init.type.typeName) || init.type.typeName.text !== "const" || !ts8.isArrayLiteralExpression(init.expression) || init.expression.elements.length < 2) {
|
|
6260
|
+
return false;
|
|
6261
|
+
}
|
|
6262
|
+
const values = init.expression.elements.map(
|
|
6263
|
+
(element) => ts8.isStringLiteral(element) || ts8.isNumericLiteral(element) ? element.text : void 0
|
|
6264
|
+
);
|
|
6265
|
+
return values.every((value) => value !== void 0) && new Set(values).size >= 2;
|
|
6266
|
+
}
|
|
6245
6267
|
var preferEnumRule = {
|
|
6246
6268
|
meta: {
|
|
6247
6269
|
schema: [],
|
|
6248
6270
|
type: "problem",
|
|
6249
6271
|
docs: {
|
|
6250
|
-
description: "Require fixed sets of named string/number values to be TypeScript enums, including Zod discriminated-union discriminator values."
|
|
6272
|
+
description: "Require fixed sets of named string/number values to be TypeScript enums, including named Zod enum tuples and discriminated-union discriminator values."
|
|
6251
6273
|
}
|
|
6252
6274
|
},
|
|
6253
6275
|
create(context) {
|
|
@@ -6255,20 +6277,54 @@ var preferEnumRule = {
|
|
|
6255
6277
|
const sourceRoot = sourceRootOf(context);
|
|
6256
6278
|
if (!filename.startsWith(sourceRoot + path44.sep)) return {};
|
|
6257
6279
|
const objectSchemas = /* @__PURE__ */ new Map();
|
|
6280
|
+
const literalTuples = /* @__PURE__ */ new Set();
|
|
6281
|
+
const enumTupleUses = [];
|
|
6258
6282
|
const discriminatedUnions = [];
|
|
6259
6283
|
const reportedDiscriminants = /* @__PURE__ */ new Set();
|
|
6284
|
+
const services = typedParserServices(context.sourceCode.parserServices);
|
|
6285
|
+
function isTupleDomain(name) {
|
|
6286
|
+
if (!services) return literalTuples.has(name.name);
|
|
6287
|
+
const tsNode = services.esTreeNodeToTSNodeMap.get(name);
|
|
6288
|
+
if (!tsNode) return false;
|
|
6289
|
+
const checker = services.program.getTypeChecker();
|
|
6290
|
+
const symbol = checker.getSymbolAtLocation(tsNode);
|
|
6291
|
+
if (!symbol) return false;
|
|
6292
|
+
const original = symbol.flags === ts8.SymbolFlags.Alias ? checker.getAliasedSymbol(symbol) : symbol;
|
|
6293
|
+
return (original.declarations ?? []).some(isTsLiteralTupleDeclaration);
|
|
6294
|
+
}
|
|
6260
6295
|
return {
|
|
6261
6296
|
VariableDeclarator(node) {
|
|
6262
6297
|
const { id, init } = node;
|
|
6263
|
-
if (id?.type !== "Identifier" ||
|
|
6264
|
-
|
|
6298
|
+
if (id?.type !== "Identifier" || !init) return;
|
|
6299
|
+
if (init.type === "CallExpression" && isZodCall(init, "object")) {
|
|
6300
|
+
objectSchemas.set(id.name, init);
|
|
6301
|
+
}
|
|
6265
6302
|
},
|
|
6266
6303
|
CallExpression(node) {
|
|
6267
6304
|
if (isZodCall(node, "discriminatedUnion")) {
|
|
6268
6305
|
discriminatedUnions.push(node);
|
|
6269
6306
|
}
|
|
6307
|
+
const argument = node.arguments?.[0];
|
|
6308
|
+
if (isZodCall(node, "enum") && argument?.type === "Identifier") {
|
|
6309
|
+
enumTupleUses.push({ name: argument, node });
|
|
6310
|
+
}
|
|
6311
|
+
},
|
|
6312
|
+
TSIndexedAccessType(node) {
|
|
6313
|
+
const { objectType, indexType } = node;
|
|
6314
|
+
if (objectType?.type === "TSTypeQuery" && objectType.exprName?.type === "Identifier" && indexType?.type === "TSNumberKeyword") {
|
|
6315
|
+
enumTupleUses.push({ name: objectType.exprName, node });
|
|
6316
|
+
}
|
|
6270
6317
|
},
|
|
6271
6318
|
"Program:exit"() {
|
|
6319
|
+
const reportedTuples = /* @__PURE__ */ new Set();
|
|
6320
|
+
for (const use of enumTupleUses) {
|
|
6321
|
+
if (reportedTuples.has(use.name.name) || !isTupleDomain(use.name)) continue;
|
|
6322
|
+
reportedTuples.add(use.name.name);
|
|
6323
|
+
context.report({
|
|
6324
|
+
node: use.node,
|
|
6325
|
+
message: "A const tuple used as a named enum domain must be replaced with a TypeScript enum. See docs/next-codebase-guide/rules/constants-rule.md"
|
|
6326
|
+
});
|
|
6327
|
+
}
|
|
6272
6328
|
for (const unionCall of discriminatedUnions) {
|
|
6273
6329
|
const [discriminatorArg, optionsArg] = unionCall.arguments ?? [];
|
|
6274
6330
|
if (discriminatorArg?.type !== "Literal" || typeof discriminatorArg.value !== "string" || optionsArg?.type !== "ArrayExpression") {
|
|
@@ -6295,6 +6351,10 @@ var preferEnumRule = {
|
|
|
6295
6351
|
},
|
|
6296
6352
|
TSAsExpression(node) {
|
|
6297
6353
|
if (!isConstAssertion(node)) return;
|
|
6354
|
+
if (isLiteralTupleAssertion(node) && node.parent?.type === "VariableDeclarator") {
|
|
6355
|
+
const { id } = node.parent;
|
|
6356
|
+
if (id.type === "Identifier") literalTuples.add(id.name);
|
|
6357
|
+
}
|
|
6298
6358
|
const expression = node.expression;
|
|
6299
6359
|
if (!expression || expression.type !== "ObjectExpression") return;
|
|
6300
6360
|
if (expression.properties.length === 0) return;
|
|
@@ -6324,7 +6384,7 @@ var preferEnumRule = {
|
|
|
6324
6384
|
};
|
|
6325
6385
|
|
|
6326
6386
|
// eslint/rules/prefer-object-destructuring.ts
|
|
6327
|
-
import
|
|
6387
|
+
import ts9 from "typescript";
|
|
6328
6388
|
var DOC5 = "See docs/next-codebase-guide/rules/redundant-aliases-rule.md";
|
|
6329
6389
|
function hasTypeAnnotation(identifier) {
|
|
6330
6390
|
return "typeAnnotation" in identifier && identifier.typeAnnotation !== void 0;
|
|
@@ -6358,13 +6418,17 @@ function canGroupSource(source) {
|
|
|
6358
6418
|
function isGroupedUsageSource(source) {
|
|
6359
6419
|
return source.type === "Identifier" || source.type === "ThisExpression";
|
|
6360
6420
|
}
|
|
6421
|
+
function supportsSinglePropertySource(source) {
|
|
6422
|
+
if (isGroupedUsageSource(source) || source.type === "CallExpression") return true;
|
|
6423
|
+
return source.type === "MemberExpression" && !source.computed && !source.optional && source.property.type === "Identifier" && supportsSinglePropertySource(source.object);
|
|
6424
|
+
}
|
|
6361
6425
|
function rootIdentifierName(node) {
|
|
6362
6426
|
if (node.type === "Identifier") return node.name;
|
|
6363
6427
|
if (node.type !== "MemberExpression" || node.object.type === "Super") return void 0;
|
|
6364
6428
|
return rootIdentifierName(node.object);
|
|
6365
6429
|
}
|
|
6366
6430
|
function isCompliantLocalName(propertyName5) {
|
|
6367
|
-
return !propertyName5.includes("_");
|
|
6431
|
+
return !propertyName5.includes("_") || /^[A-Z][A-Z0-9]*(?:_[A-Z0-9]+)*$/u.test(propertyName5);
|
|
6368
6432
|
}
|
|
6369
6433
|
function propertyNameOf(node) {
|
|
6370
6434
|
if (node.type !== "Property" || node.computed) return void 0;
|
|
@@ -6413,8 +6477,8 @@ function enumValueResolver(context) {
|
|
|
6413
6477
|
const checker = services.program.getTypeChecker();
|
|
6414
6478
|
const { esTreeNodeToTSNodeMap: nodeMap } = services;
|
|
6415
6479
|
const isEnumSymbol = (symbol) => {
|
|
6416
|
-
const resolved = symbol.flags ===
|
|
6417
|
-
return (resolved.declarations ?? []).some((declaration) =>
|
|
6480
|
+
const resolved = symbol.flags === ts9.SymbolFlags.Alias ? checker.getAliasedSymbol(symbol) : symbol;
|
|
6481
|
+
return (resolved.declarations ?? []).some((declaration) => ts9.isEnumDeclaration(declaration));
|
|
6418
6482
|
};
|
|
6419
6483
|
return (node) => {
|
|
6420
6484
|
const tsNode = nodeMap.get(node);
|
|
@@ -6607,8 +6671,8 @@ function groupedDestructuringSelections(context, first, isEnumValue) {
|
|
|
6607
6671
|
function declarationTerminator(context, declaration) {
|
|
6608
6672
|
return context.sourceCode.getText(declaration).trimEnd().endsWith(";") ? ";" : "";
|
|
6609
6673
|
}
|
|
6610
|
-
function
|
|
6611
|
-
return `"${binding.
|
|
6674
|
+
function singlePropertyMessage(binding) {
|
|
6675
|
+
return `"${binding.propertyName}" is the only property bound from "${binding.sourceText}". Read "${binding.sourceText}.${binding.propertyName}" directly instead of creating a local binding. ${DOC5}`;
|
|
6612
6676
|
}
|
|
6613
6677
|
function groupMessage(bindings) {
|
|
6614
6678
|
const firstBinding = bindings[0];
|
|
@@ -6628,7 +6692,7 @@ var preferObjectDestructuringRule = {
|
|
|
6628
6692
|
type: "problem",
|
|
6629
6693
|
fixable: "code",
|
|
6630
6694
|
docs: {
|
|
6631
|
-
description: "
|
|
6695
|
+
description: "Prefer direct access for one property and shared destructuring for related property reads."
|
|
6632
6696
|
}
|
|
6633
6697
|
},
|
|
6634
6698
|
create(context) {
|
|
@@ -6638,7 +6702,7 @@ var preferObjectDestructuringRule = {
|
|
|
6638
6702
|
const usageScopes = [];
|
|
6639
6703
|
const currentUsageScope = () => usageScopes.at(-1);
|
|
6640
6704
|
const enterUsageScope = (node) => {
|
|
6641
|
-
usageScopes.push({ node, objects: /* @__PURE__ */ new Map() });
|
|
6705
|
+
usageScopes.push({ node, objects: /* @__PURE__ */ new Map(), singleProperties: [] });
|
|
6642
6706
|
};
|
|
6643
6707
|
const enterUsageBarrier = () => {
|
|
6644
6708
|
usageScopes.push(void 0);
|
|
@@ -6685,6 +6749,31 @@ ${indentation}`;
|
|
|
6685
6749
|
}
|
|
6686
6750
|
});
|
|
6687
6751
|
}
|
|
6752
|
+
for (const binding of scope.singleProperties) {
|
|
6753
|
+
const fromSameSource = scope.singleProperties.filter(({ sourceText }) => sourceText === binding.sourceText);
|
|
6754
|
+
if (fromSameSource[0] !== binding) continue;
|
|
6755
|
+
const usage = scope.objects.get(binding.sourceText);
|
|
6756
|
+
const usedProperties = usage?.propertyNames;
|
|
6757
|
+
if (usedProperties && usedProperties.size > 1 && usage.directMembers.length > 0) {
|
|
6758
|
+
if (scope.singleProperties.some(
|
|
6759
|
+
(item) => item.node.type === "ObjectPattern" && item.sourceText === binding.sourceText
|
|
6760
|
+
)) {
|
|
6761
|
+
continue;
|
|
6762
|
+
}
|
|
6763
|
+
}
|
|
6764
|
+
if (usedProperties && usedProperties.size > 1) {
|
|
6765
|
+
context.report({ node: binding.node, message: scopeUsageMessage(binding.sourceText, usedProperties) });
|
|
6766
|
+
continue;
|
|
6767
|
+
}
|
|
6768
|
+
if (fromSameSource.length > 1) {
|
|
6769
|
+
const names = new Set(fromSameSource.map(({ propertyName: propertyName5 }) => propertyName5));
|
|
6770
|
+
if (names.size > 1) {
|
|
6771
|
+
context.report({ node: binding.node, message: scopeUsageMessage(binding.sourceText, names) });
|
|
6772
|
+
continue;
|
|
6773
|
+
}
|
|
6774
|
+
}
|
|
6775
|
+
context.report({ node: binding.node, message: singlePropertyMessage(binding) });
|
|
6776
|
+
}
|
|
6688
6777
|
};
|
|
6689
6778
|
return {
|
|
6690
6779
|
Program: enterUsageScope,
|
|
@@ -6714,7 +6803,20 @@ ${indentation}`;
|
|
|
6714
6803
|
const selection = destructuringSelection(context, node, isEnumValue);
|
|
6715
6804
|
if (selection) {
|
|
6716
6805
|
const group = groupedDestructuringSelections(context, selection, isEnumValue);
|
|
6717
|
-
if (group.length <= 1)
|
|
6806
|
+
if (group.length <= 1) {
|
|
6807
|
+
if (node.kind === "const" && selection.propertyNames.length === 1 && supportsSinglePropertySource(selection.source)) {
|
|
6808
|
+
const declarator = node.declarations[0];
|
|
6809
|
+
const propertyName5 = selection.propertyNames[0];
|
|
6810
|
+
if (declarator && propertyName5) {
|
|
6811
|
+
currentUsageScope()?.singleProperties.push({
|
|
6812
|
+
node: declarator.id,
|
|
6813
|
+
sourceText: selection.sourceText,
|
|
6814
|
+
propertyName: propertyName5
|
|
6815
|
+
});
|
|
6816
|
+
}
|
|
6817
|
+
}
|
|
6818
|
+
return;
|
|
6819
|
+
}
|
|
6718
6820
|
for (const item of group.slice(1)) grouped.add(item.declaration);
|
|
6719
6821
|
const lastDeclaration = group.at(-1)?.declaration;
|
|
6720
6822
|
if (!lastDeclaration) return;
|
|
@@ -6781,13 +6883,11 @@ ${indentation}`;
|
|
|
6781
6883
|
}
|
|
6782
6884
|
}
|
|
6783
6885
|
for (const binding of bindings) {
|
|
6784
|
-
if (!
|
|
6785
|
-
|
|
6886
|
+
if (node.kind !== "const" || !supportsSinglePropertySource(binding.source)) continue;
|
|
6887
|
+
currentUsageScope()?.singleProperties.push({
|
|
6786
6888
|
node: binding.declarator,
|
|
6787
|
-
|
|
6788
|
-
|
|
6789
|
-
return fixer.replaceText(binding.declarator, `{ ${binding.bindingText} } = ${binding.sourceText}`);
|
|
6790
|
-
}
|
|
6889
|
+
sourceText: binding.sourceText,
|
|
6890
|
+
propertyName: binding.propertyName
|
|
6791
6891
|
});
|
|
6792
6892
|
}
|
|
6793
6893
|
}
|
|
@@ -7329,7 +7429,7 @@ var rootSupportPlacementRule = {
|
|
|
7329
7429
|
|
|
7330
7430
|
// eslint/rules/route-handler-shape.ts
|
|
7331
7431
|
import path49 from "path";
|
|
7332
|
-
import
|
|
7432
|
+
import ts10 from "typescript";
|
|
7333
7433
|
var HTTP_METHODS2 = /* @__PURE__ */ new Set(["GET", "POST", "PUT", "PATCH", "DELETE", "HEAD", "OPTIONS"]);
|
|
7334
7434
|
var REQUIRED_BOUNDARY = "withResponse";
|
|
7335
7435
|
function isFunctionLike(node) {
|
|
@@ -7347,33 +7447,33 @@ function findHandler(node) {
|
|
|
7347
7447
|
return void 0;
|
|
7348
7448
|
}
|
|
7349
7449
|
function isLoop(node) {
|
|
7350
|
-
return
|
|
7450
|
+
return ts10.isForStatement(node) || ts10.isForOfStatement(node) || ts10.isForInStatement(node) || ts10.isWhileStatement(node) || ts10.isDoStatement(node);
|
|
7351
7451
|
}
|
|
7352
7452
|
function isFunctionBoundary(node) {
|
|
7353
|
-
return
|
|
7453
|
+
return ts10.isFunctionExpression(node) || ts10.isArrowFunction(node) || ts10.isFunctionDeclaration(node);
|
|
7354
7454
|
}
|
|
7355
7455
|
function analyzeHandlerBody(body, sourceText) {
|
|
7356
7456
|
const start = body.range?.[0] ?? 0;
|
|
7357
7457
|
const end = body.range?.[1] ?? sourceText.length;
|
|
7358
|
-
const sourceFile =
|
|
7458
|
+
const sourceFile = ts10.createSourceFile(
|
|
7359
7459
|
"route.ts",
|
|
7360
7460
|
sourceText.slice(start, end),
|
|
7361
|
-
|
|
7461
|
+
ts10.ScriptTarget.Latest,
|
|
7362
7462
|
true,
|
|
7363
|
-
|
|
7463
|
+
ts10.ScriptKind.TS
|
|
7364
7464
|
);
|
|
7365
7465
|
const kinds = /* @__PURE__ */ new Set();
|
|
7366
7466
|
const calledNames = /* @__PURE__ */ new Set();
|
|
7367
7467
|
const visit = (node) => {
|
|
7368
|
-
if (
|
|
7468
|
+
if (ts10.isTryStatement(node)) kinds.add("try");
|
|
7369
7469
|
if (isLoop(node)) kinds.add("loop");
|
|
7370
|
-
if (
|
|
7371
|
-
if (
|
|
7470
|
+
if (ts10.isIfStatement(node)) kinds.add("if");
|
|
7471
|
+
if (ts10.isCallExpression(node) && ts10.isPropertyAccessExpression(node.expression) && node.expression.name.text === "map") {
|
|
7372
7472
|
kinds.add("map");
|
|
7373
7473
|
}
|
|
7374
|
-
if (
|
|
7474
|
+
if (ts10.isCallExpression(node) && ts10.isIdentifier(node.expression)) calledNames.add(node.expression.text);
|
|
7375
7475
|
if (isFunctionBoundary(node)) return;
|
|
7376
|
-
|
|
7476
|
+
ts10.forEachChild(node, visit);
|
|
7377
7477
|
};
|
|
7378
7478
|
visit(sourceFile);
|
|
7379
7479
|
return { kinds, calledNames };
|
|
@@ -7535,38 +7635,38 @@ var schemaCasingRule = {
|
|
|
7535
7635
|
|
|
7536
7636
|
// eslint/rules/sole-state-owner.ts
|
|
7537
7637
|
import path51 from "path";
|
|
7538
|
-
import
|
|
7638
|
+
import ts11 from "typescript";
|
|
7539
7639
|
function findStateHooks(node) {
|
|
7540
7640
|
const hooks = [];
|
|
7541
7641
|
const visit = (child) => {
|
|
7542
|
-
if (
|
|
7543
|
-
if (
|
|
7642
|
+
if (ts11.isCallExpression(child) && ts11.isIdentifier(child.expression) && child.expression.text === "useState") {
|
|
7643
|
+
if (ts11.isVariableDeclaration(child.parent)) {
|
|
7544
7644
|
const { name } = child.parent;
|
|
7545
|
-
if (
|
|
7645
|
+
if (ts11.isArrayBindingPattern(name) && name.elements.length >= 2) {
|
|
7546
7646
|
const value = name.elements[0];
|
|
7547
7647
|
const updater = name.elements[1];
|
|
7548
|
-
if (value && updater &&
|
|
7648
|
+
if (value && updater && ts11.isBindingElement(value) && ts11.isBindingElement(updater)) {
|
|
7549
7649
|
const valueName = value.name;
|
|
7550
7650
|
const updaterName = updater.name;
|
|
7551
|
-
if (
|
|
7651
|
+
if (ts11.isIdentifier(valueName) && ts11.isIdentifier(updaterName)) {
|
|
7552
7652
|
hooks.push({ value: valueName.text, updater: updaterName.text });
|
|
7553
7653
|
}
|
|
7554
7654
|
}
|
|
7555
7655
|
}
|
|
7556
7656
|
}
|
|
7557
7657
|
}
|
|
7558
|
-
|
|
7658
|
+
ts11.forEachChild(child, visit);
|
|
7559
7659
|
};
|
|
7560
7660
|
visit(node);
|
|
7561
7661
|
return hooks;
|
|
7562
7662
|
}
|
|
7563
7663
|
function isHookUsage(node, hook) {
|
|
7564
|
-
if (
|
|
7664
|
+
if (ts11.isCallExpression(node) && ts11.isIdentifier(node.expression) && node.expression.text === hook.updater) {
|
|
7565
7665
|
return "updater";
|
|
7566
7666
|
}
|
|
7567
|
-
if (
|
|
7667
|
+
if (ts11.isIdentifier(node) && node.text === hook.value) {
|
|
7568
7668
|
const parent = node.parent;
|
|
7569
|
-
if (
|
|
7669
|
+
if (ts11.isBindingElement(parent) || ts11.isPropertyAccessExpression(parent) || ts11.isShorthandPropertyAssignment(parent)) {
|
|
7570
7670
|
return void 0;
|
|
7571
7671
|
}
|
|
7572
7672
|
return "value";
|
|
@@ -7576,16 +7676,16 @@ function isHookUsage(node, hook) {
|
|
|
7576
7676
|
function topLevelJsxChildren(initial) {
|
|
7577
7677
|
if (!initial) return void 0;
|
|
7578
7678
|
let expression = initial;
|
|
7579
|
-
while (
|
|
7580
|
-
if (
|
|
7679
|
+
while (ts11.isParenthesizedExpression(expression)) expression = expression.expression;
|
|
7680
|
+
if (ts11.isJsxFragment(expression)) {
|
|
7581
7681
|
const children = expression.children.filter(
|
|
7582
|
-
(c) => !
|
|
7682
|
+
(c) => !ts11.isJsxText(c) && !ts11.isJsxSpreadAttribute(c)
|
|
7583
7683
|
);
|
|
7584
7684
|
return { root: expression, children };
|
|
7585
7685
|
}
|
|
7586
|
-
if (
|
|
7686
|
+
if (ts11.isJsxElement(expression)) {
|
|
7587
7687
|
const children = expression.children.filter(
|
|
7588
|
-
(c) => !
|
|
7688
|
+
(c) => !ts11.isJsxText(c) && !ts11.isJsxSpreadAttribute(c)
|
|
7589
7689
|
);
|
|
7590
7690
|
return { root: expression, children };
|
|
7591
7691
|
}
|
|
@@ -7599,8 +7699,8 @@ function collectUsesIn(child, hook) {
|
|
|
7599
7699
|
positions.push(node);
|
|
7600
7700
|
count += 1;
|
|
7601
7701
|
}
|
|
7602
|
-
if (
|
|
7603
|
-
|
|
7702
|
+
if (ts11.isFunctionDeclaration(node) || ts11.isClassDeclaration(node)) return;
|
|
7703
|
+
ts11.forEachChild(node, visit);
|
|
7604
7704
|
};
|
|
7605
7705
|
visit(child);
|
|
7606
7706
|
return { positions, count };
|
|
@@ -7639,18 +7739,18 @@ var soleStateOwnerRule = {
|
|
|
7639
7739
|
}
|
|
7640
7740
|
};
|
|
7641
7741
|
function analyzeSoleOwner(declaration, hook) {
|
|
7642
|
-
const body =
|
|
7643
|
-
if (!body || !
|
|
7742
|
+
const body = ts11.isFunctionDeclaration(declaration) ? declaration.body : void 0;
|
|
7743
|
+
if (!body || !ts11.isBlock(body)) return void 0;
|
|
7644
7744
|
const returns = [];
|
|
7645
7745
|
const visit = (node) => {
|
|
7646
|
-
if (node !== body && (
|
|
7647
|
-
if (
|
|
7648
|
-
|
|
7746
|
+
if (node !== body && (ts11.isFunctionLike(node) || ts11.isClassLike(node))) return;
|
|
7747
|
+
if (ts11.isReturnStatement(node)) returns.push(node);
|
|
7748
|
+
ts11.forEachChild(node, visit);
|
|
7649
7749
|
};
|
|
7650
7750
|
visit(body);
|
|
7651
7751
|
if (returns.length !== 1) return void 0;
|
|
7652
7752
|
const single = returns[0];
|
|
7653
|
-
if (!single?.expression || !
|
|
7753
|
+
if (!single?.expression || !ts11.isExpression(single.expression)) return void 0;
|
|
7654
7754
|
const returnExpression = single.expression;
|
|
7655
7755
|
const root = topLevelJsxChildren(returnExpression);
|
|
7656
7756
|
if (!root || root.children.length === 0) return void 0;
|
|
@@ -7673,11 +7773,11 @@ function usesOutsideJsx(declaration, hook, children) {
|
|
|
7673
7773
|
let outside = false;
|
|
7674
7774
|
const visit = (node) => {
|
|
7675
7775
|
if (outside) return;
|
|
7676
|
-
if (node !== declaration && (
|
|
7776
|
+
if (node !== declaration && (ts11.isFunctionDeclaration(node) || ts11.isClassDeclaration(node))) return;
|
|
7677
7777
|
if (isHookUsage(node, hook)) {
|
|
7678
7778
|
let current = node;
|
|
7679
7779
|
let isInJsxChild = false;
|
|
7680
|
-
while (!
|
|
7780
|
+
while (!ts11.isSourceFile(current)) {
|
|
7681
7781
|
if (children.includes(current)) {
|
|
7682
7782
|
isInJsxChild = true;
|
|
7683
7783
|
break;
|
|
@@ -7686,7 +7786,7 @@ function usesOutsideJsx(declaration, hook, children) {
|
|
|
7686
7786
|
}
|
|
7687
7787
|
if (!isInJsxChild) outside = true;
|
|
7688
7788
|
}
|
|
7689
|
-
|
|
7789
|
+
ts11.forEachChild(node, visit);
|
|
7690
7790
|
};
|
|
7691
7791
|
visit(declaration);
|
|
7692
7792
|
return outside;
|