Mark private classes which are annotated with @JS as used

Work towards https://github.com/dart-lang/sdk/issues/52835

Change-Id: I300928dbfcfd819e4a9f20030cb46e2048f504e7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/313287
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
This commit is contained in:
Sam Rawlins 2023-07-13 16:06:12 +00:00 committed by Commit Queue
parent 185aa1f36f
commit dea256c9fc
2 changed files with 29 additions and 0 deletions

View file

@ -70,6 +70,13 @@ class GatherUsedLocalElementsVisitor extends RecursiveAstVisitor<void> {
@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;

View file

@ -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 {}