diff --git a/pkg/analyzer/lib/src/error/unused_local_elements_verifier.dart b/pkg/analyzer/lib/src/error/unused_local_elements_verifier.dart index 7ba8e46d7bb..8d10082606a 100644 --- a/pkg/analyzer/lib/src/error/unused_local_elements_verifier.dart +++ b/pkg/analyzer/lib/src/error/unused_local_elements_verifier.dart @@ -70,6 +70,13 @@ class GatherUsedLocalElementsVisitor extends RecursiveAstVisitor { @override void visitClassDeclaration(ClassDeclaration node) { + var element = node.declaredElement; + if (element != null) { + if (element.hasJS) { + usedElements.addElement(element); + } + } + var enclosingClassOld = _enclosingClass; try { _enclosingClass = node.declaredElement; diff --git a/pkg/analyzer/test/src/diagnostics/unused_element_test.dart b/pkg/analyzer/test/src/diagnostics/unused_element_test.dart index a8b21638bd5..64b40b96af2 100644 --- a/pkg/analyzer/test/src/diagnostics/unused_element_test.dart +++ b/pkg/analyzer/test/src/diagnostics/unused_element_test.dart @@ -84,6 +84,28 @@ void f(Object p) { '''); } + test_class_isUsed_jsAnnotation() async { + writeTestPackageConfig( + PackageConfigFileBuilder() + ..add(name: 'js', rootPath: '$workspaceRootPath/js'), + ); + + newFile('$workspaceRootPath/js/lib/js.dart', r''' +library _js_annotations; + +class JS { + const JS(); +} +'''); + + await assertNoErrorsInCode(r''' +import 'package:js/js.dart'; + +@JS() +class _A {} +'''); + } + test_class_notUsed_isExpression_typeArgument() async { await assertErrorsInCode(r''' class _A {}