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 'package:compiler/implementation/dart2jslib.dart'; | 9 import 'package:compiler/src/dart2jslib.dart'; |
10 import 'package:compiler/implementation/filenames.dart'; | 10 import 'package:compiler/src/filenames.dart'; |
11 | 11 |
12 import 'analyze_helper.dart'; | 12 import 'analyze_helper.dart'; |
13 | 13 |
14 // 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 |
15 // unused members refers to WHITE_LIST by name. | 15 // unused members refers to WHITE_LIST by name. |
16 const Map<String, List<String>> WHITE_LIST = const { | 16 const Map<String, List<String>> WHITE_LIST = const { |
17 // Helper methods for debugging should never be called from production code: | 17 // Helper methods for debugging should never be called from production code: |
18 "implementation/helpers/": const [" is never "], | 18 "lib/src/helpers/": const [" is never "], |
19 | 19 |
20 // Node.asLiteralBool is never used. | 20 // Node.asLiteralBool is never used. |
21 "implementation/tree/nodes.dart": const [ | 21 "lib/src/tree/nodes.dart": const [ |
22 "The method 'asLiteralBool' is never called"], | 22 "The method 'asLiteralBool' is never called"], |
23 | 23 |
24 // Some things in dart_printer are not yet used | 24 // Some things in dart_printer are not yet used |
25 "implementation/dart_backend/backend_ast_nodes.dart": const [" is never "], | 25 "lib/src/dart_backend/backend_ast_nodes.dart": const [" is never "], |
26 | |
27 // dart2js uses only the encoding functions, the decoding functions are used | |
28 // from the generated code. | |
29 "js_lib/shared/runtime_data.dart": const [" is never "], | |
30 | 26 |
31 // MethodElement | 27 // MethodElement |
32 // TODO(20377): Why is MethodElement unused? | 28 // TODO(20377): Why is MethodElement unused? |
33 "implementation/elements/elements.dart": const [" is never "] | 29 "lib/src/elements/elements.dart": const [" is never "] |
34 }; | 30 }; |
35 | 31 |
36 void main() { | 32 void main() { |
37 var uri = currentDirectory.resolve( | 33 var uri = currentDirectory.resolve( |
38 'sdk/lib/_internal/compiler/implementation/use_unused_api.dart'); | 34 'pkg/compiler/lib/src/use_unused_api.dart'); |
39 asyncTest(() => analyze([uri], WHITE_LIST, | 35 asyncTest(() => analyze([uri], WHITE_LIST, |
40 analyzeAll: false, checkResults: checkResults)); | 36 analyzeAll: false, checkResults: checkResults)); |
41 } | 37 } |
42 | 38 |
43 bool checkResults(Compiler compiler, CollectingDiagnosticHandler handler) { | 39 bool checkResults(Compiler compiler, CollectingDiagnosticHandler handler) { |
44 var helperUri = currentDirectory.resolve( | 40 var helperUri = currentDirectory.resolve( |
45 'sdk/lib/_internal/compiler/implementation/helpers/helpers.dart'); | 41 'pkg/compiler/lib/src/helpers/helpers.dart'); |
46 void checkLive(member) { | 42 void checkLive(member) { |
47 if (member.isFunction) { | 43 if (member.isFunction) { |
48 if (compiler.enqueuer.resolution.hasBeenResolved(member)) { | 44 if (compiler.enqueuer.resolution.hasBeenResolved(member)) { |
49 compiler.reportHint(member, MessageKind.GENERIC, | 45 compiler.reportHint(member, MessageKind.GENERIC, |
50 {'text': "Helper function in production code '$member'."}); | 46 {'text': "Helper function in production code '$member'."}); |
51 } | 47 } |
52 } else if (member.isClass) { | 48 } else if (member.isClass) { |
53 if (member.isResolved) { | 49 if (member.isResolved) { |
54 compiler.reportHint(member, MessageKind.GENERIC, | 50 compiler.reportHint(member, MessageKind.GENERIC, |
55 {'text': "Helper class in production code '$member'."}); | 51 {'text': "Helper class in production code '$member'."}); |
56 } else { | 52 } else { |
57 member.forEachLocalMember(checkLive); | 53 member.forEachLocalMember(checkLive); |
58 } | 54 } |
59 } else if (member.isTypedef) { | 55 } else if (member.isTypedef) { |
60 if (member.isResolved) { | 56 if (member.isResolved) { |
61 compiler.reportHint(member, MessageKind.GENERIC, | 57 compiler.reportHint(member, MessageKind.GENERIC, |
62 {'text': "Helper typedef in production code '$member'."}); | 58 {'text': "Helper typedef in production code '$member'."}); |
63 } | 59 } |
64 } | 60 } |
65 } | 61 } |
66 compiler.libraryLoader.lookupLibrary(helperUri).forEachLocalMember(checkLive); | 62 compiler.libraryLoader.lookupLibrary(helperUri).forEachLocalMember(checkLive); |
67 return handler.checkResults(); | 63 return handler.checkResults(); |
68 } | 64 } |
OLD | NEW |