| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library analyze_unused_dart2js; | 5 library analyze_unused_dart2js; |
| 6 | 6 |
| 7 import 'package:async_helper/async_helper.dart'; | 7 import 'package:async_helper/async_helper.dart'; |
| 8 | 8 |
| 9 import '../../../sdk/lib/_internal/compiler/implementation/dart2jslib.dart'; |
| 9 import '../../../sdk/lib/_internal/compiler/implementation/filenames.dart'; | 10 import '../../../sdk/lib/_internal/compiler/implementation/filenames.dart'; |
| 10 | 11 |
| 11 import 'analyze_helper.dart'; | 12 import 'analyze_helper.dart'; |
| 12 | 13 |
| 13 // Do not remove WHITE_LIST even if it's empty. The error message for | 14 // Do not remove WHITE_LIST even if it's empty. The error message for |
| 14 // unused members refers to WHITE_LIST by name. | 15 // unused members refers to WHITE_LIST by name. |
| 15 const Map<String, List<String>> WHITE_LIST = const {}; | 16 const Map<String, List<String>> WHITE_LIST = const { |
| 17 // TODO(johnniwinther): Explicitly check that we use no helpers, both methods |
| 18 // and classes, are used in production code.*/ |
| 19 // Helper methods for debugging should never be called from production code: |
| 20 "implementation/helpers/": const [" is never "], |
| 21 }; |
| 16 | 22 |
| 17 void main() { | 23 void main() { |
| 18 var uri = currentDirectory.resolve( | 24 var uri = currentDirectory.resolve( |
| 19 'sdk/lib/_internal/compiler/implementation/use_unused_api.dart'); | 25 'sdk/lib/_internal/compiler/implementation/use_unused_api.dart'); |
| 20 asyncTest(() => analyze([uri], WHITE_LIST, analyzeAll: false)); | 26 asyncTest(() => analyze([uri], WHITE_LIST, |
| 27 analyzeAll: false, checkResults: checkResults)); |
| 21 } | 28 } |
| 29 |
| 30 bool checkResults(Compiler compiler, CollectingDiagnosticHandler handler) { |
| 31 var helperUri = currentDirectory.resolve( |
| 32 'sdk/lib/_internal/compiler/implementation/helpers/helpers.dart'); |
| 33 void checkLive(member) { |
| 34 if (member.isFunction()) { |
| 35 if (compiler.enqueuer.resolution.isLive(member)) { |
| 36 compiler.reportHint(member, MessageKind.GENERIC, |
| 37 {'text': "Helper function in production code '$member'."}); |
| 38 } |
| 39 } else if (member.isClass()) { |
| 40 if (member.isResolved) { |
| 41 compiler.reportHint(member, MessageKind.GENERIC, |
| 42 {'text': "Helper class in production code '$member'."}); |
| 43 } else { |
| 44 member.forEachLocalMember(checkLive); |
| 45 } |
| 46 } else if (member.isTypedef()) { |
| 47 if (member.isResolved) { |
| 48 compiler.reportHint(member, MessageKind.GENERIC, |
| 49 {'text': "Helper typedef in production code '$member'."}); |
| 50 } |
| 51 } |
| 52 } |
| 53 compiler.libraries['$helperUri'].forEachLocalMember(checkLive); |
| 54 return handler.checkResults(); |
| 55 } |
| OLD | NEW |