@pobammer-ts/eslint-cease-nonsense-rules 1.14.0 → 1.15.0
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/README.md +74 -1
- package/dist/build-metadata.json +3 -3
- package/dist/constants/react-sources.d.ts +4 -0
- package/dist/index.d.ts +5 -3
- package/dist/index.js +1430 -271
- package/dist/oxfmt-sync.d.ts +0 -1
- package/dist/oxfmt-worker.d.ts +0 -1
- package/dist/oxfmt-worker.js +0 -2
- package/dist/recognizers/camel-case-detector.d.ts +0 -1
- package/dist/recognizers/code-recognizer.d.ts +0 -1
- package/dist/recognizers/contains-detector.d.ts +0 -1
- package/dist/recognizers/detector.d.ts +0 -1
- package/dist/recognizers/end-with-detector.d.ts +0 -1
- package/dist/recognizers/javascript-footprint.d.ts +0 -1
- package/dist/recognizers/keywords-detector.d.ts +0 -1
- package/dist/rules/ban-instances.d.ts +0 -1
- package/dist/rules/ban-react-fc.d.ts +0 -1
- package/dist/rules/enforce-ianitor-check-type.d.ts +0 -1
- package/dist/rules/fast-format.d.ts +0 -1
- package/dist/rules/no-async-constructor.d.ts +0 -1
- package/dist/rules/no-color3-constructor.d.ts +0 -1
- package/dist/rules/no-commented-code.d.ts +0 -1
- package/dist/rules/no-god-components.d.ts +0 -1
- package/dist/rules/no-identity-map.d.ts +0 -1
- package/dist/rules/no-instance-methods-without-this.d.ts +0 -1
- package/dist/rules/no-memo-children.d.ts +19 -0
- package/dist/rules/no-print.d.ts +0 -1
- package/dist/rules/no-shorthand-names.d.ts +0 -1
- package/dist/rules/no-useless-use-spring.d.ts +0 -1
- package/dist/rules/no-warn.d.ts +0 -1
- package/dist/rules/prefer-class-properties.d.ts +0 -1
- package/dist/rules/prefer-early-return.d.ts +0 -1
- package/dist/rules/prefer-enum-item.d.ts +1 -1
- package/dist/rules/prefer-module-scope-constants.d.ts +0 -1
- package/dist/rules/prefer-pascal-case-enums.d.ts +0 -1
- package/dist/rules/prefer-pattern-replacements.d.ts +0 -1
- package/dist/rules/prefer-sequence-overloads.d.ts +0 -1
- package/dist/rules/prefer-singular-enums.d.ts +0 -1
- package/dist/rules/prefer-udim2-shorthand.d.ts +0 -1
- package/dist/rules/react-hooks-strict-return.d.ts +0 -1
- package/dist/rules/require-named-effect-functions.d.ts +1 -4
- package/dist/rules/require-paired-calls.d.ts +0 -1
- package/dist/rules/require-react-component-keys.d.ts +0 -1
- package/dist/rules/require-react-display-names.d.ts +1 -2
- package/dist/rules/strict-component-boundaries.d.ts +5 -2
- package/dist/rules/use-exhaustive-dependencies.d.ts +0 -1
- package/dist/rules/use-hook-at-top-level.d.ts +0 -1
- package/dist/types/environment-mode.d.ts +3 -0
- package/dist/utilities/casing-utilities.d.ts +0 -1
- package/dist/utilities/configure-utilities.d.ts +7 -1
- package/dist/utilities/create-rule.d.ts +0 -1
- package/dist/utilities/format-utilities.d.ts +0 -1
- package/dist/utilities/pattern-replacement/constant-folder.d.ts +0 -1
- package/dist/utilities/pattern-replacement/index.d.ts +0 -1
- package/dist/utilities/pattern-replacement/pattern-matcher.d.ts +0 -1
- package/dist/utilities/pattern-replacement/pattern-parser.d.ts +0 -1
- package/dist/utilities/pattern-replacement/pattern-types.d.ts +0 -1
- package/dist/utilities/pattern-replacement/replacement-generator.d.ts +0 -1
- package/dist/utilities/resolve-import.d.ts +0 -1
- package/package.json +6 -4
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -724
- package/dist/oxfmt-sync.d.ts.map +0 -1
- package/dist/oxfmt-worker.d.ts.map +0 -1
- package/dist/oxfmt-worker.js.map +0 -10
- package/dist/recognizers/camel-case-detector.d.ts.map +0 -1
- package/dist/recognizers/code-recognizer.d.ts.map +0 -1
- package/dist/recognizers/contains-detector.d.ts.map +0 -1
- package/dist/recognizers/detector.d.ts.map +0 -1
- package/dist/recognizers/end-with-detector.d.ts.map +0 -1
- package/dist/recognizers/javascript-footprint.d.ts.map +0 -1
- package/dist/recognizers/keywords-detector.d.ts.map +0 -1
- package/dist/rules/ban-instances.d.ts.map +0 -1
- package/dist/rules/ban-react-fc.d.ts.map +0 -1
- package/dist/rules/enforce-ianitor-check-type.d.ts.map +0 -1
- package/dist/rules/fast-format.d.ts.map +0 -1
- package/dist/rules/no-async-constructor.d.ts.map +0 -1
- package/dist/rules/no-color3-constructor.d.ts.map +0 -1
- package/dist/rules/no-commented-code.d.ts.map +0 -1
- package/dist/rules/no-god-components.d.ts.map +0 -1
- package/dist/rules/no-identity-map.d.ts.map +0 -1
- package/dist/rules/no-instance-methods-without-this.d.ts.map +0 -1
- package/dist/rules/no-print.d.ts.map +0 -1
- package/dist/rules/no-shorthand-names.d.ts.map +0 -1
- package/dist/rules/no-useless-use-spring.d.ts.map +0 -1
- package/dist/rules/no-warn.d.ts.map +0 -1
- package/dist/rules/prefer-class-properties.d.ts.map +0 -1
- package/dist/rules/prefer-early-return.d.ts.map +0 -1
- package/dist/rules/prefer-enum-item.d.ts.map +0 -1
- package/dist/rules/prefer-module-scope-constants.d.ts.map +0 -1
- package/dist/rules/prefer-pascal-case-enums.d.ts.map +0 -1
- package/dist/rules/prefer-pattern-replacements.d.ts.map +0 -1
- package/dist/rules/prefer-sequence-overloads.d.ts.map +0 -1
- package/dist/rules/prefer-singular-enums.d.ts.map +0 -1
- package/dist/rules/prefer-udim2-shorthand.d.ts.map +0 -1
- package/dist/rules/react-hooks-strict-return.d.ts.map +0 -1
- package/dist/rules/require-named-effect-functions.d.ts.map +0 -1
- package/dist/rules/require-paired-calls.d.ts.map +0 -1
- package/dist/rules/require-react-component-keys.d.ts.map +0 -1
- package/dist/rules/require-react-display-names.d.ts.map +0 -1
- package/dist/rules/strict-component-boundaries.d.ts.map +0 -1
- package/dist/rules/use-exhaustive-dependencies.d.ts.map +0 -1
- package/dist/rules/use-hook-at-top-level.d.ts.map +0 -1
- package/dist/utilities/casing-utilities.d.ts.map +0 -1
- package/dist/utilities/configure-utilities.d.ts.map +0 -1
- package/dist/utilities/create-rule.d.ts.map +0 -1
- package/dist/utilities/format-utilities.d.ts.map +0 -1
- package/dist/utilities/pattern-replacement/constant-folder.d.ts.map +0 -1
- package/dist/utilities/pattern-replacement/index.d.ts.map +0 -1
- package/dist/utilities/pattern-replacement/pattern-matcher.d.ts.map +0 -1
- package/dist/utilities/pattern-replacement/pattern-parser.d.ts.map +0 -1
- package/dist/utilities/pattern-replacement/pattern-types.d.ts.map +0 -1
- package/dist/utilities/pattern-replacement/replacement-generator.d.ts.map +0 -1
- package/dist/utilities/resolve-import.d.ts.map +0 -1
package/dist/index.js
CHANGED
|
@@ -9658,7 +9658,7 @@ function ParsePatternIntoTypes(pattern) {
|
|
|
9658
9658
|
return result;
|
|
9659
9659
|
}
|
|
9660
9660
|
|
|
9661
|
-
// node_modules/typebox/build/type/engine/template-literal/finite.mjs
|
|
9661
|
+
// node_modules/typebox/build/type/engine/template-literal/is-finite.mjs
|
|
9662
9662
|
function FromLiteral(value) {
|
|
9663
9663
|
return true;
|
|
9664
9664
|
}
|
|
@@ -9673,7 +9673,7 @@ function FromTypes(types) {
|
|
|
9673
9673
|
function FromType2(type) {
|
|
9674
9674
|
return IsUnion(type) ? FromTypes(type.anyOf) : IsLiteral(type) ? FromLiteral(type.const) : false;
|
|
9675
9675
|
}
|
|
9676
|
-
function
|
|
9676
|
+
function IsTemplateLiteralFinite(types) {
|
|
9677
9677
|
const result = FromTypes(types);
|
|
9678
9678
|
return result;
|
|
9679
9679
|
}
|
|
@@ -9715,9 +9715,14 @@ function DecodeTypesAsUnion(types) {
|
|
|
9715
9715
|
function DecodeTypes(types) {
|
|
9716
9716
|
return exports_guard.IsEqual(types.length, 0) ? Unreachable() : exports_guard.IsEqual(types.length, 1) && IsLiteral(types[0]) ? types[0] : DecodeTypesAsUnion(types);
|
|
9717
9717
|
}
|
|
9718
|
-
function
|
|
9718
|
+
function TemplateLiteralDecodeUnsafe(pattern) {
|
|
9719
9719
|
const types = ParsePatternIntoTypes(pattern);
|
|
9720
|
-
const result = exports_guard.IsEqual(types.length, 0) ? String2() :
|
|
9720
|
+
const result = exports_guard.IsEqual(types.length, 0) ? String2() : IsTemplateLiteralFinite(types) ? DecodeTypes(types) : TemplateLiteralCreate(pattern);
|
|
9721
|
+
return result;
|
|
9722
|
+
}
|
|
9723
|
+
function TemplateLiteralDecode(pattern) {
|
|
9724
|
+
const decoded = TemplateLiteralDecodeUnsafe(pattern);
|
|
9725
|
+
const result = IsTemplateLiteral(decoded) ? String2() : decoded;
|
|
9721
9726
|
return result;
|
|
9722
9727
|
}
|
|
9723
9728
|
|
|
@@ -9749,7 +9754,7 @@ function RecordPattern(type) {
|
|
|
9749
9754
|
}
|
|
9750
9755
|
function RecordKey(type) {
|
|
9751
9756
|
const pattern = RecordPattern(type);
|
|
9752
|
-
const result = exports_guard.IsEqual(pattern, StringKey) ? String2() : exports_guard.IsEqual(pattern, IntegerKey) ? Integer() : exports_guard.IsEqual(pattern, NumberKey) ? Number2() :
|
|
9757
|
+
const result = exports_guard.IsEqual(pattern, StringKey) ? String2() : exports_guard.IsEqual(pattern, IntegerKey) ? Integer() : exports_guard.IsEqual(pattern, NumberKey) ? Number2() : TemplateLiteralDecodeUnsafe(pattern);
|
|
9753
9758
|
return result;
|
|
9754
9759
|
}
|
|
9755
9760
|
function RecordValue(type) {
|
|
@@ -12271,7 +12276,7 @@ function FromStringKey(key, value) {
|
|
|
12271
12276
|
// node_modules/typebox/build/type/engine/record/from-key-template-literal.mjs
|
|
12272
12277
|
function FromTemplateKey(pattern, value) {
|
|
12273
12278
|
const types = ParsePatternIntoTypes(pattern);
|
|
12274
|
-
const finite =
|
|
12279
|
+
const finite = IsTemplateLiteralFinite(types);
|
|
12275
12280
|
const result = finite ? FromKey(TemplateLiteralDecode(pattern), value) : CreateRecord(pattern, value);
|
|
12276
12281
|
return result;
|
|
12277
12282
|
}
|
|
@@ -18818,6 +18823,201 @@ var no_instance_methods_without_this_default = createRule({
|
|
|
18818
18823
|
name: "no-instance-methods-without-this"
|
|
18819
18824
|
});
|
|
18820
18825
|
|
|
18826
|
+
// src/rules/no-memo-children.ts
|
|
18827
|
+
import { TSESTree as TSESTree6 } from "@typescript-eslint/types";
|
|
18828
|
+
import { ESLintUtils as ESLintUtils3 } from "@typescript-eslint/utils";
|
|
18829
|
+
|
|
18830
|
+
// src/constants/react-sources.ts
|
|
18831
|
+
var REACT_SOURCES_ROBLOX = new Set(["@rbxts/react", "@rbxts/roact"]);
|
|
18832
|
+
var REACT_SOURCES_STANDARD = new Set(["react", "react-dom"]);
|
|
18833
|
+
function getReactSources(environment2) {
|
|
18834
|
+
return environment2 === "roblox-ts" ? REACT_SOURCES_ROBLOX : REACT_SOURCES_STANDARD;
|
|
18835
|
+
}
|
|
18836
|
+
function isReactImport(node, reactSources) {
|
|
18837
|
+
return reactSources.has(node.source.value);
|
|
18838
|
+
}
|
|
18839
|
+
|
|
18840
|
+
// src/rules/no-memo-children.ts
|
|
18841
|
+
var DEFAULT_OPTIONS2 = {
|
|
18842
|
+
allowedComponents: [],
|
|
18843
|
+
environment: "roblox-ts"
|
|
18844
|
+
};
|
|
18845
|
+
function isMemoCall(node, memoIdentifiers, reactNamespaces) {
|
|
18846
|
+
const { callee } = node;
|
|
18847
|
+
if (callee.type === TSESTree6.AST_NODE_TYPES.Identifier)
|
|
18848
|
+
return memoIdentifiers.has(callee.name);
|
|
18849
|
+
if (callee.type === TSESTree6.AST_NODE_TYPES.MemberExpression && callee.object.type === TSESTree6.AST_NODE_TYPES.Identifier && callee.property.type === TSESTree6.AST_NODE_TYPES.Identifier) {
|
|
18850
|
+
return reactNamespaces.has(callee.object.name) && callee.property.name === "memo";
|
|
18851
|
+
}
|
|
18852
|
+
return false;
|
|
18853
|
+
}
|
|
18854
|
+
function typeHasChildrenProperty(checker, type3, visited2 = new WeakSet) {
|
|
18855
|
+
if (visited2.has(type3))
|
|
18856
|
+
return false;
|
|
18857
|
+
visited2.add(type3);
|
|
18858
|
+
const allProperties = checker.getPropertiesOfType(type3);
|
|
18859
|
+
for (const prop of allProperties)
|
|
18860
|
+
if (prop.getName() === "children")
|
|
18861
|
+
return true;
|
|
18862
|
+
if (type3.isUnion()) {
|
|
18863
|
+
for (const constituent of type3.types)
|
|
18864
|
+
if (typeHasChildrenProperty(checker, constituent, visited2))
|
|
18865
|
+
return true;
|
|
18866
|
+
}
|
|
18867
|
+
if (type3.isIntersection()) {
|
|
18868
|
+
for (const constituent of type3.types)
|
|
18869
|
+
if (typeHasChildrenProperty(checker, constituent, visited2))
|
|
18870
|
+
return true;
|
|
18871
|
+
}
|
|
18872
|
+
const baseTypes = type3.getBaseTypes?.();
|
|
18873
|
+
if (baseTypes) {
|
|
18874
|
+
for (const baseType of baseTypes)
|
|
18875
|
+
if (typeHasChildrenProperty(checker, baseType, visited2))
|
|
18876
|
+
return true;
|
|
18877
|
+
}
|
|
18878
|
+
return false;
|
|
18879
|
+
}
|
|
18880
|
+
function getPropertiesTypeFromMemoCall(services, checker, node) {
|
|
18881
|
+
const tsCallNode = services.esTreeNodeToTSNodeMap.get(node);
|
|
18882
|
+
if (!tsCallNode)
|
|
18883
|
+
return;
|
|
18884
|
+
const memoResultType = checker.getTypeAtLocation(tsCallNode);
|
|
18885
|
+
if (!memoResultType)
|
|
18886
|
+
return;
|
|
18887
|
+
const memoResultSignatures = memoResultType.getCallSignatures();
|
|
18888
|
+
if (memoResultSignatures.length > 0) {
|
|
18889
|
+
const [firstSignature2] = memoResultSignatures;
|
|
18890
|
+
if (firstSignature2) {
|
|
18891
|
+
const [propertyParameter] = firstSignature2.getParameters();
|
|
18892
|
+
if (propertyParameter)
|
|
18893
|
+
return checker.getTypeOfSymbol(propertyParameter);
|
|
18894
|
+
}
|
|
18895
|
+
}
|
|
18896
|
+
if (node.typeArguments && node.typeArguments.params.length > 0) {
|
|
18897
|
+
const [typeArgNode] = node.typeArguments.params;
|
|
18898
|
+
if (typeArgNode) {
|
|
18899
|
+
const tsTypeArgNode = services.esTreeNodeToTSNodeMap.get(typeArgNode);
|
|
18900
|
+
if (tsTypeArgNode) {
|
|
18901
|
+
const typeFromArgument = checker.getTypeAtLocation(tsTypeArgNode);
|
|
18902
|
+
if (typeFromArgument)
|
|
18903
|
+
return typeFromArgument;
|
|
18904
|
+
}
|
|
18905
|
+
}
|
|
18906
|
+
}
|
|
18907
|
+
const [firstArgument] = node.arguments;
|
|
18908
|
+
if (!firstArgument)
|
|
18909
|
+
return;
|
|
18910
|
+
const tsNode = services.esTreeNodeToTSNodeMap.get(firstArgument);
|
|
18911
|
+
if (!tsNode)
|
|
18912
|
+
return;
|
|
18913
|
+
const componentType = checker.getTypeAtLocation(tsNode);
|
|
18914
|
+
if (!componentType)
|
|
18915
|
+
return;
|
|
18916
|
+
const callSignatures = componentType.getCallSignatures();
|
|
18917
|
+
if (callSignatures.length === 0)
|
|
18918
|
+
return;
|
|
18919
|
+
const [firstSignature] = callSignatures;
|
|
18920
|
+
if (!firstSignature)
|
|
18921
|
+
return;
|
|
18922
|
+
const parameters3 = firstSignature.getParameters();
|
|
18923
|
+
if (parameters3.length === 0)
|
|
18924
|
+
return;
|
|
18925
|
+
const [propertiesParameter] = parameters3;
|
|
18926
|
+
return propertiesParameter ? checker.getTypeOfSymbol(propertiesParameter) : undefined;
|
|
18927
|
+
}
|
|
18928
|
+
function getComponentName(node) {
|
|
18929
|
+
const [firstArgument] = node.arguments;
|
|
18930
|
+
if (!firstArgument)
|
|
18931
|
+
return;
|
|
18932
|
+
if (firstArgument.type === TSESTree6.AST_NODE_TYPES.Identifier)
|
|
18933
|
+
return firstArgument.name;
|
|
18934
|
+
if (firstArgument.type === TSESTree6.AST_NODE_TYPES.FunctionExpression && firstArgument.id) {
|
|
18935
|
+
return firstArgument.id.name;
|
|
18936
|
+
}
|
|
18937
|
+
const { parent } = node;
|
|
18938
|
+
if (parent?.type === TSESTree6.AST_NODE_TYPES.VariableDeclarator && parent.id.type === TSESTree6.AST_NODE_TYPES.Identifier) {
|
|
18939
|
+
return parent.id.name;
|
|
18940
|
+
}
|
|
18941
|
+
return;
|
|
18942
|
+
}
|
|
18943
|
+
var no_memo_children_default = createRule({
|
|
18944
|
+
create(context) {
|
|
18945
|
+
const options3 = {
|
|
18946
|
+
...DEFAULT_OPTIONS2,
|
|
18947
|
+
...context.options[0]
|
|
18948
|
+
};
|
|
18949
|
+
const reactSources = getReactSources(options3.environment);
|
|
18950
|
+
const memoIdentifiers = new Set;
|
|
18951
|
+
const reactNamespaces = new Set;
|
|
18952
|
+
const allowedSet = new Set(options3.allowedComponents);
|
|
18953
|
+
const services = ESLintUtils3.getParserServices(context);
|
|
18954
|
+
const checker = services.program.getTypeChecker();
|
|
18955
|
+
return {
|
|
18956
|
+
CallExpression(node) {
|
|
18957
|
+
if (!isMemoCall(node, memoIdentifiers, reactNamespaces))
|
|
18958
|
+
return;
|
|
18959
|
+
const componentName = getComponentName(node);
|
|
18960
|
+
if (componentName && allowedSet.has(componentName))
|
|
18961
|
+
return;
|
|
18962
|
+
const propsType = getPropertiesTypeFromMemoCall(services, checker, node);
|
|
18963
|
+
if (!propsType)
|
|
18964
|
+
return;
|
|
18965
|
+
if (typeHasChildrenProperty(checker, propsType)) {
|
|
18966
|
+
context.report({
|
|
18967
|
+
data: { componentName: componentName ?? "Component" },
|
|
18968
|
+
messageId: "memoWithChildren",
|
|
18969
|
+
node
|
|
18970
|
+
});
|
|
18971
|
+
}
|
|
18972
|
+
},
|
|
18973
|
+
ImportDeclaration(node) {
|
|
18974
|
+
if (!isReactImport(node, reactSources))
|
|
18975
|
+
return;
|
|
18976
|
+
for (const specifier of node.specifiers) {
|
|
18977
|
+
if (specifier.type === TSESTree6.AST_NODE_TYPES.ImportDefaultSpecifier || specifier.type === TSESTree6.AST_NODE_TYPES.ImportNamespaceSpecifier) {
|
|
18978
|
+
reactNamespaces.add(specifier.local.name);
|
|
18979
|
+
} else if (specifier.type === TSESTree6.AST_NODE_TYPES.ImportSpecifier) {
|
|
18980
|
+
const importedName = specifier.imported.type === TSESTree6.AST_NODE_TYPES.Identifier ? specifier.imported.name : specifier.imported.value;
|
|
18981
|
+
if (importedName === "memo")
|
|
18982
|
+
memoIdentifiers.add(specifier.local.name);
|
|
18983
|
+
}
|
|
18984
|
+
}
|
|
18985
|
+
}
|
|
18986
|
+
};
|
|
18987
|
+
},
|
|
18988
|
+
defaultOptions: [DEFAULT_OPTIONS2],
|
|
18989
|
+
meta: {
|
|
18990
|
+
docs: {
|
|
18991
|
+
description: "Disallow React.memo on components with children props, which defeats memoization since children change on every render."
|
|
18992
|
+
},
|
|
18993
|
+
messages: {
|
|
18994
|
+
memoWithChildren: "React.memo is ineffective on '{{componentName}}' because it accepts a 'children' prop. " + "The 'children' prop is typically a new JSX element on every render, causing the shallow comparison " + "performed by memo to return false on every render, negating any performance benefit. " + "Either remove 'children' from the props interface, pass children via a render prop pattern, " + "or remove the React.memo wrapper entirely."
|
|
18995
|
+
},
|
|
18996
|
+
schema: [
|
|
18997
|
+
{
|
|
18998
|
+
additionalProperties: false,
|
|
18999
|
+
properties: {
|
|
19000
|
+
allowedComponents: {
|
|
19001
|
+
default: [],
|
|
19002
|
+
description: "Component names to allow with children despite memo wrapper. " + "Use this for components where you've verified memoization is still beneficial.",
|
|
19003
|
+
items: { type: "string" },
|
|
19004
|
+
type: "array"
|
|
19005
|
+
},
|
|
19006
|
+
environment: {
|
|
19007
|
+
default: "roblox-ts",
|
|
19008
|
+
description: "The React environment: 'roblox-ts' uses @rbxts/react, 'standard' uses react.",
|
|
19009
|
+
enum: ["roblox-ts", "standard"],
|
|
19010
|
+
type: "string"
|
|
19011
|
+
}
|
|
19012
|
+
},
|
|
19013
|
+
type: "object"
|
|
19014
|
+
}
|
|
19015
|
+
],
|
|
19016
|
+
type: "suggestion"
|
|
19017
|
+
},
|
|
19018
|
+
name: "no-memo-children"
|
|
19019
|
+
});
|
|
19020
|
+
|
|
18821
19021
|
// src/rules/no-print.ts
|
|
18822
19022
|
var no_print_default = createRule({
|
|
18823
19023
|
create(context) {
|
|
@@ -18845,7 +19045,7 @@ var no_print_default = createRule({
|
|
|
18845
19045
|
});
|
|
18846
19046
|
|
|
18847
19047
|
// src/rules/no-shorthand-names.ts
|
|
18848
|
-
import { TSESTree as
|
|
19048
|
+
import { TSESTree as TSESTree7 } from "@typescript-eslint/types";
|
|
18849
19049
|
var isRuleOptions = Compile(build_default.Object({
|
|
18850
19050
|
allowPropertyAccess: build_default.Optional(build_default.Array(build_default.String())),
|
|
18851
19051
|
ignoreShorthands: build_default.Optional(build_default.Array(build_default.String())),
|
|
@@ -18854,7 +19054,7 @@ var isRuleOptions = Compile(build_default.Object({
|
|
|
18854
19054
|
function isRecord2(value) {
|
|
18855
19055
|
return value !== null && typeof value === "object";
|
|
18856
19056
|
}
|
|
18857
|
-
var
|
|
19057
|
+
var DEFAULT_OPTIONS3 = {
|
|
18858
19058
|
allowPropertyAccess: ["char"],
|
|
18859
19059
|
ignoreShorthands: [],
|
|
18860
19060
|
shorthands: {
|
|
@@ -18984,7 +19184,7 @@ function isWordIgnored(word, ignoreMatchers, ignoreExact) {
|
|
|
18984
19184
|
return false;
|
|
18985
19185
|
}
|
|
18986
19186
|
function normalizeOptions2(rawOptions) {
|
|
18987
|
-
const mergedShorthands = { ...
|
|
19187
|
+
const mergedShorthands = { ...DEFAULT_OPTIONS3.shorthands };
|
|
18988
19188
|
if (rawOptions?.shorthands) {
|
|
18989
19189
|
for (const [key, value] of Object.entries(rawOptions.shorthands))
|
|
18990
19190
|
mergedShorthands[key] = value;
|
|
@@ -18998,7 +19198,7 @@ function normalizeOptions2(rawOptions) {
|
|
|
18998
19198
|
else
|
|
18999
19199
|
matchers.push(result.matcher);
|
|
19000
19200
|
}
|
|
19001
|
-
const allowPropertyAccessSource = rawOptions?.allowPropertyAccess ??
|
|
19201
|
+
const allowPropertyAccessSource = rawOptions?.allowPropertyAccess ?? DEFAULT_OPTIONS3.allowPropertyAccess;
|
|
19002
19202
|
const ignoreMatchers = new Array;
|
|
19003
19203
|
const ignoreExact = new Set;
|
|
19004
19204
|
for (const pattern4 of rawOptions?.ignoreShorthands ?? []) {
|
|
@@ -19106,9 +19306,9 @@ var noShorthandNames = {
|
|
|
19106
19306
|
return;
|
|
19107
19307
|
}
|
|
19108
19308
|
}
|
|
19109
|
-
if (identifierName === "plr" && parent?.type ===
|
|
19309
|
+
if (identifierName === "plr" && parent?.type === TSESTree7.AST_NODE_TYPES.VariableDeclarator && parent.id === node) {
|
|
19110
19310
|
const { init } = parent;
|
|
19111
|
-
if (init && isRecord2(init) && init.type ===
|
|
19311
|
+
if (init && isRecord2(init) && init.type === TSESTree7.AST_NODE_TYPES.MemberExpression && init.object !== undefined && isRecord2(init.object) && init.object.type === TSESTree7.AST_NODE_TYPES.Identifier && init.object.name === "Players" && init.property !== undefined && isRecord2(init.property) && init.property.type === TSESTree7.AST_NODE_TYPES.Identifier && init.property.name === "LocalPlayer") {
|
|
19112
19312
|
context.report({
|
|
19113
19313
|
data: { replacement: "localPlayer", shorthand: "plr" },
|
|
19114
19314
|
messageId: "useReplacement",
|
|
@@ -19752,8 +19952,817 @@ var prefer_early_return_default = createRule({
|
|
|
19752
19952
|
});
|
|
19753
19953
|
|
|
19754
19954
|
// src/rules/prefer-enum-item.ts
|
|
19755
|
-
import { ESLintUtils as
|
|
19955
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES7, ESLintUtils as ESLintUtils4 } from "@typescript-eslint/utils";
|
|
19956
|
+
|
|
19957
|
+
// node_modules/ts-api-utils/lib/index.js
|
|
19958
|
+
import ts9 from "typescript";
|
|
19959
|
+
function isFlagSet(allFlags, flag) {
|
|
19960
|
+
return (allFlags & flag) !== 0;
|
|
19961
|
+
}
|
|
19962
|
+
function isFlagSetOnObject(obj, flag) {
|
|
19963
|
+
return isFlagSet(obj.flags, flag);
|
|
19964
|
+
}
|
|
19965
|
+
var isTypeFlagSet = isFlagSetOnObject;
|
|
19966
|
+
function includesModifier(modifiers, ...kinds) {
|
|
19967
|
+
if (modifiers === undefined) {
|
|
19968
|
+
return false;
|
|
19969
|
+
}
|
|
19970
|
+
for (const modifier of modifiers) {
|
|
19971
|
+
if (kinds.includes(modifier.kind)) {
|
|
19972
|
+
return true;
|
|
19973
|
+
}
|
|
19974
|
+
}
|
|
19975
|
+
return false;
|
|
19976
|
+
}
|
|
19977
|
+
var [tsMajor, tsMinor] = ts9.versionMajorMinor.split(".").map((raw) => Number.parseInt(raw, 10));
|
|
19978
|
+
function isNumericOrStringLikeLiteral(node) {
|
|
19979
|
+
switch (node.kind) {
|
|
19980
|
+
case ts9.SyntaxKind.NoSubstitutionTemplateLiteral:
|
|
19981
|
+
case ts9.SyntaxKind.NumericLiteral:
|
|
19982
|
+
case ts9.SyntaxKind.StringLiteral:
|
|
19983
|
+
return true;
|
|
19984
|
+
default:
|
|
19985
|
+
return false;
|
|
19986
|
+
}
|
|
19987
|
+
}
|
|
19988
|
+
function isFunctionScopeBoundary(node) {
|
|
19989
|
+
switch (node.kind) {
|
|
19990
|
+
case ts9.SyntaxKind.ArrowFunction:
|
|
19991
|
+
case ts9.SyntaxKind.CallSignature:
|
|
19992
|
+
case ts9.SyntaxKind.ClassDeclaration:
|
|
19993
|
+
case ts9.SyntaxKind.ClassExpression:
|
|
19994
|
+
case ts9.SyntaxKind.Constructor:
|
|
19995
|
+
case ts9.SyntaxKind.ConstructorType:
|
|
19996
|
+
case ts9.SyntaxKind.ConstructSignature:
|
|
19997
|
+
case ts9.SyntaxKind.EnumDeclaration:
|
|
19998
|
+
case ts9.SyntaxKind.FunctionDeclaration:
|
|
19999
|
+
case ts9.SyntaxKind.FunctionExpression:
|
|
20000
|
+
case ts9.SyntaxKind.FunctionType:
|
|
20001
|
+
case ts9.SyntaxKind.GetAccessor:
|
|
20002
|
+
case ts9.SyntaxKind.MethodDeclaration:
|
|
20003
|
+
case ts9.SyntaxKind.MethodSignature:
|
|
20004
|
+
case ts9.SyntaxKind.ModuleDeclaration:
|
|
20005
|
+
case ts9.SyntaxKind.SetAccessor:
|
|
20006
|
+
return true;
|
|
20007
|
+
case ts9.SyntaxKind.SourceFile:
|
|
20008
|
+
return ts9.isExternalModule(node);
|
|
20009
|
+
default:
|
|
20010
|
+
return false;
|
|
20011
|
+
}
|
|
20012
|
+
}
|
|
20013
|
+
var IntrinsicTypeFlags = ts9.TypeFlags.Intrinsic ?? ts9.TypeFlags.Any | ts9.TypeFlags.Unknown | ts9.TypeFlags.String | ts9.TypeFlags.Number | ts9.TypeFlags.BigInt | ts9.TypeFlags.Boolean | ts9.TypeFlags.BooleanLiteral | ts9.TypeFlags.ESSymbol | ts9.TypeFlags.Void | ts9.TypeFlags.Undefined | ts9.TypeFlags.Null | ts9.TypeFlags.Never | ts9.TypeFlags.NonPrimitive;
|
|
20014
|
+
function isUnionType(type3) {
|
|
20015
|
+
return isTypeFlagSet(type3, ts9.TypeFlags.Union);
|
|
20016
|
+
}
|
|
20017
|
+
function unionConstituents(type3) {
|
|
20018
|
+
return isUnionType(type3) ? type3.types : [type3];
|
|
20019
|
+
}
|
|
20020
|
+
function identifierToKeywordKind(node) {
|
|
20021
|
+
return "originalKeywordKind" in node ? node.originalKeywordKind : ts9.identifierToKeywordKind(node);
|
|
20022
|
+
}
|
|
20023
|
+
function getDeclarationDomain(node) {
|
|
20024
|
+
switch (node.parent.kind) {
|
|
20025
|
+
case ts9.SyntaxKind.ClassDeclaration:
|
|
20026
|
+
case ts9.SyntaxKind.ClassExpression:
|
|
20027
|
+
return 2 | 4;
|
|
20028
|
+
case ts9.SyntaxKind.EnumDeclaration:
|
|
20029
|
+
return 7;
|
|
20030
|
+
case ts9.SyntaxKind.FunctionDeclaration:
|
|
20031
|
+
case ts9.SyntaxKind.FunctionExpression:
|
|
20032
|
+
return 4;
|
|
20033
|
+
case ts9.SyntaxKind.ImportClause:
|
|
20034
|
+
case ts9.SyntaxKind.NamespaceImport:
|
|
20035
|
+
return 7 | 8;
|
|
20036
|
+
case ts9.SyntaxKind.ImportEqualsDeclaration:
|
|
20037
|
+
case ts9.SyntaxKind.ImportSpecifier:
|
|
20038
|
+
return node.parent.name === node ? 7 | 8 : undefined;
|
|
20039
|
+
case ts9.SyntaxKind.InterfaceDeclaration:
|
|
20040
|
+
case ts9.SyntaxKind.TypeAliasDeclaration:
|
|
20041
|
+
case ts9.SyntaxKind.TypeParameter:
|
|
20042
|
+
return 2;
|
|
20043
|
+
case ts9.SyntaxKind.ModuleDeclaration:
|
|
20044
|
+
return 1;
|
|
20045
|
+
case ts9.SyntaxKind.Parameter:
|
|
20046
|
+
if (node.parent.parent.kind === ts9.SyntaxKind.IndexSignature || identifierToKeywordKind(node) === ts9.SyntaxKind.ThisKeyword) {
|
|
20047
|
+
return;
|
|
20048
|
+
}
|
|
20049
|
+
case ts9.SyntaxKind.BindingElement:
|
|
20050
|
+
case ts9.SyntaxKind.VariableDeclaration:
|
|
20051
|
+
return node.parent.name === node ? 4 : undefined;
|
|
20052
|
+
}
|
|
20053
|
+
}
|
|
20054
|
+
function getPropertyName(propertyName) {
|
|
20055
|
+
if (propertyName.kind === ts9.SyntaxKind.ComputedPropertyName) {
|
|
20056
|
+
const expression = unwrapParentheses(propertyName.expression);
|
|
20057
|
+
if (ts9.isPrefixUnaryExpression(expression)) {
|
|
20058
|
+
let negate = false;
|
|
20059
|
+
switch (expression.operator) {
|
|
20060
|
+
case ts9.SyntaxKind.MinusToken:
|
|
20061
|
+
negate = true;
|
|
20062
|
+
case ts9.SyntaxKind.PlusToken:
|
|
20063
|
+
return ts9.isNumericLiteral(expression.operand) ? `${negate ? "-" : ""}${expression.operand.text}` : ts9.isBigIntLiteral(expression.operand) ? `${negate ? "-" : ""}${expression.operand.text.slice(0, -1)}` : undefined;
|
|
20064
|
+
default:
|
|
20065
|
+
return;
|
|
20066
|
+
}
|
|
20067
|
+
}
|
|
20068
|
+
if (ts9.isBigIntLiteral(expression)) {
|
|
20069
|
+
return expression.text.slice(0, -1);
|
|
20070
|
+
}
|
|
20071
|
+
if (isNumericOrStringLikeLiteral(expression)) {
|
|
20072
|
+
return expression.text;
|
|
20073
|
+
}
|
|
20074
|
+
return;
|
|
20075
|
+
}
|
|
20076
|
+
return propertyName.kind === ts9.SyntaxKind.PrivateIdentifier ? undefined : propertyName.text;
|
|
20077
|
+
}
|
|
20078
|
+
function unwrapParentheses(node) {
|
|
20079
|
+
while (node.kind === ts9.SyntaxKind.ParenthesizedExpression) {
|
|
20080
|
+
node = node.expression;
|
|
20081
|
+
}
|
|
20082
|
+
return node;
|
|
20083
|
+
}
|
|
20084
|
+
function getUsageDomain(node) {
|
|
20085
|
+
const parent = node.parent;
|
|
20086
|
+
switch (parent.kind) {
|
|
20087
|
+
case ts9.SyntaxKind.BindingElement:
|
|
20088
|
+
if (parent.initializer === node) {
|
|
20089
|
+
return 5;
|
|
20090
|
+
}
|
|
20091
|
+
break;
|
|
20092
|
+
case ts9.SyntaxKind.BreakStatement:
|
|
20093
|
+
case ts9.SyntaxKind.ClassDeclaration:
|
|
20094
|
+
case ts9.SyntaxKind.ClassExpression:
|
|
20095
|
+
case ts9.SyntaxKind.ContinueStatement:
|
|
20096
|
+
case ts9.SyntaxKind.EnumDeclaration:
|
|
20097
|
+
case ts9.SyntaxKind.FunctionDeclaration:
|
|
20098
|
+
case ts9.SyntaxKind.FunctionExpression:
|
|
20099
|
+
case ts9.SyntaxKind.GetAccessor:
|
|
20100
|
+
case ts9.SyntaxKind.ImportClause:
|
|
20101
|
+
case ts9.SyntaxKind.ImportSpecifier:
|
|
20102
|
+
case ts9.SyntaxKind.InterfaceDeclaration:
|
|
20103
|
+
case ts9.SyntaxKind.JsxAttribute:
|
|
20104
|
+
case ts9.SyntaxKind.LabeledStatement:
|
|
20105
|
+
case ts9.SyntaxKind.MethodDeclaration:
|
|
20106
|
+
case ts9.SyntaxKind.MethodSignature:
|
|
20107
|
+
case ts9.SyntaxKind.ModuleDeclaration:
|
|
20108
|
+
case ts9.SyntaxKind.NamedTupleMember:
|
|
20109
|
+
case ts9.SyntaxKind.NamespaceExport:
|
|
20110
|
+
case ts9.SyntaxKind.NamespaceExportDeclaration:
|
|
20111
|
+
case ts9.SyntaxKind.NamespaceImport:
|
|
20112
|
+
case ts9.SyntaxKind.PropertySignature:
|
|
20113
|
+
case ts9.SyntaxKind.SetAccessor:
|
|
20114
|
+
case ts9.SyntaxKind.TypeAliasDeclaration:
|
|
20115
|
+
case ts9.SyntaxKind.TypeParameter:
|
|
20116
|
+
case ts9.SyntaxKind.TypePredicate:
|
|
20117
|
+
break;
|
|
20118
|
+
case ts9.SyntaxKind.EnumMember:
|
|
20119
|
+
case ts9.SyntaxKind.ImportEqualsDeclaration:
|
|
20120
|
+
case ts9.SyntaxKind.Parameter:
|
|
20121
|
+
case ts9.SyntaxKind.PropertyAccessExpression:
|
|
20122
|
+
case ts9.SyntaxKind.PropertyAssignment:
|
|
20123
|
+
case ts9.SyntaxKind.PropertyDeclaration:
|
|
20124
|
+
case ts9.SyntaxKind.VariableDeclaration:
|
|
20125
|
+
if (parent.name !== node) {
|
|
20126
|
+
return 5;
|
|
20127
|
+
}
|
|
20128
|
+
break;
|
|
20129
|
+
case ts9.SyntaxKind.ExportAssignment:
|
|
20130
|
+
return 7;
|
|
20131
|
+
case ts9.SyntaxKind.ExportSpecifier:
|
|
20132
|
+
if (parent.propertyName === undefined || parent.propertyName === node) {
|
|
20133
|
+
return 7;
|
|
20134
|
+
}
|
|
20135
|
+
break;
|
|
20136
|
+
case ts9.SyntaxKind.ExpressionWithTypeArguments:
|
|
20137
|
+
return parent.parent.token === ts9.SyntaxKind.ImplementsKeyword || parent.parent.parent.kind === ts9.SyntaxKind.InterfaceDeclaration ? 2 : 4;
|
|
20138
|
+
case ts9.SyntaxKind.QualifiedName:
|
|
20139
|
+
if (parent.left === node) {
|
|
20140
|
+
if (getEntityNameParent(parent).kind === ts9.SyntaxKind.TypeQuery) {
|
|
20141
|
+
return 1 | 8;
|
|
20142
|
+
}
|
|
20143
|
+
return 1;
|
|
20144
|
+
}
|
|
20145
|
+
break;
|
|
20146
|
+
case ts9.SyntaxKind.TypeQuery:
|
|
20147
|
+
return 5 | 8;
|
|
20148
|
+
case ts9.SyntaxKind.TypeReference:
|
|
20149
|
+
return identifierToKeywordKind(node) !== ts9.SyntaxKind.ConstKeyword ? 2 : undefined;
|
|
20150
|
+
default:
|
|
20151
|
+
return 5;
|
|
20152
|
+
}
|
|
20153
|
+
}
|
|
20154
|
+
function getEntityNameParent(name) {
|
|
20155
|
+
let parent = name.parent;
|
|
20156
|
+
while (parent.kind === ts9.SyntaxKind.QualifiedName) {
|
|
20157
|
+
parent = parent.parent;
|
|
20158
|
+
}
|
|
20159
|
+
return parent;
|
|
20160
|
+
}
|
|
20161
|
+
function isBlockScopeBoundary(node) {
|
|
20162
|
+
switch (node.kind) {
|
|
20163
|
+
case ts9.SyntaxKind.Block: {
|
|
20164
|
+
const parent = node.parent;
|
|
20165
|
+
return parent.kind !== ts9.SyntaxKind.CatchClause && (parent.kind === ts9.SyntaxKind.SourceFile || !isFunctionScopeBoundary(parent)) ? 2 : 0;
|
|
20166
|
+
}
|
|
20167
|
+
case ts9.SyntaxKind.CaseBlock:
|
|
20168
|
+
case ts9.SyntaxKind.CatchClause:
|
|
20169
|
+
case ts9.SyntaxKind.ForInStatement:
|
|
20170
|
+
case ts9.SyntaxKind.ForOfStatement:
|
|
20171
|
+
case ts9.SyntaxKind.ForStatement:
|
|
20172
|
+
case ts9.SyntaxKind.WithStatement:
|
|
20173
|
+
return 2;
|
|
20174
|
+
default:
|
|
20175
|
+
return 0;
|
|
20176
|
+
}
|
|
20177
|
+
}
|
|
20178
|
+
var AbstractScope = class {
|
|
20179
|
+
constructor(global) {
|
|
20180
|
+
this.global = global;
|
|
20181
|
+
}
|
|
20182
|
+
namespaceScopes = undefined;
|
|
20183
|
+
uses = [];
|
|
20184
|
+
variables = /* @__PURE__ */ new Map;
|
|
20185
|
+
#enumScopes = undefined;
|
|
20186
|
+
addUse(use) {
|
|
20187
|
+
this.uses.push(use);
|
|
20188
|
+
}
|
|
20189
|
+
addVariable(identifier3, name, selector, exported, domain) {
|
|
20190
|
+
const variables = this.getDestinationScope(selector).getVariables();
|
|
20191
|
+
const declaration = {
|
|
20192
|
+
declaration: name,
|
|
20193
|
+
domain,
|
|
20194
|
+
exported
|
|
20195
|
+
};
|
|
20196
|
+
const variable = variables.get(identifier3);
|
|
20197
|
+
if (variable === undefined) {
|
|
20198
|
+
variables.set(identifier3, {
|
|
20199
|
+
declarations: [declaration],
|
|
20200
|
+
domain,
|
|
20201
|
+
uses: []
|
|
20202
|
+
});
|
|
20203
|
+
} else {
|
|
20204
|
+
variable.domain |= domain;
|
|
20205
|
+
variable.declarations.push(declaration);
|
|
20206
|
+
}
|
|
20207
|
+
}
|
|
20208
|
+
createOrReuseEnumScope(name, _exported) {
|
|
20209
|
+
let scope;
|
|
20210
|
+
if (this.#enumScopes === undefined) {
|
|
20211
|
+
this.#enumScopes = /* @__PURE__ */ new Map;
|
|
20212
|
+
} else {
|
|
20213
|
+
scope = this.#enumScopes.get(name);
|
|
20214
|
+
}
|
|
20215
|
+
if (scope === undefined) {
|
|
20216
|
+
scope = new EnumScope(this);
|
|
20217
|
+
this.#enumScopes.set(name, scope);
|
|
20218
|
+
}
|
|
20219
|
+
return scope;
|
|
20220
|
+
}
|
|
20221
|
+
createOrReuseNamespaceScope(name, _exported, ambient, hasExportStatement) {
|
|
20222
|
+
let scope;
|
|
20223
|
+
if (this.namespaceScopes === undefined) {
|
|
20224
|
+
this.namespaceScopes = /* @__PURE__ */ new Map;
|
|
20225
|
+
} else {
|
|
20226
|
+
scope = this.namespaceScopes.get(name);
|
|
20227
|
+
}
|
|
20228
|
+
if (scope === undefined) {
|
|
20229
|
+
scope = new NamespaceScope(ambient, hasExportStatement, this);
|
|
20230
|
+
this.namespaceScopes.set(name, scope);
|
|
20231
|
+
} else {
|
|
20232
|
+
scope.refresh(ambient, hasExportStatement);
|
|
20233
|
+
}
|
|
20234
|
+
return scope;
|
|
20235
|
+
}
|
|
20236
|
+
end(cb) {
|
|
20237
|
+
if (this.namespaceScopes !== undefined) {
|
|
20238
|
+
this.namespaceScopes.forEach((value) => value.finish(cb));
|
|
20239
|
+
}
|
|
20240
|
+
this.namespaceScopes = this.#enumScopes = undefined;
|
|
20241
|
+
this.applyUses();
|
|
20242
|
+
this.variables.forEach((variable) => {
|
|
20243
|
+
for (const declaration of variable.declarations) {
|
|
20244
|
+
const result = {
|
|
20245
|
+
declarations: [],
|
|
20246
|
+
domain: declaration.domain,
|
|
20247
|
+
exported: declaration.exported,
|
|
20248
|
+
inGlobalScope: this.global,
|
|
20249
|
+
uses: []
|
|
20250
|
+
};
|
|
20251
|
+
for (const other of variable.declarations) {
|
|
20252
|
+
if (other.domain & declaration.domain) {
|
|
20253
|
+
result.declarations.push(other.declaration);
|
|
20254
|
+
}
|
|
20255
|
+
}
|
|
20256
|
+
for (const use of variable.uses) {
|
|
20257
|
+
if (use.domain & declaration.domain) {
|
|
20258
|
+
result.uses.push(use);
|
|
20259
|
+
}
|
|
20260
|
+
}
|
|
20261
|
+
cb(result, declaration.declaration, this);
|
|
20262
|
+
}
|
|
20263
|
+
});
|
|
20264
|
+
}
|
|
20265
|
+
getFunctionScope() {
|
|
20266
|
+
return this;
|
|
20267
|
+
}
|
|
20268
|
+
getVariables() {
|
|
20269
|
+
return this.variables;
|
|
20270
|
+
}
|
|
20271
|
+
markExported(_name) {}
|
|
20272
|
+
addUseToParent(_use) {}
|
|
20273
|
+
applyUse(use, variables = this.variables) {
|
|
20274
|
+
const variable = variables.get(use.location.text);
|
|
20275
|
+
if (variable === undefined || (variable.domain & use.domain) === 0) {
|
|
20276
|
+
return false;
|
|
20277
|
+
}
|
|
20278
|
+
variable.uses.push(use);
|
|
20279
|
+
return true;
|
|
20280
|
+
}
|
|
20281
|
+
applyUses() {
|
|
20282
|
+
for (const use of this.uses) {
|
|
20283
|
+
if (!this.applyUse(use)) {
|
|
20284
|
+
this.addUseToParent(use);
|
|
20285
|
+
}
|
|
20286
|
+
}
|
|
20287
|
+
this.uses = [];
|
|
20288
|
+
}
|
|
20289
|
+
};
|
|
20290
|
+
var NonRootScope = class extends AbstractScope {
|
|
20291
|
+
constructor(parent, boundary) {
|
|
20292
|
+
super(false);
|
|
20293
|
+
this.parent = parent;
|
|
20294
|
+
this.boundary = boundary;
|
|
20295
|
+
}
|
|
20296
|
+
getDestinationScope(selector) {
|
|
20297
|
+
return this.boundary & selector ? this : this.parent.getDestinationScope(selector);
|
|
20298
|
+
}
|
|
20299
|
+
addUseToParent(use) {
|
|
20300
|
+
return this.parent.addUse(use, this);
|
|
20301
|
+
}
|
|
20302
|
+
};
|
|
20303
|
+
var AbstractNamedExpressionScope = class extends NonRootScope {
|
|
20304
|
+
#domain;
|
|
20305
|
+
#name;
|
|
20306
|
+
constructor(name, domain, parent) {
|
|
20307
|
+
super(parent, 1);
|
|
20308
|
+
this.#name = name;
|
|
20309
|
+
this.#domain = domain;
|
|
20310
|
+
}
|
|
20311
|
+
addUse(use, source) {
|
|
20312
|
+
if (source !== this.innerScope) {
|
|
20313
|
+
return this.innerScope.addUse(use);
|
|
20314
|
+
}
|
|
20315
|
+
if (use.domain & this.#domain && use.location.text === this.#name.text) {
|
|
20316
|
+
this.uses.push(use);
|
|
20317
|
+
} else {
|
|
20318
|
+
return this.parent.addUse(use, this);
|
|
20319
|
+
}
|
|
20320
|
+
}
|
|
20321
|
+
end(cb) {
|
|
20322
|
+
this.innerScope.end(cb);
|
|
20323
|
+
return cb({
|
|
20324
|
+
declarations: [this.#name],
|
|
20325
|
+
domain: this.#domain,
|
|
20326
|
+
exported: false,
|
|
20327
|
+
inGlobalScope: false,
|
|
20328
|
+
uses: this.uses
|
|
20329
|
+
}, this.#name, this);
|
|
20330
|
+
}
|
|
20331
|
+
getDestinationScope() {
|
|
20332
|
+
return this.innerScope;
|
|
20333
|
+
}
|
|
20334
|
+
getFunctionScope() {
|
|
20335
|
+
return this.innerScope;
|
|
20336
|
+
}
|
|
20337
|
+
};
|
|
20338
|
+
var BlockScope = class extends NonRootScope {
|
|
20339
|
+
#functionScope;
|
|
20340
|
+
constructor(functionScope, parent) {
|
|
20341
|
+
super(parent, 2);
|
|
20342
|
+
this.#functionScope = functionScope;
|
|
20343
|
+
}
|
|
20344
|
+
getFunctionScope() {
|
|
20345
|
+
return this.#functionScope;
|
|
20346
|
+
}
|
|
20347
|
+
};
|
|
20348
|
+
var ClassExpressionScope = class extends AbstractNamedExpressionScope {
|
|
20349
|
+
innerScope = new NonRootScope(this, 1);
|
|
20350
|
+
constructor(name, parent) {
|
|
20351
|
+
super(name, 4 | 2, parent);
|
|
20352
|
+
}
|
|
20353
|
+
};
|
|
20354
|
+
var ConditionalTypeScope = class extends NonRootScope {
|
|
20355
|
+
#state = 0;
|
|
20356
|
+
constructor(parent) {
|
|
20357
|
+
super(parent, 8);
|
|
20358
|
+
}
|
|
20359
|
+
addUse(use) {
|
|
20360
|
+
if (this.#state === 2) {
|
|
20361
|
+
return void this.uses.push(use);
|
|
20362
|
+
}
|
|
20363
|
+
return this.parent.addUse(use, this);
|
|
20364
|
+
}
|
|
20365
|
+
updateState(newState) {
|
|
20366
|
+
this.#state = newState;
|
|
20367
|
+
}
|
|
20368
|
+
};
|
|
20369
|
+
var EnumScope = class extends NonRootScope {
|
|
20370
|
+
constructor(parent) {
|
|
20371
|
+
super(parent, 1);
|
|
20372
|
+
}
|
|
20373
|
+
end() {
|
|
20374
|
+
this.applyUses();
|
|
20375
|
+
}
|
|
20376
|
+
};
|
|
20377
|
+
var FunctionScope = class extends NonRootScope {
|
|
20378
|
+
constructor(parent) {
|
|
20379
|
+
super(parent, 1);
|
|
20380
|
+
}
|
|
20381
|
+
beginBody() {
|
|
20382
|
+
this.applyUses();
|
|
20383
|
+
}
|
|
20384
|
+
};
|
|
20385
|
+
var FunctionExpressionScope = class extends AbstractNamedExpressionScope {
|
|
20386
|
+
innerScope = new FunctionScope(this);
|
|
20387
|
+
constructor(name, parent) {
|
|
20388
|
+
super(name, 4, parent);
|
|
20389
|
+
}
|
|
20390
|
+
beginBody() {
|
|
20391
|
+
return this.innerScope.beginBody();
|
|
20392
|
+
}
|
|
20393
|
+
};
|
|
20394
|
+
var NamespaceScope = class extends NonRootScope {
|
|
20395
|
+
#ambient;
|
|
20396
|
+
#exports = undefined;
|
|
20397
|
+
#hasExport;
|
|
20398
|
+
#innerScope = new NonRootScope(this, 1);
|
|
20399
|
+
constructor(ambient, hasExport, parent) {
|
|
20400
|
+
super(parent, 1);
|
|
20401
|
+
this.#ambient = ambient;
|
|
20402
|
+
this.#hasExport = hasExport;
|
|
20403
|
+
}
|
|
20404
|
+
addUse(use, source) {
|
|
20405
|
+
if (source !== this.#innerScope) {
|
|
20406
|
+
return this.#innerScope.addUse(use);
|
|
20407
|
+
}
|
|
20408
|
+
this.uses.push(use);
|
|
20409
|
+
}
|
|
20410
|
+
createOrReuseEnumScope(name, exported) {
|
|
20411
|
+
if (!exported && (!this.#ambient || this.#hasExport)) {
|
|
20412
|
+
return this.#innerScope.createOrReuseEnumScope(name, exported);
|
|
20413
|
+
}
|
|
20414
|
+
return super.createOrReuseEnumScope(name, exported);
|
|
20415
|
+
}
|
|
20416
|
+
createOrReuseNamespaceScope(name, exported, ambient, hasExportStatement) {
|
|
20417
|
+
if (!exported && (!this.#ambient || this.#hasExport)) {
|
|
20418
|
+
return this.#innerScope.createOrReuseNamespaceScope(name, exported, ambient || this.#ambient, hasExportStatement);
|
|
20419
|
+
}
|
|
20420
|
+
return super.createOrReuseNamespaceScope(name, exported, ambient || this.#ambient, hasExportStatement);
|
|
20421
|
+
}
|
|
20422
|
+
end(cb) {
|
|
20423
|
+
this.#innerScope.end((variable, key, scope) => {
|
|
20424
|
+
if (scope !== this.#innerScope || !variable.exported && (!this.#ambient || this.#exports !== undefined && !this.#exports.has(key.text))) {
|
|
20425
|
+
return cb(variable, key, scope);
|
|
20426
|
+
}
|
|
20427
|
+
const namespaceVar = this.variables.get(key.text);
|
|
20428
|
+
if (namespaceVar === undefined) {
|
|
20429
|
+
this.variables.set(key.text, {
|
|
20430
|
+
declarations: variable.declarations.map(mapDeclaration),
|
|
20431
|
+
domain: variable.domain,
|
|
20432
|
+
uses: [...variable.uses]
|
|
20433
|
+
});
|
|
20434
|
+
} else {
|
|
20435
|
+
outer:
|
|
20436
|
+
for (const declaration of variable.declarations) {
|
|
20437
|
+
for (const existing of namespaceVar.declarations) {
|
|
20438
|
+
if (existing.declaration === declaration) {
|
|
20439
|
+
continue outer;
|
|
20440
|
+
}
|
|
20441
|
+
namespaceVar.declarations.push(mapDeclaration(declaration));
|
|
20442
|
+
}
|
|
20443
|
+
}
|
|
20444
|
+
namespaceVar.domain |= variable.domain;
|
|
20445
|
+
for (const use of variable.uses) {
|
|
20446
|
+
if (namespaceVar.uses.includes(use)) {
|
|
20447
|
+
continue;
|
|
20448
|
+
}
|
|
20449
|
+
namespaceVar.uses.push(use);
|
|
20450
|
+
}
|
|
20451
|
+
}
|
|
20452
|
+
});
|
|
20453
|
+
this.applyUses();
|
|
20454
|
+
this.#innerScope = new NonRootScope(this, 1);
|
|
20455
|
+
}
|
|
20456
|
+
finish(cb) {
|
|
20457
|
+
return super.end(cb);
|
|
20458
|
+
}
|
|
20459
|
+
getDestinationScope() {
|
|
20460
|
+
return this.#innerScope;
|
|
20461
|
+
}
|
|
20462
|
+
markExported(name) {
|
|
20463
|
+
if (this.#exports === undefined) {
|
|
20464
|
+
this.#exports = /* @__PURE__ */ new Set;
|
|
20465
|
+
}
|
|
20466
|
+
this.#exports.add(name.text);
|
|
20467
|
+
}
|
|
20468
|
+
refresh(ambient, hasExport) {
|
|
20469
|
+
this.#ambient = ambient;
|
|
20470
|
+
this.#hasExport = hasExport;
|
|
20471
|
+
}
|
|
20472
|
+
};
|
|
20473
|
+
var RootScope = class extends AbstractScope {
|
|
20474
|
+
#exportAll;
|
|
20475
|
+
#exports = undefined;
|
|
20476
|
+
#innerScope = new NonRootScope(this, 1);
|
|
20477
|
+
constructor(exportAll, global) {
|
|
20478
|
+
super(global);
|
|
20479
|
+
this.#exportAll = exportAll;
|
|
20480
|
+
}
|
|
20481
|
+
addUse(use, origin) {
|
|
20482
|
+
if (origin === this.#innerScope) {
|
|
20483
|
+
return super.addUse(use);
|
|
20484
|
+
}
|
|
20485
|
+
return this.#innerScope.addUse(use);
|
|
20486
|
+
}
|
|
20487
|
+
addVariable(identifier3, name, selector, exported, domain) {
|
|
20488
|
+
if (domain & 8) {
|
|
20489
|
+
return super.addVariable(identifier3, name, selector, exported, domain);
|
|
20490
|
+
}
|
|
20491
|
+
return this.#innerScope.addVariable(identifier3, name, selector, exported, domain);
|
|
20492
|
+
}
|
|
20493
|
+
end(cb) {
|
|
20494
|
+
this.#innerScope.end((value, key) => {
|
|
20495
|
+
value.exported ||= this.#exportAll || this.#exports !== undefined && this.#exports.includes(key.text);
|
|
20496
|
+
value.inGlobalScope = this.global;
|
|
20497
|
+
return cb(value, key, this);
|
|
20498
|
+
});
|
|
20499
|
+
return super.end((value, key, scope) => {
|
|
20500
|
+
value.exported ||= scope === this && this.#exports !== undefined && this.#exports.includes(key.text);
|
|
20501
|
+
return cb(value, key, scope);
|
|
20502
|
+
});
|
|
20503
|
+
}
|
|
20504
|
+
getDestinationScope() {
|
|
20505
|
+
return this;
|
|
20506
|
+
}
|
|
20507
|
+
markExported(id2) {
|
|
20508
|
+
if (this.#exports === undefined) {
|
|
20509
|
+
this.#exports = [id2.text];
|
|
20510
|
+
} else {
|
|
20511
|
+
this.#exports.push(id2.text);
|
|
20512
|
+
}
|
|
20513
|
+
}
|
|
20514
|
+
};
|
|
20515
|
+
function mapDeclaration(declaration) {
|
|
20516
|
+
return {
|
|
20517
|
+
declaration,
|
|
20518
|
+
domain: getDeclarationDomain(declaration),
|
|
20519
|
+
exported: true
|
|
20520
|
+
};
|
|
20521
|
+
}
|
|
20522
|
+
var UsageWalker = class {
|
|
20523
|
+
#result = /* @__PURE__ */ new Map;
|
|
20524
|
+
#scope;
|
|
20525
|
+
getUsage(sourceFile) {
|
|
20526
|
+
const variableCallback = (variable, key) => {
|
|
20527
|
+
this.#result.set(key, variable);
|
|
20528
|
+
};
|
|
20529
|
+
const isModule = ts9.isExternalModule(sourceFile);
|
|
20530
|
+
this.#scope = new RootScope(sourceFile.isDeclarationFile && isModule && !containsExportStatement(sourceFile), !isModule);
|
|
20531
|
+
const cb = (node) => {
|
|
20532
|
+
if (isBlockScopeBoundary(node)) {
|
|
20533
|
+
return continueWithScope(node, new BlockScope(this.#scope.getFunctionScope(), this.#scope), handleBlockScope);
|
|
20534
|
+
}
|
|
20535
|
+
switch (node.kind) {
|
|
20536
|
+
case ts9.SyntaxKind.ArrowFunction:
|
|
20537
|
+
case ts9.SyntaxKind.CallSignature:
|
|
20538
|
+
case ts9.SyntaxKind.Constructor:
|
|
20539
|
+
case ts9.SyntaxKind.ConstructorType:
|
|
20540
|
+
case ts9.SyntaxKind.ConstructSignature:
|
|
20541
|
+
case ts9.SyntaxKind.FunctionDeclaration:
|
|
20542
|
+
case ts9.SyntaxKind.FunctionExpression:
|
|
20543
|
+
case ts9.SyntaxKind.FunctionType:
|
|
20544
|
+
case ts9.SyntaxKind.GetAccessor:
|
|
20545
|
+
case ts9.SyntaxKind.MethodDeclaration:
|
|
20546
|
+
case ts9.SyntaxKind.MethodSignature:
|
|
20547
|
+
case ts9.SyntaxKind.SetAccessor:
|
|
20548
|
+
return this.#handleFunctionLikeDeclaration(node, cb, variableCallback);
|
|
20549
|
+
case ts9.SyntaxKind.ClassDeclaration:
|
|
20550
|
+
this.#handleDeclaration(node, true, 4 | 2);
|
|
20551
|
+
return continueWithScope(node, new NonRootScope(this.#scope, 1));
|
|
20552
|
+
case ts9.SyntaxKind.ClassExpression:
|
|
20553
|
+
return continueWithScope(node, node.name !== undefined ? new ClassExpressionScope(node.name, this.#scope) : new NonRootScope(this.#scope, 1));
|
|
20554
|
+
case ts9.SyntaxKind.ConditionalType:
|
|
20555
|
+
return this.#handleConditionalType(node, cb, variableCallback);
|
|
20556
|
+
case ts9.SyntaxKind.EnumDeclaration:
|
|
20557
|
+
this.#handleDeclaration(node, true, 7);
|
|
20558
|
+
return continueWithScope(node, this.#scope.createOrReuseEnumScope(node.name.text, includesModifier(node.modifiers, ts9.SyntaxKind.ExportKeyword)));
|
|
20559
|
+
case ts9.SyntaxKind.EnumMember:
|
|
20560
|
+
this.#scope.addVariable(getPropertyName(node.name), node.name, 1, true, 4);
|
|
20561
|
+
break;
|
|
20562
|
+
case ts9.SyntaxKind.ExportAssignment:
|
|
20563
|
+
if (node.expression.kind === ts9.SyntaxKind.Identifier) {
|
|
20564
|
+
return this.#scope.markExported(node.expression);
|
|
20565
|
+
}
|
|
20566
|
+
break;
|
|
20567
|
+
case ts9.SyntaxKind.ExportSpecifier:
|
|
20568
|
+
if (node.propertyName !== undefined) {
|
|
20569
|
+
return this.#scope.markExported(node.propertyName, node.name);
|
|
20570
|
+
}
|
|
20571
|
+
return this.#scope.markExported(node.name);
|
|
20572
|
+
case ts9.SyntaxKind.Identifier: {
|
|
20573
|
+
const domain = getUsageDomain(node);
|
|
20574
|
+
if (domain !== undefined) {
|
|
20575
|
+
this.#scope.addUse({ domain, location: node });
|
|
20576
|
+
}
|
|
20577
|
+
return;
|
|
20578
|
+
}
|
|
20579
|
+
case ts9.SyntaxKind.ImportClause:
|
|
20580
|
+
case ts9.SyntaxKind.ImportEqualsDeclaration:
|
|
20581
|
+
case ts9.SyntaxKind.ImportSpecifier:
|
|
20582
|
+
case ts9.SyntaxKind.NamespaceImport:
|
|
20583
|
+
this.#handleDeclaration(node, false, 7 | 8);
|
|
20584
|
+
break;
|
|
20585
|
+
case ts9.SyntaxKind.InterfaceDeclaration:
|
|
20586
|
+
case ts9.SyntaxKind.TypeAliasDeclaration:
|
|
20587
|
+
this.#handleDeclaration(node, true, 2);
|
|
20588
|
+
return continueWithScope(node, new NonRootScope(this.#scope, 4));
|
|
20589
|
+
case ts9.SyntaxKind.MappedType:
|
|
20590
|
+
return continueWithScope(node, new NonRootScope(this.#scope, 4));
|
|
20591
|
+
case ts9.SyntaxKind.ModuleDeclaration:
|
|
20592
|
+
return this.#handleModule(node, continueWithScope);
|
|
20593
|
+
case ts9.SyntaxKind.Parameter:
|
|
20594
|
+
if (node.parent.kind !== ts9.SyntaxKind.IndexSignature && (node.name.kind !== ts9.SyntaxKind.Identifier || identifierToKeywordKind(node.name) !== ts9.SyntaxKind.ThisKeyword)) {
|
|
20595
|
+
this.#handleBindingName(node.name, false, false);
|
|
20596
|
+
}
|
|
20597
|
+
break;
|
|
20598
|
+
case ts9.SyntaxKind.TypeParameter:
|
|
20599
|
+
this.#scope.addVariable(node.name.text, node.name, node.parent.kind === ts9.SyntaxKind.InferType ? 8 : 7, false, 2);
|
|
20600
|
+
break;
|
|
20601
|
+
case ts9.SyntaxKind.VariableDeclarationList:
|
|
20602
|
+
this.#handleVariableDeclaration(node);
|
|
20603
|
+
break;
|
|
20604
|
+
}
|
|
20605
|
+
return ts9.forEachChild(node, cb);
|
|
20606
|
+
};
|
|
20607
|
+
const continueWithScope = (node, scope, next = forEachChild) => {
|
|
20608
|
+
const savedScope = this.#scope;
|
|
20609
|
+
this.#scope = scope;
|
|
20610
|
+
next(node);
|
|
20611
|
+
this.#scope.end(variableCallback);
|
|
20612
|
+
this.#scope = savedScope;
|
|
20613
|
+
};
|
|
20614
|
+
const handleBlockScope = (node) => {
|
|
20615
|
+
if (node.kind === ts9.SyntaxKind.CatchClause && node.variableDeclaration !== undefined) {
|
|
20616
|
+
this.#handleBindingName(node.variableDeclaration.name, true, false);
|
|
20617
|
+
}
|
|
20618
|
+
return ts9.forEachChild(node, cb);
|
|
20619
|
+
};
|
|
20620
|
+
ts9.forEachChild(sourceFile, cb);
|
|
20621
|
+
this.#scope.end(variableCallback);
|
|
20622
|
+
return this.#result;
|
|
20623
|
+
function forEachChild(node) {
|
|
20624
|
+
return ts9.forEachChild(node, cb);
|
|
20625
|
+
}
|
|
20626
|
+
}
|
|
20627
|
+
#handleBindingName(name, blockScoped, exported) {
|
|
20628
|
+
if (name.kind === ts9.SyntaxKind.Identifier) {
|
|
20629
|
+
return this.#scope.addVariable(name.text, name, blockScoped ? 3 : 1, exported, 4);
|
|
20630
|
+
}
|
|
20631
|
+
forEachDestructuringIdentifier(name, (declaration) => {
|
|
20632
|
+
this.#scope.addVariable(declaration.name.text, declaration.name, blockScoped ? 3 : 1, exported, 4);
|
|
20633
|
+
});
|
|
20634
|
+
}
|
|
20635
|
+
#handleConditionalType(node, cb, varCb) {
|
|
20636
|
+
const savedScope = this.#scope;
|
|
20637
|
+
const scope = this.#scope = new ConditionalTypeScope(savedScope);
|
|
20638
|
+
cb(node.checkType);
|
|
20639
|
+
scope.updateState(1);
|
|
20640
|
+
cb(node.extendsType);
|
|
20641
|
+
scope.updateState(2);
|
|
20642
|
+
cb(node.trueType);
|
|
20643
|
+
scope.updateState(3);
|
|
20644
|
+
cb(node.falseType);
|
|
20645
|
+
scope.end(varCb);
|
|
20646
|
+
this.#scope = savedScope;
|
|
20647
|
+
}
|
|
20648
|
+
#handleDeclaration(node, blockScoped, domain) {
|
|
20649
|
+
if (node.name !== undefined) {
|
|
20650
|
+
this.#scope.addVariable(node.name.text, node.name, blockScoped ? 3 : 1, includesModifier(node.modifiers, ts9.SyntaxKind.ExportKeyword), domain);
|
|
20651
|
+
}
|
|
20652
|
+
}
|
|
20653
|
+
#handleFunctionLikeDeclaration(node, cb, varCb) {
|
|
20654
|
+
if (ts9.canHaveDecorators(node)) {
|
|
20655
|
+
ts9.getDecorators(node)?.forEach(cb);
|
|
20656
|
+
}
|
|
20657
|
+
const savedScope = this.#scope;
|
|
20658
|
+
if (node.kind === ts9.SyntaxKind.FunctionDeclaration) {
|
|
20659
|
+
this.#handleDeclaration(node, false, 4);
|
|
20660
|
+
}
|
|
20661
|
+
const scope = this.#scope = node.kind === ts9.SyntaxKind.FunctionExpression && node.name !== undefined ? new FunctionExpressionScope(node.name, savedScope) : new FunctionScope(savedScope);
|
|
20662
|
+
if (node.name !== undefined) {
|
|
20663
|
+
cb(node.name);
|
|
20664
|
+
}
|
|
20665
|
+
if (node.typeParameters !== undefined) {
|
|
20666
|
+
node.typeParameters.forEach(cb);
|
|
20667
|
+
}
|
|
20668
|
+
node.parameters.forEach(cb);
|
|
20669
|
+
if (node.type !== undefined) {
|
|
20670
|
+
cb(node.type);
|
|
20671
|
+
}
|
|
20672
|
+
if (node.body !== undefined) {
|
|
20673
|
+
scope.beginBody();
|
|
20674
|
+
cb(node.body);
|
|
20675
|
+
}
|
|
20676
|
+
scope.end(varCb);
|
|
20677
|
+
this.#scope = savedScope;
|
|
20678
|
+
}
|
|
20679
|
+
#handleModule(node, next) {
|
|
20680
|
+
if (node.flags & ts9.NodeFlags.GlobalAugmentation) {
|
|
20681
|
+
return next(node, this.#scope.createOrReuseNamespaceScope("-global", false, true, false));
|
|
20682
|
+
}
|
|
20683
|
+
if (node.name.kind === ts9.SyntaxKind.Identifier) {
|
|
20684
|
+
const exported = isNamespaceExported(node);
|
|
20685
|
+
this.#scope.addVariable(node.name.text, node.name, 1, exported, 1 | 4);
|
|
20686
|
+
const ambient = includesModifier(node.modifiers, ts9.SyntaxKind.DeclareKeyword);
|
|
20687
|
+
return next(node, this.#scope.createOrReuseNamespaceScope(node.name.text, exported, ambient, ambient && namespaceHasExportStatement(node)));
|
|
20688
|
+
}
|
|
20689
|
+
return next(node, this.#scope.createOrReuseNamespaceScope(`"${node.name.text}"`, false, true, namespaceHasExportStatement(node)));
|
|
20690
|
+
}
|
|
20691
|
+
#handleVariableDeclaration(declarationList) {
|
|
20692
|
+
const blockScoped = isBlockScopedVariableDeclarationList(declarationList);
|
|
20693
|
+
const exported = declarationList.parent.kind === ts9.SyntaxKind.VariableStatement && includesModifier(declarationList.parent.modifiers, ts9.SyntaxKind.ExportKeyword);
|
|
20694
|
+
for (const declaration of declarationList.declarations) {
|
|
20695
|
+
this.#handleBindingName(declaration.name, blockScoped, exported);
|
|
20696
|
+
}
|
|
20697
|
+
}
|
|
20698
|
+
};
|
|
20699
|
+
function containsExportStatement(block) {
|
|
20700
|
+
for (const statement of block.statements) {
|
|
20701
|
+
if (statement.kind === ts9.SyntaxKind.ExportDeclaration || statement.kind === ts9.SyntaxKind.ExportAssignment) {
|
|
20702
|
+
return true;
|
|
20703
|
+
}
|
|
20704
|
+
}
|
|
20705
|
+
return false;
|
|
20706
|
+
}
|
|
20707
|
+
function forEachDestructuringIdentifier(pattern4, fn) {
|
|
20708
|
+
for (const element of pattern4.elements) {
|
|
20709
|
+
if (element.kind !== ts9.SyntaxKind.BindingElement) {
|
|
20710
|
+
continue;
|
|
20711
|
+
}
|
|
20712
|
+
let result;
|
|
20713
|
+
if (element.name.kind === ts9.SyntaxKind.Identifier) {
|
|
20714
|
+
result = fn(element);
|
|
20715
|
+
} else {
|
|
20716
|
+
result = forEachDestructuringIdentifier(element.name, fn);
|
|
20717
|
+
}
|
|
20718
|
+
if (result) {
|
|
20719
|
+
return result;
|
|
20720
|
+
}
|
|
20721
|
+
}
|
|
20722
|
+
}
|
|
20723
|
+
function isBlockScopedVariableDeclarationList(declarationList) {
|
|
20724
|
+
return (declarationList.flags & ts9.NodeFlags.BlockScoped) !== 0;
|
|
20725
|
+
}
|
|
20726
|
+
function isNamespaceExported(node) {
|
|
20727
|
+
return node.parent.kind === ts9.SyntaxKind.ModuleDeclaration || includesModifier(node.modifiers, ts9.SyntaxKind.ExportKeyword);
|
|
20728
|
+
}
|
|
20729
|
+
function namespaceHasExportStatement(ns) {
|
|
20730
|
+
if (ns.body === undefined || ns.body.kind !== ts9.SyntaxKind.ModuleBlock) {
|
|
20731
|
+
return false;
|
|
20732
|
+
}
|
|
20733
|
+
return containsExportStatement(ns.body);
|
|
20734
|
+
}
|
|
20735
|
+
|
|
20736
|
+
// src/rules/prefer-enum-item.ts
|
|
20737
|
+
import { SymbolFlags } from "typescript";
|
|
20738
|
+
function isJSXAttributeValue(node) {
|
|
20739
|
+
const { parent } = node;
|
|
20740
|
+
return parent !== undefined && parent.type === AST_NODE_TYPES7.JSXAttribute && parent.value === node;
|
|
20741
|
+
}
|
|
20742
|
+
function canHaveContextualEnumType(node) {
|
|
20743
|
+
const { parent } = node;
|
|
20744
|
+
if (parent === undefined)
|
|
20745
|
+
return false;
|
|
20746
|
+
switch (parent.type) {
|
|
20747
|
+
case AST_NODE_TYPES7.CallExpression:
|
|
20748
|
+
case AST_NODE_TYPES7.NewExpression:
|
|
20749
|
+
return parent.arguments.includes(node);
|
|
20750
|
+
case AST_NODE_TYPES7.Property:
|
|
20751
|
+
return parent.value === node;
|
|
20752
|
+
case AST_NODE_TYPES7.JSXAttribute:
|
|
20753
|
+
return parent.value === node;
|
|
20754
|
+
case AST_NODE_TYPES7.VariableDeclarator: {
|
|
20755
|
+
if (parent.init !== node)
|
|
20756
|
+
return false;
|
|
20757
|
+
const { id: id2 } = parent;
|
|
20758
|
+
return id2.type === AST_NODE_TYPES7.Identifier && id2.typeAnnotation !== undefined;
|
|
20759
|
+
}
|
|
20760
|
+
default:
|
|
20761
|
+
return false;
|
|
20762
|
+
}
|
|
20763
|
+
}
|
|
19756
20764
|
var ENUM_PREFIX = "Enum.";
|
|
20765
|
+
var enumLiteralIndexCache = new WeakMap;
|
|
19757
20766
|
function getFullEnumPath(checker, type3) {
|
|
19758
20767
|
const symbol3 = type3.getSymbol();
|
|
19759
20768
|
if (symbol3 === undefined)
|
|
@@ -19775,8 +20784,8 @@ function getPropertyLiteralType(checker, type3, propertyName) {
|
|
|
19775
20784
|
return;
|
|
19776
20785
|
}
|
|
19777
20786
|
function getUnionTypes(type3) {
|
|
19778
|
-
if (type3
|
|
19779
|
-
return type3
|
|
20787
|
+
if (isUnionType(type3))
|
|
20788
|
+
return unionConstituents(type3);
|
|
19780
20789
|
return [type3];
|
|
19781
20790
|
}
|
|
19782
20791
|
function createEnumMatch(enumPath) {
|
|
@@ -19784,14 +20793,153 @@ function createEnumMatch(enumPath) {
|
|
|
19784
20793
|
}
|
|
19785
20794
|
var prefer_enum_item_default = createRule({
|
|
19786
20795
|
create(context) {
|
|
19787
|
-
const [{ fixNumericToValue = false } = {}] = context.options;
|
|
19788
|
-
const services =
|
|
20796
|
+
const [{ fixNumericToValue = false, performanceMode = false } = {}] = context.options;
|
|
20797
|
+
const services = ESLintUtils4.getParserServices(context);
|
|
19789
20798
|
const checker = services.program.getTypeChecker();
|
|
20799
|
+
const unionTypesCache = new WeakMap;
|
|
20800
|
+
const enumPathCache = new WeakMap;
|
|
20801
|
+
const enumItemInfoCache = new WeakMap;
|
|
20802
|
+
const enumLookupCache = new WeakMap;
|
|
20803
|
+
function getUnionTypesCached(type3) {
|
|
20804
|
+
const cached = unionTypesCache.get(type3);
|
|
20805
|
+
if (cached !== undefined)
|
|
20806
|
+
return cached;
|
|
20807
|
+
const resolved = isUnionType(type3) ? unionConstituents(type3) : [type3];
|
|
20808
|
+
unionTypesCache.set(type3, resolved);
|
|
20809
|
+
return resolved;
|
|
20810
|
+
}
|
|
20811
|
+
function getFullEnumPathCached(type3) {
|
|
20812
|
+
const cached = enumPathCache.get(type3);
|
|
20813
|
+
if (cached !== undefined)
|
|
20814
|
+
return cached === false ? undefined : cached;
|
|
20815
|
+
const resolved = getFullEnumPath(checker, type3);
|
|
20816
|
+
enumPathCache.set(type3, resolved ?? false);
|
|
20817
|
+
return resolved;
|
|
20818
|
+
}
|
|
20819
|
+
function getEnumItemInfo(type3) {
|
|
20820
|
+
const cached = enumItemInfoCache.get(type3);
|
|
20821
|
+
if (cached !== undefined)
|
|
20822
|
+
return cached === false ? undefined : cached;
|
|
20823
|
+
const enumPath = getFullEnumPathCached(type3);
|
|
20824
|
+
if (enumPath === undefined) {
|
|
20825
|
+
enumItemInfoCache.set(type3, false);
|
|
20826
|
+
return;
|
|
20827
|
+
}
|
|
20828
|
+
const nameLiteral = getPropertyLiteralType(checker, type3, "Name");
|
|
20829
|
+
const valueLiteral = getPropertyLiteralType(checker, type3, "Value");
|
|
20830
|
+
const info = {
|
|
20831
|
+
enumPath,
|
|
20832
|
+
...typeof nameLiteral === "string" ? { nameLiteral } : {},
|
|
20833
|
+
...typeof valueLiteral === "number" ? { valueLiteral } : {}
|
|
20834
|
+
};
|
|
20835
|
+
enumItemInfoCache.set(type3, info);
|
|
20836
|
+
return info;
|
|
20837
|
+
}
|
|
20838
|
+
function getEnumLookup(type3) {
|
|
20839
|
+
const cached = enumLookupCache.get(type3);
|
|
20840
|
+
if (cached !== undefined)
|
|
20841
|
+
return cached === false ? undefined : cached;
|
|
20842
|
+
const unionTypes = getUnionTypesCached(type3);
|
|
20843
|
+
const stringMap = new Map;
|
|
20844
|
+
const numberMap = new Map;
|
|
20845
|
+
let hasAny = false;
|
|
20846
|
+
for (const memberType of unionTypes) {
|
|
20847
|
+
const info = getEnumItemInfo(memberType);
|
|
20848
|
+
if (info === undefined)
|
|
20849
|
+
continue;
|
|
20850
|
+
hasAny = true;
|
|
20851
|
+
if (info.nameLiteral !== undefined && !stringMap.has(info.nameLiteral)) {
|
|
20852
|
+
stringMap.set(info.nameLiteral, info.enumPath);
|
|
20853
|
+
}
|
|
20854
|
+
if (info.valueLiteral !== undefined && !numberMap.has(info.valueLiteral)) {
|
|
20855
|
+
numberMap.set(info.valueLiteral, info.enumPath);
|
|
20856
|
+
}
|
|
20857
|
+
}
|
|
20858
|
+
if (!hasAny) {
|
|
20859
|
+
enumLookupCache.set(type3, false);
|
|
20860
|
+
return;
|
|
20861
|
+
}
|
|
20862
|
+
const lookup = { numberMap, stringMap };
|
|
20863
|
+
enumLookupCache.set(type3, lookup);
|
|
20864
|
+
return lookup;
|
|
20865
|
+
}
|
|
20866
|
+
function resolveAliasSymbol(symbol3) {
|
|
20867
|
+
if ((symbol3.flags & SymbolFlags.Alias) !== 0)
|
|
20868
|
+
return checker.getAliasedSymbol(symbol3);
|
|
20869
|
+
return symbol3;
|
|
20870
|
+
}
|
|
20871
|
+
function buildEnumLiteralIndex(anchorNode) {
|
|
20872
|
+
const resolved = checker.resolveName("Enum", anchorNode, SymbolFlags.Namespace, false);
|
|
20873
|
+
if (resolved === undefined)
|
|
20874
|
+
return;
|
|
20875
|
+
const enumSymbol = resolveAliasSymbol(resolved);
|
|
20876
|
+
if ((enumSymbol.flags & SymbolFlags.Namespace) === 0)
|
|
20877
|
+
return;
|
|
20878
|
+
const stringSet = new Set;
|
|
20879
|
+
const numberSet = new Set;
|
|
20880
|
+
const stack = [enumSymbol];
|
|
20881
|
+
const visited2 = new Set;
|
|
20882
|
+
while (stack.length > 0) {
|
|
20883
|
+
const current = stack.pop();
|
|
20884
|
+
if (current === undefined)
|
|
20885
|
+
continue;
|
|
20886
|
+
if (visited2.has(current))
|
|
20887
|
+
continue;
|
|
20888
|
+
visited2.add(current);
|
|
20889
|
+
const exports = checker.getExportsOfModule(current);
|
|
20890
|
+
for (const exportSymbol of exports) {
|
|
20891
|
+
const unaliased = resolveAliasSymbol(exportSymbol);
|
|
20892
|
+
if ((unaliased.flags & SymbolFlags.Namespace) !== 0) {
|
|
20893
|
+
stack.push(unaliased);
|
|
20894
|
+
continue;
|
|
20895
|
+
}
|
|
20896
|
+
const type3 = checker.getTypeOfSymbol(unaliased);
|
|
20897
|
+
const info = getEnumItemInfo(type3);
|
|
20898
|
+
if (info === undefined)
|
|
20899
|
+
continue;
|
|
20900
|
+
if (info.nameLiteral !== undefined)
|
|
20901
|
+
stringSet.add(info.nameLiteral);
|
|
20902
|
+
if (info.valueLiteral !== undefined)
|
|
20903
|
+
numberSet.add(info.valueLiteral);
|
|
20904
|
+
}
|
|
20905
|
+
}
|
|
20906
|
+
if (stringSet.size === 0 && numberSet.size === 0)
|
|
20907
|
+
return;
|
|
20908
|
+
return { numberSet, stringSet };
|
|
20909
|
+
}
|
|
20910
|
+
function getEnumLiteralIndex(anchorNode) {
|
|
20911
|
+
const cached = enumLiteralIndexCache.get(checker);
|
|
20912
|
+
if (cached !== undefined)
|
|
20913
|
+
return cached === false ? undefined : cached;
|
|
20914
|
+
const built = buildEnumLiteralIndex(anchorNode);
|
|
20915
|
+
enumLiteralIndexCache.set(checker, built ?? false);
|
|
20916
|
+
return built;
|
|
20917
|
+
}
|
|
19790
20918
|
function getContextualType(node) {
|
|
19791
20919
|
const tsNode = services.esTreeNodeToTSNodeMap.get(node);
|
|
19792
20920
|
return checker.getContextualType(tsNode);
|
|
19793
20921
|
}
|
|
20922
|
+
function shouldSkipLiteral(node, value) {
|
|
20923
|
+
if (!performanceMode)
|
|
20924
|
+
return false;
|
|
20925
|
+
const tsNode = services.esTreeNodeToTSNodeMap.get(node);
|
|
20926
|
+
if (tsNode === undefined)
|
|
20927
|
+
return false;
|
|
20928
|
+
const index2 = getEnumLiteralIndex(tsNode);
|
|
20929
|
+
if (index2 === undefined)
|
|
20930
|
+
return false;
|
|
20931
|
+
if (typeof value === "string")
|
|
20932
|
+
return !index2.stringSet.has(value);
|
|
20933
|
+
return !index2.numberSet.has(value);
|
|
20934
|
+
}
|
|
19794
20935
|
function findEnumMatch(contextualType, literalValue) {
|
|
20936
|
+
if (performanceMode) {
|
|
20937
|
+
const lookup = getEnumLookup(contextualType);
|
|
20938
|
+
if (lookup === undefined)
|
|
20939
|
+
return;
|
|
20940
|
+
const enumPath = typeof literalValue === "string" ? lookup.stringMap.get(literalValue) : lookup.numberMap.get(literalValue);
|
|
20941
|
+
return enumPath === undefined ? undefined : createEnumMatch(enumPath);
|
|
20942
|
+
}
|
|
19795
20943
|
const unionTypes = getUnionTypes(contextualType);
|
|
19796
20944
|
for (const memberType of unionTypes) {
|
|
19797
20945
|
const enumPath = getFullEnumPath(checker, memberType);
|
|
@@ -19814,6 +20962,10 @@ var prefer_enum_item_default = createRule({
|
|
|
19814
20962
|
const { value } = node;
|
|
19815
20963
|
if (typeof value !== "string" && typeof value !== "number")
|
|
19816
20964
|
return;
|
|
20965
|
+
if (!canHaveContextualEnumType(node))
|
|
20966
|
+
return;
|
|
20967
|
+
if (shouldSkipLiteral(node, value))
|
|
20968
|
+
return;
|
|
19817
20969
|
const contextualType = getContextualType(node);
|
|
19818
20970
|
if (contextualType === undefined)
|
|
19819
20971
|
return;
|
|
@@ -19823,6 +20975,8 @@ var prefer_enum_item_default = createRule({
|
|
|
19823
20975
|
const isString = typeof value === "string";
|
|
19824
20976
|
const displayValue = isString ? `"${value}"` : String(value);
|
|
19825
20977
|
const fixPath = fixNumericToValue && !isString ? `${match.enumPath}.Value` : match.enumPath;
|
|
20978
|
+
const needsJSXBraces = isJSXAttributeValue(node);
|
|
20979
|
+
const fixText = needsJSXBraces ? `{${fixPath}}` : fixPath;
|
|
19826
20980
|
context.report({
|
|
19827
20981
|
data: {
|
|
19828
20982
|
enumType: match.enumPath.split(".").slice(0, -1).join("."),
|
|
@@ -19830,7 +20984,7 @@ var prefer_enum_item_default = createRule({
|
|
|
19830
20984
|
value: displayValue
|
|
19831
20985
|
},
|
|
19832
20986
|
fix(fixer) {
|
|
19833
|
-
return fixer.replaceText(node,
|
|
20987
|
+
return fixer.replaceText(node, fixText);
|
|
19834
20988
|
},
|
|
19835
20989
|
messageId: "preferEnumItem",
|
|
19836
20990
|
node
|
|
@@ -19838,7 +20992,7 @@ var prefer_enum_item_default = createRule({
|
|
|
19838
20992
|
}
|
|
19839
20993
|
};
|
|
19840
20994
|
},
|
|
19841
|
-
defaultOptions: [{}],
|
|
20995
|
+
defaultOptions: [{ fixNumericToValue: false, performanceMode: false }],
|
|
19842
20996
|
meta: {
|
|
19843
20997
|
docs: {
|
|
19844
20998
|
description: "Enforce using EnumItem values instead of string or number literals."
|
|
@@ -19855,6 +21009,11 @@ var prefer_enum_item_default = createRule({
|
|
|
19855
21009
|
default: false,
|
|
19856
21010
|
description: "When true, numeric literals fix to Enum.X.Y.Value instead of Enum.X.Y",
|
|
19857
21011
|
type: "boolean"
|
|
21012
|
+
},
|
|
21013
|
+
performanceMode: {
|
|
21014
|
+
default: false,
|
|
21015
|
+
description: "When true, uses caching to speed up enum lookups without changing behavior",
|
|
21016
|
+
type: "boolean"
|
|
19858
21017
|
}
|
|
19859
21018
|
},
|
|
19860
21019
|
type: "object"
|
|
@@ -19867,7 +21026,7 @@ var prefer_enum_item_default = createRule({
|
|
|
19867
21026
|
|
|
19868
21027
|
// src/rules/prefer-module-scope-constants.ts
|
|
19869
21028
|
var import_scope_manager3 = __toESM(require_dist2(), 1);
|
|
19870
|
-
import { AST_NODE_TYPES as
|
|
21029
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES8 } from "@typescript-eslint/utils";
|
|
19871
21030
|
var SCREAMING_SNAKE_CASE = /^[A-Z][A-Z0-9_]*$/;
|
|
19872
21031
|
function isTopScope(scope) {
|
|
19873
21032
|
const { type: type3 } = scope;
|
|
@@ -19875,7 +21034,7 @@ function isTopScope(scope) {
|
|
|
19875
21034
|
return true;
|
|
19876
21035
|
if (scope.upper?.type === import_scope_manager3.ScopeType.global) {
|
|
19877
21036
|
const { block } = scope.upper;
|
|
19878
|
-
if (block.type ===
|
|
21037
|
+
if (block.type === AST_NODE_TYPES8.Program && block.sourceType === "script")
|
|
19879
21038
|
return true;
|
|
19880
21039
|
}
|
|
19881
21040
|
return false;
|
|
@@ -19892,7 +21051,7 @@ var prefer_module_scope_constants_default = createRule({
|
|
|
19892
21051
|
},
|
|
19893
21052
|
VariableDeclarator(node) {
|
|
19894
21053
|
const { id: id2 } = node;
|
|
19895
|
-
if (id2.type !==
|
|
21054
|
+
if (id2.type !== AST_NODE_TYPES8.Identifier || !SCREAMING_SNAKE_CASE.test(id2.name))
|
|
19896
21055
|
return;
|
|
19897
21056
|
if (!inConstDeclaration) {
|
|
19898
21057
|
context.report({
|
|
@@ -19927,7 +21086,7 @@ var prefer_module_scope_constants_default = createRule({
|
|
|
19927
21086
|
});
|
|
19928
21087
|
|
|
19929
21088
|
// src/rules/prefer-pascal-case-enums.ts
|
|
19930
|
-
import { AST_NODE_TYPES as
|
|
21089
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES9 } from "@typescript-eslint/utils";
|
|
19931
21090
|
|
|
19932
21091
|
// src/utilities/casing-utilities.ts
|
|
19933
21092
|
var SPLIT_LOWER_TO_UPPER = regex2("([\\p{Ll}\\d])(\\p{Lu})", "gu");
|
|
@@ -19967,9 +21126,9 @@ function toPascalCase(value) {
|
|
|
19967
21126
|
// src/rules/prefer-pascal-case-enums.ts
|
|
19968
21127
|
var STARTS_WITH_DIGIT = regex2("^\\d");
|
|
19969
21128
|
function getIdentifierName(node) {
|
|
19970
|
-
if (node.type ===
|
|
21129
|
+
if (node.type === AST_NODE_TYPES9.Identifier)
|
|
19971
21130
|
return node.name;
|
|
19972
|
-
if (node.type !==
|
|
21131
|
+
if (node.type !== AST_NODE_TYPES9.Literal || typeof node.value !== "string")
|
|
19973
21132
|
return;
|
|
19974
21133
|
return STARTS_WITH_DIGIT.test(node.value) ? undefined : node.value;
|
|
19975
21134
|
}
|
|
@@ -20012,17 +21171,17 @@ var prefer_pascal_case_enums_default = createRule({
|
|
|
20012
21171
|
});
|
|
20013
21172
|
|
|
20014
21173
|
// src/utilities/pattern-replacement/pattern-matcher.ts
|
|
20015
|
-
import { AST_NODE_TYPES as
|
|
21174
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES11 } from "@typescript-eslint/types";
|
|
20016
21175
|
|
|
20017
21176
|
// src/utilities/pattern-replacement/constant-folder.ts
|
|
20018
|
-
import { AST_NODE_TYPES as
|
|
21177
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES10 } from "@typescript-eslint/types";
|
|
20019
21178
|
function normalizeZero(num) {
|
|
20020
21179
|
return Object.is(num, -0) ? 0 : num;
|
|
20021
21180
|
}
|
|
20022
21181
|
function unwrap(node) {
|
|
20023
21182
|
switch (node.type) {
|
|
20024
|
-
case
|
|
20025
|
-
case
|
|
21183
|
+
case AST_NODE_TYPES10.TSAsExpression:
|
|
21184
|
+
case AST_NODE_TYPES10.TSNonNullExpression:
|
|
20026
21185
|
return unwrap(node.expression);
|
|
20027
21186
|
default:
|
|
20028
21187
|
return node;
|
|
@@ -20030,10 +21189,10 @@ function unwrap(node) {
|
|
|
20030
21189
|
}
|
|
20031
21190
|
function evaluateConstant(node) {
|
|
20032
21191
|
const expression = unwrap(node);
|
|
20033
|
-
if (expression.type ===
|
|
21192
|
+
if (expression.type === AST_NODE_TYPES10.Literal && typeof expression.value === "number") {
|
|
20034
21193
|
return normalizeZero(expression.value);
|
|
20035
21194
|
}
|
|
20036
|
-
if (expression.type ===
|
|
21195
|
+
if (expression.type === AST_NODE_TYPES10.UnaryExpression) {
|
|
20037
21196
|
const argument = evaluateConstant(expression.argument);
|
|
20038
21197
|
if (argument === undefined)
|
|
20039
21198
|
return;
|
|
@@ -20046,8 +21205,8 @@ function evaluateConstant(node) {
|
|
|
20046
21205
|
return;
|
|
20047
21206
|
}
|
|
20048
21207
|
}
|
|
20049
|
-
if (expression.type ===
|
|
20050
|
-
if (expression.left.type ===
|
|
21208
|
+
if (expression.type === AST_NODE_TYPES10.BinaryExpression) {
|
|
21209
|
+
if (expression.left.type === AST_NODE_TYPES10.PrivateIdentifier)
|
|
20051
21210
|
return;
|
|
20052
21211
|
const left = evaluateConstant(expression.left);
|
|
20053
21212
|
const right = evaluateConstant(expression.right);
|
|
@@ -20090,14 +21249,14 @@ function buildPatternIndex(patterns2) {
|
|
|
20090
21249
|
}
|
|
20091
21250
|
function resolveCallee(node) {
|
|
20092
21251
|
const callee = unwrap(node.callee);
|
|
20093
|
-
if (node.type ===
|
|
21252
|
+
if (node.type === AST_NODE_TYPES11.NewExpression && callee.type === AST_NODE_TYPES11.Identifier) {
|
|
20094
21253
|
return { kind: "constructor", typeName: callee.name };
|
|
20095
21254
|
}
|
|
20096
|
-
if (node.type ===
|
|
20097
|
-
const member = callee.type ===
|
|
20098
|
-
if (member.type ===
|
|
21255
|
+
if (node.type === AST_NODE_TYPES11.CallExpression) {
|
|
21256
|
+
const member = callee.type === AST_NODE_TYPES11.ChainExpression ? unwrap(callee.expression) : callee;
|
|
21257
|
+
if (member.type === AST_NODE_TYPES11.MemberExpression && !member.computed) {
|
|
20099
21258
|
const object3 = unwrap(member.object);
|
|
20100
|
-
if (object3.type ===
|
|
21259
|
+
if (object3.type === AST_NODE_TYPES11.Identifier && member.property.type === AST_NODE_TYPES11.Identifier) {
|
|
20101
21260
|
return {
|
|
20102
21261
|
kind: "staticMethod",
|
|
20103
21262
|
methodName: member.property.name,
|
|
@@ -20114,9 +21273,9 @@ function captureParameter(node, sourceCode) {
|
|
|
20114
21273
|
const constValue = evaluateConstant(expression);
|
|
20115
21274
|
let expressionKey;
|
|
20116
21275
|
let isComplex = false;
|
|
20117
|
-
if (expression.type ===
|
|
21276
|
+
if (expression.type === AST_NODE_TYPES11.Literal && typeof expression.value === "number") {
|
|
20118
21277
|
expressionKey = `literal:${normalizeZero(expression.value)}`;
|
|
20119
|
-
} else if (expression.type ===
|
|
21278
|
+
} else if (expression.type === AST_NODE_TYPES11.Identifier) {
|
|
20120
21279
|
if (expression.name === "undefined")
|
|
20121
21280
|
expressionKey = "undefined";
|
|
20122
21281
|
else
|
|
@@ -20142,7 +21301,7 @@ function matchParameters(patterns2, parameters3, sourceCode) {
|
|
|
20142
21301
|
continue;
|
|
20143
21302
|
const parameter2 = parameters3[index2];
|
|
20144
21303
|
const unwrappedParameter = parameter2 === undefined ? undefined : unwrap(parameter2);
|
|
20145
|
-
const isMissing = parameter2 === undefined || unwrappedParameter?.type ===
|
|
21304
|
+
const isMissing = parameter2 === undefined || unwrappedParameter?.type === AST_NODE_TYPES11.Identifier && unwrappedParameter.name === "undefined";
|
|
20146
21305
|
if (pattern4.kind === "literal") {
|
|
20147
21306
|
if (isMissing)
|
|
20148
21307
|
return;
|
|
@@ -20432,13 +21591,13 @@ var prefer_pattern_replacements_default = createRule({
|
|
|
20432
21591
|
});
|
|
20433
21592
|
|
|
20434
21593
|
// src/rules/prefer-sequence-overloads.ts
|
|
20435
|
-
import { AST_NODE_TYPES as
|
|
21594
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES12 } from "@typescript-eslint/types";
|
|
20436
21595
|
var sequenceDescriptors = [
|
|
20437
21596
|
{ keypointName: "ColorSequenceKeypoint", sequenceName: "ColorSequence" },
|
|
20438
21597
|
{ keypointName: "NumberSequenceKeypoint", sequenceName: "NumberSequence" }
|
|
20439
21598
|
];
|
|
20440
21599
|
function isSequenceIdentifier(node) {
|
|
20441
|
-
if (node.type !==
|
|
21600
|
+
if (node.type !== AST_NODE_TYPES12.Identifier)
|
|
20442
21601
|
return false;
|
|
20443
21602
|
for (const { sequenceName } of sequenceDescriptors)
|
|
20444
21603
|
if (sequenceName === node.name)
|
|
@@ -20452,16 +21611,16 @@ function findDescriptor(sequenceName) {
|
|
|
20452
21611
|
return;
|
|
20453
21612
|
}
|
|
20454
21613
|
var isNumericLiteral = Compile(build_default.Object({
|
|
20455
|
-
type: build_default.Literal(
|
|
21614
|
+
type: build_default.Literal(AST_NODE_TYPES12.Literal),
|
|
20456
21615
|
value: build_default.Number()
|
|
20457
21616
|
}));
|
|
20458
21617
|
function isExpressionArgument(argument) {
|
|
20459
|
-
return argument !== undefined && argument.type !==
|
|
21618
|
+
return argument !== undefined && argument.type !== AST_NODE_TYPES12.SpreadElement;
|
|
20460
21619
|
}
|
|
20461
21620
|
function extractKeypoint(element, descriptor) {
|
|
20462
|
-
if (element === undefined || element.type !==
|
|
21621
|
+
if (element === undefined || element.type !== AST_NODE_TYPES12.NewExpression)
|
|
20463
21622
|
return;
|
|
20464
|
-
if (element.callee.type !==
|
|
21623
|
+
if (element.callee.type !== AST_NODE_TYPES12.Identifier || element.callee.name !== descriptor.keypointName)
|
|
20465
21624
|
return;
|
|
20466
21625
|
if (element.arguments.length !== 2)
|
|
20467
21626
|
return;
|
|
@@ -20487,7 +21646,7 @@ var prefer_sequence_overloads_default = createRule({
|
|
|
20487
21646
|
if (descriptor === undefined || node.arguments.length !== 1)
|
|
20488
21647
|
return;
|
|
20489
21648
|
const [argument] = node.arguments;
|
|
20490
|
-
if (argument === undefined || argument.type !==
|
|
21649
|
+
if (argument === undefined || argument.type !== AST_NODE_TYPES12.ArrayExpression || argument.elements.length !== 2)
|
|
20491
21650
|
return;
|
|
20492
21651
|
const firstElement = argument.elements[0] ?? undefined;
|
|
20493
21652
|
const secondElement = argument.elements[1] ?? undefined;
|
|
@@ -20677,7 +21836,7 @@ var prefer_singular_enums_default = createRule({
|
|
|
20677
21836
|
});
|
|
20678
21837
|
|
|
20679
21838
|
// src/rules/prefer-udim2-shorthand.ts
|
|
20680
|
-
import { TSESTree as
|
|
21839
|
+
import { TSESTree as TSESTree8 } from "@typescript-eslint/utils";
|
|
20681
21840
|
function isNumber(value) {
|
|
20682
21841
|
return typeof value === "number" && !Number.isNaN(value);
|
|
20683
21842
|
}
|
|
@@ -20691,15 +21850,15 @@ var OPERATORS2 = new Set(["+", "-", "*", "/", "%"]);
|
|
|
20691
21850
|
function reconstructText(node) {
|
|
20692
21851
|
const nodeType = node.type;
|
|
20693
21852
|
let text;
|
|
20694
|
-
if (nodeType ===
|
|
21853
|
+
if (nodeType === TSESTree8.AST_NODE_TYPES.Literal) {
|
|
20695
21854
|
const { value } = node;
|
|
20696
21855
|
text = isNumber(value) ? String(value) : undefined;
|
|
20697
21856
|
}
|
|
20698
|
-
if (nodeType ===
|
|
21857
|
+
if (nodeType === TSESTree8.AST_NODE_TYPES.Identifier) {
|
|
20699
21858
|
const { name } = node;
|
|
20700
21859
|
text = typeof name === "string" ? name : undefined;
|
|
20701
21860
|
}
|
|
20702
|
-
if (nodeType ===
|
|
21861
|
+
if (nodeType === TSESTree8.AST_NODE_TYPES.UnaryExpression) {
|
|
20703
21862
|
const { operator } = node;
|
|
20704
21863
|
if (typeof operator === "string") {
|
|
20705
21864
|
const { argument } = node;
|
|
@@ -20710,7 +21869,7 @@ function reconstructText(node) {
|
|
|
20710
21869
|
}
|
|
20711
21870
|
}
|
|
20712
21871
|
}
|
|
20713
|
-
if (nodeType ===
|
|
21872
|
+
if (nodeType === TSESTree8.AST_NODE_TYPES.BinaryExpression) {
|
|
20714
21873
|
const { operator } = node;
|
|
20715
21874
|
if (typeof operator === "string" && OPERATORS2.has(operator)) {
|
|
20716
21875
|
const { left, right } = node;
|
|
@@ -20773,11 +21932,11 @@ function evaluateExpression(node) {
|
|
|
20773
21932
|
if (!isRecord3(node))
|
|
20774
21933
|
return;
|
|
20775
21934
|
switch (node.type) {
|
|
20776
|
-
case
|
|
21935
|
+
case TSESTree8.AST_NODE_TYPES.Literal:
|
|
20777
21936
|
return evaluateLiteral(node);
|
|
20778
|
-
case
|
|
21937
|
+
case TSESTree8.AST_NODE_TYPES.UnaryExpression:
|
|
20779
21938
|
return evaluateUnary(node);
|
|
20780
|
-
case
|
|
21939
|
+
case TSESTree8.AST_NODE_TYPES.BinaryExpression:
|
|
20781
21940
|
return evaluateBinary(node);
|
|
20782
21941
|
default:
|
|
20783
21942
|
return;
|
|
@@ -20791,7 +21950,7 @@ function collectArguments(_context2, parameters3) {
|
|
|
20791
21950
|
const parameter2 = parameters3[index2];
|
|
20792
21951
|
if (!(isRecord3(parameter2) && hasTypeProperty(parameter2)))
|
|
20793
21952
|
return;
|
|
20794
|
-
if (parameter2.type ===
|
|
21953
|
+
if (parameter2.type === TSESTree8.AST_NODE_TYPES.SpreadElement)
|
|
20795
21954
|
return;
|
|
20796
21955
|
const text = reconstructText(parameter2);
|
|
20797
21956
|
if (text === undefined)
|
|
@@ -20808,7 +21967,7 @@ var preferUDim2Shorthand = {
|
|
|
20808
21967
|
create(context) {
|
|
20809
21968
|
return {
|
|
20810
21969
|
NewExpression(node) {
|
|
20811
|
-
if (node.callee.type !==
|
|
21970
|
+
if (node.callee.type !== TSESTree8.AST_NODE_TYPES.Identifier || node.callee.name !== "UDim2")
|
|
20812
21971
|
return;
|
|
20813
21972
|
const collected = collectArguments(context, node.arguments);
|
|
20814
21973
|
if (!collected)
|
|
@@ -20855,16 +22014,16 @@ var preferUDim2Shorthand = {
|
|
|
20855
22014
|
var prefer_udim2_shorthand_default = preferUDim2Shorthand;
|
|
20856
22015
|
|
|
20857
22016
|
// src/rules/react-hooks-strict-return.ts
|
|
20858
|
-
import { AST_NODE_TYPES as
|
|
22017
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES13 } from "@typescript-eslint/utils";
|
|
20859
22018
|
var MAX_RETURN_ELEMENTS = 2;
|
|
20860
22019
|
var HOOK_PATTERN = /^use[A-Z0-9].*$/;
|
|
20861
22020
|
function isHookNode(node) {
|
|
20862
22021
|
let name;
|
|
20863
|
-
if (node.type ===
|
|
22022
|
+
if (node.type === AST_NODE_TYPES13.VariableDeclarator && node.id.type === AST_NODE_TYPES13.Identifier) {
|
|
20864
22023
|
({ name } = node.id);
|
|
20865
|
-
} else if (node.type ===
|
|
22024
|
+
} else if (node.type === AST_NODE_TYPES13.FunctionDeclaration && node.id)
|
|
20866
22025
|
({ name } = node.id);
|
|
20867
|
-
else if (node.type ===
|
|
22026
|
+
else if (node.type === AST_NODE_TYPES13.FunctionExpression && node.id)
|
|
20868
22027
|
({ name } = node.id);
|
|
20869
22028
|
return name !== undefined && HOOK_PATTERN.test(name);
|
|
20870
22029
|
}
|
|
@@ -20888,27 +22047,27 @@ function getArrayElementsFromVariable(scope, name) {
|
|
|
20888
22047
|
if (!identifier3.parent)
|
|
20889
22048
|
continue;
|
|
20890
22049
|
const { parent } = identifier3;
|
|
20891
|
-
if (parent.type !==
|
|
22050
|
+
if (parent.type !== AST_NODE_TYPES13.VariableDeclarator)
|
|
20892
22051
|
continue;
|
|
20893
|
-
if (!parent.init || parent.init.type !==
|
|
22052
|
+
if (!parent.init || parent.init.type !== AST_NODE_TYPES13.ArrayExpression)
|
|
20894
22053
|
continue;
|
|
20895
22054
|
elements.push(...parent.init.elements);
|
|
20896
22055
|
}
|
|
20897
22056
|
return elements;
|
|
20898
22057
|
}
|
|
20899
22058
|
function countReturnElements(argument, scope) {
|
|
20900
|
-
if (argument.type ===
|
|
22059
|
+
if (argument.type === AST_NODE_TYPES13.Identifier)
|
|
20901
22060
|
return getArrayElementsFromVariable(scope, argument.name).length;
|
|
20902
|
-
if (argument.type !==
|
|
22061
|
+
if (argument.type !== AST_NODE_TYPES13.ArrayExpression)
|
|
20903
22062
|
return 0;
|
|
20904
22063
|
let count = 0;
|
|
20905
22064
|
for (const element of argument.elements) {
|
|
20906
22065
|
if (element === null)
|
|
20907
22066
|
count += 1;
|
|
20908
|
-
else if (element.type ===
|
|
20909
|
-
if (element.argument.type ===
|
|
22067
|
+
else if (element.type === AST_NODE_TYPES13.SpreadElement) {
|
|
22068
|
+
if (element.argument.type === AST_NODE_TYPES13.Identifier) {
|
|
20910
22069
|
count += getArrayElementsFromVariable(scope, element.argument.name).length;
|
|
20911
|
-
} else if (element.argument.type ===
|
|
22070
|
+
} else if (element.argument.type === AST_NODE_TYPES13.ArrayExpression) {
|
|
20912
22071
|
count += element.argument.elements.length;
|
|
20913
22072
|
} else
|
|
20914
22073
|
count += 1;
|
|
@@ -20921,14 +22080,14 @@ function exceedsMaxReturnProperties(node, scope) {
|
|
|
20921
22080
|
const { argument } = node;
|
|
20922
22081
|
if (argument === null)
|
|
20923
22082
|
return false;
|
|
20924
|
-
if (argument.type ===
|
|
22083
|
+
if (argument.type === AST_NODE_TYPES13.ObjectExpression)
|
|
20925
22084
|
return false;
|
|
20926
|
-
if (argument.type ===
|
|
22085
|
+
if (argument.type === AST_NODE_TYPES13.Identifier) {
|
|
20927
22086
|
const variable = getVariableByName(scope, argument.name);
|
|
20928
22087
|
if (variable) {
|
|
20929
22088
|
for (const { identifier: identifier3 } of variable.references) {
|
|
20930
22089
|
const { parent } = identifier3;
|
|
20931
|
-
if (parent?.type ===
|
|
22090
|
+
if (parent?.type === AST_NODE_TYPES13.VariableDeclarator && parent.init?.type === AST_NODE_TYPES13.ObjectExpression) {
|
|
20932
22091
|
return false;
|
|
20933
22092
|
}
|
|
20934
22093
|
}
|
|
@@ -20950,13 +22109,13 @@ var react_hooks_strict_return_default = createRule({
|
|
|
20950
22109
|
return {
|
|
20951
22110
|
ArrowFunctionExpression(node) {
|
|
20952
22111
|
const { parent } = node;
|
|
20953
|
-
if (parent?.type ===
|
|
22112
|
+
if (parent?.type === AST_NODE_TYPES13.VariableDeclarator && parent.id.type === AST_NODE_TYPES13.Identifier && HOOK_PATTERN.test(parent.id.name)) {
|
|
20954
22113
|
hookDepth += 1;
|
|
20955
22114
|
}
|
|
20956
22115
|
},
|
|
20957
22116
|
"ArrowFunctionExpression:exit"(node) {
|
|
20958
22117
|
const { parent } = node;
|
|
20959
|
-
if (parent?.type ===
|
|
22118
|
+
if (parent?.type === AST_NODE_TYPES13.VariableDeclarator && parent.id.type === AST_NODE_TYPES13.Identifier && HOOK_PATTERN.test(parent.id.name)) {
|
|
20960
22119
|
hookDepth -= 1;
|
|
20961
22120
|
}
|
|
20962
22121
|
},
|
|
@@ -20994,13 +22153,17 @@ var react_hooks_strict_return_default = createRule({
|
|
|
20994
22153
|
});
|
|
20995
22154
|
|
|
20996
22155
|
// src/rules/require-named-effect-functions.ts
|
|
20997
|
-
import { TSESTree as
|
|
22156
|
+
import { TSESTree as TSESTree9 } from "@typescript-eslint/types";
|
|
22157
|
+
|
|
22158
|
+
// src/types/environment-mode.ts
|
|
22159
|
+
var isEnvironmentMode = build_default.Union([build_default.Literal("roblox-ts"), build_default.Literal("standard")]);
|
|
22160
|
+
|
|
22161
|
+
// src/rules/require-named-effect-functions.ts
|
|
20998
22162
|
var DEFAULT_HOOKS = [
|
|
20999
22163
|
{ allowAsync: false, name: "useEffect" },
|
|
21000
22164
|
{ allowAsync: false, name: "useLayoutEffect" },
|
|
21001
22165
|
{ allowAsync: false, name: "useInsertionEffect" }
|
|
21002
22166
|
];
|
|
21003
|
-
var isEnvironmentMode = build_default.Union([build_default.Literal("roblox-ts"), build_default.Literal("standard")]);
|
|
21004
22167
|
var isHookConfiguration = build_default.Object({
|
|
21005
22168
|
allowAsync: build_default.Boolean(),
|
|
21006
22169
|
name: build_default.String()
|
|
@@ -21029,10 +22192,10 @@ function parseOptions2(options3) {
|
|
|
21029
22192
|
}
|
|
21030
22193
|
function getHookName3(callExpression) {
|
|
21031
22194
|
const { callee } = callExpression;
|
|
21032
|
-
if (callee.type ===
|
|
22195
|
+
if (callee.type === TSESTree9.AST_NODE_TYPES.Identifier && typeof callee.name === "string" && callee.name.length > 0) {
|
|
21033
22196
|
return callee.name;
|
|
21034
22197
|
}
|
|
21035
|
-
if (callee.type ===
|
|
22198
|
+
if (callee.type === TSESTree9.AST_NODE_TYPES.MemberExpression && callee.property?.type === TSESTree9.AST_NODE_TYPES.Identifier && typeof callee.property.name === "string" && callee.property.name.length > 0) {
|
|
21036
22199
|
return callee.property.name;
|
|
21037
22200
|
}
|
|
21038
22201
|
return;
|
|
@@ -21075,14 +22238,14 @@ function processFunctionExpression(init) {
|
|
|
21075
22238
|
}
|
|
21076
22239
|
function checkVariableDeclaratorDef(node) {
|
|
21077
22240
|
const castNode = node;
|
|
21078
|
-
if (castNode.type !==
|
|
22241
|
+
if (castNode.type !== TSESTree9.AST_NODE_TYPES.VariableDeclarator)
|
|
21079
22242
|
return;
|
|
21080
22243
|
if (typeof castNode.init !== "object" || castNode.init === null)
|
|
21081
22244
|
return;
|
|
21082
22245
|
const castInit = castNode.init;
|
|
21083
|
-
if (castInit.type ===
|
|
22246
|
+
if (castInit.type === TSESTree9.AST_NODE_TYPES.ArrowFunctionExpression)
|
|
21084
22247
|
return processArrowFunction(castNode.init);
|
|
21085
|
-
if (castInit.type ===
|
|
22248
|
+
if (castInit.type === TSESTree9.AST_NODE_TYPES.FunctionExpression)
|
|
21086
22249
|
return processFunctionExpression(castNode.init);
|
|
21087
22250
|
return;
|
|
21088
22251
|
}
|
|
@@ -21094,7 +22257,7 @@ function processSingleDefinition(definition) {
|
|
|
21094
22257
|
if (typeof node !== "object" || node === null)
|
|
21095
22258
|
return;
|
|
21096
22259
|
const castNode = node;
|
|
21097
|
-
if (castNode.type ===
|
|
22260
|
+
if (castNode.type === TSESTree9.AST_NODE_TYPES.FunctionDeclaration)
|
|
21098
22261
|
return processFunctionDeclaration(node);
|
|
21099
22262
|
return checkVariableDeclaratorDef(node);
|
|
21100
22263
|
}
|
|
@@ -21154,12 +22317,12 @@ function isCallbackHookResult(identifier3, context) {
|
|
|
21154
22317
|
if (typeof node !== "object" || node === null)
|
|
21155
22318
|
continue;
|
|
21156
22319
|
const castNode = node;
|
|
21157
|
-
if (castNode.type !==
|
|
22320
|
+
if (castNode.type !== TSESTree9.AST_NODE_TYPES.VariableDeclarator)
|
|
21158
22321
|
continue;
|
|
21159
22322
|
if (typeof castNode.init !== "object" || castNode.init === null)
|
|
21160
22323
|
continue;
|
|
21161
22324
|
const init = castNode.init;
|
|
21162
|
-
if (init.type !==
|
|
22325
|
+
if (init.type !== TSESTree9.AST_NODE_TYPES.CallExpression)
|
|
21163
22326
|
continue;
|
|
21164
22327
|
const calleeHookName = getHookName3(init);
|
|
21165
22328
|
if (calleeHookName === "useCallback" || calleeHookName === "useMemo")
|
|
@@ -21190,7 +22353,7 @@ var requireNamedEffectFunctions = {
|
|
|
21190
22353
|
if (firstArgument === undefined)
|
|
21191
22354
|
return;
|
|
21192
22355
|
const argumentNode = firstArgument;
|
|
21193
|
-
if (argumentNode.type ===
|
|
22356
|
+
if (argumentNode.type === TSESTree9.AST_NODE_TYPES.Identifier) {
|
|
21194
22357
|
const identifier3 = argumentNode;
|
|
21195
22358
|
const resolved = resolveIdentifierToFunction(identifier3, context);
|
|
21196
22359
|
if (resolved === undefined) {
|
|
@@ -21243,7 +22406,7 @@ var requireNamedEffectFunctions = {
|
|
|
21243
22406
|
}
|
|
21244
22407
|
return;
|
|
21245
22408
|
}
|
|
21246
|
-
if (argumentNode.type ===
|
|
22409
|
+
if (argumentNode.type === TSESTree9.AST_NODE_TYPES.ArrowFunctionExpression) {
|
|
21247
22410
|
if (argumentNode.async) {
|
|
21248
22411
|
context.report({
|
|
21249
22412
|
data: { hook: hookName },
|
|
@@ -21259,7 +22422,7 @@ var requireNamedEffectFunctions = {
|
|
|
21259
22422
|
}
|
|
21260
22423
|
return;
|
|
21261
22424
|
}
|
|
21262
|
-
if (argumentNode.type ===
|
|
22425
|
+
if (argumentNode.type === TSESTree9.AST_NODE_TYPES.FunctionExpression) {
|
|
21263
22426
|
const functionHasId = Boolean(argumentNode.id);
|
|
21264
22427
|
if (functionHasId && argumentNode.async) {
|
|
21265
22428
|
context.report({
|
|
@@ -21348,7 +22511,7 @@ var requireNamedEffectFunctions = {
|
|
|
21348
22511
|
var require_named_effect_functions_default = requireNamedEffectFunctions;
|
|
21349
22512
|
|
|
21350
22513
|
// src/rules/require-paired-calls.ts
|
|
21351
|
-
import { AST_NODE_TYPES as
|
|
22514
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES14 } from "@typescript-eslint/types";
|
|
21352
22515
|
var isStringArray = Compile(build_default.Readonly(build_default.Array(build_default.String())));
|
|
21353
22516
|
var isPairConfiguration = Compile(build_default.Readonly(build_default.Object({
|
|
21354
22517
|
alternatives: build_default.Optional(isStringArray),
|
|
@@ -21366,20 +22529,20 @@ var isRuleOptions4 = Compile(build_default.Partial(build_default.Readonly(build_
|
|
|
21366
22529
|
pairs: build_default.Readonly(build_default.Array(isPairConfiguration))
|
|
21367
22530
|
}))));
|
|
21368
22531
|
var LOOP_NODE_TYPES = new Set([
|
|
21369
|
-
|
|
21370
|
-
|
|
21371
|
-
|
|
21372
|
-
|
|
21373
|
-
|
|
22532
|
+
AST_NODE_TYPES14.DoWhileStatement,
|
|
22533
|
+
AST_NODE_TYPES14.ForInStatement,
|
|
22534
|
+
AST_NODE_TYPES14.ForOfStatement,
|
|
22535
|
+
AST_NODE_TYPES14.ForStatement,
|
|
22536
|
+
AST_NODE_TYPES14.WhileStatement
|
|
21374
22537
|
]);
|
|
21375
22538
|
var DEFAULT_ROBLOX_YIELDING_FUNCTIONS = ["task.wait", "wait", "*.WaitForChild", "*.*Async"];
|
|
21376
22539
|
function getCallName(node) {
|
|
21377
22540
|
const { callee } = node;
|
|
21378
|
-
if (callee.type ===
|
|
22541
|
+
if (callee.type === AST_NODE_TYPES14.Identifier)
|
|
21379
22542
|
return callee.name;
|
|
21380
|
-
if (callee.type ===
|
|
21381
|
-
const object3 = callee.object.type ===
|
|
21382
|
-
const property = callee.property.type ===
|
|
22543
|
+
if (callee.type === AST_NODE_TYPES14.MemberExpression) {
|
|
22544
|
+
const object3 = callee.object.type === AST_NODE_TYPES14.Identifier ? callee.object.name : undefined;
|
|
22545
|
+
const property = callee.property.type === AST_NODE_TYPES14.Identifier ? callee.property.name : undefined;
|
|
21383
22546
|
if (object3 !== undefined && property !== undefined)
|
|
21384
22547
|
return `${object3}.${property}`;
|
|
21385
22548
|
}
|
|
@@ -21415,12 +22578,12 @@ function isLoopLikeStatement(node) {
|
|
|
21415
22578
|
return LOOP_NODE_TYPES.has(node.type);
|
|
21416
22579
|
}
|
|
21417
22580
|
function isSwitchStatement(node) {
|
|
21418
|
-
return node?.type ===
|
|
22581
|
+
return node?.type === AST_NODE_TYPES14.SwitchStatement;
|
|
21419
22582
|
}
|
|
21420
22583
|
function findLabeledStatementBody(label, startingNode) {
|
|
21421
22584
|
let current = startingNode;
|
|
21422
22585
|
while (current) {
|
|
21423
|
-
if (current.type ===
|
|
22586
|
+
if (current.type === AST_NODE_TYPES14.LabeledStatement && current.label.name === label.name)
|
|
21424
22587
|
return current.body;
|
|
21425
22588
|
current = current.parent ?? undefined;
|
|
21426
22589
|
}
|
|
@@ -21682,7 +22845,7 @@ var rule = {
|
|
|
21682
22845
|
function onIfConsequentExit(node) {
|
|
21683
22846
|
const consequentNode = node;
|
|
21684
22847
|
const { parent } = consequentNode;
|
|
21685
|
-
if (parent?.type ===
|
|
22848
|
+
if (parent?.type === AST_NODE_TYPES14.IfStatement) {
|
|
21686
22849
|
const branches = branchStacks.get(parent) ?? [];
|
|
21687
22850
|
branches.push(cloneStack());
|
|
21688
22851
|
branchStacks.set(parent, branches);
|
|
@@ -21697,7 +22860,7 @@ var rule = {
|
|
|
21697
22860
|
function onIfAlternateExit(node) {
|
|
21698
22861
|
const alternateNode = node;
|
|
21699
22862
|
const { parent } = alternateNode;
|
|
21700
|
-
if (parent?.type ===
|
|
22863
|
+
if (parent?.type === AST_NODE_TYPES14.IfStatement) {
|
|
21701
22864
|
const branches = branchStacks.get(parent) ?? [];
|
|
21702
22865
|
branches.push(cloneStack());
|
|
21703
22866
|
branchStacks.set(parent, branches);
|
|
@@ -21746,7 +22909,7 @@ var rule = {
|
|
|
21746
22909
|
function onTryBlockExit(node) {
|
|
21747
22910
|
const blockNode = node;
|
|
21748
22911
|
const { parent } = blockNode;
|
|
21749
|
-
if (parent?.type ===
|
|
22912
|
+
if (parent?.type === AST_NODE_TYPES14.TryStatement) {
|
|
21750
22913
|
const branches = branchStacks.get(parent) ?? [];
|
|
21751
22914
|
branches.push(cloneStack());
|
|
21752
22915
|
branchStacks.set(parent, branches);
|
|
@@ -21765,7 +22928,7 @@ var rule = {
|
|
|
21765
22928
|
function onCatchClauseExit(node) {
|
|
21766
22929
|
const catchNode = node;
|
|
21767
22930
|
const { parent } = catchNode;
|
|
21768
|
-
if (parent?.type ===
|
|
22931
|
+
if (parent?.type === AST_NODE_TYPES14.TryStatement) {
|
|
21769
22932
|
const branches = branchStacks.get(parent) ?? [];
|
|
21770
22933
|
branches.push(cloneStack());
|
|
21771
22934
|
branchStacks.set(parent, branches);
|
|
@@ -21828,7 +22991,7 @@ var rule = {
|
|
|
21828
22991
|
function onSwitchCaseExit(node) {
|
|
21829
22992
|
const caseNode = node;
|
|
21830
22993
|
const { parent } = caseNode;
|
|
21831
|
-
if (parent?.type ===
|
|
22994
|
+
if (parent?.type === AST_NODE_TYPES14.SwitchStatement) {
|
|
21832
22995
|
const branches = branchStacks.get(parent) ?? [];
|
|
21833
22996
|
branches.push(cloneStack());
|
|
21834
22997
|
branchStacks.set(parent, branches);
|
|
@@ -21859,7 +23022,7 @@ var rule = {
|
|
|
21859
23022
|
for (const { opener, config, node: node2 } of openerStack) {
|
|
21860
23023
|
const validClosers = getValidClosers(config);
|
|
21861
23024
|
const closer = validClosers.length === 1 ? validClosers[0] ?? "closer" : validClosers.join("' or '");
|
|
21862
|
-
const statementType = statementNode.type ===
|
|
23025
|
+
const statementType = statementNode.type === AST_NODE_TYPES14.ReturnStatement ? "return" : "throw";
|
|
21863
23026
|
const lineNumber = statementNode.loc?.start.line ?? 0;
|
|
21864
23027
|
context.report({
|
|
21865
23028
|
data: {
|
|
@@ -21876,7 +23039,7 @@ var rule = {
|
|
|
21876
23039
|
const statementNode = node;
|
|
21877
23040
|
if (openerStack.length === 0)
|
|
21878
23041
|
return;
|
|
21879
|
-
const targetLoop = statementNode.type ===
|
|
23042
|
+
const targetLoop = statementNode.type === AST_NODE_TYPES14.ContinueStatement ? resolveContinueTargetLoop(statementNode) : resolveBreakTargetLoop(statementNode);
|
|
21880
23043
|
if (!targetLoop)
|
|
21881
23044
|
return;
|
|
21882
23045
|
for (const { node: openerNode, config, opener, loopAncestors } of openerStack) {
|
|
@@ -21884,7 +23047,7 @@ var rule = {
|
|
|
21884
23047
|
continue;
|
|
21885
23048
|
const validClosers = getValidClosers(config);
|
|
21886
23049
|
const closer = validClosers.length === 1 ? validClosers[0] ?? "closer" : validClosers.join("' or '");
|
|
21887
|
-
const statementType = statementNode.type ===
|
|
23050
|
+
const statementType = statementNode.type === AST_NODE_TYPES14.BreakStatement ? "break" : "continue";
|
|
21888
23051
|
const lineNumber = statementNode.loc?.start.line ?? 0;
|
|
21889
23052
|
context.report({
|
|
21890
23053
|
data: {
|
|
@@ -22022,7 +23185,7 @@ var rule = {
|
|
|
22022
23185
|
continue;
|
|
22023
23186
|
const validClosers = getValidClosers(config);
|
|
22024
23187
|
const closer = validClosers.length === 1 ? validClosers[0] ?? "closer" : validClosers.join("' or '");
|
|
22025
|
-
const asyncType = asyncNode.type ===
|
|
23188
|
+
const asyncType = asyncNode.type === AST_NODE_TYPES14.AwaitExpression ? "await" : "yield";
|
|
22026
23189
|
context.report({
|
|
22027
23190
|
data: { asyncType, closer, opener },
|
|
22028
23191
|
messageId: "asyncViolation",
|
|
@@ -22157,8 +23320,8 @@ var rule = {
|
|
|
22157
23320
|
var require_paired_calls_default = rule;
|
|
22158
23321
|
|
|
22159
23322
|
// src/rules/require-react-component-keys.ts
|
|
22160
|
-
import { TSESTree as
|
|
22161
|
-
var
|
|
23323
|
+
import { TSESTree as TSESTree10 } from "@typescript-eslint/types";
|
|
23324
|
+
var DEFAULT_OPTIONS4 = {
|
|
22162
23325
|
allowRootKeys: false,
|
|
22163
23326
|
ignoreCallExpressions: ["ReactTree.mount", "CreateReactStory"],
|
|
22164
23327
|
iterationMethods: [
|
|
@@ -22200,17 +23363,17 @@ function ascendPastWrappers(node) {
|
|
|
22200
23363
|
}
|
|
22201
23364
|
function hasKeyAttribute(node) {
|
|
22202
23365
|
for (const attribute of node.openingElement.attributes) {
|
|
22203
|
-
if (attribute.type ===
|
|
23366
|
+
if (attribute.type === TSESTree10.AST_NODE_TYPES.JSXAttribute && attribute.name.name === "key")
|
|
22204
23367
|
return true;
|
|
22205
23368
|
}
|
|
22206
23369
|
return false;
|
|
22207
23370
|
}
|
|
22208
23371
|
function isHigherOrderComponent(callExpr) {
|
|
22209
23372
|
const { callee } = callExpr;
|
|
22210
|
-
if (callee.type ===
|
|
23373
|
+
if (callee.type === TSESTree10.AST_NODE_TYPES.Identifier) {
|
|
22211
23374
|
return callee.name === "forwardRef" || callee.name === "memo";
|
|
22212
23375
|
}
|
|
22213
|
-
if (callee.type ===
|
|
23376
|
+
if (callee.type === TSESTree10.AST_NODE_TYPES.MemberExpression && callee.object.type === TSESTree10.AST_NODE_TYPES.Identifier && callee.object.name === "React" && callee.property.type === TSESTree10.AST_NODE_TYPES.Identifier) {
|
|
22214
23377
|
return callee.property.name === "forwardRef" || callee.property.name === "memo";
|
|
22215
23378
|
}
|
|
22216
23379
|
return false;
|
|
@@ -22218,7 +23381,7 @@ function isHigherOrderComponent(callExpr) {
|
|
|
22218
23381
|
function getEnclosingFunctionLike(node) {
|
|
22219
23382
|
let current = node.parent;
|
|
22220
23383
|
while (current) {
|
|
22221
|
-
if (current.type ===
|
|
23384
|
+
if (current.type === TSESTree10.AST_NODE_TYPES.ArrowFunctionExpression || current.type === TSESTree10.AST_NODE_TYPES.FunctionExpression || current.type === TSESTree10.AST_NODE_TYPES.FunctionDeclaration) {
|
|
22222
23385
|
return current;
|
|
22223
23386
|
}
|
|
22224
23387
|
current = current.parent;
|
|
@@ -22227,16 +23390,16 @@ function getEnclosingFunctionLike(node) {
|
|
|
22227
23390
|
}
|
|
22228
23391
|
function isIterationOrMemoCallback(callExpression, iterationMethods, memoizationHooks) {
|
|
22229
23392
|
const { callee } = callExpression;
|
|
22230
|
-
if (callee.type ===
|
|
23393
|
+
if (callee.type === TSESTree10.AST_NODE_TYPES.Identifier && memoizationHooks.has(callee.name))
|
|
22231
23394
|
return true;
|
|
22232
|
-
if (callee.type ===
|
|
23395
|
+
if (callee.type === TSESTree10.AST_NODE_TYPES.MemberExpression && callee.property.type === TSESTree10.AST_NODE_TYPES.Identifier) {
|
|
22233
23396
|
const { name } = callee.property;
|
|
22234
23397
|
if (iterationMethods.has(name))
|
|
22235
23398
|
return true;
|
|
22236
|
-
if (name === "from" && callee.object.type ===
|
|
23399
|
+
if (name === "from" && callee.object.type === TSESTree10.AST_NODE_TYPES.MemberExpression && callee.object.object.type === TSESTree10.AST_NODE_TYPES.Identifier && callee.object.object.name === "Array" && callExpression.arguments.length >= 2) {
|
|
22237
23400
|
return true;
|
|
22238
23401
|
}
|
|
22239
|
-
if (name === "call" && callee.object.type ===
|
|
23402
|
+
if (name === "call" && callee.object.type === TSESTree10.AST_NODE_TYPES.MemberExpression && callee.object.object.type === TSESTree10.AST_NODE_TYPES.MemberExpression && callee.object.object.property.type === TSESTree10.AST_NODE_TYPES.Identifier && iterationMethods.has(callee.object.object.property.name)) {
|
|
22240
23403
|
return true;
|
|
22241
23404
|
}
|
|
22242
23405
|
}
|
|
@@ -22246,11 +23409,11 @@ function findEnclosingCallExpression(node) {
|
|
|
22246
23409
|
let current = node;
|
|
22247
23410
|
let { parent } = node;
|
|
22248
23411
|
while (parent) {
|
|
22249
|
-
if (parent.type ===
|
|
23412
|
+
if (parent.type === TSESTree10.AST_NODE_TYPES.CallExpression) {
|
|
22250
23413
|
for (const argument of parent.arguments) {
|
|
22251
23414
|
if (argument === current)
|
|
22252
23415
|
return parent;
|
|
22253
|
-
if (argument.type ===
|
|
23416
|
+
if (argument.type === TSESTree10.AST_NODE_TYPES.SpreadElement && argument.argument === current) {
|
|
22254
23417
|
return parent;
|
|
22255
23418
|
}
|
|
22256
23419
|
}
|
|
@@ -22266,7 +23429,7 @@ function findEnclosingCallExpression(node) {
|
|
|
22266
23429
|
return;
|
|
22267
23430
|
}
|
|
22268
23431
|
function getVariableForFunction(context, functionLike) {
|
|
22269
|
-
if (functionLike.type ===
|
|
23432
|
+
if (functionLike.type === TSESTree10.AST_NODE_TYPES.FunctionDeclaration) {
|
|
22270
23433
|
const declared = context.sourceCode.getDeclaredVariables(functionLike);
|
|
22271
23434
|
if (declared.length > 0)
|
|
22272
23435
|
return declared[0];
|
|
@@ -22275,7 +23438,7 @@ function getVariableForFunction(context, functionLike) {
|
|
|
22275
23438
|
const { parent } = functionLike;
|
|
22276
23439
|
if (!parent)
|
|
22277
23440
|
return;
|
|
22278
|
-
if (parent.type ===
|
|
23441
|
+
if (parent.type === TSESTree10.AST_NODE_TYPES.VariableDeclarator || parent.type === TSESTree10.AST_NODE_TYPES.AssignmentExpression) {
|
|
22279
23442
|
const declared = context.sourceCode.getDeclaredVariables(parent);
|
|
22280
23443
|
if (declared.length > 0)
|
|
22281
23444
|
return declared[0];
|
|
@@ -22309,33 +23472,33 @@ function isFunctionUsedAsCallback(context, functionLike, iterationMethods, memoi
|
|
|
22309
23472
|
return false;
|
|
22310
23473
|
}
|
|
22311
23474
|
var SHOULD_ASCEND_TYPES = new Set([
|
|
22312
|
-
|
|
22313
|
-
|
|
23475
|
+
TSESTree10.AST_NODE_TYPES.ConditionalExpression,
|
|
23476
|
+
TSESTree10.AST_NODE_TYPES.LogicalExpression
|
|
22314
23477
|
]);
|
|
22315
23478
|
var IS_FUNCTION_EXPRESSION = new Set([
|
|
22316
|
-
|
|
22317
|
-
|
|
23479
|
+
TSESTree10.AST_NODE_TYPES.FunctionExpression,
|
|
23480
|
+
TSESTree10.AST_NODE_TYPES.ArrowFunctionExpression
|
|
22318
23481
|
]);
|
|
22319
23482
|
var CONTROL_FLOW_TYPES = new Set([
|
|
22320
|
-
|
|
22321
|
-
|
|
22322
|
-
|
|
22323
|
-
|
|
22324
|
-
|
|
22325
|
-
|
|
22326
|
-
|
|
22327
|
-
|
|
22328
|
-
|
|
22329
|
-
|
|
22330
|
-
|
|
22331
|
-
|
|
22332
|
-
|
|
23483
|
+
TSESTree10.AST_NODE_TYPES.BlockStatement,
|
|
23484
|
+
TSESTree10.AST_NODE_TYPES.IfStatement,
|
|
23485
|
+
TSESTree10.AST_NODE_TYPES.SwitchStatement,
|
|
23486
|
+
TSESTree10.AST_NODE_TYPES.SwitchCase,
|
|
23487
|
+
TSESTree10.AST_NODE_TYPES.TryStatement,
|
|
23488
|
+
TSESTree10.AST_NODE_TYPES.CatchClause,
|
|
23489
|
+
TSESTree10.AST_NODE_TYPES.WhileStatement,
|
|
23490
|
+
TSESTree10.AST_NODE_TYPES.DoWhileStatement,
|
|
23491
|
+
TSESTree10.AST_NODE_TYPES.ForStatement,
|
|
23492
|
+
TSESTree10.AST_NODE_TYPES.ForInStatement,
|
|
23493
|
+
TSESTree10.AST_NODE_TYPES.ForOfStatement,
|
|
23494
|
+
TSESTree10.AST_NODE_TYPES.LabeledStatement,
|
|
23495
|
+
TSESTree10.AST_NODE_TYPES.WithStatement
|
|
22333
23496
|
]);
|
|
22334
23497
|
function isTopLevelReturn(node) {
|
|
22335
23498
|
let parent = ascendPastWrappers(node.parent);
|
|
22336
23499
|
if (!parent)
|
|
22337
23500
|
return false;
|
|
22338
|
-
if (parent.type ===
|
|
23501
|
+
if (parent.type === TSESTree10.AST_NODE_TYPES.JSXExpressionContainer)
|
|
22339
23502
|
parent = ascendPastWrappers(parent.parent);
|
|
22340
23503
|
if (!parent)
|
|
22341
23504
|
return false;
|
|
@@ -22343,11 +23506,11 @@ function isTopLevelReturn(node) {
|
|
|
22343
23506
|
parent = ascendPastWrappers(parent.parent);
|
|
22344
23507
|
if (!parent)
|
|
22345
23508
|
return false;
|
|
22346
|
-
if (parent.type ===
|
|
23509
|
+
if (parent.type === TSESTree10.AST_NODE_TYPES.JSXExpressionContainer)
|
|
22347
23510
|
parent = ascendPastWrappers(parent.parent);
|
|
22348
23511
|
if (!parent)
|
|
22349
23512
|
return false;
|
|
22350
|
-
if (parent.type ===
|
|
23513
|
+
if (parent.type === TSESTree10.AST_NODE_TYPES.ReturnStatement) {
|
|
22351
23514
|
let currentNode = ascendPastWrappers(parent.parent);
|
|
22352
23515
|
while (currentNode && CONTROL_FLOW_TYPES.has(currentNode.type)) {
|
|
22353
23516
|
currentNode = ascendPastWrappers(currentNode.parent);
|
|
@@ -22356,16 +23519,16 @@ function isTopLevelReturn(node) {
|
|
|
22356
23519
|
return false;
|
|
22357
23520
|
if (IS_FUNCTION_EXPRESSION.has(currentNode.type)) {
|
|
22358
23521
|
const functionParent = ascendPastWrappers(currentNode.parent);
|
|
22359
|
-
if (functionParent?.type ===
|
|
23522
|
+
if (functionParent?.type === TSESTree10.AST_NODE_TYPES.CallExpression) {
|
|
22360
23523
|
return isHigherOrderComponent(functionParent);
|
|
22361
23524
|
}
|
|
22362
23525
|
return true;
|
|
22363
23526
|
}
|
|
22364
|
-
return currentNode.type ===
|
|
23527
|
+
return currentNode.type === TSESTree10.AST_NODE_TYPES.FunctionDeclaration;
|
|
22365
23528
|
}
|
|
22366
|
-
if (parent.type ===
|
|
23529
|
+
if (parent.type === TSESTree10.AST_NODE_TYPES.ArrowFunctionExpression) {
|
|
22367
23530
|
const functionParent = ascendPastWrappers(parent.parent);
|
|
22368
|
-
if (functionParent?.type ===
|
|
23531
|
+
if (functionParent?.type === TSESTree10.AST_NODE_TYPES.CallExpression) {
|
|
22369
23532
|
return isHigherOrderComponent(functionParent);
|
|
22370
23533
|
}
|
|
22371
23534
|
return true;
|
|
@@ -22376,7 +23539,7 @@ function isIgnoredCallExpression(node, ignoreList) {
|
|
|
22376
23539
|
let parent = node.parent;
|
|
22377
23540
|
if (!parent)
|
|
22378
23541
|
return false;
|
|
22379
|
-
if (parent.type ===
|
|
23542
|
+
if (parent.type === TSESTree10.AST_NODE_TYPES.JSXExpressionContainer) {
|
|
22380
23543
|
({ parent } = parent);
|
|
22381
23544
|
if (!parent)
|
|
22382
23545
|
return false;
|
|
@@ -22384,11 +23547,11 @@ function isIgnoredCallExpression(node, ignoreList) {
|
|
|
22384
23547
|
const maxDepth = 20;
|
|
22385
23548
|
for (let depth = 0;depth < maxDepth && parent; depth += 1) {
|
|
22386
23549
|
const { type: type3 } = parent;
|
|
22387
|
-
if (type3 ===
|
|
23550
|
+
if (type3 === TSESTree10.AST_NODE_TYPES.CallExpression) {
|
|
22388
23551
|
const { callee } = parent;
|
|
22389
|
-
if (callee.type ===
|
|
23552
|
+
if (callee.type === TSESTree10.AST_NODE_TYPES.Identifier)
|
|
22390
23553
|
return ignoreList.includes(callee.name);
|
|
22391
|
-
if (callee.type ===
|
|
23554
|
+
if (callee.type === TSESTree10.AST_NODE_TYPES.MemberExpression && callee.object.type === TSESTree10.AST_NODE_TYPES.Identifier && callee.property.type === TSESTree10.AST_NODE_TYPES.Identifier) {
|
|
22392
23555
|
return ignoreList.includes(`${callee.object.name}.${callee.property.name}`);
|
|
22393
23556
|
}
|
|
22394
23557
|
return false;
|
|
@@ -22401,41 +23564,41 @@ function isJSXPropValue(node) {
|
|
|
22401
23564
|
let { parent } = node;
|
|
22402
23565
|
if (!parent)
|
|
22403
23566
|
return false;
|
|
22404
|
-
while (parent && (parent.type ===
|
|
23567
|
+
while (parent && (parent.type === TSESTree10.AST_NODE_TYPES.ConditionalExpression || parent.type === TSESTree10.AST_NODE_TYPES.LogicalExpression)) {
|
|
22405
23568
|
({ parent } = parent);
|
|
22406
23569
|
}
|
|
22407
23570
|
if (!parent)
|
|
22408
23571
|
return false;
|
|
22409
|
-
if (parent.type ===
|
|
23572
|
+
if (parent.type === TSESTree10.AST_NODE_TYPES.JSXExpressionContainer) {
|
|
22410
23573
|
({ parent } = parent);
|
|
22411
23574
|
if (!parent)
|
|
22412
23575
|
return false;
|
|
22413
23576
|
}
|
|
22414
|
-
return parent.type ===
|
|
23577
|
+
return parent.type === TSESTree10.AST_NODE_TYPES.JSXAttribute;
|
|
22415
23578
|
}
|
|
22416
23579
|
function isTernaryJSXChild(node) {
|
|
22417
23580
|
let current = node.parent;
|
|
22418
23581
|
if (!current)
|
|
22419
23582
|
return false;
|
|
22420
23583
|
let foundTernary = false;
|
|
22421
|
-
while (current && (current.type ===
|
|
22422
|
-
if (current.type ===
|
|
23584
|
+
while (current && (current.type === TSESTree10.AST_NODE_TYPES.ConditionalExpression || WRAPPER_PARENT_TYPES.has(current.type))) {
|
|
23585
|
+
if (current.type === TSESTree10.AST_NODE_TYPES.ConditionalExpression)
|
|
22423
23586
|
foundTernary = true;
|
|
22424
23587
|
current = current.parent;
|
|
22425
23588
|
}
|
|
22426
23589
|
if (!(foundTernary && current))
|
|
22427
23590
|
return false;
|
|
22428
|
-
if (current.type !==
|
|
23591
|
+
if (current.type !== TSESTree10.AST_NODE_TYPES.JSXExpressionContainer)
|
|
22429
23592
|
return false;
|
|
22430
23593
|
const containerParent = current.parent;
|
|
22431
23594
|
if (!containerParent)
|
|
22432
23595
|
return false;
|
|
22433
|
-
return containerParent.type ===
|
|
23596
|
+
return containerParent.type === TSESTree10.AST_NODE_TYPES.JSXElement || containerParent.type === TSESTree10.AST_NODE_TYPES.JSXFragment;
|
|
22434
23597
|
}
|
|
22435
23598
|
var require_react_component_keys_default = createRule({
|
|
22436
23599
|
create(context) {
|
|
22437
23600
|
const options3 = {
|
|
22438
|
-
...
|
|
23601
|
+
...DEFAULT_OPTIONS4,
|
|
22439
23602
|
...context.options[0]
|
|
22440
23603
|
};
|
|
22441
23604
|
const iterationMethods = new Set(options3.iterationMethods);
|
|
@@ -22445,7 +23608,7 @@ var require_react_component_keys_default = createRule({
|
|
|
22445
23608
|
const isCallback = functionLike ? isFunctionUsedAsCallback(context, functionLike, iterationMethods, memoizationHooks) : false;
|
|
22446
23609
|
const isRoot = isTopLevelReturn(node);
|
|
22447
23610
|
if (isRoot && !isCallback) {
|
|
22448
|
-
if (!options3.allowRootKeys && node.type ===
|
|
23611
|
+
if (!options3.allowRootKeys && node.type === TSESTree10.AST_NODE_TYPES.JSXElement && hasKeyAttribute(node)) {
|
|
22449
23612
|
context.report({
|
|
22450
23613
|
messageId: "rootComponentWithKey",
|
|
22451
23614
|
node
|
|
@@ -22459,7 +23622,7 @@ var require_react_component_keys_default = createRule({
|
|
|
22459
23622
|
return;
|
|
22460
23623
|
if (isTernaryJSXChild(node))
|
|
22461
23624
|
return;
|
|
22462
|
-
if (node.type ===
|
|
23625
|
+
if (node.type === TSESTree10.AST_NODE_TYPES.JSXFragment) {
|
|
22463
23626
|
context.report({
|
|
22464
23627
|
messageId: "missingKey",
|
|
22465
23628
|
node
|
|
@@ -22482,7 +23645,7 @@ var require_react_component_keys_default = createRule({
|
|
|
22482
23645
|
}
|
|
22483
23646
|
};
|
|
22484
23647
|
},
|
|
22485
|
-
defaultOptions: [
|
|
23648
|
+
defaultOptions: [DEFAULT_OPTIONS4],
|
|
22486
23649
|
meta: {
|
|
22487
23650
|
docs: {
|
|
22488
23651
|
description: "Require keys on React components when used in lists or iteration."
|
|
@@ -22539,38 +23702,30 @@ var require_react_component_keys_default = createRule({
|
|
|
22539
23702
|
});
|
|
22540
23703
|
|
|
22541
23704
|
// src/rules/require-react-display-names.ts
|
|
22542
|
-
import { TSESTree as
|
|
22543
|
-
var
|
|
23705
|
+
import { TSESTree as TSESTree11 } from "@typescript-eslint/types";
|
|
23706
|
+
var DEFAULT_OPTIONS5 = {
|
|
22544
23707
|
environment: "roblox-ts"
|
|
22545
23708
|
};
|
|
22546
|
-
|
|
22547
|
-
var REACT_SOURCES_STANDARD = new Set(["react", "react-dom"]);
|
|
22548
|
-
function getReactSources(environment2) {
|
|
22549
|
-
return environment2 === "roblox-ts" ? REACT_SOURCES_ROBLOX : REACT_SOURCES_STANDARD;
|
|
22550
|
-
}
|
|
22551
|
-
function isReactImport(node, reactSources) {
|
|
22552
|
-
return reactSources.has(node.source.value);
|
|
22553
|
-
}
|
|
22554
|
-
function isMemoCall(node, memoIdentifiers, reactNamespaces) {
|
|
23709
|
+
function isMemoCall2(node, memoIdentifiers, reactNamespaces) {
|
|
22555
23710
|
const { callee } = node;
|
|
22556
|
-
if (callee.type ===
|
|
23711
|
+
if (callee.type === TSESTree11.AST_NODE_TYPES.Identifier)
|
|
22557
23712
|
return memoIdentifiers.has(callee.name);
|
|
22558
|
-
if (callee.type ===
|
|
23713
|
+
if (callee.type === TSESTree11.AST_NODE_TYPES.MemberExpression && callee.object.type === TSESTree11.AST_NODE_TYPES.Identifier && callee.property.type === TSESTree11.AST_NODE_TYPES.Identifier) {
|
|
22559
23714
|
return reactNamespaces.has(callee.object.name) && callee.property.name === "memo";
|
|
22560
23715
|
}
|
|
22561
23716
|
return false;
|
|
22562
23717
|
}
|
|
22563
23718
|
function isCreateContextCall(node, createContextIdentifiers, reactNamespaces) {
|
|
22564
23719
|
const { callee } = node;
|
|
22565
|
-
if (callee.type ===
|
|
23720
|
+
if (callee.type === TSESTree11.AST_NODE_TYPES.Identifier)
|
|
22566
23721
|
return createContextIdentifiers.has(callee.name);
|
|
22567
|
-
if (callee.type ===
|
|
23722
|
+
if (callee.type === TSESTree11.AST_NODE_TYPES.MemberExpression && callee.object.type === TSESTree11.AST_NODE_TYPES.Identifier && callee.property.type === TSESTree11.AST_NODE_TYPES.Identifier) {
|
|
22568
23723
|
return reactNamespaces.has(callee.object.name) && callee.property.name === "createContext";
|
|
22569
23724
|
}
|
|
22570
23725
|
return false;
|
|
22571
23726
|
}
|
|
22572
23727
|
function getVariableName(node) {
|
|
22573
|
-
if (node.id.type ===
|
|
23728
|
+
if (node.id.type === TSESTree11.AST_NODE_TYPES.Identifier)
|
|
22574
23729
|
return node.id.name;
|
|
22575
23730
|
return;
|
|
22576
23731
|
}
|
|
@@ -22578,9 +23733,9 @@ function isNodeInExport(node) {
|
|
|
22578
23733
|
let current = node;
|
|
22579
23734
|
while (current) {
|
|
22580
23735
|
const { type: type3 } = current;
|
|
22581
|
-
if (type3 ===
|
|
23736
|
+
if (type3 === TSESTree11.AST_NODE_TYPES.ExportNamedDeclaration)
|
|
22582
23737
|
return true;
|
|
22583
|
-
if (type3 ===
|
|
23738
|
+
if (type3 === TSESTree11.AST_NODE_TYPES.ExportDefaultDeclaration)
|
|
22584
23739
|
return true;
|
|
22585
23740
|
current = current.parent;
|
|
22586
23741
|
}
|
|
@@ -22592,7 +23747,7 @@ function isReferenceExported(reference) {
|
|
|
22592
23747
|
var require_react_display_names_default = createRule({
|
|
22593
23748
|
create(context) {
|
|
22594
23749
|
const options3 = {
|
|
22595
|
-
...
|
|
23750
|
+
...DEFAULT_OPTIONS5,
|
|
22596
23751
|
...context.options[0]
|
|
22597
23752
|
};
|
|
22598
23753
|
const reactSources = getReactSources(options3.environment);
|
|
@@ -22604,14 +23759,14 @@ var require_react_display_names_default = createRule({
|
|
|
22604
23759
|
return {
|
|
22605
23760
|
"AssignmentExpression[left.type='MemberExpression'][left.property.name='displayName']"(node) {
|
|
22606
23761
|
const left = node.left;
|
|
22607
|
-
if (left.object.type ===
|
|
23762
|
+
if (left.object.type === TSESTree11.AST_NODE_TYPES.Identifier) {
|
|
22608
23763
|
displayNameAssignments.add(left.object.name);
|
|
22609
23764
|
}
|
|
22610
23765
|
},
|
|
22611
23766
|
ExportDefaultDeclaration(node) {
|
|
22612
23767
|
const { declaration } = node;
|
|
22613
|
-
if (declaration.type ===
|
|
22614
|
-
if (
|
|
23768
|
+
if (declaration.type === TSESTree11.AST_NODE_TYPES.CallExpression) {
|
|
23769
|
+
if (isMemoCall2(declaration, memoIdentifiers, reactNamespaces)) {
|
|
22615
23770
|
context.report({
|
|
22616
23771
|
messageId: "directMemoExport",
|
|
22617
23772
|
node
|
|
@@ -22626,7 +23781,7 @@ var require_react_display_names_default = createRule({
|
|
|
22626
23781
|
return;
|
|
22627
23782
|
}
|
|
22628
23783
|
}
|
|
22629
|
-
if (declaration.type ===
|
|
23784
|
+
if (declaration.type === TSESTree11.AST_NODE_TYPES.Identifier) {
|
|
22630
23785
|
const tracked = trackedVariables.get(declaration.name);
|
|
22631
23786
|
if (tracked) {
|
|
22632
23787
|
trackedVariables.set(declaration.name, {
|
|
@@ -22640,10 +23795,10 @@ var require_react_display_names_default = createRule({
|
|
|
22640
23795
|
if (!node.specifiers)
|
|
22641
23796
|
return;
|
|
22642
23797
|
for (const specifier of node.specifiers) {
|
|
22643
|
-
if (specifier.type !==
|
|
23798
|
+
if (specifier.type !== TSESTree11.AST_NODE_TYPES.ExportSpecifier)
|
|
22644
23799
|
continue;
|
|
22645
|
-
const localName = specifier.local.type ===
|
|
22646
|
-
const exportedName = specifier.exported.type ===
|
|
23800
|
+
const localName = specifier.local.type === TSESTree11.AST_NODE_TYPES.Identifier ? specifier.local.name : specifier.local.value;
|
|
23801
|
+
const exportedName = specifier.exported.type === TSESTree11.AST_NODE_TYPES.Identifier ? specifier.exported.name : specifier.exported.value;
|
|
22647
23802
|
if (exportedName === "default") {
|
|
22648
23803
|
const tracked = trackedVariables.get(localName);
|
|
22649
23804
|
if (tracked) {
|
|
@@ -22659,10 +23814,10 @@ var require_react_display_names_default = createRule({
|
|
|
22659
23814
|
if (!isReactImport(node, reactSources))
|
|
22660
23815
|
return;
|
|
22661
23816
|
for (const specifier of node.specifiers) {
|
|
22662
|
-
if (specifier.type ===
|
|
23817
|
+
if (specifier.type === TSESTree11.AST_NODE_TYPES.ImportDefaultSpecifier || specifier.type === TSESTree11.AST_NODE_TYPES.ImportNamespaceSpecifier) {
|
|
22663
23818
|
reactNamespaces.add(specifier.local.name);
|
|
22664
|
-
} else if (specifier.type ===
|
|
22665
|
-
const importedName = specifier.imported.type ===
|
|
23819
|
+
} else if (specifier.type === TSESTree11.AST_NODE_TYPES.ImportSpecifier) {
|
|
23820
|
+
const importedName = specifier.imported.type === TSESTree11.AST_NODE_TYPES.Identifier ? specifier.imported.name : specifier.imported.value;
|
|
22666
23821
|
if (importedName === "memo")
|
|
22667
23822
|
memoIdentifiers.add(specifier.local.name);
|
|
22668
23823
|
else if (importedName === "createContext")
|
|
@@ -22681,7 +23836,7 @@ var require_react_display_names_default = createRule({
|
|
|
22681
23836
|
if (variable)
|
|
22682
23837
|
isExported ||= variable.references.some(isReferenceExported);
|
|
22683
23838
|
const declarationParent = tracked.node.parent;
|
|
22684
|
-
if (declarationParent?.parent?.type ===
|
|
23839
|
+
if (declarationParent?.parent?.type === TSESTree11.AST_NODE_TYPES.ExportNamedDeclaration) {
|
|
22685
23840
|
isExported = true;
|
|
22686
23841
|
}
|
|
22687
23842
|
if (isExported) {
|
|
@@ -22694,12 +23849,12 @@ var require_react_display_names_default = createRule({
|
|
|
22694
23849
|
}
|
|
22695
23850
|
},
|
|
22696
23851
|
VariableDeclarator(node) {
|
|
22697
|
-
if (!node.init || node.init.type !==
|
|
23852
|
+
if (!node.init || node.init.type !== TSESTree11.AST_NODE_TYPES.CallExpression)
|
|
22698
23853
|
return;
|
|
22699
23854
|
const name = getVariableName(node);
|
|
22700
23855
|
if (!name)
|
|
22701
23856
|
return;
|
|
22702
|
-
if (
|
|
23857
|
+
if (isMemoCall2(node.init, memoIdentifiers, reactNamespaces)) {
|
|
22703
23858
|
trackedVariables.set(name, {
|
|
22704
23859
|
hasDisplayName: false,
|
|
22705
23860
|
isDefaultExported: false,
|
|
@@ -22719,7 +23874,7 @@ var require_react_display_names_default = createRule({
|
|
|
22719
23874
|
}
|
|
22720
23875
|
};
|
|
22721
23876
|
},
|
|
22722
|
-
defaultOptions: [
|
|
23877
|
+
defaultOptions: [DEFAULT_OPTIONS5],
|
|
22723
23878
|
meta: {
|
|
22724
23879
|
docs: {
|
|
22725
23880
|
description: "Require displayName property on exported React.memo components and React.createContext contexts for better debugging."
|
|
@@ -22860,16 +24015,16 @@ var strict_component_boundaries_default = createRule({
|
|
|
22860
24015
|
});
|
|
22861
24016
|
|
|
22862
24017
|
// src/rules/use-exhaustive-dependencies.ts
|
|
22863
|
-
import { TSESTree as
|
|
24018
|
+
import { TSESTree as TSESTree12 } from "@typescript-eslint/types";
|
|
22864
24019
|
var FUNCTION_DECLARATIONS = new Set([
|
|
22865
|
-
|
|
22866
|
-
|
|
22867
|
-
|
|
24020
|
+
TSESTree12.AST_NODE_TYPES.FunctionExpression,
|
|
24021
|
+
TSESTree12.AST_NODE_TYPES.ArrowFunctionExpression,
|
|
24022
|
+
TSESTree12.AST_NODE_TYPES.FunctionDeclaration
|
|
22868
24023
|
]);
|
|
22869
24024
|
var UNSTABLE_VALUES = new Set([
|
|
22870
24025
|
...FUNCTION_DECLARATIONS,
|
|
22871
|
-
|
|
22872
|
-
|
|
24026
|
+
TSESTree12.AST_NODE_TYPES.ObjectExpression,
|
|
24027
|
+
TSESTree12.AST_NODE_TYPES.ArrayExpression
|
|
22873
24028
|
]);
|
|
22874
24029
|
var testingMetrics = {
|
|
22875
24030
|
moduleLevelStableConst: 0,
|
|
@@ -22953,9 +24108,9 @@ var GLOBAL_BUILTINS = new Set([
|
|
|
22953
24108
|
]);
|
|
22954
24109
|
function getHookName4(node) {
|
|
22955
24110
|
const { callee } = node;
|
|
22956
|
-
if (callee.type ===
|
|
24111
|
+
if (callee.type === TSESTree12.AST_NODE_TYPES.Identifier)
|
|
22957
24112
|
return callee.name;
|
|
22958
|
-
if (callee.type ===
|
|
24113
|
+
if (callee.type === TSESTree12.AST_NODE_TYPES.MemberExpression && callee.property.type === TSESTree12.AST_NODE_TYPES.Identifier) {
|
|
22959
24114
|
return callee.property.name;
|
|
22960
24115
|
}
|
|
22961
24116
|
return;
|
|
@@ -22963,9 +24118,9 @@ function getHookName4(node) {
|
|
|
22963
24118
|
function getMemberExpressionDepth(node) {
|
|
22964
24119
|
let depth = 0;
|
|
22965
24120
|
let current = node;
|
|
22966
|
-
if (current.type ===
|
|
24121
|
+
if (current.type === TSESTree12.AST_NODE_TYPES.ChainExpression)
|
|
22967
24122
|
current = current.expression;
|
|
22968
|
-
while (current.type ===
|
|
24123
|
+
while (current.type === TSESTree12.AST_NODE_TYPES.MemberExpression) {
|
|
22969
24124
|
depth += 1;
|
|
22970
24125
|
current = current.object;
|
|
22971
24126
|
}
|
|
@@ -22973,36 +24128,36 @@ function getMemberExpressionDepth(node) {
|
|
|
22973
24128
|
}
|
|
22974
24129
|
function getRootIdentifier(node) {
|
|
22975
24130
|
let current = node;
|
|
22976
|
-
if (current.type ===
|
|
24131
|
+
if (current.type === TSESTree12.AST_NODE_TYPES.ChainExpression)
|
|
22977
24132
|
current = current.expression;
|
|
22978
|
-
while (current.type ===
|
|
22979
|
-
if (current.type ===
|
|
24133
|
+
while (current.type === TSESTree12.AST_NODE_TYPES.MemberExpression || current.type === TSESTree12.AST_NODE_TYPES.TSNonNullExpression) {
|
|
24134
|
+
if (current.type === TSESTree12.AST_NODE_TYPES.MemberExpression)
|
|
22980
24135
|
current = current.object;
|
|
22981
24136
|
else
|
|
22982
24137
|
current = current.expression;
|
|
22983
24138
|
}
|
|
22984
|
-
return current.type ===
|
|
24139
|
+
return current.type === TSESTree12.AST_NODE_TYPES.Identifier ? current : undefined;
|
|
22985
24140
|
}
|
|
22986
24141
|
function nodeToDependencyString(node, sourceCode) {
|
|
22987
24142
|
return sourceCode.getText(node);
|
|
22988
24143
|
}
|
|
22989
24144
|
function nodeToSafeDependencyPath(node, sourceCode) {
|
|
22990
|
-
if (node.type ===
|
|
24145
|
+
if (node.type === TSESTree12.AST_NODE_TYPES.Identifier)
|
|
22991
24146
|
return node.name;
|
|
22992
|
-
if (node.type ===
|
|
24147
|
+
if (node.type === TSESTree12.AST_NODE_TYPES.ChainExpression) {
|
|
22993
24148
|
return nodeToSafeDependencyPath(node.expression, sourceCode);
|
|
22994
24149
|
}
|
|
22995
24150
|
if (TS_RUNTIME_EXPRESSIONS.has(node.type)) {
|
|
22996
24151
|
const expr = node;
|
|
22997
24152
|
return nodeToSafeDependencyPath(expr.expression, sourceCode);
|
|
22998
24153
|
}
|
|
22999
|
-
if (node.type ===
|
|
24154
|
+
if (node.type === TSESTree12.AST_NODE_TYPES.MemberExpression) {
|
|
23000
24155
|
const objectPath = nodeToSafeDependencyPath(node.object, sourceCode);
|
|
23001
24156
|
if (node.computed) {
|
|
23002
24157
|
const propertyText = sourceCode.getText(node.property);
|
|
23003
24158
|
return `${objectPath}[${propertyText}]`;
|
|
23004
24159
|
}
|
|
23005
|
-
const propertyName = node.property.type ===
|
|
24160
|
+
const propertyName = node.property.type === TSESTree12.AST_NODE_TYPES.Identifier ? node.property.name : "";
|
|
23006
24161
|
const separator = node.optional ? "?." : ".";
|
|
23007
24162
|
return `${objectPath}${separator}${propertyName}`;
|
|
23008
24163
|
}
|
|
@@ -23011,13 +24166,13 @@ function nodeToSafeDependencyPath(node, sourceCode) {
|
|
|
23011
24166
|
function isStableArrayIndex(stableResult, node, identifierName) {
|
|
23012
24167
|
if (!stableResult)
|
|
23013
24168
|
return false;
|
|
23014
|
-
if (!(stableResult instanceof Set) || node.type !==
|
|
24169
|
+
if (!(stableResult instanceof Set) || node.type !== TSESTree12.AST_NODE_TYPES.VariableDeclarator || node.id.type !== TSESTree12.AST_NODE_TYPES.ArrayPattern) {
|
|
23015
24170
|
return false;
|
|
23016
24171
|
}
|
|
23017
24172
|
const { elements } = node.id;
|
|
23018
24173
|
let index2 = 0;
|
|
23019
24174
|
for (const element of elements) {
|
|
23020
|
-
if (element.type ===
|
|
24175
|
+
if (element.type === TSESTree12.AST_NODE_TYPES.Identifier && element.name === identifierName) {
|
|
23021
24176
|
return stableResult.has(index2);
|
|
23022
24177
|
}
|
|
23023
24178
|
index2 += 1;
|
|
@@ -23026,7 +24181,7 @@ function isStableArrayIndex(stableResult, node, identifierName) {
|
|
|
23026
24181
|
}
|
|
23027
24182
|
function isStableHookValue(init, node, identifierName, stableHooks) {
|
|
23028
24183
|
const castInit = init;
|
|
23029
|
-
if (castInit.type !==
|
|
24184
|
+
if (castInit.type !== TSESTree12.AST_NODE_TYPES.CallExpression)
|
|
23030
24185
|
return false;
|
|
23031
24186
|
const hookName = getHookName4(castInit);
|
|
23032
24187
|
if (!hookName)
|
|
@@ -23046,35 +24201,35 @@ function isStableValue(variable, identifierName, stableHooks) {
|
|
|
23046
24201
|
const { node, type: type3 } = definition;
|
|
23047
24202
|
if (STABLE_VALUE_TYPES.has(type3))
|
|
23048
24203
|
return true;
|
|
23049
|
-
if (type3 === "Variable" && node.type ===
|
|
24204
|
+
if (type3 === "Variable" && node.type === TSESTree12.AST_NODE_TYPES.VariableDeclarator) {
|
|
23050
24205
|
const { parent } = node;
|
|
23051
|
-
if (!parent || parent.type !==
|
|
24206
|
+
if (!parent || parent.type !== TSESTree12.AST_NODE_TYPES.VariableDeclaration || parent.kind !== "const") {
|
|
23052
24207
|
continue;
|
|
23053
24208
|
}
|
|
23054
24209
|
const init = node.init;
|
|
23055
24210
|
if (init && isStableHookValue(init, node, identifierName, stableHooks))
|
|
23056
24211
|
return true;
|
|
23057
|
-
if (init?.type ===
|
|
24212
|
+
if (init?.type === TSESTree12.AST_NODE_TYPES.CallExpression) {
|
|
23058
24213
|
const { callee } = init;
|
|
23059
|
-
if (callee.type ===
|
|
24214
|
+
if (callee.type === TSESTree12.AST_NODE_TYPES.MemberExpression && callee.object.type === TSESTree12.AST_NODE_TYPES.Identifier && callee.object.name === "React" && callee.property.type === TSESTree12.AST_NODE_TYPES.Identifier && callee.property.name === "joinBindings") {
|
|
23060
24215
|
return true;
|
|
23061
24216
|
}
|
|
23062
|
-
if (callee.type ===
|
|
24217
|
+
if (callee.type === TSESTree12.AST_NODE_TYPES.MemberExpression && callee.property.type === TSESTree12.AST_NODE_TYPES.Identifier && callee.property.name === "map") {
|
|
23063
24218
|
return true;
|
|
23064
24219
|
}
|
|
23065
24220
|
}
|
|
23066
24221
|
if (init) {
|
|
23067
|
-
if (init.type ===
|
|
24222
|
+
if (init.type === TSESTree12.AST_NODE_TYPES.Literal || init.type === TSESTree12.AST_NODE_TYPES.TemplateLiteral) {
|
|
23068
24223
|
return true;
|
|
23069
24224
|
}
|
|
23070
|
-
if (init.type ===
|
|
24225
|
+
if (init.type === TSESTree12.AST_NODE_TYPES.UnaryExpression && init.argument.type === TSESTree12.AST_NODE_TYPES.Literal) {
|
|
23071
24226
|
return true;
|
|
23072
24227
|
}
|
|
23073
24228
|
}
|
|
23074
24229
|
const variableDefinition = variable.defs.find((definition2) => definition2.node === node);
|
|
23075
|
-
if (variableDefinition && variableDefinition.node.type ===
|
|
24230
|
+
if (variableDefinition && variableDefinition.node.type === TSESTree12.AST_NODE_TYPES.VariableDeclarator) {
|
|
23076
24231
|
const declarationParent = variableDefinition.node.parent?.parent;
|
|
23077
|
-
if (declarationParent && (declarationParent.type ===
|
|
24232
|
+
if (declarationParent && (declarationParent.type === TSESTree12.AST_NODE_TYPES.Program || declarationParent.type === TSESTree12.AST_NODE_TYPES.ExportNamedDeclaration)) {
|
|
23078
24233
|
testingMetrics.moduleLevelStableConst += 1;
|
|
23079
24234
|
return true;
|
|
23080
24235
|
}
|
|
@@ -23087,14 +24242,14 @@ function findTopmostMemberExpression(node) {
|
|
|
23087
24242
|
let current = node;
|
|
23088
24243
|
let { parent } = node;
|
|
23089
24244
|
while (parent) {
|
|
23090
|
-
if (parent.type ===
|
|
23091
|
-
if (current.type ===
|
|
24245
|
+
if (parent.type === TSESTree12.AST_NODE_TYPES.CallExpression && parent.callee === current) {
|
|
24246
|
+
if (current.type === TSESTree12.AST_NODE_TYPES.MemberExpression)
|
|
23092
24247
|
return current.object;
|
|
23093
24248
|
break;
|
|
23094
24249
|
}
|
|
23095
|
-
const isMemberParent = parent.type ===
|
|
23096
|
-
const isChainParent = parent.type ===
|
|
23097
|
-
const isNonNullParent = parent.type ===
|
|
24250
|
+
const isMemberParent = parent.type === TSESTree12.AST_NODE_TYPES.MemberExpression && parent.object === current;
|
|
24251
|
+
const isChainParent = parent.type === TSESTree12.AST_NODE_TYPES.ChainExpression;
|
|
24252
|
+
const isNonNullParent = parent.type === TSESTree12.AST_NODE_TYPES.TSNonNullExpression;
|
|
23098
24253
|
if (!(isMemberParent || isChainParent || isNonNullParent))
|
|
23099
24254
|
break;
|
|
23100
24255
|
current = parent;
|
|
@@ -23103,21 +24258,21 @@ function findTopmostMemberExpression(node) {
|
|
|
23103
24258
|
return current;
|
|
23104
24259
|
}
|
|
23105
24260
|
var IS_CEASE_BOUNDARY = new Set([
|
|
23106
|
-
|
|
23107
|
-
|
|
23108
|
-
|
|
23109
|
-
|
|
24261
|
+
TSESTree12.AST_NODE_TYPES.FunctionDeclaration,
|
|
24262
|
+
TSESTree12.AST_NODE_TYPES.FunctionExpression,
|
|
24263
|
+
TSESTree12.AST_NODE_TYPES.ArrowFunctionExpression,
|
|
24264
|
+
TSESTree12.AST_NODE_TYPES.VariableDeclarator
|
|
23110
24265
|
]);
|
|
23111
24266
|
var TS_RUNTIME_EXPRESSIONS = new Set([
|
|
23112
|
-
|
|
23113
|
-
|
|
23114
|
-
|
|
23115
|
-
|
|
23116
|
-
|
|
24267
|
+
TSESTree12.AST_NODE_TYPES.TSNonNullExpression,
|
|
24268
|
+
TSESTree12.AST_NODE_TYPES.TSAsExpression,
|
|
24269
|
+
TSESTree12.AST_NODE_TYPES.TSSatisfiesExpression,
|
|
24270
|
+
TSESTree12.AST_NODE_TYPES.TSTypeAssertion,
|
|
24271
|
+
TSESTree12.AST_NODE_TYPES.TSInstantiationExpression
|
|
23117
24272
|
]);
|
|
23118
24273
|
function isComputedPropertyIdentifier(identifier3) {
|
|
23119
24274
|
const { parent } = identifier3;
|
|
23120
|
-
return parent?.type ===
|
|
24275
|
+
return parent?.type === TSESTree12.AST_NODE_TYPES.Property && parent.computed && parent.key === identifier3;
|
|
23121
24276
|
}
|
|
23122
24277
|
function isInTypePosition(identifier3) {
|
|
23123
24278
|
let parent = identifier3.parent;
|
|
@@ -23171,10 +24326,10 @@ function resolveFunctionReference(identifier3, scope) {
|
|
|
23171
24326
|
return;
|
|
23172
24327
|
for (const definition of variable.defs) {
|
|
23173
24328
|
const { node } = definition;
|
|
23174
|
-
if (node.type ===
|
|
24329
|
+
if (node.type === TSESTree12.AST_NODE_TYPES.FunctionDeclaration) {
|
|
23175
24330
|
return node;
|
|
23176
24331
|
}
|
|
23177
|
-
if (node.type ===
|
|
24332
|
+
if (node.type === TSESTree12.AST_NODE_TYPES.VariableDeclarator && node.init && (node.init.type === TSESTree12.AST_NODE_TYPES.ArrowFunctionExpression || node.init.type === TSESTree12.AST_NODE_TYPES.FunctionExpression)) {
|
|
23178
24333
|
return node.init;
|
|
23179
24334
|
}
|
|
23180
24335
|
}
|
|
@@ -23184,7 +24339,7 @@ function collectCaptures(node, sourceCode) {
|
|
|
23184
24339
|
const captures = new Array;
|
|
23185
24340
|
const captureSet = new Set;
|
|
23186
24341
|
function visit(current) {
|
|
23187
|
-
if (current.type ===
|
|
24342
|
+
if (current.type === TSESTree12.AST_NODE_TYPES.Identifier) {
|
|
23188
24343
|
const { name } = current;
|
|
23189
24344
|
if (captureSet.has(name) || GLOBAL_BUILTINS.has(name) || isInTypePosition(current))
|
|
23190
24345
|
return;
|
|
@@ -23226,21 +24381,21 @@ function collectCaptures(node, sourceCode) {
|
|
|
23226
24381
|
}
|
|
23227
24382
|
}
|
|
23228
24383
|
}
|
|
23229
|
-
if (current.type ===
|
|
24384
|
+
if (current.type === TSESTree12.AST_NODE_TYPES.TSSatisfiesExpression || current.type === TSESTree12.AST_NODE_TYPES.TSAsExpression || current.type === TSESTree12.AST_NODE_TYPES.TSTypeAssertion || current.type === TSESTree12.AST_NODE_TYPES.TSNonNullExpression) {
|
|
23230
24385
|
visit(current.expression);
|
|
23231
24386
|
return;
|
|
23232
24387
|
}
|
|
23233
|
-
if (current.type ===
|
|
24388
|
+
if (current.type === TSESTree12.AST_NODE_TYPES.MemberExpression) {
|
|
23234
24389
|
visit(current.object);
|
|
23235
24390
|
if (current.computed)
|
|
23236
24391
|
visit(current.property);
|
|
23237
24392
|
return;
|
|
23238
24393
|
}
|
|
23239
|
-
if (current.type ===
|
|
24394
|
+
if (current.type === TSESTree12.AST_NODE_TYPES.ChainExpression) {
|
|
23240
24395
|
visit(current.expression);
|
|
23241
24396
|
return;
|
|
23242
24397
|
}
|
|
23243
|
-
if (current.type ===
|
|
24398
|
+
if (current.type === TSESTree12.AST_NODE_TYPES.Property) {
|
|
23244
24399
|
if (current.computed)
|
|
23245
24400
|
visit(current.key);
|
|
23246
24401
|
visit(current.value);
|
|
@@ -23265,7 +24420,7 @@ function parseDependencies(node, sourceCode) {
|
|
|
23265
24420
|
for (const element of node.elements) {
|
|
23266
24421
|
if (!element)
|
|
23267
24422
|
continue;
|
|
23268
|
-
const actualNode = element.type ===
|
|
24423
|
+
const actualNode = element.type === TSESTree12.AST_NODE_TYPES.SpreadElement ? element.argument : element;
|
|
23269
24424
|
const name = nodeToDependencyString(actualNode, sourceCode);
|
|
23270
24425
|
const depth = getMemberExpressionDepth(actualNode);
|
|
23271
24426
|
dependencies4.push({
|
|
@@ -23342,9 +24497,9 @@ var useExhaustiveDependencies = {
|
|
|
23342
24497
|
if (closureArgument === undefined)
|
|
23343
24498
|
return;
|
|
23344
24499
|
let closureFunction;
|
|
23345
|
-
if (closureArgument.type ===
|
|
24500
|
+
if (closureArgument.type === TSESTree12.AST_NODE_TYPES.ArrowFunctionExpression || closureArgument.type === TSESTree12.AST_NODE_TYPES.FunctionExpression) {
|
|
23346
24501
|
closureFunction = closureArgument;
|
|
23347
|
-
} else if (closureArgument.type ===
|
|
24502
|
+
} else if (closureArgument.type === TSESTree12.AST_NODE_TYPES.Identifier) {
|
|
23348
24503
|
const scope = getScope(callNode);
|
|
23349
24504
|
closureFunction = resolveFunctionReference(closureArgument, scope);
|
|
23350
24505
|
}
|
|
@@ -23378,7 +24533,7 @@ var useExhaustiveDependencies = {
|
|
|
23378
24533
|
}
|
|
23379
24534
|
if (!dependenciesArgument)
|
|
23380
24535
|
return;
|
|
23381
|
-
if (dependenciesArgument.type !==
|
|
24536
|
+
if (dependenciesArgument.type !== TSESTree12.AST_NODE_TYPES.ArrayExpression)
|
|
23382
24537
|
return;
|
|
23383
24538
|
const dependenciesArray = dependenciesArgument;
|
|
23384
24539
|
const captures = collectCaptures(closureFunction, context.sourceCode);
|
|
@@ -23588,7 +24743,7 @@ var useExhaustiveDependencies = {
|
|
|
23588
24743
|
var use_exhaustive_dependencies_default = useExhaustiveDependencies;
|
|
23589
24744
|
|
|
23590
24745
|
// src/rules/use-hook-at-top-level.ts
|
|
23591
|
-
import { TSESTree as
|
|
24746
|
+
import { TSESTree as TSESTree13 } from "@typescript-eslint/types";
|
|
23592
24747
|
var HOOK_NAME_PATTERN = /^use[A-Z]/;
|
|
23593
24748
|
var COMPONENT_NAME_PATTERN2 = /^[A-Z]/;
|
|
23594
24749
|
function isReactHook(name) {
|
|
@@ -23598,23 +24753,23 @@ function isComponent(name) {
|
|
|
23598
24753
|
return COMPONENT_NAME_PATTERN2.test(name);
|
|
23599
24754
|
}
|
|
23600
24755
|
function isComponentOrHook(node) {
|
|
23601
|
-
if (node.type ===
|
|
24756
|
+
if (node.type === TSESTree13.AST_NODE_TYPES.FunctionDeclaration && node.id) {
|
|
23602
24757
|
const { name } = node.id;
|
|
23603
24758
|
return isComponent(name) || isReactHook(name);
|
|
23604
24759
|
}
|
|
23605
|
-
if (node.type ===
|
|
24760
|
+
if (node.type === TSESTree13.AST_NODE_TYPES.FunctionExpression || node.type === TSESTree13.AST_NODE_TYPES.ArrowFunctionExpression) {
|
|
23606
24761
|
const { parent } = node;
|
|
23607
24762
|
if (parent === undefined)
|
|
23608
24763
|
return false;
|
|
23609
|
-
if (parent.type ===
|
|
24764
|
+
if (parent.type === TSESTree13.AST_NODE_TYPES.VariableDeclarator && parent.id.type === TSESTree13.AST_NODE_TYPES.Identifier) {
|
|
23610
24765
|
const { name } = parent.id;
|
|
23611
24766
|
return isComponent(name) || isReactHook(name);
|
|
23612
24767
|
}
|
|
23613
|
-
if (parent.type ===
|
|
24768
|
+
if (parent.type === TSESTree13.AST_NODE_TYPES.Property && parent.key.type === TSESTree13.AST_NODE_TYPES.Identifier) {
|
|
23614
24769
|
const { name } = parent.key;
|
|
23615
24770
|
return isComponent(name) || isReactHook(name);
|
|
23616
24771
|
}
|
|
23617
|
-
if (parent.type ===
|
|
24772
|
+
if (parent.type === TSESTree13.AST_NODE_TYPES.MethodDefinition && parent.key.type === TSESTree13.AST_NODE_TYPES.Identifier) {
|
|
23618
24773
|
const { name } = parent.key;
|
|
23619
24774
|
return isComponent(name) || isReactHook(name);
|
|
23620
24775
|
}
|
|
@@ -23623,17 +24778,17 @@ function isComponentOrHook(node) {
|
|
|
23623
24778
|
}
|
|
23624
24779
|
function isHookCall(node) {
|
|
23625
24780
|
const { callee } = node;
|
|
23626
|
-
if (callee.type ===
|
|
24781
|
+
if (callee.type === TSESTree13.AST_NODE_TYPES.Identifier)
|
|
23627
24782
|
return isReactHook(callee.name);
|
|
23628
|
-
if (callee.type ===
|
|
24783
|
+
if (callee.type === TSESTree13.AST_NODE_TYPES.MemberExpression && callee.property.type === TSESTree13.AST_NODE_TYPES.Identifier) {
|
|
23629
24784
|
return isReactHook(callee.property.name);
|
|
23630
24785
|
}
|
|
23631
24786
|
return false;
|
|
23632
24787
|
}
|
|
23633
24788
|
var FUNCTION_BOUNDARIES2 = new Set([
|
|
23634
|
-
|
|
23635
|
-
|
|
23636
|
-
|
|
24789
|
+
TSESTree13.AST_NODE_TYPES.FunctionDeclaration,
|
|
24790
|
+
TSESTree13.AST_NODE_TYPES.FunctionExpression,
|
|
24791
|
+
TSESTree13.AST_NODE_TYPES.ArrowFunctionExpression
|
|
23637
24792
|
]);
|
|
23638
24793
|
function isInFinallyBlock(node) {
|
|
23639
24794
|
let current = node.parent;
|
|
@@ -23642,7 +24797,7 @@ function isInFinallyBlock(node) {
|
|
|
23642
24797
|
for (let depth = 0;depth < maxDepth && current; depth += 1) {
|
|
23643
24798
|
if (FUNCTION_BOUNDARIES2.has(current.type))
|
|
23644
24799
|
break;
|
|
23645
|
-
if (current.type ===
|
|
24800
|
+
if (current.type === TSESTree13.AST_NODE_TYPES.TryStatement) {
|
|
23646
24801
|
let checkNode = node;
|
|
23647
24802
|
while (checkNode && checkNode !== current) {
|
|
23648
24803
|
if (checkNode === current.finalizer) {
|
|
@@ -23690,14 +24845,14 @@ var useHookAtTopLevel = {
|
|
|
23690
24845
|
if (ignoreHooks?.includes(hookName))
|
|
23691
24846
|
return true;
|
|
23692
24847
|
if (importSources && Object.keys(importSources).length > 0) {
|
|
23693
|
-
if (node.callee.type ===
|
|
23694
|
-
const objectName = node.callee.object.type ===
|
|
24848
|
+
if (node.callee.type === TSESTree13.AST_NODE_TYPES.MemberExpression) {
|
|
24849
|
+
const objectName = node.callee.object.type === TSESTree13.AST_NODE_TYPES.Identifier ? node.callee.object.name : undefined;
|
|
23695
24850
|
if (objectName && importSources[objectName] === false)
|
|
23696
24851
|
return true;
|
|
23697
24852
|
if (objectName && importSources[objectName] === true)
|
|
23698
24853
|
return false;
|
|
23699
24854
|
}
|
|
23700
|
-
if (node.callee.type ===
|
|
24855
|
+
if (node.callee.type === TSESTree13.AST_NODE_TYPES.Identifier) {
|
|
23701
24856
|
const importSource = importSourceMap.get(hookName);
|
|
23702
24857
|
if (importSource && importSources[importSource] === false)
|
|
23703
24858
|
return true;
|
|
@@ -23712,7 +24867,7 @@ var useHookAtTopLevel = {
|
|
|
23712
24867
|
const current = getCurrentContext();
|
|
23713
24868
|
const depth = current ? current.functionDepth + 1 : 0;
|
|
23714
24869
|
const isComponentOrHookFlag = isComponentOrHook(functionNode);
|
|
23715
|
-
if (functionNode.type ===
|
|
24870
|
+
if (functionNode.type === TSESTree13.AST_NODE_TYPES.FunctionDeclaration && functionNode.id) {
|
|
23716
24871
|
currentFunctionName = functionNode.id.name;
|
|
23717
24872
|
}
|
|
23718
24873
|
if (current?.isComponentOrHook) {
|
|
@@ -23751,7 +24906,7 @@ var useHookAtTopLevel = {
|
|
|
23751
24906
|
if (!isHookCall(callNode))
|
|
23752
24907
|
return;
|
|
23753
24908
|
const { callee } = callNode;
|
|
23754
|
-
const hookName = callee.type ===
|
|
24909
|
+
const hookName = callee.type === TSESTree13.AST_NODE_TYPES.Identifier ? callee.name : callee.type === TSESTree13.AST_NODE_TYPES.MemberExpression && callee.property.type === TSESTree13.AST_NODE_TYPES.Identifier ? callee.property.name : undefined;
|
|
23755
24910
|
if (!hookName || shouldIgnoreHook(hookName, callNode))
|
|
23756
24911
|
return;
|
|
23757
24912
|
const current = getCurrentContext();
|
|
@@ -23849,10 +25004,10 @@ var useHookAtTopLevel = {
|
|
|
23849
25004
|
if (!configuration.importSources || Object.keys(configuration.importSources).length === 0)
|
|
23850
25005
|
return;
|
|
23851
25006
|
for (const specifier of importNode.specifiers) {
|
|
23852
|
-
if (specifier.type !==
|
|
25007
|
+
if (specifier.type !== TSESTree13.AST_NODE_TYPES.ImportSpecifier)
|
|
23853
25008
|
continue;
|
|
23854
25009
|
const { imported } = specifier;
|
|
23855
|
-
if (imported.type !==
|
|
25010
|
+
if (imported.type !== TSESTree13.AST_NODE_TYPES.Identifier)
|
|
23856
25011
|
continue;
|
|
23857
25012
|
if (isReactHook(imported.name))
|
|
23858
25013
|
importSourceMap.set(specifier.local.name, source);
|
|
@@ -23961,6 +25116,9 @@ function createNoInstanceMethodsOptions(options3 = {}) {
|
|
|
23961
25116
|
...options3
|
|
23962
25117
|
};
|
|
23963
25118
|
}
|
|
25119
|
+
function createNoMemoChildrenOptions(options3 = {}) {
|
|
25120
|
+
return { allowedComponents: [], environment: "roblox-ts", ...options3 };
|
|
25121
|
+
}
|
|
23964
25122
|
function createNoShorthandOptions(options3 = {}) {
|
|
23965
25123
|
return { allowPropertyAccess: [], ignoreShorthands: [], shorthands: {}, ...options3 };
|
|
23966
25124
|
}
|
|
@@ -24044,6 +25202,7 @@ var rules = {
|
|
|
24044
25202
|
"no-god-components": no_god_components_default,
|
|
24045
25203
|
"no-identity-map": no_identity_map_default,
|
|
24046
25204
|
"no-instance-methods-without-this": no_instance_methods_without_this_default,
|
|
25205
|
+
"no-memo-children": no_memo_children_default,
|
|
24047
25206
|
"no-print": no_print_default,
|
|
24048
25207
|
"no-shorthand-names": no_shorthand_names_default,
|
|
24049
25208
|
"no-useless-use-spring": no_useless_use_spring_default,
|
|
@@ -24079,6 +25238,7 @@ var recommended = {
|
|
|
24079
25238
|
"cease-nonsense/no-god-components": "error",
|
|
24080
25239
|
"cease-nonsense/no-identity-map": "error",
|
|
24081
25240
|
"cease-nonsense/no-instance-methods-without-this": "error",
|
|
25241
|
+
"cease-nonsense/no-memo-children": "error",
|
|
24082
25242
|
"cease-nonsense/no-print": "error",
|
|
24083
25243
|
"cease-nonsense/no-shorthand-names": "error",
|
|
24084
25244
|
"cease-nonsense/no-warn": "error",
|
|
@@ -24109,6 +25269,7 @@ export {
|
|
|
24109
25269
|
createPairConfiguration,
|
|
24110
25270
|
createNoUselessUseSpringOptions,
|
|
24111
25271
|
createNoShorthandOptions,
|
|
25272
|
+
createNoMemoChildrenOptions,
|
|
24112
25273
|
createNoInstanceMethodsOptions,
|
|
24113
25274
|
createNoGodComponentsOptions,
|
|
24114
25275
|
createHookConfiguration,
|
|
@@ -24116,5 +25277,3 @@ export {
|
|
|
24116
25277
|
createComplexityConfiguration,
|
|
24117
25278
|
createBanInstancesOptions
|
|
24118
25279
|
};
|
|
24119
|
-
|
|
24120
|
-
//# debugId=82B8719F042D688964756E2164756E21
|