OLD | NEW |
| (Empty) |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | |
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. | |
4 library initialize.plugin_transformer_test; | |
5 | |
6 import 'package:analyzer/analyzer.dart'; | |
7 import 'package:initialize/plugin_transformer.dart'; | |
8 import 'package:source_maps/refactor.dart'; | |
9 import 'package:unittest/compact_vm_config.dart'; | |
10 import 'common.dart'; | |
11 | |
12 // Simple plugin which just removes all initMethod initializers. | |
13 class DeleteInitMethodPlugin extends InitializePluginTransformer { | |
14 DeleteInitMethodPlugin(String bootstrap) : super(bootstrap); | |
15 | |
16 initEntry( | |
17 InstanceCreationExpression expression, TextEditTransaction transaction) { | |
18 var firstArg = expression.argumentList.arguments[0]; | |
19 if (firstArg is PrefixedIdentifier && | |
20 firstArg.identifier.toString() == 'initMethod') { | |
21 removeInitializer(expression, transaction); | |
22 } | |
23 } | |
24 } | |
25 | |
26 main() { | |
27 useCompactVMConfiguration(); | |
28 | |
29 var transformer = new DeleteInitMethodPlugin('web/index.bootstrap.dart'); | |
30 | |
31 testPhases('basic', [[transformer]], { | |
32 'a|web/index.bootstrap.dart': ''' | |
33 import 'package:initialize/src/static_loader.dart'; | |
34 import 'package:initialize/initialize.dart'; | |
35 import 'index.dart' as i0; | |
36 | |
37 main() { | |
38 initializers.addAll([ | |
39 new InitEntry(i0.initMethod, const LibraryIdentifier(#a, null, 'a.dart')), | |
40 new InitEntry(i0.initMethod, const LibraryIdentifier(#a, 'a', 'a.dart')), | |
41 new InitEntry(i0.initMethod, i0.a), | |
42 new InitEntry(const i0.DynamicInit('a()'), i0.a), | |
43 ]); | |
44 | |
45 i0.main(); | |
46 } | |
47 ''' | |
48 }, { | |
49 'a|web/index.bootstrap.dart': ''' | |
50 import 'package:initialize/src/static_loader.dart'; | |
51 import 'package:initialize/initialize.dart'; | |
52 import 'index.dart' as i0; | |
53 | |
54 main() { | |
55 initializers.addAll([ | |
56 new InitEntry(const i0.DynamicInit('a()'), i0.a), | |
57 ]); | |
58 | |
59 i0.main(); | |
60 } | |
61 ''' | |
62 }, []); | |
63 } | |
OLD | NEW |