Properly support the -remove_unused_declarations flag.

Typescript declarations can declare arbitrary global symbols, so a declaration might be required without an explicit import.  Long term the plan is to require explicit taze comments for the such declarations, but until then the query based analyzer needs to report the same warnings that blaze analyze does.

Also warn for possibly unused css_libraries.

PiperOrigin-RevId: 234897666
diff --git a/ts_auto_deps/analyze/analyze.go b/ts_auto_deps/analyze/analyze.go
index d1ca2d5..475ab3e 100644
--- a/ts_auto_deps/analyze/analyze.go
+++ b/ts_auto_deps/analyze/analyze.go
@@ -593,7 +593,21 @@
 		return nil, err
 	}
 	for label, rule := range labelToRule {
-		if isTazeManagedRuleClass(rule.GetRuleClass()) || isGenerated(rule) {
+		switch class := rule.GetRuleClass(); class {
+		case "ts_declaration":
+			// TypeScript declarations might declare arbitrary global symbols, so it
+			// is impossible to detect reliably if the import is being used (without
+			// compiling, at least).  Report that the rule has no explicit import as a
+			// warning, so that ts_auto_deps can decide to import remove or not based on a
+			// flag.
+			warning := fmt.Sprintf("WARNING: %s: keeping possibly used %s '%s'", rule.GetLocation(), class, label)
+			report.Feedback = append(report.Feedback, warning)
+		case "css_library":
+			// Similar to ts_declaration, ts_auto_deps can't reliably detect if css_library
+			// imports are being used, since ts_auto_deps can't currently parse @requirecss
+			// annotations.  Unlike ts_declaration, there's no flag to remove them, so
+			// there's no need to report a warning.
+		default:
 			report.UnnecessaryDependency = append(report.UnnecessaryDependency, label)
 		}
 	}
diff --git a/ts_auto_deps/analyze/loader.go b/ts_auto_deps/analyze/loader.go
index 4b509ca..f70dbcb 100644
--- a/ts_auto_deps/analyze/loader.go
+++ b/ts_auto_deps/analyze/loader.go
@@ -376,21 +376,6 @@
 	return uniqueLabels
 }
 
-// isTazeManagedRuleClass checks if a class is a ts_auto_deps-managed rule class.
-func isTazeManagedRuleClass(class string) bool {
-	for _, c := range []string{
-		"ts_library",
-		"ts_declaration",
-		"ng_module",
-		"js_library",
-	} {
-		if c == class {
-			return true
-		}
-	}
-	return false
-}
-
 // typeScriptRules returns all TypeScript rules in rules.
 func typeScriptRules(rules []*appb.Rule) []*appb.Rule {
 	var tsRules []*appb.Rule