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 import "package:expect/expect.dart"; | 5 import "package:expect/expect.dart"; |
6 import 'dart:async'; | 6 import 'dart:async'; |
7 import "package:async_helper/async_helper.dart"; | 7 import "package:async_helper/async_helper.dart"; |
8 import 'memory_compiler.dart' show runCompiler; | 8 import 'memory_compiler.dart' show runCompiler; |
9 import 'package:compiler/src/apiimpl.dart' show | 9 import 'package:compiler/src/apiimpl.dart' show |
10 Compiler; | 10 CompilerImpl; |
11 import 'package:compiler/src/elements/elements.dart' show | 11 import 'package:compiler/src/elements/elements.dart' show |
12 Element, LibraryElement, ClassElement; | 12 Element, LibraryElement, ClassElement; |
13 import 'package:compiler/src/tree/tree.dart' show | 13 import 'package:compiler/src/tree/tree.dart' show |
14 Block, ExpressionStatement, FunctionExpression, Node, Send; | 14 Block, ExpressionStatement, FunctionExpression, Node, Send; |
15 import 'package:compiler/src/dart_backend/dart_backend.dart' show | 15 import 'package:compiler/src/dart_backend/dart_backend.dart' show |
16 DartBackend, ElementAst; | 16 DartBackend, ElementAst; |
17 import 'package:compiler/src/mirror_renamer/mirror_renamer.dart' show | 17 import 'package:compiler/src/mirror_renamer/mirror_renamer.dart' show |
18 MirrorRenamerImpl; | 18 MirrorRenamerImpl; |
19 | 19 |
20 main() { | 20 main() { |
21 asyncTest(() async { | 21 asyncTest(() async { |
22 await testWithMirrorRenaming(minify: true); | 22 await testWithMirrorRenaming(minify: true); |
23 await testWithMirrorRenaming(minify: false); | 23 await testWithMirrorRenaming(minify: false); |
24 await testWithoutMirrorRenaming(minify: true); | 24 await testWithoutMirrorRenaming(minify: true); |
25 await testWithoutMirrorRenaming(minify: false); | 25 await testWithoutMirrorRenaming(minify: false); |
26 }); | 26 }); |
27 } | 27 } |
28 | 28 |
29 Future<Compiler> run({useMirrorHelperLibrary: false, minify: false}) async { | 29 Future<CompilerImpl> run({useMirrorHelperLibrary: false, minify: false}) async { |
30 List<String> options = ['--output-type=dart']; | 30 List<String> options = ['--output-type=dart']; |
31 if (minify) { | 31 if (minify) { |
32 options.add('--minify'); | 32 options.add('--minify'); |
33 } | 33 } |
34 var result = await runCompiler( | 34 var result = await runCompiler( |
35 memorySourceFiles: MEMORY_SOURCE_FILES, | 35 memorySourceFiles: MEMORY_SOURCE_FILES, |
36 options: options, | 36 options: options, |
37 beforeRun: (Compiler compiler) { | 37 beforeRun: (CompilerImpl compiler) { |
38 DartBackend backend = compiler.backend; | 38 DartBackend backend = compiler.backend; |
39 backend.useMirrorHelperLibrary = useMirrorHelperLibrary; | 39 backend.useMirrorHelperLibrary = useMirrorHelperLibrary; |
40 }); | 40 }); |
41 return result.compiler; | 41 return result.compiler; |
42 } | 42 } |
43 | 43 |
44 Future testWithMirrorRenaming({bool minify}) async { | 44 Future testWithMirrorRenaming({bool minify}) async { |
45 Compiler compiler = await run(useMirrorHelperLibrary: true, minify: minify); | 45 CompilerImpl compiler = await run(useMirrorHelperLibrary: true, minify: minify ); |
Johnni Winther
2015/10/29 10:45:45
Long line.
sigurdm
2015/10/29 12:00:59
Done.
| |
46 DartBackend backend = compiler.backend; | 46 DartBackend backend = compiler.backend; |
47 MirrorRenamerImpl mirrorRenamer = backend.mirrorRenamer; | 47 MirrorRenamerImpl mirrorRenamer = backend.mirrorRenamer; |
48 Map<Node, String> renames = backend.placeholderRenamer.renames; | 48 Map<Node, String> renames = backend.placeholderRenamer.renames; |
49 Iterable<LibraryElement> imports = | 49 Iterable<LibraryElement> imports = |
50 backend.placeholderRenamer.platformImports.keys; | 50 backend.placeholderRenamer.platformImports.keys; |
51 | 51 |
52 FunctionExpression node = backend.memberNodes.values.first.first; | 52 FunctionExpression node = backend.memberNodes.values.first.first; |
53 Block block = node.body; | 53 Block block = node.body; |
54 ExpressionStatement getNameFunctionNode = block.statements.nodes.head; | 54 ExpressionStatement getNameFunctionNode = block.statements.nodes.head; |
55 Send send = getNameFunctionNode.expression; | 55 Send send = getNameFunctionNode.expression; |
56 | 56 |
57 Expect.equals(renames[mirrorRenamer.getNameFunctionNode.name], | 57 Expect.equals(renames[mirrorRenamer.getNameFunctionNode.name], |
58 renames[send.selector]); | 58 renames[send.selector]); |
59 Expect.equals("", | 59 Expect.equals("", |
60 renames[send.receiver]); | 60 renames[send.receiver]); |
61 Expect.equals(1, imports.length); | 61 Expect.equals(1, imports.length); |
62 } | 62 } |
63 | 63 |
64 Future testWithoutMirrorRenaming({bool minify}) async { | 64 Future testWithoutMirrorRenaming({bool minify}) async { |
65 Compiler compiler = await run(useMirrorHelperLibrary: false, minify: minify); | 65 CompilerImpl compiler = await run(useMirrorHelperLibrary: false, minify: minif y); |
Johnni Winther
2015/10/29 10:45:45
Long line.
sigurdm
2015/10/29 12:00:59
Done.
| |
66 DartBackend backend = compiler.backend; | 66 DartBackend backend = compiler.backend; |
67 Map<Node, String> renames = backend.placeholderRenamer.renames; | 67 Map<Node, String> renames = backend.placeholderRenamer.renames; |
68 Iterable<LibraryElement> imports = | 68 Iterable<LibraryElement> imports = |
69 backend.placeholderRenamer.platformImports.keys; | 69 backend.placeholderRenamer.platformImports.keys; |
70 FunctionExpression node = backend.memberNodes.values.first.first; | 70 FunctionExpression node = backend.memberNodes.values.first.first; |
71 Block block = node.body; | 71 Block block = node.body; |
72 ExpressionStatement getNameFunctionNode = block.statements.nodes.head; | 72 ExpressionStatement getNameFunctionNode = block.statements.nodes.head; |
73 Send send = getNameFunctionNode.expression; | 73 Send send = getNameFunctionNode.expression; |
74 | 74 |
75 Expect.isFalse(renames.containsKey(send.selector)); | 75 Expect.isFalse(renames.containsKey(send.selector)); |
76 Expect.equals(1, imports.length); | 76 Expect.equals(1, imports.length); |
77 } | 77 } |
78 | 78 |
79 const MEMORY_SOURCE_FILES = const <String, String> { | 79 const MEMORY_SOURCE_FILES = const <String, String> { |
80 'main.dart': """ | 80 'main.dart': """ |
81 import 'dart:mirrors'; | 81 import 'dart:mirrors'; |
82 | 82 |
83 class Foo { | 83 class Foo { |
84 noSuchMethod(Invocation invocation) { | 84 noSuchMethod(Invocation invocation) { |
85 MirrorSystem.getName(invocation.memberName); | 85 MirrorSystem.getName(invocation.memberName); |
86 } | 86 } |
87 } | 87 } |
88 | 88 |
89 void main() { | 89 void main() { |
90 new Foo().fisk(); | 90 new Foo().fisk(); |
91 } | 91 } |
92 """}; | 92 """}; |
OLD | NEW |