@dereekb/dbx-web 13.11.13 → 13.11.15

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.
@@ -121,22 +121,20 @@
121
121
  * @returns The decorator name, or empty string when unrecognized.
122
122
  */ function getDecoratorName(decorator) {
123
123
  var expression = decorator === null || decorator === void 0 ? void 0 : decorator.expression;
124
- if (!expression) {
125
- return '';
126
- }
127
- if (expression.type === 'CallExpression') {
128
- var _expression_callee, _expression_callee1, _expression_callee_property;
129
- if (((_expression_callee = expression.callee) === null || _expression_callee === void 0 ? void 0 : _expression_callee.type) === 'Identifier') {
130
- return expression.callee.name;
131
- }
132
- if (((_expression_callee1 = expression.callee) === null || _expression_callee1 === void 0 ? void 0 : _expression_callee1.type) === 'MemberExpression' && ((_expression_callee_property = expression.callee.property) === null || _expression_callee_property === void 0 ? void 0 : _expression_callee_property.type) === 'Identifier') {
133
- return expression.callee.property.name;
124
+ var result = '';
125
+ if (expression) {
126
+ if (expression.type === 'CallExpression') {
127
+ var _expression_callee, _expression_callee1, _expression_callee_property;
128
+ if (((_expression_callee = expression.callee) === null || _expression_callee === void 0 ? void 0 : _expression_callee.type) === 'Identifier') {
129
+ result = expression.callee.name;
130
+ } else if (((_expression_callee1 = expression.callee) === null || _expression_callee1 === void 0 ? void 0 : _expression_callee1.type) === 'MemberExpression' && ((_expression_callee_property = expression.callee.property) === null || _expression_callee_property === void 0 ? void 0 : _expression_callee_property.type) === 'Identifier') {
131
+ result = expression.callee.property.name;
132
+ }
133
+ } else if (expression.type === 'Identifier') {
134
+ result = expression.name;
134
135
  }
135
136
  }
136
- if (expression.type === 'Identifier') {
137
- return expression.name;
138
- }
139
- return '';
137
+ return result;
140
138
  }
141
139
  /**
142
140
  * Returns the first decorator on the class that names a component-tier
@@ -190,16 +188,15 @@
190
188
  * @returns The property name, or null when not a simple key.
191
189
  */ function getClassMemberName(member) {
192
190
  var key = member === null || member === void 0 ? void 0 : member.key;
193
- if (!key || member.computed) {
194
- return null;
195
- }
196
- if (key.type === 'Identifier') {
197
- return key.name;
198
- }
199
- if (key.type === 'Literal' && typeof key.value === 'string') {
200
- return key.value;
191
+ var result = null;
192
+ if (key && !member.computed) {
193
+ if (key.type === 'Identifier') {
194
+ result = key.name;
195
+ } else if (key.type === 'Literal' && typeof key.value === 'string') {
196
+ result = key.value;
197
+ }
201
198
  }
202
- return null;
199
+ return result;
203
200
  }
204
201
  /**
205
202
  * Finds the `ngOnDestroy` method declaration on the given class, if any.
@@ -241,23 +238,23 @@
241
238
  * If the given expression is a `CallExpression` whose callee is one of the
242
239
  * accepted identifier names, returns the matching name. Otherwise null.
243
240
  *
241
+ * @param node - The expression AST node.
242
+ * @param names - The accepted identifier names.
243
+ * @returns The matched name, or null.
244
+ *
244
245
  * @example
245
246
  * ```
246
247
  * isCalledIdentifier(node, ['cleanSubscription', 'clean']) // returns 'cleanSubscription'
247
248
  * ```
248
- *
249
- * @param node - The expression AST node.
250
- * @param names - The accepted identifier names.
251
- * @returns The matched name, or null.
252
249
  */ function isCalledIdentifier(node, names) {
253
- if ((node === null || node === void 0 ? void 0 : node.type) !== 'CallExpression') {
254
- return null;
255
- }
256
- var callee = node.callee;
257
- if ((callee === null || callee === void 0 ? void 0 : callee.type) === 'Identifier' && names.has(callee.name)) {
258
- return callee.name;
250
+ var result = null;
251
+ if ((node === null || node === void 0 ? void 0 : node.type) === 'CallExpression') {
252
+ var callee = node.callee;
253
+ if ((callee === null || callee === void 0 ? void 0 : callee.type) === 'Identifier' && names.has(callee.name)) {
254
+ result = callee.name;
255
+ }
259
256
  }
260
- return null;
257
+ return result;
261
258
  }
262
259
  /**
263
260
  * Returns true when the given AST node is a `this.<propName>` MemberExpression.
@@ -281,27 +278,26 @@
281
278
  */ function ensureNamedImportFix(input) {
282
279
  var fixer = input.fixer, registry = input.registry, importName = input.importName, fromSource = input.fromSource;
283
280
  var existing = registry.bySource.get(fromSource);
284
- if (existing === null || existing === void 0 ? void 0 : existing.has(importName)) {
285
- return null;
286
- }
287
- var declaration = registry.sourceToDeclaration.get(fromSource);
288
281
  var result = null;
289
- if (declaration) {
290
- var _declaration_specifiers;
291
- var lastSpecifier = (_declaration_specifiers = declaration.specifiers) === null || _declaration_specifiers === void 0 ? void 0 : _declaration_specifiers[declaration.specifiers.length - 1];
292
- if (lastSpecifier) {
293
- var updatedSet = existing !== null && existing !== void 0 ? existing : new Set();
294
- updatedSet.add(importName);
295
- registry.bySource.set(fromSource, updatedSet);
282
+ if (!(existing === null || existing === void 0 ? void 0 : existing.has(importName))) {
283
+ var declaration = registry.sourceToDeclaration.get(fromSource);
284
+ if (declaration) {
285
+ var _declaration_specifiers;
286
+ var lastSpecifier = (_declaration_specifiers = declaration.specifiers) === null || _declaration_specifiers === void 0 ? void 0 : _declaration_specifiers[declaration.specifiers.length - 1];
287
+ if (lastSpecifier) {
288
+ var updatedSet = existing !== null && existing !== void 0 ? existing : new Set();
289
+ updatedSet.add(importName);
290
+ registry.bySource.set(fromSource, updatedSet);
291
+ registry.localToSource.set(importName, fromSource);
292
+ result = fixer.insertTextAfter(lastSpecifier, ", ".concat(importName));
293
+ }
294
+ } else if (registry.lastImportDeclaration) {
295
+ var updatedSet1 = existing !== null && existing !== void 0 ? existing : new Set();
296
+ updatedSet1.add(importName);
297
+ registry.bySource.set(fromSource, updatedSet1);
296
298
  registry.localToSource.set(importName, fromSource);
297
- result = fixer.insertTextAfter(lastSpecifier, ", ".concat(importName));
299
+ result = fixer.insertTextAfter(registry.lastImportDeclaration, "\nimport { ".concat(importName, " } from '").concat(fromSource, "';"));
298
300
  }
299
- } else if (registry.lastImportDeclaration) {
300
- var updatedSet1 = existing !== null && existing !== void 0 ? existing : new Set();
301
- updatedSet1.add(importName);
302
- registry.bySource.set(fromSource, updatedSet1);
303
- registry.localToSource.set(importName, fromSource);
304
- result = fixer.insertTextAfter(registry.lastImportDeclaration, "\nimport { ".concat(importName, " } from '").concat(fromSource, "';"));
305
301
  }
306
302
  return result;
307
303
  }
@@ -419,7 +415,7 @@
419
415
  * - Rewrites the initializer to `cleanSubscription(...)` (preserving any constructor argument).
420
416
  * - Inserts the `cleanSubscription` named import from `@dereekb/dbx-core` if missing.
421
417
  * - Removes any matching `this.<field>.destroy();` line from the same class's `ngOnDestroy`.
422
- */ var dbxWebRequireCleanSubscriptionRule = {
418
+ */ var DBX_WEB_REQUIRE_CLEAN_SUBSCRIPTION_RULE = {
423
419
  meta: {
424
420
  type: 'problem',
425
421
  fixable: 'code',
@@ -657,7 +653,7 @@
657
653
  * - Wraps the initializer with `completeOnDestroy(...)`.
658
654
  * - Inserts the `completeOnDestroy` named import from `@dereekb/dbx-core` if missing.
659
655
  * - Removes any matching `this.<field>.complete();` line from the same class's `ngOnDestroy`.
660
- */ var dbxWebRequireCompleteOnDestroyRule = {
656
+ */ var DBX_WEB_REQUIRE_COMPLETE_ON_DESTROY_RULE = {
661
657
  meta: {
662
658
  type: 'problem',
663
659
  fixable: 'code',
@@ -826,7 +822,7 @@
826
822
  * - When a class declares `implements OnDestroy` from `@angular/core` but has
827
823
  * no `ngOnDestroy()` method (e.g. left over from a previous run), the
828
824
  * orphaned implements clause is removed.
829
- */ var dbxWebNoRedundantOnDestroyRule = {
825
+ */ var DBX_WEB_NO_REDUNDANT_ON_DESTROY_RULE = {
830
826
  meta: {
831
827
  type: 'suggestion',
832
828
  fixable: 'code',
@@ -845,59 +841,56 @@
845
841
  create: function create(context) {
846
842
  var registry = createImportRegistry();
847
843
  var sourceCode = context.sourceCode;
848
- var visitClass = function visitClass(classNode) {
849
- var _ngOnDestroy_value_body, _ngOnDestroy_value;
850
- var matchedDecorator = findAngularComponentDecorator(classNode, registry);
851
- if (!matchedDecorator) {
852
- return;
853
- }
854
- var ngOnDestroy = findNgOnDestroyMethod(classNode);
855
- var body = ngOnDestroy === null || ngOnDestroy === void 0 ? void 0 : (_ngOnDestroy_value = ngOnDestroy.value) === null || _ngOnDestroy_value === void 0 ? void 0 : (_ngOnDestroy_value_body = _ngOnDestroy_value.body) === null || _ngOnDestroy_value_body === void 0 ? void 0 : _ngOnDestroy_value_body.body;
856
- if (!ngOnDestroy || !body) {
857
- var implementsMatch = findOnDestroyImplementsClause(classNode, registry);
858
- if (implementsMatch) {
859
- context.report({
860
- node: implementsMatch.clauseSpecifier,
861
- messageId: 'orphanedImplementsOnDestroy',
862
- fix: function fix(fixer) {
863
- return [
864
- fixer.removeRange(getImplementsSpecifierRemovalRange(implementsMatch, sourceCode))
865
- ];
866
- }
867
- });
868
- }
869
- return;
870
- }
871
- if (body.length === 0) {
844
+ var reportOrphanedImplements = function reportOrphanedImplements(classNode) {
845
+ var implementsMatch = findOnDestroyImplementsClause(classNode, registry);
846
+ if (implementsMatch) {
872
847
  context.report({
873
- node: ngOnDestroy,
874
- messageId: 'emptyNgOnDestroy',
848
+ node: implementsMatch.clauseSpecifier,
849
+ messageId: 'orphanedImplementsOnDestroy',
875
850
  fix: function fix(fixer) {
876
- return buildRemoveNgOnDestroyFixes({
877
- fixer: fixer,
878
- ngOnDestroy: ngOnDestroy,
879
- classNode: classNode,
880
- registry: registry,
881
- sourceCode: sourceCode
882
- });
851
+ return [
852
+ fixer.removeRange(getImplementsSpecifierRemovalRange(implementsMatch, sourceCode))
853
+ ];
883
854
  }
884
855
  });
885
- return;
886
856
  }
887
- var wrappedFields = collectWrappedFieldNames(classNode);
888
- var redundantStatements = [];
889
- var hasNonRedundantStatement = false;
857
+ };
858
+ var reportRemoveNgOnDestroy = function reportRemoveNgOnDestroy(ngOnDestroy, classNode, messageId) {
859
+ context.report({
860
+ node: ngOnDestroy,
861
+ messageId: messageId,
862
+ fix: function fix(fixer) {
863
+ return buildRemoveNgOnDestroyFixes({
864
+ fixer: fixer,
865
+ ngOnDestroy: ngOnDestroy,
866
+ classNode: classNode,
867
+ registry: registry,
868
+ sourceCode: sourceCode
869
+ });
870
+ }
871
+ });
872
+ };
873
+ var reportRedundantStatements = function reportRedundantStatements(entries) {
890
874
  var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
891
875
  try {
892
- for(var _iterator = body[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
893
- var statement = _step.value;
894
- var match = matchRedundantCleanupStatement(statement, wrappedFields);
895
- if (match) {
896
- redundantStatements.push(match);
897
- } else {
898
- hasNonRedundantStatement = true;
899
- }
900
- }
876
+ var _loop = function() {
877
+ var entry = _step.value;
878
+ context.report({
879
+ node: entry.statement,
880
+ messageId: 'redundantCleanupCall',
881
+ data: {
882
+ name: entry.fieldName,
883
+ method: entry.method,
884
+ wrapper: entry.wrapper
885
+ },
886
+ fix: function fix(fixer) {
887
+ return [
888
+ fixer.removeRange(getStatementRangeWithLeadingWhitespace(entry.statement, sourceCode))
889
+ ];
890
+ }
891
+ });
892
+ };
893
+ for(var _iterator = entries[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true)_loop();
901
894
  } catch (err) {
902
895
  _didIteratorError = true;
903
896
  _iteratorError = err;
@@ -912,58 +905,29 @@
912
905
  }
913
906
  }
914
907
  }
915
- if (redundantStatements.length === 0) {
916
- return;
908
+ };
909
+ var visitNgOnDestroyBody = function visitNgOnDestroyBody(ngOnDestroy, body, classNode) {
910
+ var _partitionNgOnDestroyStatements = partitionNgOnDestroyStatements(body, classNode), redundantStatements = _partitionNgOnDestroyStatements.redundantStatements, hasNonRedundantStatement = _partitionNgOnDestroyStatements.hasNonRedundantStatement;
911
+ if (redundantStatements.length > 0) {
912
+ if (hasNonRedundantStatement) {
913
+ reportRedundantStatements(redundantStatements);
914
+ } else {
915
+ reportRemoveNgOnDestroy(ngOnDestroy, classNode, 'redundantNgOnDestroy');
916
+ }
917
917
  }
918
- if (hasNonRedundantStatement) {
919
- var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
920
- try {
921
- var _loop = function() {
922
- var entry = _step1.value;
923
- context.report({
924
- node: entry.statement,
925
- messageId: 'redundantCleanupCall',
926
- data: {
927
- name: entry.fieldName,
928
- method: entry.method,
929
- wrapper: entry.wrapper
930
- },
931
- fix: function fix(fixer) {
932
- return [
933
- fixer.removeRange(getStatementRangeWithLeadingWhitespace(entry.statement, sourceCode))
934
- ];
935
- }
936
- });
937
- };
938
- for(var _iterator1 = redundantStatements[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true)_loop();
939
- } catch (err) {
940
- _didIteratorError1 = true;
941
- _iteratorError1 = err;
942
- } finally{
943
- try {
944
- if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
945
- _iterator1.return();
946
- }
947
- } finally{
948
- if (_didIteratorError1) {
949
- throw _iteratorError1;
950
- }
951
- }
918
+ };
919
+ var visitClass = function visitClass(classNode) {
920
+ if (findAngularComponentDecorator(classNode, registry)) {
921
+ var _ngOnDestroy_value_body, _ngOnDestroy_value;
922
+ var ngOnDestroy = findNgOnDestroyMethod(classNode);
923
+ var body = ngOnDestroy === null || ngOnDestroy === void 0 ? void 0 : (_ngOnDestroy_value = ngOnDestroy.value) === null || _ngOnDestroy_value === void 0 ? void 0 : (_ngOnDestroy_value_body = _ngOnDestroy_value.body) === null || _ngOnDestroy_value_body === void 0 ? void 0 : _ngOnDestroy_value_body.body;
924
+ if (!ngOnDestroy || !body) {
925
+ reportOrphanedImplements(classNode);
926
+ } else if (body.length === 0) {
927
+ reportRemoveNgOnDestroy(ngOnDestroy, classNode, 'emptyNgOnDestroy');
928
+ } else {
929
+ visitNgOnDestroyBody(ngOnDestroy, body, classNode);
952
930
  }
953
- } else {
954
- context.report({
955
- node: ngOnDestroy,
956
- messageId: 'redundantNgOnDestroy',
957
- fix: function fix(fixer) {
958
- return buildRemoveNgOnDestroyFixes({
959
- fixer: fixer,
960
- ngOnDestroy: ngOnDestroy,
961
- classNode: classNode,
962
- registry: registry,
963
- sourceCode: sourceCode
964
- });
965
- }
966
- });
967
931
  }
968
932
  };
969
933
  return {
@@ -1030,6 +994,87 @@
1030
994
  */ function wrapperNameFromInitializer(expression) {
1031
995
  return expression ? isCalledIdentifier(expression, HELPER_NAMES) : null;
1032
996
  }
997
+ /**
998
+ * Splits an `ngOnDestroy` body into redundant cleanup matches and a flag
999
+ * indicating whether any other (non-redundant) statement is present.
1000
+ *
1001
+ * @param body - The statements of the `ngOnDestroy` method body.
1002
+ * @param classNode - The owning class node, used to gather wrapped fields.
1003
+ * @returns The redundant matches and the non-redundant flag.
1004
+ */ function partitionNgOnDestroyStatements(body, classNode) {
1005
+ var wrappedFields = collectWrappedFieldNames(classNode);
1006
+ var redundantStatements = [];
1007
+ var hasNonRedundantStatement = false;
1008
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
1009
+ try {
1010
+ for(var _iterator = body[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
1011
+ var statement = _step.value;
1012
+ var match = matchRedundantCleanupStatement(statement, wrappedFields);
1013
+ if (match) {
1014
+ redundantStatements.push(match);
1015
+ } else {
1016
+ hasNonRedundantStatement = true;
1017
+ }
1018
+ }
1019
+ } catch (err) {
1020
+ _didIteratorError = true;
1021
+ _iteratorError = err;
1022
+ } finally{
1023
+ try {
1024
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
1025
+ _iterator.return();
1026
+ }
1027
+ } finally{
1028
+ if (_didIteratorError) {
1029
+ throw _iteratorError;
1030
+ }
1031
+ }
1032
+ }
1033
+ return {
1034
+ redundantStatements: redundantStatements,
1035
+ hasNonRedundantStatement: hasNonRedundantStatement
1036
+ };
1037
+ }
1038
+ /**
1039
+ * Returns the redundant method name (`destroy` / `complete`) when the call
1040
+ * expression is a zero-argument member call to one of those methods.
1041
+ *
1042
+ * @param expression - The expression to inspect.
1043
+ * @returns The method name and its callee MemberExpression, or null.
1044
+ */ function getRedundantMethodCall(expression) {
1045
+ var _expression_arguments, _expression_callee;
1046
+ var result = null;
1047
+ var isZeroArgMemberCall = (expression === null || expression === void 0 ? void 0 : expression.type) === 'CallExpression' && ((_expression_arguments = expression.arguments) === null || _expression_arguments === void 0 ? void 0 : _expression_arguments.length) === 0 && ((_expression_callee = expression.callee) === null || _expression_callee === void 0 ? void 0 : _expression_callee.type) === 'MemberExpression';
1048
+ if (isZeroArgMemberCall) {
1049
+ var _callee_property;
1050
+ var callee = expression.callee;
1051
+ var methodName = !callee.computed && ((_callee_property = callee.property) === null || _callee_property === void 0 ? void 0 : _callee_property.type) === 'Identifier' ? callee.property.name : null;
1052
+ if (methodName && REDUNDANT_METHODS.has(methodName)) {
1053
+ result = {
1054
+ methodName: methodName,
1055
+ callee: callee
1056
+ };
1057
+ }
1058
+ }
1059
+ return result;
1060
+ }
1061
+ /**
1062
+ * Returns the `this.<fieldName>` field name from a callee object, or null
1063
+ * when the receiver is not a non-computed `this.<identifier>` access.
1064
+ *
1065
+ * @param calleeObject - The callee's object (the receiver of the method call).
1066
+ * @returns The field name or null.
1067
+ */ function getThisFieldName(calleeObject) {
1068
+ var _calleeObject_property;
1069
+ var result = null;
1070
+ if ((calleeObject === null || calleeObject === void 0 ? void 0 : calleeObject.type) === 'MemberExpression' && !calleeObject.computed && ((_calleeObject_property = calleeObject.property) === null || _calleeObject_property === void 0 ? void 0 : _calleeObject_property.type) === 'Identifier') {
1071
+ var fieldName = calleeObject.property.name;
1072
+ if (isThisMemberAccess(calleeObject, fieldName)) {
1073
+ result = fieldName;
1074
+ }
1075
+ }
1076
+ return result;
1077
+ }
1033
1078
  /**
1034
1079
  * Returns details for a redundant cleanup statement, or null when the
1035
1080
  * statement is anything other than a redundant `this.<field>.<destroy|complete>()` call.
@@ -1040,25 +1085,16 @@
1040
1085
  */ function matchRedundantCleanupStatement(statement, wrappedFields) {
1041
1086
  var result = null;
1042
1087
  if (statement.type === 'ExpressionStatement') {
1043
- var _call_arguments, _call_callee;
1044
- var call = statement.expression;
1045
- var isZeroArgMemberCall = (call === null || call === void 0 ? void 0 : call.type) === 'CallExpression' && ((_call_arguments = call.arguments) === null || _call_arguments === void 0 ? void 0 : _call_arguments.length) === 0 && ((_call_callee = call.callee) === null || _call_callee === void 0 ? void 0 : _call_callee.type) === 'MemberExpression';
1046
- if (isZeroArgMemberCall) {
1047
- var _callee_property, _callee_object, _callee_object_property;
1048
- var callee = call.callee;
1049
- var methodName = !callee.computed && ((_callee_property = callee.property) === null || _callee_property === void 0 ? void 0 : _callee_property.type) === 'Identifier' ? callee.property.name : null;
1050
- if (methodName && REDUNDANT_METHODS.has(methodName) && ((_callee_object = callee.object) === null || _callee_object === void 0 ? void 0 : _callee_object.type) === 'MemberExpression' && ((_callee_object_property = callee.object.property) === null || _callee_object_property === void 0 ? void 0 : _callee_object_property.type) === 'Identifier' && !callee.object.computed) {
1051
- var fieldName = callee.object.property.name;
1052
- var wrapper = isThisMemberAccess(callee.object, fieldName) ? wrappedFields.get(fieldName) : undefined;
1053
- if (wrapper) {
1054
- result = {
1055
- statement: statement,
1056
- fieldName: fieldName,
1057
- method: methodName,
1058
- wrapper: wrapper
1059
- };
1060
- }
1061
- }
1088
+ var methodCall = getRedundantMethodCall(statement.expression);
1089
+ var fieldName = methodCall ? getThisFieldName(methodCall.callee.object) : null;
1090
+ var wrapper = fieldName ? wrappedFields.get(fieldName) : undefined;
1091
+ if (methodCall && fieldName && wrapper) {
1092
+ result = {
1093
+ statement: statement,
1094
+ fieldName: fieldName,
1095
+ method: methodCall.methodName,
1096
+ wrapper: wrapper
1097
+ };
1062
1098
  }
1063
1099
  }
1064
1100
  return result;
@@ -1081,17 +1117,1427 @@
1081
1117
  return fixes;
1082
1118
  }
1083
1119
 
1120
+ /**
1121
+ * Initializer call names that produce a computed Signal whose property must end with `Signal`.
1122
+ */ var COMPUTED_INITIALIZERS = new Set([
1123
+ 'computed'
1124
+ ]);
1125
+ /**
1126
+ * Initializer call names that produce a raw signal-input whose property must NOT end with `Signal`.
1127
+ *
1128
+ * Includes `input.required(...)` (handled below via CallExpression callee inspection) and
1129
+ * `model.required(...)` — those are recognized when the callee's MemberExpression `object` name
1130
+ * is in this set.
1131
+ */ var INPUT_INITIALIZERS$1 = new Set([
1132
+ 'input',
1133
+ 'model'
1134
+ ]);
1135
+ /**
1136
+ * Suffix that distinguishes computed signals from raw input signals.
1137
+ */ var SIGNAL_SUFFIX = 'Signal';
1138
+ /**
1139
+ * ESLint rule that enforces the dbx-components Angular signal naming convention:
1140
+ *
1141
+ * - Class properties initialized with `computed(...)` must end with `Signal`.
1142
+ * - Class properties initialized with `input(...)`, `input.required(...)`, `model(...)`,
1143
+ * or `model.required(...)` must NOT end with `Signal`.
1144
+ *
1145
+ * Fires only on classes decorated with `@Component`, `@Directive`, or `@Pipe` from
1146
+ * `@angular/core`, and only when the relevant initializer identifier is imported from
1147
+ * `@angular/core`.
1148
+ *
1149
+ * Not auto-fixable: renaming a class field also requires updating every reference in the
1150
+ * class body and any associated templates, which is outside the safe scope of an ESLint
1151
+ * autofix.
1152
+ *
1153
+ * @see `dbx__note__angular-conventions` → ANG-C2 Computed Signal Naming.
1154
+ */ var DBX_WEB_REQUIRE_COMPUTED_SIGNAL_SUFFIX_RULE = {
1155
+ meta: {
1156
+ type: 'suggestion',
1157
+ fixable: undefined,
1158
+ docs: {
1159
+ description: 'Require the `Signal` suffix on computed() class properties and disallow it on input()/model() class properties in Angular component classes.',
1160
+ recommended: true
1161
+ },
1162
+ messages: {
1163
+ missingSignalSuffix: "Computed signal '{{property}}' must end with the 'Signal' suffix (e.g. '{{suggested}}') to distinguish it from raw input signals.",
1164
+ signalSuffixOnInput: "Raw input signal '{{property}}' must NOT end with the 'Signal' suffix — reserve that for computed signals."
1165
+ },
1166
+ schema: []
1167
+ },
1168
+ create: function create(context) {
1169
+ var registry = createImportRegistry();
1170
+ var visitClass = function visitClass(classNode) {
1171
+ var _ref;
1172
+ var _classNode_body;
1173
+ var matched = findAngularComponentDecorator(classNode, registry);
1174
+ if (!matched) {
1175
+ return;
1176
+ }
1177
+ var members = (_ref = (_classNode_body = classNode.body) === null || _classNode_body === void 0 ? void 0 : _classNode_body.body) !== null && _ref !== void 0 ? _ref : [];
1178
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
1179
+ try {
1180
+ for(var _iterator = members[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
1181
+ var member = _step.value;
1182
+ if (member.type !== 'PropertyDefinition' || isStaticProperty(member) || isDeclareProperty(member)) {
1183
+ continue;
1184
+ }
1185
+ var propName = getClassMemberName(member);
1186
+ var initializer = member.value;
1187
+ if (!propName || (initializer === null || initializer === void 0 ? void 0 : initializer.type) !== 'CallExpression') {
1188
+ continue;
1189
+ }
1190
+ var initializerKind = classifyInitializer(initializer, registry);
1191
+ if (initializerKind === 'computed') {
1192
+ if (!propName.endsWith(SIGNAL_SUFFIX)) {
1193
+ var _member_key;
1194
+ context.report({
1195
+ node: (_member_key = member.key) !== null && _member_key !== void 0 ? _member_key : member,
1196
+ messageId: 'missingSignalSuffix',
1197
+ data: {
1198
+ property: propName,
1199
+ suggested: "".concat(propName).concat(SIGNAL_SUFFIX)
1200
+ }
1201
+ });
1202
+ }
1203
+ } else if (initializerKind === 'input' && propName.endsWith(SIGNAL_SUFFIX) && propName !== SIGNAL_SUFFIX) {
1204
+ var _member_key1;
1205
+ context.report({
1206
+ node: (_member_key1 = member.key) !== null && _member_key1 !== void 0 ? _member_key1 : member,
1207
+ messageId: 'signalSuffixOnInput',
1208
+ data: {
1209
+ property: propName
1210
+ }
1211
+ });
1212
+ }
1213
+ }
1214
+ } catch (err) {
1215
+ _didIteratorError = true;
1216
+ _iteratorError = err;
1217
+ } finally{
1218
+ try {
1219
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
1220
+ _iterator.return();
1221
+ }
1222
+ } finally{
1223
+ if (_didIteratorError) {
1224
+ throw _iteratorError;
1225
+ }
1226
+ }
1227
+ }
1228
+ };
1229
+ return {
1230
+ ImportDeclaration: function ImportDeclaration(node) {
1231
+ trackImportDeclaration(registry, node);
1232
+ },
1233
+ ClassDeclaration: function ClassDeclaration(classNode) {
1234
+ visitClass(classNode);
1235
+ },
1236
+ ClassExpression: function ClassExpression(classNode) {
1237
+ visitClass(classNode);
1238
+ }
1239
+ };
1240
+ }
1241
+ };
1242
+ /**
1243
+ * Classifies a CallExpression initializer as a computed signal, raw input signal, or neither.
1244
+ *
1245
+ * Recognizes:
1246
+ * - `computed(...)` → `'computed'`
1247
+ * - `input(...)`, `input.required(...)` → `'input'`
1248
+ * - `model(...)`, `model.required(...)` → `'input'`
1249
+ *
1250
+ * Each form requires the root identifier to be imported from `@angular/core`.
1251
+ *
1252
+ * @param callExpression - The CallExpression AST node serving as the property initializer.
1253
+ * @param registry - The file's import registry.
1254
+ * @returns The initializer kind, or `null` when the call is unrelated.
1255
+ */ function classifyInitializer(callExpression, registry) {
1256
+ var _callee_object, _callee_property;
1257
+ var callee = callExpression.callee;
1258
+ var result = null;
1259
+ if ((callee === null || callee === void 0 ? void 0 : callee.type) === 'Identifier') {
1260
+ var name = callee.name;
1261
+ if (COMPUTED_INITIALIZERS.has(name) && isImportedFrom(registry, name, ANGULAR_CORE_MODULE)) {
1262
+ result = 'computed';
1263
+ } else if (INPUT_INITIALIZERS$1.has(name) && isImportedFrom(registry, name, ANGULAR_CORE_MODULE)) {
1264
+ result = 'input';
1265
+ }
1266
+ } else if ((callee === null || callee === void 0 ? void 0 : callee.type) === 'MemberExpression' && callee.computed === false && ((_callee_object = callee.object) === null || _callee_object === void 0 ? void 0 : _callee_object.type) === 'Identifier' && ((_callee_property = callee.property) === null || _callee_property === void 0 ? void 0 : _callee_property.type) === 'Identifier' && callee.property.name === 'required') {
1267
+ var rootName = callee.object.name;
1268
+ if (INPUT_INITIALIZERS$1.has(rootName) && isImportedFrom(registry, rootName, ANGULAR_CORE_MODULE)) {
1269
+ result = 'input';
1270
+ }
1271
+ }
1272
+ return result;
1273
+ }
1274
+
1275
+ /**
1276
+ * Initializer call identifiers that produce an Angular signal input.
1277
+ *
1278
+ * Includes the bare `input(...)` form and the `input.required(...)` member form.
1279
+ * `model()` / `model.required()` are intentionally excluded — two-way bindings are
1280
+ * rare and counting them would inflate the threshold for components that mix them
1281
+ * sparingly. Extending the set is a one-line change.
1282
+ */ var INPUT_INITIALIZERS = new Set([
1283
+ 'input'
1284
+ ]);
1285
+ /**
1286
+ * Default cap on the number of `input(...)` / `input.required(...)` properties a
1287
+ * single Angular component-tier class may declare before the rule fires.
1288
+ */ var DEFAULT_INPUT_THRESHOLD = 3;
1289
+ /**
1290
+ * ESLint rule that flags `@Component` / `@Directive` / `@Pipe` classes which
1291
+ * declare more than `threshold` (default 3) signal-input properties.
1292
+ *
1293
+ * When a component-tier class drifts past the threshold, the convention is to
1294
+ * consolidate the loose inputs into a single config-typed input, e.g.
1295
+ * `config = input<Maybe<DbxFooConfig>>()`. This rule does not enforce a specific
1296
+ * property name or shape — it is purely a count, analogous to the workspace's
1297
+ * `dereekb-util/prefer-config-object` rule for function parameters.
1298
+ *
1299
+ * Only `input(...)` and `input.required(...)` calls whose root identifier is
1300
+ * imported from `@angular/core` are counted. Static and `declare` members are
1301
+ * ignored, as are non-decorated classes and imports from other modules.
1302
+ *
1303
+ * Not auto-fixable: consolidating loose inputs into a config interface is a
1304
+ * design-level refactor that updates the template, the consuming sites, and the
1305
+ * type surface — outside the safe scope of an ESLint autofix.
1306
+ *
1307
+ * @see `dbx__note__angular-conventions` → ANG-C1 Component Config Input.
1308
+ */ var DBX_WEB_REQUIRE_COMPONENT_CONFIG_INPUT_RULE = {
1309
+ meta: {
1310
+ type: 'suggestion',
1311
+ fixable: undefined,
1312
+ docs: {
1313
+ description: 'Disallow more than `threshold` (default 3) signal-input properties on a single @Component/@Directive/@Pipe class; consolidate them into a single config-typed input.',
1314
+ recommended: true
1315
+ },
1316
+ messages: {
1317
+ tooManySignalInputs: "Class '{{className}}' declares {{count}} signal inputs (more than {{threshold}}). Consolidate them into a single config-typed input (e.g. `config = input<Maybe<...Config>>()`). See dbx__note__angular-conventions → ANG-C1."
1318
+ },
1319
+ schema: [
1320
+ {
1321
+ type: 'object',
1322
+ properties: {
1323
+ threshold: {
1324
+ type: 'number',
1325
+ minimum: 0,
1326
+ description: 'Maximum number of signal-input properties allowed before the rule reports. Defaults to 3.'
1327
+ }
1328
+ },
1329
+ additionalProperties: false
1330
+ }
1331
+ ]
1332
+ },
1333
+ create: function create(context) {
1334
+ var _ref;
1335
+ var _context_options;
1336
+ var registry = createImportRegistry();
1337
+ var options = (_ref = (_context_options = context.options) === null || _context_options === void 0 ? void 0 : _context_options[0]) !== null && _ref !== void 0 ? _ref : {};
1338
+ var threshold = typeof options.threshold === 'number' ? options.threshold : DEFAULT_INPUT_THRESHOLD;
1339
+ var visitClass = function visitClass(classNode) {
1340
+ var _ref;
1341
+ var _classNode_body;
1342
+ var matched = findAngularComponentDecorator(classNode, registry);
1343
+ if (!matched) {
1344
+ return;
1345
+ }
1346
+ var members = (_ref = (_classNode_body = classNode.body) === null || _classNode_body === void 0 ? void 0 : _classNode_body.body) !== null && _ref !== void 0 ? _ref : [];
1347
+ var inputCount = 0;
1348
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
1349
+ try {
1350
+ for(var _iterator = members[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
1351
+ var member = _step.value;
1352
+ if (member.type !== 'PropertyDefinition' || isStaticProperty(member) || isDeclareProperty(member)) {
1353
+ continue;
1354
+ }
1355
+ var initializer = member.value;
1356
+ if ((initializer === null || initializer === void 0 ? void 0 : initializer.type) === 'CallExpression' && isAngularInputCall(initializer, registry)) {
1357
+ inputCount += 1;
1358
+ }
1359
+ }
1360
+ } catch (err) {
1361
+ _didIteratorError = true;
1362
+ _iteratorError = err;
1363
+ } finally{
1364
+ try {
1365
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
1366
+ _iterator.return();
1367
+ }
1368
+ } finally{
1369
+ if (_didIteratorError) {
1370
+ throw _iteratorError;
1371
+ }
1372
+ }
1373
+ }
1374
+ if (inputCount > threshold) {
1375
+ var _ref1, _classNode_id;
1376
+ var _classNode_id1;
1377
+ var className = (_ref1 = (_classNode_id1 = classNode.id) === null || _classNode_id1 === void 0 ? void 0 : _classNode_id1.name) !== null && _ref1 !== void 0 ? _ref1 : '<anonymous>';
1378
+ context.report({
1379
+ node: (_classNode_id = classNode.id) !== null && _classNode_id !== void 0 ? _classNode_id : classNode,
1380
+ messageId: 'tooManySignalInputs',
1381
+ data: {
1382
+ className: className,
1383
+ count: String(inputCount),
1384
+ threshold: String(threshold)
1385
+ }
1386
+ });
1387
+ }
1388
+ };
1389
+ return {
1390
+ ImportDeclaration: function ImportDeclaration(node) {
1391
+ trackImportDeclaration(registry, node);
1392
+ },
1393
+ ClassDeclaration: function ClassDeclaration(classNode) {
1394
+ visitClass(classNode);
1395
+ },
1396
+ ClassExpression: function ClassExpression(classNode) {
1397
+ visitClass(classNode);
1398
+ }
1399
+ };
1400
+ }
1401
+ };
1402
+ /**
1403
+ * Returns true when `callExpression` is a call to an Angular signal-input
1404
+ * factory — either `input(...)` (Identifier callee) or `input.required(...)`
1405
+ * (MemberExpression callee whose root identifier is `input`) — and the root
1406
+ * identifier was imported from `@angular/core`.
1407
+ *
1408
+ * @param callExpression - The CallExpression AST node serving as a property initializer.
1409
+ * @param registry - The file's import registry.
1410
+ * @returns True when the call should be counted as a signal input.
1411
+ */ function isAngularInputCall(callExpression, registry) {
1412
+ var _callee_object, _callee_property;
1413
+ var callee = callExpression.callee;
1414
+ var result = false;
1415
+ if ((callee === null || callee === void 0 ? void 0 : callee.type) === 'Identifier') {
1416
+ var name = callee.name;
1417
+ if (INPUT_INITIALIZERS.has(name) && isImportedFrom(registry, name, ANGULAR_CORE_MODULE)) {
1418
+ result = true;
1419
+ }
1420
+ } else if ((callee === null || callee === void 0 ? void 0 : callee.type) === 'MemberExpression' && callee.computed === false && ((_callee_object = callee.object) === null || _callee_object === void 0 ? void 0 : _callee_object.type) === 'Identifier' && ((_callee_property = callee.property) === null || _callee_property === void 0 ? void 0 : _callee_property.type) === 'Identifier' && callee.property.name === 'required') {
1421
+ var rootName = callee.object.name;
1422
+ if (INPUT_INITIALIZERS.has(rootName) && isImportedFrom(registry, rootName, ANGULAR_CORE_MODULE)) {
1423
+ result = true;
1424
+ }
1425
+ }
1426
+ return result;
1427
+ }
1428
+
1429
+ function _array_like_to_array(arr, len) {
1430
+ if (len == null || len > arr.length) len = arr.length;
1431
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
1432
+ return arr2;
1433
+ }
1434
+ function _array_with_holes(arr) {
1435
+ if (Array.isArray(arr)) return arr;
1436
+ }
1437
+ function _array_without_holes(arr) {
1438
+ if (Array.isArray(arr)) return _array_like_to_array(arr);
1439
+ }
1440
+ function _iterable_to_array(iter) {
1441
+ if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
1442
+ }
1443
+ function _iterable_to_array_limit(arr, i) {
1444
+ var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
1445
+ if (_i == null) return;
1446
+ var _arr = [];
1447
+ var _n = true;
1448
+ var _d = false;
1449
+ var _s, _e;
1450
+ try {
1451
+ for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
1452
+ _arr.push(_s.value);
1453
+ if (i && _arr.length === i) break;
1454
+ }
1455
+ } catch (err) {
1456
+ _d = true;
1457
+ _e = err;
1458
+ } finally{
1459
+ try {
1460
+ if (!_n && _i["return"] != null) _i["return"]();
1461
+ } finally{
1462
+ if (_d) throw _e;
1463
+ }
1464
+ }
1465
+ return _arr;
1466
+ }
1467
+ function _non_iterable_rest() {
1468
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
1469
+ }
1470
+ function _non_iterable_spread() {
1471
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
1472
+ }
1473
+ function _sliced_to_array(arr, i) {
1474
+ return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
1475
+ }
1476
+ function _to_consumable_array(arr) {
1477
+ return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
1478
+ }
1479
+ function _type_of(obj) {
1480
+ "@swc/helpers - typeof";
1481
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
1482
+ }
1483
+ function _unsupported_iterable_to_array(o, minLen) {
1484
+ if (!o) return;
1485
+ if (typeof o === "string") return _array_like_to_array(o, minLen);
1486
+ var n = Object.prototype.toString.call(o).slice(8, -1);
1487
+ if (n === "Object" && o.constructor) n = o.constructor.name;
1488
+ if (n === "Map" || n === "Set") return Array.from(n);
1489
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
1490
+ }
1491
+ /**
1492
+ * Module that exposes the `toSignal` factory.
1493
+ */ var ANGULAR_CORE_RXJS_INTEROP_MODULE = '@angular/core/rxjs-interop';
1494
+ /**
1495
+ * Name of the Angular `computed` factory whose callbacks this rule inspects.
1496
+ */ var COMPUTED_INITIALIZER_NAME = 'computed';
1497
+ /**
1498
+ * Bare-identifier signal factories exported from `@angular/core`.
1499
+ *
1500
+ * Each name corresponds to a function that returns a Signal/InputSignal/
1501
+ * WritableSignal/ModelSignal — the kind of getter the rule needs to track
1502
+ * across class properties and module-level `const`s.
1503
+ */ var ANGULAR_CORE_SIGNAL_FACTORIES = new Set([
1504
+ 'signal',
1505
+ 'computed',
1506
+ 'input',
1507
+ 'model',
1508
+ 'linkedSignal'
1509
+ ]);
1510
+ /**
1511
+ * `Identifier.required(...)` member-form factories. Each entry's value is the
1512
+ * root identifier whose `required` property returns another signal factory.
1513
+ *
1514
+ * Example: `input.required<string>()` — `input` is the root identifier and
1515
+ * the result is still an InputSignal.
1516
+ */ var ANGULAR_CORE_REQUIRED_FACTORIES = new Set([
1517
+ 'input',
1518
+ 'model'
1519
+ ]);
1520
+ /**
1521
+ * Bare-identifier signal factories exported from `@angular/core/rxjs-interop`.
1522
+ */ var ANGULAR_CORE_RXJS_INTEROP_SIGNAL_FACTORIES = new Set([
1523
+ 'toSignal'
1524
+ ]);
1525
+ /**
1526
+ * Signal type names exported from `@angular/core`. A property or variable
1527
+ * whose declared type is one of these (and whose root identifier was imported
1528
+ * from `@angular/core`) is treated as a signal getter, even when its
1529
+ * initializer is not a recognized signal factory call (e.g. produced by a
1530
+ * helper or returned from a base class).
1531
+ */ var ANGULAR_CORE_SIGNAL_TYPE_NAMES = new Set([
1532
+ 'Signal',
1533
+ 'WritableSignal',
1534
+ 'InputSignal',
1535
+ 'InputSignalWithTransform',
1536
+ 'ModelSignal'
1537
+ ]);
1538
+ /**
1539
+ * Maximum number of characters from the offending call expression that should
1540
+ * appear in the report message. Long expressions are truncated so the message
1541
+ * stays readable in editor tooltips.
1542
+ */ var CALL_PREVIEW_MAX_LENGTH = 40;
1543
+ /**
1544
+ * ESLint rule that requires every signal read inside a `computed(() => { ... })`
1545
+ * callback to appear in an unconditional, top-level position rather than
1546
+ * inside a branching path (if/else, ternary, short-circuit, switch case,
1547
+ * loop body, catch handler).
1548
+ *
1549
+ * Angular `computed` re-tracks its dependencies on every run, so a signal
1550
+ * read that only happens inside one branch is not registered as a dependency
1551
+ * when the other branch executes. When that signal subsequently changes the
1552
+ * computed does not recompute and the value goes stale. Reading every signal
1553
+ * up front — before any branching — keeps the dependency set stable.
1554
+ *
1555
+ * To avoid false positives on plain methods and utility functions, the rule
1556
+ * only flags calls whose name can be statically traced back to a signal
1557
+ * factory:
1558
+ *
1559
+ * - `this.<name>()` is flagged when `<name>` is a class property initialized
1560
+ * with one of `signal`, `computed`, `input`, `input.required`, `model`,
1561
+ * `model.required`, `linkedSignal` (from `@angular/core`), or `toSignal`
1562
+ * (from `@angular/core/rxjs-interop`).
1563
+ * - `<name>()` (bare identifier) is flagged when `<name>` is a module-level
1564
+ * `const` initialized with one of those factories.
1565
+ *
1566
+ * Everything else — calls with arguments, chained property accesses on
1567
+ * services, calls on local loop variables, calls on globals — is left
1568
+ * alone. Cross-class signal tracking (e.g. `this.someService.someSignal()`)
1569
+ * is intentionally out of scope: it would require type analysis to
1570
+ * distinguish signal getters from plain getter methods, and the rule
1571
+ * prefers a clean report set over partial coverage.
1572
+ *
1573
+ * Only `computed` identifiers imported from `@angular/core` are considered.
1574
+ * Nested function expressions (callbacks passed to `.map` / `.filter` etc.)
1575
+ * are not inspected because Angular does not synchronously track signals
1576
+ * read inside them.
1577
+ *
1578
+ * Auto-fix: for each flagged callback, the fix inserts one
1579
+ * `const <localName> = this.<signalName>();` (or `const <localName> = <signalName>();`
1580
+ * for module-scope captures) at the top of the callback body and replaces
1581
+ * every flagged call with `<localName>`. The local name is the signal name
1582
+ * with the trailing `Signal` suffix removed when present (`xSignal` → `x`).
1583
+ * If that name would shadow an existing local binding in the callback, the
1584
+ * fix is skipped for that signal to avoid generating a syntax error.
1585
+ * Expression-body callbacks (`computed(() => …)`) are converted to block
1586
+ * bodies as part of the fix; the previous expression becomes the `return`
1587
+ * value.
1588
+ */ var DBX_WEB_REQUIRE_TOP_LEVEL_COMPUTED_SIGNALS_RULE = {
1589
+ meta: {
1590
+ type: 'problem',
1591
+ fixable: 'code',
1592
+ docs: {
1593
+ description: 'Require signal reads inside a computed() callback to occur in unconditional top-level statements, not inside if/else, ternary, short-circuit, switch, loop, or catch branches.',
1594
+ recommended: true
1595
+ },
1596
+ messages: {
1597
+ conditionalSignalRead: "Signal read '{{call}}' is inside a conditional execution path of computed(); hoist it to an unconditional top-level read before the branch so the computed tracks it on every run."
1598
+ },
1599
+ schema: []
1600
+ },
1601
+ create: function create(context) {
1602
+ var imports = createImportRegistry();
1603
+ var signals = {
1604
+ classSignalProps: new WeakMap(),
1605
+ moduleSignalNames: new Set()
1606
+ };
1607
+ var visitClass = function visitClass(classNode) {
1608
+ collectClassSignalProperties(classNode, imports, signals);
1609
+ };
1610
+ var inspectComputedCall = function inspectComputedCall(callNode) {
1611
+ var _callNode_arguments;
1612
+ if (!isComputedCall(callNode, imports)) {
1613
+ return;
1614
+ }
1615
+ var callback = (_callNode_arguments = callNode.arguments) === null || _callNode_arguments === void 0 ? void 0 : _callNode_arguments[0];
1616
+ if (!callback || !isFunctionNode(callback) || !callback.body) {
1617
+ return;
1618
+ }
1619
+ var enclosingClass = findEnclosingClass(callNode);
1620
+ var classSignalNames = enclosingClass ? signals.classSignalProps.get(enclosingClass) : null;
1621
+ var violations = [];
1622
+ // The function body itself is the entry point. Conditional state starts
1623
+ // as `false` — top-level statements in the body run unconditionally.
1624
+ walk(callback.body, false, {
1625
+ classSignalNames: classSignalNames,
1626
+ moduleSignalNames: signals.moduleSignalNames,
1627
+ violations: violations
1628
+ });
1629
+ if (violations.length === 0) {
1630
+ return;
1631
+ }
1632
+ reportViolations(callback, violations, context);
1633
+ };
1634
+ return {
1635
+ ImportDeclaration: function ImportDeclaration(node) {
1636
+ trackImportDeclaration(imports, node);
1637
+ },
1638
+ VariableDeclaration: function VariableDeclaration(node) {
1639
+ collectModuleSignalConsts(node, imports, signals);
1640
+ },
1641
+ ClassDeclaration: function ClassDeclaration(classNode) {
1642
+ visitClass(classNode);
1643
+ },
1644
+ ClassExpression: function ClassExpression(classNode) {
1645
+ visitClass(classNode);
1646
+ },
1647
+ CallExpression: function CallExpression(node) {
1648
+ inspectComputedCall(node);
1649
+ }
1650
+ };
1651
+ }
1652
+ };
1653
+ /**
1654
+ * Returns true when `node` is a `computed(...)` call whose `computed`
1655
+ * identifier was imported from `@angular/core`.
1656
+ *
1657
+ * @param node - The CallExpression AST node to test.
1658
+ * @param imports - The file's import registry.
1659
+ * @returns True when the call refers to Angular's `computed`.
1660
+ */ function isComputedCall(node, imports) {
1661
+ var _node_callee;
1662
+ return (node === null || node === void 0 ? void 0 : node.type) === 'CallExpression' && ((_node_callee = node.callee) === null || _node_callee === void 0 ? void 0 : _node_callee.type) === 'Identifier' && node.callee.name === COMPUTED_INITIALIZER_NAME && isImportedFrom(imports, COMPUTED_INITIALIZER_NAME, ANGULAR_CORE_MODULE);
1663
+ }
1664
+ /**
1665
+ * Returns true when `callExpression` is a call to one of the Angular signal
1666
+ * factories whose return value is a Signal/InputSignal/WritableSignal/
1667
+ * ModelSignal. Handles bare-identifier calls (`signal(...)`), required
1668
+ * member-form calls (`input.required(...)`, `model.required(...)`), and
1669
+ * `toSignal(...)` from `@angular/core/rxjs-interop`.
1670
+ *
1671
+ * @param callExpression - The CallExpression AST node serving as an initializer.
1672
+ * @param imports - The file's import registry.
1673
+ * @returns True when the call returns a signal.
1674
+ */ function isSignalFactoryCall(callExpression, imports) {
1675
+ var _callee_object, _callee_property;
1676
+ var callee = callExpression === null || callExpression === void 0 ? void 0 : callExpression.callee;
1677
+ var result = false;
1678
+ if ((callee === null || callee === void 0 ? void 0 : callee.type) === 'Identifier') {
1679
+ var name = callee.name;
1680
+ if (ANGULAR_CORE_SIGNAL_FACTORIES.has(name) && isImportedFrom(imports, name, ANGULAR_CORE_MODULE)) {
1681
+ result = true;
1682
+ } else if (ANGULAR_CORE_RXJS_INTEROP_SIGNAL_FACTORIES.has(name) && isImportedFrom(imports, name, ANGULAR_CORE_RXJS_INTEROP_MODULE)) {
1683
+ result = true;
1684
+ }
1685
+ } else if ((callee === null || callee === void 0 ? void 0 : callee.type) === 'MemberExpression' && callee.computed === false && ((_callee_object = callee.object) === null || _callee_object === void 0 ? void 0 : _callee_object.type) === 'Identifier' && ((_callee_property = callee.property) === null || _callee_property === void 0 ? void 0 : _callee_property.type) === 'Identifier' && callee.property.name === 'required') {
1686
+ var rootName = callee.object.name;
1687
+ if (ANGULAR_CORE_REQUIRED_FACTORIES.has(rootName) && isImportedFrom(imports, rootName, ANGULAR_CORE_MODULE)) {
1688
+ result = true;
1689
+ }
1690
+ }
1691
+ return result;
1692
+ }
1693
+ /**
1694
+ * Returns true when `typeAnnotation` is a TypeScript type annotation node whose
1695
+ * root type name is one of the Angular signal types and resolves to an
1696
+ * `@angular/core` import (e.g. `Signal<number>`, `InputSignal<string>`).
1697
+ *
1698
+ * Accepts both the `TSTypeAnnotation` wrapper and the inner `TSTypeReference`
1699
+ * form. Returns false for any other shape (unions, intersections, generic
1700
+ * wrappers, etc.) — the rule prefers under-coverage to false positives.
1701
+ *
1702
+ * @param typeAnnotation - The TSTypeAnnotation / TSTypeReference AST node.
1703
+ * @param imports - The file's import registry.
1704
+ * @returns True when the type annotation names an Angular signal type.
1705
+ */ function isSignalTypeAnnotation(typeAnnotation, imports) {
1706
+ var _typeNode_typeName;
1707
+ var typeNode = typeAnnotation;
1708
+ if ((typeNode === null || typeNode === void 0 ? void 0 : typeNode.type) === 'TSTypeAnnotation') {
1709
+ typeNode = typeNode.typeAnnotation;
1710
+ }
1711
+ var result = false;
1712
+ if ((typeNode === null || typeNode === void 0 ? void 0 : typeNode.type) === 'TSTypeReference' && ((_typeNode_typeName = typeNode.typeName) === null || _typeNode_typeName === void 0 ? void 0 : _typeNode_typeName.type) === 'Identifier') {
1713
+ var name = typeNode.typeName.name;
1714
+ if (ANGULAR_CORE_SIGNAL_TYPE_NAMES.has(name) && isImportedFrom(imports, name, ANGULAR_CORE_MODULE)) {
1715
+ result = true;
1716
+ }
1717
+ }
1718
+ return result;
1719
+ }
1720
+ /**
1721
+ * Scans the class body for `PropertyDefinition` members whose initializer is
1722
+ * a signal factory call, and stores their names in `signals.classSignalProps`.
1723
+ *
1724
+ * Static and `declare` properties are ignored. Property names that are not
1725
+ * simple identifiers (e.g. computed keys, symbols) are also ignored.
1726
+ *
1727
+ * @param classNode - The ClassDeclaration / ClassExpression AST node.
1728
+ * @param imports - The file's import registry.
1729
+ * @param signals - The signal registry that is mutated with the results.
1730
+ */ function collectClassSignalProperties(classNode, imports, signals) {
1731
+ var _ref;
1732
+ var _classNode_body;
1733
+ var members = (_ref = (_classNode_body = classNode.body) === null || _classNode_body === void 0 ? void 0 : _classNode_body.body) !== null && _ref !== void 0 ? _ref : [];
1734
+ var names = new Set();
1735
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
1736
+ try {
1737
+ for(var _iterator = members[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
1738
+ var member = _step.value;
1739
+ if ((member === null || member === void 0 ? void 0 : member.type) !== 'PropertyDefinition' || member.static === true || member.declare === true || member.computed === true) {
1740
+ continue;
1741
+ }
1742
+ var key = member.key;
1743
+ var initializer = member.value;
1744
+ var propName = null;
1745
+ if ((key === null || key === void 0 ? void 0 : key.type) === 'Identifier') {
1746
+ propName = key.name;
1747
+ } else if ((key === null || key === void 0 ? void 0 : key.type) === 'Literal' && typeof key.value === 'string') {
1748
+ propName = key.value;
1749
+ }
1750
+ if (propName) {
1751
+ var initializerIsSignal = (initializer === null || initializer === void 0 ? void 0 : initializer.type) === 'CallExpression' && isSignalFactoryCall(initializer, imports);
1752
+ var typeIsSignal = member.typeAnnotation && isSignalTypeAnnotation(member.typeAnnotation, imports);
1753
+ if (initializerIsSignal || typeIsSignal) {
1754
+ names.add(propName);
1755
+ }
1756
+ }
1757
+ }
1758
+ } catch (err) {
1759
+ _didIteratorError = true;
1760
+ _iteratorError = err;
1761
+ } finally{
1762
+ try {
1763
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
1764
+ _iterator.return();
1765
+ }
1766
+ } finally{
1767
+ if (_didIteratorError) {
1768
+ throw _iteratorError;
1769
+ }
1770
+ }
1771
+ }
1772
+ signals.classSignalProps.set(classNode, names);
1773
+ }
1774
+ /**
1775
+ * Scans a `VariableDeclaration` node that lives directly inside the program
1776
+ * body for `const` declarators whose initializer is a signal factory call,
1777
+ * adding their names to `signals.moduleSignalNames`.
1778
+ *
1779
+ * Non-`const` declarations, declarations nested inside functions or blocks,
1780
+ * and declarations whose initializer is not a signal factory are skipped.
1781
+ *
1782
+ * @param node - The VariableDeclaration AST node.
1783
+ * @param imports - The file's import registry.
1784
+ * @param signals - The signal registry that is mutated with the results.
1785
+ */ function collectModuleSignalConsts(node, imports, signals) {
1786
+ var _node_declarations;
1787
+ var _node_parent;
1788
+ if ((node === null || node === void 0 ? void 0 : node.kind) !== 'const' || ((_node_parent = node.parent) === null || _node_parent === void 0 ? void 0 : _node_parent.type) !== 'Program') {
1789
+ return;
1790
+ }
1791
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
1792
+ try {
1793
+ for(var _iterator = ((_node_declarations = node.declarations) !== null && _node_declarations !== void 0 ? _node_declarations : [])[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
1794
+ var declarator = _step.value;
1795
+ var id = declarator === null || declarator === void 0 ? void 0 : declarator.id;
1796
+ var init = declarator === null || declarator === void 0 ? void 0 : declarator.init;
1797
+ if ((id === null || id === void 0 ? void 0 : id.type) === 'Identifier') {
1798
+ var initIsSignal = (init === null || init === void 0 ? void 0 : init.type) === 'CallExpression' && isSignalFactoryCall(init, imports);
1799
+ var typeIsSignal = id.typeAnnotation && isSignalTypeAnnotation(id.typeAnnotation, imports);
1800
+ if (initIsSignal || typeIsSignal) {
1801
+ signals.moduleSignalNames.add(id.name);
1802
+ }
1803
+ }
1804
+ }
1805
+ } catch (err) {
1806
+ _didIteratorError = true;
1807
+ _iteratorError = err;
1808
+ } finally{
1809
+ try {
1810
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
1811
+ _iterator.return();
1812
+ }
1813
+ } finally{
1814
+ if (_didIteratorError) {
1815
+ throw _iteratorError;
1816
+ }
1817
+ }
1818
+ }
1819
+ }
1820
+ /**
1821
+ * Walks up from `node` via `parent` references to find the nearest enclosing
1822
+ * `ClassDeclaration` or `ClassExpression`, or null if there isn't one.
1823
+ *
1824
+ * @param node - The starting AST node.
1825
+ * @returns The enclosing class node, or null.
1826
+ */ function findEnclosingClass(node) {
1827
+ var current = node.parent;
1828
+ var result = null;
1829
+ while(current && !result){
1830
+ if (current.type === 'ClassDeclaration' || current.type === 'ClassExpression') {
1831
+ result = current;
1832
+ } else {
1833
+ current = current.parent;
1834
+ }
1835
+ }
1836
+ return result;
1837
+ }
1838
+ /**
1839
+ * Returns true when `node` is any function-like AST node (arrow, expression,
1840
+ * declaration). Used both to find the computed callback and to stop the walk
1841
+ * when it would otherwise descend into a nested function body.
1842
+ *
1843
+ * @param node - The AST node to test.
1844
+ * @returns True when `node` is a function-like node.
1845
+ */ function isFunctionNode(node) {
1846
+ return (node === null || node === void 0 ? void 0 : node.type) === 'ArrowFunctionExpression' || (node === null || node === void 0 ? void 0 : node.type) === 'FunctionExpression' || (node === null || node === void 0 ? void 0 : node.type) === 'FunctionDeclaration';
1847
+ }
1848
+ /**
1849
+ * Recursively walks the body of a `computed(...)` callback. For each
1850
+ * zero-argument `CallExpression` that can be statically traced to a known
1851
+ * signal getter, records a violation when `conditional` is true. Stops at
1852
+ * any nested function boundary.
1853
+ *
1854
+ * @param node - The current AST node being inspected.
1855
+ * @param conditional - True when `node` is inside a conditional execution path.
1856
+ * @param state - Shared walk state (signal registries + violation accumulator).
1857
+ */ function walk(node, conditional, state) {
1858
+ if (!node || typeof node.type !== 'string') {
1859
+ return;
1860
+ }
1861
+ // Stop at nested functions. The caller passes the computed callback's body
1862
+ // (not the function node itself) as the entry point, so any function node
1863
+ // we encounter while walking children is a nested function whose interior
1864
+ // is not synchronously tracked by Angular.
1865
+ if (isFunctionNode(node)) {
1866
+ return;
1867
+ }
1868
+ if (conditional && node.type === 'CallExpression' && Array.isArray(node.arguments) && node.arguments.length === 0) {
1869
+ var match = classifySignalRead(node.callee, state);
1870
+ if (match) {
1871
+ state.violations.push({
1872
+ node: node,
1873
+ signalName: match.name,
1874
+ source: match.source
1875
+ });
1876
+ }
1877
+ }
1878
+ walkChildren(node, conditional, state);
1879
+ }
1880
+ /**
1881
+ * Returns the signal-name match for `callee` when it reads a known signal:
1882
+ * either a `this.<name>` access where `<name>` is a class signal property,
1883
+ * or a bare `<name>` identifier where `<name>` is a module-level signal
1884
+ * `const`. Returns null otherwise.
1885
+ *
1886
+ * Cross-class accesses (`this.someService.someSignal()`), method calls on
1887
+ * locals (`icons.reverse()`), and untracked identifiers (`Math.random()`)
1888
+ * return null: the rule prefers silent under-coverage to false positives.
1889
+ *
1890
+ * @param callee - The CallExpression's callee AST node.
1891
+ * @param state - The shared walk state (used to read the signal registries).
1892
+ * @returns Match details (signal name + source), or null when not a known signal read.
1893
+ */ function classifySignalRead(callee, state) {
1894
+ var _callee_object, _callee_property;
1895
+ var result = null;
1896
+ if ((callee === null || callee === void 0 ? void 0 : callee.type) === 'Identifier') {
1897
+ if (state.moduleSignalNames.has(callee.name)) {
1898
+ result = {
1899
+ name: callee.name,
1900
+ source: 'module'
1901
+ };
1902
+ }
1903
+ } else if ((callee === null || callee === void 0 ? void 0 : callee.type) === 'MemberExpression' && callee.computed === false && ((_callee_object = callee.object) === null || _callee_object === void 0 ? void 0 : _callee_object.type) === 'ThisExpression' && ((_callee_property = callee.property) === null || _callee_property === void 0 ? void 0 : _callee_property.type) === 'Identifier') {
1904
+ var _state_classSignalNames;
1905
+ var propName = callee.property.name;
1906
+ if (((_state_classSignalNames = state.classSignalNames) === null || _state_classSignalNames === void 0 ? void 0 : _state_classSignalNames.has(propName)) === true) {
1907
+ result = {
1908
+ name: propName,
1909
+ source: 'this'
1910
+ };
1911
+ }
1912
+ }
1913
+ return result;
1914
+ }
1915
+ /**
1916
+ * Recurses into the appropriate children of `node`, switching `conditional`
1917
+ * to true when descending into a branch that may not execute on every run.
1918
+ *
1919
+ * @param node - The current AST node whose children are walked.
1920
+ * @param conditional - True when `node` itself is in a conditional path.
1921
+ * @param state - Shared walk state.
1922
+ */ function walkChildren(node, conditional, state) {
1923
+ switch(node.type){
1924
+ case 'IfStatement':
1925
+ walk(node.test, conditional, state);
1926
+ walk(node.consequent, true, state);
1927
+ walk(node.alternate, true, state);
1928
+ break;
1929
+ case 'ConditionalExpression':
1930
+ walk(node.test, conditional, state);
1931
+ walk(node.consequent, true, state);
1932
+ walk(node.alternate, true, state);
1933
+ break;
1934
+ case 'LogicalExpression':
1935
+ // `&&`, `||`, and `??` all short-circuit: the right operand only runs
1936
+ // when the left operand triggers the corresponding short-circuit miss.
1937
+ walk(node.left, conditional, state);
1938
+ walk(node.right, true, state);
1939
+ break;
1940
+ case 'SwitchStatement':
1941
+ var _node_cases;
1942
+ walk(node.discriminant, conditional, state);
1943
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
1944
+ try {
1945
+ for(var _iterator = ((_node_cases = node.cases) !== null && _node_cases !== void 0 ? _node_cases : [])[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
1946
+ var switchCase = _step.value;
1947
+ var _switchCase_consequent;
1948
+ walk(switchCase.test, conditional, state);
1949
+ var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
1950
+ try {
1951
+ for(var _iterator1 = ((_switchCase_consequent = switchCase.consequent) !== null && _switchCase_consequent !== void 0 ? _switchCase_consequent : [])[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
1952
+ var statement = _step1.value;
1953
+ walk(statement, true, state);
1954
+ }
1955
+ } catch (err) {
1956
+ _didIteratorError1 = true;
1957
+ _iteratorError1 = err;
1958
+ } finally{
1959
+ try {
1960
+ if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
1961
+ _iterator1.return();
1962
+ }
1963
+ } finally{
1964
+ if (_didIteratorError1) {
1965
+ throw _iteratorError1;
1966
+ }
1967
+ }
1968
+ }
1969
+ }
1970
+ } catch (err) {
1971
+ _didIteratorError = true;
1972
+ _iteratorError = err;
1973
+ } finally{
1974
+ try {
1975
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
1976
+ _iterator.return();
1977
+ }
1978
+ } finally{
1979
+ if (_didIteratorError) {
1980
+ throw _iteratorError;
1981
+ }
1982
+ }
1983
+ }
1984
+ break;
1985
+ case 'ForStatement':
1986
+ walk(node.init, conditional, state);
1987
+ walk(node.test, conditional, state);
1988
+ walk(node.update, true, state);
1989
+ walk(node.body, true, state);
1990
+ break;
1991
+ case 'ForInStatement':
1992
+ case 'ForOfStatement':
1993
+ walk(node.left, conditional, state);
1994
+ walk(node.right, conditional, state);
1995
+ walk(node.body, true, state);
1996
+ break;
1997
+ case 'WhileStatement':
1998
+ case 'DoWhileStatement':
1999
+ walk(node.test, conditional, state);
2000
+ walk(node.body, true, state);
2001
+ break;
2002
+ case 'TryStatement':
2003
+ walk(node.block, conditional, state);
2004
+ walk(node.handler, true, state);
2005
+ walk(node.finalizer, conditional, state);
2006
+ break;
2007
+ default:
2008
+ walkGenericChildren(node, conditional, state);
2009
+ }
2010
+ }
2011
+ /**
2012
+ * Generic AST-walking fallback used for node types that do not introduce
2013
+ * conditional execution. Recurses into every object-valued or array-valued
2014
+ * property whose value looks like an AST node.
2015
+ *
2016
+ * @param node - The current AST node.
2017
+ * @param conditional - True when `node` itself is in a conditional path.
2018
+ * @param state - Shared walk state.
2019
+ */ function walkGenericChildren(node, conditional, state) {
2020
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
2021
+ try {
2022
+ for(var _iterator = Object.keys(node)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
2023
+ var key = _step.value;
2024
+ if (key === 'parent' || key === 'loc' || key === 'range' || key === 'start' || key === 'end') {
2025
+ continue;
2026
+ }
2027
+ var child = node[key];
2028
+ if (Array.isArray(child)) {
2029
+ var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
2030
+ try {
2031
+ for(var _iterator1 = child[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
2032
+ var entry = _step1.value;
2033
+ walk(entry, conditional, state);
2034
+ }
2035
+ } catch (err) {
2036
+ _didIteratorError1 = true;
2037
+ _iteratorError1 = err;
2038
+ } finally{
2039
+ try {
2040
+ if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
2041
+ _iterator1.return();
2042
+ }
2043
+ } finally{
2044
+ if (_didIteratorError1) {
2045
+ throw _iteratorError1;
2046
+ }
2047
+ }
2048
+ }
2049
+ } else if (child && (typeof child === "undefined" ? "undefined" : _type_of(child)) === 'object' && typeof child.type === 'string') {
2050
+ walk(child, conditional, state);
2051
+ }
2052
+ }
2053
+ } catch (err) {
2054
+ _didIteratorError = true;
2055
+ _iteratorError = err;
2056
+ } finally{
2057
+ try {
2058
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
2059
+ _iterator.return();
2060
+ }
2061
+ } finally{
2062
+ if (_didIteratorError) {
2063
+ throw _iteratorError;
2064
+ }
2065
+ }
2066
+ }
2067
+ }
2068
+ /**
2069
+ * Emits one diagnostic per accumulated violation. The first emitted report
2070
+ * carries a combined autofix that hoists each flagged signal read to the top
2071
+ * of the callback body and replaces every flagged call with the hoisted
2072
+ * local. Subsequent reports do not carry a fix because `--fix` will already
2073
+ * have rewritten them via the first report's fix.
2074
+ *
2075
+ * @param callback - The Function/ArrowFunction AST node passed to `computed(...)`.
2076
+ * @param violations - Conditional signal reads collected during the walk.
2077
+ * @param context - The ESLint rule context.
2078
+ */ function reportViolations(callback, violations, context) {
2079
+ var _context_sourceCode;
2080
+ var _context_getSourceCode;
2081
+ var sourceCode = (_context_sourceCode = context.sourceCode) !== null && _context_sourceCode !== void 0 ? _context_sourceCode : (_context_getSourceCode = context.getSourceCode) === null || _context_getSourceCode === void 0 ? void 0 : _context_getSourceCode.call(context);
2082
+ var plan = buildFixPlan(callback, violations);
2083
+ violations.forEach(function(violation, index) {
2084
+ context.report({
2085
+ node: violation.node,
2086
+ messageId: 'conditionalSignalRead',
2087
+ data: {
2088
+ call: getCallPreview(violation.node, context)
2089
+ },
2090
+ fix: index === 0 && plan ? function(fixer) {
2091
+ return applyFixPlan(fixer, plan, sourceCode);
2092
+ } : undefined
2093
+ });
2094
+ });
2095
+ }
2096
+ /**
2097
+ * Plans the hoisting transformation for a callback whose violations have
2098
+ * been collected. Returns null when no hoist can be planned (e.g. every
2099
+ * candidate name would shadow an existing binding).
2100
+ *
2101
+ * @param callback - The Function/ArrowFunction AST node passed to `computed(...)`.
2102
+ * @param violations - Conditional signal reads collected during the walk.
2103
+ * @param sourceCode - The ESLint sourceCode service.
2104
+ * @returns A fix plan, or null when no hoist is possible.
2105
+ */ function buildFixPlan(callback, violations, sourceCode) {
2106
+ var body = callback === null || callback === void 0 ? void 0 : callback.body;
2107
+ var result = null;
2108
+ if (body) {
2109
+ var existingLocals = collectExistingLocalNames(body);
2110
+ var localNames = new Map();
2111
+ var usedNames = new Set(existingLocals);
2112
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
2113
+ try {
2114
+ for(var _iterator = violations[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
2115
+ var violation = _step.value;
2116
+ if (localNames.has(violation.signalName)) {
2117
+ continue;
2118
+ }
2119
+ var preferred = computeLocalName(violation.signalName);
2120
+ if (usedNames.has(preferred)) {
2121
+ continue;
2122
+ }
2123
+ usedNames.add(preferred);
2124
+ localNames.set(violation.signalName, {
2125
+ name: preferred,
2126
+ source: violation.source
2127
+ });
2128
+ }
2129
+ } catch (err) {
2130
+ _didIteratorError = true;
2131
+ _iteratorError = err;
2132
+ } finally{
2133
+ try {
2134
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
2135
+ _iterator.return();
2136
+ }
2137
+ } finally{
2138
+ if (_didIteratorError) {
2139
+ throw _iteratorError;
2140
+ }
2141
+ }
2142
+ }
2143
+ if (localNames.size > 0) {
2144
+ var replacements = violations.filter(function(violation) {
2145
+ return localNames.has(violation.signalName);
2146
+ });
2147
+ if (replacements.length > 0) {
2148
+ result = {
2149
+ callback: callback,
2150
+ body: body,
2151
+ localNames: localNames,
2152
+ replacements: replacements
2153
+ };
2154
+ }
2155
+ }
2156
+ }
2157
+ return result;
2158
+ }
2159
+ /**
2160
+ * Computes the local variable name for a signal property name. Strips the
2161
+ * trailing `Signal` suffix when present (`xSignal` → `x`, `_configSignal` →
2162
+ * `_config`); otherwise returns the original name unchanged.
2163
+ *
2164
+ * A name that is purely `'Signal'` is returned as-is rather than stripped
2165
+ * to an empty string.
2166
+ *
2167
+ * @param signalName - The signal property name to derive the local from.
2168
+ * @returns The local variable name.
2169
+ */ function computeLocalName(signalName) {
2170
+ var suffix = 'Signal';
2171
+ var result = signalName;
2172
+ if (signalName.length > suffix.length && signalName.endsWith(suffix)) {
2173
+ result = signalName.slice(0, signalName.length - suffix.length);
2174
+ }
2175
+ return result;
2176
+ }
2177
+ /**
2178
+ * Collects all identifier names introduced by `VariableDeclarator`s within
2179
+ * the function body's top-level statements (the only locations a hoist
2180
+ * could possibly shadow). Nested function bodies and inner block scopes are
2181
+ * not inspected — shadowing those is harmless.
2182
+ *
2183
+ * Also accepts expression-body callbacks: an expression body cannot declare
2184
+ * locals, so it contributes no names.
2185
+ *
2186
+ * @param body - The callback's BlockStatement or expression AST node.
2187
+ * @returns Identifier names already declared in the body's scope.
2188
+ */ function collectExistingLocalNames(body) {
2189
+ var names = new Set();
2190
+ if ((body === null || body === void 0 ? void 0 : body.type) === 'BlockStatement') {
2191
+ var _body_body;
2192
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
2193
+ try {
2194
+ for(var _iterator = ((_body_body = body.body) !== null && _body_body !== void 0 ? _body_body : [])[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
2195
+ var statement = _step.value;
2196
+ if ((statement === null || statement === void 0 ? void 0 : statement.type) === 'VariableDeclaration') {
2197
+ var _statement_declarations;
2198
+ var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
2199
+ try {
2200
+ for(var _iterator1 = ((_statement_declarations = statement.declarations) !== null && _statement_declarations !== void 0 ? _statement_declarations : [])[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
2201
+ var declarator = _step1.value;
2202
+ collectPatternNames(declarator === null || declarator === void 0 ? void 0 : declarator.id, names);
2203
+ }
2204
+ } catch (err) {
2205
+ _didIteratorError1 = true;
2206
+ _iteratorError1 = err;
2207
+ } finally{
2208
+ try {
2209
+ if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
2210
+ _iterator1.return();
2211
+ }
2212
+ } finally{
2213
+ if (_didIteratorError1) {
2214
+ throw _iteratorError1;
2215
+ }
2216
+ }
2217
+ }
2218
+ }
2219
+ }
2220
+ } catch (err) {
2221
+ _didIteratorError = true;
2222
+ _iteratorError = err;
2223
+ } finally{
2224
+ try {
2225
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
2226
+ _iterator.return();
2227
+ }
2228
+ } finally{
2229
+ if (_didIteratorError) {
2230
+ throw _iteratorError;
2231
+ }
2232
+ }
2233
+ }
2234
+ }
2235
+ return names;
2236
+ }
2237
+ /**
2238
+ * Recursively collects identifier names introduced by a destructuring
2239
+ * pattern (or a plain Identifier). Handles ObjectPattern, ArrayPattern,
2240
+ * RestElement, and AssignmentPattern; ignores other shapes.
2241
+ *
2242
+ * @param pattern - The Identifier or destructuring pattern AST node.
2243
+ * @param names - The set that is mutated with discovered names.
2244
+ */ function collectPatternNames(pattern, names) {
2245
+ if (!pattern || typeof pattern.type !== 'string') {
2246
+ return;
2247
+ }
2248
+ switch(pattern.type){
2249
+ case 'Identifier':
2250
+ names.add(pattern.name);
2251
+ break;
2252
+ case 'ObjectPattern':
2253
+ var _pattern_properties;
2254
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
2255
+ try {
2256
+ for(var _iterator = ((_pattern_properties = pattern.properties) !== null && _pattern_properties !== void 0 ? _pattern_properties : [])[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
2257
+ var property = _step.value;
2258
+ if ((property === null || property === void 0 ? void 0 : property.type) === 'Property') {
2259
+ collectPatternNames(property.value, names);
2260
+ } else if ((property === null || property === void 0 ? void 0 : property.type) === 'RestElement') {
2261
+ collectPatternNames(property.argument, names);
2262
+ }
2263
+ }
2264
+ } catch (err) {
2265
+ _didIteratorError = true;
2266
+ _iteratorError = err;
2267
+ } finally{
2268
+ try {
2269
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
2270
+ _iterator.return();
2271
+ }
2272
+ } finally{
2273
+ if (_didIteratorError) {
2274
+ throw _iteratorError;
2275
+ }
2276
+ }
2277
+ }
2278
+ break;
2279
+ case 'ArrayPattern':
2280
+ var _pattern_elements;
2281
+ var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
2282
+ try {
2283
+ for(var _iterator1 = ((_pattern_elements = pattern.elements) !== null && _pattern_elements !== void 0 ? _pattern_elements : [])[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
2284
+ var element = _step1.value;
2285
+ collectPatternNames(element, names);
2286
+ }
2287
+ } catch (err) {
2288
+ _didIteratorError1 = true;
2289
+ _iteratorError1 = err;
2290
+ } finally{
2291
+ try {
2292
+ if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
2293
+ _iterator1.return();
2294
+ }
2295
+ } finally{
2296
+ if (_didIteratorError1) {
2297
+ throw _iteratorError1;
2298
+ }
2299
+ }
2300
+ }
2301
+ break;
2302
+ case 'RestElement':
2303
+ collectPatternNames(pattern.argument, names);
2304
+ break;
2305
+ case 'AssignmentPattern':
2306
+ collectPatternNames(pattern.left, names);
2307
+ break;
2308
+ }
2309
+ }
2310
+ /**
2311
+ * Applies a fix plan, returning the list of fixer operations that hoist each
2312
+ * planned signal read and replace its flagged call sites.
2313
+ *
2314
+ * For BlockStatement bodies the hoists are inserted before the first
2315
+ * statement (or after the opening brace when the body is empty). For
2316
+ * expression-body callbacks the entire body expression is replaced with a
2317
+ * BlockStatement that contains the hoists followed by a `return <expr>;`.
2318
+ *
2319
+ * @param fixer - The ESLint RuleFixer.
2320
+ * @param plan - The fix plan to apply.
2321
+ * @param sourceCode - The ESLint sourceCode service.
2322
+ * @returns The list of fixer operations.
2323
+ */ function applyFixPlan(fixer, plan, sourceCode) {
2324
+ var fixes = [];
2325
+ var hoistLines = [];
2326
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
2327
+ try {
2328
+ for(var _iterator = plan.localNames[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
2329
+ var _step_value = _sliced_to_array(_step.value, 2), signalName = _step_value[0], local = _step_value[1];
2330
+ var rhs = local.source === 'this' ? "this.".concat(signalName, "()") : "".concat(signalName, "()");
2331
+ hoistLines.push("const ".concat(local.name, " = ").concat(rhs, ";"));
2332
+ }
2333
+ } catch (err) {
2334
+ _didIteratorError = true;
2335
+ _iteratorError = err;
2336
+ } finally{
2337
+ try {
2338
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
2339
+ _iterator.return();
2340
+ }
2341
+ } finally{
2342
+ if (_didIteratorError) {
2343
+ throw _iteratorError;
2344
+ }
2345
+ }
2346
+ }
2347
+ if (plan.body.type === 'BlockStatement') {
2348
+ var _plan_body_body;
2349
+ var indent = getBlockIndent(plan.body, sourceCode);
2350
+ var firstStatement = (_plan_body_body = plan.body.body) === null || _plan_body_body === void 0 ? void 0 : _plan_body_body[0];
2351
+ if (firstStatement) {
2352
+ // `insertTextBefore(firstStatement, …)` inserts at the position of the
2353
+ // first non-whitespace character of the statement; the existing line
2354
+ // already carries the leading indent up to that position. So the first
2355
+ // hoist line is emitted WITHOUT a leading indent (it reuses the
2356
+ // existing one), every subsequent line carries the full indent, and
2357
+ // the trailing `\n${indent}` re-establishes the indent for the
2358
+ // original statement that follows.
2359
+ var hoistText = hoistLines.map(function(line, index) {
2360
+ return index === 0 ? line : "".concat(indent).concat(line);
2361
+ }).join('\n');
2362
+ fixes.push(fixer.insertTextBefore(firstStatement, "".concat(hoistText, "\n").concat(indent)));
2363
+ } else {
2364
+ var openBrace = sourceCode.getFirstToken(plan.body);
2365
+ if (openBrace) {
2366
+ var hoistText1 = hoistLines.map(function(line) {
2367
+ return "".concat(indent).concat(line);
2368
+ }).join('\n');
2369
+ fixes.push(fixer.insertTextAfter(openBrace, "\n".concat(hoistText1, "\n")));
2370
+ }
2371
+ }
2372
+ var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
2373
+ try {
2374
+ for(var _iterator1 = plan.replacements[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
2375
+ var replacement = _step1.value;
2376
+ var local1 = plan.localNames.get(replacement.signalName);
2377
+ if (local1) {
2378
+ fixes.push(fixer.replaceText(replacement.node, local1.name));
2379
+ }
2380
+ }
2381
+ } catch (err) {
2382
+ _didIteratorError1 = true;
2383
+ _iteratorError1 = err;
2384
+ } finally{
2385
+ try {
2386
+ if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
2387
+ _iterator1.return();
2388
+ }
2389
+ } finally{
2390
+ if (_didIteratorError1) {
2391
+ throw _iteratorError1;
2392
+ }
2393
+ }
2394
+ }
2395
+ } else {
2396
+ // Expression body: rewrite `(arg) => <expr>` to
2397
+ // `(arg) => { …hoists; return <expr-with-substitutions>; }`. The body
2398
+ // replacement covers every flagged call site, so per-call replacements
2399
+ // are baked into the substituted expression text rather than emitted as
2400
+ // separate fixer operations (which would overlap the body replacement).
2401
+ var baseIndent = getStatementIndent(plan.callback, sourceCode);
2402
+ var innerIndent = "".concat(baseIndent, " ");
2403
+ var hoistText2 = hoistLines.map(function(line) {
2404
+ return "".concat(innerIndent).concat(line);
2405
+ }).join('\n');
2406
+ var substitutedExpr = substituteInExpression(plan, sourceCode);
2407
+ fixes.push(fixer.replaceText(plan.body, "{\n".concat(hoistText2, "\n").concat(innerIndent, "return ").concat(substitutedExpr, ";\n").concat(baseIndent, "}")));
2408
+ }
2409
+ return fixes;
2410
+ }
2411
+ /**
2412
+ * Returns the leading-whitespace indent of the line that contains the start
2413
+ * of `node`. Used to align the inserted block body with the surrounding
2414
+ * statement (e.g. the `readonly fooSignal = computed(() => …)` line).
2415
+ *
2416
+ * Falls back to an empty string when the node has no detectable line indent.
2417
+ *
2418
+ * @param node - The AST node whose enclosing line indent is wanted.
2419
+ * @param sourceCode - The ESLint sourceCode service.
2420
+ * @returns The indent string (spaces / tabs), or `''` when none can be derived.
2421
+ */ function getStatementIndent(node, sourceCode) {
2422
+ var _ref, _sourceCode_text;
2423
+ var _sourceCode_getText;
2424
+ var source = (_ref = (_sourceCode_text = sourceCode.text) !== null && _sourceCode_text !== void 0 ? _sourceCode_text : (_sourceCode_getText = sourceCode.getText) === null || _sourceCode_getText === void 0 ? void 0 : _sourceCode_getText.call(sourceCode)) !== null && _ref !== void 0 ? _ref : '';
2425
+ var start = node.range[0];
2426
+ var lineStart = start;
2427
+ var result = '';
2428
+ while(lineStart > 0 && source[lineStart - 1] !== '\n'){
2429
+ lineStart -= 1;
2430
+ }
2431
+ var slice = source.slice(lineStart, start);
2432
+ var match = /^[ \t]*/.exec(slice);
2433
+ if (match) {
2434
+ result = match[0];
2435
+ }
2436
+ return result;
2437
+ }
2438
+ /**
2439
+ * Builds the substituted text for an expression-body callback by walking the
2440
+ * raw source text and swapping each flagged call's source range for its
2441
+ * hoisted local name. Replacements are applied right-to-left so earlier
2442
+ * ranges stay valid as the string is mutated.
2443
+ *
2444
+ * @param plan - The fix plan whose body is an expression.
2445
+ * @param sourceCode - The ESLint sourceCode service.
2446
+ * @returns The expression text with every flagged call site replaced.
2447
+ */ function substituteInExpression(plan, sourceCode) {
2448
+ var bodyStart = plan.body.range[0];
2449
+ var ordered = _to_consumable_array(plan.replacements).sort(function(a, b) {
2450
+ return b.node.range[0] - a.node.range[0];
2451
+ });
2452
+ var result = sourceCode.getText(plan.body);
2453
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
2454
+ try {
2455
+ for(var _iterator = ordered[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
2456
+ var replacement = _step.value;
2457
+ var local = plan.localNames.get(replacement.signalName);
2458
+ if (local) {
2459
+ var start = replacement.node.range[0] - bodyStart;
2460
+ var end = replacement.node.range[1] - bodyStart;
2461
+ result = result.slice(0, start) + local.name + result.slice(end);
2462
+ }
2463
+ }
2464
+ } catch (err) {
2465
+ _didIteratorError = true;
2466
+ _iteratorError = err;
2467
+ } finally{
2468
+ try {
2469
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
2470
+ _iterator.return();
2471
+ }
2472
+ } finally{
2473
+ if (_didIteratorError) {
2474
+ throw _iteratorError;
2475
+ }
2476
+ }
2477
+ }
2478
+ return result;
2479
+ }
2480
+ /**
2481
+ * Returns the indent string (whitespace before the first statement) for a
2482
+ * BlockStatement, falling back to a sensible default (`' '`) when the
2483
+ * block contains no statements or no leading whitespace can be located.
2484
+ *
2485
+ * @param block - The BlockStatement AST node.
2486
+ * @param sourceCode - The ESLint sourceCode service.
2487
+ * @returns The indent string to use for inserted hoist lines.
2488
+ */ function getBlockIndent(block, sourceCode) {
2489
+ var _block_body;
2490
+ var firstStatement = (_block_body = block.body) === null || _block_body === void 0 ? void 0 : _block_body[0];
2491
+ var result = ' ';
2492
+ if (firstStatement) {
2493
+ var _ref, _sourceCode_text;
2494
+ var _sourceCode_getText;
2495
+ var source = (_ref = (_sourceCode_text = sourceCode.text) !== null && _sourceCode_text !== void 0 ? _sourceCode_text : (_sourceCode_getText = sourceCode.getText) === null || _sourceCode_getText === void 0 ? void 0 : _sourceCode_getText.call(sourceCode)) !== null && _ref !== void 0 ? _ref : '';
2496
+ var textBefore = source.slice(block.range[0], firstStatement.range[0]);
2497
+ var match = /(?:^|\n)([ \t]*)$/.exec(textBefore);
2498
+ if (match) {
2499
+ result = match[1];
2500
+ }
2501
+ }
2502
+ return result;
2503
+ }
2504
+ /**
2505
+ * Returns a short, human-readable textual preview of the call expression,
2506
+ * suitable for inclusion in the diagnostic message. Falls back to `'signal'`
2507
+ * when the source code is unavailable.
2508
+ *
2509
+ * @param node - The CallExpression AST node.
2510
+ * @param context - The ESLint rule context (used to access `sourceCode`).
2511
+ * @returns A truncated textual preview of the call.
2512
+ */ function getCallPreview(node, context) {
2513
+ var _context_sourceCode;
2514
+ var _context_getSourceCode;
2515
+ var sourceCode = (_context_sourceCode = context.sourceCode) !== null && _context_sourceCode !== void 0 ? _context_sourceCode : (_context_getSourceCode = context.getSourceCode) === null || _context_getSourceCode === void 0 ? void 0 : _context_getSourceCode.call(context);
2516
+ var preview = 'signal';
2517
+ if (sourceCode && node.callee) {
2518
+ var calleeText = sourceCode.getText(node.callee);
2519
+ preview = "".concat(calleeText, "()");
2520
+ if (preview.length > CALL_PREVIEW_MAX_LENGTH) {
2521
+ preview = "".concat(preview.slice(0, CALL_PREVIEW_MAX_LENGTH - 3), "...");
2522
+ }
2523
+ }
2524
+ return preview;
2525
+ }
2526
+
1084
2527
  /**
1085
2528
  * ESLint plugin for dbx-web rules.
1086
2529
  *
1087
2530
  * Register as a plugin in your flat ESLint config, then enable individual rules
1088
2531
  * under the chosen plugin prefix (e.g. 'dereekb-dbx-web/require-clean-subscription').
1089
- */ var dbxWebEslintPlugin = {
2532
+ */ var DBX_WEB_ESLINT_PLUGIN = {
1090
2533
  rules: {
1091
- 'require-clean-subscription': dbxWebRequireCleanSubscriptionRule,
1092
- 'require-complete-on-destroy': dbxWebRequireCompleteOnDestroyRule,
1093
- 'no-redundant-on-destroy': dbxWebNoRedundantOnDestroyRule
2534
+ 'require-clean-subscription': DBX_WEB_REQUIRE_CLEAN_SUBSCRIPTION_RULE,
2535
+ 'require-complete-on-destroy': DBX_WEB_REQUIRE_COMPLETE_ON_DESTROY_RULE,
2536
+ 'no-redundant-on-destroy': DBX_WEB_NO_REDUNDANT_ON_DESTROY_RULE,
2537
+ 'require-computed-signal-suffix': DBX_WEB_REQUIRE_COMPUTED_SIGNAL_SUFFIX_RULE,
2538
+ 'require-component-config-input': DBX_WEB_REQUIRE_COMPONENT_CONFIG_INPUT_RULE,
2539
+ 'require-top-level-computed-signals': DBX_WEB_REQUIRE_TOP_LEVEL_COMPUTED_SIGNALS_RULE
1094
2540
  }
1095
2541
  };
1096
2542
 
1097
- export { dbxWebEslintPlugin, dbxWebNoRedundantOnDestroyRule, dbxWebRequireCleanSubscriptionRule, dbxWebRequireCompleteOnDestroyRule };
2543
+ export { DBX_WEB_ESLINT_PLUGIN, DBX_WEB_NO_REDUNDANT_ON_DESTROY_RULE, DBX_WEB_REQUIRE_CLEAN_SUBSCRIPTION_RULE, DBX_WEB_REQUIRE_COMPLETE_ON_DESTROY_RULE, DBX_WEB_REQUIRE_COMPONENT_CONFIG_INPUT_RULE, DBX_WEB_REQUIRE_COMPUTED_SIGNAL_SUFFIX_RULE, DBX_WEB_REQUIRE_TOP_LEVEL_COMPUTED_SIGNALS_RULE };