From e73ac1e9921e6610cd52fb312a03ef0a1fca062d Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Thu, 21 Jul 2016 11:48:23 -0700 Subject: [PATCH] chore(Dart): remove obsolete files, update the docs --- CONTRIBUTING.md | 2 +- DEVELOPER.md | 49 +- README.md | 5 +- TOOLS_DART.md | 376 ------ modules_dart/README.md | 34 - modules_dart/angular2_testing/README.md | 46 - .../lib/angular2_testing.dart | 120 -- modules_dart/angular2_testing/pubspec.yaml | 18 - .../test/angular2_testing_test.dart | 117 -- .../angular2_testing/test/test_template.html | 1 - modules_dart/payload/hello_world/pubspec.yaml | 23 - .../payload/hello_world/web/index.dart | 40 - .../payload/hello_world/web/index.html | 12 - .../transform/lib/extract_messages.dart | 118 -- .../transform/common/annotation_matcher.dart | 132 -- .../src/transform/common/asset_reader.dart | 28 - .../transform/common/async_string_writer.dart | 78 -- .../transform/common/class_matcher_base.dart | 127 -- .../common/code/annotation_code.dart | 80 -- .../src/transform/common/code/constify.dart | 64 - .../common/code/import_export_code.dart | 130 -- .../transform/common/code/ng_deps_code.dart | 182 --- .../transform/common/code/parameter_code.dart | 138 -- .../common/code/reflection_info_code.dart | 256 ---- .../transform/common/code/source_module.dart | 42 - .../common/eager_transformer_wrapper.dart | 45 - .../lib/src/transform/common/formatter.dart | 32 - .../transform/common/interface_matcher.dart | 135 -- .../lib/src/transform/common/logging.dart | 147 --- .../src/transform/common/mirror_matcher.dart | 43 - .../lib/src/transform/common/mirror_mode.dart | 10 - .../common/model/annotation_model.pb.dart | 107 -- .../common/model/annotation_model.proto | 25 - .../common/model/import_export_model.pb.dart | 115 -- .../common/model/import_export_model.proto | 28 - .../common/model/ng_deps_model.pb.dart | 78 -- .../common/model/ng_deps_model.proto | 27 - .../common/model/parameter_model.pb.dart | 68 - .../common/model/parameter_model.proto | 13 - .../model/reflection_info_model.pb.dart | 129 -- .../common/model/reflection_info_model.proto | 40 - .../transform/common/model/source_module.dart | 83 -- .../lib/src/transform/common/naive_eval.dart | 26 - .../lib/src/transform/common/names.dart | 89 -- .../lib/src/transform/common/ng_compiler.dart | 52 - .../lib/src/transform/common/ng_meta.dart | 151 --- .../lib/src/transform/common/options.dart | 157 --- .../src/transform/common/options_reader.dart | 143 --- .../common/type_metadata_reader.dart | 1135 ----------------- .../src/transform/common/url_resolver.dart | 64 - .../lib/src/transform/common/xhr_impl.dart | 31 - .../lib/src/transform/common/zone.dart | 74 -- .../transform/deferred_rewriter/rewriter.dart | 179 --- .../deferred_rewriter/transformer.dart | 94 -- .../ng_deps_linker.dart | 83 -- .../ng_meta_linker.dart | 460 ------- .../transformer.dart | 78 -- .../directive_processor/inliner.dart | 109 -- .../directive_processor/rewriter.dart | 170 --- .../directive_processor/transformer.dart | 76 -- .../inliner_for_test/transformer.dart | 241 ---- .../transform/reflection_remover/codegen.dart | 35 - .../entrypoint_matcher.dart | 59 - .../remove_reflection_capabilities.dart | 32 - .../reflection_remover/rewriter.dart | 331 ----- .../reflection_remover/transformer.dart | 69 - .../stylesheet_compiler/processor.dart | 36 - .../stylesheet_compiler/transformer.dart | 50 - .../compile_data_creator.dart | 264 ---- .../template_compiler/generator.dart | 85 -- .../template_compiler/transformer.dart | 89 -- .../lib/src/transform/transformer.dart | 57 - .../transform/lib/transform/codegen.dart | 56 - .../lib/transform/deferred_rewriter.dart | 45 - .../lib/transform/reflection_remover.dart | 65 - modules_dart/transform/lib/transformer.dart | 3 - modules_dart/transform/pubspec.yaml | 24 - .../common/annotation_matcher_test.dart | 109 -- .../test/transform/common/application.dart | 14 - .../common/async_string_writer_tests.dart | 109 -- .../common/code/ng_deps_code_tests.dart | 70 - .../ng_for.ng_meta.dart | 26 - .../test/transform/common/ng_meta_helper.dart | 84 -- .../test/transform/common/ng_meta_test.dart | 158 --- .../test/transform/common/read_file.dart | 51 - .../transform/common/recording_logger.dart | 27 - .../common/reflection_capabilities.dart | 9 - .../transform/common/url_resolver_tests.dart | 149 --- .../deferred_rewriter/all_tests.dart | 62 - .../expected/index.dart | 17 - .../complex_deferred_example/hello.dart | 8 - .../hello.ng_meta.json | 32 - .../complex_deferred_example/index.dart | 15 - .../deferred_example_no_ng_deps/hello.dart | 8 - .../deferred_example_no_ng_deps/index.dart | 13 - .../no_deferred_libraries/index.dart | 10 - .../no_ng_deps_libraries/index.dart | 11 - .../expected/index.dart | 15 - .../simple_deferred_example/hello.dart | 8 - .../hello.ng_meta.json | 32 - .../simple_deferred_example/index.dart | 13 - .../directive_metadata_linker/all_tests.dart | 685 ---------- .../absolute_url_expression_files/hello.dart | 13 - .../template.css | 1 - .../template.html | 1 - .../abstract_classes/classes.dart | 10 - .../directive_processor/all_tests.dart | 1104 ---------------- .../bad_directives_files/directives.dart | 10 - .../bad_directives_files/pipes.dart | 9 - .../bad_directives_files/template.dart | 10 - .../bad_directives_files/template_url.dart | 10 - .../custom_metadata/bad_soup.dart | 8 - .../custom_metadata/package_soup.dart | 10 - .../custom_metadata/relative_soup.dart | 10 - .../directive_aliases_files/a.dart | 3 - .../directive_aliases_files/b.dart | 1 - .../directive_aliases_files/hello.dart | 20 - .../directive_aliases_files/template.css | 1 - .../directive_aliases_files/template.html | 1 - .../directives_files/components.dart | 271 ---- .../directives_files/dep1.dart | 17 - .../directives_files/dep2.dart | 14 - .../directives_files/services.dart | 9 - .../identifiers/classes.dart | 10 - .../identifiers/classes_no_injectable.dart | 3 - .../identifiers/constants.dart | 5 - .../identifiers/enums.dart | 3 - .../identifiers/factories.dart | 10 - .../identifiers/provider_constants.dart | 13 - .../identifiers/typedefs.dart | 3 - .../interface_chain_files/soup.dart | 13 - .../interfaces_files/soup.dart | 8 - .../invalid_url_files/hello.dart | 10 - .../soup.dart | 8 - .../multiple_part_files/main.dart | 12 - .../multiple_part_files/part1.dart | 7 - .../multiple_part_files/part2.dart | 7 - .../parameter_metadata/soup.dart | 9 - .../directive_processor/part_files/main.dart | 11 - .../directive_processor/part_files/part.dart | 7 - .../directive_processor/pipe_files/pipes.dart | 9 - .../prefixed_annotations_files/soup.dart | 7 - .../soup.dart | 8 - .../prop_metadata_files/fields.dart | 9 - .../prop_metadata_files/getters.dart | 9 - .../getters_and_setters.dart | 11 - .../prop_metadata_files/override.dart | 14 - .../prop_metadata_files/setters.dart | 9 - .../static_function_files/hello.dart | 11 - .../superclass_files/soup.dart | 11 - .../superclass_lifecycle_files/soup.dart | 8 - .../template_files/property.dart | 8 - .../unusual_component_files/hello.dart | 22 - .../unusual_component_files/template.html | 1 - .../expected/hello.dart | 12 - .../absolute_url_expression_files/hello.dart | 12 - .../template.css | 1 - .../template.html | 1 - .../transform/inliner_for_test/all_tests.dart | 233 ---- .../false_match_files/hello.dart | 12 - .../false_match_files/template.css | 1 - .../false_match_files/template.html | 1 - .../multiline_template/hello.dart | 14 - .../expected/hello.dart | 12 - .../multiple_style_urls_files/hello.dart | 10 - .../multiple_style_urls_files/template.css | 1 - .../multiple_style_urls_files/template.html | 1 - .../template_other.css | 1 - .../no_modify_files/hello.dart | 8 - .../no_modify_files/hello_part.dart | 3 - .../prop_annotations_files/hello.dart | 10 - .../prop_annotations_files/template.css | 1 - .../split_url_expression_files/hello.dart | 8 - .../split_url_expression_files/template.html | 1 - .../url_expression_files/hello.dart | 8 - .../url_expression_files/template.html | 1 - .../test/transform/integration/all_tests.dart | 198 --- .../integration/deferred_files/bar.dart | 17 - .../integration/deferred_files/dep.dart | 6 - .../expected/bar.ngfactory.dart | 19 - .../deferred_files/expected/output.dart | 38 - .../integration/deferred_files/index.dart | 9 - .../directive_chain_files/bar.dart | 10 - .../directive_chain_files/baz.dart | 3 - .../expected/bar.ngfactory.dart | 22 - .../directive_chain_files/foo.dart | 6 - .../directive_chain_files/index.dart | 10 - .../integration/directive_dep_files/bar.dart | 10 - .../expected/bar.ngfactory.dart | 22 - .../integration/directive_dep_files/foo.dart | 6 - .../directive_dep_files/index.dart | 10 - .../integration/empty_ng_deps_files/bar.dart | 3 - .../expected/bar.ngfactory.dart | 1 - .../expected/foo.ngfactory.dart | 22 - .../integration/empty_ng_deps_files/foo.dart | 8 - .../integration/list_of_types_files/bar.dart | 11 - .../expected/bar.ngfactory.dart | 23 - .../integration/list_of_types_files/foo.dart | 6 - .../list_of_types_files/index.dart | 10 - .../simple_annotation_files/bar.dart | 8 - .../expected/bar.ngfactory.dart | 19 - .../expected/index.ngfactory.dart | 16 - .../simple_annotation_files/index.dart | 11 - .../integration/synthetic_ctor_files/bar.dart | 7 - .../expected/bar.ngfactory.dart | 19 - .../synthetic_ctor_files/index.dart | 10 - .../two_annotations_files/bar.dart | 12 - .../expected/bar.ngfactory.dart | 22 - .../two_annotations_files/index.dart | 10 - .../integration/two_deps_files/bar.dart | 14 - .../expected/bar.ngfactory.dart | 28 - .../integration/two_deps_files/foo.dart | 11 - .../integration/two_deps_files/index.dart | 10 - .../index.dart | 8 - .../reflection_remover/all_tests.dart | 150 --- .../arrow_annotation_files/index.dart | 8 - .../bootstrap_files/README.md | 5 - .../bootstrap_files/expected/index.dart | 19 - .../bootstrap_files/index.dart | 7 - .../combinator_files/expected/index.dart | 17 - .../combinator_files/index.dart | 5 - .../reflection_remover/debug_files/README.md | 5 - .../debug_files/expected/index.dart | 22 - .../reflection_remover/debug_files/index.dart | 10 - .../debug_mirrors_files/README.md | 7 - .../debug_mirrors_files/expected/index.dart | 22 - .../debug_mirrors_files/index.dart | 10 - .../expected/index.dart | 19 - .../deferred_bootstrap_files/index.dart | 7 - .../expected/index.dart | 23 - .../function_annotation_files/index.dart | 11 - .../transform/reflection_remover/index.dart | 10 - .../log_mirrors_files/README.md | 7 - .../log_mirrors_files/expected/index.dart | 22 - .../log_mirrors_files/index.dart | 10 - .../expected/index.dart | 20 - .../method_annotation_files/index.dart | 8 - .../native_annotation_files/index.dart | 8 - .../reflection_remover_files/README.md | 7 - .../expected/index.dart | 22 - .../reflection_remover_files/index.dart | 10 - .../verbose_files/expected/index.dart | 22 - .../stylesheet_compiler/all_tests.dart | 107 -- .../template_compiler/all_tests.dart | 395 ------ .../hello1.ng_deps.dart | 28 - .../hello2.ng_deps.dart | 28 - .../expected/hello.ng_deps.dart | 19 - .../directive_event_files/hello.ng_deps.dart | 19 - .../event_files/expected/hello.ng_deps.dart | 23 - .../event_files/hello.ng_deps.dart | 20 - .../expected/hello.ng_deps.dart | 23 - .../hello.ng_deps.dart | 20 - .../expected/hello.ng_deps.dart | 23 - .../inline_method_files/hello.ng_deps.dart | 20 - .../expected/hello.ng_deps.dart | 32 - .../one_directive_files/hello.ng_deps.dart | 28 - .../expected/registrations.ng_deps.dart | 88 -- .../registrations.ng_deps.dart | 88 -- .../expected/hello.ng_deps.dart | 23 - .../url_expression_files/hello.ng_deps.dart | 20 - .../expected/hello.ng_deps.dart | 23 - .../url_method_files/hello.ng_deps.dart | 20 - .../expected/goodbye.ng_deps.dart | 23 - .../expected/hello.ng_deps.dart | 27 - .../with_prefix_files/goodbye.ng_deps.dart | 20 - .../with_prefix_files/hello.ng_deps.dart | 24 - .../transform/transform.e2e.server.spec.dart | 11 - .../test/transform/transform.server.spec.dart | 26 - .../transform.unittest.server.spec.dart | 18 - protractor-dart2js.conf.js | 18 - protractor-ddc.conf.js | 3 - pubspec.yaml | 10 - 272 files changed, 7 insertions(+), 14339 deletions(-) delete mode 100644 TOOLS_DART.md delete mode 100644 modules_dart/README.md delete mode 100644 modules_dart/angular2_testing/README.md delete mode 100644 modules_dart/angular2_testing/lib/angular2_testing.dart delete mode 100644 modules_dart/angular2_testing/pubspec.yaml delete mode 100644 modules_dart/angular2_testing/test/angular2_testing_test.dart delete mode 100644 modules_dart/angular2_testing/test/test_template.html delete mode 100644 modules_dart/payload/hello_world/pubspec.yaml delete mode 100644 modules_dart/payload/hello_world/web/index.dart delete mode 100644 modules_dart/payload/hello_world/web/index.html delete mode 100644 modules_dart/transform/lib/extract_messages.dart delete mode 100644 modules_dart/transform/lib/src/transform/common/annotation_matcher.dart delete mode 100644 modules_dart/transform/lib/src/transform/common/asset_reader.dart delete mode 100644 modules_dart/transform/lib/src/transform/common/async_string_writer.dart delete mode 100644 modules_dart/transform/lib/src/transform/common/class_matcher_base.dart delete mode 100644 modules_dart/transform/lib/src/transform/common/code/annotation_code.dart delete mode 100644 modules_dart/transform/lib/src/transform/common/code/constify.dart delete mode 100644 modules_dart/transform/lib/src/transform/common/code/import_export_code.dart delete mode 100644 modules_dart/transform/lib/src/transform/common/code/ng_deps_code.dart delete mode 100644 modules_dart/transform/lib/src/transform/common/code/parameter_code.dart delete mode 100644 modules_dart/transform/lib/src/transform/common/code/reflection_info_code.dart delete mode 100644 modules_dart/transform/lib/src/transform/common/code/source_module.dart delete mode 100644 modules_dart/transform/lib/src/transform/common/eager_transformer_wrapper.dart delete mode 100644 modules_dart/transform/lib/src/transform/common/formatter.dart delete mode 100644 modules_dart/transform/lib/src/transform/common/interface_matcher.dart delete mode 100644 modules_dart/transform/lib/src/transform/common/logging.dart delete mode 100644 modules_dart/transform/lib/src/transform/common/mirror_matcher.dart delete mode 100644 modules_dart/transform/lib/src/transform/common/mirror_mode.dart delete mode 100644 modules_dart/transform/lib/src/transform/common/model/annotation_model.pb.dart delete mode 100644 modules_dart/transform/lib/src/transform/common/model/annotation_model.proto delete mode 100644 modules_dart/transform/lib/src/transform/common/model/import_export_model.pb.dart delete mode 100644 modules_dart/transform/lib/src/transform/common/model/import_export_model.proto delete mode 100644 modules_dart/transform/lib/src/transform/common/model/ng_deps_model.pb.dart delete mode 100644 modules_dart/transform/lib/src/transform/common/model/ng_deps_model.proto delete mode 100644 modules_dart/transform/lib/src/transform/common/model/parameter_model.pb.dart delete mode 100644 modules_dart/transform/lib/src/transform/common/model/parameter_model.proto delete mode 100644 modules_dart/transform/lib/src/transform/common/model/reflection_info_model.pb.dart delete mode 100644 modules_dart/transform/lib/src/transform/common/model/reflection_info_model.proto delete mode 100644 modules_dart/transform/lib/src/transform/common/model/source_module.dart delete mode 100644 modules_dart/transform/lib/src/transform/common/naive_eval.dart delete mode 100644 modules_dart/transform/lib/src/transform/common/names.dart delete mode 100644 modules_dart/transform/lib/src/transform/common/ng_compiler.dart delete mode 100644 modules_dart/transform/lib/src/transform/common/ng_meta.dart delete mode 100644 modules_dart/transform/lib/src/transform/common/options.dart delete mode 100644 modules_dart/transform/lib/src/transform/common/options_reader.dart delete mode 100644 modules_dart/transform/lib/src/transform/common/type_metadata_reader.dart delete mode 100644 modules_dart/transform/lib/src/transform/common/url_resolver.dart delete mode 100644 modules_dart/transform/lib/src/transform/common/xhr_impl.dart delete mode 100644 modules_dart/transform/lib/src/transform/common/zone.dart delete mode 100644 modules_dart/transform/lib/src/transform/deferred_rewriter/rewriter.dart delete mode 100644 modules_dart/transform/lib/src/transform/deferred_rewriter/transformer.dart delete mode 100644 modules_dart/transform/lib/src/transform/directive_metadata_linker/ng_deps_linker.dart delete mode 100644 modules_dart/transform/lib/src/transform/directive_metadata_linker/ng_meta_linker.dart delete mode 100644 modules_dart/transform/lib/src/transform/directive_metadata_linker/transformer.dart delete mode 100644 modules_dart/transform/lib/src/transform/directive_processor/inliner.dart delete mode 100644 modules_dart/transform/lib/src/transform/directive_processor/rewriter.dart delete mode 100644 modules_dart/transform/lib/src/transform/directive_processor/transformer.dart delete mode 100644 modules_dart/transform/lib/src/transform/inliner_for_test/transformer.dart delete mode 100644 modules_dart/transform/lib/src/transform/reflection_remover/codegen.dart delete mode 100644 modules_dart/transform/lib/src/transform/reflection_remover/entrypoint_matcher.dart delete mode 100644 modules_dart/transform/lib/src/transform/reflection_remover/remove_reflection_capabilities.dart delete mode 100644 modules_dart/transform/lib/src/transform/reflection_remover/rewriter.dart delete mode 100644 modules_dart/transform/lib/src/transform/reflection_remover/transformer.dart delete mode 100644 modules_dart/transform/lib/src/transform/stylesheet_compiler/processor.dart delete mode 100644 modules_dart/transform/lib/src/transform/stylesheet_compiler/transformer.dart delete mode 100644 modules_dart/transform/lib/src/transform/template_compiler/compile_data_creator.dart delete mode 100644 modules_dart/transform/lib/src/transform/template_compiler/generator.dart delete mode 100644 modules_dart/transform/lib/src/transform/template_compiler/transformer.dart delete mode 100644 modules_dart/transform/lib/src/transform/transformer.dart delete mode 100644 modules_dart/transform/lib/transform/codegen.dart delete mode 100644 modules_dart/transform/lib/transform/deferred_rewriter.dart delete mode 100644 modules_dart/transform/lib/transform/reflection_remover.dart delete mode 100644 modules_dart/transform/lib/transformer.dart delete mode 100644 modules_dart/transform/pubspec.yaml delete mode 100644 modules_dart/transform/test/transform/common/annotation_matcher_test.dart delete mode 100644 modules_dart/transform/test/transform/common/application.dart delete mode 100644 modules_dart/transform/test/transform/common/async_string_writer_tests.dart delete mode 100644 modules_dart/transform/test/transform/common/code/ng_deps_code_tests.dart delete mode 100644 modules_dart/transform/test/transform/common/compile_directive_metadata/ng_for.ng_meta.dart delete mode 100644 modules_dart/transform/test/transform/common/ng_meta_helper.dart delete mode 100644 modules_dart/transform/test/transform/common/ng_meta_test.dart delete mode 100644 modules_dart/transform/test/transform/common/read_file.dart delete mode 100644 modules_dart/transform/test/transform/common/recording_logger.dart delete mode 100644 modules_dart/transform/test/transform/common/reflection_capabilities.dart delete mode 100644 modules_dart/transform/test/transform/common/url_resolver_tests.dart delete mode 100644 modules_dart/transform/test/transform/deferred_rewriter/all_tests.dart delete mode 100644 modules_dart/transform/test/transform/deferred_rewriter/complex_deferred_example/expected/index.dart delete mode 100644 modules_dart/transform/test/transform/deferred_rewriter/complex_deferred_example/hello.dart delete mode 100644 modules_dart/transform/test/transform/deferred_rewriter/complex_deferred_example/hello.ng_meta.json delete mode 100644 modules_dart/transform/test/transform/deferred_rewriter/complex_deferred_example/index.dart delete mode 100644 modules_dart/transform/test/transform/deferred_rewriter/deferred_example_no_ng_deps/hello.dart delete mode 100644 modules_dart/transform/test/transform/deferred_rewriter/deferred_example_no_ng_deps/index.dart delete mode 100644 modules_dart/transform/test/transform/deferred_rewriter/no_deferred_libraries/index.dart delete mode 100644 modules_dart/transform/test/transform/deferred_rewriter/no_ng_deps_libraries/index.dart delete mode 100644 modules_dart/transform/test/transform/deferred_rewriter/simple_deferred_example/expected/index.dart delete mode 100644 modules_dart/transform/test/transform/deferred_rewriter/simple_deferred_example/hello.dart delete mode 100644 modules_dart/transform/test/transform/deferred_rewriter/simple_deferred_example/hello.ng_meta.json delete mode 100644 modules_dart/transform/test/transform/deferred_rewriter/simple_deferred_example/index.dart delete mode 100644 modules_dart/transform/test/transform/directive_metadata_linker/all_tests.dart delete mode 100644 modules_dart/transform/test/transform/directive_processor/absolute_url_expression_files/hello.dart delete mode 100644 modules_dart/transform/test/transform/directive_processor/absolute_url_expression_files/template.css delete mode 100644 modules_dart/transform/test/transform/directive_processor/absolute_url_expression_files/template.html delete mode 100644 modules_dart/transform/test/transform/directive_processor/abstract_classes/classes.dart delete mode 100644 modules_dart/transform/test/transform/directive_processor/all_tests.dart delete mode 100644 modules_dart/transform/test/transform/directive_processor/bad_directives_files/directives.dart delete mode 100644 modules_dart/transform/test/transform/directive_processor/bad_directives_files/pipes.dart delete mode 100644 modules_dart/transform/test/transform/directive_processor/bad_directives_files/template.dart delete mode 100644 modules_dart/transform/test/transform/directive_processor/bad_directives_files/template_url.dart delete mode 100644 modules_dart/transform/test/transform/directive_processor/custom_metadata/bad_soup.dart delete mode 100644 modules_dart/transform/test/transform/directive_processor/custom_metadata/package_soup.dart delete mode 100644 modules_dart/transform/test/transform/directive_processor/custom_metadata/relative_soup.dart delete mode 100644 modules_dart/transform/test/transform/directive_processor/directive_aliases_files/a.dart delete mode 100644 modules_dart/transform/test/transform/directive_processor/directive_aliases_files/b.dart delete mode 100644 modules_dart/transform/test/transform/directive_processor/directive_aliases_files/hello.dart delete mode 100644 modules_dart/transform/test/transform/directive_processor/directive_aliases_files/template.css delete mode 100644 modules_dart/transform/test/transform/directive_processor/directive_aliases_files/template.html delete mode 100644 modules_dart/transform/test/transform/directive_processor/directives_files/components.dart delete mode 100644 modules_dart/transform/test/transform/directive_processor/directives_files/dep1.dart delete mode 100644 modules_dart/transform/test/transform/directive_processor/directives_files/dep2.dart delete mode 100644 modules_dart/transform/test/transform/directive_processor/directives_files/services.dart delete mode 100644 modules_dart/transform/test/transform/directive_processor/identifiers/classes.dart delete mode 100644 modules_dart/transform/test/transform/directive_processor/identifiers/classes_no_injectable.dart delete mode 100644 modules_dart/transform/test/transform/directive_processor/identifiers/constants.dart delete mode 100644 modules_dart/transform/test/transform/directive_processor/identifiers/enums.dart delete mode 100644 modules_dart/transform/test/transform/directive_processor/identifiers/factories.dart delete mode 100644 modules_dart/transform/test/transform/directive_processor/identifiers/provider_constants.dart delete mode 100644 modules_dart/transform/test/transform/directive_processor/identifiers/typedefs.dart delete mode 100644 modules_dart/transform/test/transform/directive_processor/interface_chain_files/soup.dart delete mode 100644 modules_dart/transform/test/transform/directive_processor/interfaces_files/soup.dart delete mode 100644 modules_dart/transform/test/transform/directive_processor/invalid_url_files/hello.dart delete mode 100644 modules_dart/transform/test/transform/directive_processor/multiple_interface_lifecycle_files/soup.dart delete mode 100644 modules_dart/transform/test/transform/directive_processor/multiple_part_files/main.dart delete mode 100644 modules_dart/transform/test/transform/directive_processor/multiple_part_files/part1.dart delete mode 100644 modules_dart/transform/test/transform/directive_processor/multiple_part_files/part2.dart delete mode 100644 modules_dart/transform/test/transform/directive_processor/parameter_metadata/soup.dart delete mode 100644 modules_dart/transform/test/transform/directive_processor/part_files/main.dart delete mode 100644 modules_dart/transform/test/transform/directive_processor/part_files/part.dart delete mode 100644 modules_dart/transform/test/transform/directive_processor/pipe_files/pipes.dart delete mode 100644 modules_dart/transform/test/transform/directive_processor/prefixed_annotations_files/soup.dart delete mode 100644 modules_dart/transform/test/transform/directive_processor/prefixed_interface_lifecycle_files/soup.dart delete mode 100644 modules_dart/transform/test/transform/directive_processor/prop_metadata_files/fields.dart delete mode 100644 modules_dart/transform/test/transform/directive_processor/prop_metadata_files/getters.dart delete mode 100644 modules_dart/transform/test/transform/directive_processor/prop_metadata_files/getters_and_setters.dart delete mode 100644 modules_dart/transform/test/transform/directive_processor/prop_metadata_files/override.dart delete mode 100644 modules_dart/transform/test/transform/directive_processor/prop_metadata_files/setters.dart delete mode 100644 modules_dart/transform/test/transform/directive_processor/static_function_files/hello.dart delete mode 100644 modules_dart/transform/test/transform/directive_processor/superclass_files/soup.dart delete mode 100644 modules_dart/transform/test/transform/directive_processor/superclass_lifecycle_files/soup.dart delete mode 100644 modules_dart/transform/test/transform/directive_processor/template_files/property.dart delete mode 100644 modules_dart/transform/test/transform/directive_processor/unusual_component_files/hello.dart delete mode 100644 modules_dart/transform/test/transform/directive_processor/unusual_component_files/template.html delete mode 100644 modules_dart/transform/test/transform/inliner_for_test/absolute_url_expression_files/expected/hello.dart delete mode 100644 modules_dart/transform/test/transform/inliner_for_test/absolute_url_expression_files/hello.dart delete mode 100644 modules_dart/transform/test/transform/inliner_for_test/absolute_url_expression_files/template.css delete mode 100644 modules_dart/transform/test/transform/inliner_for_test/absolute_url_expression_files/template.html delete mode 100644 modules_dart/transform/test/transform/inliner_for_test/all_tests.dart delete mode 100644 modules_dart/transform/test/transform/inliner_for_test/false_match_files/hello.dart delete mode 100644 modules_dart/transform/test/transform/inliner_for_test/false_match_files/template.css delete mode 100644 modules_dart/transform/test/transform/inliner_for_test/false_match_files/template.html delete mode 100644 modules_dart/transform/test/transform/inliner_for_test/multiline_template/hello.dart delete mode 100644 modules_dart/transform/test/transform/inliner_for_test/multiple_style_urls_files/expected/hello.dart delete mode 100644 modules_dart/transform/test/transform/inliner_for_test/multiple_style_urls_files/hello.dart delete mode 100644 modules_dart/transform/test/transform/inliner_for_test/multiple_style_urls_files/template.css delete mode 100644 modules_dart/transform/test/transform/inliner_for_test/multiple_style_urls_files/template.html delete mode 100644 modules_dart/transform/test/transform/inliner_for_test/multiple_style_urls_files/template_other.css delete mode 100644 modules_dart/transform/test/transform/inliner_for_test/no_modify_files/hello.dart delete mode 100644 modules_dart/transform/test/transform/inliner_for_test/no_modify_files/hello_part.dart delete mode 100644 modules_dart/transform/test/transform/inliner_for_test/prop_annotations_files/hello.dart delete mode 100644 modules_dart/transform/test/transform/inliner_for_test/prop_annotations_files/template.css delete mode 100644 modules_dart/transform/test/transform/inliner_for_test/split_url_expression_files/hello.dart delete mode 100644 modules_dart/transform/test/transform/inliner_for_test/split_url_expression_files/template.html delete mode 100644 modules_dart/transform/test/transform/inliner_for_test/url_expression_files/hello.dart delete mode 100644 modules_dart/transform/test/transform/inliner_for_test/url_expression_files/template.html delete mode 100644 modules_dart/transform/test/transform/integration/all_tests.dart delete mode 100644 modules_dart/transform/test/transform/integration/deferred_files/bar.dart delete mode 100644 modules_dart/transform/test/transform/integration/deferred_files/dep.dart delete mode 100644 modules_dart/transform/test/transform/integration/deferred_files/expected/bar.ngfactory.dart delete mode 100644 modules_dart/transform/test/transform/integration/deferred_files/expected/output.dart delete mode 100644 modules_dart/transform/test/transform/integration/deferred_files/index.dart delete mode 100644 modules_dart/transform/test/transform/integration/directive_chain_files/bar.dart delete mode 100644 modules_dart/transform/test/transform/integration/directive_chain_files/baz.dart delete mode 100644 modules_dart/transform/test/transform/integration/directive_chain_files/expected/bar.ngfactory.dart delete mode 100644 modules_dart/transform/test/transform/integration/directive_chain_files/foo.dart delete mode 100644 modules_dart/transform/test/transform/integration/directive_chain_files/index.dart delete mode 100644 modules_dart/transform/test/transform/integration/directive_dep_files/bar.dart delete mode 100644 modules_dart/transform/test/transform/integration/directive_dep_files/expected/bar.ngfactory.dart delete mode 100644 modules_dart/transform/test/transform/integration/directive_dep_files/foo.dart delete mode 100644 modules_dart/transform/test/transform/integration/directive_dep_files/index.dart delete mode 100644 modules_dart/transform/test/transform/integration/empty_ng_deps_files/bar.dart delete mode 100644 modules_dart/transform/test/transform/integration/empty_ng_deps_files/expected/bar.ngfactory.dart delete mode 100644 modules_dart/transform/test/transform/integration/empty_ng_deps_files/expected/foo.ngfactory.dart delete mode 100644 modules_dart/transform/test/transform/integration/empty_ng_deps_files/foo.dart delete mode 100644 modules_dart/transform/test/transform/integration/list_of_types_files/bar.dart delete mode 100644 modules_dart/transform/test/transform/integration/list_of_types_files/expected/bar.ngfactory.dart delete mode 100644 modules_dart/transform/test/transform/integration/list_of_types_files/foo.dart delete mode 100644 modules_dart/transform/test/transform/integration/list_of_types_files/index.dart delete mode 100644 modules_dart/transform/test/transform/integration/simple_annotation_files/bar.dart delete mode 100644 modules_dart/transform/test/transform/integration/simple_annotation_files/expected/bar.ngfactory.dart delete mode 100644 modules_dart/transform/test/transform/integration/simple_annotation_files/expected/index.ngfactory.dart delete mode 100644 modules_dart/transform/test/transform/integration/simple_annotation_files/index.dart delete mode 100644 modules_dart/transform/test/transform/integration/synthetic_ctor_files/bar.dart delete mode 100644 modules_dart/transform/test/transform/integration/synthetic_ctor_files/expected/bar.ngfactory.dart delete mode 100644 modules_dart/transform/test/transform/integration/synthetic_ctor_files/index.dart delete mode 100644 modules_dart/transform/test/transform/integration/two_annotations_files/bar.dart delete mode 100644 modules_dart/transform/test/transform/integration/two_annotations_files/expected/bar.ngfactory.dart delete mode 100644 modules_dart/transform/test/transform/integration/two_annotations_files/index.dart delete mode 100644 modules_dart/transform/test/transform/integration/two_deps_files/bar.dart delete mode 100644 modules_dart/transform/test/transform/integration/two_deps_files/expected/bar.ngfactory.dart delete mode 100644 modules_dart/transform/test/transform/integration/two_deps_files/foo.dart delete mode 100644 modules_dart/transform/test/transform/integration/two_deps_files/index.dart delete mode 100644 modules_dart/transform/test/transform/reflection_remover/abstract_method_annotation_files/index.dart delete mode 100644 modules_dart/transform/test/transform/reflection_remover/all_tests.dart delete mode 100644 modules_dart/transform/test/transform/reflection_remover/arrow_annotation_files/index.dart delete mode 100644 modules_dart/transform/test/transform/reflection_remover/bootstrap_files/README.md delete mode 100644 modules_dart/transform/test/transform/reflection_remover/bootstrap_files/expected/index.dart delete mode 100644 modules_dart/transform/test/transform/reflection_remover/bootstrap_files/index.dart delete mode 100644 modules_dart/transform/test/transform/reflection_remover/combinator_files/expected/index.dart delete mode 100644 modules_dart/transform/test/transform/reflection_remover/combinator_files/index.dart delete mode 100644 modules_dart/transform/test/transform/reflection_remover/debug_files/README.md delete mode 100644 modules_dart/transform/test/transform/reflection_remover/debug_files/expected/index.dart delete mode 100644 modules_dart/transform/test/transform/reflection_remover/debug_files/index.dart delete mode 100644 modules_dart/transform/test/transform/reflection_remover/debug_mirrors_files/README.md delete mode 100644 modules_dart/transform/test/transform/reflection_remover/debug_mirrors_files/expected/index.dart delete mode 100644 modules_dart/transform/test/transform/reflection_remover/debug_mirrors_files/index.dart delete mode 100644 modules_dart/transform/test/transform/reflection_remover/deferred_bootstrap_files/expected/index.dart delete mode 100644 modules_dart/transform/test/transform/reflection_remover/deferred_bootstrap_files/index.dart delete mode 100644 modules_dart/transform/test/transform/reflection_remover/function_annotation_files/expected/index.dart delete mode 100644 modules_dart/transform/test/transform/reflection_remover/function_annotation_files/index.dart delete mode 100644 modules_dart/transform/test/transform/reflection_remover/index.dart delete mode 100644 modules_dart/transform/test/transform/reflection_remover/log_mirrors_files/README.md delete mode 100644 modules_dart/transform/test/transform/reflection_remover/log_mirrors_files/expected/index.dart delete mode 100644 modules_dart/transform/test/transform/reflection_remover/log_mirrors_files/index.dart delete mode 100644 modules_dart/transform/test/transform/reflection_remover/method_annotation_files/expected/index.dart delete mode 100644 modules_dart/transform/test/transform/reflection_remover/method_annotation_files/index.dart delete mode 100644 modules_dart/transform/test/transform/reflection_remover/native_annotation_files/index.dart delete mode 100644 modules_dart/transform/test/transform/reflection_remover/reflection_remover_files/README.md delete mode 100644 modules_dart/transform/test/transform/reflection_remover/reflection_remover_files/expected/index.dart delete mode 100644 modules_dart/transform/test/transform/reflection_remover/reflection_remover_files/index.dart delete mode 100644 modules_dart/transform/test/transform/reflection_remover/verbose_files/expected/index.dart delete mode 100644 modules_dart/transform/test/transform/stylesheet_compiler/all_tests.dart delete mode 100644 modules_dart/transform/test/transform/template_compiler/all_tests.dart delete mode 100644 modules_dart/transform/test/transform/template_compiler/directive_aliases_files/hello1.ng_deps.dart delete mode 100644 modules_dart/transform/test/transform/template_compiler/directive_aliases_files/hello2.ng_deps.dart delete mode 100644 modules_dart/transform/test/transform/template_compiler/directive_event_files/expected/hello.ng_deps.dart delete mode 100644 modules_dart/transform/test/transform/template_compiler/directive_event_files/hello.ng_deps.dart delete mode 100644 modules_dart/transform/test/transform/template_compiler/event_files/expected/hello.ng_deps.dart delete mode 100644 modules_dart/transform/test/transform/template_compiler/event_files/hello.ng_deps.dart delete mode 100644 modules_dart/transform/test/transform/template_compiler/inline_expression_files/expected/hello.ng_deps.dart delete mode 100644 modules_dart/transform/test/transform/template_compiler/inline_expression_files/hello.ng_deps.dart delete mode 100644 modules_dart/transform/test/transform/template_compiler/inline_method_files/expected/hello.ng_deps.dart delete mode 100644 modules_dart/transform/test/transform/template_compiler/inline_method_files/hello.ng_deps.dart delete mode 100644 modules_dart/transform/test/transform/template_compiler/one_directive_files/expected/hello.ng_deps.dart delete mode 100644 modules_dart/transform/test/transform/template_compiler/one_directive_files/hello.ng_deps.dart delete mode 100644 modules_dart/transform/test/transform/template_compiler/registrations_files/expected/registrations.ng_deps.dart delete mode 100644 modules_dart/transform/test/transform/template_compiler/registrations_files/registrations.ng_deps.dart delete mode 100644 modules_dart/transform/test/transform/template_compiler/url_expression_files/expected/hello.ng_deps.dart delete mode 100644 modules_dart/transform/test/transform/template_compiler/url_expression_files/hello.ng_deps.dart delete mode 100644 modules_dart/transform/test/transform/template_compiler/url_method_files/expected/hello.ng_deps.dart delete mode 100644 modules_dart/transform/test/transform/template_compiler/url_method_files/hello.ng_deps.dart delete mode 100644 modules_dart/transform/test/transform/template_compiler/with_prefix_files/expected/goodbye.ng_deps.dart delete mode 100644 modules_dart/transform/test/transform/template_compiler/with_prefix_files/expected/hello.ng_deps.dart delete mode 100644 modules_dart/transform/test/transform/template_compiler/with_prefix_files/goodbye.ng_deps.dart delete mode 100644 modules_dart/transform/test/transform/template_compiler/with_prefix_files/hello.ng_deps.dart delete mode 100644 modules_dart/transform/test/transform/transform.e2e.server.spec.dart delete mode 100644 modules_dart/transform/test/transform/transform.server.spec.dart delete mode 100644 modules_dart/transform/test/transform/transform.unittest.server.spec.dart delete mode 100644 protractor-dart2js.conf.js delete mode 100644 protractor-ddc.conf.js delete mode 100644 pubspec.yaml diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 3f1ed7796d..606d75020c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -95,7 +95,7 @@ Before you submit your Pull Request (PR) consider the following guidelines: * In GitHub, send a pull request to `angular:master`. * If we suggest changes then: * Make the required updates. - * Re-run the Angular 2 test suites for JS and Dart to ensure tests are still passing. + * Re-run the Angular 2 test suites to ensure tests are still passing. * Rebase your branch and force push to your GitHub repository (this will update your Pull Request): ```shell diff --git a/DEVELOPER.md b/DEVELOPER.md index 6085ac6cf6..3159aa5a40 100644 --- a/DEVELOPER.md +++ b/DEVELOPER.md @@ -5,8 +5,7 @@ JS and Dart versions. It also explains the basic mechanics of using `git`, `node * [Prerequisite Software](#prerequisite-software) * [Getting the Sources](#getting-the-sources) -* [Environment Variable Setup](#environment-variable-setup) -* [Installing NPM Modules and Dart Packages](#installing-npm-modules-and-dart-packages) +* [Installing NPM Modules](#installing-npm-modules) * [Building](#building) * [Running Tests Locally](#running-tests-locally) @@ -27,15 +26,6 @@ following products on your development machine: (version `>=3.5.3 <4.0`), which comes with Node. Depending on your system, you can install Node either from source or as a pre-packaged bundle. -* *Optional*: [Dart](https://www.dartlang.org) (version `>=1.13.2 <2.0.0`), specifically the Dart SDK and - Dartium (a version of [Chromium](http://www.chromium.org) with native support for Dart through - the Dart VM). Visit Dart's [Downloads page](https://www.dartlang.org/downloads) page for - instructions. You can also download both **stable** and **dev** channel versions from the - [download archive](https://www.dartlang.org/downloads/archive/). In that case, on Windows, Dart - must be added to the `PATH` (e.g. `path-to-dart-sdk-folder\bin`) and a new `DARTIUM_BIN` - environment variable must be created, pointing to the executable (e.g. - `path-to-dartium-folder\chrome.exe`). - * [Java Development Kit](http://www.oracle.com/technetwork/es/java/javase/downloads/index.html) which is used to execute the selenium standalone server for e2e testing. @@ -60,42 +50,7 @@ cd angular # Add the main Angular repository as an upstream remote to your repository: git remote add upstream https://github.com/angular/angular.git ``` - -## Environment Variable Setup - -Define the environment variables listed below. These are mainly needed for the testing. The -notation shown here is for [`bash`](http://www.gnu.org/software/bash); adapt as appropriate for -your favorite shell. - -Examples given below of possible values for initializing the environment variables assume **Mac OS -X** and that you have installed the Dart Editor in the directory named by -`DART_EDITOR_DIR=/Applications/dart`. This is only for illustrative purposes. - -```shell -# DARTIUM_BIN: path to a Dartium browser executable; used by Karma to run Dart tests -export DARTIUM_BIN="$DART_EDITOR_DIR/chromium/Chromium.app/Contents/MacOS/Chromium" -``` - -Add the Dart SDK `bin` directory to your path and/or define `DART_SDK` (this is also detailed -[here](https://www.dartlang.org/tools/pub/installing.html)): - -```shell -# DART_SDK: path to a Dart SDK directory -export DART_SDK="$DART_EDITOR_DIR/dart-sdk" - -# Update PATH to include the Dart SDK bin directory -PATH+=":$DART_SDK/bin" -``` - -And specify where the pub’s dependencies are downloaded. By default, this directory is located under .pub_cache -in your home directory (on Mac and Linux), or in AppData\Roaming\Pub\Cache (on Windows). - -```shell -# PUB_CACHE: location of pub dependencies -export PUB_CACHE="/Users//.pub-cache" -``` - -## Installing NPM Modules and Dart Packages +## Installing NPM Modules Next, install the JavaScript modules and Dart packages needed to build and test Angular: diff --git a/README.md b/README.md index 47f776eb59..2880d47626 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,9 @@ Angular ========= Angular is a development platform for building mobile and desktop web applications. This is the -repository for [Angular 2][ng2], both the JavaScript (JS) and [Dart][dart] versions. +repository for [Angular 2][ng2] Typescript/JavaScript (JS). + +Angular2 for [Dart][dart] can be found at [dart-lang/angular2][ng2dart]. Angular 2 is currently in **Release Candidate**. @@ -34,3 +36,4 @@ guidelines for [contributing][contributing] and then check out one of our issues [ng2]: http://angular.io [ngDart]: http://angulardart.org [ngJS]: http://angularjs.org +[ng2dart]: https://github.com/dart-lang/angular2 diff --git a/TOOLS_DART.md b/TOOLS_DART.md deleted file mode 100644 index c61b97c25d..0000000000 --- a/TOOLS_DART.md +++ /dev/null @@ -1,376 +0,0 @@ -# Developer Tools for Dart - -Use these tools and techniques to increase your app's performance -and reliability. - -* [Angular debugging tools](#angular-debugging-tools) -* [Code size](#code-size) -* [Performance](#performance) - - -## Angular debugging tools - -Starting with alpha.38, Angular provides a set of debugging tools -that are accessible from any browser's developer console. -In Chrome, you can get to the dev console by pressing -Ctrl + Shift + J (on Mac: Cmd + Opt + J). - -### Enabling the debugging tools - -By default the debugging tools are disabled. -Enable the debugging tools as follows: - -```dart -import 'package:angular2/platform/browser.dart'; - -main() async { - var appRef = await bootstrap(Application); - enableDebugTools(appRef); -} -``` - - - - -### Using the debugging tools - -In the browser, open the dev console. The top-level object is called `ng` and -contains more specific tools inside it. - -For example, to run the change detection profiler on your app: - -```javascript -// In the dev console: -ng.profiler.timeChangeDetection(); -``` - -The [Change detection profiler](#change-detection-profiler) section -has more details. - - - -## Code size - -Code must be downloaded, parsed, and executed. Too much code can lead to -slow application start-up time, especially on slow networks and low-end devices. -The tools and techniques in this section can help you to identify -unnecessarily large code and to reduce code size. - -### Finding contributors to code size - -Options for investigating code size include the `--dump-info` dart2js option, -ng2soyc, `reflector.trackUsage()`, and code coverage information -from the Dart VM. - -#### Use --dump-info - -The `--dump-info` option of `dart2js` outputs information about what happened -during compilation. You can specify `--dump-info` in `pubspec.yaml`: - -```yaml -transformers: -... -- $dart2js: - commandLineOptions: - - --dump-info -``` - -The [Dump Info Visualizer](https://github.com/dart-lang/dump-info-visualizer) -can help you analyze the output. -For more information, see the -[dart2js_info API reference](http://dart-lang.github.io/dart2js_info/doc/api/). - -#### Use ng2soyc.dart - -[ng2soyc](https://github.com/angular/ng2soyc.dart) is a utility for analyzing -code size contributors in Angular 2 applications. It groups code size by -library and, assuming your library names follow -[standard naming conventions](https://www.dartlang.org/articles/style-guide/#do-prefix-library-names-with-the-package-name-and-a-dot-separated-path) -(package.library.sublibrary...), gives the code size breakdown at -each level. To reduce noise in the output of very large apps, ng2soyc provides -an option to hide libraries that are too small, so you can focus on the biggest -contributors. - -#### Find unused reflection data - -Your app might have types that are annotated with `@Component` or `@Injectable` -but never used. -To find these unused types, use `reflector.trackUsage()` and then, -after exercising your app, `reflector.listUnusedKeys()`. -For example: - -``` -import 'package:angular2/src/core/reflection/reflection.dart'; -... -main() async { - reflector.trackUsage(); - await bootstrap(AppComponent); - print('Unused keys: ${reflector.listUnusedKeys()}'); -} -``` - -When you run that code (in Dartium or another browser), -you'll see a list of types that Angular _can_ inject but hasn't needed to. -Consider removing those types or their `@Component`/`@Injectable` annotation -to decrease your app's code size. - -Three conditions must be true for `listUnusedKeys()` to return helpful data: - -1. The angular2 transformer must run on the app. -2. If you're running a JavaScript version of the app, - the app must not be minified, so that the names are readable. -3. You must exercise your app in as many ways as possible - before calling `listUnusedKeys()`. - Otherwise, you might get false positives: - keys that haven't been used only because you didn't exercise - the relevant feature of the app. - -To run the angular2 transformer, first specify it in `pubspec.yaml`: - -``` -name: hello_world -... -transformers: -- angular2: - entry_points: web/main.dart -``` - -Then use pub to run the transformer. If you use `pub serve`, -it provides both Dart and unminified (by default) JavaScript versions. -If you want to serve actual files, then use `pub build` in debug mode -to generate Dart and unminified JavaScript files: -`pub build --mode=debug`. - -The `reflector.trackUsage()` method makes Angular track the reflection -information used by the app. Reflection information (`ReflectionInfo`) is a data -structure that stores information that Angular uses for locating DI factories -and for generating change detectors and other code related to a -given type. - -#### Use code coverage to find dead code - -When running in Dartium (or in the Dart VM, in general) you can request code -coverage information from the VM. You can either use -[observatory](https://www.dartlang.org/tools/observatory/) or download -the coverage file and use your own tools to inspect it. Lines of code that are -not covered are top candidates for dead code. - -Keep in mind, however, that uncovered code is not sufficient evidence of dead -code, only necessary evidence. It is perfectly possible that you simply didn't -exercise your application in a way that triggers the execution of uncovered -code. A common example is error handling code. Just because your testing never -encountered an error does not mean the error won't happen in production. You -therefore don't have to rush and remove all the `catch` blocks. - -### Reducing code size - -To reduce code size, you can disable reflection, -enable minification, and manually remove dead code. -You can also try less safe options such as -telling dart2js to trust type annotations. - - -#### Disable reflection - -`dart:mirrors` allows discovering program metadata at runtime. However, this -means that `dart2js` needs to retain that metadata and thus increase the size -of resulting JS output. In practice, however, it is possible to extract most -metadata necessary for your metaprogramming tasks statically using a -transformer and `package:analyzer`, and act on it before compiling to JS. - -#### Enable minification - -Minification shortens all your `longMethodNames` into 2- or 3-letter long -symbols. `dart2js` ensures that this kind of renaming is done safely, without -breaking the functionality of your programs. You can enable it in `pubspec.yaml` -under `$dart2js` transformer: - -```yaml -transformers: -... -- $dart2js: - minify: true -``` - -#### Manually remove dead code - -`dart2js` comes with dead code elimination out-of-the-box. However, it may not -always be able to tell if a piece of code could be used. Consider the following -example: - -```dart -/// This function decides which serialization format to use -void setupSerializers() { - if (server.doYouSupportProtocolBuffers()) { - useProtobufSerializers(); - } else { - useJsonSerializers(); - } -} -``` - -In this example the application asks the server what kind of serialization -format it uses and dynamically chooses one or the other. `dart2js` can't -tell whether the server responds with yes or no, so it must retain both -kinds of serializers. However, if you know that your server supports -protocol buffers, you can remove that `if` block entirely and default to -protocol buffers. - -Code coverage (see above) is a good way to find dead code in your app. - -#### Unsafe options - -Dart also provides more aggressive optimization options. However, you have to -be careful when using them and as of today the benefits aren't that clear. If -your type annotations are inaccurate you may end up with non-Darty runtime -behavior, including the classic "undefined is not a function" tautology, as -well as the "keep on truckin'" behavior, e.g. `null + 1 == 1` and -`{} + [] == 0`. - -`--trust-type-annotations` tells `dart2js` to trust that your type annotations -are correct. So if you have a function `foo(Bar bar)` the compiler can omit the -check that `bar` is truly `Bar` when calling methods on it. - -`--trust-primitives` tells `dart2js` that primitive types, such as numbers and -booleans are never `null` when performing arithmetic, and that your program -does not run into range error when operating on lists, letting the compiler -remove some of the error checking code. - -Specify these options in `pubspec.yaml`. - -Example: - -```yaml -transformers: -... -- $dart2js: - commandLineOptions: - - --trust-type-annotations - - --trust-primitives -``` - -## Performance - -### Change detection profiler - -If your application is janky (it misses frames) or is slow according to other -metrics, you need to find out why. This tool helps by measuring the average -speed of _change detection_, a phase in Angular's -lifecycle that detects changes in values that are bound to the UI. -Janky UI updates can result from slowness either in _computing_ the changes or -in _applying_ those changes to the UI. - -For your app to be performant, the process of _computing_ changes must be very -fast—preferably **under 3 milliseconds**. -Fast change computation leaves room for -the application logic, UI updates, and browser rendering pipeline -to fit within a 16 ms frame (assuming a target frame rate of 60 FPS). - -The change detection profiler repeatedly performs change detection -without invoking any user actions, such as clicking buttons or entering -text in input fields. It then computes the average amount of time -(in milliseconds) to perform a single cycle of change detection and -prints that to the console. This number depends on the current state of the UI. You are likely to see different numbers -as you go from one screen in your application to another. - -#### Running the profiler - -Before running the profiler, enable the debugging tools -and put the app into the state you want to measure: - -1. If you haven't already done so, - [enable the debugging tools](#enabling-the-debugging-tools). -2. Navigate the app to a screen whose performance you want to profile. -3. Make sure the screen is in a state that you want to measure. - For example, you might want to profile the screen several times, - with different amounts and kinds of data. - -To run the profiler, enter the following in the dev console: - -```javascript -ng.profiler.timeChangeDetection(); -``` - -The results are visible in the console. - - -#### Recording CPU profiles - -To record a profile, pass `{record: true}` to `timeChangeDetection()`: - -```javascript -ng.profiler.timeChangeDetection({record: true}); -``` - -Then open the **Profiles** tab. The recorded profile has the title -**Change Detection**. In Chrome, if you record the profile repeatedly, all the -profiles are nested under Change Detection. - - -#### Interpreting the numbers - -In a properly designed application, repeated attempts to detect changes without -any user actions result in no changes to the UI. It is -also desirable to have the cost of a user action be proportional to the amount -of UI changes required. For example, popping up a menu with 5 items should be -vastly faster than rendering a table of 500 rows and 10 columns. Therefore, -change detection with no UI updates should be as fast as possible. - -#### Investigating slow change detection - -So you found a screen in your application on which the profiler reports a very -high number (i.e. >3ms). This is where a recorded CPU profile can help. Enable -recording while profiling: - -```javascript -ng.profiler.timeChangeDetection({record: true}); -``` - -Then look for hot spots using -[Chrome CPU profiler](https://developer.chrome.com/devtools/docs/cpu-profiling). - -#### Reducing change detection cost - -There are many reasons for slow change detection. To gain intuition about -possible causes it helps to understand how change detection works. Such a -discussion is outside the scope of this document, -but here are some key concepts. - - - -By default, Angular uses a _dirty checking_ mechanism to find model changes. -This mechanism involves evaluating every bound expression that's active on the -UI. These usually include text interpolation via `{{expression}}` and property -bindings via `[prop]="expression"`. If any of the evaluated expressions are -costly to compute, they might contribute to slow change detection. A good way to -speed things up is to use plain class fields in your expressions and avoid any -kind of computation. For example: - -```dart -@View( - template: '' -) -class FancyButton { - // GOOD: no computation, just returns the value - bool isEnabled; - - // BAD: computes the final value upon request - String _title; - String get title => _title.trim().toUpperCase(); -} -``` - -Most cases like these can be solved by precomputing the value and storing the -final value in a field. - -Angular also supports a second type of change detection: the _push_ model. In -this model, Angular does not poll your component for changes. Instead, the -component tells Angular when it changes, and only then does Angular perform -the update. This model is suitable in situations when your data model uses -observable or immutable objects. - - diff --git a/modules_dart/README.md b/modules_dart/README.md deleted file mode 100644 index 189330257b..0000000000 --- a/modules_dart/README.md +++ /dev/null @@ -1,34 +0,0 @@ -This directory contains pure Dart packages that use standard pub layout. - -# Working with an existing package - -1. Run `gulp build.dart` -1. Open the package in any Dart IDE of your choice -1. Tada! - -You do not need to rerun step 1 if you are only making changes in -`modules_dart`. However, you do need to run it again after you make a change -in `modules`. This is because these packages depend on code inside the `dist` -directory via `dependency_overrides`. Code in `modules` need to be transpiled -into `dist` before the IDE can "feel" your changes in `modules`. - -# Creating a new package - -1. Create a new directory with its own `pubspec.yaml` and standard pub layout. -1. Add both a normal dependency on `angular2` _and_ a `dependency_overrides`, - like this: - -```yaml -version: 0.0.0 -dependencies: - angular2: '0.0.0' -dependency_overrides: - angular2: - path: ../../dist/dart/angular2 -``` - -The publishing script will automatically rewrite version numbers, so use -`0.0.0` both for your package and `angular2` version. Similarly, do not -include `authors` and `homepage`, as they will be auto-populated. However, -do provide `description`, `name` (prefixed with `angular2_`), `dependencies`, -and `dev_dependencies`. diff --git a/modules_dart/angular2_testing/README.md b/modules_dart/angular2_testing/README.md deleted file mode 100644 index b6f4ea1965..0000000000 --- a/modules_dart/angular2_testing/README.md +++ /dev/null @@ -1,46 +0,0 @@ -Contains helpers to run unit tests for angular2 components and injectables, -backed by the `package:test` [library](https://pub.dartlang.org/packages/test). - -Usage ------ - - -Update the dev dependencies in your `pubspec.yaml` to include the angular testing -and test packages: - -```yaml -dev_dependencies: - test: '^0.12.6' - angular2_testing: any - -``` - -Then in your test files, use angular2_testing helpers in place of `setUp` and `test`: - -```dart -import 'package:test/test.dart'; -import 'package:angular2_testing/angular2_testing.dart'; - -void main() { - // This must be called at the beginning of your tests. - initAngularTests(); - - // Initialize the injection tokens you will use in your tests. - setUpProviders(() => [provide(MyToken, useValue: 'my string'), TestService]); - - // You can then get tokens from the injector via ngSetUp and ngTest. - ngSetUp((TestService testService) { - testService.initialize(); - }); - - ngTest('can grab injected values', (@Inject(MyToken) token, TestService testService) { - expect(token, equals('my string')); - expect(testService.status, equals('ready')); - }); -} -``` - -Examples --------- - -A sample test is available in `test/angular2_testing_test.dart`. diff --git a/modules_dart/angular2_testing/lib/angular2_testing.dart b/modules_dart/angular2_testing/lib/angular2_testing.dart deleted file mode 100644 index f59974a855..0000000000 --- a/modules_dart/angular2_testing/lib/angular2_testing.dart +++ /dev/null @@ -1,120 +0,0 @@ -library angular2_testing.angular2_testing; - -import 'package:test/test.dart'; - -import 'package:angular2/angular2.dart'; -import 'package:angular2/src/core/di/metadata.dart' show InjectMetadata; -import 'package:angular2/src/core/di/reflective_exceptions.dart' show NoAnnotationError; -import 'package:angular2/src/core/reflection/reflection.dart'; -import 'package:angular2/src/core/reflection/reflection_capabilities.dart'; -import 'package:angular2/src/testing/test_injector.dart'; -export 'package:angular2/src/testing/test_component_builder.dart'; -export 'package:angular2/src/testing/test_injector.dart' show inject; -import 'package:angular2/platform/testing/browser.dart'; - -/// One time initialization that must be done for Angular2 component -/// tests. Call before any test methods. -/// -/// Example: -/// -/// ``` -/// main() { -/// initAngularTests(); -/// group(...); -/// } -/// ``` -void initAngularTests() { - reflector.reflectionCapabilities = new ReflectionCapabilities(); - setBaseTestProviders(TEST_BROWSER_PLATFORM_PROVIDERS, TEST_BROWSER_APPLICATION_PROVIDERS); -} - -void _addTestInjectorTearDown() { - // Multiple resets are harmless. - tearDown(() { - _testInjector.reset(); - }); -} - -/// Allows overriding default bindings defined in test_injector.dart. -/// -/// The given function must return a list of DI providers. -/// -/// Example: -/// -/// ``` -/// setUpProviders(() => [ -/// provide(Compiler, useClass: MockCompiler), -/// provide(SomeToken, useValue: myValue), -/// ]); -/// ``` -void setUpProviders(Iterable providerFactory()) { - setUp(() { - try { - _testInjector.addProviders(providerFactory()); - } catch (e) { - throw 'setUpProviders was called after the injector had ' - 'been used in a setUp or test block. This invalidates the ' - 'test injector'; - } - }); - - _addTestInjectorTearDown(); -} - -dynamic _runInjectableFunction(Function fn) { - var params = reflector.parameters(fn); - List tokens = []; - for (var param in params) { - var token = null; - for (var paramMetadata in param) { - if (paramMetadata is Type) { - token = paramMetadata; - } else if (paramMetadata is InjectMetadata) { - token = paramMetadata.token; - } - } - if (token == null) { - throw new NoAnnotationError(fn, params); - } - tokens.add(token); - } - - return _testInjector.execute(tokens, fn); -} - -/// Use the test injector to get bindings and run a function. -/// -/// Example: -/// -/// ``` -/// ngSetUp((SomeToken token) { -/// token.init(); -/// }); -/// ``` -void ngSetUp(Function fn) { - setUp(() async { - await _runInjectableFunction(fn); - }); - - _addTestInjectorTearDown(); -} - -/// Add a test which can use the test injector. -/// -/// Example: -/// -/// ``` -/// ngTest('description', (SomeToken token) { -/// expect(token, equals('expected')); -/// }); -/// ``` -void ngTest(String description, Function fn, - {String testOn, Timeout timeout, skip, Map onPlatform}) { - test(description, () async { - await _runInjectableFunction(fn); - }, testOn: testOn, timeout: timeout, skip: skip, onPlatform: onPlatform); - - _addTestInjectorTearDown(); -} - -final TestInjector _testInjector = getTestInjector(); diff --git a/modules_dart/angular2_testing/pubspec.yaml b/modules_dart/angular2_testing/pubspec.yaml deleted file mode 100644 index 59dc9f6cf2..0000000000 --- a/modules_dart/angular2_testing/pubspec.yaml +++ /dev/null @@ -1,18 +0,0 @@ -name: angular2_testing -description: 'Helpers to run unit tests for angular2 components and injectables.' -version: 0.0.0 -environment: - sdk: '>=1.10.0 <2.0.0' -dependencies: -# This will be overridden by scripts/publish/pubspec_cleaner -# to point to the current version of Angular2. - angular2: - path: '../angular2' -dev_dependencies: - test: '^0.12.6' - quiver: '^0.21.4' -transformers: -# Allows testing with `pub serve` -# See https://github.com/dart-lang/test#testing-with-barback -- test/pub_serve: - $include: test/**_test.dart diff --git a/modules_dart/angular2_testing/test/angular2_testing_test.dart b/modules_dart/angular2_testing/test/angular2_testing_test.dart deleted file mode 100644 index 1d1c218f00..0000000000 --- a/modules_dart/angular2_testing/test/angular2_testing_test.dart +++ /dev/null @@ -1,117 +0,0 @@ -// Because Angular is using dart:html, we need these tests to run on an actual -// browser. This means that it should be run with `-p dartium` or `-p chrome`. -@TestOn('browser') -import 'package:angular2/angular2.dart' - show Component, View, NgFor, provide, Inject, Injectable, Optional; - -import 'package:test/test.dart'; -import 'package:angular2_testing/angular2_testing.dart'; - -// This is the component we will be testing. -@Component(selector: 'test-cmp') -@View(directives: const [NgFor]) -class TestComponent { - List items; - TestComponent() { - this.items = [1, 2]; - } -} - -@Injectable() -class TestService { - String status = 'not ready'; - - init() { - this.status = 'ready'; - } -} - -@Component(selector: 'external-template-cmp') -@View(templateUrl: 'test_template.html') -class ExternalTemplateComponent { - ExternalTemplateComponent() { - } -} - -class MyToken {} - -const TEMPLATE = - '
{{item.toString()}};
'; - -void main() { - initAngularTests(); - - setUpProviders(() => [provide(MyToken, useValue: 'my string'), TestService]); - - test('normal function', () { - var string = 'foo,bar,baz'; - expect(string.split(','), equals(['foo', 'bar', 'baz'])); - }); - - ngTest('can grab injected values', - (@Inject(MyToken) token, TestService testService) { - expect(token, equals('my string')); - expect(testService.status, equals('not ready')); - }); - - group('nested ngSetUp', () { - ngSetUp((TestService testService) { - testService.init(); - }); - - ngTest('ngSetUp modifies injected services', (TestService testService) { - expect(testService.status, equals('ready')); - }); - }); - - ngTest('create a component using the TestComponentBuilder', - (TestComponentBuilder tcb) async { - var rootTC = await tcb - .overrideTemplate(TestComponent, TEMPLATE) - .createAsync(TestComponent); - - rootTC.detectChanges(); - expect(rootTC.debugElement.nativeElement.text, equals('1;2;')); - }); - - ngTest('should reflect added elements', (TestComponentBuilder tcb) async { - var rootTC = await tcb - .overrideTemplate(TestComponent, TEMPLATE) - .createAsync(TestComponent); - - rootTC.detectChanges(); - (rootTC.debugElement.componentInstance.items as List).add(3); - rootTC.detectChanges(); - - expect(rootTC.debugElement.nativeElement.text, equals('1;2;3;')); - }); - - ngTest('should allow a component using a templateUrl', (TestComponentBuilder tcb) async { - var rootTC = await tcb - .createAsync(ExternalTemplateComponent); - - rootTC.detectChanges(); - - expect(rootTC.debugElement.nativeElement.text, equals('from external template\n')); - }); - - group('expected failures', () { - ngTest('no type in param list', (notTyped) { - expect(1, equals(2)); - }); - - ngSetUp((TestService testService) { - testService.init(); - }); - - // This would fail, since setUpProviders is used after a call to ngSetUp has already - // initialized the injector. - group('nested', () { - setUpProviders(() => [TestService]); - - test('foo', () { - expect(1 + 1, equals(2)); - }); - }); - }, skip: 'expected failures'); -} diff --git a/modules_dart/angular2_testing/test/test_template.html b/modules_dart/angular2_testing/test/test_template.html deleted file mode 100644 index 4c2b23755f..0000000000 --- a/modules_dart/angular2_testing/test/test_template.html +++ /dev/null @@ -1 +0,0 @@ -from external template diff --git a/modules_dart/payload/hello_world/pubspec.yaml b/modules_dart/payload/hello_world/pubspec.yaml deleted file mode 100644 index c46afe332a..0000000000 --- a/modules_dart/payload/hello_world/pubspec.yaml +++ /dev/null @@ -1,23 +0,0 @@ -name: hello_world -environment: - sdk: '>=1.10.0 <2.0.0' -dependencies: - observe: '^0.13.1' - angular2: any - browser: '^0.10.0' -dependency_overrides: - angular2: - path: ../../../dist/dart/angular2 -transformers: -- angular2/transform/codegen: - platform_directives: 'package:angular2/src/common/directives.dart#CORE_DIRECTIVES' -- angular2/transform/reflection_remover: - $include: [web/index.dart] -- $dart2js: - minify: true - commandLineOptions: - - --show-package-warnings - - --trust-type-annotations - - --trust-primitives - # Uncomment to generate summaries from dart2js - # - --dump-info diff --git a/modules_dart/payload/hello_world/web/index.dart b/modules_dart/payload/hello_world/web/index.dart deleted file mode 100644 index 6c6918b076..0000000000 --- a/modules_dart/payload/hello_world/web/index.dart +++ /dev/null @@ -1,40 +0,0 @@ -library hello_world.index; - -import "package:angular2/platform/browser.dart" - show AngularEntrypoint, bootstrap; -import "package:angular2/core.dart" - show Component, Directive, ElementRef, Injectable, Renderer; - -@AngularEntrypoint("Hello World Entrypoint") -main() { - bootstrap(HelloCmp); -} - -@Injectable() -class GreetingService { - String greeting = "hello"; -} - -@Directive(selector: "[red]") -class RedDec { - RedDec(ElementRef el, Renderer renderer) { - renderer.setElementStyle(el.nativeElement, "color", "red"); - } -} - -@Component( - selector: "hello-app", - viewProviders: const [GreetingService], - template: - '''
{{greeting}} world!
- ''', - directives: const [RedDec]) -class HelloCmp { - String greeting; - HelloCmp(GreetingService service) { - this.greeting = service.greeting; - } - void changeGreeting() { - this.greeting = "howdy"; - } -} diff --git a/modules_dart/payload/hello_world/web/index.html b/modules_dart/payload/hello_world/web/index.html deleted file mode 100644 index 119f5ead0f..0000000000 --- a/modules_dart/payload/hello_world/web/index.html +++ /dev/null @@ -1,12 +0,0 @@ - - - Hello Angular 2.0 - - - Loading... - - - - - - diff --git a/modules_dart/transform/lib/extract_messages.dart b/modules_dart/transform/lib/extract_messages.dart deleted file mode 100644 index ce31362336..0000000000 --- a/modules_dart/transform/lib/extract_messages.dart +++ /dev/null @@ -1,118 +0,0 @@ -import 'package:build/build.dart'; -import 'package:analyzer/src/generated/element.dart'; -import 'src/transform/common/url_resolver.dart'; - -import 'dart:async'; -import 'package:angular2/i18n.dart'; -import 'package:angular2/src/compiler/expression_parser/parser.dart'; -import 'package:angular2/src/compiler/expression_parser/lexer.dart'; -import 'package:angular2/src/compiler/html_parser.dart'; - -/** - * An command-line utility extracting i18n messages from an application. - * - * For instance, the following command will extract all the messages from the 'my-app-package' package, where - * index.dart is the entry point, and will serialize them into i18n-messages.xml. - * - * pub run packages/angular2/extract_messages.dart 'my-app-package' 'web/src/index.dart' 'i18n-messages.xml' - */ -main(List args) async { - final input = new InputSet(args[0], [args[1]]); - final output = new AssetId(args[0], args[2]); - - await build(new PhaseGroup.singleAction(new I18nMessageExtractorBuilder(output), input)); -} - -class I18nMessageExtractorBuilder implements Builder { - final AssetId outputAssetId; - - I18nMessageExtractorBuilder(this.outputAssetId); - - Future build(BuildStep buildStep) async { - final resolver = await buildStep.resolve(buildStep.input.id); - final entryLib = resolver.getLibrary(buildStep.input.id); - - final extractor = new I18nMessageExtractor((path) => buildStep.readAsString(path)); - await extractor.processLibrary(entryLib); - resolver.release(); - - if (extractor.errors.length > 0) { - print("Errors:"); - extractor.errors.forEach(print); - throw "Failed to extract messages"; - - } else { - await buildStep.writeAsString(new Asset(outputAssetId, extractor.output)); - } - } - - List declareOutputs(AssetId inputId) => [outputAssetId]; -} - -class I18nMessageExtractor { - final urlResovler = createOfflineCompileUrlResolver(); - final List messages = []; - final List errors = []; - final HtmlParser htmlParser = new HtmlParser(); - final Parser parser = new Parser(new Lexer()); - - final Function readInput; - - I18nMessageExtractor(this.readInput); - - String get output => serializeXmb(removeDuplicates(messages)); - - Future processLibrary(LibraryElement el) async { - return Future.wait(el.units.map(processCompilationUnit)); - } - - Future processCompilationUnit(CompilationUnitElement el) async { - return Future.wait(el.types.map(processClass)); - } - - Future processClass(ClassElement el) async { - final baseUrl = (el.source as dynamic).assetId; - final filtered = el.metadata.where((m) { - if (m.element is ConstructorElement) { - final isComponent = m.element.enclosingElement.name == "Component" && - m.element.library.displayName == "angular2.src.core.metadata"; - - final isView = m.element.enclosingElement.name == "View" && - m.element.library.displayName == "angular2.src.core.metadata"; - - return isComponent || isView; - } else { - return false; - } - }); - - return Future.wait(filtered.map((m) => processAnnotation(el, m, baseUrl))); - } - - Future processAnnotation(ClassElement el, ElementAnnotation m, baseUrl) async { - final fields = (m.constantValue as dynamic).fields["(super)"].fields; - final template = fields["template"]; - final templateUrl = fields["templateUrl"]; - - if (template != null && !template.isNull) { - processTemplate(template.toStringValue(), baseUrl.toString()); - } - - if (templateUrl != null && !templateUrl.isNull) { - final value = templateUrl.toStringValue(); - final resolvedPath = urlResovler.resolve(toAssetUri(baseUrl), value); - final template = await readInput(fromUri(resolvedPath)); - processTemplate(template.toStringValue(), baseUrl.toString()); - } - } - - void processTemplate(String template, String sourceUrl) { - final m = new MessageExtractor(htmlParser, parser); - final res = m.extract(template, sourceUrl); - if (res.errors.isNotEmpty) { - errors.addAll(res.errors); - } else { - messages.addAll(res.messages); - } - } -} \ No newline at end of file diff --git a/modules_dart/transform/lib/src/transform/common/annotation_matcher.dart b/modules_dart/transform/lib/src/transform/common/annotation_matcher.dart deleted file mode 100644 index f8c1ebb007..0000000000 --- a/modules_dart/transform/lib/src/transform/common/annotation_matcher.dart +++ /dev/null @@ -1,132 +0,0 @@ -library angular2.transform.common.annotation_matcher; - -import 'package:analyzer/src/generated/ast.dart'; -import 'package:barback/barback.dart' show AssetId; -import 'class_matcher_base.dart'; - -export 'class_matcher_base.dart' show ClassDescriptor; - -/// [ClassDescriptor]s for the default angular annotations that can appear -/// on a class. These classes are re-exported in many places so this covers all -/// the possible libraries which could provide them. -const _INJECTABLES = const [ - const ClassDescriptor( - 'Injectable', 'package:angular2/src/core/di/decorators.dart'), - const ClassDescriptor('Injectable', 'package:angular2/core.dart'), - const ClassDescriptor('Injectable', 'package:angular2/src/core/di.dart'), - const ClassDescriptor('Injectable', 'package:angular2/angular2.dart'), - const ClassDescriptor( - 'Injectable', 'package:angular2/web_worker/worker.dart'), -]; - -const _DIRECTIVES = const [ - const ClassDescriptor( - 'Directive', 'package:angular2/src/core/metadata/directive.dart', - superClass: 'Injectable'), - const ClassDescriptor('Directive', 'package:angular2/src/core/metadata.dart', - superClass: 'Injectable'), - const ClassDescriptor('Directive', 'package:angular2/angular2.dart', - superClass: 'Injectable'), - const ClassDescriptor('Directive', 'package:angular2/core.dart', - superClass: 'Injectable'), - const ClassDescriptor('Directive', 'package:angular2/web_worker/worker.dart', - superClass: 'Injectable'), -]; - -const _COMPONENTS = const [ - const ClassDescriptor( - 'Component', 'package:angular2/src/core/metadata/directive.dart', - superClass: 'Directive'), - const ClassDescriptor('Component', 'package:angular2/src/core/metadata.dart', - superClass: 'Directive'), - const ClassDescriptor('Component', 'package:angular2/angular2.dart', - superClass: 'Directive'), - const ClassDescriptor('Component', 'package:angular2/core.dart', - superClass: 'Directive'), - const ClassDescriptor('Component', 'package:angular2/web_worker/worker.dart', - superClass: 'Directive'), -]; - -const _PIPES = const [ - const ClassDescriptor( - 'Pipe', 'package:angular2/src/core/metadata/directive.dart', - superClass: 'Injectable'), - const ClassDescriptor('Pipe', 'package:angular2/src/core/metadata.dart', - superClass: 'Injectable'), - const ClassDescriptor('Pipe', 'package:angular2/angular2.dart', - superClass: 'Injectable'), - const ClassDescriptor('Pipe', 'package:angular2/core.dart', - superClass: 'Injectable'), - const ClassDescriptor('Pipe', 'package:angular2/web_worker/worker.dart', - superClass: 'Injectable'), -]; - -const _VIEWS = const [ - const ClassDescriptor('View', 'package:angular2/angular2.dart'), - const ClassDescriptor('View', 'package:angular2/web_worker/worker.dart'), - const ClassDescriptor('View', 'package:angular2/core.dart'), - const ClassDescriptor('View', 'package:angular2/src/core/metadata/view.dart'), - const ClassDescriptor('View', 'package:angular2/src/core/metadata.dart'), -]; - -const _ENTRYPOINTS = const [ - const ClassDescriptor('AngularEntrypoint', 'package:angular2/angular2.dart'), - const ClassDescriptor('AngularEntrypoint', 'package:angular2/core.dart'), - const ClassDescriptor( - 'AngularEntrypoint', 'package:angular2/platform/browser.dart'), - const ClassDescriptor( - 'AngularEntrypoint', 'package:angular2/platform/worker_app.dart'), - const ClassDescriptor( - 'AngularEntrypoint', 'package:angular2/platform/browser_static.dart'), - const ClassDescriptor( - 'AngularEntrypoint', 'package:angular2/src/core/angular_entrypoint.dart'), -]; - -/// Checks if a given [Annotation] matches any of the given -/// [ClassDescriptors]. -class AnnotationMatcher extends ClassMatcherBase { - AnnotationMatcher._(classDescriptors) : super(classDescriptors); - - factory AnnotationMatcher() { - return new AnnotationMatcher._([] - ..addAll(_COMPONENTS) - ..addAll(_DIRECTIVES) - ..addAll(_PIPES) - ..addAll(_INJECTABLES) - ..addAll(_VIEWS) - ..addAll(_ENTRYPOINTS)); - } - - bool _implementsWithWarning(Annotation annotation, AssetId assetId, - List interfaces) { - ClassDescriptor descriptor = firstMatch(annotation.name, assetId); - if (descriptor == null) return false; - return implements(descriptor, interfaces, - missingSuperClassWarning: - 'Missing `custom_annotation` entry for `${descriptor.superClass}`.'); - } - - /// Checks if an [Annotation] node implements [Injectable]. - bool isInjectable(Annotation annotation, AssetId assetId) => - _implementsWithWarning(annotation, assetId, _INJECTABLES); - - /// Checks if an [Annotation] node implements [Directive]. - bool isDirective(Annotation annotation, AssetId assetId) => - _implementsWithWarning(annotation, assetId, _DIRECTIVES); - - /// Checks if an [Annotation] node implements [Component]. - bool isComponent(Annotation annotation, AssetId assetId) => - _implementsWithWarning(annotation, assetId, _COMPONENTS); - - /// Checks if an [Annotation] node implements [View]. - bool isView(Annotation annotation, AssetId assetId) => - _implementsWithWarning(annotation, assetId, _VIEWS); - - /// Checks if an [Annotation] node implements [Pipe]. - bool isPipe(Annotation annotation, AssetId assetId) => - _implementsWithWarning(annotation, assetId, _PIPES); - - /// Checks if an [Annotation] node implements [AngularEntrypoint] - bool isEntrypoint(Annotation annotation, AssetId assetId) => - _implementsWithWarning(annotation, assetId, _ENTRYPOINTS); -} diff --git a/modules_dart/transform/lib/src/transform/common/asset_reader.dart b/modules_dart/transform/lib/src/transform/common/asset_reader.dart deleted file mode 100644 index d3ec874c47..0000000000 --- a/modules_dart/transform/lib/src/transform/common/asset_reader.dart +++ /dev/null @@ -1,28 +0,0 @@ -library angular2.transform.common.asset_reader; - -import 'dart:async'; -import 'dart:convert'; - -import 'package:barback/barback.dart'; - -/// A class that allows fetching code using {@link AssetId}s without all the -/// additional baggage of a {@link Transform}. -abstract class AssetReader { - Future readAsString(AssetId id, {Encoding encoding}); - Future hasInput(AssetId id); - - /// Creates an {@link AssetReader} using the `transform`, which should be a - /// {@link Transform} or {@link AggregateTransform}. - factory AssetReader.fromTransform(dynamic transform) => - new _TransformAssetReader(transform); -} - -class _TransformAssetReader implements AssetReader { - final dynamic t; - _TransformAssetReader(this.t); - - Future readAsString(AssetId id, {Encoding encoding}) => - t.readInputAsString(id, encoding: encoding); - - Future hasInput(AssetId id) => t.hasInput(id); -} diff --git a/modules_dart/transform/lib/src/transform/common/async_string_writer.dart b/modules_dart/transform/lib/src/transform/common/async_string_writer.dart deleted file mode 100644 index 96c753cd41..0000000000 --- a/modules_dart/transform/lib/src/transform/common/async_string_writer.dart +++ /dev/null @@ -1,78 +0,0 @@ -library angular2.transform.common.async_string_writer; - -import 'dart:async'; - -import 'package:analyzer/src/generated/java_core.dart'; - -/// [PrintWriter] implementation that allows asynchronous printing via -/// [asyncPrint] and [asyncToString]. See those methods for details. -class AsyncStringWriter extends PrintWriter { - /// All [Future]s we are currently waiting on. - final List> _toAwait = >[]; - final List _bufs; - StringBuffer _curr; - int _asyncCount = 0; - - AsyncStringWriter._(StringBuffer curr) - : _curr = curr, - _bufs = [curr]; - - AsyncStringWriter([Object content = ""]) : this._(new StringBuffer(content)); - - @override - void print(x) { - _curr.write(x); - } - - /// Adds the result of `futureText` to the writer at the current position - /// in the string being built. If using this method, you must use - /// [asyncToString] instead of [toString] to get the value of the writer or - /// your string may not appear as expected. - Future asyncPrint(Future futureText) { - _semaphoreIncrement(); - var myBuf = new StringBuffer(); - _bufs.add(myBuf); - _curr = new StringBuffer(); - _bufs.add(_curr); - - var toAwait = futureText.then((val) { - myBuf.write(val); - return val; - }); - _toAwait.add(toAwait); - return toAwait.whenComplete(() { - _semaphoreDecrementAndCleanup(); - _toAwait.remove(toAwait); - }); - } - - /// Waits for any values added via [asyncPrint] and returns the fully - /// built string. - Future asyncToString() { - _semaphoreIncrement(); - var bufLen = _bufs.length; - return Future.wait(_toAwait).then((_) { - return _bufs.sublist(0, bufLen).join(''); - }).whenComplete(_semaphoreDecrementAndCleanup); - } - - @override - String toString() => _bufs.map((buf) => '$buf').join('(async gap)'); - - void _semaphoreIncrement() { - ++_asyncCount; - } - - void _semaphoreDecrementAndCleanup() { - assert(_asyncCount > 0); - - --_asyncCount; - if (_asyncCount == 0) { - _curr = _bufs[0]; - for (var i = 1; i < _bufs.length; ++i) { - _curr.write('${_bufs[i]}'); - } - _bufs.removeRange(1, _bufs.length); - } - } -} diff --git a/modules_dart/transform/lib/src/transform/common/class_matcher_base.dart b/modules_dart/transform/lib/src/transform/common/class_matcher_base.dart deleted file mode 100644 index 737d3761b5..0000000000 --- a/modules_dart/transform/lib/src/transform/common/class_matcher_base.dart +++ /dev/null @@ -1,127 +0,0 @@ -library angular2.transform.common.class_matcher_base; - -import 'package:analyzer/src/generated/ast.dart'; -import 'package:barback/barback.dart' show AssetId; -import 'package:path/path.dart' as path; - -import 'logging.dart' show log; -import 'url_resolver.dart'; - -/// Checks if a given [Identifier] matches any of the given [ClassDescriptor]s. -abstract class ClassMatcherBase { - /// Always start out with the default angular [ClassDescriptor]s. - final List _classDescriptors; - - ClassMatcherBase(this._classDescriptors); - - /// Adds a new [ClassDescriptor]. - void add(ClassDescriptor classDescriptor) => - _classDescriptors.add(classDescriptor); - - /// Adds a number of [ClassDescriptor]s. - void addAll(Iterable classDescriptors) => - _classDescriptors.addAll(classDescriptors); - - /// Returns the first [ClassDescriptor] that matches the given - /// [Identifier] node which appears in `assetId`. - ClassDescriptor firstMatch(Identifier className, AssetId assetId) => - _classDescriptors.firstWhere((a) => isMatch(className, a, assetId), - orElse: () => null); - - /// Checks whether an [Identifier] matches any [ClassDescriptor]. - bool hasMatch(Identifier className, AssetId assetId) => - _classDescriptors.any((a) => isMatch(className, a, assetId)); - - /// Checks whether an [Identifier] matches any [ClassDescriptor]. - ImportDirective getMatchingImport(Identifier className, AssetId assetId) { - for (var d in _classDescriptors) { - var matchingImport = _getMatchingImport(className, d, assetId); - if (matchingImport != null) { - return matchingImport; - } - } - return null; - } - - /// Checks if `descriptor` extends or is any of the supplied `interfaces`. - bool implements(ClassDescriptor descriptor, List interfaces, - {String missingSuperClassWarning}) { - if (descriptor == null) return false; - if (interfaces.contains(descriptor)) return true; - if (descriptor.superClass == null) return false; - var superClass = _classDescriptors - .firstWhere((a) => a.name == descriptor.superClass, orElse: () => null); - if (superClass == null) { - if (missingSuperClassWarning != null && - missingSuperClassWarning.isNotEmpty) { - log.warning(missingSuperClassWarning); - } - return false; - } - return implements(superClass, interfaces); - } -} - -// Returns an [ImportDirective] matching `descriptor` for `className` which appears in `assetId`, or `null` if none exists. -ImportDirective _getMatchingImport( - Identifier className, ClassDescriptor descriptor, AssetId assetId) { - if (className == null) return null; - String name; - Identifier prefix; - if (className is PrefixedIdentifier) { - name = className.identifier.name; - prefix = className.prefix; - } else { - name = className.name; - } - if (name != descriptor.name) return null; - final assetUri = toAssetUri(assetId); - return (className.root as CompilationUnit) - .directives - .where((d) => d is ImportDirective) - .firstWhere((ImportDirective i) { - var importMatch = false; - var uriString = i.uri.stringValue; - if (uriString == descriptor.import) { - importMatch = true; - } else if (uriString.startsWith('package:') || isDartCoreUri(uriString)) { - return false; - } else { - final candidateAssetId = - fromUri(createOfflineCompileUrlResolver().resolve(assetUri, uriString)); - - importMatch = descriptor.assetId == candidateAssetId; - } - - if (!importMatch) return false; - if (prefix == null) return i.prefix == null; - if (i.prefix == null) return false; - return prefix.name == i.prefix.name; - }, orElse: () => null); -} - -// Checks if `className` which appears in `assetId` matches a [ClassDescriptor]. -bool isMatch( - Identifier className, ClassDescriptor descriptor, AssetId assetId) { - return _getMatchingImport(className, descriptor, assetId) != null; -} - -/// String based description of a class and its location. -class ClassDescriptor { - /// The name of the class. - final String name; - - /// A `package:` style import path to the file where the class is defined. - final String import; - - /// The class that this class extends or implements. This is the only optional - /// field. - final String superClass; - - AssetId get assetId => new AssetId(package, packagePath); - String get package => path.split(import.replaceFirst('package:', '')).first; - String get packagePath => path.joinAll(['lib'] - ..addAll(path.split(import.replaceFirst('package:', ''))..removeAt(0))); - - const ClassDescriptor(this.name, this.import, {this.superClass}); -} diff --git a/modules_dart/transform/lib/src/transform/common/code/annotation_code.dart b/modules_dart/transform/lib/src/transform/common/code/annotation_code.dart deleted file mode 100644 index 5d81f54759..0000000000 --- a/modules_dart/transform/lib/src/transform/common/code/annotation_code.dart +++ /dev/null @@ -1,80 +0,0 @@ -library angular2.transform.common.code.annotation_code; - -import 'package:analyzer/analyzer.dart'; -import 'package:analyzer/src/generated/ast.dart'; -import 'package:angular2/src/transform/common/model/annotation_model.pb.dart'; -import 'package:barback/barback.dart' show AssetId; - -import 'constify.dart' show constify; - -/// Visitor responsible for parsing [Annotation]s into [AnnotationModel]s. -class AnnotationVisitor extends SimpleAstVisitor { - /// The file we are processing. - final AssetId assetId; - - AnnotationVisitor(this.assetId); - - @override - AnnotationModel visitAnnotation(Annotation node) { - var name = constify(node.name); - if (node.constructorName != null) { - name += '.${constify(node.constructorName)}'; - } - var model = new AnnotationModel() - ..name = name - ..isConstObject = node.arguments == null; - - // This annotation is a constant instance creation expression, - // e.g. @Injectable(), rather than a const object, e.g. @override. - if (!model.isConstObject) { - for (var arg in node.arguments.arguments) { - if (arg is NamedExpression) { - model.namedParameters.add(new NamedParameter() - ..name = constify(arg.name.label) - ..value = constify(arg.expression)); - } else { - model.parameters.add(constify(arg)); - } - } - } - - return model; - } -} - -/// Defines the format in which an [AnnotationModel] is expressed as Dart code -/// when registered with the reflector. -abstract class AnnotationWriterMixin { - StringBuffer get buffer; - - void writeAnnotationModel(AnnotationModel model) { - if (model.isConstObject) { - // This is a const instance, not a ctor invocation and does not need a - // const instance creation expression. - buffer.write(model.name); - } else { - buffer.write('const ${model.name}('); - var first = true; - for (var param in model.parameters) { - if (!first) { - buffer.write(', '); - } - first = false; - buffer.write(param); - } - // TODO(kegluneq): We are currently outputting these sorted to ensure we - // have repeatable output for testing purposes. - // Remove this sorting once we are not testing output code directly. - var namedParameters = model.namedParameters.toList(); - namedParameters.sort((a, b) => a.name.compareTo(b.name)); - for (var param in namedParameters) { - if (!first) { - buffer.write(', '); - } - first = false; - buffer.write('${param.name}: ${param.value}'); - } - buffer.write(')'); - } - } -} diff --git a/modules_dart/transform/lib/src/transform/common/code/constify.dart b/modules_dart/transform/lib/src/transform/common/code/constify.dart deleted file mode 100644 index 83e3e1dfcb..0000000000 --- a/modules_dart/transform/lib/src/transform/common/code/constify.dart +++ /dev/null @@ -1,64 +0,0 @@ -library angular2.transform.common.code.constify; - -import 'package:analyzer/analyzer.dart'; -import 'package:analyzer/src/generated/java_core.dart'; - -/// Serializes the provided [AstNode] to Dart source, replacing `new` in -/// [InstanceCreationExpression]s and the `@` in [Annotation]s with `const`. -String constify(AstNode node) { - var writer = new PrintStringWriter(); - node.accept(new _ConstifyingVisitor(writer)); - return '$writer'; -} - -class _ConstifyingVisitor extends ToSourceVisitor { - final PrintWriter writer; - - _ConstifyingVisitor(PrintWriter writer) - : this.writer = writer, - super(writer); - - @override - Object visitInstanceCreationExpression(InstanceCreationExpression node) { - if (node.keyword.lexeme == 'const') { - return super.visitInstanceCreationExpression(node); - } else if (node.keyword.lexeme == 'new') { - writer.print('const '); - if (node.constructorName != null) { - node.constructorName.accept(this); - } - if (node.argumentList != null) { - node.argumentList.accept(this); - } - } - return null; - } - - @override - Object visitAnnotation(Annotation node) { - var hasArguments = - node.arguments != null && node.arguments.arguments != null; - if (hasArguments) { - writer.print('const '); - } - if (node.name != null) { - node.name.accept(this); - } - if (node.constructorName != null) { - writer.print('.'); - node.constructorName.accept(this); - } - if (hasArguments) { - var args = node.arguments.arguments; - writer.print('('); - for (var i = 0, iLen = args.length; i < iLen; ++i) { - if (i != 0) { - writer.print(', '); - } - args[i].accept(this); - } - writer.print(')'); - } - return null; - } -} diff --git a/modules_dart/transform/lib/src/transform/common/code/import_export_code.dart b/modules_dart/transform/lib/src/transform/common/code/import_export_code.dart deleted file mode 100644 index c8ee4cd2ae..0000000000 --- a/modules_dart/transform/lib/src/transform/common/code/import_export_code.dart +++ /dev/null @@ -1,130 +0,0 @@ -library angular2.transform.common.code.import_export_code; - -import 'package:analyzer/analyzer.dart'; - -import 'package:angular2/src/transform/common/mirror_matcher.dart'; -import 'package:angular2/src/transform/common/names.dart'; -import 'package:angular2/src/transform/common/model/import_export_model.pb.dart'; - -const _mirrorMatcher = const MirrorMatcher(); - -/// Visitor responsible for parsing [ImportDirective]s into [ImportModel]s. -class ImportVisitor extends SimpleAstVisitor { - @override - ImportModel visitImportDirective(ImportDirective node) { - if (node.isSynthetic) return null; - - // This transitively imports 'dart:mirrors'. - if (_mirrorMatcher.hasReflectionCapabilitiesUri(node)) return null; - - final model = new ImportModel() - ..uri = stringLiteralToString(node.uri) - ..isDeferred = node.deferredKeyword != null; - if (node.prefix != null) { - model.prefix = node.prefix.name; - } - _populateCombinators(node, model); - _updateIfBootstrap(node, model); - return model; - } -} - -/// Visitor responsible for parsing [ExportDirective]s into [ExportModel]s. -class ExportVisitor extends SimpleAstVisitor { - @override - ExportModel visitExportDirective(ExportDirective node) { - if (node.isSynthetic) return null; - - // This transitively imports 'dart:mirrors'. - if (_mirrorMatcher.hasReflectionCapabilitiesUri(node)) return null; - - var model = new ExportModel()..uri = stringLiteralToString(node.uri); - _populateCombinators(node, model); - _updateIfBootstrap(node, model); - return model; - } -} - -/// Ensures that the bootstrap import is not retained in .ng_deps. -/// -/// If `model` has a combinator referencing `BOOTSTRAP_NAME`, rewrite it to -/// `BOOTSTRAP_STATIC_NAME`. -/// `model` should be an [ImportModel] or an [ExportModel]. -void _updateIfBootstrap(NamespaceDirective node, dynamic model) { - if (_mirrorMatcher.hasBootstrapUri(node)) { - model.uri = BOOTSTRAP_STATIC_URI; - [model.showCombinators, model.hideCombinators] - .forEach((List cList) { - for (var i = 0; i < cList.length; ++i) { - if (cList[i] == BOOTSTRAP_NAME) { - cList[i] = BOOTSTRAP_STATIC_NAME; - } - } - }); - } -} - -/// Parses `combinators` in `node` and adds them to `model`, which should be -/// either an [ImportModel] or an [ExportModel]. -void _populateCombinators(NamespaceDirective node, dynamic model) { - if (node.combinators != null) { - node.combinators.forEach((c) { - if (c is ShowCombinator) { - model.showCombinators.addAll(c.shownNames.map((id) => '$id')); - } else if (c is HideCombinator) { - model.hideCombinators.addAll(c.hiddenNames.map((id) => '$id')); - } - }); - } -} - -/// Defines the format in which an [ImportModel] is expressed as Dart code when -/// registered with the reflector. -abstract class ImportWriterMixin { - StringBuffer get buffer; - - void writeImportModel(ImportModel model) { - buffer.write("import '${model.uri}'"); - if (model.isDeferred) { - buffer.write(' deferred'); - } - if (model.prefix != null && model.prefix.isNotEmpty) { - buffer.write(' as ${model.prefix}'); - } - _writeCombinators(buffer, model); - buffer.writeln(';'); - } -} - -/// Defines the format in which an [ExportModel] is expressed as Dart code when -/// registered with the reflector. -abstract class ExportWriterMixin { - StringBuffer get buffer; - - void writeExportModel(ExportModel model) { - buffer.write("export '${model.uri}'"); - _writeCombinators(buffer, model); - buffer.writeln(';'); - } -} - -void _writeCombinators(StringBuffer buffer, dynamic model) { - if (model.showCombinators != null && model.showCombinators.isNotEmpty) { - buffer.write(' show '); - for (var i = 0; i < model.showCombinators.length; ++i) { - if (i != 0) { - buffer.write(', '); - } - buffer.write(model.showCombinators[i]); - } - } - if (model.hideCombinators != null && model.hideCombinators.isNotEmpty) { - buffer.write(' hide '); - for (var i = 0; i < model.hideCombinators.length; ++i) { - if (i != 0) { - buffer.write(', '); - } - buffer.write(model.hideCombinators[i]); - } - } -} diff --git a/modules_dart/transform/lib/src/transform/common/code/ng_deps_code.dart b/modules_dart/transform/lib/src/transform/common/code/ng_deps_code.dart deleted file mode 100644 index 38c0d9b588..0000000000 --- a/modules_dart/transform/lib/src/transform/common/code/ng_deps_code.dart +++ /dev/null @@ -1,182 +0,0 @@ -library angular2.transform.common.code.ng_deps_code; - -import 'package:analyzer/analyzer.dart'; -import 'package:angular2/src/transform/common/annotation_matcher.dart'; -import 'package:angular2/src/transform/common/model/ng_deps_model.pb.dart'; -import 'package:angular2/src/transform/common/model/import_export_model.pb.dart'; -import 'package:angular2/src/transform/common/names.dart'; -import 'package:barback/barback.dart' show AssetId; -import 'package:path/path.dart' as path; - -import 'annotation_code.dart'; -import 'import_export_code.dart'; -import 'reflection_info_code.dart'; -import 'parameter_code.dart'; - -/// Visitor responsible for parsing Dart source into [NgDepsModel] objects. -class NgDepsVisitor extends RecursiveAstVisitor { - final AssetId processedFile; - final _importVisitor = new ImportVisitor(); - final _exportVisitor = new ExportVisitor(); - final ReflectionInfoVisitor _reflectableVisitor; - - bool _isPart = false; - NgDepsModel _model = null; - - NgDepsVisitor(AssetId processedFile, AnnotationMatcher annotationMatcher) - : this.processedFile = processedFile, - _reflectableVisitor = - new ReflectionInfoVisitor(processedFile, annotationMatcher); - - bool get isPart => _isPart; - NgDepsModel get model { - if (_model == null) { - _createModel(''); - } - return _model; - } - - void _createModel(String libraryUri) { - _model = new NgDepsModel() - ..libraryUri = libraryUri - ..sourceFile = path.basename(processedFile.path); - } - - @override - Object visitClassDeclaration(ClassDeclaration node) { - var reflectableModel = _reflectableVisitor.visitClassDeclaration(node); - if (reflectableModel != null) { - model.reflectables.add(reflectableModel); - } - return null; - } - - @override - Object visitExportDirective(ExportDirective node) { - var export = _exportVisitor.visitExportDirective(node); - if (export != null) { - model.exports.add(export); - } - return null; - } - - @override - Object visitImportDirective(ImportDirective node) { - var import = _importVisitor.visitImportDirective(node); - if (import != null) { - model.imports.add(import); - } - return null; - } - - @override - Object visitLibraryDirective(LibraryDirective node) { - if (node != null) { - assert(_model == null); - _createModel('${node.name}'); - } - return null; - } - - @override - Object visitPartDirective(PartDirective node) { - model.partUris.add(stringLiteralToString(node.uri)); - return null; - } - - @override - Object visitPartOfDirective(PartOfDirective node) { - _isPart = true; - return null; - } - - @override - Object visitFunctionDeclaration(FunctionDeclaration node) { - var reflectableModel = _reflectableVisitor.visitFunctionDeclaration(node); - if (reflectableModel != null) { - model.reflectables.add(reflectableModel); - } - return null; - } -} - -/// Defines the format in which an [NgDepsModel] is expressed as Dart code -/// when registered with the reflector. -class NgDepsWriter extends Object - with - AnnotationWriterMixin, - ExportWriterMixin, - ImportWriterMixin, - NgDepsWriterMixin, - ParameterWriterMixin, - ReflectionWriterMixin { - final StringBuffer buffer; - - NgDepsWriter([StringBuffer buffer]) - : this.buffer = buffer != null ? buffer : new StringBuffer(); -} - -abstract class NgDepsWriterMixin - implements - AnnotationWriterMixin, - ExportWriterMixin, - ImportWriterMixin, - ParameterWriterMixin, - ReflectionWriterMixin { - StringBuffer get buffer; - - void writeNgDepsModel(NgDepsModel model, String templateCode) { - if (model.libraryUri.isNotEmpty) { - buffer.writeln('library ${model.libraryUri}${TEMPLATE_EXTENSION};\n'); - } - - // We need to import & export (see below) the source file. - writeImportModel(new ImportModel()..uri = model.sourceFile); - - // Used to register reflective information. - writeImportModel(new ImportModel() - ..uri = REFLECTOR_IMPORT - ..prefix = REFLECTOR_PREFIX); - - // We do not support `partUris`, so skip outputting them. - - // Ignore deferred imports here so as to not load the deferred libraries - // code in the current library causing much of the code to not be - // deferred. Instead `DeferredRewriter` will rewrite the code as to load - // `ng_deps` in a deferred way. - model.imports.where((i) => !i.isDeferred).forEach(writeImportModel); - model.depImports.where((i) => !i.isDeferred).forEach(writeImportModel); - - writeExportModel(new ExportModel()..uri = model.sourceFile); - model.exports.forEach(writeExportModel); - - buffer.writeln(templateCode); - - buffer - ..writeln('var _visited = false;') - ..writeln('void ${SETUP_METHOD_NAME}() {') - ..writeln('if (_visited) return; _visited = true;'); - - final needsReceiver = (model.reflectables != null && - model.reflectables.isNotEmpty); - - if (needsReceiver) { - buffer.writeln('$REFLECTOR_PREFIX.$REFLECTOR_VAR_NAME'); - } - - if (model.reflectables != null && model.reflectables.isNotEmpty) { - model.reflectables.forEach(writeRegistration); - } - - if (needsReceiver) { - buffer.writeln(';'); - } - - // Call the setup method for our dependencies. - for (var importModel in model.depImports) { - buffer.writeln('${importModel.prefix}.${SETUP_METHOD_NAME}();'); - } - - buffer.writeln('}'); - } -} diff --git a/modules_dart/transform/lib/src/transform/common/code/parameter_code.dart b/modules_dart/transform/lib/src/transform/common/code/parameter_code.dart deleted file mode 100644 index 79c796f85b..0000000000 --- a/modules_dart/transform/lib/src/transform/common/code/parameter_code.dart +++ /dev/null @@ -1,138 +0,0 @@ -library angular2.transform.common.code.parameter_code; - -import 'package:analyzer/analyzer.dart'; -import 'package:analyzer/src/generated/ast.dart'; -import 'package:angular2/src/transform/common/logging.dart'; -import 'package:angular2/src/transform/common/model/parameter_model.pb.dart'; - -import 'constify.dart'; - -/// Visitor responsible for parsing [FormalParameter]s into -/// [ParameterModel]s. -class ParameterVisitor extends SimpleAstVisitor { - /// Maps field names to their declared types. See `_populateFieldMap` - final Map _fieldNameToType = {}; - final Set _seen = new Set(); - - void _populateFieldMap(AstNode node) { - ClassDeclaration clazz = - node.getAncestor((node) => node is ClassDeclaration); - if (_seen.contains(clazz)) return; - _seen.add(clazz); - - clazz.members - .where((member) => member is FieldDeclaration) - .forEach((FieldDeclaration field) { - var type = field.fields.type; - if (type != null) { - field.fields.variables.forEach((VariableDeclaration decl) { - var key = '${decl.name}'; - if (_fieldNameToType.containsKey(key)) { - // Need to clear our `seen` list as the type for a var name has - // changed and could be incorrect. - _seen.clear(); - } - _fieldNameToType[key] = type; - }); - } - }); - } - - ParameterModel _visitNormalFormalParameter( - NodeList metadata, TypeName type, SimpleIdentifier name) { - var model = new ParameterModel(); - if (name != null && name.name != null && name.name.isNotEmpty) { - model.paramName = '$name'; - } - if (type != null) { - var sTypeName = '${type.name}'; - if (sTypeName.isNotEmpty) { - model.typeName = sTypeName; - } - if (type.typeArguments != null) { - model.typeArgs = '${type.typeArguments}'; - } - } - if (metadata != null) { - model.metadata.addAll(metadata.map(constify)); - } - return model; - } - - @override - ParameterModel visitSimpleFormalParameter(SimpleFormalParameter node) { - return _visitNormalFormalParameter( - node.metadata, node.type, node.identifier); - } - - @override - ParameterModel visitFieldFormalParameter(FieldFormalParameter node) { - if (node.parameters != null) { - log.error('Parameters in ctor not supported ' - '(${node.toSource()})'); - } - var type = node.type; - if (type == null) { - _populateFieldMap(node); - type = _fieldNameToType[node.identifier.toString()]; - } - return _visitNormalFormalParameter(node.metadata, type, node.identifier); - } - - @override - ParameterModel visitFunctionTypedFormalParameter( - FunctionTypedFormalParameter node) { - log.error('Function typed formal parameters not supported ' - '(${node.toSource()})'); - return _visitNormalFormalParameter(node.metadata, null, node.identifier); - } - - @override - ParameterModel visitDefaultFormalParameter(DefaultFormalParameter node) { - // Ignore the declared default value. - return node.parameter != null ? node.parameter.accept(this) : null; - } -} - -/// Defines the format in which a [ParameterModel] is expressed as Dart code -/// when registered with the reflector. -abstract class ParameterWriterMixin { - StringBuffer get buffer; - - void writeParameterModelForList(ParameterModel model) { - buffer.write('const ['); - var first = true; - if (model.typeName != null && model.typeName.isNotEmpty) { - if (!first) { - buffer.write(', '); - } - first = false; - buffer.write('${model.typeName}'); - } - for (var meta in model.metadata) { - if (!first) { - buffer.write(', '); - } - first = false; - buffer.write('$meta'); - } - buffer.write(']'); - } - - void writeParameterModelForDeclaration(ParameterModel model) { - if (model.typeName != null && model.typeName.isNotEmpty) { - buffer.write(model.typeName); - if (model.typeArgs != null && model.typeArgs.isNotEmpty) { - buffer.write(model.typeArgs); - } - buffer.write(' '); - } - if (model.paramName != null && model.paramName.isNotEmpty) { - buffer.write(model.paramName); - } - } - - void writeParameterModelForImpl(ParameterModel model) { - buffer.write(model.paramName); - } -} diff --git a/modules_dart/transform/lib/src/transform/common/code/reflection_info_code.dart b/modules_dart/transform/lib/src/transform/common/code/reflection_info_code.dart deleted file mode 100644 index 131aff7b53..0000000000 --- a/modules_dart/transform/lib/src/transform/common/code/reflection_info_code.dart +++ /dev/null @@ -1,256 +0,0 @@ -library angular2.transform.common.code.reflection_info_code; - -import 'package:analyzer/analyzer.dart'; -import 'package:angular2/src/transform/common/annotation_matcher.dart'; -import 'package:angular2/src/transform/common/logging.dart'; -import 'package:angular2/src/transform/common/model/reflection_info_model.pb.dart'; -import 'package:angular2/src/transform/common/names.dart'; -import 'package:barback/barback.dart' show AssetId; - -import 'annotation_code.dart'; -import 'parameter_code.dart'; - -/// Visitor responsible for parsing [ClassDeclaration]s into -/// [ReflectionInfoModel]s. -class ReflectionInfoVisitor extends RecursiveAstVisitor { - /// The file we are processing. - final AssetId assetId; - - /// Responsible for testing whether [Annotation]s are those recognized by - /// Angular 2, for example `@Component`. - final AnnotationMatcher _annotationMatcher; - - final AnnotationVisitor _annotationVisitor; - final ParameterVisitor _parameterVisitor = new ParameterVisitor(); - - ReflectionInfoVisitor._(this.assetId, this._annotationMatcher, - this._annotationVisitor); - - factory ReflectionInfoVisitor( - AssetId assetId, AnnotationMatcher annotationMatcher) { - var annotationVisitor = new AnnotationVisitor(assetId); - return new ReflectionInfoVisitor._(assetId, annotationMatcher, - annotationVisitor); - } - - ConstructorDeclaration _getCtor(ClassDeclaration node) { - int numCtorsFound = 0; - var ctor = null; - - for (ClassMember classMember in node.members) { - if (classMember is ConstructorDeclaration) { - numCtorsFound++; - ConstructorDeclaration constructor = classMember; - - // Use the unnnamed constructor if it is present. - // Otherwise, use the first encountered. - if (ctor == null) { - ctor = constructor; - } else if (constructor.name == null) { - ctor = constructor; - } - } - } - if (numCtorsFound > 1) { - var ctorName = ctor.name; - if (ctorName != null) { - log.warning( - 'Found ${numCtorsFound} constructors for class ' - '${node.name}; using constructor ${ctorName}.', - asset: assetId); - } - } - return ctor; - } - - @override - ReflectionInfoModel visitClassDeclaration(ClassDeclaration node) { - if (!node.metadata - .any((a) => _annotationMatcher.hasMatch(a.name, assetId))) { - return null; - } - - var ctor = _getCtor(node); - var model = new ReflectionInfoModel()..name = '${node.name}'; - if (ctor != null && ctor.name != null) { - model.ctorName = '${ctor.name}'; - } - - if (node.metadata != null) { - var componentDirectives = new Iterable.empty(); - var componentPipes = new Iterable.empty(); - var viewDirectives, viewPipes; - node.metadata.forEach((node) { - var keepAnnotation = true; - if (_annotationMatcher.isComponent(node, assetId)) { - componentDirectives = _extractReferencedTypes(node, 'directives'); - componentPipes = _extractReferencedTypes(node, 'pipes'); - keepAnnotation = false; - } else if (_annotationMatcher.isView(node, assetId)) { - viewDirectives = _extractReferencedTypes(node, 'directives'); - viewPipes = _extractReferencedTypes(node, 'pipes'); - keepAnnotation = false; - } else if (_annotationMatcher.isDirective(node, assetId)) { - keepAnnotation = false; - } - if (keepAnnotation) { - model.annotations.add(_annotationVisitor.visitAnnotation(node)); - } - }); - if ((componentDirectives.isNotEmpty || componentPipes.isNotEmpty) && - (viewDirectives != null || viewPipes != null)) { - log.warning( - 'Cannot specify view parameters on @Component when a @View ' - 'is present. Component name: ${model.name}', - asset: assetId); - } - model.directives.addAll(componentDirectives); - model.pipes.addAll(componentPipes); - if (viewDirectives != null) { - model.directives.addAll(viewDirectives); - } - if (viewPipes != null) { - model.pipes.addAll(viewPipes); - } - } - if (ctor != null && - ctor.parameters != null && - ctor.parameters.parameters != null) { - ctor.parameters.parameters.forEach((node) { - model.parameters.add(node.accept(_parameterVisitor)); - }); - } - if (node.implementsClause != null && - node.implementsClause.interfaces != null && - node.implementsClause.interfaces.isNotEmpty) { - model.interfaces.addAll(node.implementsClause.interfaces - .map((interface) => '${interface.name}')); - } - - return model; - } - - /// Returns [PrefixedType] values parsed from the value of the - /// `fieldName` parameter of the provided `node`. - /// This will always return a non-null value, so if there is no field - /// called `fieldName`, it will return an empty iterable. - Iterable _extractReferencedTypes( - Annotation node, String fieldName) { - assert(_annotationMatcher.isComponent(node, assetId) || - _annotationMatcher.isView(node, assetId)); - - if (node.arguments == null && node.arguments.arguments == null) { - return const []; - } - final typesNode = node.arguments.arguments.firstWhere((arg) { - return arg is NamedExpression && '${arg.name.label}' == fieldName; - }, orElse: () => null); - if (typesNode == null) return const []; - - if (typesNode.expression is! ListLiteral) { - log.warning( - 'Angular 2 expects a list literal for `${fieldName}` ' - 'but found a ${typesNode.expression.runtimeType}', - asset: assetId); - return const []; - } - final types = []; - for (var dep in (typesNode.expression as ListLiteral).elements) { - if (dep is PrefixedIdentifier) { - types.add(new PrefixedType() - ..prefix = '${dep.prefix}' - ..name = '${dep.identifier}'); - } else if (dep is Identifier) { - types.add(new PrefixedType()..name = '${dep}'); - } else { - log.warning('Ignoring unexpected value $dep in `${fieldName}`.', - asset: assetId); - } - } - return types; - } - - @override - ReflectionInfoModel visitFunctionDeclaration(FunctionDeclaration node) { - if (!node.metadata - .any((a) => _annotationMatcher.hasMatch(a.name, assetId))) { - return null; - } - - var model = new ReflectionInfoModel() - ..name = '${node.name}' - ..isFunction = true; - if (node.metadata != null) { - node.metadata.forEach((node) { - var annotation = _annotationVisitor.visitAnnotation(node); - if (annotation != null) { - model.annotations.add(annotation); - } - }); - } - if (node.functionExpression.parameters != null && - node.functionExpression.parameters.parameters != null) { - node.functionExpression.parameters.parameters.forEach((node) { - var param = node.accept(_parameterVisitor); - if (param != null) { - model.parameters.add(param); - } - }); - } - return model; - } -} - -/// Defines the format in which an [ReflectionInfoModel] is expressed as Dart -/// code when registered with the reflector. -abstract class ReflectionWriterMixin - implements AnnotationWriterMixin, ParameterWriterMixin { - StringBuffer get buffer; - - void _writeListWithSeparator(List l, Function writeFn, - {String prefix, String suffix, String separator: ', '}) { - buffer.write(prefix); - for (var i = 0, iLen = l.length; i < iLen; ++i) { - if (i != 0) { - buffer.write(', '); - } - writeFn(l[i]); - } - buffer.write(suffix); - } - - void writeRegistration(ReflectionInfoModel model) { - buffer.write('..register'); - if (model.isFunction) { - buffer.write('Function'); - } else { - buffer.write('Type'); - } - buffer.writeln('(${model.name}, new $REFLECTOR_PREFIX.ReflectionInfo('); - - // Annotations - _writeListWithSeparator(model.annotations, writeAnnotationModel, - prefix: 'const [', suffix: ']'); - // Parameters - _writeListWithSeparator(model.parameters, writeParameterModelForList, - prefix: ',\nconst [', suffix: ']'); - if (!model.isFunction) { - // Factory - _writeListWithSeparator( - model.parameters, writeParameterModelForDeclaration, - prefix: ',\n(', suffix: ')'); - buffer.write(' => new ${model.name}'); - if (model.ctorName != null && model.ctorName.isNotEmpty) { - buffer.write('.${model.ctorName}'); - } - _writeListWithSeparator(model.parameters, writeParameterModelForImpl, - prefix: '(', suffix: ')'); - // Interfaces - if (model.interfaces != null && model.interfaces.isNotEmpty) { - _writeListWithSeparator(model.interfaces, buffer.write, - prefix: ',\nconst [', suffix: ']'); - } - } - buffer.writeln(')\n)'); - } -} diff --git a/modules_dart/transform/lib/src/transform/common/code/source_module.dart b/modules_dart/transform/lib/src/transform/common/code/source_module.dart deleted file mode 100644 index 08ed6e7f9a..0000000000 --- a/modules_dart/transform/lib/src/transform/common/code/source_module.dart +++ /dev/null @@ -1,42 +0,0 @@ -library angular2.transform.common.code.source_module; - -import 'package:angular2/src/compiler/offline_compiler.dart'; -import 'package:analyzer/src/generated/scanner.dart' show Keyword; -import 'package:angular2/src/transform/common/model/ng_deps_model.pb.dart'; - -import 'ng_deps_code.dart'; - -/// Writes the full Dart code for the provided [SourceModule]. -String writeSourceModule(SourceModule sourceModule, {String libraryName}) { - if (sourceModule == null) return null; - var buf = new StringBuffer(); - libraryName = _sanitizeLibName( - libraryName != null ? libraryName : sourceModule.moduleUrl); - buf..writeln('library $libraryName;')..writeln(); - - buf..writeln()..writeln(sourceModule.source); - - return buf.toString(); -} - -/// Uses `writer` to write a Dart library representing `model` and -/// `sourceModule`. -void writeTemplateFile( - NgDepsWriterMixin writer, NgDepsModel model, SourceModule sourceModule) { - if (model == null) return null; - var sourceModuleCode = ''; - if (sourceModule != null) { - sourceModuleCode = sourceModule.source; - } - writer.writeNgDepsModel(model, sourceModuleCode); -} - -final _unsafeCharsPattern = new RegExp(r'[^a-zA-Z0-9_\.]'); -String _sanitizeLibName(String moduleUrl) { - var sanitized = - moduleUrl.replaceAll(_unsafeCharsPattern, '_').replaceAll('/', '.'); - for (var keyword in Keyword.values) { - sanitized.replaceAll(keyword.syntax, '${keyword.syntax}_'); - } - return sanitized; -} diff --git a/modules_dart/transform/lib/src/transform/common/eager_transformer_wrapper.dart b/modules_dart/transform/lib/src/transform/common/eager_transformer_wrapper.dart deleted file mode 100644 index 96b7d17590..0000000000 --- a/modules_dart/transform/lib/src/transform/common/eager_transformer_wrapper.dart +++ /dev/null @@ -1,45 +0,0 @@ -library angular2.src.transform.common.eager_transformer_wrapper; - -import 'package:barback/barback.dart'; - -abstract class EagerTransformerWrapper { - EagerTransformerWrapper._(); - factory EagerTransformerWrapper(wrapped) { - return wrapped is AggregateTransformer - ? new _EagerAggregateTransformerWrapper(wrapped) - : new _EagerTransformerWrapper(wrapped); - } -} - -class _EagerTransformerWrapper extends EagerTransformerWrapper - implements Transformer { - final Transformer _wrapped; - _EagerTransformerWrapper(this._wrapped) : super._(); - - @override - String get allowedExtensions => _wrapped.allowedExtensions; - - @override - apply(Transform transform) => _wrapped.apply(transform); - - @override - isPrimary(AssetId id) => _wrapped.isPrimary(id); - - @override - toString() => _wrapped.toString(); -} - -class _EagerAggregateTransformerWrapper extends EagerTransformerWrapper - implements AggregateTransformer { - final AggregateTransformer _wrapped; - _EagerAggregateTransformerWrapper(this._wrapped) : super._(); - - @override - apply(AggregateTransform transform) => _wrapped.apply(transform); - - @override - classifyPrimary(AssetId id) => _wrapped.classifyPrimary(id); - - @override - toString() => _wrapped.toString(); -} diff --git a/modules_dart/transform/lib/src/transform/common/formatter.dart b/modules_dart/transform/lib/src/transform/common/formatter.dart deleted file mode 100644 index b6809a298c..0000000000 --- a/modules_dart/transform/lib/src/transform/common/formatter.dart +++ /dev/null @@ -1,32 +0,0 @@ -library angular2.transform.common.formatter; - -import 'package:dart_style/dart_style.dart'; - -AngularDartFormatter _formatter = null; - -void init(DartFormatter formatter) { - _formatter = new _RealFormatter(formatter); -} - -AngularDartFormatter get formatter { - if (_formatter == null) { - _formatter = new _PassThroughFormatter(); - } - return _formatter; -} - -abstract class AngularDartFormatter { - String format(String source, {uri}); -} - -class _PassThroughFormatter implements AngularDartFormatter { - String format(String source, {uri}) => source; -} - -class _RealFormatter implements AngularDartFormatter { - final DartFormatter _formatter; - - _RealFormatter(this._formatter); - - String format(source, {uri}) => _formatter.format(source, uri: uri); -} diff --git a/modules_dart/transform/lib/src/transform/common/interface_matcher.dart b/modules_dart/transform/lib/src/transform/common/interface_matcher.dart deleted file mode 100644 index b9ea1bcaf3..0000000000 --- a/modules_dart/transform/lib/src/transform/common/interface_matcher.dart +++ /dev/null @@ -1,135 +0,0 @@ -library angular2.transform.common.annotati_ON_matcher; - -import 'package:analyzer/src/generated/ast.dart'; -import 'package:barback/barback.dart' show AssetId; -import 'class_matcher_base.dart'; - -export 'class_matcher_base.dart' show ClassDescriptor; - -/// [ClassDescriptor]s for the default angular interfaces that may be -/// implemented by a class. These classes are re-exported in many places so this -/// covers all libraries which provide them. -const _ON_CHANGE_INTERFACES = const [ - const ClassDescriptor('OnChanges', 'package:angular2/angular2.dart'), - const ClassDescriptor('OnChanges', 'package:angular2/lifecycle_hooks.dart'), - const ClassDescriptor('OnChanges', 'package:angular2/src/core/metadata.dart'), - const ClassDescriptor('OnChanges', 'package:angular2/core.dart'), - const ClassDescriptor( - 'OnChanges', 'package:angular2/src/core/src/core/meta/lifecycle_hooks.dart'), -]; -const _ON_DESTROY_INTERFACES = const [ - const ClassDescriptor('OnDestroy', 'package:angular2/angular2.dart'), - const ClassDescriptor('OnDestroy', 'package:angular2/lifecycle_hooks.dart'), - const ClassDescriptor('OnDestroy', 'package:angular2/src/core/metadata.dart'), - const ClassDescriptor('OnDestroy', 'package:angular2/core.dart'), - const ClassDescriptor( - 'OnDestroy', 'package:angular2/src/core/src/core/meta/lifecycle_hooks.dart'), -]; -const _DO_CHECK_INTERFACES = const [ - const ClassDescriptor('DoCheck', 'package:angular2/angular2.dart'), - const ClassDescriptor('DoCheck', 'package:angular2/lifecycle_hooks.dart'), - const ClassDescriptor('DoCheck', 'package:angular2/src/core/metadata.dart'), - const ClassDescriptor('DoCheck', 'package:angular2/core.dart'), - const ClassDescriptor( - 'DoCheck', 'package:angular2/src/core/src/core/meta/lifecycle_hooks.dart'), -]; -const _ON_INIT_INTERFACES = const [ - const ClassDescriptor('OnInit', 'package:angular2/angular2.dart'), - const ClassDescriptor('OnInit', 'package:angular2/lifecycle_hooks.dart'), - const ClassDescriptor('OnInit', 'package:angular2/src/core/metadata.dart'), - const ClassDescriptor('OnInit', 'package:angular2/core.dart'), - const ClassDescriptor( - 'OnInit', 'package:angular2/src/core/src/core/meta/lifecycle_hooks.dart'), -]; -const _ON_AFTER_CONTENT_INIT_INTERFACES = const [ - const ClassDescriptor('AfterContentInit', 'package:angular2/angular2.dart'), - const ClassDescriptor( - 'AfterContentInit', 'package:angular2/lifecycle_hooks.dart'), - const ClassDescriptor( - 'AfterContentInit', 'package:angular2/src/core/metadata.dart'), - const ClassDescriptor('AfterContentInit', 'package:angular2/core.dart'), - const ClassDescriptor( - 'AfterContentInit', 'package:angular2/src/core/src/core/meta/lifecycle_hooks.dart') -]; -const _ON_AFTER_CONTENT_CHECKED_INTERFACES = const [ - const ClassDescriptor( - 'AfterContentChecked', 'package:angular2/angular2.dart'), - const ClassDescriptor( - 'AfterContentChecked', 'package:angular2/lifecycle_hooks.dart'), - const ClassDescriptor( - 'AfterContentChecked', 'package:angular2/src/core/metadata.dart'), - const ClassDescriptor('AfterContentChecked', 'package:angular2/core.dart'), - const ClassDescriptor( - 'AfterContentChecked', 'package:angular2/src/core/src/core/meta/lifecycle_hooks.dart') -]; -const _ON_AFTER_VIEW_INIT_INTERFACES = const [ - const ClassDescriptor('AfterViewInit', 'package:angular2/angular2.dart'), - const ClassDescriptor( - 'AfterViewInit', 'package:angular2/lifecycle_hooks.dart'), - const ClassDescriptor( - 'AfterViewInit', 'package:angular2/src/core/metadata.dart'), - const ClassDescriptor('AfterViewInit', 'package:angular2/core.dart'), - const ClassDescriptor( - 'AfterViewInit', 'package:angular2/src/core/src/core/meta/lifecycle_hooks.dart') -]; -const _ON_AFTER_VIEW_CHECKED_INTERFACES = const [ - const ClassDescriptor('AfterViewChecked', 'package:angular2/angular2.dart'), - const ClassDescriptor( - 'AfterViewChecked', 'package:angular2/lifecycle_hooks.dart'), - const ClassDescriptor( - 'AfterViewChecked', 'package:angular2/src/core/metadata.dart'), - const ClassDescriptor('AfterViewChecked', 'package:angular2/core.dart'), - const ClassDescriptor( - 'AfterViewChecked', 'package:angular2/src/core/src/core/meta/lifecycle_hooks.dart') -]; - -/// Checks if a given [Annotation] matches any of the given -/// [ClassDescriptors]. -class InterfaceMatcher extends ClassMatcherBase { - InterfaceMatcher._(classDescriptors) : super(classDescriptors); - - factory InterfaceMatcher() { - return new InterfaceMatcher._([] - ..addAll(_ON_CHANGE_INTERFACES) - ..addAll(_ON_DESTROY_INTERFACES) - ..addAll(_DO_CHECK_INTERFACES) - ..addAll(_ON_INIT_INTERFACES) - ..addAll(_ON_AFTER_CONTENT_INIT_INTERFACES) - ..addAll(_ON_AFTER_CONTENT_CHECKED_INTERFACES) - ..addAll(_ON_AFTER_VIEW_INIT_INTERFACES) - ..addAll(_ON_AFTER_VIEW_CHECKED_INTERFACES)); - } - - /// Checks if an [Identifier] implements [OnChanges]. - bool isOnChange(Identifier typeName, AssetId assetId) => - implements(firstMatch(typeName, assetId), _ON_CHANGE_INTERFACES); - - /// Checks if an [Identifier] implements [OnDestroy]. - bool isOnDestroy(Identifier typeName, AssetId assetId) => - implements(firstMatch(typeName, assetId), _ON_DESTROY_INTERFACES); - - /// Checks if an [Identifier] implements [DoCheck]. - bool isDoCheck(Identifier typeName, AssetId assetId) => - implements(firstMatch(typeName, assetId), _DO_CHECK_INTERFACES); - - /// Checks if an [Identifier] implements [OnInit]. - bool isOnInit(Identifier typeName, AssetId assetId) => - implements(firstMatch(typeName, assetId), _ON_INIT_INTERFACES); - - /// Checks if an [Identifier] implements [AfterContentInit]. - bool isAfterContentInit(Identifier typeName, AssetId assetId) => implements( - firstMatch(typeName, assetId), _ON_AFTER_CONTENT_INIT_INTERFACES); - - /// Checks if an [Identifier] implements [AfterContentChecked]. - bool isAfterContentChecked(Identifier typeName, AssetId assetId) => - implements( - firstMatch(typeName, assetId), _ON_AFTER_CONTENT_CHECKED_INTERFACES); - - /// Checks if an [Identifier] implements [AfterViewInit]. - bool isAfterViewInit(Identifier typeName, AssetId assetId) => - implements(firstMatch(typeName, assetId), _ON_AFTER_VIEW_INIT_INTERFACES); - - /// Checks if an [Identifier] implements [AfterViewChecked]. - bool isAfterViewChecked(Identifier typeName, AssetId assetId) => implements( - firstMatch(typeName, assetId), _ON_AFTER_VIEW_CHECKED_INTERFACES); -} diff --git a/modules_dart/transform/lib/src/transform/common/logging.dart b/modules_dart/transform/lib/src/transform/common/logging.dart deleted file mode 100644 index 1e74e74bdc..0000000000 --- a/modules_dart/transform/lib/src/transform/common/logging.dart +++ /dev/null @@ -1,147 +0,0 @@ -library angular2.src.transform.common.logging; - -import 'dart:async'; -import 'dart:io' show stderr; - -import 'package:barback/barback.dart'; -import 'package:source_span/source_span.dart'; - -import 'zone.dart' as zone show log; - -/// The [TransformLogger] for the current {@link Zone}. -TransformLogger get log { - var log = zone.log; - return log != null ? log : new PrintLogger(); -} - -/// Writes a log entry at `LogLevel.FINE` granularity with the time taken by -/// `asyncOperation`. -/// -/// Returns the result of executing `asyncOperation`. -Future logElapsedAsync(Future asyncOperation(), - {String operationName: 'unknown', AssetId assetId}) async { - final timer = new Stopwatch()..start(); - final result = await asyncOperation(); - timer.stop(); - _logElapsed(timer, operationName, assetId); - return result; -} - -/// Writes a log entry at `LogLevel.FINE` granularity with the time taken by -/// `operation`. -/// -/// Returns the result of executing `operation`. -dynamic logElapsedSync(dynamic operation(), - {String operationName: 'unknown', AssetId assetId}) { - final timer = new Stopwatch()..start(); - final result = operation(); - timer.stop(); - _logElapsed(timer, operationName, assetId); - return result; -} - -/// Logs the time since `timer` was started. -void _logElapsed(Stopwatch timer, String operationName, AssetId assetId) { - final buf = - new StringBuffer('[$operationName] took ${timer.elapsedMilliseconds} ms'); - if (assetId != null) { - buf.write(' on $assetId'); - } - log.fine(buf.toString(), asset: assetId); -} - -/// Writes logged messages to the provided [StringSink]. -/// -/// A simple implementation of [TransformLogger] that writes messages to a -/// [StringSink] and discards `asset` and `span` information. -class SinkLogger implements TransformLogger { - final StringSink _sink; - - SinkLogger(this._sink); - - void _printWithPrefix(prefix, msg) => _sink.writeln('$prefix: $msg'); - - @override - void info(msg, {AssetId asset, SourceSpan span}) => - _printWithPrefix('INFO', msg); - - @override - void fine(msg, {AssetId asset, SourceSpan span}) => - _printWithPrefix('FINE', msg); - - @override - void warning(msg, {AssetId asset, SourceSpan span}) => - _printWithPrefix('WARN', msg); - - @override - void error(msg, {AssetId asset, SourceSpan span}) { - throw new PrintLoggerError(msg, asset, span); - } -} - -/// Prints logged messages to stderr. -/// -/// A simple implementation of [TransformLogger] that prints messages to -/// [stderr] and discards `asset` and `span` information. -class PrintLogger extends SinkLogger { - PrintLogger() : super(stderr); -} - -/// Wraps the logger and prints the messages -/// only if they have not been printed before -class DeduppingLogger implements TransformLogger { - Set _printedMessages; - - final TransformLogger _logger; - - DeduppingLogger(this._logger, this._printedMessages); - - String _key(msg, AssetId asset) => "$msg $asset"; - - @override - void info(msg, {AssetId asset, SourceSpan span}) { - if (!_printedMessages.contains(_key(msg, asset))) { - _printedMessages.add(_key(msg, asset)); - _logger.info(msg, asset: asset, span: span); - } - } - - @override - void fine(msg, {AssetId asset, SourceSpan span}) { - if (!_printedMessages.contains(_key(msg, asset))) { - _printedMessages.add(_key(msg, asset)); - _logger.fine(msg, asset: asset, span: span); - } - } - - @override - void warning(msg, {AssetId asset, SourceSpan span}) { - if (!_printedMessages.contains(_key(msg, asset))) { - _printedMessages.add(_key(msg, asset)); - _logger.warning(msg, asset: asset, span: span); - } - } - - @override - void error(msg, {AssetId asset, SourceSpan span}) { - if (!_printedMessages.contains(_key(msg, asset))) { - _printedMessages.add(_key(msg, asset)); - _logger.error(msg, asset: asset, span: span); - } - } -} - -class PrintLoggerError extends Error { - final String message; - final AssetId asset; - final SourceSpan span; - - PrintLoggerError(this.message, this.asset, this.span); - - @override - String toString() { - return 'Message: ${Error.safeToString(message)}, ' - 'Asset: ${Error.safeToString(asset)}, ' - 'Span: ${Error.safeToString(span)}.'; - } -} diff --git a/modules_dart/transform/lib/src/transform/common/mirror_matcher.dart b/modules_dart/transform/lib/src/transform/common/mirror_matcher.dart deleted file mode 100644 index f61198cda8..0000000000 --- a/modules_dart/transform/lib/src/transform/common/mirror_matcher.dart +++ /dev/null @@ -1,43 +0,0 @@ -library angular2.transform.common.mirror_matcher; - -import 'package:analyzer/src/generated/ast.dart'; -import 'package:angular2/src/transform/common/names.dart'; - -/// File from which `bootstrap` is exported. -/// -/// This file transitively imports dart:mirrors. -/// It should be replaced with [BOOTSTRAP_STATIC_URI] in production apps. -const _BOOTSTRAP_URI = 'package:angular2/platform/browser.dart'; - -/// File from which `ReflectionCapabilities` is exported. -/// -/// This file transitively imports dart:mirrors and should be removed from -/// production apps. The Angular2 reflection framework should be initialized -/// with generated code such that no reflection is necessary. -const _REFLECTION_CAPABILITIES_URI = - 'package:angular2/src/core/reflection/reflection_capabilities.dart'; - -/// File from which `bootstrapStatic` is exported. -/// -/// This file does not transitively import dart:mirrors. -/// It should be used in place of [_BOOTSTRAP_URI] in production apps. -const BOOTSTRAP_STATIC_URI = 'package:angular2/platform/browser_static.dart'; - -/// Syntactially checks for code related to the use of `dart:mirrors`. -/// -/// Checks various [AstNode]s to determine if they are -/// - Libraries that transitively import `dart:mirrors` -/// - Instantiations of [ReflectionCapabilities] -class MirrorMatcher { - const MirrorMatcher(); - - bool isNewReflectionCapabilities(InstanceCreationExpression node) => - '${node.constructorName.type.name}' == REFLECTION_CAPABILITIES_NAME; - - bool hasReflectionCapabilitiesUri(UriBasedDirective node) { - return node.uri.stringValue == _REFLECTION_CAPABILITIES_URI; - } - - bool hasBootstrapUri(UriBasedDirective node) => - _BOOTSTRAP_URI == node.uri.stringValue; -} diff --git a/modules_dart/transform/lib/src/transform/common/mirror_mode.dart b/modules_dart/transform/lib/src/transform/common/mirror_mode.dart deleted file mode 100644 index 8f2c16a6b5..0000000000 --- a/modules_dart/transform/lib/src/transform/common/mirror_mode.dart +++ /dev/null @@ -1,10 +0,0 @@ -library angular2.transform.common.mirror_mode; - -/// Modes for mirror use. -/// `none` is the default value and signifies that mirror use should be -/// removed. -/// `debug` allows the use of mirrors and logs a notice whenever they are -/// accessed. -/// `verbose` allows the use of mirrors and logs a stack trace whenever they -/// are accessed. -enum MirrorMode { debug, none, verbose } diff --git a/modules_dart/transform/lib/src/transform/common/model/annotation_model.pb.dart b/modules_dart/transform/lib/src/transform/common/model/annotation_model.pb.dart deleted file mode 100644 index bdb0ffbda2..0000000000 --- a/modules_dart/transform/lib/src/transform/common/model/annotation_model.pb.dart +++ /dev/null @@ -1,107 +0,0 @@ -/// -// Generated code. Do not modify. -/// -library angular2.src.transform.common.model.proto_annotation_model; - -import 'package:protobuf/protobuf.dart'; - -class NamedParameter extends GeneratedMessage { - static final BuilderInfo _i = new BuilderInfo('NamedParameter') - ..a(1, 'name', PbFieldType.QS) - ..a(2, 'value', PbFieldType.QS) - ; - - NamedParameter() : super(); - NamedParameter.fromBuffer(List i, [ExtensionRegistry r = ExtensionRegistry.EMPTY]) : super.fromBuffer(i, r); - NamedParameter.fromJson(String i, [ExtensionRegistry r = ExtensionRegistry.EMPTY]) : super.fromJson(i, r); - NamedParameter clone() => new NamedParameter()..mergeFromMessage(this); - BuilderInfo get info_ => _i; - static NamedParameter create() => new NamedParameter(); - static PbList createRepeated() => new PbList(); - static NamedParameter getDefault() { - if (_defaultInstance == null) _defaultInstance = new _ReadonlyNamedParameter(); - return _defaultInstance; - } - static NamedParameter _defaultInstance; - static void $checkItem(NamedParameter v) { - if (v is !NamedParameter) checkItemFailed(v, 'NamedParameter'); - } - - String get name => $_get(0, 1, ''); - void set name(String v) { $_setString(0, 1, v); } - bool hasName() => $_has(0, 1); - void clearName() => clearField(1); - - String get value => $_get(1, 2, ''); - void set value(String v) { $_setString(1, 2, v); } - bool hasValue() => $_has(1, 2); - void clearValue() => clearField(2); -} - -class _ReadonlyNamedParameter extends NamedParameter with ReadonlyMessageMixin {} - -class AnnotationModel extends GeneratedMessage { - static final BuilderInfo _i = new BuilderInfo('AnnotationModel') - ..a(1, 'name', PbFieldType.QS) - ..p(2, 'parameters', PbFieldType.PS) - ..pp(3, 'namedParameters', PbFieldType.PM, NamedParameter.$checkItem, NamedParameter.create) - ..a(4, 'isConstObject', PbFieldType.OB) - ; - - AnnotationModel() : super(); - AnnotationModel.fromBuffer(List i, [ExtensionRegistry r = ExtensionRegistry.EMPTY]) : super.fromBuffer(i, r); - AnnotationModel.fromJson(String i, [ExtensionRegistry r = ExtensionRegistry.EMPTY]) : super.fromJson(i, r); - AnnotationModel clone() => new AnnotationModel()..mergeFromMessage(this); - BuilderInfo get info_ => _i; - static AnnotationModel create() => new AnnotationModel(); - static PbList createRepeated() => new PbList(); - static AnnotationModel getDefault() { - if (_defaultInstance == null) _defaultInstance = new _ReadonlyAnnotationModel(); - return _defaultInstance; - } - static AnnotationModel _defaultInstance; - static void $checkItem(AnnotationModel v) { - if (v is !AnnotationModel) checkItemFailed(v, 'AnnotationModel'); - } - - String get name => $_get(0, 1, ''); - void set name(String v) { $_setString(0, 1, v); } - bool hasName() => $_has(0, 1); - void clearName() => clearField(1); - - List get parameters => $_get(1, 2, null); - - List get namedParameters => $_get(2, 3, null); - - bool get isConstObject => $_get(3, 4, false); - void set isConstObject(bool v) { $_setBool(3, 4, v); } - bool hasIsConstObject() => $_has(3, 4); - void clearIsConstObject() => clearField(4); -} - -class _ReadonlyAnnotationModel extends AnnotationModel with ReadonlyMessageMixin {} - -const NamedParameter$json = const { - '1': 'NamedParameter', - '2': const [ - const {'1': 'name', '3': 1, '4': 2, '5': 9}, - const {'1': 'value', '3': 2, '4': 2, '5': 9}, - ], -}; - -const AnnotationModel$json = const { - '1': 'AnnotationModel', - '2': const [ - const {'1': 'name', '3': 1, '4': 2, '5': 9}, - const {'1': 'parameters', '3': 2, '4': 3, '5': 9}, - const {'1': 'named_parameters', '3': 3, '4': 3, '5': 11, '6': '.angular2.src.transform.common.model.proto.NamedParameter'}, - const {'1': 'is_const_object', '3': 4, '4': 1, '5': 8}, - ], -}; - -/** - * Generated with: - * annotation_model.proto (a7c9ec37cbc4916ddc7b132710da0856fa76cb5a) - * libprotoc 3.0.0 - * dart-protoc-plugin (af5fc2bf1de367a434c3b1847ab260510878ffc0) - */ diff --git a/modules_dart/transform/lib/src/transform/common/model/annotation_model.proto b/modules_dart/transform/lib/src/transform/common/model/annotation_model.proto deleted file mode 100644 index 03c26cde98..0000000000 --- a/modules_dart/transform/lib/src/transform/common/model/annotation_model.proto +++ /dev/null @@ -1,25 +0,0 @@ -syntax = "proto2"; - -package angular2.src.transform.common.model.proto; - -message NamedParameter { - required string name = 1; - required string value = 2; -} - -message AnnotationModel { - // The constructor that creates the annotation, or the name of the field that - // defines the annotation. - required string name = 1; - - // The positional parameters provided to the annotation. - repeated string parameters = 2; - - // The named parameters provided to the annotation. - repeated NamedParameter named_parameters = 3; - - // Whether this annotation is a constant object (for example, `@override`) as - // opposed to a const instance creation expression - // (for example, `@Injectable()`). - optional bool is_const_object = 4; -} diff --git a/modules_dart/transform/lib/src/transform/common/model/import_export_model.pb.dart b/modules_dart/transform/lib/src/transform/common/model/import_export_model.pb.dart deleted file mode 100644 index 5b2f7b86d8..0000000000 --- a/modules_dart/transform/lib/src/transform/common/model/import_export_model.pb.dart +++ /dev/null @@ -1,115 +0,0 @@ -/// -// Generated code. Do not modify. -/// -library angular2.src.transform.common.model.proto_import_export_model; - -import 'package:protobuf/protobuf.dart'; - -class ImportModel extends GeneratedMessage { - static final BuilderInfo _i = new BuilderInfo('ImportModel') - ..a(1, 'uri', PbFieldType.QS) - ..p(2, 'showCombinators', PbFieldType.PS) - ..p(3, 'hideCombinators', PbFieldType.PS) - ..a(4, 'prefix', PbFieldType.OS) - ..a(5, 'isDeferred', PbFieldType.OB) - ; - - ImportModel() : super(); - ImportModel.fromBuffer(List i, [ExtensionRegistry r = ExtensionRegistry.EMPTY]) : super.fromBuffer(i, r); - ImportModel.fromJson(String i, [ExtensionRegistry r = ExtensionRegistry.EMPTY]) : super.fromJson(i, r); - ImportModel clone() => new ImportModel()..mergeFromMessage(this); - BuilderInfo get info_ => _i; - static ImportModel create() => new ImportModel(); - static PbList createRepeated() => new PbList(); - static ImportModel getDefault() { - if (_defaultInstance == null) _defaultInstance = new _ReadonlyImportModel(); - return _defaultInstance; - } - static ImportModel _defaultInstance; - static void $checkItem(ImportModel v) { - if (v is !ImportModel) checkItemFailed(v, 'ImportModel'); - } - - String get uri => $_get(0, 1, ''); - void set uri(String v) { $_setString(0, 1, v); } - bool hasUri() => $_has(0, 1); - void clearUri() => clearField(1); - - List get showCombinators => $_get(1, 2, null); - - List get hideCombinators => $_get(2, 3, null); - - String get prefix => $_get(3, 4, ''); - void set prefix(String v) { $_setString(3, 4, v); } - bool hasPrefix() => $_has(3, 4); - void clearPrefix() => clearField(4); - - bool get isDeferred => $_get(4, 5, false); - void set isDeferred(bool v) { $_setBool(4, 5, v); } - bool hasIsDeferred() => $_has(4, 5); - void clearIsDeferred() => clearField(5); -} - -class _ReadonlyImportModel extends ImportModel with ReadonlyMessageMixin {} - -class ExportModel extends GeneratedMessage { - static final BuilderInfo _i = new BuilderInfo('ExportModel') - ..a(1, 'uri', PbFieldType.QS) - ..p(2, 'showCombinators', PbFieldType.PS) - ..p(3, 'hideCombinators', PbFieldType.PS) - ; - - ExportModel() : super(); - ExportModel.fromBuffer(List i, [ExtensionRegistry r = ExtensionRegistry.EMPTY]) : super.fromBuffer(i, r); - ExportModel.fromJson(String i, [ExtensionRegistry r = ExtensionRegistry.EMPTY]) : super.fromJson(i, r); - ExportModel clone() => new ExportModel()..mergeFromMessage(this); - BuilderInfo get info_ => _i; - static ExportModel create() => new ExportModel(); - static PbList createRepeated() => new PbList(); - static ExportModel getDefault() { - if (_defaultInstance == null) _defaultInstance = new _ReadonlyExportModel(); - return _defaultInstance; - } - static ExportModel _defaultInstance; - static void $checkItem(ExportModel v) { - if (v is !ExportModel) checkItemFailed(v, 'ExportModel'); - } - - String get uri => $_get(0, 1, ''); - void set uri(String v) { $_setString(0, 1, v); } - bool hasUri() => $_has(0, 1); - void clearUri() => clearField(1); - - List get showCombinators => $_get(1, 2, null); - - List get hideCombinators => $_get(2, 3, null); -} - -class _ReadonlyExportModel extends ExportModel with ReadonlyMessageMixin {} - -const ImportModel$json = const { - '1': 'ImportModel', - '2': const [ - const {'1': 'uri', '3': 1, '4': 2, '5': 9}, - const {'1': 'show_combinators', '3': 2, '4': 3, '5': 9}, - const {'1': 'hide_combinators', '3': 3, '4': 3, '5': 9}, - const {'1': 'prefix', '3': 4, '4': 1, '5': 9}, - const {'1': 'is_deferred', '3': 5, '4': 1, '5': 8}, - ], -}; - -const ExportModel$json = const { - '1': 'ExportModel', - '2': const [ - const {'1': 'uri', '3': 1, '4': 2, '5': 9}, - const {'1': 'show_combinators', '3': 2, '4': 3, '5': 9}, - const {'1': 'hide_combinators', '3': 3, '4': 3, '5': 9}, - ], -}; - -/** - * Generated with: - * import_export_model.proto (36a3a72d0884b84b451b7188ffa1fc93b44e7b62) - * libprotoc 3.0.0 - * dart-protoc-plugin (af5fc2bf1de367a434c3b1847ab260510878ffc0) - */ diff --git a/modules_dart/transform/lib/src/transform/common/model/import_export_model.proto b/modules_dart/transform/lib/src/transform/common/model/import_export_model.proto deleted file mode 100644 index eb23a3b712..0000000000 --- a/modules_dart/transform/lib/src/transform/common/model/import_export_model.proto +++ /dev/null @@ -1,28 +0,0 @@ -syntax = "proto2"; - -package angular2.src.transform.common.model.proto; - -// Note that the fields that are common between `ImportModel` and `ExportModel` -// are stored at the same indexes, which allows them to be semi-wire-compatible -// with one another. This will hopefully not be necessary to exploit, but on the -// chance that it is it's easier to define this now. -message ImportModel { - required string uri = 1; - - repeated string show_combinators = 2; - - repeated string hide_combinators = 3; - - optional string prefix = 4; - - optional bool is_deferred = 5; -} - -// See message above about wire-compatiblity with `ImportModel`. -message ExportModel { - required string uri = 1; - - repeated string show_combinators = 2; - - repeated string hide_combinators = 3; -} diff --git a/modules_dart/transform/lib/src/transform/common/model/ng_deps_model.pb.dart b/modules_dart/transform/lib/src/transform/common/model/ng_deps_model.pb.dart deleted file mode 100644 index e44dc81c7e..0000000000 --- a/modules_dart/transform/lib/src/transform/common/model/ng_deps_model.pb.dart +++ /dev/null @@ -1,78 +0,0 @@ -/// -// Generated code. Do not modify. -/// -library angular2.src.transform.common.model.proto_ng_deps_model; - -import 'package:protobuf/protobuf.dart'; -import 'import_export_model.pb.dart'; -import 'reflection_info_model.pb.dart'; - -class NgDepsModel extends GeneratedMessage { - static final BuilderInfo _i = new BuilderInfo('NgDepsModel') - ..a(1, 'libraryUri', PbFieldType.OS) - ..p(2, 'partUris', PbFieldType.PS) - ..pp(3, 'imports', PbFieldType.PM, ImportModel.$checkItem, ImportModel.create) - ..pp(4, 'exports', PbFieldType.PM, ExportModel.$checkItem, ExportModel.create) - ..pp(5, 'reflectables', PbFieldType.PM, ReflectionInfoModel.$checkItem, ReflectionInfoModel.create) - ..a(6, 'sourceFile', PbFieldType.OS) - ..pp(7, 'depImports', PbFieldType.PM, ImportModel.$checkItem, ImportModel.create) - ; - - NgDepsModel() : super(); - NgDepsModel.fromBuffer(List i, [ExtensionRegistry r = ExtensionRegistry.EMPTY]) : super.fromBuffer(i, r); - NgDepsModel.fromJson(String i, [ExtensionRegistry r = ExtensionRegistry.EMPTY]) : super.fromJson(i, r); - NgDepsModel clone() => new NgDepsModel()..mergeFromMessage(this); - BuilderInfo get info_ => _i; - static NgDepsModel create() => new NgDepsModel(); - static PbList createRepeated() => new PbList(); - static NgDepsModel getDefault() { - if (_defaultInstance == null) _defaultInstance = new _ReadonlyNgDepsModel(); - return _defaultInstance; - } - static NgDepsModel _defaultInstance; - static void $checkItem(NgDepsModel v) { - if (v is !NgDepsModel) checkItemFailed(v, 'NgDepsModel'); - } - - String get libraryUri => $_get(0, 1, ''); - void set libraryUri(String v) { $_setString(0, 1, v); } - bool hasLibraryUri() => $_has(0, 1); - void clearLibraryUri() => clearField(1); - - List get partUris => $_get(1, 2, null); - - List get imports => $_get(2, 3, null); - - List get exports => $_get(3, 4, null); - - List get reflectables => $_get(4, 5, null); - - String get sourceFile => $_get(5, 6, ''); - void set sourceFile(String v) { $_setString(5, 6, v); } - bool hasSourceFile() => $_has(5, 6); - void clearSourceFile() => clearField(6); - - List get depImports => $_get(6, 7, null); -} - -class _ReadonlyNgDepsModel extends NgDepsModel with ReadonlyMessageMixin {} - -const NgDepsModel$json = const { - '1': 'NgDepsModel', - '2': const [ - const {'1': 'library_uri', '3': 1, '4': 1, '5': 9}, - const {'1': 'part_uris', '3': 2, '4': 3, '5': 9}, - const {'1': 'imports', '3': 3, '4': 3, '5': 11, '6': '.angular2.src.transform.common.model.proto.ImportModel'}, - const {'1': 'exports', '3': 4, '4': 3, '5': 11, '6': '.angular2.src.transform.common.model.proto.ExportModel'}, - const {'1': 'reflectables', '3': 5, '4': 3, '5': 11, '6': '.angular2.src.transform.common.model.proto.ReflectionInfoModel'}, - const {'1': 'source_file', '3': 6, '4': 1, '5': 9}, - const {'1': 'dep_imports', '3': 7, '4': 3, '5': 11, '6': '.angular2.src.transform.common.model.proto.ImportModel'}, - ], -}; - -/** - * Generated with: - * ng_deps_model.proto (5c881da448125df1d4eefec6ec3e7b7b6c5c25c0) - * libprotoc 3.0.0 - * dart-protoc-plugin (af5fc2bf1de367a434c3b1847ab260510878ffc0) - */ diff --git a/modules_dart/transform/lib/src/transform/common/model/ng_deps_model.proto b/modules_dart/transform/lib/src/transform/common/model/ng_deps_model.proto deleted file mode 100644 index de357598eb..0000000000 --- a/modules_dart/transform/lib/src/transform/common/model/ng_deps_model.proto +++ /dev/null @@ -1,27 +0,0 @@ -syntax = "proto2"; - -import "import_export_model.proto"; -import "reflection_info_model.proto"; - -package angular2.src.transform.common.model.proto; - -message NgDepsModel { - optional string library_uri = 1; - - repeated string part_uris = 2; - - repeated ImportModel imports = 3; - - repeated ExportModel exports = 4; - - // All classes in `source_file` marked with @Injectable or a known subclass. - repeated ReflectionInfoModel reflectables = 5; - - // The basename of the file from which the ng_deps were generated. - // Example: component.dart - optional string source_file = 6; - - // Imports of the generated files associated with the declared `imports` - // and `exports` of the source file. - repeated ImportModel dep_imports = 7; -} diff --git a/modules_dart/transform/lib/src/transform/common/model/parameter_model.pb.dart b/modules_dart/transform/lib/src/transform/common/model/parameter_model.pb.dart deleted file mode 100644 index 8b2004d9aa..0000000000 --- a/modules_dart/transform/lib/src/transform/common/model/parameter_model.pb.dart +++ /dev/null @@ -1,68 +0,0 @@ -/// -// Generated code. Do not modify. -/// -library angular2.src.transform.common.model.proto_parameter_model; - -import 'package:protobuf/protobuf.dart'; - -class ParameterModel extends GeneratedMessage { - static final BuilderInfo _i = new BuilderInfo('ParameterModel') - ..a(1, 'typeName', PbFieldType.OS) - ..a(2, 'typeArgs', PbFieldType.OS) - ..p(3, 'metadata', PbFieldType.PS) - ..a(4, 'paramName', PbFieldType.OS) - ..hasRequiredFields = false - ; - - ParameterModel() : super(); - ParameterModel.fromBuffer(List i, [ExtensionRegistry r = ExtensionRegistry.EMPTY]) : super.fromBuffer(i, r); - ParameterModel.fromJson(String i, [ExtensionRegistry r = ExtensionRegistry.EMPTY]) : super.fromJson(i, r); - ParameterModel clone() => new ParameterModel()..mergeFromMessage(this); - BuilderInfo get info_ => _i; - static ParameterModel create() => new ParameterModel(); - static PbList createRepeated() => new PbList(); - static ParameterModel getDefault() { - if (_defaultInstance == null) _defaultInstance = new _ReadonlyParameterModel(); - return _defaultInstance; - } - static ParameterModel _defaultInstance; - static void $checkItem(ParameterModel v) { - if (v is !ParameterModel) checkItemFailed(v, 'ParameterModel'); - } - - String get typeName => $_get(0, 1, ''); - void set typeName(String v) { $_setString(0, 1, v); } - bool hasTypeName() => $_has(0, 1); - void clearTypeName() => clearField(1); - - String get typeArgs => $_get(1, 2, ''); - void set typeArgs(String v) { $_setString(1, 2, v); } - bool hasTypeArgs() => $_has(1, 2); - void clearTypeArgs() => clearField(2); - - List get metadata => $_get(2, 3, null); - - String get paramName => $_get(3, 4, ''); - void set paramName(String v) { $_setString(3, 4, v); } - bool hasParamName() => $_has(3, 4); - void clearParamName() => clearField(4); -} - -class _ReadonlyParameterModel extends ParameterModel with ReadonlyMessageMixin {} - -const ParameterModel$json = const { - '1': 'ParameterModel', - '2': const [ - const {'1': 'type_name', '3': 1, '4': 1, '5': 9}, - const {'1': 'type_args', '3': 2, '4': 1, '5': 9}, - const {'1': 'metadata', '3': 3, '4': 3, '5': 9}, - const {'1': 'param_name', '3': 4, '4': 1, '5': 9}, - ], -}; - -/** - * Generated with: - * parameter_model.proto (2a97dcb9a65b199f50fba67120a85590bceb083a) - * libprotoc 3.0.0 - * dart-protoc-plugin (af5fc2bf1de367a434c3b1847ab260510878ffc0) - */ diff --git a/modules_dart/transform/lib/src/transform/common/model/parameter_model.proto b/modules_dart/transform/lib/src/transform/common/model/parameter_model.proto deleted file mode 100644 index d5ed0b21ad..0000000000 --- a/modules_dart/transform/lib/src/transform/common/model/parameter_model.proto +++ /dev/null @@ -1,13 +0,0 @@ -syntax = "proto2"; - -package angular2.src.transform.common.model.proto; - -message ParameterModel { - optional string type_name = 1; - - optional string type_args = 2; - - repeated string metadata = 3; - - optional string param_name = 4; -} diff --git a/modules_dart/transform/lib/src/transform/common/model/reflection_info_model.pb.dart b/modules_dart/transform/lib/src/transform/common/model/reflection_info_model.pb.dart deleted file mode 100644 index 59ac591280..0000000000 --- a/modules_dart/transform/lib/src/transform/common/model/reflection_info_model.pb.dart +++ /dev/null @@ -1,129 +0,0 @@ -/// -// Generated code. Do not modify. -/// -library angular2.src.transform.common.model.proto_reflection_info_model; - -import 'package:protobuf/protobuf.dart'; -import 'annotation_model.pb.dart'; -import 'parameter_model.pb.dart'; - -class PrefixedType extends GeneratedMessage { - static final BuilderInfo _i = new BuilderInfo('PrefixedType') - ..a(1, 'prefix', PbFieldType.OS) - ..a(2, 'name', PbFieldType.OS) - ..hasRequiredFields = false - ; - - PrefixedType() : super(); - PrefixedType.fromBuffer(List i, [ExtensionRegistry r = ExtensionRegistry.EMPTY]) : super.fromBuffer(i, r); - PrefixedType.fromJson(String i, [ExtensionRegistry r = ExtensionRegistry.EMPTY]) : super.fromJson(i, r); - PrefixedType clone() => new PrefixedType()..mergeFromMessage(this); - BuilderInfo get info_ => _i; - static PrefixedType create() => new PrefixedType(); - static PbList createRepeated() => new PbList(); - static PrefixedType getDefault() { - if (_defaultInstance == null) _defaultInstance = new _ReadonlyPrefixedType(); - return _defaultInstance; - } - static PrefixedType _defaultInstance; - static void $checkItem(PrefixedType v) { - if (v is !PrefixedType) checkItemFailed(v, 'PrefixedType'); - } - - String get prefix => $_get(0, 1, ''); - void set prefix(String v) { $_setString(0, 1, v); } - bool hasPrefix() => $_has(0, 1); - void clearPrefix() => clearField(1); - - String get name => $_get(1, 2, ''); - void set name(String v) { $_setString(1, 2, v); } - bool hasName() => $_has(1, 2); - void clearName() => clearField(2); -} - -class _ReadonlyPrefixedType extends PrefixedType with ReadonlyMessageMixin {} - -class ReflectionInfoModel extends GeneratedMessage { - static final BuilderInfo _i = new BuilderInfo('ReflectionInfoModel') - ..a(1, 'name', PbFieldType.QS) - ..a(2, 'ctorName', PbFieldType.OS) - ..a(3, 'isFunction', PbFieldType.OB) - ..pp(4, 'annotations', PbFieldType.PM, AnnotationModel.$checkItem, AnnotationModel.create) - ..pp(5, 'parameters', PbFieldType.PM, ParameterModel.$checkItem, ParameterModel.create) - ..p(6, 'interfaces', PbFieldType.PS) - ..pp(7, 'directives', PbFieldType.PM, PrefixedType.$checkItem, PrefixedType.create) - ..pp(8, 'pipes', PbFieldType.PM, PrefixedType.$checkItem, PrefixedType.create) - ; - - ReflectionInfoModel() : super(); - ReflectionInfoModel.fromBuffer(List i, [ExtensionRegistry r = ExtensionRegistry.EMPTY]) : super.fromBuffer(i, r); - ReflectionInfoModel.fromJson(String i, [ExtensionRegistry r = ExtensionRegistry.EMPTY]) : super.fromJson(i, r); - ReflectionInfoModel clone() => new ReflectionInfoModel()..mergeFromMessage(this); - BuilderInfo get info_ => _i; - static ReflectionInfoModel create() => new ReflectionInfoModel(); - static PbList createRepeated() => new PbList(); - static ReflectionInfoModel getDefault() { - if (_defaultInstance == null) _defaultInstance = new _ReadonlyReflectionInfoModel(); - return _defaultInstance; - } - static ReflectionInfoModel _defaultInstance; - static void $checkItem(ReflectionInfoModel v) { - if (v is !ReflectionInfoModel) checkItemFailed(v, 'ReflectionInfoModel'); - } - - String get name => $_get(0, 1, ''); - void set name(String v) { $_setString(0, 1, v); } - bool hasName() => $_has(0, 1); - void clearName() => clearField(1); - - String get ctorName => $_get(1, 2, ''); - void set ctorName(String v) { $_setString(1, 2, v); } - bool hasCtorName() => $_has(1, 2); - void clearCtorName() => clearField(2); - - bool get isFunction => $_get(2, 3, false); - void set isFunction(bool v) { $_setBool(2, 3, v); } - bool hasIsFunction() => $_has(2, 3); - void clearIsFunction() => clearField(3); - - List get annotations => $_get(3, 4, null); - - List get parameters => $_get(4, 5, null); - - List get interfaces => $_get(5, 6, null); - - List get directives => $_get(6, 7, null); - - List get pipes => $_get(7, 8, null); -} - -class _ReadonlyReflectionInfoModel extends ReflectionInfoModel with ReadonlyMessageMixin {} - -const PrefixedType$json = const { - '1': 'PrefixedType', - '2': const [ - const {'1': 'prefix', '3': 1, '4': 1, '5': 9}, - const {'1': 'name', '3': 2, '4': 1, '5': 9}, - ], -}; - -const ReflectionInfoModel$json = const { - '1': 'ReflectionInfoModel', - '2': const [ - const {'1': 'name', '3': 1, '4': 2, '5': 9}, - const {'1': 'ctor_name', '3': 2, '4': 1, '5': 9}, - const {'1': 'is_function', '3': 3, '4': 1, '5': 8}, - const {'1': 'annotations', '3': 4, '4': 3, '5': 11, '6': '.angular2.src.transform.common.model.proto.AnnotationModel'}, - const {'1': 'parameters', '3': 5, '4': 3, '5': 11, '6': '.angular2.src.transform.common.model.proto.ParameterModel'}, - const {'1': 'interfaces', '3': 6, '4': 3, '5': 9}, - const {'1': 'directives', '3': 7, '4': 3, '5': 11, '6': '.angular2.src.transform.common.model.proto.PrefixedType'}, - const {'1': 'pipes', '3': 8, '4': 3, '5': 11, '6': '.angular2.src.transform.common.model.proto.PrefixedType'}, - ], -}; - -/** - * Generated with: - * reflection_info_model.proto (c5cb9bba874abdca05cc0e4d69b66b7faa12fc1a) - * libprotoc 3.0.0 - * dart-protoc-plugin (af5fc2bf1de367a434c3b1847ab260510878ffc0) - */ diff --git a/modules_dart/transform/lib/src/transform/common/model/reflection_info_model.proto b/modules_dart/transform/lib/src/transform/common/model/reflection_info_model.proto deleted file mode 100644 index c780b632f8..0000000000 --- a/modules_dart/transform/lib/src/transform/common/model/reflection_info_model.proto +++ /dev/null @@ -1,40 +0,0 @@ -syntax = "proto2"; - -import "annotation_model.proto"; -import "parameter_model.proto"; - -package angular2.src.transform.common.model.proto; - -message PrefixedType { - // The prefix used to reference this Type, if any. - optional string prefix = 1; - - // The name of the Type or type alias. - // See https://goo.gl/d8XPt0 for info on type aliases. - optional string name = 2; -} - -message ReflectionInfoModel { - // The (potentially prefixed) name of this Injectable. - // This can be a `Type` or a function name. - required string name = 1; - - // The name of the ctor used to create this Injectable. In most cases, this - // will be null and we will use the default constructor. - optional string ctor_name = 2; - - optional bool is_function = 3; - - repeated AnnotationModel annotations = 4; - - repeated ParameterModel parameters = 5; - - repeated string interfaces = 6; - - // Directive dependencies parsed from the @View or @Component `directives` - // parameter. - repeated PrefixedType directives = 7; - - // Pipe dependencies parsed from the @View or @Component `pipes` parameter. - repeated PrefixedType pipes = 8; -} diff --git a/modules_dart/transform/lib/src/transform/common/model/source_module.dart b/modules_dart/transform/lib/src/transform/common/model/source_module.dart deleted file mode 100644 index 7c44321cf0..0000000000 --- a/modules_dart/transform/lib/src/transform/common/model/source_module.dart +++ /dev/null @@ -1,83 +0,0 @@ -library angular2.transform.common.model.source_module; - -import 'package:path/path.dart' as path; - -import 'package:angular2/src/transform/common/url_resolver.dart'; - -import 'import_export_model.pb.dart'; - -/// Generates an [ImportModel] for the file specified by `importPath`. -/// -/// If `fromAbsolute` is specified, `importPath` may be a relative path, -/// otherwise it is expected to be absolute. -ImportModel toImportModel(String importPath, - {String prefix, String fromAbsolute}) { - var urlResolver = createOfflineCompileUrlResolver(); - var codegenImportPath; - - var importUri = - toAssetScheme(Uri.parse(urlResolver.resolve(fromAbsolute, importPath))); - if (_canPackageImport(importUri) || - fromAbsolute == null || - fromAbsolute.isEmpty) { - codegenImportPath = _toPackageImport(importUri); - } else { - var moduleUri = toAssetScheme(Uri.parse(fromAbsolute)); - if (_canImportRelative(importUri, from: moduleUri)) { - codegenImportPath = path.url.relative(importUri.toString(), - from: path.dirname(moduleUri.toString())); - } else { - var errMsg; - if (fromAbsolute == null || fromAbsolute.isEmpty) { - errMsg = 'Can only import $importPath using a relative uri'; - } else { - errMsg = 'Cannot import $importPath from $fromAbsolute'; - } - throw new FormatException(errMsg, importPath); - } - } - - final model = new ImportModel()..uri = codegenImportPath; - - if (prefix != null && prefix.isNotEmpty) { - model.prefix = prefix; - } - return model; -} - -// For a relative import, the scheme, first (package) and second (lib|test|web) -// path segments must be equal. -bool _canImportRelative(Uri importUri, {Uri from}) { - if (importUri == null) throw new ArgumentError.notNull('importUri'); - if (from == null) throw new ArgumentError.notNull('from'); - assert(importUri.scheme == 'asset'); - assert(importUri.pathSegments.length >= 2); - assert(from.scheme == 'asset'); - assert(from.pathSegments.length >= 2); - return importUri.pathSegments.first == from.pathSegments.first && - importUri.pathSegments[1] == from.pathSegments[1]; -} - -/// Pub's package scheme assumes that an asset lives under the lib/ directory, -/// so an asset: Uri is package-importable if its second path segment is lib/. -/// -/// For a file located at angular2/lib/src/file.dart: -/// - Asset scheme => asset:angular2/lib/src/file.dart -/// - Package scheme => package:angular2/src/file.dart -bool _canPackageImport(Uri assetImport) { - if (assetImport == null) throw new ArgumentError.notNull('assetImport'); - if (!assetImport.isAbsolute || assetImport.scheme != 'asset') { - throw new ArgumentError.value(assetImport.toString(), 'assetImport', - 'Must be an absolute uri using the asset: scheme'); - } - return assetImport.pathSegments.length >= 2 && - assetImport.pathSegments[1] == 'lib'; -} - -String _toPackageImport(Uri assetImport) { - assert(_canPackageImport(assetImport)); - var subPath = assetImport.pathSegments - .getRange(2, assetImport.pathSegments.length) - .join('/'); - return 'package:${assetImport.pathSegments.first}/$subPath'; -} diff --git a/modules_dart/transform/lib/src/transform/common/naive_eval.dart b/modules_dart/transform/lib/src/transform/common/naive_eval.dart deleted file mode 100644 index 7f73ee338b..0000000000 --- a/modules_dart/transform/lib/src/transform/common/naive_eval.dart +++ /dev/null @@ -1,26 +0,0 @@ -library angular2.transform.common.naive_eval; - -import 'package:analyzer/analyzer.dart'; - -final _constantEvaluator = new ConstantEvaluator(); - -/// The value returned if the result of `naiveEval` is not a constant. -final NOT_A_CONSTANT = ConstantEvaluator.NOT_A_CONSTANT; - -/// Performs a very limited syntactic evaluation of `expr`. -/// -/// This lack of semantic information means this method cannot do much - for -/// example, it can create a list from a list literal and combine adjacent -/// strings but cannot determine that an identifier is a constant string, -/// even if that identifier is defined in the same [CompilationUnit]. -/// -/// Returns the result of evaluation or [NOT_A_CONSTANT] where appropriate. -dynamic naiveEval(Expression expr) { - var val; - if (expr is SimpleStringLiteral) { - val = stringLiteralToString(expr); - } else { - val = expr.accept(_constantEvaluator); - } - return val != NOT_A_CONSTANT ? val : null; -} diff --git a/modules_dart/transform/lib/src/transform/common/names.dart b/modules_dart/transform/lib/src/transform/common/names.dart deleted file mode 100644 index 2ea8d1d733..0000000000 --- a/modules_dart/transform/lib/src/transform/common/names.dart +++ /dev/null @@ -1,89 +0,0 @@ -library angular2.transform.common.names; - -const BOOTSTRAP_NAME = 'bootstrap'; -const BOOTSTRAP_STATIC_NAME = 'bootstrapStatic'; -const SETUP_METHOD_NAME = 'initReflector'; -const REFLECTOR_VAR_NAME = 'reflector'; -const TRANSFORM_DYNAMIC_MODE = 'transform_dynamic'; -const CSS_EXTENSION = '.css'; -const DEFERRED_EXTENSION = '.dart.deferredCount'; -const SHIMMED_STYLESHEET_EXTENSION = '.css.shim.dart'; -const NON_SHIMMED_STYLESHEET_EXTENSION = '.css.dart'; -const META_EXTENSION = '.ng_meta.json'; -const REFLECTION_CAPABILITIES_NAME = 'ReflectionCapabilities'; -const REFLECTOR_IMPORT = 'package:angular2/src/core/reflection/reflection.dart'; -const REFLECTOR_PREFIX = '_ngRef'; -const REGISTER_TYPE_METHOD_NAME = 'registerType'; -const SUMMARY_META_EXTENSION = '.ng_summary.json'; -const TEMPLATE_EXTENSION = '.ngfactory.dart'; - -/// Note that due to the implementation of `_toExtension`, ordering is -/// important. For example, putting '.dart' first in this list will cause -/// incorrect behavior because it will (incompletely) match '.ngfactory.dart' -/// files. -const ALL_EXTENSIONS = const [ - DEFERRED_EXTENSION, - META_EXTENSION, - SUMMARY_META_EXTENSION, - TEMPLATE_EXTENSION, - '.dart' -]; - -/// Whether `uri` was created by a transform phase. -/// -/// This may return false positives for problematic inputs. -/// This just tests file extensions known to be created by the transformer, so -/// any files named like transformer outputs will be reported as generated. -bool isGenerated(String uri) { - return const [ - DEFERRED_EXTENSION, - META_EXTENSION, - NON_SHIMMED_STYLESHEET_EXTENSION, - SHIMMED_STYLESHEET_EXTENSION, - SUMMARY_META_EXTENSION, - TEMPLATE_EXTENSION, - ].any((ext) => uri.endsWith(ext)); -} - -/// Returns `uri` with its extension updated to [DEFERRED_EXTENSION]. -String toDeferredExtension(String uri) => - _toExtension(uri, ALL_EXTENSIONS, DEFERRED_EXTENSION); - -/// Returns `uri` with its extension updated to [META_EXTENSION]. -String toMetaExtension(String uri) => - _toExtension(uri, ALL_EXTENSIONS, META_EXTENSION); - -/// Returns `uri` with its extension updated to [TEMPLATES_EXTENSION]. -String toTemplateExtension(String uri) => - _toExtension(uri, ALL_EXTENSIONS, TEMPLATE_EXTENSION); - -/// Returns `uri` with its extension updated to [SHIMMED_STYLESHEET_EXTENSION]. -String toShimmedStylesheetExtension(String uri) => - _toExtension(uri, const [CSS_EXTENSION], SHIMMED_STYLESHEET_EXTENSION); - -/// Returns `uri` with its extension updated to [NON_SHIMMED_STYLESHEET_EXTENSION]. -String toNonShimmedStylesheetExtension(String uri) => - _toExtension(uri, const [CSS_EXTENSION], NON_SHIMMED_STYLESHEET_EXTENSION); - -/// Returns `uri` with its extension updated to [SUMMARY_META_EXTENSION]. -String toSummaryExtension(String uri) => - _toExtension(uri, ALL_EXTENSIONS, SUMMARY_META_EXTENSION); - -/// Returns `uri` with its extension updated to `toExtension` if its -/// extension is currently in `fromExtension`. -String _toExtension( - String uri, Iterable fromExtensions, String toExtension) { - if (uri == null) return null; - if (uri.endsWith(toExtension)) return uri; - for (var extension in fromExtensions) { - if (uri.endsWith(extension)) { - return '${uri.substring(0, uri.length-extension.length)}' - '$toExtension'; - } - } - throw new ArgumentError.value( - uri, - 'uri', - 'Provided value ends with an unexpected extension. ' - 'Expected extension(s): [${fromExtensions.join(', ')}].'); -} diff --git a/modules_dart/transform/lib/src/transform/common/ng_compiler.dart b/modules_dart/transform/lib/src/transform/common/ng_compiler.dart deleted file mode 100644 index 994b4d8351..0000000000 --- a/modules_dart/transform/lib/src/transform/common/ng_compiler.dart +++ /dev/null @@ -1,52 +0,0 @@ -library angular2.transform.template_compiler.ng_compiler; - -import 'package:angular2/src/compiler/config.dart'; -import 'package:angular2/src/compiler/view_compiler/view_compiler.dart'; -import 'package:angular2/src/core/console.dart'; -import 'package:angular2/src/compiler/html_parser.dart'; -import 'package:angular2/src/compiler/style_compiler.dart'; -import 'package:angular2/src/compiler/offline_compiler.dart'; -import 'package:angular2/src/compiler/directive_normalizer.dart'; -import 'package:angular2/src/compiler/template_parser.dart'; -import 'package:angular2/src/compiler/expression_parser/lexer.dart' as ng; -import 'package:angular2/src/compiler/expression_parser/parser.dart' as ng; -import 'package:angular2/src/compiler/schema/dom_element_schema_registry.dart'; -import 'package:angular2/src/compiler/output/dart_emitter.dart'; -import 'package:angular2/src/transform/common/asset_reader.dart'; -import 'package:angular2/i18n.dart'; - -import 'xhr_impl.dart'; -import 'url_resolver.dart'; - -OfflineCompiler createTemplateCompiler(AssetReader reader, - {CompilerConfig compilerConfig, XmbDeserializationResult translations}) { - var _xhr = new XhrImpl(reader); - var _urlResolver = createOfflineCompileUrlResolver(); - - // TODO(yjbanov): add router AST transformer when ready - var parser = new ng.Parser(new ng.Lexer()); - var _htmlParser = _createHtmlParser(translations, parser); - - var templateParser = new TemplateParser( - parser, - new DomElementSchemaRegistry(), - _htmlParser, - new Console(), - [new RouterLinkTransform(parser)]); - - return new OfflineCompiler( - new DirectiveNormalizer(_xhr, _urlResolver, _htmlParser), - templateParser, - new StyleCompiler(_urlResolver), - new ViewCompiler(compilerConfig), - new DartEmitter() - ); -} - -HtmlParser _createHtmlParser(XmbDeserializationResult translations, ng.Parser parser) { - if (translations != null) { - return new I18nHtmlParser(new HtmlParser(), parser, translations.content, translations.messages); - } else { - return new HtmlParser(); - } -} diff --git a/modules_dart/transform/lib/src/transform/common/ng_meta.dart b/modules_dart/transform/lib/src/transform/common/ng_meta.dart deleted file mode 100644 index f4a9599004..0000000000 --- a/modules_dart/transform/lib/src/transform/common/ng_meta.dart +++ /dev/null @@ -1,151 +0,0 @@ -library angular2.transform.common.ng_meta; - -import 'package:angular2/src/compiler/compile_metadata.dart'; -import 'logging.dart'; -import 'model/ng_deps_model.pb.dart'; -import 'url_resolver.dart' show isDartCoreUri; - -/// Metadata about directives, pipes, directive aliases, and injectable values. -/// -/// [NgMeta] is used in three stages of the transformation process: -/// -/// First we store directive aliases and types exported directly (that is, not -/// via an `export` statement) from a single file in an [NgMeta] instance. -/// -/// In the second phase, we perform two actions: -/// 1. Incorporate all the data from [NgMeta] instances created by all -/// files `exported` by the original file, such that all aliases and types -/// visible when importing the original file are stored in its associated -/// [NgMeta] instance. -/// 2. Use the [NgDepsModel] to write Dart code registering all injectable -/// values with the Angular 2 runtime reflection system. -/// -/// Later in the compilation process, the template compiler needs to reason -/// about the namespace of import prefixes, so it will combine multiple [NgMeta] -/// instances together if they were imported into a file with the same prefix. -/// -/// Instances of this class are serialized into `.ng_summary.json` and -/// `.ng_meta.json` files as intermediate assets during the compilation process. -class NgMeta { - static const _ALIAS_VALUE = 'alias'; - static const _NG_DEPS_KEY = 'ngDeps'; - static const _TYPE_VALUE = 'type'; - - /// Metadata for each identifier - /// Type: [CompileDirectiveMetadata]|[CompilePipeMetadata]|[CompileTypeMetadata]| - /// [CompileIdentifierMetadata]|[CompileFactoryMetadata] - final Map identifiers; - - /// List of other types and names associated with a given name. - final Map> aliases; - - // The NgDeps generated from - final NgDepsModel ngDeps; - - NgMeta({Map> aliases, - Map identifiers, - this.ngDeps: null}) - :this.aliases = aliases != null ? aliases : {}, - this.identifiers = identifiers != null ? identifiers : {}; - - NgMeta.empty() : this(); - - // `model` can be an `ImportModel` or `ExportModel`. - static bool _isDartImport(dynamic model) => isDartCoreUri(model.uri); - - bool get isNgDepsEmpty { - if (ngDeps == null) return true; - // If this file imports only dart: libraries and does not define any - // reflectables of its own, we don't need to register any information from - // it with the Angular 2 reflector. - if (ngDeps.reflectables == null || ngDeps.reflectables.isEmpty) { - if ((ngDeps.imports == null || ngDeps.imports.every(_isDartImport)) && - (ngDeps.exports == null || ngDeps.exports.every(_isDartImport))) { - return true; - } - } - return false; - } - - bool get isEmpty => identifiers.isEmpty && aliases.isEmpty && isNgDepsEmpty; - - bool get needsResolution { - return identifiers.values.any((id) => - id is CompileDirectiveMetadata || id is CompilePipeMetadata || id is CompileTypeMetadata || id is CompileFactoryMetadata - || (id is CompileIdentifierMetadata && id.value != null)); - } - - /// Parse from the serialized form produced by [toJson]. - factory NgMeta.fromJson(Map json) { - var ngDeps = null; - - if (json.containsKey(_NG_DEPS_KEY)) { - var ngDepsJsonMap = json[_NG_DEPS_KEY]; - if (ngDepsJsonMap != null) { - if (ngDepsJsonMap is! Map) { - log.warning( - 'Unexpected value $ngDepsJsonMap for key "$_NG_DEPS_KEY" in NgMeta.'); - } else { - ngDeps = new NgDepsModel()..mergeFromJsonMap(ngDepsJsonMap); - } - } - } - - final aliases = json[_ALIAS_VALUE] != null ? json[_ALIAS_VALUE] : {}; - - final identifiers = {}; - if (json.containsKey(_TYPE_VALUE)) { - for (var key in json[_TYPE_VALUE].keys) { - var entry = json[_TYPE_VALUE][key]; - if (entry is! Map) { - log.warning('Unexpected value $entry for key "$key" in NgMeta.'); - continue; - } - identifiers[key] = metadataFromJson(entry); - } - } - - return new NgMeta(identifiers: identifiers, aliases: aliases, ngDeps: ngDeps); - } - - /// Serialized representation of this instance. - Map toJson() { - var result = {}; - result[_NG_DEPS_KEY] = isNgDepsEmpty ? null : ngDeps.writeToJsonMap(); - - result[_TYPE_VALUE] = {}; - identifiers.forEach((k, v) { - result[_TYPE_VALUE][k] = v.toJson(); - }); - result[_ALIAS_VALUE] = aliases; - return result; - } - - /// Merge into this instance all information from [other]. - /// This does not include `ngDeps`. - void addAll(NgMeta other) { - aliases.addAll(other.aliases); - identifiers.addAll(other.identifiers); - } - - /// Returns the metadata for every type associated with the given [alias]. - List flatten(String alias) { - var result = []; - helper(name, path) { - final newPath = []..addAll(path)..add(name); - if (path.contains(name)) { - log.error('Circular alias dependency for "$name". Cycle: ${newPath.join(' -> ')}.'); - return; - } - if (aliases.containsKey(name)) { - aliases[name].forEach((n) => helper(n, newPath)); - } else if (identifiers.containsKey(name)) { - result.add(identifiers[name]); - } else { - log.error('Unknown alias: ${newPath.join(' -> ')}. Make sure you export ${name} from the file where ${path.last} is defined.'); - } - } - helper(alias, []); - return result; - } -} diff --git a/modules_dart/transform/lib/src/transform/common/options.dart b/modules_dart/transform/lib/src/transform/common/options.dart deleted file mode 100644 index 9b87ae213f..0000000000 --- a/modules_dart/transform/lib/src/transform/common/options.dart +++ /dev/null @@ -1,157 +0,0 @@ -library angular2.transform.common.options; - -import 'package:glob/glob.dart'; - -import 'annotation_matcher.dart'; -import 'mirror_mode.dart'; -import 'package:barback/src/asset/asset_id.dart'; - -const CUSTOM_ANNOTATIONS_PARAM = 'custom_annotations'; -const ENTRY_POINT_PARAM = 'entry_points'; -const FORMAT_CODE_PARAM = 'format_code'; -const REFLECT_PROPERTIES_AS_ATTRIBUTES = 'reflect_properties_as_attributes'; -const PLATFORM_DIRECTIVES = 'platform_directives'; -const PLATFORM_PIPES = 'platform_pipes'; -const RESOLVED_IDENTIFIERS = 'resolved_identifiers'; -const ERROR_ON_MISSING_IDENTIFIERS = 'error_on_missing_identifiers'; -const INIT_REFLECTOR_PARAM = 'init_reflector'; -const INLINE_VIEWS_PARAM = 'inline_views'; -const MIRROR_MODE_PARAM = 'mirror_mode'; -const CODEGEN_MODE_PARAM = 'codegen_mode'; -const LAZY_TRANSFORMERS = 'lazy_transformers'; -const TRANSLATIONS = 'translations'; - -const CODEGEN_DEBUG_MODE = 'debug'; - -/// Provides information necessary to transform an Angular2 app. -class TransformerOptions { - final List entryPointGlobs; - - /// The path to the files where the application's calls to `bootstrap` are. - final List entryPoints; - - /// The `BarbackMode#name` we are running in. - final String modeName; - - /// The [MirrorMode] to use for the transformation. - final MirrorMode mirrorMode; - - /// Whether to generate calls to our generated `initReflector` code - final bool initReflector; - - /// The [AnnotationMatcher] which is used to identify angular annotations. - final AnnotationMatcher annotationMatcher; - - /// Whether to reflect property values as attributes. - /// If this is `true`, the change detection code will echo set property values - /// as attributes on DOM elements, which may aid in application debugging. - final bool reflectPropertiesAsAttributes; - - /// Whether to generate debug information in views. - /// Needed for testing and improves error messages when exception are triggered. - final String codegenMode; - - /// A set of directives that will be automatically passed-in to the template compiler - /// Format of an item in the list: - /// angular2/lib/src/common/common_directives.dart#COMMON_DIRECTIVES - final List platformDirectives; - - /// A set of pipes that will be automatically passed-in to the template compiler - /// Format of an item in the list: - /// angular2/lib/src/common/pipes.dart#COMMON_PIPES - final List platformPipes; - - /// A map of identifier/asset pairs used when resolving identifiers. - final Map resolvedIdentifiers; - - /// when set ot false, the transformer will warn about missing identifiers but not error - final bool errorOnMissingIdentifiers; - - /// Whether to format generated code. - /// Code that is only modified will never be formatted because doing so may - /// invalidate the source maps generated by `dart2js` and/or other tools. - final bool formatCode; - - /// Whether to inline views. - /// If this is `true`, the transformer will *only* make a single pass over the - /// input files and inline `templateUrl` and `styleUrls` values. - /// This is undocumented, for testing purposes only, and may change or break - /// at any time. - final bool inlineViews; - - /// Whether to make transformers lazy. - /// If this is `true`, and in `debug` mode only, the transformers will be - /// lazy (will only build assets that are requested). - /// This is undocumented, for testing purposes only, and may change or break - /// at any time. - final bool lazyTransformers; - - /// Whether to generate compiled templates. - /// - /// This option is strictly for internal testing and is not available as an - /// option on the transformer. - /// Setting this to `false` means that our generated .ngfactory.dart files do - /// not have any compiled templates or change detectors defined in them. - /// These files will not be usable, but this allows us to test the code output - /// of the transformer without breaking when compiled template internals - /// change. - final bool genCompiledTemplates; - - /// The path to the file with translations. - final AssetId translations; - - TransformerOptions._internal( - this.entryPoints, - this.entryPointGlobs, - this.modeName, - this.mirrorMode, - this.initReflector, - this.annotationMatcher, - {this.formatCode, - this.codegenMode, - this.genCompiledTemplates, - this.inlineViews, - this.lazyTransformers, - this.platformDirectives, - this.platformPipes, - this.resolvedIdentifiers, - this.errorOnMissingIdentifiers, - this.translations, - this.reflectPropertiesAsAttributes}); - - factory TransformerOptions(List entryPoints, - {String modeName: 'release', - MirrorMode mirrorMode: MirrorMode.none, - bool initReflector: true, - List customAnnotationDescriptors: const [], - bool inlineViews: false, - String codegenMode: '', - bool genCompiledTemplates: true, - bool reflectPropertiesAsAttributes: false, - bool errorOnMissingIdentifiers: true, - List platformDirectives, - List platformPipes, - Map resolvedIdentifiers, - bool lazyTransformers: false, - AssetId translations: null, - bool formatCode: false}) { - var annotationMatcher = new AnnotationMatcher() - ..addAll(customAnnotationDescriptors); - var entryPointGlobs = entryPoints != null - ? entryPoints.map((path) => new Glob(path)).toList(growable: false) - : null; - return new TransformerOptions._internal(entryPoints, entryPointGlobs, - modeName, mirrorMode, initReflector, annotationMatcher, - codegenMode: codegenMode, - genCompiledTemplates: genCompiledTemplates, - reflectPropertiesAsAttributes: reflectPropertiesAsAttributes, - platformDirectives: platformDirectives, - platformPipes: platformPipes, - resolvedIdentifiers: resolvedIdentifiers, - errorOnMissingIdentifiers: errorOnMissingIdentifiers, - inlineViews: inlineViews, - lazyTransformers: lazyTransformers, - translations: translations, - formatCode: formatCode); - } -} diff --git a/modules_dart/transform/lib/src/transform/common/options_reader.dart b/modules_dart/transform/lib/src/transform/common/options_reader.dart deleted file mode 100644 index 0bb38dd15e..0000000000 --- a/modules_dart/transform/lib/src/transform/common/options_reader.dart +++ /dev/null @@ -1,143 +0,0 @@ -library angular2.transform.common.options_reader; - -import 'dart:io'; - -import 'package:barback/barback.dart'; - -import 'annotation_matcher.dart'; -import 'mirror_mode.dart'; -import 'options.dart'; -import './url_resolver.dart'; - -TransformerOptions parseBarbackSettings(BarbackSettings settings) { - var config = settings.configuration; - var entryPoints = _readStringList(config, ENTRY_POINT_PARAM); - var initReflector = - _readBool(config, INIT_REFLECTOR_PARAM, defaultValue: true); - var reflectPropertiesAsAttributes = - _readBool(config, REFLECT_PROPERTIES_AS_ATTRIBUTES, defaultValue: false); - var platformDirectives = _readStringList(config, PLATFORM_DIRECTIVES); - var platformPipes = _readStringList(config, PLATFORM_PIPES); - var resolvedIdentifiers = config[RESOLVED_IDENTIFIERS]; - var errorOnMissingIdentifiers = _readBool(config, ERROR_ON_MISSING_IDENTIFIERS, defaultValue: true); - var formatCode = _readBool(config, FORMAT_CODE_PARAM, defaultValue: false); - String mirrorModeVal = - config.containsKey(MIRROR_MODE_PARAM) ? config[MIRROR_MODE_PARAM] : ''; - var mirrorMode = MirrorMode.none; - var codegenMode; - if (settings.mode == BarbackMode.DEBUG) { - codegenMode = CODEGEN_DEBUG_MODE; - } else { - codegenMode = config[CODEGEN_MODE_PARAM]; - } - switch (mirrorModeVal) { - case 'debug': - mirrorMode = MirrorMode.debug; - break; - case 'verbose': - mirrorMode = MirrorMode.verbose; - break; - default: - mirrorMode = MirrorMode.none; - break; - } - return new TransformerOptions(entryPoints, - modeName: settings.mode.name, - mirrorMode: mirrorMode, - initReflector: initReflector, - codegenMode: codegenMode, - customAnnotationDescriptors: _readCustomAnnotations(config), - reflectPropertiesAsAttributes: reflectPropertiesAsAttributes, - platformDirectives: platformDirectives, - platformPipes: platformPipes, - resolvedIdentifiers: resolvedIdentifiers, - errorOnMissingIdentifiers: errorOnMissingIdentifiers, - inlineViews: _readBool(config, INLINE_VIEWS_PARAM, defaultValue: false), - lazyTransformers: - _readBool(config, LAZY_TRANSFORMERS, defaultValue: false), - translations: _readAssetId(config, TRANSLATIONS), - formatCode: formatCode); -} - -bool _readBool(Map config, String paramName, {bool defaultValue}) { - return config.containsKey(paramName) - ? config[paramName] != false - : defaultValue; -} - -AssetId _readAssetId(Map config, String paramName) { - if (config.containsKey(paramName)) { - return fromUri(config[paramName]); - } else { - return null; - } -} - -/// Cribbed from the polymer project. -/// {@link https://github.com/dart-lang/polymer-dart} -List _readStringList(Map config, String paramName) { - var value = config[paramName]; - if (value == null) return null; - var result = []; - bool error = false; - if (value is List) { - result = value; - error = value.any((e) => e is! String); - } else if (value is String) { - result = [value]; - error = false; - } else { - error = true; - } - if (error) { - stderr.writeln( - 'Invalid value for "$paramName" in the Angular 2 transformer.'); - } - return result; -} - -/// Parse the [CUSTOM_ANNOTATIONS_PARAM] options out of the transformer into -/// [ClassDescriptor]s. -List _readCustomAnnotations(Map config) { - var descriptors = []; - var customAnnotations = config[CUSTOM_ANNOTATIONS_PARAM]; - if (customAnnotations == null) return descriptors; - var error = false; - if (customAnnotations is! List) { - error = true; - } else { - for (var description in customAnnotations) { - if (description is! Map) { - error = true; - continue; - } - var name = description['name']; - var import = description['import']; - var superClass = description['superClass']; - if (name == null || import == null || superClass == null) { - error = true; - continue; - } - descriptors - .add(new ClassDescriptor(name, import, superClass: superClass)); - } - } - if (error) { - stderr.writeln(CUSTOM_ANNOTATIONS_ERROR); - } - return descriptors; -} - -const CUSTOM_ANNOTATIONS_ERROR = ''' - Invalid value for $CUSTOM_ANNOTATIONS_PARAM in the Angular2 transformer. - Expected something that looks like the following: - - transformers: - - angular2[/transform/codegen]: - custom_annotations: - - name: MyAnnotation - import: 'package:my_package/my_annotation.dart' - superClass: Component - - name: ... - import: ... - superClass: ...'''; diff --git a/modules_dart/transform/lib/src/transform/common/type_metadata_reader.dart b/modules_dart/transform/lib/src/transform/common/type_metadata_reader.dart deleted file mode 100644 index 94a8d56bd8..0000000000 --- a/modules_dart/transform/lib/src/transform/common/type_metadata_reader.dart +++ /dev/null @@ -1,1135 +0,0 @@ -library angular2.transform.common.type_metadata_reader; - -import 'dart:async'; - -import 'package:analyzer/analyzer.dart'; - -import 'package:angular2/src/compiler/compile_metadata.dart'; -import 'package:angular2/src/compiler/offline_compiler.dart'; - -import 'package:angular2/src/core/change_detection/change_detection.dart'; -import 'package:angular2/src/core/metadata/lifecycle_hooks.dart' show LifecycleHooks; -import 'package:angular2/src/core/metadata/view.dart' show ViewEncapsulation; -import 'package:angular2/src/transform/common/annotation_matcher.dart'; -import 'package:angular2/src/transform/common/interface_matcher.dart'; -import 'package:angular2/src/transform/common/logging.dart'; -import 'package:barback/barback.dart' show AssetId; - -import 'naive_eval.dart'; -import 'url_resolver.dart'; - -class TypeMetadataReader { - final _DirectiveMetadataVisitor _directiveVisitor; - final _PipeMetadataVisitor _pipeVisitor; - final _CompileTypeMetadataVisitor _typeVisitor; - final _CompileFactoryMetadataVisitor _factoryVisitor; - final OfflineCompiler _templateCompiler; - - TypeMetadataReader._(this._directiveVisitor, this._pipeVisitor, - this._templateCompiler, this._typeVisitor, this._factoryVisitor); - - /// Accepts an [AnnotationMatcher] which tests that an [Annotation] - /// is a [Directive], [Component], or [View]. - factory TypeMetadataReader(AnnotationMatcher annotationMatcher, - InterfaceMatcher interfaceMatcher, OfflineCompiler templateCompiler) { - var lifecycleVisitor = new _LifecycleHookVisitor(interfaceMatcher); - var typeVisitor = new _CompileTypeMetadataVisitor(annotationMatcher); - var factoryVisitor = new _CompileFactoryMetadataVisitor(annotationMatcher); - var directiveVisitor = new _DirectiveMetadataVisitor( - annotationMatcher, lifecycleVisitor, typeVisitor); - var pipeVisitor = new _PipeMetadataVisitor(annotationMatcher); - - return new TypeMetadataReader._( - directiveVisitor, pipeVisitor, templateCompiler, typeVisitor, factoryVisitor); - } - - /// Reads *un-normalized* [CompileDirectiveMetadata]/[CompilePipeMetadata] from the - /// [ClassDeclaration] `node`. - /// - /// `node` is expected to be a class which may have a [Directive] or [Component] - /// annotation. If `node` does not have one of these annotations, this function - /// returns `null`. - /// - /// `assetId` is the [AssetId] from which `node` was read, unless `node` was - /// read from a part file, in which case `assetId` should be the [AssetId] of - /// the parent file. - Future readTypeMetadata(ClassDeclaration node, AssetId assetId) { - _directiveVisitor.reset(assetId); - _pipeVisitor.reset(assetId); - _typeVisitor.reset(assetId); - - node.accept(_directiveVisitor); - node.accept(_pipeVisitor); - node.accept(_typeVisitor); - - if (_directiveVisitor.hasMetadata) { - final metadata = _directiveVisitor.createMetadata(); - return _templateCompiler.normalizeDirectiveMetadata(metadata); - } else if (_pipeVisitor.hasMetadata) { - return new Future.value(_pipeVisitor.createMetadata()); - } else if (_typeVisitor.isInjectable) { - return new Future.value(_typeVisitor.type); - } else { - return new Future.value(null); - } - } - - Future readFactoryMetadata(FunctionDeclaration node, AssetId assetId) { - _factoryVisitor.reset(assetId); - - node.accept(_factoryVisitor); - - if (_factoryVisitor.isInjectable) { - return new Future.value(_factoryVisitor.factory); - } else { - return new Future.value(null); - } - } - - CompileIdentifierMetadata readIdentifierMetadata( - VariableDeclaration decl, AssetId assetId) { - final name = decl.name.name; - return new CompileIdentifierMetadata( - name: name, moduleUrl: toAssetUri(assetId), value: _readValue(decl.initializer)); - } - - dynamic _readValue(dynamic initializer) { - try { - if (initializer is InstanceCreationExpression && - ((initializer as InstanceCreationExpression) - .constructorName - .toString() == - "Provider" || - (initializer as InstanceCreationExpression) - .constructorName - .toString() == - "Binding")) { - return _readProvider(initializer); - } else if (initializer is ListLiteral) { - return _readProviders(initializer); - } else { - return null; - } - } catch (e) { - return null; - } - } -} - -/// Evaluates the [Map] represented by `expression` and adds all `key`, -/// `value` pairs to `map`. If `expression` does not evaluate to a [Map], -/// throws a descriptive [FormatException]. -void _populateMap(Expression expression, Map map, String propertyName) { - var evaluated = naiveEval(expression); - if (evaluated is! Map) { - throw new FormatException( - 'Angular 2 expects a Map but could not understand the value for ' - '$propertyName.', - '$expression' /* source */); - } - evaluated.forEach((key, value) { - if (value != null) { - map[key] = '$value'; - } - }); -} - -/// Evaluates the [List] represented by `expression` and adds all values, -/// to `list`. If `expression` does not evaluate to a [List], throws a -/// descriptive [FormatException]. -void _populateList( - Expression expression, List list, String propertyName) { - var evaluated = naiveEval(expression); - if (evaluated is! List) { - throw new FormatException( - 'Angular 2 expects a List but could not understand the value for ' - '$propertyName.', - '$expression' /* source */); - } - list.addAll(evaluated.map((e) => e.toString())); -} - -/// Evaluates `node` and expects that the result will be a string. If not, -/// throws a [FormatException]. -String _expressionToString(Expression node, String nodeDescription) { - var value = naiveEval(node); - if (value is! String) { - throw new FormatException( - 'Angular 2 could not understand the value ' - 'in $nodeDescription.', - '$node' /* source */); - } - return value; -} - -/// Evaluates `node` and expects that the result will be a bool. If not, -/// throws a [FormatException]. -bool _expressionToBool(Expression node, String nodeDescription) { - var value = naiveEval(node); - if (value is! bool) { - throw new FormatException( - 'Angular 2 could not understand the value ' - 'in $nodeDescription.', - '$node' /* source */); - } - return value; -} - -class _CompileTypeMetadataVisitor extends Object - with RecursiveAstVisitor { - bool _isInjectable = false; - CompileTypeMetadata _type; - AssetId _assetId; - final AnnotationMatcher _annotationMatcher; - - _CompileTypeMetadataVisitor(this._annotationMatcher); - - bool get isInjectable => _isInjectable; - - CompileTypeMetadata get type => _type; - - void reset(AssetId assetId) { - this._assetId = assetId; - this._isInjectable = false; - this._type = null; - } - - @override - Object visitAnnotation(Annotation node) { - final isComponent = _annotationMatcher.isComponent(node, _assetId); - final isDirective = _annotationMatcher.isDirective(node, _assetId); - final isInjectable = _annotationMatcher.isInjectable(node, _assetId); - - _isInjectable = _isInjectable || isComponent || isDirective || isInjectable; - - return null; - } - - @override - Object visitClassDeclaration(ClassDeclaration node) { - node.metadata.accept(this); - final fieldTypes = _readFields(node); - if (this._isInjectable) { - final constructor = node.getConstructor(null); - final diDeps = constructor == null ? [] : - _getCompileDiDependencyMetadata(constructor.parameters, fieldTypes); - - _type = new CompileTypeMetadata( - moduleUrl: toAssetUri(_assetId), - name: node.name.toString(), - diDeps: diDeps, - runtime: null // Intentionally `null`, cannot be provided here. - ); - } - return null; - } - - Map _readFields(ClassDeclaration clazz) { - final res = {}; - clazz.members - .where((member) => member is FieldDeclaration) - .forEach((FieldDeclaration field) { - var type = field.fields.type; - if (type != null) { - field.fields.variables.forEach((VariableDeclaration decl) { - var key = '${decl.name}'; - res[key] = type; - }); - } - }); - return res; - } -} - -class _CompileFactoryMetadataVisitor extends Object - with RecursiveAstVisitor { - bool _isInjectable = false; - CompileFactoryMetadata _factory; - AssetId _assetId; - final AnnotationMatcher _annotationMatcher; - - _CompileFactoryMetadataVisitor(this._annotationMatcher); - - bool get isInjectable => _isInjectable; - - CompileFactoryMetadata get factory => _factory; - - void reset(AssetId assetId) { - this._assetId = assetId; - this._isInjectable = false; - this._factory = null; - } - - @override - Object visitAnnotation(Annotation node) { - _isInjectable = _annotationMatcher.isInjectable(node, _assetId); - return null; - } - - @override - Object visitFunctionDeclaration(FunctionDeclaration node) { - node.metadata.accept(this); - if (this._isInjectable) { - _factory = new CompileFactoryMetadata( - moduleUrl: toAssetUri(_assetId), - name: node.name.toString(), - diDeps: _getCompileDiDependencyMetadata(node.functionExpression.parameters, {}), - runtime: null // Intentionally `null`, cannot be provided here. - ); - } - return null; - } -} - -/// Visitor responsible for processing a [Directive] annotated -/// [ClassDeclaration] and creating a [CompileDirectiveMetadata] object. -class _DirectiveMetadataVisitor extends Object - with RecursiveAstVisitor { - /// Tests [Annotation]s to determine if they deifne a [Directive], - /// [Component], [View], or none of these. - final AnnotationMatcher _annotationMatcher; - - final _LifecycleHookVisitor _lifecycleVisitor; - - final _CompileTypeMetadataVisitor _typeVisitor; - - /// The [AssetId] we are currently processing. - AssetId _assetId; - - _DirectiveMetadataVisitor( - this._annotationMatcher, this._lifecycleVisitor, this._typeVisitor) { - reset(null); - } - - /// Whether the visitor has found a [Component] or [Directive] annotation - /// since the last call to `reset`. - bool _hasMetadata = false; - - // Annotation fields - CompileTypeMetadata _type; - bool _isComponent; - String _selector; - String _exportAs; - ChangeDetectionStrategy _changeDetection; - List _inputs; - List _outputs; - Map _host; - List _providers; - List _viewProviders; - List _queries; - List _viewQueries; - List _lifecycleHooks; - CompileTemplateMetadata _cmpTemplate; - CompileTemplateMetadata _viewTemplate; - - void reset(AssetId assetId) { - _lifecycleVisitor.reset(assetId); - _typeVisitor.reset(assetId); - _assetId = assetId; - - _type = null; - _isComponent = false; - _hasMetadata = false; - _selector = ''; - _exportAs = null; - _changeDetection = ChangeDetectionStrategy.Default; - _inputs = []; - _outputs = []; - _host = {}; - _providers = []; - _viewProviders = []; - _queries = []; - _viewQueries = []; - _lifecycleHooks = null; - _cmpTemplate = null; - _viewTemplate = null; - } - - bool get hasMetadata => _hasMetadata; - - get _template => _viewTemplate != null ? _viewTemplate : _cmpTemplate; - - CompileDirectiveMetadata createMetadata() { - return CompileDirectiveMetadata.create( - type: _type, - isComponent: _isComponent, - // NOTE(kegluneq): For future optimization. - selector: _selector, - exportAs: _exportAs, - changeDetection: _changeDetection, - inputs: _inputs, - outputs: _outputs, - host: _host, - providers: _providers, - viewProviders: _viewProviders, - queries: _queries, - viewQueries: _viewQueries, - lifecycleHooks: _lifecycleHooks, - template: _template); - } - - /// Ensures that we do not specify View values on an `@Component` annotation - /// when there is a @View annotation present. - void _validateTemplates() { - if (_cmpTemplate != null && _viewTemplate != null) { - var name = '(Unknown)'; - if (_type != null && _type.name != null && _type.name.isNotEmpty) { - name = _type.name; - } - log.warning( - 'Cannot specify view parameters on @Component when a @View ' - 'is present. Component name: ${name}', - asset: _assetId); - } - } - - @override - Object visitAnnotation(Annotation node) { - var isComponent = _annotationMatcher.isComponent(node, _assetId); - var isDirective = _annotationMatcher.isDirective(node, _assetId); - if (isDirective) { - if (_hasMetadata) { - throw new FormatException( - 'Only one Directive is allowed per class. ' - 'Found unexpected "$node".', - '$node' /* source */); - } - _isComponent = isComponent; - _hasMetadata = true; - if (isComponent) { - _cmpTemplate = - new _CompileTemplateMetadataVisitor(toAssetUri(_assetId)).visitAnnotation(node); - _validateTemplates(); - } - super.visitAnnotation(node); - } else if (_annotationMatcher.isView(node, _assetId)) { - if (_viewTemplate != null) { - // TODO(kegluneq): Support multiple views on a single class. - throw new FormatException( - 'Only one View is allowed per class. ' - 'Found unexpected "$node".', - '$node' /* source */); - } - _viewTemplate = - new _CompileTemplateMetadataVisitor(toAssetUri(_assetId)).visitAnnotation(node); - _validateTemplates(); - } - - // Annotation we do not recognize - no need to visit. - return null; - } - - @override - Object visitFieldDeclaration(FieldDeclaration node) { - for (var variable in node.fields.variables) { - for (var meta in node.metadata) { - if (_isAnnotation(meta, 'Output')) { - _addPropertyToType(_outputs, variable.name.toString(), meta); - } - - if (_isAnnotation(meta, 'Input')) { - _addPropertyToType(_inputs, variable.name.toString(), meta); - } - - if (_isAnnotation(meta, 'HostBinding')) { - final renamed = _getRenamedValue(meta); - if (renamed != null) { - _host['[${renamed}]'] = '${variable.name}'; - } else { - _host['[${variable.name}]'] = '${variable.name}'; - } - } - - if (_isAnnotation(meta, 'ContentChild')) { - this._queries.add(_createQueryMetadata(meta, false, true, variable.name.toString())); - } - if (_isAnnotation(meta, 'ContentChildren')) { - this._queries.add(_createQueryMetadata(meta, false, false, variable.name.toString())); - } - if (_isAnnotation(meta, 'ViewChild')) { - this._viewQueries.add(_createQueryMetadata(meta, true, true, variable.name.toString())); - } - if (_isAnnotation(meta, 'ViewChildren')) { - this._viewQueries.add(_createQueryMetadata(meta, false, false, variable.name.toString())); - } - } - } - return null; - } - - @override - Object visitMethodDeclaration(MethodDeclaration node) { - for (var meta in node.metadata) { - if (_isAnnotation(meta, 'Output') && node.isGetter) { - _addPropertyToType(_outputs, node.name.toString(), meta); - } - - if (_isAnnotation(meta, 'Input') && node.isSetter) { - _addPropertyToType(_inputs, node.name.toString(), meta); - } - - if (_isAnnotation(meta, 'ContentChild') && node.isSetter) { - this._queries.add(_createQueryMetadata(meta, false, true, node.name.toString())); - } - if (_isAnnotation(meta, 'ContentChildren') && node.isSetter) { - this._queries.add(_createQueryMetadata(meta, false, false, node.name.toString())); - } - if (_isAnnotation(meta, 'ViewChild') && node.isSetter) { - this._viewQueries.add(_createQueryMetadata(meta, true, true, node.name.toString())); - } - if (_isAnnotation(meta, 'ViewChildren') && node.isSetter) { - this._viewQueries.add(_createQueryMetadata(meta, false, false, node.name.toString())); - } - - if (_isAnnotation(meta, 'HostListener')) { - if (meta.arguments.arguments.length == 0 || - meta.arguments.arguments.length > 2) { - throw new ArgumentError( - 'Incorrect value passed to HostListener. Expected 1 or 2.'); - } - - final eventName = _getHostListenerEventName(meta); - final params = _getHostListenerParams(meta); - _host['(${eventName})'] = '${node.name}($params)'; - } - - if (_isAnnotation(meta, 'HostBinding') && node.isGetter) { - final renamed = _getRenamedValue(meta); - if (renamed != null) { - _host['[${renamed}]'] = '${node.name}'; - } else { - _host['[${node.name}]'] = '${node.name}'; - } - } - } - return null; - } - - void _addPropertyToType(List type, String name, Annotation meta) { - final renamed = _getRenamedValue(meta); - if (renamed != null) { - type.add('${name}: ${renamed}'); - } else { - type.add('${name}'); - } - } - - void _populateProviders(Expression providerValues, List providers) { - _checkMeta(); - - if (providerValues is ListLiteral) { - providers.addAll(_readProviders(providerValues)); - } else { - providers.add(_readIdentifier(providerValues)); - } - } - - //TODO Use AnnotationMatcher instead of string matching - bool _isAnnotation(Annotation node, String annotationName) { - var id = node.name; - final name = id is PrefixedIdentifier ? '${id.identifier}' : '$id'; - return name == annotationName; - } - - String _getRenamedValue(Annotation node) { - if (node.arguments.arguments.length == 1) { - final renamed = naiveEval(node.arguments.arguments.single); - if (renamed is! String) { - throw new ArgumentError( - 'Incorrect value. Expected a String, but got "${renamed}".'); - } - return renamed; - } else { - return null; - } - } - - String _getHostListenerEventName(Annotation node) { - final name = naiveEval(node.arguments.arguments.first); - if (name is! String) { - throw new ArgumentError( - 'Incorrect event name. Expected a String, but got "${name}".'); - } - return name; - } - - String _getHostListenerParams(Annotation node) { - if (node.arguments.arguments.length == 2) { - return naiveEval(node.arguments.arguments[1]).join(','); - } else { - return ""; - } - } - - @override - Object visitClassDeclaration(ClassDeclaration node) { - node.metadata.accept(this); - node.accept(_typeVisitor); - _type = _typeVisitor.type; - - if (this._hasMetadata) { - _lifecycleHooks = node.implementsClause != null - ? node.implementsClause.accept(_lifecycleVisitor) - : const []; - - node.members.accept(this); - } - return null; - } - - @override - Object visitNamedExpression(NamedExpression node) { - // TODO(kegluneq): Remove this limitation. - if (node.name is! Label || node.name.label is! SimpleIdentifier) { - throw new FormatException( - 'Angular 2 currently only supports simple identifiers in directives.', - '$node' /* source */); - } - var keyString = '${node.name.label}'; - switch (keyString) { - case 'selector': - _populateSelector(node.expression); - break; - case 'inputs': - _populateProperties(node.expression); - break; - case 'properties': - _populateProperties(node.expression); - break; - case 'host': - _populateHost(node.expression); - break; - case 'exportAs': - _populateExportAs(node.expression); - break; - case 'changeDetection': - _populateChangeDetection(node.expression); - break; - case 'outputs': - _populateEvents(node.expression); - break; - case 'events': - _populateEvents(node.expression); - break; - case 'providers': - _populateProviders(node.expression, _providers); - break; - case 'bindings': - _populateProviders(node.expression, _providers); - break; - case 'viewProviders': - _populateProviders(node.expression, _viewProviders); - break; - case 'viewBindings': - _populateProviders(node.expression, _viewProviders); - break; - } - return null; - } - - void _populateSelector(Expression selectorValue) { - _checkMeta(); - _selector = _expressionToString(selectorValue, 'Directive#selector'); - } - - void _checkMeta() { - if (!_hasMetadata) { - throw new ArgumentError('Incorrect value passed to readTypeMetadata. ' - 'Expected type is ClassDeclaration'); - } - } - - void _populateProperties(Expression inputsValue) { - _checkMeta(); - _populateList(inputsValue, _inputs, 'Directive#inputs'); - } - - void _populateHost(Expression hostValue) { - _checkMeta(); - _populateMap(hostValue, _host, 'Directive#host'); - } - - void _populateExportAs(Expression exportAsValue) { - _checkMeta(); - _exportAs = _expressionToString(exportAsValue, 'Directive#exportAs'); - } - - void _populateEvents(Expression outputsValue) { - _checkMeta(); - _populateList(outputsValue, _outputs, 'Directive#outputs'); - } - - void _populateChangeDetection(Expression value) { - _checkMeta(); - _changeDetection = _changeDetectionStrategies[value.toSource()]; - } - - static final Map _changeDetectionStrategies = - new Map.fromIterable(ChangeDetectionStrategy.values, - key: (v) => v.toString()); -} - -/// Visitor responsible for parsing an [ImplementsClause] and returning a -/// [List] that the [Directive] subscribes to. -class _LifecycleHookVisitor extends SimpleAstVisitor> { - /// Tests [Identifier]s of implemented interfaces to determine if they - /// correspond to [LifecycleHooks] values. - final InterfaceMatcher _ifaceMatcher; - - /// The [AssetId] we are currently processing. - AssetId _assetId; - - _LifecycleHookVisitor(this._ifaceMatcher); - - void reset(AssetId assetId) { - _assetId = assetId; - } - - @override - List visitImplementsClause(ImplementsClause node) { - if (node == null || node.interfaces == null) return const []; - - return node.interfaces - .map((TypeName ifaceTypeName) { - var id = ifaceTypeName.name; - if (_ifaceMatcher.isAfterContentChecked(id, _assetId)) { - return LifecycleHooks.AfterContentChecked; - } else if (_ifaceMatcher.isAfterContentInit(id, _assetId)) { - return LifecycleHooks.AfterContentInit; - } else if (_ifaceMatcher.isAfterViewChecked(id, _assetId)) { - return LifecycleHooks.AfterViewChecked; - } else if (_ifaceMatcher.isAfterViewInit(id, _assetId)) { - return LifecycleHooks.AfterViewInit; - } else if (_ifaceMatcher.isDoCheck(id, _assetId)) { - return LifecycleHooks.DoCheck; - } else if (_ifaceMatcher.isOnChange(id, _assetId)) { - return LifecycleHooks.OnChanges; - } else if (_ifaceMatcher.isOnDestroy(id, _assetId)) { - return LifecycleHooks.OnDestroy; - } else if (_ifaceMatcher.isOnInit(id, _assetId)) { - return LifecycleHooks.OnInit; - } - return null; - }) - .where((e) => e != null) - .toList(growable: false); - } -} - -/// Visitor responsible for parsing a @View [Annotation] and producing a -/// [CompileTemplateMetadata]. -class _CompileTemplateMetadataVisitor - extends RecursiveAstVisitor { - String _baseUrl; - ViewEncapsulation _encapsulation; - String _template; - String _templateUrl; - List _styles; - List _styleUrls; - - _CompileTemplateMetadataVisitor(this._baseUrl); - - @override - CompileTemplateMetadata visitAnnotation(Annotation node) { - super.visitAnnotation(node); - - if (_encapsulation == null && - _template == null && - _templateUrl == null && - _styles == null && - _styleUrls == null) { - return null; - } - - return new CompileTemplateMetadata( - encapsulation: _encapsulation, - template: _template, - templateUrl: _templateUrl, - styles: _styles, - styleUrls: _styleUrls, - baseUrl: _baseUrl); - } - - @override - CompileTemplateMetadata visitNamedExpression(NamedExpression node) { - // TODO(kegluneq): Remove this limitation. - if (node.name is! Label || node.name.label is! SimpleIdentifier) { - throw new FormatException( - 'Angular 2 currently only supports simple identifiers in directives.', - '$node' /* source */); - } - var keyString = '${node.name.label}'; - switch (keyString) { - case 'encapsulation': - _populateEncapsulation(node.expression); - break; - case 'template': - _populateTemplate(node.expression); - break; - case 'templateUrl': - _populateTemplateUrl(node.expression); - break; - case 'styles': - _populateStyles(node.expression); - break; - case 'styleUrls': - _populateStyleUrls(node.expression); - break; - } - return null; - } - - void _populateTemplate(Expression value) { - _template = _expressionToString(value, 'View#template'); - } - - void _populateTemplateUrl(Expression value) { - _templateUrl = _expressionToString(value, 'View#templateUrl'); - } - - void _populateStyles(Expression value) { - _styles = []; - _populateList(value, _styles, 'View#styles'); - } - - void _populateStyleUrls(Expression value) { - _styleUrls = []; - _populateList(value, _styleUrls, 'View#styleUrls'); - } - - void _populateEncapsulation(Expression value) { - _encapsulation = _viewEncapsulationMap[value.toSource()]; - } - - static final _viewEncapsulationMap = - new Map.fromIterable(ViewEncapsulation.values, key: (v) => v.toString()); -} - -/// Visitor responsible for processing a [Pipe] annotated -/// [ClassDeclaration] and creating a [CompilePipeMetadata] object. -class _PipeMetadataVisitor extends Object with RecursiveAstVisitor { - /// Tests [Annotation]s to determine if they deifne a [Directive], - /// [Component], [View], or none of these. - final AnnotationMatcher _annotationMatcher; - - /// The [AssetId] we are currently processing. - AssetId _assetId; - - _PipeMetadataVisitor(this._annotationMatcher) { - reset(null); - } - - /// Whether the visitor has found a [Pipe] annotation - /// since the last call to `reset`. - bool _hasMetadata = false; - - // Annotation fields - CompileTypeMetadata _type; - String _name; - bool _pure; - - void reset(AssetId assetId) { - _assetId = assetId; - - _hasMetadata = false; - _type = null; - _name = null; - _pure = null; - } - - bool get hasMetadata => _hasMetadata; - - CompilePipeMetadata createMetadata() { - return new CompilePipeMetadata(type: _type, name: _name, pure: _pure); - } - - @override - Object visitAnnotation(Annotation node) { - var isPipe = _annotationMatcher.isPipe(node, _assetId); - if (isPipe) { - if (_hasMetadata) { - throw new FormatException( - 'Only one Pipe is allowed per class. ' - 'Found unexpected "$node".', - '$node' /* source */); - } - _hasMetadata = true; - super.visitAnnotation(node); - } - - // Annotation we do not recognize - no need to visit. - return null; - } - - @override - Object visitClassDeclaration(ClassDeclaration node) { - node.metadata.accept(this); - if (this._hasMetadata) { - _type = new CompileTypeMetadata( - moduleUrl: toAssetUri(_assetId), - name: node.name.toString(), - runtime: null // Intentionally `null`, cannot be provided here. - ); - node.members.accept(this); - } - return null; - } - - @override - Object visitNamedExpression(NamedExpression node) { - // TODO(kegluneq): Remove this limitation. - if (node.name is! Label || node.name.label is! SimpleIdentifier) { - throw new FormatException( - 'Angular 2 currently only supports simple identifiers in pipes.', - '$node' /* source */); - } - var keyString = '${node.name.label}'; - switch (keyString) { - case 'name': - _popuplateName(node.expression); - break; - case 'pure': - _populatePure(node.expression); - break; - } - return null; - } - - void _checkMeta() { - if (!_hasMetadata) { - throw new ArgumentError('Incorrect value passed to readTypeMetadata. ' - 'Expected type is ClassDeclaration'); - } - } - - void _popuplateName(Expression nameValue) { - _checkMeta(); - _name = _expressionToString(nameValue, 'Pipe#name'); - } - - void _populatePure(Expression pureValue) { - _checkMeta(); - _pure = _expressionToBool(pureValue, 'Pipe#pure'); - } -} - -List _readProviders(ListLiteral providerValues) { - return providerValues.elements.map((el) { - if (el is PrefixedIdentifier || el is SimpleIdentifier) { - return _readIdentifier(el); - } else if (el is InstanceCreationExpression && - (el.constructorName.toString() == "Provider" || - el.constructorName.toString() == "Binding")) { - return _readProvider(el); - } else { - throw new ArgumentError( - 'Incorrect value. Expected a Provider or a String, but got "${el}".'); - } - }).toList(); -} - - -CompileProviderMetadata _readProvider(InstanceCreationExpression el) { - final token = el.argumentList.arguments.first; - - var useClass, useExisting, useValue, useFactory, deps, multi; - el.argumentList.arguments.skip(1).forEach((arg) { - switch (arg.name.toString()) { - case "useClass:": - final id = _readIdentifier(arg.expression); - useClass = new CompileTypeMetadata(prefix: id.prefix, name: id.name); - break; - case "toClass:": - final id = _readIdentifier(arg.expression); - useClass = new CompileTypeMetadata(prefix: id.prefix, name: id.name); - break; - case "useExisting:": - useExisting = _readToken(arg.expression); - break; - case "toAlias:": - useExisting = _readToken(arg.expression); - break; - case "useValue:": - useValue = _readValue(arg.expression); - break; - case "toValue:": - useValue = _readValue(arg.expression); - break; - case "useFactory:": - final id = _readIdentifier(arg.expression); - useFactory = new CompileFactoryMetadata( - name: id.name, prefix: id.prefix); - break; - case "toFactory:": - final id = _readIdentifier(arg.expression); - useFactory = new CompileFactoryMetadata( - name: id.name, prefix: id.prefix); - break; - case "deps:": - deps = _readDeps(arg.expression); - break; - case "multi:": - multi = _readValue(arg.expression); - break; - } - }); - return new CompileProviderMetadata( - token: _readToken(token), - useClass: useClass, - useExisting: useExisting, - useValue: useValue, - useFactory: useFactory, - multi: multi, - deps: deps); -} - -List _readDeps(ListLiteral deps) { - if (deps is! ListLiteral) { - throw new ArgumentError('Incorrect value is set as deps. ' - 'Expected type is ListLiteral'); - } - - return deps.elements.map((p) { - final list = p is ListLiteral ? p.elements : [p]; - final first = list.first; - - var token; - if (first is InstanceCreationExpression && - (first as InstanceCreationExpression).constructorName.toString() == - "Inject") { - token = _readToken(first.argumentList.arguments[0]); - } else { - token = _readToken(first); - } - - return new CompileDiDependencyMetadata( - token: token, - isSelf: _hasConst(list, "Self"), - isHost: _hasConst(list, "Host"), - isSkipSelf: _hasConst(list, "SkipSelf"), - isOptional: _hasConst(list, "Optional")); - }).toList(); -} - -_createQueryMetadata(Annotation a, bool defaultDescendantsValue, bool first, String propertyName) { - final selector = _readToken(a.arguments.arguments.first); - var descendants = defaultDescendantsValue; - var read = null; - a.arguments.arguments.skip(0).forEach((arg) { - if (arg is NamedExpression) { - var name = arg.name.toString(); - if (name == "descendants:") { - descendants = naiveEval(arg.expression); - } else if (name == "read:") { - read = _readToken(arg.expression); - } - } - }); - - final selectors = selector.value is String ? - selector.value.split(",").map( (value) => new CompileTokenMetadata(value: value) ).toList() : - [selector]; - return new CompileQueryMetadata( - selectors: selectors, descendants: descendants, first: first, - read: read, propertyName: propertyName); -} - -List _getCompileDiDependencyMetadata( - FormalParameterList params, Map fieldTypes) { - return params.parameters.map((p) { - if (p is DefaultFormalParameter) { - p = p.parameter; - } - - var token; - final isAttribute = _hasAnnotation(p, "Attribute"); - if (isAttribute) { - token = _readToken(_getAnnotation(p, "Attribute").arguments.arguments.first); - } else { - var type = null; - if (p is SimpleFormalParameter) { - type = p.type; - } else if (p is FieldFormalParameter) { - type = fieldTypes[p.identifier.toString()]; - } - final typeToken = type != null ? _readToken(type.name) : null; - final injectTokens = p.metadata - .where((m) => m.name.toString() == "Inject") - .map((m) => _readToken(m.arguments.arguments[0])); - token = injectTokens.isNotEmpty ? injectTokens.first : typeToken; - } - - var query; - if(_hasAnnotation(p, "Query")) { - query = _createQueryMetadata(_getAnnotation(p, "Query"), false, false, null); - } - if(_hasAnnotation(p, "ContentChildren")) { - query = _createQueryMetadata(_getAnnotation(p, "ContentChildren"), true, false, null); - } - - var viewQuery; - if(_hasAnnotation(p, "ViewQuery")) { - viewQuery = _createQueryMetadata(_getAnnotation(p, "ViewQuery"), false, false, null); - } - if(_hasAnnotation(p, "ViewChildren")) { - viewQuery = _createQueryMetadata(_getAnnotation(p, "ViewChildren"), true, false, null); - } - - return new CompileDiDependencyMetadata( - token: token, - isAttribute: _hasAnnotation(p, "Attribute"), - isSelf: _hasAnnotation(p, "Self"), - isHost: _hasAnnotation(p, "Host"), - isSkipSelf: _hasAnnotation(p, "SkipSelf"), - isOptional: _hasAnnotation(p, "Optional"), - query: query, - viewQuery: viewQuery); - }).toList(); -} - -_getAnnotation(p, String attrName) => - p.metadata.where((m) => m.name.toString() == attrName).first; - -_hasAnnotation(p, String attrName) => - p.metadata.where((m) => m.name.toString() == attrName).isNotEmpty; - -bool _hasConst(List list, String name) => list - .where((m) => - m is InstanceCreationExpression && m.constructorName.toString() == name) - .isNotEmpty; - -dynamic _readIdentifier(dynamic el) { - if (el is PrefixedIdentifier) { - final prefix = '${el.prefix}'; - if (prefix.length > 0 && prefix.toUpperCase()[0] == prefix[0]) { - throw new ArgumentError('Incorrect identifier "${el}".'); - } else { - return new CompileIdentifierMetadata( - name: '${el.identifier}', prefix: prefix); - } - } else if (el is SimpleIdentifier) { - return new CompileIdentifierMetadata(name: '$el'); - } else { - throw new ArgumentError('Incorrect identifier "${el}".'); - } -} - -dynamic _readValue(dynamic el) { - if (el is DoubleLiteral || el is IntegerLiteral || el is SimpleStringLiteral || el is BooleanLiteral){ - return el.value; - } else if (el is NullLiteral){ - return null; - } else { - return _readIdentifier(el); - } -} - -dynamic _readToken(dynamic el) { - if (el is DoubleLiteral || el is IntegerLiteral || el is SimpleStringLiteral || el is BooleanLiteral) { - return new CompileTokenMetadata(value: el.value); - } else if (el is InstanceCreationExpression) { - return new CompileTokenMetadata(identifier: new CompileIdentifierMetadata(name: '${el.constructorName}'), identifierIsInstance: true); - } else { - return new CompileTokenMetadata(identifier: _readIdentifier(el)); - } -} diff --git a/modules_dart/transform/lib/src/transform/common/url_resolver.dart b/modules_dart/transform/lib/src/transform/common/url_resolver.dart deleted file mode 100644 index 8c7d8c0ca1..0000000000 --- a/modules_dart/transform/lib/src/transform/common/url_resolver.dart +++ /dev/null @@ -1,64 +0,0 @@ -library angular2.transform.template_compiler.url_resolver; - -import 'package:barback/barback.dart'; - -export 'package:angular2/src/compiler/url_resolver.dart' show createOfflineCompileUrlResolver; - -String toAssetUri(AssetId assetId) { - if (assetId == null) throw new ArgumentError.notNull('assetId'); - return 'asset:${assetId.package}/${assetId.path}'; -} - -AssetId fromUri(String assetUri) { - if (assetUri == null) throw new ArgumentError.notNull('assetUri'); - if (assetUri.isEmpty) - throw new ArgumentError.value('(empty string)', 'assetUri'); - var uri = toAssetScheme(Uri.parse(assetUri)); - return new AssetId( - uri.pathSegments.first, uri.pathSegments.skip(1).join('/')); -} - -/// Converts `absoluteUri` to use the 'asset' scheme used in the Angular 2 -/// template compiler. -/// -/// The `scheme` of `absoluteUri` is expected to be either 'package' or -/// 'asset'. -Uri toAssetScheme(Uri absoluteUri) { - if (absoluteUri == null) throw new ArgumentError.notNull('absoluteUri'); - - if (!absoluteUri.isAbsolute) { - throw new ArgumentError.value(absoluteUri.toString(), 'absoluteUri', - 'Value passed must be an absolute uri'); - } - if (absoluteUri.scheme == 'asset') { - if (absoluteUri.pathSegments.length < 3) { - throw new FormatException( - 'An asset: URI must have at least 3 path ' - 'segments, for example ' - 'asset://.', - absoluteUri.toString()); - } - return absoluteUri; - } - if (absoluteUri.scheme != 'package') { - // Pass through URIs with non-package scheme - return absoluteUri; - } - - if (absoluteUri.pathSegments.length < 2) { - throw new FormatException( - 'A package: URI must have at least 2 path ' - 'segments, for example ' - 'package:/', - absoluteUri.toString()); - } - - var pathSegments = absoluteUri.pathSegments.toList()..insert(1, 'lib'); - return new Uri(scheme: 'asset', pathSegments: pathSegments); -} - -bool isDartCoreUri(String uri) { - if (uri == null) throw new ArgumentError.notNull('uri'); - if (uri.isEmpty) throw new ArgumentError.value('(empty string)', 'uri'); - return uri.startsWith('dart:'); -} diff --git a/modules_dart/transform/lib/src/transform/common/xhr_impl.dart b/modules_dart/transform/lib/src/transform/common/xhr_impl.dart deleted file mode 100644 index 6b39efa364..0000000000 --- a/modules_dart/transform/lib/src/transform/common/xhr_impl.dart +++ /dev/null @@ -1,31 +0,0 @@ -library angular2.transform.template_compiler.xhr_impl; - -import 'dart:async'; -import 'package:angular2/src/compiler/xhr.dart' show XHR; -import 'package:angular2/src/transform/common/asset_reader.dart'; -import 'package:angular2/src/transform/common/logging.dart'; -import 'package:angular2/src/transform/common/url_resolver.dart'; - -/// Transformer-specific implementation of XHR that is backed by an -/// [AssetReader]. -/// -/// This implementation expects urls using the asset: scheme. -/// See [src/transform/common/url_resolver.dart] for a way to convert package: -/// and relative urls to asset: urls. -class XhrImpl implements XHR { - final AssetReader _reader; - - XhrImpl(this._reader); - - Future get(String url) async { - final assetId = fromUri(url); - if (!url.startsWith('asset:')) { - log.warning('XhrImpl received unexpected url: $url'); - } - - if (!await _reader.hasInput(assetId)) { - throw new ArgumentError.value('Could not read asset at uri $url', 'url'); - } - return _reader.readAsString(assetId); - } -} diff --git a/modules_dart/transform/lib/src/transform/common/zone.dart b/modules_dart/transform/lib/src/transform/common/zone.dart deleted file mode 100644 index 7714a3dca9..0000000000 --- a/modules_dart/transform/lib/src/transform/common/zone.dart +++ /dev/null @@ -1,74 +0,0 @@ -library angular2.src.transform.common.zone; - -import 'dart:async'; - -import 'package:analyzer/analyzer.dart'; -import 'package:barback/barback.dart'; -import 'package:source_span/source_span.dart'; - -import 'package:angular2/src/compiler/offline_compiler.dart'; - -typedef _SimpleCallback(); - -// Keys used to store zone local values on the current zone. -final _loggerKey = #loggingZonedLoggerKey; -final _templateCompilerKey = #templateCompilerKey; - -/// Executes `fn` inside a new `Zone` with the provided zone-local values. -Future exec(_SimpleCallback fn, - {TransformLogger log, OfflineCompiler templateCompiler}) async { - return runZoned(() async { - try { - return await fn(); - } on AnalyzerError catch (e) { - // Do not worry about printing the stack trace, barback will handle - // that on its own when it catches the rethrown exception. - log.error(' Failed with ${e.runtimeType}\n${_friendlyError(e.error)}'); - rethrow; - } on AnalyzerErrorGroup catch (eGroup) { - // See above re: stack trace. - var numErrors = eGroup.errors.length; - if (numErrors == 1) { - log.error(_friendlyError(eGroup.errors[0].error)); - } else { - var buf = new StringBuffer(); - buf.writeln(' Failed with ${numErrors} errors'); - for (var i = 0; i < numErrors; ++i) { - buf.writeln( - 'Error ${i + 1}: ${_friendlyError(eGroup.errors[i].error)}'); - } - log.error('$buf'); - } - rethrow; - } - }, zoneValues: {_loggerKey: log, _templateCompilerKey: templateCompiler}); -} - -/// The [TransformLogger] for the current zone. -/// -/// Typically, this should not be used directly, since it will return `null` if -/// there is no [TransformLogger] registered on the current zone. Instead, -/// import `logging.dart` and use the `log` value it exports, which defines a -/// reasonable default value. -TransformLogger get log => Zone.current[_loggerKey] as TransformLogger; - -/// The [OfflineCompiler] for the current zone. -/// -/// This will return `null` if there is no [OfflineCompiler] registered on the -/// current zone. -OfflineCompiler get templateCompiler => - Zone.current[_templateCompilerKey] as OfflineCompiler; - -/// Generate a human-readable error message from `error`. -String _friendlyError(AnalysisError error) { - if (error.source != null) { - var file = - new SourceFile(error.source.contents.data, url: error.source.fullName); - - return file - .span(error.offset, error.offset + error.length) - .message(error.message, color: false); - } else { - return ': ${error.message}'; - } -} diff --git a/modules_dart/transform/lib/src/transform/deferred_rewriter/rewriter.dart b/modules_dart/transform/lib/src/transform/deferred_rewriter/rewriter.dart deleted file mode 100644 index c423592a65..0000000000 --- a/modules_dart/transform/lib/src/transform/deferred_rewriter/rewriter.dart +++ /dev/null @@ -1,179 +0,0 @@ -library angular2.transform.deferred_rewriter.rewriter; - -import 'dart:async'; - -import 'package:analyzer/analyzer.dart'; -import 'package:analyzer/src/generated/ast.dart'; -import 'package:barback/barback.dart'; - -import 'package:angular2/src/transform/common/asset_reader.dart'; -import 'package:angular2/src/transform/common/logging.dart'; -import 'package:angular2/src/transform/common/names.dart'; -import 'package:angular2/src/transform/common/url_resolver.dart'; - -/// Rewrites `loadLibrary` calls to initialize libraries once loaded. -/// -/// 1. Finds all the deferred library imports and loadLibrary invocations in -/// `_entryPoint` -/// 2. Removes any libraries that don't require angular codegen. -/// 3. For the remaining libraries, rewrites the import to the corresponding -/// `.ngfactory.dart` file. -/// 4. Chains a future to the `loadLibrary` call which initializes the -/// library. -/// -/// To the extent possible, this method does not change line numbers or -/// offsets in the provided code to facilitate debugging via source maps. -Future rewriteLibrary(AssetId entryPoint, AssetReader reader) async { - var code = await reader.readAsString(entryPoint); - - return logElapsedAsync(() async { - // If we can determine there are no deferred libraries, avoid additional - // parsing the entire file and bail early. - var onlyDirectives = parseDirectives(code, name: entryPoint.path); - if (onlyDirectives == null) { - log.fine('No directives parsed, bailing early.', asset: entryPoint); - return null; - } - - final importVisitor = new _FindDeferredLibraries(reader, entryPoint); - onlyDirectives.directives.accept(importVisitor); - - // Get imports that need rewriting. - final deferredImports = await importVisitor.process(); - if (deferredImports.isEmpty) { - log.fine('There are no deferred library imports that need rewriting.', - asset: entryPoint); - return null; - } - - var node = parseCompilationUnit(code, name: entryPoint.path); - if (node == null) { - log.fine('No declarations parsed, bailing early.', asset: entryPoint); - return null; - } - - final declarationsVisitor = new _FindLoadLibraryCalls(deferredImports); - node.declarations.accept(declarationsVisitor); - - // Get libraries that need rewriting. - if (declarationsVisitor.loadLibraryInvocations.isEmpty) { - log.fine( - 'There are no loadLibrary invocations that need to be rewritten.', - asset: entryPoint); - return null; - } - - return _rewriteLibrary( - code, deferredImports, declarationsVisitor.loadLibraryInvocations); - }, operationName: 'rewriteDeferredLibraries', assetId: entryPoint); -} - -/// Rewrites the original [code] to initialize deferred libraries prior to use. -/// -/// Note: This method may modify the order of [imports] and [loadLibCalls]. -String _rewriteLibrary(String code, List imports, - List loadLibCalls) { - /// Compares two [AstNode]s by position in the source code. - var _compareNodes = (AstNode a, AstNode b) => a.offset - b.offset; - - // Necessary for indexes into [code] to function. - imports.sort(_compareNodes); - loadLibCalls.sort(_compareNodes); - - var buf = new StringBuffer(); - var idx = imports.fold(0, (int lastIdx, ImportDirective node) { - // Write from where we left off until the start of the import uri. - buf.write(code.substring(lastIdx, node.uri.offset)); - // Rewrite the uri to be that of the generated file. - buf.write("'${toTemplateExtension('${node.uri.stringValue}')}'"); - // Update the last index we've processed. - return node.uri.end; - }); - - idx = loadLibCalls.fold(idx, (int lastIdx, MethodInvocation node) { - buf.write(code.substring(lastIdx, node.offset)); - var prefix = (node.realTarget as SimpleIdentifier).name; - // Chain a future that initializes the reflector. - buf.write('$prefix.loadLibrary().then((_) {$prefix.initReflector();})'); - return node.end; - }); - if (idx < code.length) buf.write(code.substring(idx)); - return '$buf'; -} - -/// Finds all `deferred` [ImportDirectives]s in an Ast that require init. -/// -/// Use this to visit all [ImportDirective]s, then call [process] to get only -/// those [ImportDirective]s which are `deferred` and need Angular 2 -/// initialization before use. -class _FindDeferredLibraries extends Object with SimpleAstVisitor { - final _deferredImports = []; - final _urlResolver = createOfflineCompileUrlResolver(); - - final AssetReader _reader; - final AssetId _entryPoint; - final String _entryPointUri; - - _FindDeferredLibraries(this._reader, AssetId entryPoint) - : _entryPoint = entryPoint, - _entryPointUri = toAssetUri(entryPoint); - - @override - Object visitImportDirective(ImportDirective node) { - if (node.deferredKeyword != null) { - _deferredImports.add(node); - } - return null; - } - - /// Gets the [AssetId] for the .ng_meta.json file associated with [import]. - AssetId _getAssociatedMetaAsset(ImportDirective import) { - final importUri = stringLiteralToString(import.uri); - final associatedMetaUri = toMetaExtension(importUri); - return fromUri(_urlResolver.resolve(_entryPointUri, associatedMetaUri)); - } - - /// Gets a list of `deferred` [ImportDirective]s which need init. - /// - /// Removes all [ImportDirective]s from [_deferredImports] without an - /// associated .ng_meta.json file. - Future> process() async { - // Parallel array with whether the input has an associated .ng_meta.json - // file. - final List hasInputs = await Future.wait( - _deferredImports.map(_getAssociatedMetaAsset).map(_reader.hasInput)); - - // Filter out any deferred imports that do not have an associated generated - // file. - // Iteration order is important! - for (var i = _deferredImports.length - 1; i >= 0; --i) { - if (!hasInputs[i]) { - _deferredImports.removeAt(i); - } - } - return _deferredImports; - } -} - -/// Finds all `loadLibrary` calls in the Ast that require init. -class _FindLoadLibraryCalls extends Object with RecursiveAstVisitor { - /// The prefixes used by all `deferred` [ImportDirective]s that need init. - final Set _deferredPrefixes; - final loadLibraryInvocations = []; - - _FindLoadLibraryCalls(List deferredImports) - : _deferredPrefixes = - new Set.from(deferredImports.map((import) => import.prefix.name)); - - @override - Object visitMethodInvocation(MethodInvocation node) { - if (node.methodName.name == 'loadLibrary') { - var prefix = (node.realTarget as SimpleIdentifier).name; - if (_deferredPrefixes.contains(prefix)) { - loadLibraryInvocations.add(node); - } - } - // Important! Children could include more `loadLibrary` calls. - return super.visitMethodInvocation(node); - } -} diff --git a/modules_dart/transform/lib/src/transform/deferred_rewriter/transformer.dart b/modules_dart/transform/lib/src/transform/deferred_rewriter/transformer.dart deleted file mode 100644 index b414f7fed4..0000000000 --- a/modules_dart/transform/lib/src/transform/deferred_rewriter/transformer.dart +++ /dev/null @@ -1,94 +0,0 @@ -library angular2.transform.deferred_rewriter.transformer; - -import 'dart:async'; - -import 'package:barback/barback.dart'; - -import 'package:angular2/src/transform/common/asset_reader.dart'; -import 'package:angular2/src/transform/common/names.dart'; -import 'package:angular2/src/transform/common/zone.dart' as zone; - -import 'rewriter.dart'; - -/// Transformer which rewrites deferred imports and `loadLibrary` calls. -/// -/// Deferred imports with associated initialization code are rewritten to -/// point to their associated generated code file. -/// `loadLibrary` calls for libraries with associated initialization methods -/// are rewritten to initialize after the library is loaded and before use. -class DeferredRewriter extends AggregateTransformer implements LazyTransformer { - DeferredRewriter(); - - /// Ctor which tells pub that this can be run as a standalone transformer. - DeferredRewriter.asPlugin(BarbackSettings _); - - @override - declareOutputs(DeclaringTransform transform) { - transform.declareOutput(transform.primaryId); - } - - @override - dynamic classifyPrimary(AssetId id) { - // Map .dart and .dart.deferredCount => . - // Anything else to `null`. - var extension = null; - if (id.path.endsWith(DEFERRED_EXTENSION)) { - extension = DEFERRED_EXTENSION; - } else if (id.path.endsWith('.dart') && !isGenerated(id.path)) { - extension = '.dart'; - } else { - return null; - } - return id.path.substring(0, id.path.length - extension.length); - } - - @override - Future apply(AggregateTransform transform) async { - final dartAsset = await _assetToProcess(transform); - if (dartAsset == null) return null; - return applyImpl(transform, dartAsset.id); - } - - /// Transforms the asset with id [id]. - /// - /// [transform] must be an [AggregateTransform] or [Transform]. - Future applyImpl(dynamic transform, AssetId id) { - assert(transform is AggregateTransform || transform is Transform); - - return zone.exec(() async { - var transformedCode = await rewriteDeferredLibraries( - new AssetReader.fromTransform(transform), id); - if (transformedCode != null) { - transform.addOutput(new Asset.fromString(id, transformedCode)); - } - }, log: transform.logger); - } -} - -/// Returns the asset we need to process or `null` if none exists. -/// -/// Consumes the .dart.deferredCount asset if it is present. -Future _assetToProcess(AggregateTransform transform) async { - // We only need to process .dart files that have an associated - // .dart.deferredCount file with a value != "0". - // - // The .dart.deferredCount file is generated by a previous phase for files - // which have deferred imports. An absent .dart.deferredCount asset is the - // treated the same as a .dart.deferredCount asset with value "0". - var dartAsset, deferredCountAsset; - await for (Asset a in transform.primaryInputs) { - if (a.id.path.endsWith(DEFERRED_EXTENSION)) { - deferredCountAsset = a; - } else if (a.id.path.endsWith('.dart')) { - dartAsset = a; - } - } - if (deferredCountAsset == null) return null; - // No longer necessary. - transform.consumePrimary(deferredCountAsset.id); - if ((await deferredCountAsset.readAsString()) == "0") return null; - return dartAsset; -} - -Future rewriteDeferredLibraries(AssetReader reader, AssetId id) => - rewriteLibrary(id, reader); diff --git a/modules_dart/transform/lib/src/transform/directive_metadata_linker/ng_deps_linker.dart b/modules_dart/transform/lib/src/transform/directive_metadata_linker/ng_deps_linker.dart deleted file mode 100644 index 84255395b2..0000000000 --- a/modules_dart/transform/lib/src/transform/directive_metadata_linker/ng_deps_linker.dart +++ /dev/null @@ -1,83 +0,0 @@ -library angular2.transform.directive_metadata_linker.ng_deps_linker; - -import 'dart:async'; - -import 'package:angular2/compiler.dart' show UrlResolver; -import 'package:angular2/src/transform/common/asset_reader.dart'; -import 'package:angular2/src/transform/common/logging.dart'; -import 'package:angular2/src/transform/common/names.dart'; -import 'package:angular2/src/transform/common/model/import_export_model.pb.dart'; -import 'package:angular2/src/transform/common/model/ng_deps_model.pb.dart'; -import 'package:angular2/src/transform/common/url_resolver.dart'; -import 'package:barback/barback.dart'; - -/// Modifies the [NgDepsModel] represented by `entryPoint` to import its -/// dependencies' associated, generated files. -/// -/// For example, if entry_point.dart imports dependency.dart, this will check if -/// dependency.ng_meta.json exists. If it does, we add an entry to the -/// `depImports` of [NgDepsModel] for dependency.ngfactory.dart. -/// -/// We use this information later to ensure that each file's dependencies are -/// initialized when that file is initialized. -Future linkNgDeps(NgDepsModel ngDepsModel, AssetReader reader, - AssetId assetId, UrlResolver resolver) async { - if (ngDepsModel == null) return null; - return logElapsedAsync(() async { - var linkedDepsMap = - await _processNgImports(ngDepsModel, reader, assetId, resolver); - - if (linkedDepsMap.isEmpty) { - // We are not calling `initReflector` on any other libraries, but we still - // return the model to ensure it is written to code. - return ngDepsModel; - } - - final seen = new Set(); - var idx = 0; - final allDeps = [ngDepsModel.imports, ngDepsModel.exports].expand((e) => e); - for (var dep in allDeps) { - if (linkedDepsMap.containsKey(dep.uri) && !seen.contains(dep.uri)) { - seen.add(dep.uri); - var linkedModel = new ImportModel() - ..uri = toTemplateExtension(dep.uri) - ..prefix = 'i${idx++}'; - // TODO(kegluneq): Preserve combinators? - ngDepsModel.depImports.add(linkedModel); - } - } - return ngDepsModel; - }, operationName: 'linkNgDeps', assetId: assetId); -} - -bool _isNotDartDirective(dynamic model) => !isDartCoreUri(model.uri); - -/// Maps the `uri` of each input [ImportModel] or [ExportModel] to its -/// associated `.ng_deps.json` file, if one exists. -Future> _processNgImports(NgDepsModel model, - AssetReader reader, AssetId assetId, UrlResolver resolver) async { - final importsAndExports = - new List.from(model.imports.where((i) => !i.isDeferred)) - ..addAll(model.exports); - final retVal = {}; - final assetUri = toAssetUri(assetId); - return Future - .wait( - importsAndExports.where(_isNotDartDirective).map((dynamic directive) { - // Check whether the import or export generated summary NgMeta information. - final summaryJsonUri = - resolver.resolve(assetUri, toSummaryExtension(directive.uri)); - return reader.hasInput(fromUri(summaryJsonUri)).then((hasInput) { - if (hasInput) { - retVal[directive.uri] = summaryJsonUri; - } - }, onError: (err, stack) { - log.warning( - 'Error while looking for $summaryJsonUri. ' - 'Message: $err\n' - 'Stack: $stack', - asset: assetId); - }); - })) - .then((_) => retVal); -} diff --git a/modules_dart/transform/lib/src/transform/directive_metadata_linker/ng_meta_linker.dart b/modules_dart/transform/lib/src/transform/directive_metadata_linker/ng_meta_linker.dart deleted file mode 100644 index f0c7487f5c..0000000000 --- a/modules_dart/transform/lib/src/transform/directive_metadata_linker/ng_meta_linker.dart +++ /dev/null @@ -1,460 +0,0 @@ -library angular2.transform.directive_metadata_linker.linker; - -import 'dart:async'; -import 'dart:convert'; - -import 'package:angular2/src/compiler/compile_metadata.dart'; -import 'package:angular2/src/transform/common/asset_reader.dart'; -import 'package:angular2/src/transform/common/logging.dart'; -import 'package:angular2/src/transform/common/names.dart'; -import 'package:angular2/src/transform/common/ng_meta.dart'; -import 'package:angular2/src/transform/common/url_resolver.dart'; -import 'package:barback/barback.dart'; - -import 'ng_deps_linker.dart'; - -/// Returns [NgMeta] associated with the provided asset combined with the [NgMeta] of -/// all files `export`ed from the original file. -/// -/// The returned NgMeta has all the identifiers resolved. -/// -/// `summaryAssetId` - the unlinked asset id (source) -/// `summaryAssetId` - the linked asset id (dest) -/// `resolvedIdentifiers` - preresolved identifiers (e.g., Window) -/// `ngMetas` - in memory cache of linked ngMeta files -Future linkDirectiveMetadata(AssetReader reader, AssetId summaryAssetId, - AssetId metaAssetId, Map resolvedIdentifiers, - [bool errorOnMissingIdentifiers = true, Map ngMetas]) async { - if (ngMetas == null) ngMetas = {}; - - var ngMeta = await _readNgMeta(reader, summaryAssetId, ngMetas); - if (ngMeta == null || ngMeta.isEmpty) return null; - - await Future.wait([ - linkNgDeps(ngMeta.ngDeps, reader, summaryAssetId, _urlResolver), - logElapsedAsync(() async { - final linker = new _Linker(reader, ngMetas, resolvedIdentifiers, errorOnMissingIdentifiers); - await linker.linkRecursive(ngMeta, metaAssetId, new Set()); - return ngMeta; - }, operationName: 'linkDirectiveMetadata', assetId: summaryAssetId) - ]); - - return ngMeta; -} - -final _urlResolver = createOfflineCompileUrlResolver(); - -Future _readNgMeta(AssetReader reader, AssetId ngMetaAssetId, - Map ngMetas) async { - if (ngMetas.containsKey(ngMetaAssetId)) return ngMetas[ngMetaAssetId]; - if (!(await reader.hasInput(ngMetaAssetId))) return null; - - var ngMetaJson = await reader.readAsString(ngMetaAssetId); - if (ngMetaJson == null || ngMetaJson.isEmpty) return null; - - return new NgMeta.fromJson(JSON.decode(ngMetaJson)); -} - -class _Linker { - final AssetReader reader; - final Map ngMetas; - final Map resolvedIdentifiers; - final bool errorOnMissingIdentifiers; - - _Linker(this.reader, this.ngMetas, this.resolvedIdentifiers, this.errorOnMissingIdentifiers); - - Future linkRecursive(NgMeta ngMeta, AssetId assetId, Set seen) async { - if (seen.contains(assetId)) return ngMeta; - - final newSeen = new Set.from(seen) - ..add(assetId); - - await _resolveDeps(ngMeta, assetId, newSeen); - await _resolveIdentifiers(ngMeta, assetId); - await _mergeExports(ngMeta, assetId); - - ngMetas[assetId] = ngMeta; - - return ngMeta; - } - - Future _resolveDeps(NgMeta ngMeta, AssetId assetId, Set seen) async { - final importsAndExports = []; - if (ngMeta != null && - ngMeta.ngDeps != null && - ngMeta.ngDeps.exports != null) - importsAndExports.addAll(ngMeta.ngDeps.exports); - - if (ngMeta != null && - ngMeta.needsResolution && - ngMeta.ngDeps != null && - ngMeta.ngDeps.imports != null) - importsAndExports - .addAll(ngMeta.ngDeps.imports.where((i) => !i.isDeferred)); - - final assetUri = toAssetUri(assetId); - for (var withUri in importsAndExports) { - if (isDartCoreUri(withUri.uri)) continue; - final metaAsset = - fromUri(_urlResolver.resolve(assetUri, toMetaExtension(withUri.uri))); - final summaryAsset = fromUri( - _urlResolver.resolve(assetUri, toSummaryExtension(withUri.uri))); - - if (!await _hasMeta(metaAsset)) { - final ngMeta = await _readSummary(summaryAsset); - if (ngMeta != null) { - await linkRecursive(ngMeta, metaAsset, seen); - } - } - } - } - - Future _resolveIdentifiers(NgMeta ngMeta, AssetId assetId) async { - if (ngMeta.needsResolution) { - final resolver = new _NgMetaIdentifierResolver( - assetId, reader, ngMetas, resolvedIdentifiers, errorOnMissingIdentifiers); - return resolver.resolveNgMeta(ngMeta); - } else { - return null; - } - } - - Future _mergeExports(NgMeta ngMeta, AssetId assetId) async { - if (ngMeta == null || - ngMeta.ngDeps == null || - ngMeta.ngDeps.exports == null) { - return ngMeta; - } - var assetUri = toAssetUri(assetId); - - return Future.wait(ngMeta.ngDeps.exports.map((r) => r.uri) - .where((export) => !isDartCoreUri(export)) - .map((export) => - _urlResolver.resolve(assetUri, toMetaExtension(export))) - .map((uri) async { - try { - final exportAssetId = fromUri(uri); - final exportNgMeta = await _readMeta(exportAssetId); - if (exportNgMeta != null) { - ngMeta.addAll(exportNgMeta); - } - } catch (err, st) { - // Log and continue. - log.warning('Failed to fetch $uri. Message: $err.\n$st', - asset: assetId); - } - })); - } - - Future _readSummary(AssetId summaryAssetId) async { - if (!(await reader.hasInput(summaryAssetId))) return null; - - var ngMetaJson = await reader.readAsString(summaryAssetId); - if (ngMetaJson == null || ngMetaJson.isEmpty) return null; - return new NgMeta.fromJson(JSON.decode(ngMetaJson)); - } - - Future _readMeta(AssetId metaAssetId) async { - final content = await _readNgMeta(reader, metaAssetId, ngMetas); - if (content != null) { - ngMetas[metaAssetId] = content; - } - return content; - } - - Future _hasMeta(AssetId ngMetaAssetId) async { - return ngMetas.containsKey(ngMetaAssetId) || - await reader.hasInput(ngMetaAssetId); - } -} - -class _NgMetaIdentifierResolver { - final Map resolvedIdentifiers; - final Map ngMetas; - final AssetReader reader; - final AssetId entryPoint; - final bool errorOnMissingIdentifiers; - - _NgMetaIdentifierResolver(this.entryPoint, this.reader, this.ngMetas, this.resolvedIdentifiers, this.errorOnMissingIdentifiers); - - Future resolveNgMeta(NgMeta ngMeta) async { - final ngMetaMap = await _extractNgMetaMap(ngMeta); - ngMeta.identifiers.forEach((_, meta) { - if (meta is CompileIdentifierMetadata && meta.value != null) { - meta.value = _resolveProviders(ngMetaMap, meta.value, "root"); - } - }); - - ngMeta.identifiers.forEach((_, meta) { - if (meta is CompileDirectiveMetadata) { - _resolveProviderMetadata(ngMetaMap, meta); - _resolveQueryMetadata(ngMetaMap, meta); - _resolveDiDependencyMetadata(ngMetaMap, meta.type.name, meta.type.diDeps); - } else if (meta is CompileTypeMetadata) { - _resolveDiDependencyMetadata(ngMetaMap, meta.name, meta.diDeps); - } else if (meta is CompileFactoryMetadata) { - _resolveDiDependencyMetadata(ngMetaMap, meta.name, meta.diDeps); - } - }); - } - - List _resolveProviders(Map ngMetaMap, Object value, String neededBy) { - - if (value is List) { - final res = []; - for (var v in value) { - res.addAll(_resolveProviders(ngMetaMap, v, neededBy)); - } - return res; - - } else if (value is CompileProviderMetadata) { - _resolveProvider(ngMetaMap, neededBy, value); - - return [value]; - - } else if (value is CompileIdentifierMetadata) { - final resolved = _resolveIdentifier(ngMetaMap, neededBy, value); - if (resolved == null) return []; - - if (resolved is CompileTypeMetadata) { - return [new CompileProviderMetadata(token: new CompileTokenMetadata(identifier: resolved), useClass: resolved)]; - - } else if (resolved is CompileIdentifierMetadata && resolved.value is List) { - return _resolveProviders(ngMetaMap, resolved.value, neededBy); - - } else if (resolved is CompileIdentifierMetadata && resolved.value is CompileProviderMetadata) { - return [_resolveProviders(ngMetaMap, resolved.value, neededBy)]; - - } else { - return []; - } - - } else { - return []; - } - } - - void _resolveProviderMetadata(Map ngMetaMap, CompileDirectiveMetadata dirMeta) { - final neededBy = dirMeta.type.name; - if (dirMeta.providers != null) { - dirMeta.providers = - _resolveProviders(ngMetaMap, dirMeta.providers, neededBy); - } - - if (dirMeta.viewProviders != null) { - dirMeta.viewProviders = - _resolveProviders(ngMetaMap, dirMeta.viewProviders, neededBy); - } - } - - void _resolveQueryMetadata(Map ngMetaMap, CompileDirectiveMetadata dirMeta) { - final neededBy = dirMeta.type.name; - if (dirMeta.queries != null) { - _resolveQueries(ngMetaMap, dirMeta.queries, neededBy); - } - if (dirMeta.viewQueries != null) { - _resolveQueries(ngMetaMap, dirMeta.viewQueries, neededBy); - } - } - - void _resolveQueries(Map ngMetaMap, List queries, String neededBy) { - queries.forEach((q) { - q.selectors.forEach((s) => s.identifier = _resolveIdentifier(ngMetaMap, neededBy, s.identifier)); - if (q.read != null) { - q.read.identifier = _resolveIdentifier(ngMetaMap, neededBy, q.read.identifier); - } - }); - } - - void _resolveProvider(Map ngMetaMap, - String neededBy, CompileProviderMetadata provider) { - provider.token.identifier = _resolveIdentifier(ngMetaMap, neededBy, provider.token.identifier); - if (provider.useClass != null) { - provider.useClass = - _resolveIdentifier(ngMetaMap, neededBy, provider.useClass); - } - if (provider.useExisting != null) { - provider.useExisting.identifier = - _resolveIdentifier(ngMetaMap, neededBy, provider.useExisting.identifier); - } - if (provider.useValue != null) { - provider.useValue = - _resolveIdentifier(ngMetaMap, neededBy, provider.useValue); - } - if (provider.useFactory != null) { - provider.useFactory = _resolveIdentifier(ngMetaMap, neededBy, provider.useFactory); - } - if (provider.deps != null) { - _resolveDiDependencyMetadata(ngMetaMap, neededBy, provider.deps); - };; - } - - void _resolveDiDependencyMetadata(Map ngMetaMap, - String neededBy, List deps) { - if (deps == null) return; - for (var dep in deps) { - if (dep.token != null) { - _setModuleUrl(ngMetaMap, neededBy, dep.token.identifier); - } - if (dep.query != null) { - dep.query.selectors - .forEach((s) => _setModuleUrl(ngMetaMap, neededBy, s.identifier)); - } - if (dep.viewQuery != null) { - dep.viewQuery.selectors - .forEach((s) => _setModuleUrl(ngMetaMap, neededBy, s.identifier)); - } - } - } - - void _setModuleUrl(Map ngMetaMap, String neededBy, dynamic id) { - final resolved = _resolveIdentifier(ngMetaMap, neededBy, id); - if (resolved != null && id is CompileIdentifierMetadata) { - id.moduleUrl = resolved.moduleUrl; - } - } - - /// Resolves an identifier using the provided ngMetaMap. - /// - /// ngMetaMap - a map of prefixes to the symbols available via those prefixes - /// neededBy - a type using the unresolved symbol. It's used to generate - /// good error message. - /// id - an unresolved id. - dynamic _resolveIdentifier(Map ngMetaMap, String neededBy, dynamic id) { - if (id is String || id is bool || id is num || id == null) return id; - if (id is CompileMetadataWithIdentifier) { - id = id.identifier; - } - - if (id.moduleUrl != null) return id; - - final prefix = id.prefix == null ? "" : id.prefix; - - if (!ngMetaMap.containsKey(prefix)) { - final resolved = _resolveSpecialCases(id); - if (resolved != null) { - return resolved; - } else { - final message = 'Missing prefix "${prefix}" ' - 'needed by "${neededBy}" from metadata map'; - if (errorOnMissingIdentifiers) { - log.error(message, asset: entryPoint); - } else { - log.warning(message, asset: entryPoint); - } - return null; - } - } - - final depNgMeta = ngMetaMap[prefix]; - if (depNgMeta.identifiers.containsKey(id.name)) { - final res = depNgMeta.identifiers[id.name]; - if (res is CompileMetadataWithIdentifier) { - return res.identifier; - } else { - return res; - } - } else if (_isPrimitive(id.name)) { - return id; - } else { - final resolved = _resolveSpecialCases(id); - if (resolved != null) { - return resolved; - } else { - final message = 'Missing identifier "${id.name}" ' - 'needed by "${neededBy}" from metadata map'; - if (errorOnMissingIdentifiers) { - log.error(message, asset: entryPoint); - } else { - log.warning(message, asset: entryPoint); - } - return null; - } - } - } - - dynamic _resolveSpecialCases(CompileIdentifierMetadata id) { - if (resolvedIdentifiers != null && - resolvedIdentifiers.containsKey(id.name)) { - return new CompileIdentifierMetadata( - name: id.name, moduleUrl: resolvedIdentifiers[id.name]); - - // these are so common that we special case them in the transformer - } else if (id.name == "Window" || id.name == "Document") { - return new CompileIdentifierMetadata(name: id.name, moduleUrl: 'dart:html'); - } else if (id.name == "Profiler") { - return new CompileIdentifierMetadata(name: id.name, moduleUrl: 'asset:perf_api/lib/perf_api.dart'); - } else if (id.name == "Logger") { - return new CompileIdentifierMetadata(name: id.name, moduleUrl: 'asset:logging/lib/logging.dart'); - } else if (id.name == "Clock") { - return new CompileIdentifierMetadata(name: id.name, moduleUrl: 'asset:quiver/lib/src/time/clock.dart'); - } else if (id.name == "Log") { - return new CompileIdentifierMetadata(name: id.name, moduleUrl: 'asset:angular2/lib/src/testing/utils.dart'); - } else if (id.name == "TestComponentBuilder") { - return new CompileIdentifierMetadata(name: id.name, moduleUrl: 'asset:angular2/lib/src/testing/test_component_builder.dart'); - } else if (id.name == "Stream") { - return new CompileIdentifierMetadata(name: id.name, moduleUrl: 'dart:async'); - } else if (id.name == "StreamController") { - return new CompileIdentifierMetadata(name: id.name, moduleUrl: 'dart:async'); - } else if (id.name == "FakeAsync") { - return new CompileIdentifierMetadata(name: id.name, moduleUrl: 'asset:angular2/lib/src/testing/fake_async.dart'); - } else if (id.name == "StreamTracer") { - return new CompileIdentifierMetadata(name: id.name, moduleUrl: 'asset:streamy/lib/src/core/tracing.dart'); - } else if (id.name == "Tracer") { - return new CompileIdentifierMetadata(name: id.name, moduleUrl: 'asset:streamy/lib/src/core/tracing.dart'); - } else if (id.name == "RequestHandler") { - return new CompileIdentifierMetadata(name: id.name, moduleUrl: 'asset:streamy/lib/src/core/request_handler.dart'); - } else if (id.name == "BatchingStrategy") { - return new CompileIdentifierMetadata(name: id.name, moduleUrl: 'asset:streamy/lib/src/extra/request_handler/batching.dart'); - } else if (id.name == "ProxyClient") { - return new CompileIdentifierMetadata(name: id.name, moduleUrl: 'asset:streamy/lib/src/extra/request_handler/proxy.dart'); - } else if (id.name == "StreamyHttpService") { - return new CompileIdentifierMetadata(name: id.name, moduleUrl: 'asset:streamy/lib/src/toolbox/http.dart'); - } else { - return null; - } - } - - bool _isPrimitive(String typeName) => - typeName == "String" || - typeName == "Object" || - typeName == "num" || - typeName == "int" || - typeName == "double" || - typeName == "bool" || - typeName == "dynamic"; - - /// Walks all the imports and creates a map from prefixes to - /// all the symbols available through those prefixes - Future> _extractNgMetaMap(NgMeta ngMeta) async { - final res = {"": new NgMeta.empty()}; - res[""].addAll(ngMeta); - - if (ngMeta.ngDeps == null || ngMeta.ngDeps.imports == null) return res; - - for (var import in ngMeta.ngDeps.imports) { - if (isDartCoreUri(import.uri)) continue; - - final assetUri = toAssetUri(entryPoint); - final metaAsset = - fromUri(_urlResolver.resolve(assetUri, toMetaExtension(import.uri))); - final newMeta = await _readNgMeta(reader, metaAsset, ngMetas); - - if (!res.containsKey(import.prefix)) { - res[import.prefix] = new NgMeta.empty(); - } - - if (newMeta != null) { - res[import.prefix].addAll(newMeta); - } else { - final summaryAsset = - fromUri(_urlResolver.resolve(assetUri, toSummaryExtension(import.uri))); - final summary = await _readNgMeta(reader, summaryAsset, {}); - if (summary != null) { - res[import.prefix].addAll(summary); - } - } - } - return res; - } -} diff --git a/modules_dart/transform/lib/src/transform/directive_metadata_linker/transformer.dart b/modules_dart/transform/lib/src/transform/directive_metadata_linker/transformer.dart deleted file mode 100644 index a5d0e8fb5d..0000000000 --- a/modules_dart/transform/lib/src/transform/directive_metadata_linker/transformer.dart +++ /dev/null @@ -1,78 +0,0 @@ -library angular2.transform.directive_metadata_linker.transformer; - -import 'dart:async'; -import 'dart:convert'; - -import 'package:barback/barback.dart'; - -import 'package:angular2/src/transform/common/asset_reader.dart'; -import 'package:angular2/src/transform/common/names.dart'; -import 'package:angular2/src/transform/common/zone.dart' as zone; -import 'package:angular2/src/transform/common/options.dart'; -import 'package:angular2/src/transform/common/logging.dart'; - -import 'ng_meta_linker.dart'; - -/// Transformer responsible for processing .ng_summary.json files created by -/// {@link DirectiveProcessor} and "linking" them. -/// -/// This step ensures that for libraries that export, all `Directive`s reachable -/// from that library are declared in its associated .ng_meta.json file. -/// -/// Said another way, after this step there should be an entry in this `NgMeta` -/// object for all `Directives` visible from its associated `.dart` file. -/// -/// This step also ensures that, if `a.dart` imports `b.dart`, `a.ngfactory.dart` -/// imports `b.ngfactory.dart` (if it exists) and we note that this is a -/// ngDeps dependency, ensuring that a's `initReflector` function calls b's -/// `initReflector' function. -/// -/// See `common/ng_meta.dart` for the JSON format of these files are serialized -/// to. -/// -/// This transformer is part of a multi-phase transform. -/// See `angular2/src/transform/transformer.dart` for transformer ordering. -class DirectiveMetadataLinker extends Transformer implements LazyTransformer { - final _encoder = const JsonEncoder.withIndent(' '); - - final TransformerOptions options; - final Map ngMetasCache = {}; - final Set errorMessages = new Set(); - - DirectiveMetadataLinker(this.options); - - @override - bool isPrimary(AssetId id) => id.path.endsWith(SUMMARY_META_EXTENSION); - - @override - declareOutputs(DeclaringTransform transform) { - transform.declareOutput(_ngLinkedAssetId(transform.primaryId)); - } - - @override - Future apply(Transform transform) { - return zone.exec(() { - var primaryId = transform.primaryInput.id; - - return linkDirectiveMetadata( - new AssetReader.fromTransform(transform), - primaryId, - _ngLinkedAssetId(primaryId), - options.resolvedIdentifiers, - options.errorOnMissingIdentifiers, - ngMetasCache).then((ngMeta) { - if (ngMeta != null) { - final outputId = _ngLinkedAssetId(primaryId); - // Not outputting an asset could confuse barback. - var output = ngMeta.isEmpty ? '' : _encoder.convert(ngMeta.toJson()); - transform.addOutput(new Asset.fromString(outputId, output)); - } - }); - }, log: new DeduppingLogger(transform.logger, errorMessages)); - } -} - -AssetId _ngLinkedAssetId(AssetId primaryInputId) { - return new AssetId( - primaryInputId.package, toMetaExtension(primaryInputId.path)); -} diff --git a/modules_dart/transform/lib/src/transform/directive_processor/inliner.dart b/modules_dart/transform/lib/src/transform/directive_processor/inliner.dart deleted file mode 100644 index 4e08ab354d..0000000000 --- a/modules_dart/transform/lib/src/transform/directive_processor/inliner.dart +++ /dev/null @@ -1,109 +0,0 @@ -library angular2.transform.directive_processor.inliner; - -import 'dart:async'; - -import 'package:analyzer/analyzer.dart'; -import 'package:analyzer/src/generated/ast.dart'; -import 'package:barback/barback.dart' show AssetId; -import 'package:source_span/source_span.dart'; -import 'package:path/path.dart' as path; - -import 'package:angular2/src/transform/common/asset_reader.dart'; -import 'package:angular2/src/transform/common/async_string_writer.dart'; -import 'package:angular2/src/transform/common/logging.dart'; -import 'package:angular2/src/transform/common/url_resolver.dart'; - -/// Reads the code at `assetId`, inlining any `part` directives in that code. -/// -/// Returns `null` if the code represented by `assetId` is a `part`. -/// -/// Order of `part`s is preserved. That is, if in the main library we have -/// ``` -/// library main; -/// -/// part 'lib1.dart' -/// part 'lib2.dart' -/// ``` -/// The output will first have the contents of lib1 followed by the contents of -/// lib2.dart, followed by the original code in the library. -Future inlineParts(AssetReader reader, AssetId assetId) async { - var code = await reader.readAsString(assetId); - - var directivesVisitor = new _NgDepsDirectivesVisitor(); - parseDirectives(code, name: assetId.path) - .directives - .accept(directivesVisitor); - - // If this is part of another library, its contents will be processed by its - // parent, so it does not need its own generated file. - if (directivesVisitor.isPart) return null; - - return logElapsedAsync(() { - return _getAllDeclarations(reader, assetId, code, directivesVisitor); - }, operationName: 'inlineParts', assetId: assetId); -} - -/// Processes `visitor.parts`, reading and appending their contents to the -/// original `code`. -Future _getAllDeclarations(AssetReader reader, AssetId assetId, - String code, _NgDepsDirectivesVisitor visitor) { - if (visitor.parts.isEmpty) return new Future.value(code); - - var partsStart = visitor.parts.first.offset, - partsEnd = visitor.parts.last.end; - final assetUri = toAssetUri(assetId); - - var asyncWriter = new AsyncStringWriter(code.substring(0, partsStart)); - visitor.parts.forEach((partDirective) { - var uri = stringLiteralToString(partDirective.uri); - var partAssetId = - fromUri(createOfflineCompileUrlResolver().resolve(assetUri, uri)); - asyncWriter.asyncPrint(reader.readAsString(partAssetId).then((partCode) { - if (partCode == null || partCode.isEmpty) { - log.warning('Empty part at "${partDirective.uri}. Ignoring.', - asset: partAssetId); - return ''; - } - // Remove any directives -- we just want declarations. - var parsedDirectives = parseDirectives(partCode, name: uri).directives; - return partCode.substring(parsedDirectives.last.end); - }).catchError((err, stackTrace) { - log.warning( - 'Failed while reading part at ${partDirective.uri}. Ignoring.\n' - 'Error: $err\n' - 'Stack Trace: $stackTrace', - asset: partAssetId, - span: new SourceFile(code, url: path.basename(assetId.path)) - .span(partDirective.offset, partDirective.end)); - })); - }); - asyncWriter.print(code.substring(partsEnd)); - - return asyncWriter.asyncToString(); -} - -/// Visitor responsible for reading the `part` files of the visited AST and -/// determining if it is a part of another library. -class _NgDepsDirectivesVisitor extends Object with SimpleAstVisitor { - /// Whether the file we are processing is a part, that is, whether we have - /// visited a `part of` directive. - bool _isPart = false; - - final List _parts = []; - bool get isPart => _isPart; - - /// In the order encountered in the source. - Iterable get parts => _parts; - - @override - Object visitPartDirective(PartDirective node) { - _parts.add(node); - return null; - } - - @override - Object visitPartOfDirective(PartOfDirective node) { - _isPart = true; - return null; - } -} diff --git a/modules_dart/transform/lib/src/transform/directive_processor/rewriter.dart b/modules_dart/transform/lib/src/transform/directive_processor/rewriter.dart deleted file mode 100644 index bdc3240d5e..0000000000 --- a/modules_dart/transform/lib/src/transform/directive_processor/rewriter.dart +++ /dev/null @@ -1,170 +0,0 @@ -library angular2.transform.directive_processor.rewriter; - -import 'dart:async'; - -import 'package:analyzer/analyzer.dart'; -import 'package:barback/barback.dart' show AssetId; - -import 'package:angular2/src/compiler/compile_metadata.dart' - show CompileIdentifierMetadata, CompileProviderMetadata; -import 'package:angular2/src/compiler/offline_compiler.dart'; -import 'package:angular2/src/transform/common/annotation_matcher.dart'; -import 'package:angular2/src/transform/common/asset_reader.dart'; -import 'package:angular2/src/transform/common/code/ng_deps_code.dart'; -import 'package:angular2/src/transform/common/type_metadata_reader.dart'; -import 'package:angular2/src/transform/common/interface_matcher.dart'; -import 'package:angular2/src/transform/common/logging.dart'; -import 'package:angular2/src/transform/common/ng_compiler.dart'; -import 'package:angular2/src/transform/common/ng_meta.dart'; -import 'package:angular2/src/transform/common/url_resolver.dart'; -import 'package:angular2/src/transform/common/zone.dart' as zone; - -import 'inliner.dart'; - -/// Generates an instance of [NgMeta] describing the file at `assetId`. -Future createNgMeta(AssetReader reader, AssetId assetId, - AnnotationMatcher annotationMatcher) async { - // TODO(kegluneq): Shortcut if we can determine that there are no - // [Directive]s present, taking into account `export`s. - var codeWithParts = await inlineParts(reader, assetId); - if (codeWithParts == null || codeWithParts.isEmpty) return null; - var parsedCode = - parseCompilationUnit(codeWithParts, name: '${assetId.path} and parts'); - - final ngDepsVisitor = await logElapsedAsync(() async { - var ngDepsVisitor = new NgDepsVisitor(assetId, annotationMatcher); - parsedCode.accept(ngDepsVisitor); - return ngDepsVisitor; - }, operationName: 'createNgDeps', assetId: assetId); - - return logElapsedAsync(() async { - var ngMeta = new NgMeta(ngDeps: ngDepsVisitor.model); - - var templateCompiler = zone.templateCompiler; - if (templateCompiler == null) { - templateCompiler = createTemplateCompiler(reader); - } - var ngMetaVisitor = new _NgMetaVisitor(ngMeta, assetId, annotationMatcher, - _interfaceMatcher, templateCompiler); - parsedCode.accept(ngMetaVisitor); - await ngMetaVisitor.whenDone(); - return ngMeta; - }, operationName: 'createNgMeta', assetId: assetId); -} - -// TODO(kegluneq): Allow the caller to provide an InterfaceMatcher. -final _interfaceMatcher = new InterfaceMatcher(); - -/// Visitor responsible for visiting a file and outputting the -/// code necessary to register the file with the Angular 2 system. -class _NgMetaVisitor extends Object with SimpleAstVisitor { - /// Output ngMeta information about aliases. - // TODO(sigmund): add more to ngMeta. Currently this only contains aliasing - // information, but we could produce here all the metadata we need and avoid - // parsing the ngdeps files later. - final NgMeta ngMeta; - - /// The [AssetId] we are currently processing. - final AssetId assetId; - - final TypeMetadataReader _reader; - final _normalizations = []; - - _NgMetaVisitor(this.ngMeta, this.assetId, AnnotationMatcher annotationMatcher, - InterfaceMatcher interfaceMatcher, OfflineCompiler templateCompiler) - : _reader = new TypeMetadataReader( - annotationMatcher, interfaceMatcher, templateCompiler); - - Future whenDone() { - return Future.wait(_normalizations); - } - - @override - Object visitCompilationUnit(CompilationUnit node) { - if (node == null || - (node.directives == null && node.declarations == null)) { - return null; - } - node.directives.accept(this); - return node.declarations.accept(this); - } - - @override - Object visitClassDeclaration(ClassDeclaration node) { - _normalizations.add(_reader - .readTypeMetadata(node, assetId) - .then((compileMetadataWithIdentifier) { - if (compileMetadataWithIdentifier != null) { - ngMeta.identifiers[compileMetadataWithIdentifier.identifier.name] = - compileMetadataWithIdentifier; - } else { - ngMeta.identifiers[node.name.name] = new CompileIdentifierMetadata( - name: node.name.name, moduleUrl: toAssetUri(assetId)); - } - }).catchError((err) { - log.error('ERROR: $err', asset: assetId); - })); - - return null; - } - - @override - Object visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) { - // We process any top-level declaration that fits the directive-alias - // declaration pattern. Ideally we would use an annotation on the field to - // help us filter out only what's needed, but unfortunately TypeScript - // doesn't support decorators on variable declarations (see - // angular/angular#1747 and angular/ts2dart#249 for context). - outer: for (var variable in node.variables.variables) { - if (variable.isConst) { - final id = _reader.readIdentifierMetadata(variable, assetId); - ngMeta.identifiers[variable.name.name] = id; - } - - var initializer = variable.initializer; - if (initializer != null && initializer is ListLiteral) { - var otherNames = []; - for (var exp in initializer.elements) { - // Only simple identifiers are supported for now. - // TODO(sigmund): add support for prefixes (see issue #3232). - if (exp is! SimpleIdentifier) continue outer; - otherNames.add(exp.name); - } - ngMeta.aliases[variable.name.name] = otherNames; - } - } - return null; - } - - @override - Object visitFunctionTypeAlias(FunctionTypeAlias node) { - ngMeta.identifiers[node.name.name] = new CompileIdentifierMetadata( - name: node.name.name, moduleUrl: toAssetUri(assetId)); - return null; - } - - @override - Object visitFunctionDeclaration(FunctionDeclaration node) { - _normalizations.add(_reader - .readFactoryMetadata(node, assetId) - .then((compileMetadataWithIdentifier) { - if (compileMetadataWithIdentifier != null) { - ngMeta.identifiers[compileMetadataWithIdentifier.identifier.name] = - compileMetadataWithIdentifier; - } else { - ngMeta.identifiers[node.name.name] = new CompileIdentifierMetadata( - name: node.name.name, moduleUrl: toAssetUri(assetId)); - } - }).catchError((err) { - log.error('ERROR: $err', asset: assetId); - })); - return null; - } - - @override - Object visitEnumDeclaration(EnumDeclaration node) { - ngMeta.identifiers[node.name.name] = new CompileIdentifierMetadata( - name: node.name.name, moduleUrl: toAssetUri(assetId)); - return null; - } -} diff --git a/modules_dart/transform/lib/src/transform/directive_processor/transformer.dart b/modules_dart/transform/lib/src/transform/directive_processor/transformer.dart deleted file mode 100644 index 89f8451c1b..0000000000 --- a/modules_dart/transform/lib/src/transform/directive_processor/transformer.dart +++ /dev/null @@ -1,76 +0,0 @@ -library angular2.transform.directive_processor.transformer; - -import 'dart:async'; -import 'dart:convert'; - -import 'package:barback/barback.dart'; - -import 'package:angular2/src/platform/server/html_adapter.dart'; -import 'package:angular2/src/transform/common/asset_reader.dart'; -import 'package:angular2/src/transform/common/names.dart'; -import 'package:angular2/src/transform/common/options.dart'; -import 'package:angular2/src/transform/common/zone.dart' as zone; - -import 'rewriter.dart'; - -/// Transformer responsible for processing all .dart assets and creating -/// .ng_summary.json files which summarize those assets. -/// -/// See `angular2/src/transform/common/ng_meta.dart` for the structure of these -/// output files. -/// -/// This transformer is part of a multi-phase transform. -/// See `angular2/src/transform/transformer.dart` for transformer ordering. -class DirectiveProcessor extends Transformer implements LazyTransformer { - final TransformerOptions options; - final _encoder = const JsonEncoder.withIndent(' '); - - DirectiveProcessor(this.options); - - @override - bool isPrimary(AssetId id) => - id.extension.endsWith('dart') && !isGenerated(id.path); - - @override - declareOutputs(DeclaringTransform transform) { - transform.declareOutput(_deferredAssetId(transform.primaryId)); - transform.declareOutput(_ngSummaryAssetId(transform.primaryId)); - } - - @override - Future apply(Transform transform) async { - Html5LibDomAdapter.makeCurrent(); - return zone.exec(() async { - var primaryId = transform.primaryInput.id; - var reader = new AssetReader.fromTransform(transform); - var ngMeta = - await createNgMeta(reader, primaryId, options.annotationMatcher); - if (ngMeta == null || ngMeta.isEmpty) { - return; - } - transform.addOutput(new Asset.fromString( - _ngSummaryAssetId(primaryId), _encoder.convert(ngMeta.toJson()))); - - var deferredCount = 0; - if (ngMeta.ngDeps != null) { - deferredCount = ngMeta.ngDeps.imports.where((i) => i.isDeferred).length; - } - if (deferredCount > 0) { - // The existence of this file with the value != "0" signals - // DeferredRewriter that the associated .dart file needs attention. - transform.addOutput(new Asset.fromString( - _deferredAssetId(primaryId), deferredCount.toString())); - } - }, log: transform.logger); - } -} - -AssetId _ngSummaryAssetId(AssetId primaryInputId) { - return new AssetId( - primaryInputId.package, toSummaryExtension(primaryInputId.path)); -} - -AssetId _deferredAssetId(AssetId primaryInputId) { - return new AssetId( - primaryInputId.package, toDeferredExtension(primaryInputId.path)); -} diff --git a/modules_dart/transform/lib/src/transform/inliner_for_test/transformer.dart b/modules_dart/transform/lib/src/transform/inliner_for_test/transformer.dart deleted file mode 100644 index d9147c6b3a..0000000000 --- a/modules_dart/transform/lib/src/transform/inliner_for_test/transformer.dart +++ /dev/null @@ -1,241 +0,0 @@ -library angular2.src.transform.inliner_for_test.transformer; - -import 'dart:async'; -import 'dart:convert' show LineSplitter; - -import 'package:analyzer/analyzer.dart'; -import 'package:analyzer/src/generated/ast.dart'; -import 'package:barback/barback.dart'; -import 'package:dart_style/dart_style.dart'; - -import 'package:angular2/src/compiler/xhr.dart' show XHR; -import 'package:angular2/src/transform/common/annotation_matcher.dart'; -import 'package:angular2/src/transform/common/asset_reader.dart'; -import 'package:angular2/src/transform/common/naive_eval.dart'; -import 'package:angular2/src/transform/common/async_string_writer.dart'; -import 'package:angular2/src/transform/common/options.dart'; -import 'package:angular2/src/transform/common/url_resolver.dart'; -import 'package:angular2/src/transform/common/xhr_impl.dart'; -import 'package:angular2/src/transform/common/zone.dart' as zone; -import 'package:angular2/src/transform/directive_processor/inliner.dart'; - -/// Processes .dart files and inlines `templateUrl` and styleUrls` values. -class InlinerForTest extends Transformer { - final DartFormatter _formatter; - final AnnotationMatcher _annotationMatcher; - - InlinerForTest(TransformerOptions options) - : _formatter = options.formatCode ? new DartFormatter() : null, - _annotationMatcher = options.annotationMatcher; - - @override - bool isPrimary(AssetId id) => id.extension.endsWith('dart'); - - @override - Future apply(Transform transform) async { - return zone.exec(() async { - var primaryId = transform.primaryInput.id; - var inlinedCode = await inline(new AssetReader.fromTransform(transform), - primaryId, _annotationMatcher); - if (inlinedCode == null || inlinedCode.isEmpty) { - transform.addOutput(transform.primaryInput); - } else { - if (_formatter != null) { - inlinedCode = _formatter.format(inlinedCode); - } - transform.addOutput(new Asset.fromString(primaryId, inlinedCode)); - } - }, log: transform.logger); - } -} - -/// Reads the code at `assetId`, inlining values where possible. -/// -/// Returns the code at `assetId` with the following modifications: -/// - `part` Directives are inlined -/// - `templateUrl` values are inlined as `template` values. -/// - `styleUrls` values are inlined as `styles` values. -/// -/// If this does not inline any `templateUrl` or `styleUrls` values, it will -/// return `null` to signal that no modifications to the input code were -/// necessary. -Future inline(AssetReader reader, AssetId assetId, - AnnotationMatcher annotationMatcher) async { - var codeWithParts = await inlineParts(reader, assetId); - if (codeWithParts == null) return null; - var parsedCode = - parseCompilationUnit(codeWithParts, name: '${assetId.path} and parts'); - var writer = new AsyncStringWriter(); - var visitor = new _ViewPropInliner( - assetId, codeWithParts, writer, new XhrImpl(reader), annotationMatcher); - parsedCode.accept(visitor); - return visitor.modifiedSource ? writer.asyncToString() : null; -} - -final _urlResolver = createOfflineCompileUrlResolver(); - -class _ViewPropInliner extends RecursiveAstVisitor { - /// The prefixes given to inlined names. - static const _inlinedTemplateBase = '_template'; - static const _inlinedStyleBase = '_style'; - - final AssetId _assetId; - - /// The code we are operating on. - final String _code; - - /// The asset uri for the code we are operating on. - final Uri _baseUri; - final AsyncStringWriter _writer; - final XHR _xhr; - final AnnotationMatcher _annotationMatcher; - - /// Variable name, string to be inlined pairs. - final _inlinedValues = <_InlinedValue>[]; - - /// The final index of the last substring we wrote. - int _lastIndex = 0; - - /// Whether we are currently inlining. - bool _isInlining = false; - - /// Whether this visitor actually inlined any properties. - bool get modifiedSource => _lastIndex > 0; - - _ViewPropInliner(AssetId assetId, this._code, AsyncStringWriter writer, - this._xhr, this._annotationMatcher) - : _assetId = assetId, - _baseUri = Uri.parse(toAssetUri(assetId)), - _writer = writer, - super(); - - @override - Object visitCompilationUnit(CompilationUnit node) { - final retVal = super.visitCompilationUnit(node); - if (modifiedSource) { - _writer.print(_code.substring(_lastIndex)); - _inlinedValues.forEach((v) => _writer.asyncPrint(v.asyncToString())); - } - return retVal; - } - - @override - Object visitAnnotation(Annotation node) { - var wasInlining = _isInlining; - _isInlining = _annotationMatcher.isView(node, _assetId) || - _annotationMatcher.isComponent(node, _assetId); - final retVal = super.visitAnnotation(node); - _isInlining = wasInlining; - return retVal; - } - - @override - Object visitNamedExpression(NamedExpression node) { - if (_isInlining) { - if (node.name is! Label || node.name.label is! SimpleIdentifier) { - throw new FormatException( - 'Angular 2 currently only supports simple identifiers in directives.', - '$node' /* source */); - } - var keyString = '${node.name.label}'; - switch (keyString) { - case 'templateUrl': - _populateTemplateUrl(node); - // Remove `templateUrl` - return null; - case 'styleUrls': - _populateStyleUrls(node); - // Remove `styleUrls` - return null; - } - } - return super.visitNamedExpression(node); - } - - /// Counts the newline characters in the code represented by `node`. - int _countNewlines(AstNode node) { - if (node.offset == null || - node.offset < 0 || - node.end == null || - node.end < 0) { - return 0; - } - return LineSplitter.split(_code.substring(node.offset, node.end)).length - - 1; - } - - void _populateStyleUrls(NamedExpression node) { - var urls = naiveEval(node.expression); - if (urls is! List) { - zone.log - .warning('styleUrls is not a List of Strings (${node.expression})'); - return; - } - _writer.print(_code.substring(_lastIndex, node.offset)); - _lastIndex = node.end; - _writer.print('styles: const ['); - for (var url in urls) { - if (url is String) { - final inlinedVal = _addInlineValue(url, varBase: _inlinedStyleBase); - _writer.print('${inlinedVal.name},'); - } else { - zone.log.warning('style url is not a String (${url})', asset: _assetId); - } - } - _writer.print(']'); - for (var i = 0, n = _countNewlines(node); i < n; ++i) { - _writer.println(''); - } - } - - void _populateTemplateUrl(NamedExpression node) { - var url = naiveEval(node.expression); - if (url is! String) { - zone.log.warning('template url is not a String (${node.expression})', - asset: _assetId); - return; - } - _writer.print(_code.substring(_lastIndex, node.offset)); - _lastIndex = node.end; - final inlinedVal = _addInlineValue(url, varBase: _inlinedTemplateBase); - _writer.print('template: ${inlinedVal.name}'); - for (var i = 0, n = _countNewlines(node); i < n; ++i) { - _writer.println(''); - } - } - - /// Attempts to read the content from [url]. If [url] is relative, uses - /// [_baseUri] as resolution base. - Future _readOrEmptyString(String url) async { - final resolvedUri = _urlResolver.resolve(_baseUri.toString(), url); - - return _xhr.get(resolvedUri).catchError((_) { - zone.log.error('$_baseUri: could not read $url', asset: _assetId); - return ''; - }); - } - - /// Adds a url to be inlined and requests its content. - /// - /// `varBase` is the base of the variable name the inlined value will be - /// assigned to. - /// Returns the created [_InlinedValue] object. - _InlinedValue _addInlineValue(String url, {String varBase}) { - final val = new _InlinedValue( - '${varBase}${_inlinedValues.length}', _readOrEmptyString(url)); - _inlinedValues.add(val); - return val; - } -} - -class _InlinedValue { - final String name; - final Future futureValue; - - _InlinedValue(this.name, this.futureValue); - - /// Returns a const declaration of the inlined value. - Future asyncToString() async { - return "const $name = r'''${await futureValue}''';"; - } -} diff --git a/modules_dart/transform/lib/src/transform/reflection_remover/codegen.dart b/modules_dart/transform/lib/src/transform/reflection_remover/codegen.dart deleted file mode 100644 index 74da666598..0000000000 --- a/modules_dart/transform/lib/src/transform/reflection_remover/codegen.dart +++ /dev/null @@ -1,35 +0,0 @@ -library angular2.transform.reflection_remover.codegen; - -import 'package:angular2/src/transform/common/names.dart'; -import 'package:barback/barback.dart'; -import 'package:path/path.dart' as path; - -class Codegen { - static const _PREFIX_BASE = 'ngStaticInit'; - final AssetId reflectionEntryPoint; - - /// The prefix used to import our generated file. - final String prefix; - - Codegen(this.reflectionEntryPoint, {String prefix}) - : this.prefix = prefix == null ? _PREFIX_BASE : prefix { - if (this.prefix.isEmpty) throw new ArgumentError.value('(empty)', 'prefix'); - } - - /// Generates code to import the library containing the method which sets up - /// Angular2 reflection statically. - /// - /// The code generated here should follow the example of code generated for - /// an {@link ImportDirective} node. - String codegenImport() { - var importUri = path.basename( - reflectionEntryPoint.changeExtension(TEMPLATE_EXTENSION).path); - return '''import '$importUri' as $prefix;'''; - } - - /// Generates code to call the method which sets up Angular2 reflection - /// statically. - String codegenSetupReflectionCall() { - return '$prefix.$SETUP_METHOD_NAME();'; - } -} diff --git a/modules_dart/transform/lib/src/transform/reflection_remover/entrypoint_matcher.dart b/modules_dart/transform/lib/src/transform/reflection_remover/entrypoint_matcher.dart deleted file mode 100644 index 6b9fdf07a1..0000000000 --- a/modules_dart/transform/lib/src/transform/reflection_remover/entrypoint_matcher.dart +++ /dev/null @@ -1,59 +0,0 @@ -library angular2.transform.reflection_remover.entrypoint_matcher; - -import 'package:analyzer/analyzer.dart'; -import 'package:barback/barback.dart'; - -import 'package:angular2/src/transform/common/annotation_matcher.dart'; -import 'package:angular2/src/transform/common/naive_eval.dart'; - -/// Determines if a [FunctionDeclaration] or [MethodDeclaration] is an -/// `AngularEntrypoint`. -class EntrypointMatcher { - final AssetId _assetId; - final AnnotationMatcher _annotationMatcher; - - EntrypointMatcher(this._assetId, this._annotationMatcher) { - if (_assetId == null) { - throw new ArgumentError.notNull('AssetId'); - } - if (_annotationMatcher == null) { - throw new ArgumentError.notNull('AnnotationMatcher'); - } - } - - bool isEntrypoint(AnnotatedNode node) { - if (node == null || - (node is! FunctionDeclaration && node is! MethodDeclaration)) { - return false; - } - return node.metadata - .any((a) => _annotationMatcher.isEntrypoint(a, _assetId)); - } - - /// Gets the name assigned to the `AngularEntrypoint`. - /// - /// This method assumes the name is the first argument to `AngularEntrypoint`; - String getName(AnnotatedNode node) { - final annotation = node.metadata.firstWhere( - (a) => _annotationMatcher.isEntrypoint(a, _assetId), - orElse: () => null); - if (annotation == null) return null; - if (annotation.arguments == null || - annotation.arguments.arguments == null || - annotation.arguments.arguments.isEmpty) { - return _defaultEntrypointName; - } - final entryPointName = naiveEval(annotation.arguments.arguments.first); - if (entryPointName == NOT_A_CONSTANT) { - throw new ArgumentError( - 'Could not evaluate "${node}" as parameter to @AngularEntrypoint'); - } - if (entryPointName is! String) { - throw new ArgumentError('Unexpected type "${entryPointName.runtimeType}" ' - 'as first parameter to @AngularEntrypoint'); - } - return entryPointName; - } -} - -const _defaultEntrypointName = "(no name provided)"; diff --git a/modules_dart/transform/lib/src/transform/reflection_remover/remove_reflection_capabilities.dart b/modules_dart/transform/lib/src/transform/reflection_remover/remove_reflection_capabilities.dart deleted file mode 100644 index bf32c20b31..0000000000 --- a/modules_dart/transform/lib/src/transform/reflection_remover/remove_reflection_capabilities.dart +++ /dev/null @@ -1,32 +0,0 @@ -library angular2.transform.reflection_remover.remove_reflection_capabilities; - -import 'dart:async'; -import 'package:analyzer/analyzer.dart'; -import 'package:barback/barback.dart'; - -import 'package:angular2/src/transform/common/annotation_matcher.dart'; -import 'package:angular2/src/transform/common/asset_reader.dart'; -import 'package:angular2/src/transform/common/mirror_mode.dart'; - -import 'codegen.dart'; -import 'entrypoint_matcher.dart'; -import 'rewriter.dart'; - -/// Finds the call to the Angular2 `ReflectionCapabilities` constructor -/// in `reflectionEntryPoint` and replaces it with a call to -/// `setupReflection` in `newEntryPoint`. -/// -/// This only searches the code in `reflectionEntryPoint`, not `part`s, -/// `import`s, `export`s, etc. -Future removeReflectionCapabilities(AssetReader reader, - AssetId reflectionEntryPoint, AnnotationMatcher annotationMatcher, - {MirrorMode mirrorMode: MirrorMode.none, - bool writeStaticInit: true}) async { - var code = await reader.readAsString(reflectionEntryPoint); - - var codegen = new Codegen(reflectionEntryPoint); - return new Rewriter(code, codegen, - new EntrypointMatcher(reflectionEntryPoint, annotationMatcher), - mirrorMode: mirrorMode, writeStaticInit: writeStaticInit) - .rewrite(parseCompilationUnit(code, name: reflectionEntryPoint.path)); -} diff --git a/modules_dart/transform/lib/src/transform/reflection_remover/rewriter.dart b/modules_dart/transform/lib/src/transform/reflection_remover/rewriter.dart deleted file mode 100644 index e22b14533b..0000000000 --- a/modules_dart/transform/lib/src/transform/reflection_remover/rewriter.dart +++ /dev/null @@ -1,331 +0,0 @@ -library angular2.transform.reflection_remover.rewriter; - -import 'package:analyzer/src/generated/ast.dart'; -import 'package:path/path.dart' as path; - -import 'package:angular2/src/transform/common/logging.dart'; -import 'package:angular2/src/transform/common/mirror_matcher.dart'; -import 'package:angular2/src/transform/common/mirror_mode.dart'; -import 'package:angular2/src/transform/common/names.dart'; - -import 'codegen.dart'; -import 'entrypoint_matcher.dart'; - -class Rewriter { - final String _code; - final Codegen _codegen; - final EntrypointMatcher _entrypointMatcher; - final MirrorMatcher _mirrorMatcher; - final MirrorMode _mirrorMode; - final bool _writeStaticInit; - - Rewriter(this._code, this._codegen, this._entrypointMatcher, - {MirrorMatcher mirrorMatcher, - MirrorMode mirrorMode: MirrorMode.none, - bool writeStaticInit: true}) - : _mirrorMode = mirrorMode, - _writeStaticInit = writeStaticInit, - _mirrorMatcher = - mirrorMatcher == null ? const MirrorMatcher() : mirrorMatcher { - if (_codegen == null) { - throw new ArgumentError.notNull('Codegen'); - } - if (_entrypointMatcher == null) { - throw new ArgumentError.notNull('EntrypointMatcher'); - } - } - - /// Rewrites the provided code to remove dart:mirrors. - /// - /// Specifically, removes imports of the - /// {@link ReflectionCapabilities} library and instantiations of - /// {@link ReflectionCapabilities}, as detected by the (potentially) provided - /// {@link MirrorMatcher}. - /// - /// To the extent possible, this method does not change line numbers or - /// offsets in the provided code to facilitate debugging via source maps. - String rewrite(CompilationUnit node) { - if (node == null) throw new ArgumentError.notNull('node'); - - var visitor = new _RewriterVisitor(this); - - node.accept(visitor); - - return visitor.outputRewrittenCode(); - } -} - -/// Visitor responsible for rewriting the Angular 2 code which instantiates -/// {@link ReflectionCapabilities} and removing its associated import. -/// -/// This breaks our dependency on dart:mirrors, which enables smaller code -/// size and better performance. -class _RewriterVisitor extends Object with RecursiveAstVisitor { - final Rewriter _rewriter; - final buf = new StringBuffer(); - final reflectionCapabilityAssignments = []; - - int _currentIndex = 0; - bool _setupAdded = false; - bool _importAdded = false; - - /// Whether we imported static bootstrap by e.g. rewriting a non-static - /// bootstrap import. - bool _hasStaticBootstrapImport = false; - - _RewriterVisitor(this._rewriter); - - @override - Object visitImportDirective(ImportDirective node) { - buf.write(_rewriter._code.substring(_currentIndex, node.offset)); - _currentIndex = node.offset; - if (_rewriter._mirrorMatcher.hasReflectionCapabilitiesUri(node)) { - _rewriteReflectionCapabilitiesImport(node); - } else if (_rewriter._mirrorMatcher.hasBootstrapUri(node)) { - _rewriteBootstrapImportToStatic(node); - } - if (!_importAdded && _rewriter._writeStaticInit) { - // Add imports for ng_deps (once) - buf.write(_rewriter._codegen.codegenImport()); - _importAdded = true; - } - return null; - } - - @override - Object visitAssignmentExpression(AssignmentExpression node) { - if (node.rightHandSide is InstanceCreationExpression && - _rewriter._mirrorMatcher - .isNewReflectionCapabilities(node.rightHandSide)) { - reflectionCapabilityAssignments.add(node); - _rewriteReflectionCapabilitiesAssignment(node); - } - return super.visitAssignmentExpression(node); - } - - @override - Object visitInstanceCreationExpression(InstanceCreationExpression node) { - if (_rewriter._mirrorMatcher.isNewReflectionCapabilities(node) && - !reflectionCapabilityAssignments.contains(node.parent)) { - log.error('Unexpected format in creation of ' - '${REFLECTION_CAPABILITIES_NAME}'); - } - return super.visitInstanceCreationExpression(node); - } - - @override - Object visitMethodInvocation(MethodInvocation node) { - if (_hasStaticBootstrapImport && - node.methodName.toString() == BOOTSTRAP_NAME) { - _rewriteBootstrapCallToStatic(node); - } - return super.visitMethodInvocation(node); - } - - @override - Object visitMethodDeclaration(MethodDeclaration node) { - if (_rewriter._entrypointMatcher.isEntrypoint(node)) { - if (_rewriter._writeStaticInit) { - _rewriteEntrypointFunctionBody(node.body); - } - } - return super.visitMethodDeclaration(node); - } - - @override - Object visitFunctionDeclaration(FunctionDeclaration node) { - if (_rewriter._entrypointMatcher.isEntrypoint(node)) { - if (_rewriter._writeStaticInit) { - _rewriteEntrypointFunctionBody(node.functionExpression.body); - } - } - return super.visitFunctionDeclaration(node); - } - - void _rewriteEntrypointFunctionBody(FunctionBody node) { - if (node is BlockFunctionBody) { - final insertOffset = node.block.leftBracket.end; - buf.write(_rewriter._code.substring(_currentIndex, insertOffset)); - buf.write(_getStaticReflectorInitBlock()); - _currentIndex = insertOffset; - _setupAdded = true; - } else if (node is ExpressionFunctionBody) { - // TODO(kegluneq): Add support, see issue #5474. - throw new ArgumentError( - 'Arrow syntax is not currently supported as `@AngularEntrypoint`s'); - } else if (node is NativeFunctionBody) { - throw new ArgumentError('Native functions and methods are not supported ' - 'as `@AngularEntrypoint`s'); - } else if (node is EmptyFunctionBody) { - throw new ArgumentError('Empty functions and methods are not supported ' - 'as `@AngularEntrypoint`s'); - } - } - - String outputRewrittenCode() { - if (_currentIndex < _rewriter._code.length) { - buf.write(_rewriter._code.substring(_currentIndex)); - } - return '$buf'; - } - - _rewriteBootstrapImportToStatic(ImportDirective node) { - if (_rewriter._writeStaticInit) { - // rewrite bootstrap import to its static version. - buf.write(_rewriter._code.substring(_currentIndex, node.offset)); - buf.write("import '$BOOTSTRAP_STATIC_URI'"); - - // The index of the last character we've processed. - var lastIdx = node.uri.end; - - // Maintain the import prefix, if present. - if (node.prefix != null) { - buf.write(_rewriter._code.substring(lastIdx, node.prefix.end)); - lastIdx = node.prefix.end; - } - - // Handle combinators ("show" and "hide" on an "import" directive). - // 1. A combinator like "show $BOOTSTRAP_NAME" no longer makes sense, so - // we need to rewrite it. - // 2. It's possible we'll need to call the setup method - // (SETUP_METHOD_NAME), so make sure it is visible. - if (node.combinators != null) { - for (var combinator in node.combinators) { - buf.write(_rewriter._code - .substring(lastIdx, combinator.end) - .replaceAll(BOOTSTRAP_NAME, BOOTSTRAP_STATIC_NAME)); - lastIdx = combinator.end; - if (combinator is ShowCombinator) { - buf.write(', $SETUP_METHOD_NAME'); - } else if (combinator is HideCombinator) { - // Ensure the user is not explicitly hiding SETUP_METHOD_NAME. - // I don't know why anyone would do this, but it would result in - // some confusing behavior, so throw an explicit error. - combinator.hiddenNames.forEach((id) { - if (id.toString() == SETUP_METHOD_NAME) { - throw new FormatException( - 'Import statement explicitly hides initialization function ' - '$SETUP_METHOD_NAME. Please do not do this: "$node"'); - } - }); - } - } - } - - // Write anything after the combinators. - buf.write(_rewriter._code.substring(lastIdx, node.end)); - _hasStaticBootstrapImport = true; - } else { - // leave it as is - buf.write(_rewriter._code.substring(_currentIndex, node.end)); - } - _currentIndex = node.end; - } - - _rewriteBootstrapCallToStatic(MethodInvocation node) { - if (_rewriter._writeStaticInit) { - buf.write(_rewriter._code.substring(_currentIndex, node.offset)); - - var args = node.argumentList.arguments; - int numArgs = node.argumentList.arguments.length; - if (numArgs < 1 || numArgs > 2) { - log.warning('`bootstrap` does not support $numArgs arguments. ' - 'Found bootstrap${node.argumentList}. Transform may not succeed.'); - } - - var reflectorInit = - _setupAdded ? '' : ', () { ${_getStaticReflectorInitBlock()} }'; - - // rewrite `bootstrap(...)` to `bootstrapStatic(...)` - if (node.target != null && node.target is SimpleIdentifier) { - // `bootstrap` imported with a prefix, maintain this. - buf.write('${node.target}.'); - } - buf.write('$BOOTSTRAP_STATIC_NAME(${args[0]}'); - if (numArgs == 1) { - // bootstrap args are positional, so before we pass reflectorInit code - // we need to pass `null` for DI bindings. - if (reflectorInit.isNotEmpty) { - buf.write(', null'); - } - } else { - // pass DI bindings - buf.write(', ${args[1]}'); - } - buf.write(reflectorInit); - buf.write(')'); - _setupAdded = true; - } else { - // leave it as is - buf.write(_rewriter._code.substring(_currentIndex, node.end)); - } - _currentIndex = node.end; - } - - String _getStaticReflectorInitBlock() { - return _rewriter._codegen.codegenSetupReflectionCall(); - } - - _rewriteReflectionCapabilitiesImport(ImportDirective node) { - buf.write(_rewriter._code.substring(_currentIndex, node.offset)); - if ('${node.prefix}' == _rewriter._codegen.prefix) { - log.warning( - 'Found import prefix "${_rewriter._codegen.prefix}" in source file.' - ' Transform may not succeed.'); - } - if (_rewriter._mirrorMode != MirrorMode.none) { - buf.write(_importDebugReflectionCapabilities(node)); - } else { - buf.write(_commentedNode(node)); - } - _currentIndex = node.end; - } - - _rewriteReflectionCapabilitiesAssignment(AssignmentExpression assignNode) { - var node = assignNode; - while (node.parent is ExpressionStatement) { - node = node.parent; - } - buf.write(_rewriter._code.substring(_currentIndex, node.offset)); - if (_rewriter._writeStaticInit && !_setupAdded) { - buf.write(_getStaticReflectorInitBlock()); - _setupAdded = true; - } - switch (_rewriter._mirrorMode) { - case MirrorMode.debug: - buf.write(node); - break; - case MirrorMode.verbose: - buf.write(_instantiateVerboseReflectionCapabilities(assignNode)); - break; - case MirrorMode.none: - default: - buf.write(_commentedNode(node)); - break; - } - _currentIndex = node.end; - } - - String _commentedNode(AstNode node) { - return '/*${_rewriter._code.substring(node.offset, node.end)}*/'; - } -} - -String _importDebugReflectionCapabilities(ImportDirective node) { - var uri = '${node.uri}'; - uri = path - .join(path.dirname(uri), 'debug_${path.basename(uri)}') - .replaceAll('\\', '/'); - var asClause = node.prefix != null ? ' as ${node.prefix}' : ''; - return 'import $uri$asClause;'; -} - -String _instantiateVerboseReflectionCapabilities( - AssignmentExpression assignNode) { - if (assignNode.rightHandSide is! InstanceCreationExpression) { - return '$assignNode;'; - } - var rhs = (assignNode.rightHandSide as InstanceCreationExpression); - return '${assignNode.leftHandSide} ${assignNode.operator} ' - 'new ${rhs.constructorName}(verbose: true);'; -} diff --git a/modules_dart/transform/lib/src/transform/reflection_remover/transformer.dart b/modules_dart/transform/lib/src/transform/reflection_remover/transformer.dart deleted file mode 100644 index f98cd6d779..0000000000 --- a/modules_dart/transform/lib/src/transform/reflection_remover/transformer.dart +++ /dev/null @@ -1,69 +0,0 @@ -library angular2.transform.reflection_remover.transformer; - -import 'dart:async'; - -import 'package:barback/barback.dart'; - -import 'package:angular2/src/transform/common/asset_reader.dart'; -import 'package:angular2/src/transform/common/mirror_mode.dart'; -import 'package:angular2/src/transform/common/names.dart'; -import 'package:angular2/src/transform/common/options.dart'; -import 'package:angular2/src/transform/common/options_reader.dart'; -import 'package:angular2/src/transform/common/zone.dart' as zone; - -import 'remove_reflection_capabilities.dart'; - -/// Transformer responsible for removing the import and instantiation of -/// {@link ReflectionCapabilities}. -/// -/// The goal of this is to break the app's dependency on dart:mirrors. -/// -/// This transformer assumes that {@link DirectiveProcessor} and {@link DirectiveLinker} -/// have already been run and that a .ngfactory.dart file has been generated for -/// {@link options.entryPoint}. The instantiation of {@link ReflectionCapabilities} is -/// replaced by calling `initReflector` in that .ngfactory.dart file. -class ReflectionRemover extends Transformer implements LazyTransformer { - final TransformerOptions options; - - ReflectionRemover(this.options); - - /// Ctor which tells pub that this can be run as a standalone transformer. - factory ReflectionRemover.asPlugin(BarbackSettings settings) => - new ReflectionRemover(parseBarbackSettings(settings)); - - @override - bool isPrimary(AssetId id) => - options.entryPointGlobs != null && - options.entryPointGlobs.any((g) => g.matches(id.path)); - - @override - declareOutputs(DeclaringTransform transform) { - transform.declareOutput(transform.primaryId); - } - - @override - Future apply(Transform transform) async { - return zone.exec(() async { - var primaryId = transform.primaryInput.id; - var mirrorMode = options.mirrorMode; - var writeStaticInit = options.initReflector; - if (options.modeName == TRANSFORM_DYNAMIC_MODE) { - mirrorMode = MirrorMode.debug; - writeStaticInit = false; - zone.log.info( - 'Running in "${options.modeName}", ' - 'mirrorMode: ${mirrorMode}, ' - 'writeStaticInit: ${writeStaticInit}.', - asset: primaryId); - } - - var transformedCode = await removeReflectionCapabilities( - new AssetReader.fromTransform(transform), - primaryId, - options.annotationMatcher, - mirrorMode: mirrorMode, - writeStaticInit: writeStaticInit); - transform.addOutput(new Asset.fromString(primaryId, transformedCode)); - }, log: transform.logger); - } -} diff --git a/modules_dart/transform/lib/src/transform/stylesheet_compiler/processor.dart b/modules_dart/transform/lib/src/transform/stylesheet_compiler/processor.dart deleted file mode 100644 index 40c5a3f8d1..0000000000 --- a/modules_dart/transform/lib/src/transform/stylesheet_compiler/processor.dart +++ /dev/null @@ -1,36 +0,0 @@ -library angular2.transform.stylesheet_compiler.processor; - -import 'dart:async'; - -import 'package:angular2/src/compiler/offline_compiler.dart'; -import 'package:angular2/src/transform/common/asset_reader.dart'; -import 'package:angular2/src/transform/common/code/source_module.dart'; -import 'package:angular2/src/transform/common/logging.dart'; -import 'package:angular2/src/transform/common/names.dart'; -import 'package:angular2/src/transform/common/ng_compiler.dart'; -import 'package:angular2/src/transform/common/zone.dart' as zone; - -import 'package:barback/barback.dart'; - -AssetId shimmedStylesheetAssetId(AssetId cssAssetId) => new AssetId( - cssAssetId.package, toShimmedStylesheetExtension(cssAssetId.path)); - -AssetId nonShimmedStylesheetAssetId(AssetId cssAssetId) => new AssetId( - cssAssetId.package, toNonShimmedStylesheetExtension(cssAssetId.path)); - -Future> processStylesheet( - AssetReader reader, AssetId stylesheetId) async { - final stylesheetUrl = '${stylesheetId.package}|${stylesheetId.path}'; - var templateCompiler = zone.templateCompiler; - if (templateCompiler == null) { - templateCompiler = createTemplateCompiler(reader); - } - final cssText = await reader.readAsString(stylesheetId); - return logElapsedAsync(() async { - final sourceModules = - templateCompiler.compileStylesheet(stylesheetUrl, cssText); - - return sourceModules.map((SourceModule module) => new Asset.fromString( - new AssetId.parse('${module.moduleUrl}'), writeSourceModule(module))); - }, operationName: 'processStylesheet', assetId: stylesheetId); -} diff --git a/modules_dart/transform/lib/src/transform/stylesheet_compiler/transformer.dart b/modules_dart/transform/lib/src/transform/stylesheet_compiler/transformer.dart deleted file mode 100644 index 541f35dc9f..0000000000 --- a/modules_dart/transform/lib/src/transform/stylesheet_compiler/transformer.dart +++ /dev/null @@ -1,50 +0,0 @@ -library angular2.transform.stylesheet_compiler.transformer; - -import 'dart:async'; - -import 'package:barback/barback.dart'; - -import 'package:angular2/src/platform/server/html_adapter.dart'; -import 'package:angular2/src/transform/common/asset_reader.dart'; -import 'package:angular2/src/transform/common/names.dart'; -import 'package:angular2/src/transform/common/zone.dart' as zone; - -import 'processor.dart'; - -/// Pre-compiles CSS stylesheet files to Dart code for Angular 2. -class StylesheetCompiler extends Transformer implements LazyTransformer { - StylesheetCompiler(); - - @override - bool isPrimary(AssetId id) { - return id.path.endsWith(CSS_EXTENSION); - } - - @override - declareOutputs(DeclaringTransform transform) { - // Note: we check this assumption below. - _getExpectedOutputs(transform.primaryId).forEach(transform.declareOutput); - } - - List _getExpectedOutputs(AssetId cssId) => - [shimmedStylesheetAssetId(cssId), nonShimmedStylesheetAssetId(cssId)]; - - @override - Future apply(Transform transform) async { - final reader = new AssetReader.fromTransform(transform); - return zone.exec(() async { - Html5LibDomAdapter.makeCurrent(); - var primaryId = transform.primaryInput.id; - var outputs = await processStylesheet(reader, primaryId); - var expectedIds = _getExpectedOutputs(primaryId); - outputs.forEach((Asset compiledStylesheet) { - var id = compiledStylesheet.id; - if (!expectedIds.contains(id)) { - throw new StateError( - 'Unexpected output for css processing of $primaryId: $id'); - } - transform.addOutput(compiledStylesheet); - }); - }, log: transform.logger); - } -} diff --git a/modules_dart/transform/lib/src/transform/template_compiler/compile_data_creator.dart b/modules_dart/transform/lib/src/transform/template_compiler/compile_data_creator.dart deleted file mode 100644 index 6530b19c86..0000000000 --- a/modules_dart/transform/lib/src/transform/template_compiler/compile_data_creator.dart +++ /dev/null @@ -1,264 +0,0 @@ -library angular2.transform.template_compiler.compile_data_creator; - -import 'dart:async'; -import 'dart:convert'; - -import 'package:angular2/src/compiler/compile_metadata.dart'; -import 'package:angular2/src/compiler/offline_compiler.dart'; -import 'package:angular2/src/transform/common/asset_reader.dart'; -import 'package:angular2/src/transform/common/logging.dart'; -import 'package:angular2/src/transform/common/model/ng_deps_model.pb.dart'; -import 'package:angular2/src/transform/common/model/reflection_info_model.pb.dart'; -import 'package:angular2/src/transform/common/names.dart'; -import 'package:angular2/src/transform/common/ng_meta.dart'; -import 'package:angular2/src/transform/common/url_resolver.dart'; -import 'package:barback/barback.dart'; - -/// Creates [NormalizedComponentWithViewDirectives] objects for all `View` -/// `Directive`s defined in `assetId`. -/// -/// The returned value wraps the [NgDepsModel] at `assetId` as well as these -/// created objects. -/// -/// `platformDirectives` is an optional [List] containing names of [Directive]s -/// which should be available to all [View]s in this app. -/// -/// `platformPipes` is an optional [List] containing names of [Pipe]s which -/// should be available to all [View]s in this app. -Future createCompileData( - AssetReader reader, - AssetId assetId, - List platformDirectives, - List platformPipes) async { - return logElapsedAsync(() async { - final creator = await _CompileDataCreator.create( - reader, assetId, platformDirectives, platformPipes); - return creator != null ? creator.createCompileData() : null; - }, operationName: 'createCompileData', assetId: assetId); -} - -class CompileDataResults { - final NgMeta ngMeta; - final Map - viewDefinitions; - - CompileDataResults._(this.ngMeta, this.viewDefinitions); -} - -/// Creates [ViewDefinition] objects for all `View` `Directive`s defined in -/// `entryPoint`. -class _CompileDataCreator { - final AssetReader reader; - final AssetId entryPoint; - final NgMeta ngMeta; - final List platformDirectives; - final List platformPipes; - - _CompileDataCreator(this.reader, this.entryPoint, this.ngMeta, - this.platformDirectives, this.platformPipes); - - static Future<_CompileDataCreator> create(AssetReader reader, AssetId assetId, - List platformDirectives, List platformPipes) async { - if (!(await reader.hasInput(assetId))) return null; - final json = await reader.readAsString(assetId); - if (json == null || json.isEmpty) return null; - - final ngMeta = new NgMeta.fromJson(JSON.decode(json)); - return new _CompileDataCreator( - reader, assetId, ngMeta, platformDirectives, platformPipes); - } - - NgDepsModel get ngDeps => ngMeta.ngDeps; - - Future createCompileData() async { - var hasTemplate = ngDeps != null && - ngDeps.reflectables != null && - ngDeps.reflectables.any((reflectable) { - if (ngMeta.identifiers.containsKey(reflectable.name)) { - final metadata = ngMeta.identifiers[reflectable.name]; - return metadata is CompileDirectiveMetadata; - } - return false; - }); - - if (!hasTemplate) return new CompileDataResults._(ngMeta, const {}); - - final compileData = - {}; - final platformDirectives = - await _readPlatformTypes(this.platformDirectives, 'directives'); - final platformPipes = await _readPlatformTypes(this.platformPipes, 'pipes'); - final ngMetaMap = await _extractNgMeta(); - - for (var reflectable in ngDeps.reflectables) { - if (ngMeta.identifiers.containsKey(reflectable.name)) { - final compileDirectiveMetadata = ngMeta.identifiers[reflectable.name]; - if (compileDirectiveMetadata is CompileDirectiveMetadata && - compileDirectiveMetadata.template != null) { - final compileDatum = new NormalizedComponentWithViewDirectives( - compileDirectiveMetadata, - [], - []); - compileDatum.directives.addAll(platformDirectives); - compileDatum.directives - .addAll(_resolveTypeMetadata(ngMetaMap, reflectable.directives)); - compileDatum.pipes.addAll(platformPipes); - compileDatum.pipes - .addAll(_resolveTypeMetadata(ngMetaMap, reflectable.pipes)); - compileData[reflectable] = compileDatum; - } - } - } - return new CompileDataResults._(ngMeta, compileData); - } - - List _resolveTypeMetadata( - Map ngMetaMap, List prefixedTypes) { - var resolvedMetadata = []; - for (var dep in prefixedTypes) { - if (!ngMetaMap.containsKey(dep.prefix)) { - log.error( - 'Missing prefix "${dep.prefix}" ' - 'needed by "${dep}" from metadata map,', - asset: entryPoint); - return null; - } - final depNgMeta = ngMetaMap[dep.prefix]; - if (depNgMeta.aliases.containsKey(dep.name)) { - resolvedMetadata.addAll(depNgMeta.flatten(dep.name)); - - } else if (depNgMeta.identifiers.containsKey(dep.name)) { - resolvedMetadata.add(depNgMeta.identifiers[dep.name]); - - } else { - log.error( - 'Could not find Directive/Pipe entry for $dep. ' - 'Please be aware that Dart transformers have limited support for ' - 'reusable, pre-defined lists of Directives/Pipes (aka ' - '"directive/pipe aliases"). See https://goo.gl/d8XPt0 for details.', - asset: entryPoint); - } - } - return resolvedMetadata; - } - - Future> _readPlatformTypes( - List inputPlatformTypes, String configOption) async { - if (inputPlatformTypes == null) return const []; - - final res = []; - for (var pd in inputPlatformTypes) { - final parts = pd.split("#"); - if (parts.length != 2) { - log.warning( - 'The platform ${configOption} configuration option ' - 'must be in the following format: "URI#TOKEN"', - asset: entryPoint); - return const []; - } - res.addAll(await _readPlatformTypesFromUri(parts[0], parts[1])); - } - return res; - } - - Future> _readPlatformTypesFromUri( - String uri, String token) async { - final metaAssetId = fromUri(toMetaExtension(uri)); - try { - var jsonString = await reader.readAsString(metaAssetId); - if (jsonString != null && jsonString.isNotEmpty) { - var newMetadata = new NgMeta.fromJson(JSON.decode(jsonString)); - - if (newMetadata.aliases.containsKey(token)) { - return newMetadata.flatten(token); - - } else if (newMetadata.identifiers.containsKey(token)) { - return [newMetadata.identifiers[token]]; - - } else { - log.warning('Could not resolve platform type ${token} in ${uri}', - asset: metaAssetId); - } - } - } catch (ex, stackTrace) { - log.warning('Failed to decode: $ex, $stackTrace', asset: metaAssetId); - } - return []; - } - - /// Creates a map from import prefix to the asset: uris of all `.dart` - /// libraries visible from `entryPoint`, excluding `dart:` and generated files - /// it imports. Unprefixed imports have the empty string as their key. - /// `entryPoint` is included in the map with no prefix. - Map> _createPrefixToImportsMap() { - final baseUri = toAssetUri(entryPoint); - final map = >{'': new Set()..add(baseUri)}; - if (ngDeps == null || ngDeps.imports == null || ngDeps.imports.isEmpty) { - return map; - } - final resolver = createOfflineCompileUrlResolver(); - ngMeta.ngDeps.imports - .where((model) => !isDartCoreUri(model.uri)) - .forEach((model) { - var prefix = model.prefix == null ? '' : model.prefix; - map - .putIfAbsent(prefix, () => new Set()) - .add(resolver.resolve(baseUri, model.uri)); - }); - return map; - } - - /// Reads the `.ng_meta.json` files associated with all of `entryPoint`'s - /// imports and creates a map of prefix (or blank) to the - /// associated [NgMeta] object. - /// - /// For example, if in `entryPoint` we have: - /// - /// ``` - /// import 'component.dart' as prefix; - /// ``` - /// - /// and in 'component.dart' we have: - /// - /// ``` - /// @Component(...) - /// class MyComponent {...} - /// ``` - /// - /// This method will look for `component.ng_meta.json`to contain the - /// serialized [NgMeta] for `MyComponent` and any other - /// `Directive`s declared in `component.dart`. We use this information to - /// build a map: - /// - /// ``` - /// { - /// "prefix": [NgMeta with CompileDirectiveMetadata for MyComponent], - /// ...... - /// } - /// ``` - Future> _extractNgMeta() async { - var prefixToImports = _createPrefixToImportsMap(); - - final retVal = {}; - for (var prefix in prefixToImports.keys) { - var ngMeta = retVal[prefix] = new NgMeta.empty(); - for (var importAssetUri in prefixToImports[prefix]) { - var metaAssetId = fromUri(toMetaExtension(importAssetUri)); - - if (await reader.hasInput(metaAssetId)) { - try { - var jsonString = await reader.readAsString(metaAssetId); - if (jsonString != null && jsonString.isNotEmpty) { - var newMetadata = new NgMeta.fromJson(JSON.decode(jsonString)); - ngMeta.addAll(newMetadata); - } - } catch (ex, stackTrace) { - log.warning('Failed to decode: $ex, $stackTrace', - asset: metaAssetId); - } - } - } - } - return retVal; - } -} diff --git a/modules_dart/transform/lib/src/transform/template_compiler/generator.dart b/modules_dart/transform/lib/src/transform/template_compiler/generator.dart deleted file mode 100644 index 4d4aefa50d..0000000000 --- a/modules_dart/transform/lib/src/transform/template_compiler/generator.dart +++ /dev/null @@ -1,85 +0,0 @@ -library angular2.transform.template_compiler.generator; - -import 'dart:async'; - -import 'package:barback/barback.dart'; - -import 'package:angular2/src/compiler/offline_compiler.dart'; -import 'package:angular2/src/compiler/config.dart'; -import 'package:angular2/src/facade/lang.dart'; -import 'package:angular2/src/transform/common/asset_reader.dart'; -import 'package:angular2/src/transform/common/logging.dart'; -import 'package:angular2/src/transform/common/model/annotation_model.pb.dart'; -import 'package:angular2/src/transform/common/model/ng_deps_model.pb.dart'; -import 'package:angular2/src/transform/common/names.dart'; -import 'package:angular2/src/transform/common/ng_compiler.dart'; -import 'package:angular2/src/transform/common/zone.dart' as zone; -import 'package:angular2/i18n.dart'; -import 'package:angular2/src/transform/common/options.dart' show CODEGEN_DEBUG_MODE; - -import 'compile_data_creator.dart'; - -/// Generates `.ngfactory.dart` files to initialize the Angular2 system. -/// -/// - Processes the `.ng_meta.json` file represented by `assetId` using -/// `createCompileData`. -/// - Passes the resulting `NormalizedComponentWithViewDirectives` instance(s) -/// to the `TemplateCompiler` to generate compiled template(s) as a -/// `SourceModule`. -/// - Uses the resulting `NgDeps` object to generate code which initializes the -/// Angular2 reflective system. -/// -/// This method assumes a {@link DomAdapter} has been registered. -Future processTemplates(AssetReader reader, AssetId assetId, - {String codegenMode: '', - bool reflectPropertiesAsAttributes: false, - List platformDirectives, - List platformPipes, - XmbDeserializationResult translations, - Map resolvedIdentifiers - }) async { - var viewDefResults = await createCompileData( - reader, assetId, platformDirectives, platformPipes); - if (viewDefResults == null) return null; - var templateCompiler = zone.templateCompiler; - if (templateCompiler == null) { - templateCompiler = createTemplateCompiler(reader, - compilerConfig: new CompilerConfig( - codegenMode == CODEGEN_DEBUG_MODE, reflectPropertiesAsAttributes, false), - translations: translations); - } - - final compileData = - viewDefResults.viewDefinitions.values.toList(growable: false); - if (compileData.isEmpty) { - return new Outputs._(viewDefResults.ngMeta.ngDeps, null); - } - - final compiledTemplates = logElapsedSync(() { - return templateCompiler.compileTemplates(compileData); - }, operationName: 'compileTemplates', assetId: assetId); - - if (compiledTemplates != null) { - // We successfully compiled templates! - // For each compiled template, add the compiled template class as an - // "Annotation" on the code to be registered with the reflector. - for (var reflectable in viewDefResults.viewDefinitions.keys) { - // TODO(kegluneq): Avoid duplicating naming logic for generated classes. - reflectable.annotations.add(new AnnotationModel() - ..name = '${reflectable.name}NgFactory' - ..isConstObject = true); - } - } - - return new Outputs._(viewDefResults.ngMeta.ngDeps, compiledTemplates); -} - -AssetId templatesAssetId(AssetId primaryId) => - new AssetId(primaryId.package, toTemplateExtension(primaryId.path)); - -class Outputs { - final NgDepsModel ngDeps; - final SourceModule templatesSource; - - Outputs._(this.ngDeps, this.templatesSource); -} diff --git a/modules_dart/transform/lib/src/transform/template_compiler/transformer.dart b/modules_dart/transform/lib/src/transform/template_compiler/transformer.dart deleted file mode 100644 index 6539695f23..0000000000 --- a/modules_dart/transform/lib/src/transform/template_compiler/transformer.dart +++ /dev/null @@ -1,89 +0,0 @@ -library angular2.transform.template_compiler.transformer; - -import 'dart:async'; - -import 'package:barback/barback.dart'; - -import 'package:angular2/src/platform/server/html_adapter.dart'; -import 'package:angular2/src/transform/common/asset_reader.dart'; -import 'package:angular2/src/transform/common/code/ng_deps_code.dart'; -import 'package:angular2/src/transform/common/code/source_module.dart'; -import 'package:angular2/src/transform/common/formatter.dart'; -import 'package:angular2/src/transform/common/names.dart'; -import 'package:angular2/src/transform/common/options.dart'; -import 'package:angular2/src/transform/common/logging.dart'; -import 'package:angular2/src/transform/common/zone.dart' as zone; -import 'package:angular2/i18n.dart'; - -import 'generator.dart'; - -/// {@link Transformer} responsible for processing Angular 2 templates. -/// -/// {@link TemplateCompiler} uses the Angular 2 `TemplateCompiler` to process -/// the templates, extracting information about what reflection is necessary to -/// render and use that template. It then generates code in place of those -/// reflective accesses. -/// -/// This transformer is part of a multi-phase transform. -/// See `angular2/src/transform/transformer.dart` for transformer ordering. -class TemplateCompiler extends Transformer implements LazyTransformer { - final TransformerOptions options; - XmbDeserializationResult translations; - - TemplateCompiler(this.options); - - @override - bool isPrimary(AssetId id) => id.path.endsWith(META_EXTENSION); - - @override - declareOutputs(DeclaringTransform transform) { - transform.declareOutput(templatesAssetId(transform.primaryId)); - } - - @override - Future apply(Transform transform) async { - return zone.exec(() async { - Html5LibDomAdapter.makeCurrent(); - var primaryId = transform.primaryInput.id; - var reader = new AssetReader.fromTransform(transform); - if (translations == null && options.translations != null) { - translations = await _deserializeXmb(reader, options.translations); - } - - var outputs = await processTemplates(reader, primaryId, - codegenMode: options.codegenMode, - reflectPropertiesAsAttributes: options.reflectPropertiesAsAttributes, - platformDirectives: options.platformDirectives, - platformPipes: options.platformPipes, - resolvedIdentifiers: options.resolvedIdentifiers, - translations: translations - ); - var ngDepsCode = _emptyNgDepsContents; - if (outputs != null) { - if (outputs.ngDeps != null) { - final buf = new StringBuffer(); - final templatesSrc = - options.genCompiledTemplates ? outputs.templatesSource : null; - writeTemplateFile( - new NgDepsWriter(buf), outputs.ngDeps, templatesSrc); - ngDepsCode = formatter.format(buf.toString()); - } - } - transform.addOutput( - new Asset.fromString(templatesAssetId(primaryId), ngDepsCode)); - }, log: transform.logger); - } - - Future _deserializeXmb(AssetReader reader, AssetId translations) async { - final content = await reader.readAsString(translations); - final res = deserializeXmb(content, translations.toString()); - if (res.errors.length > 0) { - res.errors.forEach((e) => log.error(e.msg)); - throw "Cannot parse xmb file"; - } else { - return res; - } - } -} - -const _emptyNgDepsContents = 'initReflector() {}\n'; diff --git a/modules_dart/transform/lib/src/transform/transformer.dart b/modules_dart/transform/lib/src/transform/transformer.dart deleted file mode 100644 index 63dc89dea8..0000000000 --- a/modules_dart/transform/lib/src/transform/transformer.dart +++ /dev/null @@ -1,57 +0,0 @@ -library angular2.src.transform.transformer; - -import 'package:barback/barback.dart'; -import 'package:dart_style/dart_style.dart'; - -import 'common/eager_transformer_wrapper.dart'; -import 'common/formatter.dart' as formatter; -import 'common/options.dart'; -import 'common/options_reader.dart'; -import 'deferred_rewriter/transformer.dart'; -import 'directive_metadata_linker/transformer.dart'; -import 'directive_processor/transformer.dart'; -import 'inliner_for_test/transformer.dart'; -import 'reflection_remover/transformer.dart'; -import 'stylesheet_compiler/transformer.dart'; -import 'template_compiler/transformer.dart'; - -export 'common/options.dart'; - -/// Replaces Angular 2 mirror use with generated code. -class AngularTransformerGroup extends TransformerGroup { - AngularTransformerGroup._(phases, {bool formatCode: false}) : super(phases) { - if (formatCode) { - formatter.init(new DartFormatter()); - } - } - - factory AngularTransformerGroup(TransformerOptions options) { - var phases; - if (options.inlineViews) { - phases = [ - [new InlinerForTest(options)] - ]; - } else { - phases = [ - [new DirectiveProcessor(options)], - [new DirectiveMetadataLinker(options)], - [new ReflectionRemover(options)], - [ - new DeferredRewriter(), - new StylesheetCompiler(), - new TemplateCompiler(options) - ], - ]; - } - if (options.modeName == BarbackMode.RELEASE || !options.lazyTransformers) { - phases = phases - .map((phase) => phase.map((t) => new EagerTransformerWrapper(t))); - } - return new AngularTransformerGroup._(phases, - formatCode: options.formatCode); - } - - factory AngularTransformerGroup.asPlugin(BarbackSettings settings) { - return new AngularTransformerGroup(parseBarbackSettings(settings)); - } -} diff --git a/modules_dart/transform/lib/transform/codegen.dart b/modules_dart/transform/lib/transform/codegen.dart deleted file mode 100644 index 236807d290..0000000000 --- a/modules_dart/transform/lib/transform/codegen.dart +++ /dev/null @@ -1,56 +0,0 @@ -library angular2.transform.codegen.dart; - -import 'package:barback/barback.dart'; -import 'package:dart_style/dart_style.dart'; - -import 'package:angular2/src/transform/common/eager_transformer_wrapper.dart'; -import 'package:angular2/src/transform/common/formatter.dart' as formatter; -import 'package:angular2/src/transform/common/options.dart'; -import 'package:angular2/src/transform/common/options_reader.dart'; -import 'package:angular2/src/transform/directive_metadata_linker/transformer.dart'; -import 'package:angular2/src/transform/directive_processor/transformer.dart'; -import 'package:angular2/src/transform/inliner_for_test/transformer.dart'; -import 'package:angular2/src/transform/stylesheet_compiler/transformer.dart'; -import 'package:angular2/src/transform/template_compiler/transformer.dart'; - -export 'package:angular2/src/transform/common/options.dart'; - -/// Generates code to replace mirror use in Angular 2 apps. -/// -/// This transformer can be used along with others as a faster alternative to -/// the single angular2 transformer. -/// -/// See [the wiki][] for details. -/// -/// [the wiki]: https://github.com/angular/angular/wiki/Angular-2-Dart-Transformer -class CodegenTransformer extends TransformerGroup { - CodegenTransformer._(phases, {bool formatCode: false}) : super(phases) { - if (formatCode) { - formatter.init(new DartFormatter()); - } - } - - factory CodegenTransformer(TransformerOptions options) { - var phases; - if (options.inlineViews) { - phases = [ - [new InlinerForTest(options)] - ]; - } else { - phases = [ - [new DirectiveProcessor(options)], - [new DirectiveMetadataLinker(options)], - [new StylesheetCompiler(), new TemplateCompiler(options),], - ]; - } - if (options.modeName == BarbackMode.RELEASE || !options.lazyTransformers) { - phases = phases - .map((phase) => phase.map((t) => new EagerTransformerWrapper(t))); - } - return new CodegenTransformer._(phases, formatCode: options.formatCode); - } - - factory CodegenTransformer.asPlugin(BarbackSettings settings) { - return new CodegenTransformer(parseBarbackSettings(settings)); - } -} diff --git a/modules_dart/transform/lib/transform/deferred_rewriter.dart b/modules_dart/transform/lib/transform/deferred_rewriter.dart deleted file mode 100644 index c0f54ed2cb..0000000000 --- a/modules_dart/transform/lib/transform/deferred_rewriter.dart +++ /dev/null @@ -1,45 +0,0 @@ -library angular2.transform.deferred_rewriter.dart; - -import 'dart:async'; - -import 'package:barback/barback.dart'; - -import 'package:angular2/src/transform/deferred_rewriter/transformer.dart' - as base show DeferredRewriter; - -// TODO(kegluneq): Make this a TransformerGroup and add an AggregateTransformer -// that counts the number of transformed files & primary inputs. -// If the number of primary inputs is >> transformed files, output an error -// telling the user to use $include or $exclude in their pubspec. - -/// Rewrites `deferred` imports that need Angular 2 initialization. -/// -/// This transformer can be used along with others as a faster alternative to -/// the single angular2 transformer. -/// -/// See [the wiki][] for details. -/// -/// [the wiki]: https://github.com/angular/angular/wiki/Angular-2-Dart-Transformer -class DeferredRewriter extends Transformer implements DeclaringTransformer { - final base.DeferredRewriter _impl; - - /// Ctor which tells pub that this can be run as a standalone transformer. - DeferredRewriter.asPlugin(BarbackSettings _) - : _impl = new base.DeferredRewriter(); - - /// Signal that we process all .dart files. - /// - /// Instead, use the standard, built-in $exclude and $include transformer - /// parameters to control which files this transformer runs on. - /// See [https://www.dartlang.org/tools/pub/assets-and-transformers.html] for - /// details. - @override - String get allowedExtensions => '.dart'; - - @override - declareOutputs(transform) => _impl.declareOutputs(transform); - - @override - Future apply(transform) => - _impl.applyImpl(transform, transform.primaryInput.id); -} diff --git a/modules_dart/transform/lib/transform/reflection_remover.dart b/modules_dart/transform/lib/transform/reflection_remover.dart deleted file mode 100644 index ee3ba329c0..0000000000 --- a/modules_dart/transform/lib/transform/reflection_remover.dart +++ /dev/null @@ -1,65 +0,0 @@ -library angular2.transform.reflection_remover.dart; - -import 'dart:async'; - -import 'package:barback/barback.dart'; - -import 'package:angular2/src/transform/common/options.dart'; -import 'package:angular2/src/transform/common/options_reader.dart'; -import 'package:angular2/src/transform/reflection_remover/transformer.dart' - as base show ReflectionRemover; - -// TODO(kegluneq): Make this a TransformerGroup and add an AggregateTransformer -// that counts the number of transformed files & primary inputs. -// If the number of primary inputs is >> transformed files, output an error -// telling the user to use $include or $exclude in their pubspec. - -/// Removes the transitive dart:mirrors import from Angular 2 entrypoints. -/// -/// This transformer can be used along with others as a faster alternative to -/// the single angular2 transformer. -/// -/// See [the wiki][] for details. -/// -/// [the wiki]: https://github.com/angular/angular/wiki/Angular-2-Dart-Transformer -class ReflectionRemover extends Transformer implements DeclaringTransformer { - final base.ReflectionRemover _impl; - - ReflectionRemover._(this._impl); - - /// Ctor which tells pub that this can be run as a standalone transformer. - factory ReflectionRemover.asPlugin(BarbackSettings settings) { - final options = parseBarbackSettings(settings); - final entryPoints = options.entryPoints; - if (entryPoints != null && entryPoints.isNotEmpty) { - // TODO(kegluneq): Add a goo.gl link with more info. - throw new ArgumentError.value( - entryPoints.join(', '), - ENTRY_POINT_PARAM, - "Do not use '$ENTRY_POINT_PARAM' when specifying the Angular 2 " - "reflection_remover transformer. Instead, use pub's built-in " - r"$include and $exclude parameters to filter which files are " - "processed."); - } - return new ReflectionRemover._(new base.ReflectionRemover(options)); - } - - /// Signal that we process all .dart files. - /// - /// The underlying ReflectionRemover implementation respects the entry_points - /// transformer parameter, but this is inefficient and can be expensive for - /// large numbers of files. - /// - /// Instead, use the standard, built-in $exclude and $include transformer - /// parameters to control which files this transformer runs on. - /// See [https://www.dartlang.org/tools/pub/assets-and-transformers.html] for - /// details. - @override - String get allowedExtensions => '.dart'; - - @override - declareOutputs(transform) => _impl.declareOutputs(transform); - - @override - Future apply(transform) => _impl.apply(transform); -} diff --git a/modules_dart/transform/lib/transformer.dart b/modules_dart/transform/lib/transformer.dart deleted file mode 100644 index fdcc8187c5..0000000000 --- a/modules_dart/transform/lib/transformer.dart +++ /dev/null @@ -1,3 +0,0 @@ -library angular2.transformer_dart; - -export 'src/transform/transformer.dart'; diff --git a/modules_dart/transform/pubspec.yaml b/modules_dart/transform/pubspec.yaml deleted file mode 100644 index aa54344601..0000000000 --- a/modules_dart/transform/pubspec.yaml +++ /dev/null @@ -1,24 +0,0 @@ -name: ng2_transform -version: 0.0.0 -environment: - sdk: '>=1.10.0 <2.0.0' -dependencies: - angular2: - path: ../../dist/dart/angular2 - analyzer: '>=0.24.4 <0.28.0' - barback: '^0.15.2+2' - dart_style: '>=0.1.8 <0.3.0' - glob: '^1.0.0' - html: '^0.12.0' - intl: '^0.12.4' - logging: '>=0.9.0 <0.12.0' - observe: '^0.13.1' - path: '^1.0.0' - protobuf: '^0.5.0' - source_span: '^1.0.0' - stack_trace: '^1.1.1' -dev_dependencies: - transformer_test: '^0.2.0' - guinness: any - quiver: '^0.21.4' - test: '>=0.12.0 <0.13.0' diff --git a/modules_dart/transform/test/transform/common/annotation_matcher_test.dart b/modules_dart/transform/test/transform/common/annotation_matcher_test.dart deleted file mode 100644 index 03d7df55fd..0000000000 --- a/modules_dart/transform/test/transform/common/annotation_matcher_test.dart +++ /dev/null @@ -1,109 +0,0 @@ -library angular2.test.transform.common.annotation_matcher_test; - -import 'dart:async'; - -import 'package:analyzer/analyzer.dart'; -import 'package:barback/barback.dart' show AssetId; -import 'package:test/test.dart'; - -import 'package:angular2/src/transform/common/annotation_matcher.dart'; - -main() { - allTests(); -} - -var simpleAst = parseCompilationUnit(''' -import 'package:test/test.dart'; - -@Test() -var foo; -'''); - -var namespacedAst = parseCompilationUnit(''' -import 'package:test/test.dart' as test; - -@test.Test() -var foo; -'''); - -var relativePathAst = parseCompilationUnit(''' -import 'test.dart'; - -@Test() -var foo; -'''); - -var namespacedRelativePathAst = parseCompilationUnit(''' -import 'test.dart' as test; - -@test.Test() -var foo; -'''); - -void allTests() { - test('should be able to match basic annotations.', () { - var matcher = new AnnotationMatcher() - ..add(const ClassDescriptor('Test', 'package:test/test.dart')); - var visitor = new MatchRecordingVisitor(matcher); - simpleAst.accept(visitor); - expect(visitor.matches.length, equals(1)); - }); - - test('should be able to match namespaced annotations.', () { - var matcher = new AnnotationMatcher() - ..add(const ClassDescriptor('Test', 'package:test/test.dart')); - var visitor = new MatchRecordingVisitor(matcher); - namespacedAst.accept(visitor); - expect(visitor.matches.length, equals(1)); - }); - - test('should be able to match relative imports.', () { - var matcher = new AnnotationMatcher() - ..add(const ClassDescriptor('Test', 'package:test/test.dart')); - var visitor = - new MatchRecordingVisitor(matcher, new AssetId('test', 'lib/foo.dart')); - relativePathAst.accept(visitor); - expect(visitor.matches.length, equals(1)); - }); - - test('should be able to match relative imports with a namespace.', () { - var matcher = new AnnotationMatcher() - ..add(const ClassDescriptor('Test', 'package:test/test.dart')); - var visitor = - new MatchRecordingVisitor(matcher, new AssetId('test', 'lib/foo.dart')); - namespacedRelativePathAst.accept(visitor); - expect(visitor.matches.length, equals(1)); - }); - - test('should not match annotations if the import is missing.', () { - var matcher = new AnnotationMatcher() - ..add(const ClassDescriptor('Test', 'package:test/foo.dart')); - var visitor = new MatchRecordingVisitor(matcher); - simpleAst.accept(visitor); - expect(visitor.matches.isEmpty, isTrue); - }); - - test('should not match annotations if the name is different.', () { - var matcher = new AnnotationMatcher() - ..add(const ClassDescriptor('Foo', 'package:test/test.dart')); - var visitor = new MatchRecordingVisitor(matcher); - simpleAst.accept(visitor); - expect(visitor.matches.isEmpty, isTrue); - }); -} - -class MatchRecordingVisitor extends RecursiveAstVisitor { - final AssetId assetId; - final AnnotationMatcher matcher; - final matches = []; - - MatchRecordingVisitor(this.matcher, [AssetId assetId]) - : super(), - this.assetId = - assetId != null ? assetId : new AssetId('a', 'lib/a.dart'); - - @override - void visitAnnotation(Annotation annotation) { - if (matcher.hasMatch(annotation.name, assetId)) matches.add(annotation); - } -} diff --git a/modules_dart/transform/test/transform/common/application.dart b/modules_dart/transform/test/transform/common/application.dart deleted file mode 100644 index 39e48857f5..0000000000 --- a/modules_dart/transform/test/transform/common/application.dart +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. -library angular2.test.transform; - -import 'dart:async'; - -/// Mocked out version of `bootstrap`, defined in application.dart. Importing -/// the actual file in tests causes issues with resolution due to its -/// transitive dependencies. -Future bootstrap(Type appComponentType, - [List bindings = null, Function givenBootstrapErrorReporter = null]) { - return null; -} diff --git a/modules_dart/transform/test/transform/common/async_string_writer_tests.dart b/modules_dart/transform/test/transform/common/async_string_writer_tests.dart deleted file mode 100644 index 93f60955d4..0000000000 --- a/modules_dart/transform/test/transform/common/async_string_writer_tests.dart +++ /dev/null @@ -1,109 +0,0 @@ -library angular2.test.transform.common.async_string_writer; - -import 'dart:async'; - -import 'package:test/test.dart'; - -import 'package:angular2/src/transform/common/async_string_writer.dart'; - -void allTests() { - test('should function as a basic Writer without async calls.', () { - var writer = new AsyncStringWriter(); - writer.print('hello'); - expect('$writer', equals('hello')); - writer.println(', world'); - expect('$writer', equals('hello, world\n')); - }); - - test('should concatenate futures added with `asyncPrint`.', () async { - var writer = new AsyncStringWriter(); - writer.print('hello'); - expect('$writer', equals('hello')); - writer.asyncPrint(new Future.value(', world.')); - writer.print(' It is a beautiful day.'); - expect(await writer.asyncToString(), - equals('hello, world. It is a beautiful day.')); - }); - - test('should concatenate multiple futures regardless of order.', () async { - var completer1 = new Completer(); - var completer2 = new Completer(); - - var writer = new AsyncStringWriter(); - writer.print('hello'); - expect('$writer', equals('hello')); - writer.asyncPrint(completer1.future); - writer.asyncPrint(completer2.future); - - completer2.complete(' It is a beautiful day.'); - completer1.complete(', world.'); - - expect(await writer.asyncToString(), - equals('hello, world. It is a beautiful day.')); - }); - - test('should allow multiple "rounds" of `asyncPrint`.', () async { - var writer = new AsyncStringWriter(); - writer.print('hello'); - expect('$writer', equals('hello')); - writer.asyncPrint(new Future.value(', world.')); - expect(await writer.asyncToString(), equals('hello, world.')); - - writer.asyncPrint(new Future.value(' It is ')); - writer.asyncPrint(new Future.value('a beautiful ')); - writer.asyncPrint(new Future.value('day.')); - - expect(await writer.asyncToString(), - equals('hello, world. It is a beautiful day.')); - }); - - test('should handle calls to async methods while waiting.', () { - var completer1 = new Completer(); - var completer2 = new Completer(); - - var writer = new AsyncStringWriter(); - writer.print('hello'); - expect('$writer', equals('hello')); - - writer.asyncPrint(completer1.future); - var f1 = writer.asyncToString().then((result) { - expect(result, equals('hello, world.')); - }); - - writer.asyncPrint(completer2.future); - var f2 = writer.asyncToString().then((result) { - expect(result, equals('hello, world. It is a beautiful day.')); - }); - - completer1.complete(', world.'); - completer2.complete(' It is a beautiful day.'); - - return Future.wait([f1, f2]); - }); - - test( - 'should handle calls to async methods that complete in reverse ' - 'order while waiting.', () { - var completer1 = new Completer(); - var completer2 = new Completer(); - - var writer = new AsyncStringWriter(); - writer.print('hello'); - expect('$writer', equals('hello')); - - writer.asyncPrint(completer1.future); - var f1 = writer.asyncToString().then((result) { - expect(result, equals('hello, world.')); - }); - - writer.asyncPrint(completer2.future); - var f2 = writer.asyncToString().then((result) { - expect(result, equals('hello, world. It is a beautiful day.')); - }); - - completer2.complete(' It is a beautiful day.'); - completer1.complete(', world.'); - - return Future.wait([f1, f2]); - }); -} diff --git a/modules_dart/transform/test/transform/common/code/ng_deps_code_tests.dart b/modules_dart/transform/test/transform/common/code/ng_deps_code_tests.dart deleted file mode 100644 index c5fef0f875..0000000000 --- a/modules_dart/transform/test/transform/common/code/ng_deps_code_tests.dart +++ /dev/null @@ -1,70 +0,0 @@ -library angular2.test.transform.common.code.ng_deps_code_tests; - -import 'package:analyzer/analyzer.dart'; -import 'package:test/test.dart'; - -import 'package:angular2/src/transform/common/code/ng_deps_code.dart'; -import 'package:angular2/src/transform/common/model/import_export_model.pb.dart'; -import 'package:angular2/src/transform/common/model/ng_deps_model.pb.dart'; - -main() => allTests(); - -void allTests() { - group('writeNgDepsModel', () { - test('should output parsable code', () async { - final ngDeps = new NgDepsModel() - ..libraryUri = 'test.foo' - ..imports.add(new ImportModel() - ..uri = 'bar.dart' - ..prefix = 'dep'); - - final buf = new StringBuffer(); - final writer = new NgDepsWriter(buf); - writer.writeNgDepsModel(ngDeps, ''); - - var compilationUnit = parseCompilationUnit(buf.toString()); - - expect(compilationUnit, isNotNull); - expect(compilationUnit.declarations, isNotNull); - expect(compilationUnit.declarations.length > 0, isTrue); - }); - - test('should output parsable code with deferred imports', () async { - // Regression test for i/4587. - final ngDeps = new NgDepsModel() - ..libraryUri = 'test.foo' - ..imports.add(new ImportModel() - ..uri = 'bar.dart' - ..isDeferred = true - ..prefix = 'dep'); - - final buf = new StringBuffer(); - final writer = new NgDepsWriter(buf); - writer.writeNgDepsModel(ngDeps, ''); - - var compilationUnit = parseCompilationUnit(buf.toString()); - - expect(compilationUnit, isNotNull); - expect(compilationUnit.declarations, isNotNull); - expect(compilationUnit.declarations.length > 0, isTrue); - }); - - test('should add the given templateSource', () async { - final ngDeps = new NgDepsModel() - ..libraryUri = 'test.foo' - ..imports.add(new ImportModel() - ..uri = 'bar.dart' - ..prefix = 'dep'); - - final buf = new StringBuffer(); - final writer = new NgDepsWriter(buf); - writer.writeNgDepsModel(ngDeps, 'import \'foo.dart\';\nvar x = true;'); - - var compilationUnit = parseCompilationUnit(buf.toString()); - - expect(compilationUnit, isNotNull); - expect(compilationUnit.declarations, isNotNull); - expect(compilationUnit.declarations.length > 0, isTrue); - }); - }); -} diff --git a/modules_dart/transform/test/transform/common/compile_directive_metadata/ng_for.ng_meta.dart b/modules_dart/transform/test/transform/common/compile_directive_metadata/ng_for.ng_meta.dart deleted file mode 100644 index 2565807583..0000000000 --- a/modules_dart/transform/test/transform/common/compile_directive_metadata/ng_for.ng_meta.dart +++ /dev/null @@ -1,26 +0,0 @@ -library angular2.test.transform.common.compile_directive_metadata; - -final ngFor = { - "NgFor": { - "kind": "type", - "value": { - "class": "Directive", - "isComponent": false, - "selector": "[ngFor][ngForOf]", - "exportAs": null, - "type": { - "id": 9999, - "name": "NgFor", - "moduleUrl": "asset:angular2/lib/src/common/directives/ng_for.dart" - }, - "changeDetection": null, - "inputs": {"ngForOf": "ngForOf"}, - "outputs": {}, - "hostListeners": {}, - "hostProperties": {}, - "hostAttributes": {}, - "lifecycleHooks": [2], - "template": null - } - } -}; diff --git a/modules_dart/transform/test/transform/common/ng_meta_helper.dart b/modules_dart/transform/test/transform/common/ng_meta_helper.dart deleted file mode 100644 index 98b42737ae..0000000000 --- a/modules_dart/transform/test/transform/common/ng_meta_helper.dart +++ /dev/null @@ -1,84 +0,0 @@ -library angular2.test.transform.common.ng_meta_helper; - -import 'package:angular2/src/compiler/compile_metadata.dart'; -import 'package:angular2/src/core/change_detection/change_detection.dart'; -import 'package:angular2/src/core/metadata/view.dart' show ViewEncapsulation; - -export 'package:angular2/src/compiler/compile_metadata.dart'; -export 'package:angular2/src/core/change_detection/change_detection.dart'; -export 'package:angular2/src/core/metadata/view.dart' show ViewEncapsulation; -export 'package:angular2/src/transform/common/model/annotation_model.pb.dart'; -export 'package:angular2/src/transform/common/model/import_export_model.pb.dart'; -export 'package:angular2/src/transform/common/model/ng_deps_model.pb.dart'; -export 'package:angular2/src/transform/common/model/reflection_info_model.pb.dart'; -export 'package:angular2/src/transform/common/ng_meta.dart'; - -CompileDirectiveMetadata createComponentMetadataForTest( - {String name: 'TestMetadata', - moduleUrl: 'asset:angular2/test/test.dart', - selector: '[test]', - String template: 'Test'}) { - return createDirectiveMetadataForTest( - name: name, - moduleUrl: moduleUrl, - selector: selector, - template: new CompileTemplateMetadata( - encapsulation: ViewEncapsulation.Emulated, template: template)); -} - -CompilePipeMetadata createPipeMetadataForTest( - {String name: 'TestPipe', - moduleUrl: 'asset:angular2/test/test.dart', - String pipeName: 'test', - bool pure: false}) { - return new CompilePipeMetadata( - type: new CompileTypeMetadata(name: name, moduleUrl: moduleUrl), - name: pipeName, - pure: pure); -} - -CompileDirectiveMetadata createDirectiveMetadataForTest( - {String name: 'TestMetadata', - String moduleUrl: 'asset:angular2/test/test.dart', - String selector: 'test', - CompileTemplateMetadata template: null}) { - return CompileDirectiveMetadata.create( - type: new CompileTypeMetadata(name: name, moduleUrl: moduleUrl), - isComponent: template != null, - selector: selector, - exportAs: null, - changeDetection: ChangeDetectionStrategy.Default, - inputs: [], - outputs: [], - host: {}, - lifecycleHooks: [], - template: template); -} - -CompileDirectiveMetadata createFoo([String moduleBase = 'asset:a']) => - createComponentMetadataForTest( - name: 'FooComponent', - moduleUrl: '$moduleBase/export_cycle_files/foo.dart', - selector: 'foo', - template: 'Foo'); - -CompileDirectiveMetadata createBar([String moduleBase = 'asset:a']) => - createComponentMetadataForTest( - name: 'BarComponent', - moduleUrl: '$moduleBase/export_cycle_files/bar.dart', - selector: 'bar', - template: 'Bar'); - -CompilePipeMetadata createBarPipe([String moduleBase = 'asset:a']) => - createPipeMetadataForTest( - name: 'BarPipe', - pipeName: 'bar', - moduleUrl: '$moduleBase/export_cycle_files/bar.dart', - pure: false); - -CompileDirectiveMetadata createBaz([String moduleBase = 'asset:a']) => - createComponentMetadataForTest( - name: 'BazComponent', - moduleUrl: '$moduleBase/export_cycle_files/baz.dart', - selector: 'baz', - template: 'Baz'); diff --git a/modules_dart/transform/test/transform/common/ng_meta_test.dart b/modules_dart/transform/test/transform/common/ng_meta_test.dart deleted file mode 100644 index 74d759ec77..0000000000 --- a/modules_dart/transform/test/transform/common/ng_meta_test.dart +++ /dev/null @@ -1,158 +0,0 @@ -library angular2.test.transform.common.annotation_matcher_test; - -import 'package:test/test.dart'; - -import 'package:angular2/src/core/render/api.dart'; -import 'package:angular2/src/compiler/compile_metadata.dart'; -import 'package:angular2/src/transform/common/ng_meta.dart'; - -main() => allTests(); - -void allTests() { - var mockDirMetadata = [ - CompileDirectiveMetadata.create(type: new CompileTypeMetadata(name: 'N1')), - CompileDirectiveMetadata.create(type: new CompileTypeMetadata(name: 'N2')), - CompileDirectiveMetadata.create(type: new CompileTypeMetadata(name: 'N3')), - CompileDirectiveMetadata.create(type: new CompileTypeMetadata(name: 'N4')) - ]; - - test('should allow empty data.', () { - var ngMeta = new NgMeta.empty(); - expect(ngMeta.isEmpty, isTrue); - }); - - group('serialization', () { - test('should parse empty data correctly.', () { - var ngMeta = new NgMeta.fromJson({}); - expect(ngMeta.isEmpty, isTrue); - }); - - test('should be lossless', () { - var a = new NgMeta.empty(); - a.identifiers['T0'] = mockDirMetadata[0]; - a.identifiers['T1'] = mockDirMetadata[1]; - a.identifiers['T2'] = mockDirMetadata[2]; - a.identifiers['T3'] = mockDirMetadata[3]; - - a.aliases['a1'] = ['T1']; - a.aliases['a2'] = ['a1']; - a.aliases['a3'] = ['T3', 'a2']; - a.aliases['a4'] = ['a3', 'T3']; - - _checkSimilar(a, new NgMeta.fromJson(a.toJson())); - }); - }); - - group('flatten', () { - test('should include recursive aliases.', () { - var a = new NgMeta.empty(); - a.identifiers['T0'] = mockDirMetadata[0]; - a.identifiers['T1'] = mockDirMetadata[1]; - a.identifiers['T2'] = mockDirMetadata[2]; - a.identifiers['T3'] = mockDirMetadata[3]; - a.aliases['a1'] = ['T1']; - a.aliases['a2'] = ['a1']; - a.aliases['a3'] = ['T3', 'a2']; - a.aliases['a4'] = ['a3', 'T0']; - - expect(a.flatten('a4'), - equals([mockDirMetadata[3], mockDirMetadata[1], mockDirMetadata[0]])); - }); - - test('should detect cycles.', () { - var a = new NgMeta.empty(); - a.identifiers['T0'] = mockDirMetadata[0]; - a.aliases['a1'] = ['T0', 'a2']; - a.aliases['a2'] = ['a1']; - - expect( - () => a.flatten('a1'), - throwsA(predicate((ex) => - new RegExp('Cycle: a1 -> a2 -> a1.').hasMatch(ex.message)))); - }); - - test('should allow duplicates.', () { - var a = new NgMeta.empty(); - a.identifiers['T0'] = mockDirMetadata[0]; - a.aliases['a1'] = ['T0', 'a2']; - a.aliases['a2'] = ['T0']; - - expect(() => a.flatten('a1'), returnsNormally); - }); - }); - - group('merge', () { - test('should merge all identifiers on addAll', () { - var a = new NgMeta.empty(); - var b = new NgMeta.empty(); - a.identifiers['T0'] = mockDirMetadata[0]; - b.identifiers['T1'] = mockDirMetadata[1]; - a.addAll(b); - expect(a.identifiers, contains('T1')); - expect(a.identifiers['T1'], equals(mockDirMetadata[1])); - }); - - test('should merge all aliases on addAll', () { - var a = new NgMeta.empty(); - var b = new NgMeta.empty(); - a.aliases['a'] = ['x']; - b.aliases['b'] = ['y']; - a.addAll(b); - expect(a.aliases, contains('b')); - expect(a.aliases['b'], equals(['y'])); - }); - }); - - group('needsResolution', () { - test('should be true if there is a provider', () { - var a = new NgMeta.empty(); - a.identifiers["MyIdentifier"] = new CompileIdentifierMetadata(name: 'MyIdentifier', value: new CompileProviderMetadata()); - expect(a.needsResolution, isTrue); - }); - - test('should be true if there is an injectable service', () { - var a = new NgMeta.empty(); - a.identifiers["MyIdentifier"] = new CompileTypeMetadata(); - expect(a.needsResolution, isTrue); - }); - - test('should be true if there is an directive', () { - var a = new NgMeta.empty(); - a.identifiers["MyIdentifier"] = new CompileDirectiveMetadata(); - expect(a.needsResolution, isTrue); - }); - - test('should be true if there is a pipe', () { - var a = new NgMeta.empty(); - a.identifiers["MyIdentifier"] = new CompilePipeMetadata(); - expect(a.needsResolution, isTrue); - }); - - test('should be true if there is a factory', () { - var a = new NgMeta.empty(); - a.identifiers["MyIdentifier"] = new CompileFactoryMetadata(); - expect(a.needsResolution, isTrue); - }); - - test('should be false otherwise', () { - var a = new NgMeta.empty(); - a.identifiers["MyIdentifier"] = "some value"; - expect(a.needsResolution, isFalse); - }); - }); -} - -_checkSimilar(NgMeta a, NgMeta b) { - expect(a.identifiers.length, equals(b.identifiers.length)); - expect(a.aliases.length, equals(b.aliases.length)); - for (var k in a.identifiers.keys) { - expect(b.identifiers, contains(k)); - var at = a.identifiers[k]; - var bt = b.identifiers[k]; - expect(at.type.name, equals(bt.type.name)); - } - for (var k in a.aliases.keys) { - expect(b.aliases, contains(k)); - expect(b.aliases[k], equals(a.aliases[k])); - } -} diff --git a/modules_dart/transform/test/transform/common/read_file.dart b/modules_dart/transform/test/transform/common/read_file.dart deleted file mode 100644 index 3249e365da..0000000000 --- a/modules_dart/transform/test/transform/common/read_file.dart +++ /dev/null @@ -1,51 +0,0 @@ -library angular2.test.transform.common.read_file; - -import 'dart:async'; -import 'dart:convert'; -import 'dart:io'; - -import 'package:angular2/src/transform/common/asset_reader.dart'; -import 'package:barback/barback.dart'; - -/// Smooths over differences in CWD between IDEs and running tests in Travis. -String readFile(String path) { - for (var myPath in [path, 'test/transform/${path}']) { - var file = new File(myPath); - if (file.existsSync()) { - return file.readAsStringSync(); - } - } - return null; -} - -class TestAssetReader implements AssetReader { - /// This allows "faking" - final Map _overrideAssets = {}; - - Future readAsString(AssetId id, {Encoding encoding}) { - if (_overrideAssets.containsKey(id)) { - return new Future.value(_overrideAssets[id]); - } else { - return new Future.value(readFile(id.path)); - } - } - - Future hasInput(AssetId id) { - var exists = _overrideAssets.containsKey(id); - if (exists) return new Future.value(true); - - for (var myPath in [id.path, 'test/transform/${id.path}']) { - var file = new File(myPath); - exists = exists || file.existsSync(); - } - return new Future.value(exists); - } - - void clear() { - this._overrideAssets.clear(); - } - - void addAsset(AssetId id, String contents) { - _overrideAssets[id] = contents; - } -} diff --git a/modules_dart/transform/test/transform/common/recording_logger.dart b/modules_dart/transform/test/transform/common/recording_logger.dart deleted file mode 100644 index 9dce3d1d4a..0000000000 --- a/modules_dart/transform/test/transform/common/recording_logger.dart +++ /dev/null @@ -1,27 +0,0 @@ -library angular2.test.transform.common.recording_logger; - -import 'package:barback/barback.dart'; -import 'package:source_span/source_span.dart'; - -class RecordingLogger implements TransformLogger { - bool hasErrors = false; - - List logs = []; - - void _record(prefix, msg) => logs.add('$prefix: $msg'); - - @override - void info(msg, {AssetId asset, SourceSpan span}) => _record('INFO', msg); - - @override - void fine(msg, {AssetId asset, SourceSpan span}) => _record('FINE', msg); - - @override - void warning(msg, {AssetId asset, SourceSpan span}) => _record('WARN', msg); - - @override - void error(msg, {AssetId asset, SourceSpan span}) { - hasErrors = true; - _record('ERROR', msg); - } -} diff --git a/modules_dart/transform/test/transform/common/reflection_capabilities.dart b/modules_dart/transform/test/transform/common/reflection_capabilities.dart deleted file mode 100644 index 5aabb94df0..0000000000 --- a/modules_dart/transform/test/transform/common/reflection_capabilities.dart +++ /dev/null @@ -1,9 +0,0 @@ -// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. -library angular2.test.transform; - -/// Mocked out version of {@link ReflectionCapabilities}, defined in -/// src/core/reflection/reflection_capabilities.dart. Importing the actual file in -/// tests causes issues with resolution due to transitive dependencies. -class ReflectionCapabilities {} diff --git a/modules_dart/transform/test/transform/common/url_resolver_tests.dart b/modules_dart/transform/test/transform/common/url_resolver_tests.dart deleted file mode 100644 index 0a53499ae2..0000000000 --- a/modules_dart/transform/test/transform/common/url_resolver_tests.dart +++ /dev/null @@ -1,149 +0,0 @@ -library angular2.test.transform.common.url_resolver_tests; - -import 'package:barback/barback.dart'; -import 'package:test/test.dart'; - -import 'package:angular2/src/transform/common/url_resolver.dart'; - -main() => allTests(); - -void allTests() { - var urlResolver = createOfflineCompileUrlResolver(); - - group('toAssetUri', () { - test('should convert `AssetId`s to asset: uris', () { - var assetId = new AssetId('test_package', 'lib/src/impl.dart'); - expect( - toAssetUri(assetId), equals('asset:test_package/lib/src/impl.dart')); - }); - - test('should throw if passed a null AssetId', () { - expect(() => toAssetUri(null), throwsArgumentError); - }); - }); - - group('fromUri', () { - test('should convert asset: `uri`s to `AssetId`s', () { - expect(fromUri('asset:test_package/lib/src/impl.dart'), - equals(new AssetId('test_package', 'lib/src/impl.dart'))); - }); - - test('should convert package: `uri`s to `AssetId`s', () { - expect(fromUri('package:test_package/src/impl.dart'), - equals(new AssetId('test_package', 'lib/src/impl.dart'))); - }); - - test('should throw if passed a null uri', () { - expect(() => fromUri(null), throwsArgumentError); - }); - - test('should throw if passed an empty uri', () { - expect(() => fromUri(''), throwsArgumentError); - }); - }); - - group('isDartCoreUri', () { - test('should detect dart: uris', () { - expect(isDartCoreUri('dart:core'), isTrue); - expect(isDartCoreUri('dart:convert'), isTrue); - expect(isDartCoreUri('package:angular2/angular2.dart'), isFalse); - expect(isDartCoreUri('asset:angular2/lib/angular2.dart'), isFalse); - }); - - test('should throw if passed a null uri', () { - expect(() => isDartCoreUri(null), throwsArgumentError); - }); - - test('should throw if passed an empty uri', () { - expect(() => isDartCoreUri(''), throwsArgumentError); - }); - }); - - group('toAssetScheme', () { - test('should throw for relative `Uri`s', () { - expect(() => toAssetScheme(Uri.parse('/lib/src/file.dart')), - throwsArgumentError); - }); - - test('should convert package: `Uri`s to asset:', () { - expect(toAssetScheme(Uri.parse('package:angular2/angular2.dart')), - equals(Uri.parse('asset:angular2/lib/angular2.dart'))); - }); - - test('should throw for package: `Uri`s which are too short', () { - expect(() => toAssetScheme(Uri.parse('package:angular2')), - throwsFormatException); - }); - - test('should convert asset: `Uri`s to asset:', () { - expect(toAssetScheme(Uri.parse('asset:angular2/lib/angular2.dart')), - equals(Uri.parse('asset:angular2/lib/angular2.dart'))); - }); - - test('should throw for asset: `Uri`s which are too short', () { - expect(() => toAssetScheme(Uri.parse('asset:angular2')), - throwsFormatException); - - expect(() => toAssetScheme(Uri.parse('asset:angular2/lib')), - throwsFormatException); - }); - - test('should pass through unsupported schemes', () { - var uri = 'http://server.com/style.css'; - expect('${toAssetScheme(Uri.parse(uri))}', equals(uri)); - }); - - test('should throw if passed a null uri', () { - expect(() => toAssetScheme(null), throwsArgumentError); - }); - }); - - group('resolve', () { - test('should resolve package: uris to asset: uris', () { - expect(urlResolver.resolve('', 'package:angular2/angular2.dart'), - equals('asset:angular2/lib/angular2.dart')); - }); - - test('should ignore baseUrl for absolute uris', () { - expect(urlResolver.resolve(null, 'package:angular2/angular2.dart'), - equals('asset:angular2/lib/angular2.dart')); - expect(urlResolver.resolve(null, 'asset:angular2/lib/angular2.dart'), - equals('asset:angular2/lib/angular2.dart')); - }); - - test('should resolve asset: uris to asset: uris', () { - expect(urlResolver.resolve('', 'asset:angular2/lib/angular2.dart'), - equals('asset:angular2/lib/angular2.dart')); - }); - - test('should resolve relative uris when baseUrl is package: uri', () { - expect( - urlResolver.resolve('package:angular2/angular2.dart', - 'src/transform/transformer.dart'), - equals('asset:angular2/lib/src/transform/transformer.dart')); - }); - - test('should resolve relative uris when baseUrl is asset: uri', () { - expect( - urlResolver.resolve('asset:angular2/lib/angular2.dart', - 'src/transform/transformer.dart'), - equals('asset:angular2/lib/src/transform/transformer.dart')); - }); - - test('should normalize uris', () { - expect( - urlResolver.resolve('asset:angular2/lib/angular2.dart', - 'src/transform/../transform/transformer.dart'), - equals('asset:angular2/lib/src/transform/transformer.dart')); - expect( - urlResolver.resolve('asset:angular2/lib/src/../angular2.dart', - 'src/transform/transformer.dart'), - equals('asset:angular2/lib/src/transform/transformer.dart')); - }); - - test('should gracefully handle an empty uri', () { - expect(urlResolver.resolve('package:angular2/angular2.dart', ''), - equals('asset:angular2/lib/angular2.dart')); - }); - }); -} diff --git a/modules_dart/transform/test/transform/deferred_rewriter/all_tests.dart b/modules_dart/transform/test/transform/deferred_rewriter/all_tests.dart deleted file mode 100644 index b7dac99f2b..0000000000 --- a/modules_dart/transform/test/transform/deferred_rewriter/all_tests.dart +++ /dev/null @@ -1,62 +0,0 @@ -library angular2.test.transform.deferred_rewriter.all_tests; - -import 'package:barback/barback.dart'; -import 'package:dart_style/dart_style.dart'; -import 'package:path/path.dart' as path; -import 'package:test/test.dart'; - -import 'package:angular2/src/transform/common/zone.dart' as zone; -import 'package:angular2/src/transform/deferred_rewriter/transformer.dart'; - -import '../common/read_file.dart'; -import '../common/recording_logger.dart'; - -var formatter = new DartFormatter(); - -main() { - allTests(); -} - -void allTests() { - _testRewriteDeferredLibraries( - 'should return null when no deferred libraries found.', - 'no_deferred_libraries/index.dart'); - _testRewriteDeferredLibraries( - 'should return null when deferred libraries with no ng_deps.', - 'no_ng_deps_libraries/index.dart'); - _testRewriteDeferredLibraries( - 'should rewrite deferred libraries with ng_deps.', - 'simple_deferred_example/index.dart'); - _testRewriteDeferredLibraries( - 'should not rewrite deferred libraries without ng_deps.', - 'deferred_example_no_ng_deps/index.dart'); - _testRewriteDeferredLibraries( - 'should rewrite deferred libraries with ng_deps leave other deferred library alone.', - 'complex_deferred_example/index.dart'); -} - -void _testRewriteDeferredLibraries(String name, String inputPath) { - test(name, () { - return zone.exec(() async { - var inputId = _assetIdForPath(inputPath); - var reader = new TestAssetReader(); - var expectedPath = path.join( - path.dirname(inputPath), 'expected', path.basename(inputPath)); - var expectedId = _assetIdForPath(expectedPath); - - var actualOutput = await rewriteDeferredLibraries(reader, inputId); - var expectedOutput = await reader.readAsString(expectedId); - if (expectedOutput == null) { - // Null expectedOutput signals no output. Ensure that is true. - expect(actualOutput, isNull); - } else { - expect(actualOutput, isNotNull); - expect(formatter.format(actualOutput), - equals(formatter.format(expectedOutput))); - } - }, log: new RecordingLogger()); - }); -} - -AssetId _assetIdForPath(String path) => - new AssetId('angular2', 'test/transform/deferred_rewriter/$path'); diff --git a/modules_dart/transform/test/transform/deferred_rewriter/complex_deferred_example/expected/index.dart b/modules_dart/transform/test/transform/deferred_rewriter/complex_deferred_example/expected/index.dart deleted file mode 100644 index 4f6a154ded..0000000000 --- a/modules_dart/transform/test/transform/deferred_rewriter/complex_deferred_example/expected/index.dart +++ /dev/null @@ -1,17 +0,0 @@ -library web_foo; - -import 'package:angular2/src/core/application.dart'; -import 'package:angular2/src/core/reflection/reflection.dart'; -import 'package:angular2/src/core/reflection/reflection_capabilities.dart'; -import 'hello.ngfactory.dart' deferred as a; // ng_deps. Should be rewritten. -import 'b.dart' deferred as b; // No ng_deps. Shouldn't be rewritten. - -void main() { - reflector.reflectionCapabilities = new ReflectionCapabilities(); - a.loadLibrary().then((_) { - a.initReflector(); - }).then((_) { - bootstrap(a.HelloCmp); - }); - b.loadLibrary(); -} diff --git a/modules_dart/transform/test/transform/deferred_rewriter/complex_deferred_example/hello.dart b/modules_dart/transform/test/transform/deferred_rewriter/complex_deferred_example/hello.dart deleted file mode 100644 index 6ea8f87ad9..0000000000 --- a/modules_dart/transform/test/transform/deferred_rewriter/complex_deferred_example/hello.dart +++ /dev/null @@ -1,8 +0,0 @@ -library playground.src.hello_world.absolute_url_expression_files; - -import 'package:angular2/angular2.dart' - show bootstrap, Component, Directive, View, NgElement; - -@Component(selector: 'hello-app') -@View(templateUrl: 'package:other_package/template.html') -class HelloCmp {} diff --git a/modules_dart/transform/test/transform/deferred_rewriter/complex_deferred_example/hello.ng_meta.json b/modules_dart/transform/test/transform/deferred_rewriter/complex_deferred_example/hello.ng_meta.json deleted file mode 100644 index e43ab83833..0000000000 --- a/modules_dart/transform/test/transform/deferred_rewriter/complex_deferred_example/hello.ng_meta.json +++ /dev/null @@ -1,32 +0,0 @@ -{ - "HelloCmp": - { - "kind": "type", - "value": { - "class": "Directive", - "isComponent": true, - "selector":"hello-app", - "exportAs": null, - "type": { - "id": 1, - "name": "HelloCmp", - "moduleUrl": "asset:angular2/test/transform/deferred_rewriter/complex_deferred_example/hello.dart" - }, - "changeDetection": 5, - "inputs": {}, - "outputs": {}, - "hostListeners": {}, - "hostProperties": {}, - "hostAttributes": {}, - "lifecycleHooks": [], - "template": { - "encapsulation": 0, - "template": "Hi", - "templateUrl": "package:other_package/template.html", - "styles": null, - "styleUrls": null, - "ngContentSelectors": null - } - } - } -} diff --git a/modules_dart/transform/test/transform/deferred_rewriter/complex_deferred_example/index.dart b/modules_dart/transform/test/transform/deferred_rewriter/complex_deferred_example/index.dart deleted file mode 100644 index ca2f2196a1..0000000000 --- a/modules_dart/transform/test/transform/deferred_rewriter/complex_deferred_example/index.dart +++ /dev/null @@ -1,15 +0,0 @@ -library web_foo; - -import 'package:angular2/src/core/application.dart'; -import 'package:angular2/src/core/reflection/reflection.dart'; -import 'package:angular2/src/core/reflection/reflection_capabilities.dart'; -import 'hello.dart' deferred as a; // ng_deps. Should be rewritten. -import 'b.dart' deferred as b; // No ng_deps. Shouldn't be rewritten. - -void main() { - reflector.reflectionCapabilities = new ReflectionCapabilities(); - a.loadLibrary().then((_) { - bootstrap(a.HelloCmp); - }); - b.loadLibrary(); -} diff --git a/modules_dart/transform/test/transform/deferred_rewriter/deferred_example_no_ng_deps/hello.dart b/modules_dart/transform/test/transform/deferred_rewriter/deferred_example_no_ng_deps/hello.dart deleted file mode 100644 index 6ea8f87ad9..0000000000 --- a/modules_dart/transform/test/transform/deferred_rewriter/deferred_example_no_ng_deps/hello.dart +++ /dev/null @@ -1,8 +0,0 @@ -library playground.src.hello_world.absolute_url_expression_files; - -import 'package:angular2/angular2.dart' - show bootstrap, Component, Directive, View, NgElement; - -@Component(selector: 'hello-app') -@View(templateUrl: 'package:other_package/template.html') -class HelloCmp {} diff --git a/modules_dart/transform/test/transform/deferred_rewriter/deferred_example_no_ng_deps/index.dart b/modules_dart/transform/test/transform/deferred_rewriter/deferred_example_no_ng_deps/index.dart deleted file mode 100644 index 7d93631551..0000000000 --- a/modules_dart/transform/test/transform/deferred_rewriter/deferred_example_no_ng_deps/index.dart +++ /dev/null @@ -1,13 +0,0 @@ -library web_foo; - -import 'package:angular2/src/core/application.dart'; -import 'package:angular2/src/core/reflection/reflection.dart'; -import 'package:angular2/src/core/reflection/reflection_capabilities.dart'; -import 'hello.dart' deferred as a; - -void main() { - reflector.reflectionCapabilities = new ReflectionCapabilities(); - a.loadLibrary().then((_) { - bootstrap(a.HelloCmp); - }); -} diff --git a/modules_dart/transform/test/transform/deferred_rewriter/no_deferred_libraries/index.dart b/modules_dart/transform/test/transform/deferred_rewriter/no_deferred_libraries/index.dart deleted file mode 100644 index 7df32a51a0..0000000000 --- a/modules_dart/transform/test/transform/deferred_rewriter/no_deferred_libraries/index.dart +++ /dev/null @@ -1,10 +0,0 @@ -library web_foo; - -import 'package:angular2/src/core/application.dart'; -import 'package:angular2/src/core/reflection/reflection.dart'; -import 'package:angular2/src/core/reflection/reflection_capabilities.dart'; - -void main() { - reflector.reflectionCapabilities = new ReflectionCapabilities(); - bootstrap(MyComponent); -} diff --git a/modules_dart/transform/test/transform/deferred_rewriter/no_ng_deps_libraries/index.dart b/modules_dart/transform/test/transform/deferred_rewriter/no_ng_deps_libraries/index.dart deleted file mode 100644 index 768de29c23..0000000000 --- a/modules_dart/transform/test/transform/deferred_rewriter/no_ng_deps_libraries/index.dart +++ /dev/null @@ -1,11 +0,0 @@ -library web_foo; - -import 'package:angular2/src/core/application.dart'; -import 'package:angular2/src/core/reflection/reflection.dart'; -import 'package:angular2/src/core/reflection/reflection_capabilities.dart'; -import 'a.dart' deferred as a; - -void main() { - reflector.reflectionCapabilities = new ReflectionCapabilities(); - bootstrap(MyComponent); -} diff --git a/modules_dart/transform/test/transform/deferred_rewriter/simple_deferred_example/expected/index.dart b/modules_dart/transform/test/transform/deferred_rewriter/simple_deferred_example/expected/index.dart deleted file mode 100644 index 42adfe5efd..0000000000 --- a/modules_dart/transform/test/transform/deferred_rewriter/simple_deferred_example/expected/index.dart +++ /dev/null @@ -1,15 +0,0 @@ -library web_foo; - -import 'package:angular2/src/core/application.dart'; -import 'package:angular2/src/core/reflection/reflection.dart'; -import 'package:angular2/src/core/reflection/reflection_capabilities.dart'; -import 'hello.ngfactory.dart' deferred as a; - -void main() { - reflector.reflectionCapabilities = new ReflectionCapabilities(); - a.loadLibrary().then((_) { - a.initReflector(); - }).then((_) { - bootstrap(a.HelloCmp); - }); -} diff --git a/modules_dart/transform/test/transform/deferred_rewriter/simple_deferred_example/hello.dart b/modules_dart/transform/test/transform/deferred_rewriter/simple_deferred_example/hello.dart deleted file mode 100644 index 6ea8f87ad9..0000000000 --- a/modules_dart/transform/test/transform/deferred_rewriter/simple_deferred_example/hello.dart +++ /dev/null @@ -1,8 +0,0 @@ -library playground.src.hello_world.absolute_url_expression_files; - -import 'package:angular2/angular2.dart' - show bootstrap, Component, Directive, View, NgElement; - -@Component(selector: 'hello-app') -@View(templateUrl: 'package:other_package/template.html') -class HelloCmp {} diff --git a/modules_dart/transform/test/transform/deferred_rewriter/simple_deferred_example/hello.ng_meta.json b/modules_dart/transform/test/transform/deferred_rewriter/simple_deferred_example/hello.ng_meta.json deleted file mode 100644 index 6a16aaf5d7..0000000000 --- a/modules_dart/transform/test/transform/deferred_rewriter/simple_deferred_example/hello.ng_meta.json +++ /dev/null @@ -1,32 +0,0 @@ -{ - "HelloCmp": - { - "kind": "type", - "value": { - "class": "Directive", - "isComponent": true, - "selector":"hello-app", - "exportAs": null, - "type": { - "id": 1, - "name": "HelloCmp", - "moduleUrl": "asset:angular2/test/transform/deferred_rewriter/simple_deferred_example/hello.dart" - }, - "changeDetection": 5, - "inputs": {}, - "outputs": {}, - "hostListeners": {}, - "hostProperties": {}, - "hostAttributes": {}, - "lifecycleHooks": [], - "template": { - "encapsulation": 0, - "template": "Hi", - "templateUrl": "package:other_package/template.html", - "styles": null, - "styleUrls": null, - "ngContentSelectors": null - } - } - } -} diff --git a/modules_dart/transform/test/transform/deferred_rewriter/simple_deferred_example/index.dart b/modules_dart/transform/test/transform/deferred_rewriter/simple_deferred_example/index.dart deleted file mode 100644 index 7d93631551..0000000000 --- a/modules_dart/transform/test/transform/deferred_rewriter/simple_deferred_example/index.dart +++ /dev/null @@ -1,13 +0,0 @@ -library web_foo; - -import 'package:angular2/src/core/application.dart'; -import 'package:angular2/src/core/reflection/reflection.dart'; -import 'package:angular2/src/core/reflection/reflection_capabilities.dart'; -import 'hello.dart' deferred as a; - -void main() { - reflector.reflectionCapabilities = new ReflectionCapabilities(); - a.loadLibrary().then((_) { - bootstrap(a.HelloCmp); - }); -} diff --git a/modules_dart/transform/test/transform/directive_metadata_linker/all_tests.dart b/modules_dart/transform/test/transform/directive_metadata_linker/all_tests.dart deleted file mode 100644 index a9c3de067d..0000000000 --- a/modules_dart/transform/test/transform/directive_metadata_linker/all_tests.dart +++ /dev/null @@ -1,685 +0,0 @@ -library angular2.test.transform.directive_metadata_linker.all_tests; - -import 'dart:async'; -import 'dart:convert'; - -import 'package:barback/barback.dart'; -import 'package:dart_style/dart_style.dart'; -import 'package:test/test.dart'; - -import 'package:angular2/src/transform/common/asset_reader.dart'; -import 'package:angular2/src/transform/common/names.dart'; -import 'package:angular2/src/transform/common/model/import_export_model.pb.dart'; -import 'package:angular2/src/transform/common/zone.dart' as zone; -import 'package:angular2/src/transform/directive_metadata_linker/ng_meta_linker.dart'; - -import '../common/ng_meta_helper.dart'; -import '../common/read_file.dart'; -import '../common/recording_logger.dart'; - -var formatter = new DartFormatter(); - -main() => allTests(); - -var oldTest = test; -void allTests() { - var test = (name, fn) { -// if (name.contains('indirection')) { - oldTest(name, fn); -// } - }; - - TestAssetReader reader = null; - final moduleBase = 'asset:a'; - var fooNgMeta, fooAssetId, fooMetaAssetId, fooComponentMeta; - var barNgMeta, barAssetId, barMetaAssetId, barComponentMeta; - var bazNgMeta, bazAssetId, bazMetaAssetId, bazComponentMeta; - - /// Call after making changes to `fooNgMeta`, `barNgMeta`, or `bazNgMeta` and - /// before trying to read them from `reader`. - final updateReader = () => reader - ..addAsset(fooAssetId, JSON.encode(fooNgMeta.toJson())) - ..addAsset(barMetaAssetId, JSON.encode(fooNgMeta.toJson())) - ..addAsset(barAssetId, JSON.encode(barNgMeta.toJson())) - ..addAsset(barMetaAssetId, JSON.encode(barNgMeta.toJson())) - ..addAsset(bazAssetId, JSON.encode(bazNgMeta.toJson())) - ..addAsset(bazMetaAssetId, JSON.encode(bazNgMeta.toJson())); - - setUp(() { - reader = new TestAssetReader(); - - // Establish some test NgMeta objects with one Component each. - fooComponentMeta = createFoo(moduleBase); - fooNgMeta = new NgMeta(ngDeps: new NgDepsModel()); - fooNgMeta.identifiers[fooComponentMeta.type.name] = fooComponentMeta; - - barComponentMeta = createBar(moduleBase); - barNgMeta = new NgMeta(ngDeps: new NgDepsModel()); - barNgMeta.identifiers[barComponentMeta.type.name] = barComponentMeta; - - bazComponentMeta = createBaz(moduleBase); - bazNgMeta = new NgMeta(ngDeps: new NgDepsModel()); - barNgMeta.identifiers[bazComponentMeta.type.name] = bazComponentMeta; - - fooAssetId = new AssetId('a', toSummaryExtension('lib/foo.dart')); - fooMetaAssetId = new AssetId('a', toMetaExtension('lib/foo.dart')); - barAssetId = new AssetId('a', toSummaryExtension('lib/bar.dart')); - barMetaAssetId = new AssetId('a', toMetaExtension('lib/bar.dart')); - bazAssetId = new AssetId('a', toSummaryExtension('lib/baz.dart')); - bazMetaAssetId = new AssetId('a', toMetaExtension('lib/baz.dart')); - - updateReader(); - }); - - group('NgMeta linker', () { - test('should include `DirectiveMetadata` from exported files.', () async { - fooNgMeta.ngDeps.exports.add(new ExportModel()..uri = 'bar.dart'); - updateReader(); - - var extracted = await _testLink(reader, fooAssetId, fooMetaAssetId); - expect(extracted.identifiers['FooComponent'], isNotNull); - expect(extracted.identifiers['BarComponent'], isNotNull); - - expect(extracted.identifiers['FooComponent'].selector, equals('foo')); - expect(extracted.identifiers['BarComponent'].selector, equals('bar')); - }); - - test('should include `DirectiveMetadata` recursively from exported files.', - () async { - fooNgMeta.ngDeps.exports.add(new ExportModel()..uri = 'bar.dart'); - barNgMeta.ngDeps.exports.add(new ExportModel()..uri = 'baz.dart'); - updateReader(); - - var extracted = await _testLink(reader, fooAssetId, fooMetaAssetId); - expect(extracted.identifiers['FooComponent'], isNotNull); - expect(extracted.identifiers['BarComponent'], isNotNull); - expect(extracted.identifiers['BazComponent'], isNotNull); - - expect(extracted.identifiers['FooComponent'].selector, equals('foo')); - expect(extracted.identifiers['BarComponent'].selector, equals('bar')); - expect(extracted.identifiers['BazComponent'].selector, equals('baz')); - }); - - test('should handle `DirectiveMetadata` export cycles gracefully.', () async { - fooNgMeta.ngDeps.exports.add(new ExportModel()..uri = 'bar.dart'); - barNgMeta.ngDeps.exports.add(new ExportModel()..uri = 'baz.dart'); - bazNgMeta.ngDeps.exports.add(new ExportModel()..uri = 'foo.dart'); - updateReader(); - - var extracted = await _testLink(reader, bazAssetId, bazMetaAssetId); - expect(extracted.identifiers['FooComponent'], isNotNull); - expect(extracted.identifiers['BarComponent'], isNotNull); - expect(extracted.identifiers['BazComponent'], isNotNull); - }); - - test('should include `DirectiveMetadata` from exported files ' - 'expressed as absolute uris', () async { - fooNgMeta.ngDeps.exports - .add(new ExportModel()..uri = 'package:bar/bar.dart'); - updateReader(); - reader.addAsset(new AssetId('bar', toMetaExtension('lib/bar.dart')), - JSON.encode(barNgMeta.toJson())); - - var extracted = await _testLink(reader, fooAssetId, fooMetaAssetId); - - expect(extracted.identifiers['FooComponent'], isNotNull); - expect(extracted.identifiers['BarComponent'], isNotNull); - - expect(extracted.identifiers['FooComponent'].selector, equals('foo')); - expect(extracted.identifiers['BarComponent'].selector, equals('bar')); - }); - - test('should resolve queries from types.', () async { - barNgMeta.identifiers['Service'] = - new CompileTypeMetadata(name: 'Service', moduleUrl: 'moduleUrl'); - - fooComponentMeta.queries = [ - new CompileQueryMetadata(selectors: [new CompileTokenMetadata(identifier: new CompileIdentifierMetadata(name: 'Service'))], - read: new CompileTokenMetadata(identifier: new CompileIdentifierMetadata(name: 'Service'))), - new CompileQueryMetadata(selectors: [new CompileTokenMetadata(value: 'one')], - read: new CompileTokenMetadata(value: 'one')) - ]; - - fooComponentMeta.viewQueries = [ - new CompileQueryMetadata(selectors: [new CompileTokenMetadata(identifier: new CompileIdentifierMetadata(name: 'Service'))], - read: new CompileTokenMetadata(identifier: new CompileIdentifierMetadata(name: 'Service'))), - new CompileQueryMetadata(selectors: [new CompileTokenMetadata(value: 'one')], - read: new CompileTokenMetadata(value: 'one')) - ]; - - fooNgMeta.ngDeps.imports.add(new ImportModel()..uri = 'bar.dart'); - - updateReader(); - - final extracted = await _testLink(reader, fooAssetId, fooMetaAssetId); - final cmp = extracted.identifiers["FooComponent"]; - - expect(cmp.queries.length, equals(2)); - expect(cmp.viewQueries.length, equals(2)); - - expect(cmp.queries[0].selectors[0].identifier.name, equals("Service")); - expect(cmp.queries[0].selectors[0].identifier.moduleUrl, equals("moduleUrl")); - expect(cmp.queries[0].read.identifier.name, equals("Service")); - expect(cmp.queries[0].read.identifier.moduleUrl, equals("moduleUrl")); - expect(cmp.queries[1].selectors[0].value, equals("one")); - expect(cmp.queries[1].read.value, equals("one")); - - expect(cmp.viewQueries[0].selectors[0].identifier.name, equals("Service")); - expect(cmp.viewQueries[0].selectors[0].identifier.moduleUrl, equals("moduleUrl")); - expect(cmp.viewQueries[0].read.identifier.name, equals("Service")); - expect(cmp.viewQueries[0].read.identifier.moduleUrl, equals("moduleUrl")); - expect(cmp.viewQueries[1].selectors[0].value, equals("one")); - expect(cmp.viewQueries[1].read.value, equals("one")); - }); - - test('should resolve providers from types.', () async { - barNgMeta.identifiers['Service'] = - new CompileTypeMetadata(name: 'Service', moduleUrl: 'moduleUrl'); - - fooComponentMeta.providers = [ - new CompileIdentifierMetadata(name: 'Service') - ]; - fooComponentMeta.type.diDeps = [ - new CompileDiDependencyMetadata( - token: new CompileTokenMetadata(identifier: - new CompileIdentifierMetadata(name: 'Service'))) - ]; - - fooNgMeta.ngDeps.imports.add(new ImportModel()..uri = 'bar.dart'); - - updateReader(); - - final extracted = await _testLink(reader, fooAssetId, fooMetaAssetId); - final cmp = extracted.identifiers["FooComponent"]; - - expect(cmp.providers.length, equals(1)); - - expect(cmp.providers[0].token.identifier.name, equals("Service")); - expect(cmp.providers[0].token.identifier.moduleUrl, equals("moduleUrl")); - expect(cmp.providers[0].useClass.identifier.name, equals("Service")); - expect(cmp.providers[0].useClass.identifier.moduleUrl, equals("moduleUrl")); - - expect(cmp.type.diDeps.length, equals(1)); - expect(cmp.type.diDeps[0].token.identifier.name, equals("Service")); - expect(cmp.type.diDeps[0].token.identifier.moduleUrl, equals("moduleUrl")); - }); - - test('should resolve providers from functions.', () async { - barNgMeta.identifiers['Service'] = - new CompileTypeMetadata(name: 'Service', moduleUrl: 'moduleUrl'); - - fooNgMeta.identifiers['factory'] = - new CompileFactoryMetadata(name: 'factory', moduleUrl: 'moduleUrl', diDeps: [ - new CompileDiDependencyMetadata( - token: new CompileTokenMetadata(identifier: new CompileIdentifierMetadata(name: 'Service'))) - ]); - - fooComponentMeta.providers = [ - new CompileProviderMetadata(token: new CompileTokenMetadata(value: 'someFunc'), useFactory: - new CompileFactoryMetadata(name: 'factory')) - ]; - - fooNgMeta.ngDeps.imports.add(new ImportModel()..uri = 'bar.dart'); - - updateReader(); - - final extracted = await _testLink(reader, fooAssetId, fooMetaAssetId); - final cmp = extracted.identifiers["FooComponent"]; - - expect(cmp.providers.length, equals(1)); - - expect(cmp.providers[0].token.value, equals("someFunc")); - expect(cmp.providers[0].useFactory.name, equals("factory")); - expect(cmp.providers[0].useFactory.moduleUrl, equals("moduleUrl")); - - expect(cmp.providers[0].useFactory.diDeps[0].token.identifier.name, equals("Service")); - expect(cmp.providers[0].useFactory.diDeps[0].token.identifier.moduleUrl, equals("moduleUrl")); - }); - - test('should resolve viewProviders from types.', () async { - barNgMeta.identifiers['Service'] = - new CompileTypeMetadata(name: 'Service', moduleUrl: 'moduleUrl'); - - fooComponentMeta.viewProviders = [ - new CompileProviderMetadata( - token: new CompileTokenMetadata(identifier: new CompileIdentifierMetadata(name: 'Service'))) - ]; - fooNgMeta.ngDeps.imports.add(new ImportModel()..uri = 'bar.dart'); - - updateReader(); - - final extracted = await _testLink(reader, fooAssetId, fooMetaAssetId); - final cmp = extracted.identifiers["FooComponent"]; - - expect(cmp.viewProviders.length, equals(1)); - expect(cmp.viewProviders[0].token.identifier.name, equals("Service")); - expect(cmp.viewProviders[0].token.identifier.moduleUrl, equals("moduleUrl")); - }); - - test('should resolve providers from Provider objects (literals).', () async { - barNgMeta.identifiers['Service'] = - new CompileTypeMetadata(name: 'Service', moduleUrl: 'moduleUrl'); - - fooComponentMeta.template = - new CompileTemplateMetadata(template: "import 'bar.dart';"); - fooComponentMeta.providers = [ - new CompileProviderMetadata( - token: new CompileTokenMetadata(value: "StrService"), - useClass: new CompileTypeMetadata(name: 'Service')) - ]; - fooComponentMeta.type.diDeps = [ - new CompileDiDependencyMetadata(token: new CompileTokenMetadata(value: "StrService")) - ]; - - fooNgMeta.ngDeps.imports - .add(new ImportModel()..uri = 'package:a/bar.dart'); - - updateReader(); - - final extracted = await _testLink(reader, fooAssetId, fooMetaAssetId); - final cmp = extracted.identifiers["FooComponent"]; - - expect(cmp.providers.length, equals(1)); - - expect(cmp.providers[0].token.value, equals("StrService")); - expect(cmp.providers[0].useClass.name, equals("Service")); - expect(cmp.providers[0].useClass.moduleUrl, equals("moduleUrl")); - - expect(cmp.type.diDeps.length, equals(1)); - expect(cmp.type.diDeps[0].token.value, equals("StrService")); - }); - - test('should resolve providers from references', () async { - barNgMeta.identifiers['Service'] = - new CompileTypeMetadata(name: 'Service', moduleUrl: 'moduleUrl'); - - fooNgMeta.identifiers["PROVIDER"] = new CompileIdentifierMetadata( - name: 'PROVIDER', - value: new CompileProviderMetadata( - token: new CompileTokenMetadata(identifier: new CompileIdentifierMetadata(name: 'Service')))); - - fooComponentMeta.providers = [ - new CompileIdentifierMetadata(name: 'PROVIDER') - ]; - fooNgMeta.ngDeps.imports - .add(new ImportModel()..uri = 'package:a/bar.dart'); - - updateReader(); - - final extracted = await _testLink(reader, fooAssetId, fooMetaAssetId); - final cmp = extracted.identifiers["FooComponent"]; - - expect(cmp.providers.length, equals(1)); - expect(cmp.providers[0].token.identifier.name, equals("Service")); - expect(cmp.providers[0].token.identifier.moduleUrl, equals("moduleUrl")); - }); - - test('should resolve providers from lists.', () async { - barNgMeta.identifiers['Service'] = - new CompileTypeMetadata(name: 'Service', moduleUrl: 'moduleUrl'); - - fooNgMeta.identifiers["PROVIDERS"] = new CompileIdentifierMetadata(name: 'PROVIDERS', - value: [ - new CompileIdentifierMetadata(name: "Service") - ]); - - fooComponentMeta.providers = [ - new CompileIdentifierMetadata(name: 'PROVIDERS') - ]; - fooNgMeta.ngDeps.imports - .add(new ImportModel()..uri = 'package:a/bar.dart'); - - updateReader(); - - final extracted = await _testLink(reader, fooAssetId, fooMetaAssetId); - final cmp = extracted.identifiers["FooComponent"]; - - expect(cmp.providers.length, equals(1)); - expect(cmp.providers[0].token.identifier.name, equals("Service")); - expect(cmp.providers[0].token.identifier.moduleUrl, equals("moduleUrl")); - }); - - test('should resolve providers from lists (two lists in the same file).', () async { - barNgMeta.identifiers['Service'] = - new CompileTypeMetadata(name: 'Service', moduleUrl: 'moduleUrl'); - - - fooNgMeta.identifiers["OUTER_PROVIDERS"] = new CompileIdentifierMetadata(name: 'PROVIDERS', - value: [ - new CompileIdentifierMetadata(name: "INNER_PROVIDERS") - ]); - - fooNgMeta.identifiers["INNER_PROVIDERS"] = new CompileIdentifierMetadata(name: 'PROVIDERS', - value: [ - new CompileIdentifierMetadata(name: "Service") - ]); - - fooComponentMeta.providers = [ - new CompileIdentifierMetadata(name: 'OUTER_PROVIDERS') - ]; - fooNgMeta.ngDeps.imports - .add(new ImportModel()..uri = 'package:a/bar.dart'); - - updateReader(); - - final extracted = await _testLink(reader, fooAssetId, fooMetaAssetId); - final cmp = extracted.identifiers["FooComponent"]; - - expect(cmp.providers.length, equals(1)); - expect(cmp.providers[0].token.identifier.name, equals("Service")); - expect(cmp.providers[0].token.identifier.moduleUrl, equals("moduleUrl")); - }); - - test('should resolve providers when there is a level of indirection.', () async { - bazNgMeta.identifiers['Service'] = - new CompileTypeMetadata(name: 'Service', moduleUrl: 'moduleUrl'); - - barNgMeta.identifiers['BAR_PROVIDERS'] = new CompileIdentifierMetadata(name: 'BAR_PROVIDERS', - moduleUrl: 'moduleUrl', - value: [ - new CompileIdentifierMetadata(name: "Service") - ]); - barNgMeta.ngDeps.imports - .add(new ImportModel()..uri = 'package:a/baz.dart'); - - - fooNgMeta.identifiers["PROVIDERS"] = new CompileIdentifierMetadata(name: 'PROVIDERS', moduleUrl: 'moduleUrl', - value: new CompileIdentifierMetadata(name: 'BAR_PROVIDERS')); - fooNgMeta.ngDeps.imports - .add(new ImportModel()..uri = 'package:a/bar.dart'); - fooComponentMeta.providers = [new CompileIdentifierMetadata(name: 'PROVIDERS')]; - - reader.clear(); - reader - ..addAsset(fooAssetId, JSON.encode(fooNgMeta.toJson())) - ..addAsset(barAssetId, JSON.encode(barNgMeta.toJson())) - ..addAsset(bazAssetId, JSON.encode(bazNgMeta.toJson())); - - final extracted = await _testLink(reader, fooAssetId, fooMetaAssetId); - final cmp = extracted.identifiers["FooComponent"]; - - expect(cmp.providers.length, equals(1)); - expect(cmp.providers[0].token.identifier.name, equals("Service")); - expect(cmp.providers[0].token.identifier.moduleUrl, equals("moduleUrl")); - }); - - test('should generate generate diDeps of injectable services.', () async { - fooNgMeta.identifiers['Service2'] = - new CompileTypeMetadata(name: 'Service2', moduleUrl: 'moduleUrl'); - - fooNgMeta.identifiers['Service'] = new CompileTypeMetadata( - name: 'Service', - moduleUrl: 'moduleUrl', - diDeps: [ - new CompileDiDependencyMetadata( - token: new CompileTokenMetadata(identifier: new CompileIdentifierMetadata(name: 'Service2'))) - ]); - - fooComponentMeta.providers = [ - new CompileProviderMetadata( - token: new CompileTokenMetadata(identifier: new CompileIdentifierMetadata(name: 'Service')), - useClass: new CompileTypeMetadata(name: 'Service')) - ]; - - updateReader(); - - final extracted = await _testLink(reader, fooAssetId, fooMetaAssetId); - final cmp = extracted.identifiers["FooComponent"]; - - expect(cmp.providers.length, equals(1)); - - expect(cmp.providers[0].useClass.name, equals("Service")); - expect(cmp.providers[0].useClass.moduleUrl, equals("moduleUrl")); - expect(cmp.providers[0].useClass.diDeps.first.token.identifier.name, equals("Service2")); - expect(cmp.providers[0].useClass.diDeps.first.token.identifier.moduleUrl, equals("moduleUrl")); - }); - - test('should resolve queries and viewQueries.', () async { - barNgMeta.identifiers['Service'] = - new CompileTypeMetadata(name: 'Service', moduleUrl: 'moduleUrl'); - - fooComponentMeta.template = - new CompileTemplateMetadata(template: "import 'bar.dart';"); - fooComponentMeta.type.diDeps = [ - new CompileDiDependencyMetadata( - token: new CompileTokenMetadata(value: 'someToken'), - query: new CompileQueryMetadata( - selectors: [new CompileTokenMetadata(identifier: new CompileIdentifierMetadata(name: 'Service'))])), - new CompileDiDependencyMetadata( - token: new CompileTokenMetadata(value: 'someToken'), - viewQuery: new CompileQueryMetadata( - selectors: [new CompileTokenMetadata(identifier: new CompileIdentifierMetadata(name: 'Service'))])) - ]; - - fooNgMeta.ngDeps.imports - .add(new ImportModel()..uri = 'package:a/bar.dart'); - - updateReader(); - - final extracted = await _testLink(reader, fooAssetId, fooMetaAssetId); - final cmp = extracted.identifiers["FooComponent"]; - - expect(cmp.type.diDeps.length, equals(2)); - - expect(cmp.type.diDeps[0].query.selectors[0].identifier.name, equals("Service")); - expect(cmp.type.diDeps[0].query.selectors[0].identifier.moduleUrl, equals("moduleUrl")); - expect(cmp.type.diDeps[1].viewQuery.selectors[0].identifier.name, equals("Service")); - expect(cmp.type.diDeps[1].viewQuery.selectors[0].identifier.moduleUrl, equals("moduleUrl")); - }); - - test('should generate providers from Provider objects (references).', - () async { - barNgMeta.identifiers['Service1'] = - new CompileTypeMetadata(name: 'Service1', moduleUrl: 'moduleUrl'); - barNgMeta.identifiers['Service2'] = - new CompileTypeMetadata(name: 'Service2', moduleUrl: 'moduleUrl'); - barNgMeta.identifiers['factory'] = - new CompileFactoryMetadata(name: 'factory', moduleUrl: 'moduleUrl', diDeps: [ - new CompileDiDependencyMetadata( - token: new CompileTokenMetadata(identifier: new CompileIdentifierMetadata(name: 'Service2', moduleUrl: 'moduleUrl'))) - ]); - - fooComponentMeta.template = - new CompileTemplateMetadata(template: "import 'bar.dart';"); - fooComponentMeta.providers = [ - new CompileProviderMetadata( - token: new CompileTokenMetadata(identifier: new CompileIdentifierMetadata(name: 'Service1')), - useClass: new CompileTypeMetadata(name: 'Service2')), - new CompileProviderMetadata( - token: new CompileTokenMetadata(identifier: new CompileIdentifierMetadata(name: 'Service1')), - useExisting: new CompileTokenMetadata(identifier: new CompileIdentifierMetadata(name: 'Service2'))), - new CompileProviderMetadata( - token: new CompileTokenMetadata(identifier: new CompileIdentifierMetadata(name: 'Service1')), - useValue: new CompileIdentifierMetadata(name: 'Service2')), - new CompileProviderMetadata( - token: new CompileTokenMetadata(identifier: new CompileIdentifierMetadata(name: 'Service1')), - useFactory: new CompileFactoryMetadata(name: 'factory')) - ]; - - fooNgMeta.ngDeps.imports - .add(new ImportModel()..uri = 'package:a/bar.dart'); - - updateReader(); - - final extracted = await _testLink(reader, fooAssetId, fooMetaAssetId); - final cmp = extracted.identifiers["FooComponent"]; - - expect(cmp.providers.length, equals(4)); - - expect(cmp.providers[0].token.identifier.name, equals("Service1")); - expect(cmp.providers[0].token.identifier.moduleUrl, equals("moduleUrl")); - expect(cmp.providers[0].useClass.name, equals("Service2")); - expect(cmp.providers[0].useClass.moduleUrl, equals("moduleUrl")); - - expect(cmp.providers[1].token.identifier.name, equals("Service1")); - expect(cmp.providers[1].token.identifier.moduleUrl, equals("moduleUrl")); - expect(cmp.providers[1].useExisting.identifier.name, equals("Service2")); - expect(cmp.providers[1].useExisting.identifier.moduleUrl, equals("moduleUrl")); - - expect(cmp.providers[2].token.identifier.name, equals("Service1")); - expect(cmp.providers[2].token.identifier.moduleUrl, equals("moduleUrl")); - expect(cmp.providers[2].useValue.name, equals("Service2")); - expect(cmp.providers[2].useValue.moduleUrl, equals("moduleUrl")); - - expect(cmp.providers[3].token.identifier.name, equals("Service1")); - expect(cmp.providers[3].token.identifier.moduleUrl, equals("moduleUrl")); - expect(cmp.providers[3].useFactory.name, equals("factory")); - expect(cmp.providers[3].useFactory.moduleUrl, equals("moduleUrl")); - }); - - test('should fallback to the list of resolved identifiers.', () async { - fooNgMeta.identifiers['Service2'] = - new CompileTypeMetadata(name: 'Service2', moduleUrl: 'moduleUrl'); - - fooComponentMeta.providers = [ - new CompileProviderMetadata( - token: new CompileTokenMetadata(identifier: new CompileIdentifierMetadata(name: 'Service1')), - useClass: new CompileTypeMetadata(name: 'Service2')) - ]; - - updateReader(); - - final extracted = await _testLink(reader, fooAssetId, fooMetaAssetId, - {"Service1": "someModuleUrl", "Service2": "someModuleUrl"}); - final cmp = extracted.identifiers["FooComponent"]; - - expect(cmp.providers.length, equals(1)); - - expect(cmp.providers[0].token.identifier.name, equals("Service1")); - expect(cmp.providers[0].token.identifier.moduleUrl, equals("someModuleUrl")); - expect(cmp.providers[0].useClass.name, equals("Service2")); - expect(cmp.providers[0].useClass.moduleUrl, equals("moduleUrl")); - }); - - test('should resolve circular references.', () async { - barNgMeta.identifiers['Service1'] = - new CompileTypeMetadata(name: 'Service1', moduleUrl: 'moduleUrl', - diDeps: [new CompileDiDependencyMetadata(token: new CompileTokenMetadata(identifier: new CompileIdentifierMetadata(name: "Service2")))]); - barNgMeta.ngDeps.imports.add(new ImportModel()..uri = 'foo.dart'); - - fooNgMeta.identifiers['Service2'] = - new CompileTypeMetadata(name: 'Service2', moduleUrl: 'moduleUrl', - diDeps: [new CompileDiDependencyMetadata(token: new CompileTokenMetadata(identifier: new CompileIdentifierMetadata(name: "Service1")))]); - fooNgMeta.ngDeps.imports.add(new ImportModel()..uri = 'bar.dart'); - - updateReader(); - - final extracted = await _testLink(reader, fooAssetId, fooMetaAssetId); - final service2 = extracted.identifiers["Service2"]; - - expect(service2.diDeps[0].token.identifier.name, equals("Service1")); - expect(service2.diDeps[0].token.identifier.moduleUrl, equals("moduleUrl")); - }); - - test('should link dependencies (imports and exports first).', () async { - bazNgMeta.identifiers['Service2'] = - new CompileTypeMetadata(name: 'Service2', moduleUrl: 'moduleUrl'); - - barNgMeta.identifiers['Service1'] = new CompileTypeMetadata( - name: 'Service1', - moduleUrl: 'moduleUrl', - diDeps: [ - new CompileDiDependencyMetadata( - token: new CompileTokenMetadata(identifier: new CompileIdentifierMetadata(name: 'Service2'))) - ]); - barNgMeta.ngDeps..imports.add(new ImportModel()..uri = 'baz.dart'); - - fooComponentMeta.providers = [ - new CompileProviderMetadata( - token: new CompileTokenMetadata(identifier: new CompileIdentifierMetadata(name: 'Service1'))) - ]; - fooNgMeta.ngDeps..imports.add(new ImportModel()..uri = 'bar.dart'); - - reader.clear(); - reader - ..addAsset(fooAssetId, JSON.encode(fooNgMeta.toJson())) - ..addAsset(barAssetId, JSON.encode(barNgMeta.toJson())) - ..addAsset(bazAssetId, JSON.encode(bazNgMeta.toJson())); - - final extracted = await _testLink(reader, fooAssetId, fooMetaAssetId); - - final cmp = extracted.identifiers["FooComponent"]; - - expect(cmp.providers.length, equals(1)); - final firstProvider = cmp.providers[0]; - - expect(firstProvider.token.identifier.diDeps[0].token.identifier.name, equals("Service2")); - expect(firstProvider.token.identifier.diDeps[0].token.identifier.moduleUrl, equals("moduleUrl")); - }); - - test('should not resolve when not needed', () async { - fooNgMeta.identifiers['SomeId'] = new CompileIdentifierMetadata(name: 'SomeId'); - fooNgMeta.ngDeps..imports.add(new ImportModel()..uri = 'bar.dart'); - - fooNgMeta.identifiers.clear(); - reader.clear(); - // there is no bar, so it should throw when trying to resolve - reader - ..addAsset(fooAssetId, JSON.encode(fooNgMeta.toJson())) - ..addAsset(barAssetId, "Invalid"); - - await _testLink(reader, fooAssetId, fooMetaAssetId); - }); - }); - - group('NgDeps linker', () { - test('should chain imported dependencies.', () async { - fooNgMeta.ngDeps - ..libraryUri = 'test.foo' - ..imports.add(new ImportModel() - ..uri = 'bar.dart' - ..prefix = 'dep'); - barNgMeta.ngDeps.libraryUri = 'test.bar'; - updateReader(); - - var linked = (await _testLink(reader, fooAssetId, fooMetaAssetId)).ngDeps; - expect(linked, isNotNull); - var linkedImport = linked.depImports - .firstWhere((i) => i.uri.endsWith('bar.ngfactory.dart')); - expect(linkedImport, isNotNull); - expect(linkedImport.prefix.startsWith('i'), isTrue); - }); - - test('should chain exported dependencies.', () async { - fooNgMeta.ngDeps - ..libraryUri = 'test.foo' - ..exports.add(new ExportModel()..uri = 'bar.dart'); - barNgMeta.ngDeps.libraryUri = 'test.bar'; - updateReader(); - - var linked = (await _testLink(reader, fooAssetId, fooMetaAssetId)).ngDeps; - expect(linked, isNotNull); - var linkedImport = linked.depImports - .firstWhere((i) => i.uri.endsWith('bar.ngfactory.dart')); - expect(linkedImport, isNotNull); - expect(linkedImport.prefix.startsWith('i'), isTrue); - }); - - test('should not chain `deferred` libraries.', () async { - fooNgMeta.ngDeps - ..libraryUri = 'test.foo' - ..imports.add(new ImportModel() - ..uri = 'bar.dart' - ..isDeferred = true - ..prefix = 'dep'); - barNgMeta.ngDeps.libraryUri = 'test.bar'; - updateReader(); - - var linked = (await _testLink(reader, fooAssetId, fooMetaAssetId)).ngDeps; - expect(linked, isNotNull); - var linkedImport = linked.depImports.firstWhere( - (i) => i.uri.endsWith('bar.ngfactory.dart'), - orElse: () => null); - expect(linkedImport, isNull); - }); - }); -} - -Future _testLink( - AssetReader reader, AssetId summaryAssetId, AssetId metaAssetId, - [Map resolvedIdentifiers]) { - return zone.exec( - () => linkDirectiveMetadata( - reader, summaryAssetId, metaAssetId, resolvedIdentifiers), - log: new RecordingLogger()); -} diff --git a/modules_dart/transform/test/transform/directive_processor/absolute_url_expression_files/hello.dart b/modules_dart/transform/test/transform/directive_processor/absolute_url_expression_files/hello.dart deleted file mode 100644 index 1369bc34ff..0000000000 --- a/modules_dart/transform/test/transform/directive_processor/absolute_url_expression_files/hello.dart +++ /dev/null @@ -1,13 +0,0 @@ -library playground.src.hello_world.absolute_url_expression_files; - -import 'package:angular2/angular2.dart' - show Component, Directive, View, NgElement; - -@Component(selector: 'hello-app') -@View( - templateUrl: 'package:other_package/template.html', - styleUrls: const ['package:other_package/template.css']) -class HelloCmp {} - -@Injectable() -hello() {} diff --git a/modules_dart/transform/test/transform/directive_processor/absolute_url_expression_files/template.css b/modules_dart/transform/test/transform/directive_processor/absolute_url_expression_files/template.css deleted file mode 100644 index c48477652e..0000000000 --- a/modules_dart/transform/test/transform/directive_processor/absolute_url_expression_files/template.css +++ /dev/null @@ -1 +0,0 @@ -.greeting { .color: blue; } \ No newline at end of file diff --git a/modules_dart/transform/test/transform/directive_processor/absolute_url_expression_files/template.html b/modules_dart/transform/test/transform/directive_processor/absolute_url_expression_files/template.html deleted file mode 100644 index d75013393f..0000000000 --- a/modules_dart/transform/test/transform/directive_processor/absolute_url_expression_files/template.html +++ /dev/null @@ -1 +0,0 @@ -{{greeting}} \ No newline at end of file diff --git a/modules_dart/transform/test/transform/directive_processor/abstract_classes/classes.dart b/modules_dart/transform/test/transform/directive_processor/abstract_classes/classes.dart deleted file mode 100644 index 67fdf8ecaf..0000000000 --- a/modules_dart/transform/test/transform/directive_processor/abstract_classes/classes.dart +++ /dev/null @@ -1,10 +0,0 @@ -library angular2.test.transform.directive_processor.abstract_classes.classes; - -import 'package:angular2/angular2.dart' show Injectable; - -@Injectable() -abstract class Service { - factory Service() { - return null; - } -} diff --git a/modules_dart/transform/test/transform/directive_processor/all_tests.dart b/modules_dart/transform/test/transform/directive_processor/all_tests.dart deleted file mode 100644 index 76337af479..0000000000 --- a/modules_dart/transform/test/transform/directive_processor/all_tests.dart +++ /dev/null @@ -1,1104 +0,0 @@ -library angular2.test.transform.directive_processor.all_tests; - -import 'dart:async'; - -import 'package:barback/barback.dart'; -import 'package:dart_style/dart_style.dart'; -import 'package:test/test.dart'; - -import 'package:angular2/src/compiler/compile_metadata.dart' - show CompileIdentifierMetadata, CompileProviderMetadata, CompileTypeMetadata, CompileTokenMetadata; -import 'package:angular2/src/core/change_detection/change_detection.dart'; -import 'package:angular2/src/platform/server/html_adapter.dart'; -import 'package:angular2/src/core/metadata/lifecycle_hooks.dart' show LifecycleHooks; -import 'package:angular2/src/transform/common/annotation_matcher.dart'; -import 'package:angular2/src/transform/common/asset_reader.dart'; -import 'package:angular2/src/transform/common/code/ng_deps_code.dart'; -import 'package:angular2/src/transform/common/model/ng_deps_model.pb.dart'; -import 'package:angular2/src/transform/common/model/reflection_info_model.pb.dart'; -import 'package:angular2/src/transform/common/ng_meta.dart'; -import 'package:angular2/src/transform/common/zone.dart' as zone; -import 'package:angular2/src/transform/directive_processor/rewriter.dart'; - -import '../common/read_file.dart'; -import '../common/recording_logger.dart'; - -var formatter = new DartFormatter(); - -main() { - Html5LibDomAdapter.makeCurrent(); - allTests(); -} - -var oldTest = test; -void allTests() { - var test = (name, fn) { -// if (name.contains('CompileFactoryMetadata')) { - oldTest(name, fn); -// } - }; - - test('should preserve parameter annotations.', () async { - var model = (await _testCreateModel('parameter_metadata/soup.dart')).ngDeps; - expect(model.reflectables.length, equals(1)); - var reflectable = model.reflectables.first; - expect(reflectable.parameters.length, equals(2)); - - expect(reflectable.parameters.first.typeName, equals('String')); - expect(reflectable.parameters.first.metadata.length, equals(1)); - expect(reflectable.parameters.first.metadata.first, contains('Tasty')); - expect(reflectable.parameters.first.paramName, equals('description')); - - var typeName = reflectable.parameters[1].typeName; - expect(typeName == null || typeName.isEmpty, isTrue); - var secondParam = reflectable.parameters[1]; - expect(secondParam.metadata.first, contains('Inject(Salt)')); - expect(secondParam.paramName, equals('salt')); - }); - - group('part support', () { - var modelFuture = _testCreateModel('part_files/main.dart') - .then((ngMeta) => ngMeta != null ? ngMeta.ngDeps : null); - - test('should include directives from the part.', () async { - var model = await modelFuture; - expect(model.reflectables.length, equals(2)); - }); - - test('should list part contributions first.', () async { - var model = await modelFuture; - expect(model.reflectables.first.name, equals('PartComponent')); - }); - - test('should list main contributions second.', () async { - var model = await modelFuture; - expect(model.reflectables[1].name, equals('MainComponent')); - }); - - test('should handle multiple `part` directives.', () async { - var model = - (await _testCreateModel('multiple_part_files/main.dart')).ngDeps; - expect(model.reflectables.length, equals(3)); - }); - - test('should not generate anything for `part` files.', () async { - expect(await _testCreateModel('part_files/part.dart'), isNull); - }); - }); - - group('custom annotations', () { - test('should be recognized from package: imports', () async { - var ngMeta = await _testCreateModel('custom_metadata/package_soup.dart', - customDescriptors: [ - const ClassDescriptor('Soup', 'package:soup/soup.dart', - superClass: 'Component') - ]); - var model = ngMeta.ngDeps; - expect(model.reflectables.length, equals(1)); - expect(model.reflectables.first.name, equals('PackageSoup')); - }); - - test('should be recognized from relative imports', () async { - var ngMeta = await _testCreateModel('custom_metadata/relative_soup.dart', - assetId: new AssetId('soup', 'lib/relative_soup.dart'), - customDescriptors: [ - const ClassDescriptor('Soup', 'package:soup/annotations/soup.dart', - superClass: 'Component') - ]); - var model = ngMeta.ngDeps; - expect(model.reflectables.length, equals(1)); - expect(model.reflectables.first.name, equals('RelativeSoup')); - }); - - test('should ignore annotations that are not imported', () async { - var ngMeta = await _testCreateModel('custom_metadata/bad_soup.dart', - customDescriptors: [ - const ClassDescriptor('Soup', 'package:soup/soup.dart', - superClass: 'Component') - ]); - expect( - ngMeta.ngDeps == null || ngMeta.ngDeps.reflectables.isEmpty, isTrue); - }); - }); - - group('interfaces', () { - test('should include implemented types', () async { - var model = (await _testCreateModel('interfaces_files/soup.dart')).ngDeps; - - expect(model.reflectables.first.interfaces, isNotNull); - expect(model.reflectables.first.interfaces.isNotEmpty, isTrue); - expect(model.reflectables.first.interfaces.contains('OnChanges'), isTrue); - expect(model.reflectables.first.interfaces.contains('AnotherInterface'), - isTrue); - }); - - test('should not include transitively implemented types', () async { - var model = - (await _testCreateModel('interface_chain_files/soup.dart')).ngDeps; - - expect(model.reflectables.first.interfaces, isNotNull); - expect(model.reflectables.first.interfaces.isNotEmpty, isTrue); - expect(model.reflectables.first.interfaces.contains('PrimaryInterface'), - isTrue); - expect(model.reflectables.first.interfaces.contains('SecondaryInterface'), - isFalse); - expect(model.reflectables.first.interfaces.contains('TernaryInterface'), - isFalse); - }); - - test('should not include superclasses.', () async { - var model = (await _testCreateModel('superclass_files/soup.dart')).ngDeps; - - var interfaces = model.reflectables.first.interfaces; - expect(interfaces == null || interfaces.isEmpty, isTrue); - }); - - test('should populate multiple `lifecycle` values when necessary.', - () async { - var model = (await _testCreateModel( - 'multiple_interface_lifecycle_files/soup.dart')) - .ngDeps; - - expect(model.reflectables.first.interfaces, isNotNull); - expect(model.reflectables.first.interfaces.isNotEmpty, isTrue); - expect(model.reflectables.first.interfaces.contains('OnChanges'), isTrue); - expect(model.reflectables.first.interfaces.contains('OnDestroy'), isTrue); - expect(model.reflectables.first.interfaces.contains('OnInit'), isTrue); - }); - - test( - 'should not populate `lifecycle` when lifecycle superclass is present.', - () async { - var model = - (await _testCreateModel('superclass_lifecycle_files/soup.dart')) - .ngDeps; - - var interfaces = model.reflectables.first.interfaces; - expect(interfaces == null || interfaces.isEmpty, isTrue); - }); - - test('should populate `lifecycle` with prefix when necessary.', () async { - var model = (await _testCreateModel( - 'prefixed_interface_lifecycle_files/soup.dart')) - .ngDeps; - expect(model.reflectables.first.interfaces, isNotNull); - expect(model.reflectables.first.interfaces.isNotEmpty, isTrue); - expect( - model.reflectables.first.interfaces - .firstWhere((i) => i.contains('OnChanges'), orElse: () => null), - isNotNull); - }); - }); - - test('should record information about abstract classes', () async { - var model = - (await _testCreateModel('abstract_classes/classes.dart')).ngDeps; - - expect(model.reflectables.first.name, equals("Service")); - }); - - test('should not throw/hang on invalid urls', () async { - var logger = new RecordingLogger(); - await _testCreateModel('invalid_url_files/hello.dart', logger: logger); - expect(logger.hasErrors, isTrue); - expect( - logger.logs, - contains('ERROR: ERROR: Invalid argument (url): ' - '"Could not read asset at uri asset:/bad/absolute/url.html"')); - }); - - test('should find and register static functions.', () async { - var model = - (await _testCreateModel('static_function_files/hello.dart')).ngDeps; - - var functionReflectable = - model.reflectables.firstWhere((i) => i.isFunction, orElse: () => null); - expect(functionReflectable, isNotNull); - expect(functionReflectable.name, equals('getMessage')); - }); - - group('NgMeta', () { - var fakeReader; - setUp(() { - fakeReader = new TestAssetReader(); - }); - - test('should find direcive aliases patterns.', () async { - var ngMeta = await _testCreateModel('directive_aliases_files/hello.dart'); - - expect(ngMeta.aliases, contains('alias1')); - expect(ngMeta.aliases['alias1'], contains('HelloCmp')); - - expect(ngMeta.aliases, contains('alias2')); - expect(ngMeta.aliases['alias2'], contains('HelloCmp')); - expect(ngMeta.aliases['alias2'], contains('Foo')); - }); - - test('should include hooks for implemented types (single)', () async { - var ngMeta = await _testCreateModel('interfaces_files/soup.dart'); - - expect(ngMeta.identifiers.isNotEmpty, isTrue); - expect(ngMeta.identifiers['ChangingSoupComponent'], isNotNull); - expect(ngMeta.identifiers['ChangingSoupComponent'].selector, - equals('[soup]')); - expect(ngMeta.identifiers['ChangingSoupComponent'].lifecycleHooks, - contains(LifecycleHooks.OnChanges)); - }); - - test('should include hooks for implemented types (many)', () async { - var ngMeta = await _testCreateModel( - 'multiple_interface_lifecycle_files/soup.dart'); - - expect(ngMeta.identifiers.isNotEmpty, isTrue); - expect(ngMeta.identifiers['MultiSoupComponent'], isNotNull); - expect( - ngMeta.identifiers['MultiSoupComponent'].selector, equals('[soup]')); - final hooks = ngMeta.identifiers['MultiSoupComponent'].lifecycleHooks; - expect(hooks, contains(LifecycleHooks.OnChanges)); - expect(hooks, contains(LifecycleHooks.OnDestroy)); - expect(hooks, contains(LifecycleHooks.OnInit)); - }); - - test('should create type entries for Directives', () async { - fakeReader - ..addAsset(new AssetId('other_package', 'lib/template.html'), '') - ..addAsset(new AssetId('other_package', 'lib/template.css'), ''); - var ngMeta = await _testCreateModel( - 'absolute_url_expression_files/hello.dart', - reader: fakeReader); - - expect(ngMeta.identifiers.isNotEmpty, isTrue); - expect(ngMeta.identifiers['HelloCmp'], isNotNull); - expect(ngMeta.identifiers['HelloCmp'].selector, equals('hello-app')); - }); - - test('should populate all provided values for Components & Directives', - () async { - var ngMeta = await _testCreateModel('unusual_component_files/hello.dart'); - - expect(ngMeta.identifiers.isNotEmpty, isTrue); - - var component = ngMeta.identifiers['UnusualComp']; - expect(component, isNotNull); - expect(component.selector, equals('unusual-comp')); - expect(component.isComponent, isTrue); - expect(component.exportAs, equals('ComponentExportAsValue')); - expect(component.changeDetection, - equals(ChangeDetectionStrategy.CheckAlways)); - expect(component.inputs, contains('aProperty')); - expect(component.inputs['aProperty'], equals('aProperty')); - expect(component.outputs, contains('anEvent')); - expect(component.outputs['anEvent'], equals('anEvent')); - expect(component.hostAttributes, contains('hostKey')); - expect(component.hostAttributes['hostKey'], equals('hostValue')); - - var directive = ngMeta.identifiers['UnusualDirective']; - expect(directive, isNotNull); - expect(directive.selector, equals('unusual-directive')); - expect(directive.isComponent, isFalse); - expect(directive.exportAs, equals('DirectiveExportAsValue')); - expect(directive.inputs, contains('aDirectiveProperty')); - expect( - directive.inputs['aDirectiveProperty'], equals('aDirectiveProperty')); - expect(directive.outputs, contains('aDirectiveEvent')); - expect(directive.outputs['aDirectiveEvent'], equals('aDirectiveEvent')); - expect(directive.hostAttributes, contains('directiveHostKey')); - expect(directive.hostAttributes['directiveHostKey'], - equals('directiveHostValue')); - }); - - test('should include hooks for implemented types (single)', () async { - var ngMeta = await _testCreateModel('interfaces_files/soup.dart'); - - expect(ngMeta.identifiers.isNotEmpty, isTrue); - expect(ngMeta.identifiers['ChangingSoupComponent'], isNotNull); - expect(ngMeta.identifiers['ChangingSoupComponent'].selector, - equals('[soup]')); - expect(ngMeta.identifiers['ChangingSoupComponent'].lifecycleHooks, - contains(LifecycleHooks.OnChanges)); - }); - - test('should include hooks for implemented types (many)', () async { - var ngMeta = await _testCreateModel( - 'multiple_interface_lifecycle_files/soup.dart'); - - expect(ngMeta.identifiers.isNotEmpty, isTrue); - expect(ngMeta.identifiers['MultiSoupComponent'], isNotNull); - expect( - - ngMeta.identifiers['MultiSoupComponent'].selector, equals('[soup]')); - final hooks = ngMeta.identifiers['MultiSoupComponent'].lifecycleHooks; - expect(hooks, contains(LifecycleHooks.OnChanges)); - expect(hooks, contains(LifecycleHooks.OnDestroy)); - expect(hooks, contains(LifecycleHooks.OnInit)); - }); - - test('should parse templates from View annotations', () async { - fakeReader - ..addAsset(new AssetId('other_package', 'lib/template.html'), '') - ..addAsset(new AssetId('other_package', 'lib/template.css'), ''); - var ngMeta = await _testCreateModel( - 'absolute_url_expression_files/hello.dart', - reader: fakeReader); - - expect(ngMeta.identifiers.isNotEmpty, isTrue); - expect(ngMeta.identifiers['HelloCmp'], isNotNull); - expect(ngMeta.identifiers['HelloCmp'].template, isNotNull); - expect(ngMeta.identifiers['HelloCmp'].template.templateUrl, - equals('asset:other_package/lib/template.html')); - }); - - test('should handle prefixed annotations', () async { - var ngMeta = - (await _testCreateModel('prefixed_annotations_files/soup.dart')); - expect(ngMeta.identifiers.isNotEmpty, isTrue); - expect(ngMeta.identifiers['SoupComponent'], isNotNull); - expect( - ngMeta.identifiers['SoupComponent'].selector, equals('[soup]')); - expect( - ngMeta.identifiers['SoupComponent'].template.template, equals('SoupView')); - }); - }); - - group("identifiers", () { - test("should populate `identifier` with CompileTypeMetadata.", () async { - var model = (await _testCreateModel('identifiers/classes.dart')); - final moduleUrl = - "asset:angular2/test/transform/directive_processor/identifiers/classes.dart"; - expect(model.identifiers['Service1'].name, equals('Service1')); - expect(model.identifiers['Service1'].moduleUrl, equals(moduleUrl)); - expect(model.identifiers['Service2'].name, equals('Service2')); - expect(model.identifiers['Service2'].moduleUrl, equals(moduleUrl)); - - expect(model.identifiers['Service2'].diDeps.length, equals(1)); - expect(model.identifiers['Service2'].diDeps[0].token.name, equals('Service1')); - }); - - test("should populate `identifier` with CompileFactoryMetadata.", () async { - var model = (await _testCreateModel('identifiers/factories' - '.dart')); - final moduleUrl = - "asset:angular2/test/transform/directive_processor/identifiers/factories.dart"; - - expect(model.identifiers['factory1'].name, equals('factory1')); - expect(model.identifiers['factory1'].moduleUrl, equals(moduleUrl)); - expect(model.identifiers['factory2'].name, equals('factory2')); - expect(model.identifiers['factory2'].moduleUrl, equals(moduleUrl)); - - expect(model.identifiers['factory2'].diDeps.length, equals(1)); - expect(model.identifiers['factory2'].diDeps[0].token.name, equals('SomeClass')); - }); - - test("should populate `identifier` with constants.", () async { - var model = (await _testCreateModel('identifiers/constants.dart')); - final moduleUrl = - "asset:angular2/test/transform/directive_processor/identifiers/constants.dart"; - expect( - model.identifiers['a'].toJson(), - equals(new CompileIdentifierMetadata(name: 'a', moduleUrl: moduleUrl) - .toJson())); - expect( - model.identifiers['b'].toJson(), - equals(new CompileIdentifierMetadata(name: 'b', moduleUrl: moduleUrl) - .toJson())); - expect(model.identifiers['c'], isNull); - }); - - test("should populate `identifier` with provider constants.", () async { - var model = - (await _testCreateModel('identifiers/provider_constants.dart')); - expect( - model.identifiers['a'].value.toJson(), - equals(new CompileProviderMetadata( - token: new CompileTokenMetadata(value: 'someToken'), - useClass: new CompileTypeMetadata(name: 'SomeClass')) - .toJson())); - }); - - test("should populate `identifier` with lists of providers.", () async { - var model = - (await _testCreateModel('identifiers/provider_constants.dart')); - - final List list = model.identifiers['b'].value; - - expect(list.length, equals(3)); - expect(list[0].name, equals("SomeClass")); - expect(list[1].name, equals("a")); - expect(list[2].toJson(), equals(new CompileProviderMetadata( - token: new CompileTokenMetadata(value: 'someOtherToken'), - useClass: new CompileTypeMetadata(name: 'SomeClass')) - .toJson())); - }); - - test( - "should populate `identifier` with class names that do not have @Injectable;'.", - () async { - var model = - (await _testCreateModel('identifiers/classes_no_injectable.dart')); - final moduleUrl = - "asset:angular2/test/transform/directive_processor/identifiers/classes_no_injectable.dart"; - expect( - model.identifiers['ClassA'].toJson(), - equals(new CompileIdentifierMetadata( - name: 'ClassA', moduleUrl: moduleUrl) - .toJson())); - }); - - test("should populate `identifier` with typedefs.", () async { - var model = (await _testCreateModel('identifiers/typedefs.dart')); - final moduleUrl = - "asset:angular2/test/transform/directive_processor/identifiers/typedefs.dart"; - expect( - model.identifiers['TypeDef'].toJson(), - equals(new CompileIdentifierMetadata( - name: 'TypeDef', moduleUrl: moduleUrl) - .toJson())); - }); - - test("should populate `identifier` with enums.", () async { - var model = (await _testCreateModel('identifiers/enums.dart')); - final moduleUrl = - "asset:angular2/test/transform/directive_processor/identifiers/enums.dart"; - - expect( - model.identifiers['Enum'].toJson(), - equals( - new CompileIdentifierMetadata(name: 'Enum', moduleUrl: moduleUrl) - .toJson())); - }); - }); - - group('directives', () { - final reflectableNamed = (NgDepsModel model, String name) { - return model.reflectables - .firstWhere((r) => r.name == name, orElse: () => null); - }; - - test('should populate `directives` from @View value specified second.', - () async { - var model = - (await _testCreateModel('directives_files/components.dart')).ngDeps; - final componentFirst = reflectableNamed(model, 'ComponentFirst'); - expect(componentFirst, isNotNull); - expect(componentFirst.directives, isNotNull); - expect(componentFirst.directives.length, equals(2)); - expect(componentFirst.directives.first, - equals(new PrefixedType()..name = 'Dep')); - expect( - componentFirst.directives[1], - equals(new PrefixedType() - ..name = 'Dep' - ..prefix = 'dep2')); - }); - - test('should populate `directives` from @View value specified first.', - () async { - var model = - (await _testCreateModel('directives_files/components.dart')).ngDeps; - final viewFirst = reflectableNamed(model, 'ViewFirst'); - expect(viewFirst, isNotNull); - expect(viewFirst.directives, isNotNull); - expect(viewFirst.directives.length, equals(2)); - expect( - viewFirst.directives.first, - equals(new PrefixedType() - ..name = 'Dep' - ..prefix = 'dep2')); - expect(viewFirst.directives[1], equals(new PrefixedType()..name = 'Dep')); - }); - - test('should populate `directives` from @Component value with no @View.', - () async { - var model = - (await _testCreateModel('directives_files/components.dart')).ngDeps; - final componentOnly = reflectableNamed(model, 'ComponentOnly'); - expect(componentOnly, isNotNull); - expect(componentOnly.directives, isNotNull); - expect(componentOnly.directives.length, equals(2)); - expect(componentOnly.directives.first, - equals(new PrefixedType()..name = 'Dep')); - expect( - componentOnly.directives[1], - equals(new PrefixedType() - ..name = 'Dep' - ..prefix = 'dep2')); - }); - - test('should populate `pipes` from @View value specified second.', - () async { - var model = - (await _testCreateModel('directives_files/components.dart')).ngDeps; - final componentFirst = reflectableNamed(model, 'ComponentFirst'); - expect(componentFirst, isNotNull); - expect(componentFirst.pipes, isNotNull); - expect(componentFirst.pipes.length, equals(2)); - expect(componentFirst.pipes.first, - equals(new PrefixedType()..name = 'PipeDep')); - expect( - componentFirst.pipes[1], - equals(new PrefixedType() - ..name = 'PipeDep' - ..prefix = 'dep2')); - }); - - test('should populate `pipes` from @View value specified first.', () async { - var model = - (await _testCreateModel('directives_files/components.dart')).ngDeps; - final viewFirst = reflectableNamed(model, 'ViewFirst'); - expect(viewFirst, isNotNull); - expect(viewFirst.pipes, isNotNull); - expect(viewFirst.pipes.length, equals(2)); - expect( - viewFirst.pipes.first, - equals(new PrefixedType() - ..name = 'PipeDep' - ..prefix = 'dep2')); - expect(viewFirst.pipes[1], equals(new PrefixedType()..name = 'PipeDep')); - }); - - test('should populate `pipes` from @Component value with no @View.', - () async { - var model = - (await _testCreateModel('directives_files/components.dart')).ngDeps; - final componentOnly = reflectableNamed(model, 'ComponentOnly'); - expect(componentOnly, isNotNull); - expect(componentOnly.pipes, isNotNull); - expect(componentOnly.pipes.length, equals(2)); - expect(componentOnly.pipes.first, - equals(new PrefixedType()..name = 'PipeDep')); - expect( - componentOnly.pipes[1], - equals(new PrefixedType() - ..name = 'PipeDep' - ..prefix = 'dep2')); - }); - - test('should populate `diDependency`.', () async { - var cmp = (await _testCreateModel('directives_files/components.dart')) - .identifiers['ComponentWithDiDeps']; - - expect(cmp, isNotNull); - var deps = cmp.type.diDeps; - expect(deps, isNotNull); - expect(deps.length, equals(13)); - expect(deps[0].token.identifier.name, equals("ServiceDep")); - expect(deps[1].token.identifier.name, equals("ServiceDep")); - expect(deps[2].token.value, "one"); - expect(deps[2].isAttribute, isTrue); - expect(deps[3].isSelf, isTrue); - expect(deps[4].isSkipSelf, isTrue); - expect(deps[5].isOptional, isTrue); - expect(deps[6].query.selectors[0].name, equals("ServiceDep")); - expect(deps[6].query.descendants, isTrue); - expect(deps[6].query.read.identifier.name, equals("ServiceDep")); - expect(deps[7].query.selectors[0].identifier.name, equals("ServiceDep")); - expect(deps[7].query.descendants, isTrue); - expect(deps[8].viewQuery.selectors[0].value, equals("one")); - expect(deps[8].viewQuery.selectors[1].value, equals("two")); - expect(deps[8].viewQuery.read.value, equals("three")); - expect(deps[9].viewQuery.selectors[0].value, equals("one")); - expect(deps[9].viewQuery.selectors[1].value, equals("two")); - expect(deps[10].token.identifier.name, equals("ServiceDep")); - expect(deps[11].token.identifier.name, equals("ServiceDep")); - expect(deps[12].token.identifier.name, equals("ServiceDep")); - }); - - test('should populate `diDependency` using a string token.', - () async { - var cmp = - (await _testCreateModel('directives_files/components.dart')).identifiers['ComponentWithDiDepsStrToken']; - - var deps = cmp.type.diDeps; - expect(deps, isNotNull); - expect(deps.length, equals(1)); - expect(deps[0].token.value, equals("StringDep")); - }); - - test('should populate `services`.', () async { - var service = (await _testCreateModel('directives_files/services.dart')) - .identifiers['Service']; - - expect(service, isNotNull); - - var deps = service.diDeps; - expect(deps, isNotNull); - expect(deps.length, equals(2)); - expect(deps[0].token.identifier.name, equals("ServiceDep")); - expect(deps[1].token.identifier.name, equals("ServiceDep")); - }); - - test('should populate `providers` using types.', () async { - var cmp = (await _testCreateModel('directives_files/components.dart')) - .identifiers['ComponentWithProvidersTypes']; - - expect(cmp, isNotNull); - expect(cmp.providers, isNotNull); - expect(cmp.providers.length, equals(2)); - - var firstToken = cmp.providers.first; - expect(firstToken.identifier.prefix, isNull); - expect(firstToken.identifier.name, equals("ServiceDep")); - - var secondToken = cmp.providers[1]; - expect(secondToken.identifier.prefix, equals("dep2")); - expect(secondToken.identifier.name, equals("ServiceDep")); - }); - - test('should populate `viewProviders` using types.', () async { - var cmp = (await _testCreateModel('directives_files/components.dart')) - .identifiers['ComponentWithViewProvidersTypes']; - - expect(cmp, isNotNull); - expect(cmp.viewProviders, isNotNull); - expect(cmp.viewProviders.length, equals(1)); - - var firstToken = cmp.viewProviders.first; - expect(firstToken.prefix, isNull); - expect(firstToken.name, equals("ServiceDep")); - }); - - test('should populate `bindings` using types.', () async { - var cmp = (await _testCreateModel('directives_files/components.dart')) - .identifiers['ComponentWithBindingsTypes']; - - expect(cmp, isNotNull); - expect(cmp.providers, isNotNull); - expect(cmp.providers.length, equals(1)); - - var firstToken = cmp.providers.first; - expect(firstToken.prefix, isNull); - expect(firstToken.name, equals("ServiceDep")); - }); - - test('should populate `viewBindings` using types.', () async { - var cmp = (await _testCreateModel('directives_files/components.dart')) - .identifiers['ComponentWithViewBindingsTypes']; - - expect(cmp, isNotNull); - expect(cmp.viewProviders, isNotNull); - expect(cmp.viewProviders.length, equals(1)); - - var firstToken = cmp.viewProviders.first; - expect(firstToken.prefix, isNull); - expect(firstToken.name, equals("ServiceDep")); - }); - - test('should populate `providers` using useClass.', () async { - var cmp = (await _testCreateModel('directives_files/components.dart')) - .identifiers['ComponentWithProvidersUseClass']; - - expect(cmp, isNotNull); - expect(cmp.providers, isNotNull); - expect(cmp.providers.length, equals(1)); - - var token = cmp.providers.first.token; - var useClass = cmp.providers.first.useClass; - expect(token.identifier.prefix, isNull); - expect(token.identifier.name, equals("ServiceDep")); - - expect(useClass.prefix, isNull); - expect(useClass.name, equals("ServiceDep")); - }); - - test('should populate `providers` using a string token.', () async { - var cmp = (await _testCreateModel('directives_files/components.dart')) - .identifiers['ComponentWithProvidersStringToken']; - - expect(cmp, isNotNull); - expect(cmp.providers, isNotNull); - expect(cmp.providers.length, equals(1)); - - var token = cmp.providers.first.token; - expect(token.value, equals("StringDep")); - }); - - test('should populate `providers` using toClass.', () async { - var cmp = (await _testCreateModel('directives_files/components.dart')) - .identifiers['ComponentWithProvidersToClass']; - - expect(cmp, isNotNull); - expect(cmp.providers, isNotNull); - expect(cmp.providers.length, equals(1)); - - var token = cmp.providers.first.token; - var useExisting = cmp.providers.first.useClass; - - expect(useExisting.prefix, isNull); - expect(useExisting.name, equals("ServiceDep")); - }); - - test('should populate `providers` using useExisting.', () async { - var cmp = (await _testCreateModel('directives_files/components.dart')) - .identifiers['ComponentWithProvidersUseExisting']; - - expect(cmp, isNotNull); - expect(cmp.providers, isNotNull); - expect(cmp.providers.length, equals(1)); - - var token = cmp.providers.first.token; - var useExisting = cmp.providers.first.useExisting; - - expect(useExisting.identifier.prefix, isNull); - expect(useExisting.name, equals("ServiceDep")); - }); - - test('should populate `providers` using toAlias.', () async { - var cmp = (await _testCreateModel('directives_files/components.dart')) - .identifiers['ComponentWithProvidersToAlias']; - - expect(cmp, isNotNull); - expect(cmp.providers, isNotNull); - expect(cmp.providers.length, equals(1)); - - var token = cmp.providers.first.token; - var useExisting = cmp.providers.first.useExisting; - - expect(useExisting.identifier.prefix, isNull); - expect(useExisting.identifier.name, equals("ServiceDep")); - }); - - test('should populate `providers` using useExisting (string token).', - () async { - var cmp = (await _testCreateModel('directives_files/components.dart')) - .identifiers['ComponentWithProvidersUseExistingStr']; - - expect(cmp, isNotNull); - expect(cmp.providers, isNotNull); - expect(cmp.providers.length, equals(1)); - - var token = cmp.providers.first.token; - var useExisting = cmp.providers.first.useExisting; - - expect(useExisting.value, equals("StrToken")); - }); - - test('should populate `providers` using useValue.', () async { - var cmp = (await _testCreateModel('directives_files/components.dart')) - .identifiers['ComponentWithProvidersUseValue']; - - expect(cmp, isNotNull); - expect(cmp.providers, isNotNull); - expect(cmp.providers.length, equals(1)); - - var token = cmp.providers.first.token; - var useValue = cmp.providers.first.useValue; - - expect(useValue.prefix, isNull); - expect(useValue.name, equals("ServiceDep")); - }); - - test('should populate `providers` using toValue.', () async { - var cmp = (await _testCreateModel('directives_files/components.dart')) - .identifiers['ComponentWithProvidersToValue']; - - expect(cmp, isNotNull); - expect(cmp.providers, isNotNull); - expect(cmp.providers.length, equals(1)); - - var token = cmp.providers.first.token; - var useValue = cmp.providers.first.useValue; - - expect(useValue.prefix, isNull); - expect(useValue.name, equals("ServiceDep")); - }); - - test('should populate `providers` using useValue (string token).', - () async { - var cmp = (await _testCreateModel('directives_files/components.dart')) - .identifiers['ComponentWithProvidersUseValueStr']; - - expect(cmp, isNotNull); - expect(cmp.providers, isNotNull); - expect(cmp.providers.length, equals(1)); - - var token = cmp.providers.first.token; - var useValue = cmp.providers.first.useValue; - - expect(useValue, equals("StrToken")); - }); - - test('should populate `providers` using useValue (num token).', () async { - var cmp = (await _testCreateModel('directives_files/components.dart')) - .identifiers['ComponentWithProvidersUseValueNum']; - - expect(cmp, isNotNull); - expect(cmp.providers, isNotNull); - expect(cmp.providers.length, equals(1)); - - var token = cmp.providers.first.token; - var useValue = cmp.providers.first.useValue; - - expect(useValue, equals(42)); - }); - - test('should populate `providers` using useValue (bool token).', () async { - var cmp = (await _testCreateModel('directives_files/components.dart')) - .identifiers['ComponentWithProvidersUseValueBool']; - - expect(cmp, isNotNull); - expect(cmp.providers, isNotNull); - expect(cmp.providers.length, equals(1)); - - var token = cmp.providers.first.token; - var useValue = cmp.providers.first.useValue; - - expect(useValue, equals(true)); - }); - - test('should populate `providers` using useValue (null token).', () async { - var cmp = (await _testCreateModel('directives_files/components.dart')) - .identifiers['ComponentWithProvidersUseValueNull']; - - expect(cmp, isNotNull); - expect(cmp.providers, isNotNull); - expect(cmp.providers.length, equals(1)); - - var token = cmp.providers.first.token; - var useValue = cmp.providers.first.useValue; - - expect(useValue, isNull); - }); - - test('should populate `providers` using useFactory.', () async { - var cmp = (await _testCreateModel('directives_files/components.dart')) - .identifiers['ComponentWithProvidersUseFactory']; - - expect(cmp, isNotNull); - expect(cmp.providers, isNotNull); - expect(cmp.providers.length, equals(1)); - - var useFactory = cmp.providers.first.useFactory; - var deps = cmp.providers.first.deps; - - expect(useFactory.prefix, isNull); - expect(useFactory.name, equals("funcDep")); - - expect(deps[0].token.identifier.name, equals("ServiceDep")); - expect(deps[1].token.value, equals("Str")); - expect(deps[2].token.identifier.name, equals("ServiceDep")); - expect(deps[3].token.identifier.name, equals("ServiceDep")); - expect(deps[3].isSelf, equals(true)); - expect(deps[4].token.identifier.name, equals("ServiceDep")); - expect(deps[4].isSkipSelf, equals(true)); - expect(deps[5].token.identifier.name, equals("ServiceDep")); - expect(deps[5].isOptional, equals(true)); - }); - - test('should populate `providers` using toFactory.', () async { - var cmp = (await _testCreateModel('directives_files/components.dart')) - .identifiers['ComponentWithProvidersToFactory']; - - expect(cmp, isNotNull); - expect(cmp.providers, isNotNull); - expect(cmp.providers.length, equals(1)); - - var useFactory = cmp.providers.first.useFactory; - expect(useFactory.prefix, isNull); - expect(useFactory.name, equals("funcDep")); - }); - - test('should populate factories', () async { - var factory = (await _testCreateModel('directives_files/components.dart')) - .identifiers['factoryWithDeps']; - - expect(factory, isNotNull); - - expect(factory.prefix, isNull); - expect(factory.name, equals("factoryWithDeps")); - - var factoryDeps = factory.diDeps; - - expect(factoryDeps[0].token.identifier.name, equals("ServiceDep")); - expect(factoryDeps[1].token.value, equals("Str")); - expect(factoryDeps[2].token.identifier.name, equals("ServiceDep")); - expect(factoryDeps[3].token.identifier.name, equals("ServiceDep")); - expect(factoryDeps[3].isSelf, equals(true)); - expect(factoryDeps[4].token.identifier.name, equals("ServiceDep")); - expect(factoryDeps[4].isSkipSelf, equals(true)); - expect(factoryDeps[5].token.identifier.name, equals("ServiceDep")); - expect(factoryDeps[5].isOptional, equals(true)); - }); - - test('should populate `providers` using a const token.', () async { - var cmp = (await _testCreateModel('directives_files/components.dart')) - .identifiers['ComponentWithProvidersConstToken']; - - expect(cmp, isNotNull); - expect(cmp.providers, isNotNull); - expect(cmp.providers.length, equals(1)); - - var token = cmp.providers.first.token; - expect(token.identifier.name, equals("ServiceDep")); - expect(token.identifierIsInstance, isTrue); - }); - - test('should populate `queries`.', () async { - var cmp = (await _testCreateModel('directives_files/components.dart')) - .identifiers['ComponentWithQueries']; - - expect(cmp, isNotNull); - expect(cmp.queries, isNotNull); - expect(cmp.queries.length, equals(4)); - expect(cmp.queries[0].selectors[0].name, equals("child")); - expect(cmp.queries[0].first, isTrue); - expect(cmp.queries[1].selectors[0].name, equals("child")); - expect(cmp.queries[1].first, isFalse); - expect(cmp.queries[1].descendants, isTrue); - expect(cmp.queries[2].selectors[0].name, equals("child")); - expect(cmp.queries[2].first, isTrue); - expect(cmp.queries[3].selectors[0].name, equals("child")); - expect(cmp.queries[3].first, isFalse); - expect(cmp.queries[3].descendants, isTrue); - - expect(cmp.viewQueries, isNotNull); - expect(cmp.viewQueries.length, equals(4)); - expect(cmp.viewQueries[0].selectors[0].value, equals("child")); - expect(cmp.viewQueries[0].first, isTrue); - expect(cmp.viewQueries[1].selectors[0].value, equals("child")); - expect(cmp.viewQueries[1].first, isFalse); - expect(cmp.viewQueries[2].selectors[0].value, equals("child")); - expect(cmp.viewQueries[2].first, isTrue); - expect(cmp.viewQueries[3].selectors[0].value, equals("child")); - expect(cmp.viewQueries[3].first, isFalse); - }); - - test('should merge `outputs` from the annotation and fields.', () async { - var model = await _testCreateModel('directives_files/components.dart'); - expect( - model.identifiers['ComponentWithOutputs'].outputs, - equals({ - 'a': 'a', - 'b': 'b', - 'c': 'renamed', - 'd': 'd', - 'e': 'get-renamed' - })); - }); - - test('should merge `inputs` from the annotation and fields.', () async { - var model = await _testCreateModel('directives_files/components.dart'); - expect( - model.identifiers['ComponentWithInputs'].inputs, - equals({ - 'a': 'a', - 'b': 'b', - 'c': 'renamed', - 'd': 'd', - 'e': 'set-renamed' - })); - }); - - test('should merge host bindings from the annotation and fields.', - () async { - var model = await _testCreateModel('directives_files/components.dart'); - expect( - model.identifiers['ComponentWithHostBindings'].hostProperties, - equals({ - 'a': 'a', - 'b': 'b', - 'renamed': 'c', - 'd': 'd', - 'get-renamed': 'e' - })); - }); - - test('should merge host listeners from the annotation and fields.', - () async { - var model = await _testCreateModel('directives_files/components.dart'); - expect( - model.identifiers['ComponentWithHostListeners'].hostListeners, - equals({ - 'a': 'onA()', - 'b': 'onB()', - 'c': 'onC(\$event.target,\$event.target.value)' - })); - }); - - test('should warn if @Component has a `template` and @View is present.', - () async { - final logger = new RecordingLogger(); - final model = await _testCreateModel('bad_directives_files/template.dart', - logger: logger); - var warning = - logger.logs.firstWhere((l) => l.contains('WARN'), orElse: () => null); - expect(warning, isNotNull); - expect(warning.toLowerCase(), - contains('cannot specify view parameters on @component')); - }); - - test('should warn if @Component has a `templateUrl` and @View is present.', - () async { - final logger = new RecordingLogger(); - final model = await _testCreateModel( - 'bad_directives_files/template_url.dart', - logger: logger); - var warning = - logger.logs.firstWhere((l) => l.contains('WARN'), orElse: () => null); - expect(warning, isNotNull); - expect(warning.toLowerCase(), - contains('cannot specify view parameters on @component')); - }); - - test('should warn if @Component has `directives` and @View is present.', - () async { - final logger = new RecordingLogger(); - final model = await _testCreateModel( - 'bad_directives_files/directives.dart', - logger: logger); - var warning = - logger.logs.firstWhere((l) => l.contains('WARN'), orElse: () => null); - expect(warning, isNotNull); - expect(warning.toLowerCase(), - contains('cannot specify view parameters on @component')); - }); - - test('should warn if @Component has `pipes` and @View is present.', - () async { - final logger = new RecordingLogger(); - final model = await _testCreateModel('bad_directives_files/pipes.dart', - logger: logger); - var warning = - logger.logs.firstWhere((l) => l.contains('WARN'), orElse: () => null); - expect(warning, isNotNull); - expect(warning.toLowerCase(), - contains('cannot specify view parameters on @component')); - }); - }); - - group('pipes', () { - test('should read the pipe name', () async { - var model = await _testCreateModel('pipe_files/pipes.dart'); - expect(model.identifiers['NameOnlyPipe'].name, equals('nameOnly')); - expect(model.identifiers['NameOnlyPipe'].pure, isFalse); - }); - - test('should read the pure flag', () async { - var model = await _testCreateModel('pipe_files/pipes.dart'); - expect(model.identifiers['NameAndPurePipe'].pure, isTrue); - }); - }); -} - -Future _testCreateModel(String inputPath, - {List customDescriptors: const [], - AssetId assetId, - AssetReader reader, - TransformLogger logger}) { - if (logger == null) logger = new RecordingLogger(); - return zone.exec(() async { - var inputId = _assetIdForPath(inputPath); - if (reader == null) { - reader = new TestAssetReader(); - } - if (assetId != null) { - reader.addAsset(assetId, await reader.readAsString(inputId)); - inputId = assetId; - } - - var annotationMatcher = new AnnotationMatcher()..addAll(customDescriptors); - return createNgMeta(reader, inputId, annotationMatcher); - }, log: logger); -} - -AssetId _assetIdForPath(String path) => - new AssetId('angular2', 'test/transform/directive_processor/$path'); diff --git a/modules_dart/transform/test/transform/directive_processor/bad_directives_files/directives.dart b/modules_dart/transform/test/transform/directive_processor/bad_directives_files/directives.dart deleted file mode 100644 index dd91efd9d0..0000000000 --- a/modules_dart/transform/test/transform/directive_processor/bad_directives_files/directives.dart +++ /dev/null @@ -1,10 +0,0 @@ -library angular2.test.transform.directive_processor.bad_directives_files.directives; - -import 'package:angular2/angular2.dart' - show Component, Directive, View, NgElement; -import 'dep1.dart'; -import 'dep2.dart' as dep2; - -@Component(selector: 'component-first', directives: [Dep, dep2.Dep]) -@View(template: '
Hi
') -class BadDirectives {} diff --git a/modules_dart/transform/test/transform/directive_processor/bad_directives_files/pipes.dart b/modules_dart/transform/test/transform/directive_processor/bad_directives_files/pipes.dart deleted file mode 100644 index c455922fd9..0000000000 --- a/modules_dart/transform/test/transform/directive_processor/bad_directives_files/pipes.dart +++ /dev/null @@ -1,9 +0,0 @@ -library angular2.test.transform.directive_processor.bad_directives_files.pipes; - -import 'package:angular2/angular2.dart' - show Component, Directive, View, NgElement; -import 'dep1.dart'; - -@Component(selector: 'component-first', pipes: [Dep]) -@View(template: '
Hi
') -class BadDirectives {} diff --git a/modules_dart/transform/test/transform/directive_processor/bad_directives_files/template.dart b/modules_dart/transform/test/transform/directive_processor/bad_directives_files/template.dart deleted file mode 100644 index 3bbd6f2e97..0000000000 --- a/modules_dart/transform/test/transform/directive_processor/bad_directives_files/template.dart +++ /dev/null @@ -1,10 +0,0 @@ -library angular2.test.transform.directive_processor.bad_directives_files.template; - -import 'package:angular2/angular2.dart' - show Component, Directive, View, NgElement; -import 'dep1.dart'; -import 'dep2.dart' as dep2; - -@Component(selector: 'component-first', template: 'bad!') -@View(template: 'good!', directives: [Dep, dep2.Dep]) -class BadTemplate {} diff --git a/modules_dart/transform/test/transform/directive_processor/bad_directives_files/template_url.dart b/modules_dart/transform/test/transform/directive_processor/bad_directives_files/template_url.dart deleted file mode 100644 index c4058bc6f9..0000000000 --- a/modules_dart/transform/test/transform/directive_processor/bad_directives_files/template_url.dart +++ /dev/null @@ -1,10 +0,0 @@ -library angular2.test.transform.directive_processor.bad_directives_files.template_url; - -import 'package:angular2/angular2.dart' - show Component, Directive, View, NgElement; -import 'dep1.dart'; -import 'dep2.dart' as dep2; - -@Component(selector: 'component-first', templateUrl: 'bad_template.html') -@View(templateUrl: 'good_template.html', directives: [Dep, dep2.Dep]) -class BadTemplateUrl {} diff --git a/modules_dart/transform/test/transform/directive_processor/custom_metadata/bad_soup.dart b/modules_dart/transform/test/transform/directive_processor/custom_metadata/bad_soup.dart deleted file mode 100644 index e6caa22a8c..0000000000 --- a/modules_dart/transform/test/transform/directive_processor/custom_metadata/bad_soup.dart +++ /dev/null @@ -1,8 +0,0 @@ -library dinner.bad_soup; - -// No recognized import for [Soup] - -@Soup() -class BadSoup { - BadSoup(); -} diff --git a/modules_dart/transform/test/transform/directive_processor/custom_metadata/package_soup.dart b/modules_dart/transform/test/transform/directive_processor/custom_metadata/package_soup.dart deleted file mode 100644 index 447d761bd0..0000000000 --- a/modules_dart/transform/test/transform/directive_processor/custom_metadata/package_soup.dart +++ /dev/null @@ -1,10 +0,0 @@ -library dinner.package_soup; - -import 'package:angular2/angular2.dart'; -import 'package:soup/soup.dart'; - -@Soup() -@View(template: '') -class PackageSoup { - PackageSoup(); -} diff --git a/modules_dart/transform/test/transform/directive_processor/custom_metadata/relative_soup.dart b/modules_dart/transform/test/transform/directive_processor/custom_metadata/relative_soup.dart deleted file mode 100644 index 522a15fee1..0000000000 --- a/modules_dart/transform/test/transform/directive_processor/custom_metadata/relative_soup.dart +++ /dev/null @@ -1,10 +0,0 @@ -library dinner.relative_soup; - -import 'package:angular2/angular2.dart'; -import 'annotations/soup.dart'; - -@Soup() -@View(template: '') -class RelativeSoup { - RelativeSoup(); -} diff --git a/modules_dart/transform/test/transform/directive_processor/directive_aliases_files/a.dart b/modules_dart/transform/test/transform/directive_processor/directive_aliases_files/a.dart deleted file mode 100644 index c6691d2b6b..0000000000 --- a/modules_dart/transform/test/transform/directive_processor/directive_aliases_files/a.dart +++ /dev/null @@ -1,3 +0,0 @@ -class Bar {} - -const alias3 = const [Bar]; diff --git a/modules_dart/transform/test/transform/directive_processor/directive_aliases_files/b.dart b/modules_dart/transform/test/transform/directive_processor/directive_aliases_files/b.dart deleted file mode 100644 index f1e00d1589..0000000000 --- a/modules_dart/transform/test/transform/directive_processor/directive_aliases_files/b.dart +++ /dev/null @@ -1 +0,0 @@ -class Baz {} diff --git a/modules_dart/transform/test/transform/directive_processor/directive_aliases_files/hello.dart b/modules_dart/transform/test/transform/directive_processor/directive_aliases_files/hello.dart deleted file mode 100644 index b1c3b2c1dd..0000000000 --- a/modules_dart/transform/test/transform/directive_processor/directive_aliases_files/hello.dart +++ /dev/null @@ -1,20 +0,0 @@ -library playground.src.hello_world.absolute_url_expression_files; - -import 'package:angular2/angular2.dart' - show bootstrap, Component, Directive, View, NgElement; -export 'a.dart' show alias3; -import 'b.dart' as b; - -@Component(selector: 'hello-app') -@View(templateUrl: 'template.html', styleUrls: const ['template.css']) -class HelloCmp {} - -class Foo {} - -// valid -const alias1 = const [HelloCmp]; -// valid, even though it includes things that are not components -const alias2 = const [HelloCmp, Foo]; - -// Prefixed names are not supported -const alias4 = const [b.Baz]; diff --git a/modules_dart/transform/test/transform/directive_processor/directive_aliases_files/template.css b/modules_dart/transform/test/transform/directive_processor/directive_aliases_files/template.css deleted file mode 100644 index c48477652e..0000000000 --- a/modules_dart/transform/test/transform/directive_processor/directive_aliases_files/template.css +++ /dev/null @@ -1 +0,0 @@ -.greeting { .color: blue; } \ No newline at end of file diff --git a/modules_dart/transform/test/transform/directive_processor/directive_aliases_files/template.html b/modules_dart/transform/test/transform/directive_processor/directive_aliases_files/template.html deleted file mode 100644 index d75013393f..0000000000 --- a/modules_dart/transform/test/transform/directive_processor/directive_aliases_files/template.html +++ /dev/null @@ -1 +0,0 @@ -{{greeting}} \ No newline at end of file diff --git a/modules_dart/transform/test/transform/directive_processor/directives_files/components.dart b/modules_dart/transform/test/transform/directive_processor/directives_files/components.dart deleted file mode 100644 index dbc4b81070..0000000000 --- a/modules_dart/transform/test/transform/directive_processor/directives_files/components.dart +++ /dev/null @@ -1,271 +0,0 @@ -library angular2.test.transform.directive_processor.directive_files.components; - -import 'package:angular2/angular2.dart' - show Component, Directive, View, NgElement, Output, Input, Provider, ContentChild, ContentChildren, ViewChild, ViewChildren; -import 'dep1.dart'; -import 'dep2.dart' as dep2; - -@Component(selector: 'component-first') -@View( - template: '', - directives: [Dep, dep2.Dep], - pipes: [PipeDep, dep2.PipeDep]) -class ComponentFirst {} - -@View( - template: '', - directives: [dep2.Dep, Dep], - pipes: [dep2.PipeDep, PipeDep]) -@Component(selector: 'view-first') -class ViewFirst {} - -@Component( - selector: 'component-only', - template: '', - directives: [Dep, dep2.Dep], - pipes: [PipeDep, dep2.PipeDep]) -class ComponentOnly {} - -@Component( - selector: 'component-with-outputs', - template: '', - outputs: ['a']) -class ComponentWithOutputs { - @Output() Object b; - @Output('renamed') Object c; - - Object _d; - @Output() Object get d => _d; - - Object _e; - @Output('get-renamed') Object get e => _e; -} - -@Component( - selector: 'component-with-inputs', - template: '', - inputs: ['a']) -class ComponentWithInputs { - @Input() Object b; - @Input('renamed') Object c; - - Object _d; - @Input() void set d(Object value) { - _d = value; - } - - Object _e; - @Input('set-renamed') void set e(Object value) { - _e = value; - } -} - -@Component( - selector: 'component-with-inputs', - template: '', - host: {'[a]': 'a'}) -class ComponentWithHostBindings { - @HostBinding() Object b; - @HostBinding('renamed') Object c; - - Object _d; - @HostBinding() Object get d => _d; - - Object _e; - @HostBinding('get-renamed') Object get e => _e; -} - -@Component( - selector: 'component-with-inputs', - template: '', - host: {'(a)': 'onA()'}) -class ComponentWithHostListeners { - @HostListener('b') void onB() {} - @HostListener('c', ['\$event.target', '\$event.target.value']) void onC( - t, v) {} -} - -@Component( - selector: 'component-with-providers-types', - template: '', - providers: [ServiceDep, dep2.ServiceDep]) -class ComponentWithProvidersTypes {} - -@Component( - selector: 'component-with-view-providers-types', - template: '', - viewProviders: [ServiceDep]) -class ComponentWithViewProvidersTypes {} - -@Component( - selector: 'component-with-bindings-types', - template: '', - bindings: [ServiceDep]) -class ComponentWithBindingsTypes {} - -@Component( - selector: 'component-with-view-bindings-types', - template: '', - viewBindings: [ServiceDep]) -class ComponentWithViewBindingsTypes {} - -@Component( - selector: 'component-with-providers-string-token', - template: '', - providers: [const Provider("StringDep", useClass: ServiceDep)]) -class ComponentWithProvidersStringToken {} - -@Component( - selector: 'ComponentWithProvidersConstToken', - template: '', - providers: [const Provider(const ServiceDep(), useClass: ServiceDep)]) -class ComponentWithProvidersConstToken { - ComponentWithProvidersConstToken(); -} - -@Component( - selector: 'component-with-providers-use-class', - template: '', - providers: [const Provider(ServiceDep, useClass: ServiceDep)]) -class ComponentWithProvidersUseClass {} - -@Component(selector: 'component-with-di-deps', template: '') -class ComponentWithDiDeps { - ServiceDep arg11; - ServiceDep arg13; - - ComponentWithDiDeps( - ServiceDep arg1, - @Inject(ServiceDep) arg2, - @Attribute('one') arg3, - @Self() ServiceDep arg4, - @SkipSelf() ServiceDep arg5, - @Optional() ServiceDep arg6, - @Query(ServiceDep, descendants: true, read: ServiceDep) arg7, - @ContentChildren(ServiceDep) arg8, - @ViewQuery("one,two", read: "three") arg9, - @ViewChildren("one,two") arg10, - this.arg11, - [@Optional() ServiceDep arg12, - @Optional() this.arg13] - ); -} - -@Component( - selector: 'component-with-providers-use-class', - template: '', - providers: [const Provider(ServiceDep, useClass: ServiceDep)]) -class ComponentWithProvidersUseClass {} - -@Component( - selector: 'component-with-providers-to-class', - template: '', - providers: [const Binding(ServiceDep, toClass: ServiceDep)]) -class ComponentWithProvidersToClass {} - -@Component( - selector: 'component-with-providers-use-existing', - template: '', - providers: [const Provider(ServiceDep, useExisting: ServiceDep)]) -class ComponentWithProvidersUseExisting {} - -@Component( - selector: 'component-with-providers-to-alias', - template: '', - providers: [const Binding(ServiceDep, toAlias: ServiceDep)]) -class ComponentWithProvidersToAlias {} - -@Component( - selector: 'component-with-providers-use-existing-string', - template: '', - providers: [const Provider(ServiceDep, useExisting: 'StrToken')]) -class ComponentWithProvidersUseExistingStr {} - -@Component( - selector: 'component-with-providers-use-value', - template: '', - providers: [const Provider(ServiceDep, useValue: ServiceDep)]) -class ComponentWithProvidersUseValue {} - -@Component( - selector: 'component-with-providers-to-value', - template: '', - providers: [const Binding(ServiceDep, toValue: ServiceDep)]) -class ComponentWithProvidersToValue {} - -@Component( - selector: 'component-with-providers-use-value-string', - template: '', - providers: [const Provider(ServiceDep, useValue: 'StrToken')]) -class ComponentWithProvidersUseValueStr {} - -@Component( - selector: 'component-with-providers-use-value-num', - template: '', - providers: [const Provider(ServiceDep, useValue: 42)]) -class ComponentWithProvidersUseValueNum {} - -@Component( - selector: 'component-with-providers-use-value-bool', - template: '', - providers: [const Provider(ServiceDep, useValue: true)]) -class ComponentWithProvidersUseValueBool {} - -@Component( - selector: 'component-with-providers-use-value-null', - template: '', - providers: [const Provider(ServiceDep, useValue: null)]) -class ComponentWithProvidersUseValueNull {} - -@Component( - selector: 'component-with-providers-use-factory', - template: '', - providers: [ - const Provider(ServiceDep, useFactory: funcDep, deps: const [ - ServiceDep, - "Str", - [const Inject(ServiceDep)], - [ServiceDep, const Self()], - [ServiceDep, const SkipSelf()], - [ServiceDep, const Optional()] - ]) - ]) -class ComponentWithProvidersUseFactory {} - -@Component( - selector: 'component-with-providers-to-factory', - template: '', - providers: [const Binding(ServiceDep, toFactory: funcDep)]) -class ComponentWithProvidersToFactory {} - -@Component(selector: 'component-with-di-deps-string-token', template: '') -class ComponentWithDiDepsStrToken { - ComponentWithDiDepsStrToken(@Inject("StringDep") arg1); -} - -@Component( - selector: 'component-with-queries', - template: '') -class ComponentWithQueries { - @ContentChild('child') var contentChild; - @ContentChildren('child', descendants: true) var contentChildren; - - @ViewChild('child') var viewChild; - @ViewChildren('child') var viewChildren; - - @ContentChild('child') set contentChildSetter(s){} - @ContentChildren('child', descendants: true) set contentChildrenSetter(s){} - - @ViewChild('child') set viewChildSetter(s){} - @ViewChildren('child') set viewChildrenSetter(s){} -} - -funcDep() {} - -@Injectable() -factoryWithDeps(ServiceDep a, - @Inject("Str") b, - @Inject(ServiceDep) c, - @Self ServiceDep d, - @SkipSelf ServiceDep e, - @Optional ServiceDep f) {} \ No newline at end of file diff --git a/modules_dart/transform/test/transform/directive_processor/directives_files/dep1.dart b/modules_dart/transform/test/transform/directive_processor/directives_files/dep1.dart deleted file mode 100644 index 335558ca4b..0000000000 --- a/modules_dart/transform/test/transform/directive_processor/directives_files/dep1.dart +++ /dev/null @@ -1,17 +0,0 @@ -library angular2.test.transform.directive_processor.directive_files.dep1; - -import 'package:angular2/angular2.dart' - show Component, Directive, View, Pipe, Injectable; - -@Component(selector: 'dep1') -@View(template: 'Dep1') -class Dep {} - -@Pipe(name: 'dep1') -class PipeDep {} - -@Injectable() -class ServiceDep { - const ServiceDep(); - static someFactory() {} -} diff --git a/modules_dart/transform/test/transform/directive_processor/directives_files/dep2.dart b/modules_dart/transform/test/transform/directive_processor/directives_files/dep2.dart deleted file mode 100644 index fc502a5d51..0000000000 --- a/modules_dart/transform/test/transform/directive_processor/directives_files/dep2.dart +++ /dev/null @@ -1,14 +0,0 @@ -library angular2.test.transform.directive_processor.directive_files.dep2; - -import 'package:angular2/angular2.dart' - show Component, Directive, View, Pipe, Injectable; - -@Component(selector: 'dep2') -@View(template: 'Dep2') -class Dep {} - -@Pipe(name: 'dep2') -class PipeDep {} - -@Injectable() -class ServiceDep {} diff --git a/modules_dart/transform/test/transform/directive_processor/directives_files/services.dart b/modules_dart/transform/test/transform/directive_processor/directives_files/services.dart deleted file mode 100644 index 8deaa140b1..0000000000 --- a/modules_dart/transform/test/transform/directive_processor/directives_files/services.dart +++ /dev/null @@ -1,9 +0,0 @@ -library angular2.test.transform.directive_processor.directive_files.components; - -import 'package:angular2/angular2.dart' show Injectable, Inject; -import 'dep1.dart'; - -@Injectable() -class Service { - Service(ServiceDep arg1, @Inject(ServiceDep) arg2); -} diff --git a/modules_dart/transform/test/transform/directive_processor/identifiers/classes.dart b/modules_dart/transform/test/transform/directive_processor/identifiers/classes.dart deleted file mode 100644 index d99cd73c83..0000000000 --- a/modules_dart/transform/test/transform/directive_processor/identifiers/classes.dart +++ /dev/null @@ -1,10 +0,0 @@ -library angular2.test.transform.directive_processor.identifiers.classes; - -import 'package:angular2/angular2.dart' show Injectable; - -class Service1 {} - -@Injectable() -class Service2 { - Service2(Service1 service1) {} -} \ No newline at end of file diff --git a/modules_dart/transform/test/transform/directive_processor/identifiers/classes_no_injectable.dart b/modules_dart/transform/test/transform/directive_processor/identifiers/classes_no_injectable.dart deleted file mode 100644 index 2f5b6f52c9..0000000000 --- a/modules_dart/transform/test/transform/directive_processor/identifiers/classes_no_injectable.dart +++ /dev/null @@ -1,3 +0,0 @@ -library angular2.test.transform.directive_processor.identifiers.classes_no_injectable; - -abstract class ClassA {} diff --git a/modules_dart/transform/test/transform/directive_processor/identifiers/constants.dart b/modules_dart/transform/test/transform/directive_processor/identifiers/constants.dart deleted file mode 100644 index 5fcf54ae47..0000000000 --- a/modules_dart/transform/test/transform/directive_processor/identifiers/constants.dart +++ /dev/null @@ -1,5 +0,0 @@ -library angular2.test.transform.directive_processor.identifiers.constants; - -const a = "a"; -const b = "b"; -var c = "c"; diff --git a/modules_dart/transform/test/transform/directive_processor/identifiers/enums.dart b/modules_dart/transform/test/transform/directive_processor/identifiers/enums.dart deleted file mode 100644 index a39cc11610..0000000000 --- a/modules_dart/transform/test/transform/directive_processor/identifiers/enums.dart +++ /dev/null @@ -1,3 +0,0 @@ -library angular2.test.transform.directive_processor.identifiers.enums; - -enum Enum { one } diff --git a/modules_dart/transform/test/transform/directive_processor/identifiers/factories.dart b/modules_dart/transform/test/transform/directive_processor/identifiers/factories.dart deleted file mode 100644 index 5d34d97b80..0000000000 --- a/modules_dart/transform/test/transform/directive_processor/identifiers/factories.dart +++ /dev/null @@ -1,10 +0,0 @@ -library angular2.test.transform.directive_processor.identifiers.classes; - -import 'package:angular2/angular2.dart' show Injectable; - -class SomeClass {} - -factory1(SomeClass c) {} - -@Injectable() -factory2(SomeClass c) {} \ No newline at end of file diff --git a/modules_dart/transform/test/transform/directive_processor/identifiers/provider_constants.dart b/modules_dart/transform/test/transform/directive_processor/identifiers/provider_constants.dart deleted file mode 100644 index 29a73f031b..0000000000 --- a/modules_dart/transform/test/transform/directive_processor/identifiers/provider_constants.dart +++ /dev/null @@ -1,13 +0,0 @@ -library angular2.test.transform.directive_processor.identifiers.constants; - -import 'package:angular2/angular2.dart' show Provider; - -class SomeClass {} - -const a = const Provider("someToken", useClass: SomeClass); - -const b = const [ - SomeClass, - a, - const Provider("someOtherToken", useClass: SomeClass) -]; \ No newline at end of file diff --git a/modules_dart/transform/test/transform/directive_processor/identifiers/typedefs.dart b/modules_dart/transform/test/transform/directive_processor/identifiers/typedefs.dart deleted file mode 100644 index 2072a601b3..0000000000 --- a/modules_dart/transform/test/transform/directive_processor/identifiers/typedefs.dart +++ /dev/null @@ -1,3 +0,0 @@ -library angular2.test.transform.directive_processor.identifiers.typedefs; - -typedef String TypeDef(String); diff --git a/modules_dart/transform/test/transform/directive_processor/interface_chain_files/soup.dart b/modules_dart/transform/test/transform/directive_processor/interface_chain_files/soup.dart deleted file mode 100644 index 3dad29afe7..0000000000 --- a/modules_dart/transform/test/transform/directive_processor/interface_chain_files/soup.dart +++ /dev/null @@ -1,13 +0,0 @@ -library dinner.soup; - -import 'package:angular2/src/core/metadata.dart'; - -@Component(selector: '[soup]') -@View(template: '') -class ChangingSoupComponent implements PrimaryInterface {} - -class TernaryInterface {} - -class SecondaryInterface implements TernaryInterface {} - -class PrimaryInterface implements SecondaryInterface {} diff --git a/modules_dart/transform/test/transform/directive_processor/interfaces_files/soup.dart b/modules_dart/transform/test/transform/directive_processor/interfaces_files/soup.dart deleted file mode 100644 index dc596b09a6..0000000000 --- a/modules_dart/transform/test/transform/directive_processor/interfaces_files/soup.dart +++ /dev/null @@ -1,8 +0,0 @@ -library dinner.soup; - -import 'package:angular2/src/core/metadata.dart'; -import 'package:angular2/src/core/linker.dart'; - -@Component(selector: '[soup]') -@View(template: '') -class ChangingSoupComponent implements OnChanges, AnotherInterface {} diff --git a/modules_dart/transform/test/transform/directive_processor/invalid_url_files/hello.dart b/modules_dart/transform/test/transform/directive_processor/invalid_url_files/hello.dart deleted file mode 100644 index bfa8563643..0000000000 --- a/modules_dart/transform/test/transform/directive_processor/invalid_url_files/hello.dart +++ /dev/null @@ -1,10 +0,0 @@ -library test.transform.directive_processor.invalid_url_files.hello; - -import 'package:angular2/angular2.dart' - show Component, Directive, View, NgElement; - -@Component(selector: 'hello-app') -@View( - templateUrl: '/bad/absolute/url.html', - styleUrls: const ['package:invalid/package.css', 'bad_relative_url.css']) -class HelloCmp {} diff --git a/modules_dart/transform/test/transform/directive_processor/multiple_interface_lifecycle_files/soup.dart b/modules_dart/transform/test/transform/directive_processor/multiple_interface_lifecycle_files/soup.dart deleted file mode 100644 index e569c10d83..0000000000 --- a/modules_dart/transform/test/transform/directive_processor/multiple_interface_lifecycle_files/soup.dart +++ /dev/null @@ -1,8 +0,0 @@ -library dinner.soup; - -import 'package:angular2/src/core/metadata.dart'; -import 'package:angular2/src/core/linker.dart'; - -@Component(selector: '[soup]') -@View(template: '') -class MultiSoupComponent implements OnChanges, OnDestroy, OnInit {} diff --git a/modules_dart/transform/test/transform/directive_processor/multiple_part_files/main.dart b/modules_dart/transform/test/transform/directive_processor/multiple_part_files/main.dart deleted file mode 100644 index 86b4ba2787..0000000000 --- a/modules_dart/transform/test/transform/directive_processor/multiple_part_files/main.dart +++ /dev/null @@ -1,12 +0,0 @@ -library main; - -import 'package:angular2/src/core/metadata.dart'; - -part 'part1.dart'; -part 'part2.dart'; - -@Component(selector: '[main]') -@View(template: '') -class MainComponent { - MainComponent(); -} diff --git a/modules_dart/transform/test/transform/directive_processor/multiple_part_files/part1.dart b/modules_dart/transform/test/transform/directive_processor/multiple_part_files/part1.dart deleted file mode 100644 index 56f9c1bd38..0000000000 --- a/modules_dart/transform/test/transform/directive_processor/multiple_part_files/part1.dart +++ /dev/null @@ -1,7 +0,0 @@ -part of main; - -@Component(selector: '[part1]') -@View(template: '') -class Part1Component { - Part1Component(); -} diff --git a/modules_dart/transform/test/transform/directive_processor/multiple_part_files/part2.dart b/modules_dart/transform/test/transform/directive_processor/multiple_part_files/part2.dart deleted file mode 100644 index 5a86818c34..0000000000 --- a/modules_dart/transform/test/transform/directive_processor/multiple_part_files/part2.dart +++ /dev/null @@ -1,7 +0,0 @@ -part of main; - -@Component(selector: '[part2]') -@View(template: '') -class Part2Component { - Part2Component(); -} diff --git a/modules_dart/transform/test/transform/directive_processor/parameter_metadata/soup.dart b/modules_dart/transform/test/transform/directive_processor/parameter_metadata/soup.dart deleted file mode 100644 index e7b8c206a0..0000000000 --- a/modules_dart/transform/test/transform/directive_processor/parameter_metadata/soup.dart +++ /dev/null @@ -1,9 +0,0 @@ -library dinner.soup; - -import 'package:angular2/src/core/metadata.dart'; - -@Component(selector: '[soup]') -@View(template: '') -class SoupComponent { - SoupComponent(@Tasty() String description, @Inject(Salt) salt); -} diff --git a/modules_dart/transform/test/transform/directive_processor/part_files/main.dart b/modules_dart/transform/test/transform/directive_processor/part_files/main.dart deleted file mode 100644 index cafbe51ad0..0000000000 --- a/modules_dart/transform/test/transform/directive_processor/part_files/main.dart +++ /dev/null @@ -1,11 +0,0 @@ -library main; - -import 'package:angular2/src/core/metadata.dart'; - -part 'part.dart'; - -@Component(selector: '[main]') -@View(template: '') -class MainComponent { - MainComponent(); -} diff --git a/modules_dart/transform/test/transform/directive_processor/part_files/part.dart b/modules_dart/transform/test/transform/directive_processor/part_files/part.dart deleted file mode 100644 index f506a71f75..0000000000 --- a/modules_dart/transform/test/transform/directive_processor/part_files/part.dart +++ /dev/null @@ -1,7 +0,0 @@ -part of main; - -@Component(selector: '[part]') -@View(template: '') -class PartComponent { - PartComponent(); -} diff --git a/modules_dart/transform/test/transform/directive_processor/pipe_files/pipes.dart b/modules_dart/transform/test/transform/directive_processor/pipe_files/pipes.dart deleted file mode 100644 index 88d76174da..0000000000 --- a/modules_dart/transform/test/transform/directive_processor/pipe_files/pipes.dart +++ /dev/null @@ -1,9 +0,0 @@ -library angular2.test.transform.directive_processor.pipe_files.pipes; - -import 'package:angular2/angular2.dart' show Pipe; - -@Pipe(name: 'nameOnly') -class NameOnlyPipe {} - -@Pipe(name: 'nameAndPure', pure: true) -class NameAndPurePipe {} diff --git a/modules_dart/transform/test/transform/directive_processor/prefixed_annotations_files/soup.dart b/modules_dart/transform/test/transform/directive_processor/prefixed_annotations_files/soup.dart deleted file mode 100644 index 0d9c9c32c8..0000000000 --- a/modules_dart/transform/test/transform/directive_processor/prefixed_annotations_files/soup.dart +++ /dev/null @@ -1,7 +0,0 @@ -library dinner.soup; - -import 'package:angular2/src/core/metadata.dart' as ng; - -@ng.Component(selector: '[soup]') -@ng.View(template: 'SoupView') -class SoupComponent {} diff --git a/modules_dart/transform/test/transform/directive_processor/prefixed_interface_lifecycle_files/soup.dart b/modules_dart/transform/test/transform/directive_processor/prefixed_interface_lifecycle_files/soup.dart deleted file mode 100644 index 66aa5e07e7..0000000000 --- a/modules_dart/transform/test/transform/directive_processor/prefixed_interface_lifecycle_files/soup.dart +++ /dev/null @@ -1,8 +0,0 @@ -library dinner.soup; - -import 'package:angular2/src/core/linker.dart' as prefix; -import 'package:angular2/src/core/metadata.dart'; - -@Component(selector: '[soup]') -@View(template: '') -class OnChangeSoupComponent implements prefix.OnChanges {} diff --git a/modules_dart/transform/test/transform/directive_processor/prop_metadata_files/fields.dart b/modules_dart/transform/test/transform/directive_processor/prop_metadata_files/fields.dart deleted file mode 100644 index 04438e3e5d..0000000000 --- a/modules_dart/transform/test/transform/directive_processor/prop_metadata_files/fields.dart +++ /dev/null @@ -1,9 +0,0 @@ -library fields; - -import 'package:angular2/src/core/metadata.dart'; - -@Component(selector: '[fields]') -@View(template: '') -class FieldComponent { - @FieldDecorator("field") String field; -} diff --git a/modules_dart/transform/test/transform/directive_processor/prop_metadata_files/getters.dart b/modules_dart/transform/test/transform/directive_processor/prop_metadata_files/getters.dart deleted file mode 100644 index 5ff6738e09..0000000000 --- a/modules_dart/transform/test/transform/directive_processor/prop_metadata_files/getters.dart +++ /dev/null @@ -1,9 +0,0 @@ -library fields; - -import 'package:angular2/src/core/metadata.dart'; - -@Component(selector: '[getters]') -@View(template: '') -class FieldComponent { - @GetDecorator("get") String get getVal => 'a'; -} diff --git a/modules_dart/transform/test/transform/directive_processor/prop_metadata_files/getters_and_setters.dart b/modules_dart/transform/test/transform/directive_processor/prop_metadata_files/getters_and_setters.dart deleted file mode 100644 index 427b25abf1..0000000000 --- a/modules_dart/transform/test/transform/directive_processor/prop_metadata_files/getters_and_setters.dart +++ /dev/null @@ -1,11 +0,0 @@ -library fields; - -import 'package:angular2/src/core/metadata.dart'; - -@Component(selector: '[getters-and-setters]') -@View(template: '') -class FieldComponent { - String _val; - @GetDecorator("get") String get myVal => _val; - @SetDecorator("set") String set myVal(val) => _val = val; -} diff --git a/modules_dart/transform/test/transform/directive_processor/prop_metadata_files/override.dart b/modules_dart/transform/test/transform/directive_processor/prop_metadata_files/override.dart deleted file mode 100644 index 4bdb4cc057..0000000000 --- a/modules_dart/transform/test/transform/directive_processor/prop_metadata_files/override.dart +++ /dev/null @@ -1,14 +0,0 @@ -library override; - -import 'package:angular2/src/core/metadata.dart'; - -@Component(selector: '[getters]') -@View(template: '') -class FieldComponent implements ValGetter { - @override - String get getVal => 'a'; -} - -abstract class ValGetter { - String get getVal; -} diff --git a/modules_dart/transform/test/transform/directive_processor/prop_metadata_files/setters.dart b/modules_dart/transform/test/transform/directive_processor/prop_metadata_files/setters.dart deleted file mode 100644 index 92c051961c..0000000000 --- a/modules_dart/transform/test/transform/directive_processor/prop_metadata_files/setters.dart +++ /dev/null @@ -1,9 +0,0 @@ -library fields; - -import 'package:angular2/src/core/metadata.dart'; - -@Component(selector: '[setters]') -@View(template: '') -class FieldComponent { - @SetDecorator("set") String set setVal(val) => null; -} diff --git a/modules_dart/transform/test/transform/directive_processor/static_function_files/hello.dart b/modules_dart/transform/test/transform/directive_processor/static_function_files/hello.dart deleted file mode 100644 index a9ac2ddd9c..0000000000 --- a/modules_dart/transform/test/transform/directive_processor/static_function_files/hello.dart +++ /dev/null @@ -1,11 +0,0 @@ -library static_function_files.hello; - -import 'package:angular2/angular2.dart'; - -@Injectable() -String getMessage(@Inject(Message) message) => message.value; - -@Injectable() -class Message { - String value = 'hello!'; -} diff --git a/modules_dart/transform/test/transform/directive_processor/superclass_files/soup.dart b/modules_dart/transform/test/transform/directive_processor/superclass_files/soup.dart deleted file mode 100644 index d0a38942bd..0000000000 --- a/modules_dart/transform/test/transform/directive_processor/superclass_files/soup.dart +++ /dev/null @@ -1,11 +0,0 @@ -library dinner.soup; - -import 'package:angular2/src/core/metadata.dart'; - -@Component(selector: '[soup]') -@View(template: '') -class ChangingSoupComponent extends Super {} - -class Iface {} - -class Super implements Iface {} diff --git a/modules_dart/transform/test/transform/directive_processor/superclass_lifecycle_files/soup.dart b/modules_dart/transform/test/transform/directive_processor/superclass_lifecycle_files/soup.dart deleted file mode 100644 index fd491c8d11..0000000000 --- a/modules_dart/transform/test/transform/directive_processor/superclass_lifecycle_files/soup.dart +++ /dev/null @@ -1,8 +0,0 @@ -library dinner.soup; - -import 'package:angular2/src/core/linker.dart'; -import 'package:angular2/src/core/metadata.dart'; - -@Component(selector: '[soup]') -@View(template: '') -class OnChangeSoupComponent extends OnChanges {} diff --git a/modules_dart/transform/test/transform/directive_processor/template_files/property.dart b/modules_dart/transform/test/transform/directive_processor/template_files/property.dart deleted file mode 100644 index 8683640f04..0000000000 --- a/modules_dart/transform/test/transform/directive_processor/template_files/property.dart +++ /dev/null @@ -1,8 +0,0 @@ -library playground.src.hello_world.template_files.property; - -import 'package:angular2/angular2.dart' - show Component, Directive, View, NgElement; - -@Component(selector: 'property') -@View(template: '
Hi
') -class PropertyTestComponent {} diff --git a/modules_dart/transform/test/transform/directive_processor/unusual_component_files/hello.dart b/modules_dart/transform/test/transform/directive_processor/unusual_component_files/hello.dart deleted file mode 100644 index e6ae73216e..0000000000 --- a/modules_dart/transform/test/transform/directive_processor/unusual_component_files/hello.dart +++ /dev/null @@ -1,22 +0,0 @@ -library playground.src.hello_world.unusual_component_files; - -import 'package:angular2/angular2.dart' - show Component, Directive, View, NgElement; - -@Component( - selector: 'unusual-comp', - exportAs: 'ComponentExportAsValue', - changeDetection: ChangeDetectionStrategy.CheckAlways, - inputs: const ['aProperty'], - host: const {'hostKey': 'hostValue'}, - outputs: const ['anEvent']) -@View(templateUrl: 'template.html') -class UnusualComp {} - -@Directive( - selector: 'unusual-directive', - exportAs: 'DirectiveExportAsValue', - inputs: const ['aDirectiveProperty'], - host: const {'directiveHostKey': 'directiveHostValue'}, - outputs: const ['aDirectiveEvent']) -class UnusualDirective {} diff --git a/modules_dart/transform/test/transform/directive_processor/unusual_component_files/template.html b/modules_dart/transform/test/transform/directive_processor/unusual_component_files/template.html deleted file mode 100644 index d75013393f..0000000000 --- a/modules_dart/transform/test/transform/directive_processor/unusual_component_files/template.html +++ /dev/null @@ -1 +0,0 @@ -{{greeting}} \ No newline at end of file diff --git a/modules_dart/transform/test/transform/inliner_for_test/absolute_url_expression_files/expected/hello.dart b/modules_dart/transform/test/transform/inliner_for_test/absolute_url_expression_files/expected/hello.dart deleted file mode 100644 index ddb3bee244..0000000000 --- a/modules_dart/transform/test/transform/inliner_for_test/absolute_url_expression_files/expected/hello.dart +++ /dev/null @@ -1,12 +0,0 @@ -library playground.src.hello_world.absolute_url_expression_files; - -import 'package:angular2/angular2.dart' - show Component, Directive, View, NgElement; - -@Component(selector: 'hello-app') -@View(template: _template0, styles: const [_style1,]) -class HelloCmp {} - -@Injectable() hello() {} -const _template0 = r'''{{greeting}}'''; -const _style1 = r'''.greeting { .color: blue; }'''; diff --git a/modules_dart/transform/test/transform/inliner_for_test/absolute_url_expression_files/hello.dart b/modules_dart/transform/test/transform/inliner_for_test/absolute_url_expression_files/hello.dart deleted file mode 100644 index 210c120364..0000000000 --- a/modules_dart/transform/test/transform/inliner_for_test/absolute_url_expression_files/hello.dart +++ /dev/null @@ -1,12 +0,0 @@ -library playground.src.hello_world.absolute_url_expression_files; - -import 'package:angular2/angular2.dart' - show Component, Directive, View, NgElement; - -@Component(selector: 'hello-app') -@View( - templateUrl: 'package:other_package/template.html', - styleUrls: const ['package:other_package/template.css']) -class HelloCmp {} - -@Injectable() hello() {} diff --git a/modules_dart/transform/test/transform/inliner_for_test/absolute_url_expression_files/template.css b/modules_dart/transform/test/transform/inliner_for_test/absolute_url_expression_files/template.css deleted file mode 100644 index c48477652e..0000000000 --- a/modules_dart/transform/test/transform/inliner_for_test/absolute_url_expression_files/template.css +++ /dev/null @@ -1 +0,0 @@ -.greeting { .color: blue; } \ No newline at end of file diff --git a/modules_dart/transform/test/transform/inliner_for_test/absolute_url_expression_files/template.html b/modules_dart/transform/test/transform/inliner_for_test/absolute_url_expression_files/template.html deleted file mode 100644 index d75013393f..0000000000 --- a/modules_dart/transform/test/transform/inliner_for_test/absolute_url_expression_files/template.html +++ /dev/null @@ -1 +0,0 @@ -{{greeting}} \ No newline at end of file diff --git a/modules_dart/transform/test/transform/inliner_for_test/all_tests.dart b/modules_dart/transform/test/transform/inliner_for_test/all_tests.dart deleted file mode 100644 index c4507e7613..0000000000 --- a/modules_dart/transform/test/transform/inliner_for_test/all_tests.dart +++ /dev/null @@ -1,233 +0,0 @@ -library angular2.test.transform.inliner_for_test.all_tests; - -import 'dart:async'; -import 'dart:convert' show LineSplitter; - -import 'package:barback/barback.dart'; -import 'package:dart_style/dart_style.dart'; -import 'package:test/test.dart'; -import 'package:transformer_test/utils.dart'; - -import 'package:angular2/src/transform/common/annotation_matcher.dart'; -import 'package:angular2/src/transform/common/asset_reader.dart'; -import 'package:angular2/src/transform/common/options.dart'; -import 'package:angular2/src/transform/common/zone.dart' as zone; -import 'package:angular2/src/transform/inliner_for_test/transformer.dart'; - -import '../common/read_file.dart'; -import '../common/recording_logger.dart'; - -main() { - allTests(); - endToEndTests(); -} - -DartFormatter formatter = new DartFormatter(); -AnnotationMatcher annotationMatcher; - -void allTests() { - TestAssetReader absoluteReader; - - setUp(() { - absoluteReader = new TestAssetReader(); - annotationMatcher = new AnnotationMatcher(); - }); - - test('should inline `templateUrl` values', () async { - var output = await _testInline( - absoluteReader, _assetId('url_expression_files/hello.dart')); - expect(output, isNotNull); - expect(() => formatter.format(output), returnsNormally); - expect(output, contains("r'''{{greeting}}'''")); - }); - - test( - 'should inline `templateUrl` and `styleUrls` values expressed as ' - 'absolute urls.', () async { - absoluteReader.addAsset( - new AssetId('other_package', 'lib/template.html'), - readFile( - 'inliner_for_test/absolute_url_expression_files/template.html')); - absoluteReader.addAsset( - new AssetId('other_package', 'lib/template.css'), - readFile( - 'inliner_for_test/absolute_url_expression_files/template.css')); - - var output = await _testInline( - absoluteReader, _assetId('absolute_url_expression_files/hello.dart')); - - expect(output, isNotNull); - expect(() => formatter.format(output), returnsNormally); - - expect(output, contains("r'''{{greeting}}'''")); - expect(output, contains("r'''.greeting { .color: blue; }'''")); - }); - - test('should inline multiple `styleUrls` values expressed as absolute urls.', - () async { - absoluteReader - ..addAsset(new AssetId('other_package', 'lib/template.html'), '') - ..addAsset(new AssetId('other_package', 'lib/template.css'), ''); - var output = await _testInline( - absoluteReader, _assetId('multiple_style_urls_files/hello.dart')); - - expect(output, isNotNull); - expect(() => formatter.format(output), returnsNormally); - - expect(output, contains("r'''.greeting { .color: blue; }'''")); - expect(output, contains("r'''.hello { .color: red; }'''")); - }); - - test('should inline `templateUrl`s expressed as adjacent strings.', () async { - var output = await _testInline( - absoluteReader, _assetId('split_url_expression_files/hello.dart')); - - expect(output, isNotNull); - expect(() => formatter.format(output), returnsNormally); - - expect(output, contains("{{greeting}}")); - }); - - test('should not inline values outside of View/Component annotations', - () async { - var output = await _testInline( - absoluteReader, _assetId('false_match_files/hello.dart')); - - expect(output, isNotNull); - expect(output, isNot(contains('{{greeting}}'))); - expect(output, contains('.greeting { .color: blue; }')); - }); - - test('should not modify files with no `templateUrl` or `styleUrls` values.', - () async { - var output = await _testInline( - absoluteReader, _assetId('no_modify_files/hello.dart')); - - expect(output, isNull); - }); - - test('should not strip property annotations.', () async { - // Regression test for https://github.com/dart-lang/sdk/issues/24578 - var output = await _testInline( - absoluteReader, _assetId('prop_annotations_files/hello.dart')); - - expect(output, contains('@Attribute(\'thing\')')); - }); - - test('should maintain line numbers for long `templateUrl` values', () async { - // Regression test for https://github.com/angular/angular/issues/5281 - final templateUrlVal = - 'supersupersupersupersupersupersupersupersupersupersupersuper' - 'superlongtemplate.html'; - absoluteReader.addAsset( - _assetId('multiline_template/$templateUrlVal'), '{{greeting}}'); - var output = await _testInline( - absoluteReader, _assetId('multiline_template/hello.dart')); - expect(output, isNotNull); - expect(() => formatter.format(output), returnsNormally); - expect(output, contains("r'''{{greeting}}'''")); - expect(output, contains('template: _template0\n')); - }); - - test('should maintain line numbers when replacing values', () async { - // Regression test for https://github.com/angular/angular/issues/5281 - final templateUrlVal = - 'supersupersupersupersupersupersupersupersupersupersupersuper' - 'superlongtemplate.html'; - final t1Styles = '.body { color: green; }'; - final t2Styles = '.div { color: red; }'; - absoluteReader.addAsset( - _assetId('multiline_template/$templateUrlVal'), '{{greeting}}'); - absoluteReader.addAsset( - _assetId('multiline_template/pretty_longish_template.css'), t1Styles); - absoluteReader.addAsset( - _assetId('multiline_template/other_pretty_longish_template.css'), - t2Styles); - var output = await _testInline( - absoluteReader, _assetId('multiline_template/hello.dart')); - expect(output, isNotNull); - expect(() => formatter.format(output), returnsNormally); - expect(output, contains("r'''{{greeting}}'''")); - expect(output, contains("r'''$t1Styles'''")); - expect(output, contains("r'''$t2Styles'''")); - - final splitter = const LineSplitter(); - final inputLines = - splitter.convert(_readFile('multiline_template/hello.dart')); - final outputLines = splitter.convert(output); - - expect(outputLines.indexOf('class HelloCmp {}'), - equals(inputLines.indexOf('class HelloCmp {}'))); - }); -} - -void endToEndTests() { - _runAbsoluteUrlEndToEndTest(); - _runMultiStylesEndToEndTest(); -} - -Future _testInline(AssetReader reader, AssetId assetId) { - return zone.exec(() => inline(reader, assetId, annotationMatcher), - log: new RecordingLogger()); -} - -AssetId _assetId(String path) => new AssetId('a', 'inliner_for_test/$path'); - -void _runAbsoluteUrlEndToEndTest() { - var options = new TransformerOptions([], inlineViews: true, formatCode: true); - InlinerForTest transformer = new InlinerForTest(options); - var inputMap = { - 'a|absolute_url_expression_files/hello.dart': - _readFile('absolute_url_expression_files/hello.dart'), - 'other_package|lib/template.css': - _readFile('absolute_url_expression_files/template.css'), - 'other_package|lib/template.html': - _readFile('absolute_url_expression_files/template.html') - }; - var outputMap = { - 'a|absolute_url_expression_files/hello.dart': - _readFile('absolute_url_expression_files/expected/hello.dart') - }; - testPhases( - 'Inliner For Test should inline `templateUrl` and `styleUrls` values ' - 'expressed as absolute urls', - [ - [transformer] - ], - inputMap, - outputMap); -} - -void _runMultiStylesEndToEndTest() { - var options = new TransformerOptions([], inlineViews: true, formatCode: true); - InlinerForTest transformer = new InlinerForTest(options); - var inputMap = { - 'pkg|web/hello.dart': _readFile('multiple_style_urls_files/hello.dart'), - 'pkg|web/template.css': _readFile('multiple_style_urls_files/template.css'), - 'pkg|web/template_other.css': - _readFile('multiple_style_urls_files/template_other.css'), - 'pkg|web/template.html': - _readFile('multiple_style_urls_files/template.html') - }; - var outputMap = { - 'pkg|web/hello.dart': - _readFile('multiple_style_urls_files/expected/hello.dart') - }; - testPhases( - 'Inliner For Test should inline `templateUrl` and `styleUrls` values ' - 'expressed as relative urls', - [ - [transformer] - ], - inputMap, - outputMap); -} - -/// Smooths over differences in CWD between IDEs and running tests in Travis. -String _readFile(String path) { - var code = readFile('inliner_for_test/$path'); - if (path.endsWith('.dart')) { - code = formatter.format(code); - } - return code; -} diff --git a/modules_dart/transform/test/transform/inliner_for_test/false_match_files/hello.dart b/modules_dart/transform/test/transform/inliner_for_test/false_match_files/hello.dart deleted file mode 100644 index 85baa92b79..0000000000 --- a/modules_dart/transform/test/transform/inliner_for_test/false_match_files/hello.dart +++ /dev/null @@ -1,12 +0,0 @@ -library angular2.test.transform.inliner_for_test.false_match_files; - -import 'package:angular2/angular2.dart' - show Component, Directive, View, NgElement; - -@Component(selector: 'hello-app') -@View(styleUrls: const ['template.css']) -class HelloCmp {} - -void main() { - final testThing = new Component(templateUrl: 'template.html'); -} diff --git a/modules_dart/transform/test/transform/inliner_for_test/false_match_files/template.css b/modules_dart/transform/test/transform/inliner_for_test/false_match_files/template.css deleted file mode 100644 index c48477652e..0000000000 --- a/modules_dart/transform/test/transform/inliner_for_test/false_match_files/template.css +++ /dev/null @@ -1 +0,0 @@ -.greeting { .color: blue; } \ No newline at end of file diff --git a/modules_dart/transform/test/transform/inliner_for_test/false_match_files/template.html b/modules_dart/transform/test/transform/inliner_for_test/false_match_files/template.html deleted file mode 100644 index d75013393f..0000000000 --- a/modules_dart/transform/test/transform/inliner_for_test/false_match_files/template.html +++ /dev/null @@ -1 +0,0 @@ -{{greeting}} \ No newline at end of file diff --git a/modules_dart/transform/test/transform/inliner_for_test/multiline_template/hello.dart b/modules_dart/transform/test/transform/inliner_for_test/multiline_template/hello.dart deleted file mode 100644 index d33fd5bb5c..0000000000 --- a/modules_dart/transform/test/transform/inliner_for_test/multiline_template/hello.dart +++ /dev/null @@ -1,14 +0,0 @@ -library playground.src.hello_world.url_expression_files; - -import 'package:angular2/angular2.dart' - show Component, Directive, View, NgElement; - -@Component(selector: 'hello-app') -@View( - templateUrl: 'supersupersupersupersupersupersupersupersupersupersupersuper' - 'superlongtemplate.html', - styleUrls: const [ - 'pretty_longish_template.css', - 'other_pretty_longish_template.css' - ]) -class HelloCmp {} diff --git a/modules_dart/transform/test/transform/inliner_for_test/multiple_style_urls_files/expected/hello.dart b/modules_dart/transform/test/transform/inliner_for_test/multiple_style_urls_files/expected/hello.dart deleted file mode 100644 index db46c02ace..0000000000 --- a/modules_dart/transform/test/transform/inliner_for_test/multiple_style_urls_files/expected/hello.dart +++ /dev/null @@ -1,12 +0,0 @@ -library playground.src.hello_world.multiple_style_urls_files; - -import 'package:angular2/angular2.dart' - show Component, Directive, View, NgElement; - -@Component(selector: 'hello-app') -@View(template: _template0, styles: const [_style1, _style2,]) -class HelloCmp {} - -const _template0 = r'''{{greeting}}'''; -const _style1 = r'''.greeting { .color: blue; }'''; -const _style2 = r'''.hello { .color: red; }'''; diff --git a/modules_dart/transform/test/transform/inliner_for_test/multiple_style_urls_files/hello.dart b/modules_dart/transform/test/transform/inliner_for_test/multiple_style_urls_files/hello.dart deleted file mode 100644 index 1829a04a07..0000000000 --- a/modules_dart/transform/test/transform/inliner_for_test/multiple_style_urls_files/hello.dart +++ /dev/null @@ -1,10 +0,0 @@ -library playground.src.hello_world.multiple_style_urls_files; - -import 'package:angular2/angular2.dart' - show Component, Directive, View, NgElement; - -@Component(selector: 'hello-app') -@View( - templateUrl: 'template.html', - styleUrls: const ['template.css', 'template_other.css']) -class HelloCmp {} diff --git a/modules_dart/transform/test/transform/inliner_for_test/multiple_style_urls_files/template.css b/modules_dart/transform/test/transform/inliner_for_test/multiple_style_urls_files/template.css deleted file mode 100644 index c48477652e..0000000000 --- a/modules_dart/transform/test/transform/inliner_for_test/multiple_style_urls_files/template.css +++ /dev/null @@ -1 +0,0 @@ -.greeting { .color: blue; } \ No newline at end of file diff --git a/modules_dart/transform/test/transform/inliner_for_test/multiple_style_urls_files/template.html b/modules_dart/transform/test/transform/inliner_for_test/multiple_style_urls_files/template.html deleted file mode 100644 index d75013393f..0000000000 --- a/modules_dart/transform/test/transform/inliner_for_test/multiple_style_urls_files/template.html +++ /dev/null @@ -1 +0,0 @@ -{{greeting}} \ No newline at end of file diff --git a/modules_dart/transform/test/transform/inliner_for_test/multiple_style_urls_files/template_other.css b/modules_dart/transform/test/transform/inliner_for_test/multiple_style_urls_files/template_other.css deleted file mode 100644 index e461b8ddde..0000000000 --- a/modules_dart/transform/test/transform/inliner_for_test/multiple_style_urls_files/template_other.css +++ /dev/null @@ -1 +0,0 @@ -.hello { .color: red; } \ No newline at end of file diff --git a/modules_dart/transform/test/transform/inliner_for_test/no_modify_files/hello.dart b/modules_dart/transform/test/transform/inliner_for_test/no_modify_files/hello.dart deleted file mode 100644 index fc2ded50bd..0000000000 --- a/modules_dart/transform/test/transform/inliner_for_test/no_modify_files/hello.dart +++ /dev/null @@ -1,8 +0,0 @@ -library angular2.test.transform.inliner_for_test.false_match_files; - -import 'package:angular2/angular2.dart' - show Component, Directive, View, NgElement; - -part 'hello_part.dart'; - -void main() {} diff --git a/modules_dart/transform/test/transform/inliner_for_test/no_modify_files/hello_part.dart b/modules_dart/transform/test/transform/inliner_for_test/no_modify_files/hello_part.dart deleted file mode 100644 index ece667e5d8..0000000000 --- a/modules_dart/transform/test/transform/inliner_for_test/no_modify_files/hello_part.dart +++ /dev/null @@ -1,3 +0,0 @@ -part of angular2.test.transform.inliner_for_test.false_match_files; - -void doStuff() {} diff --git a/modules_dart/transform/test/transform/inliner_for_test/prop_annotations_files/hello.dart b/modules_dart/transform/test/transform/inliner_for_test/prop_annotations_files/hello.dart deleted file mode 100644 index b64302c1ee..0000000000 --- a/modules_dart/transform/test/transform/inliner_for_test/prop_annotations_files/hello.dart +++ /dev/null @@ -1,10 +0,0 @@ -library angular2.test.transform.inliner_for_test.false_match_files; - -import 'package:angular2/angular2.dart' - show Component, Directive, View, NgElement; - -@Component(selector: 'hello-app') -@View(styleUrls: const ['template.css']) -class HelloCmp { - HelloCmp(@Attribute('thing') String thing); -} diff --git a/modules_dart/transform/test/transform/inliner_for_test/prop_annotations_files/template.css b/modules_dart/transform/test/transform/inliner_for_test/prop_annotations_files/template.css deleted file mode 100644 index c48477652e..0000000000 --- a/modules_dart/transform/test/transform/inliner_for_test/prop_annotations_files/template.css +++ /dev/null @@ -1 +0,0 @@ -.greeting { .color: blue; } \ No newline at end of file diff --git a/modules_dart/transform/test/transform/inliner_for_test/split_url_expression_files/hello.dart b/modules_dart/transform/test/transform/inliner_for_test/split_url_expression_files/hello.dart deleted file mode 100644 index a60c8680b4..0000000000 --- a/modules_dart/transform/test/transform/inliner_for_test/split_url_expression_files/hello.dart +++ /dev/null @@ -1,8 +0,0 @@ -library playground.src.hello_world.split_url_expression_files; - -import 'package:angular2/angular2.dart' - show Component, Directive, View, NgElement; - -@Component(selector: 'hello-app') -@View(templateUrl: 'templ' 'ate.html') -class HelloCmp {} diff --git a/modules_dart/transform/test/transform/inliner_for_test/split_url_expression_files/template.html b/modules_dart/transform/test/transform/inliner_for_test/split_url_expression_files/template.html deleted file mode 100644 index d75013393f..0000000000 --- a/modules_dart/transform/test/transform/inliner_for_test/split_url_expression_files/template.html +++ /dev/null @@ -1 +0,0 @@ -{{greeting}} \ No newline at end of file diff --git a/modules_dart/transform/test/transform/inliner_for_test/url_expression_files/hello.dart b/modules_dart/transform/test/transform/inliner_for_test/url_expression_files/hello.dart deleted file mode 100644 index b2404c9329..0000000000 --- a/modules_dart/transform/test/transform/inliner_for_test/url_expression_files/hello.dart +++ /dev/null @@ -1,8 +0,0 @@ -library playground.src.hello_world.url_expression_files; - -import 'package:angular2/angular2.dart' - show Component, Directive, View, NgElement; - -@Component(selector: 'hello-app') -@View(templateUrl: 'template.html') -class HelloCmp {} diff --git a/modules_dart/transform/test/transform/inliner_for_test/url_expression_files/template.html b/modules_dart/transform/test/transform/inliner_for_test/url_expression_files/template.html deleted file mode 100644 index d75013393f..0000000000 --- a/modules_dart/transform/test/transform/inliner_for_test/url_expression_files/template.html +++ /dev/null @@ -1 +0,0 @@ -{{greeting}} \ No newline at end of file diff --git a/modules_dart/transform/test/transform/integration/all_tests.dart b/modules_dart/transform/test/transform/integration/all_tests.dart deleted file mode 100644 index 4387ca1850..0000000000 --- a/modules_dart/transform/test/transform/integration/all_tests.dart +++ /dev/null @@ -1,198 +0,0 @@ -library angular2.test.transform.integration; - -import 'package:angular2/src/platform/server/html_adapter.dart'; -import 'package:angular2/transformer.dart'; -import 'package:dart_style/dart_style.dart'; -import 'package:transformer_test/utils.dart'; - -import '../common/read_file.dart'; -import 'deferred_files/expected/output.dart' as deferredOuts; - -main() { - allTests(); -} - -var formatter = new DartFormatter(); -var transform = new AngularTransformerGroup(new TransformerOptions( - ['web/index.dart'], - formatCode: true, - genCompiledTemplates: false)); - -// Each test has its own directory for inputs & an `expected` directory for -// expected outputs. -// -// In addition to these declared inputs, we inject a set of common inputs for -// every test. -const commonInputs = const { - 'angular2|lib/src/core/metadata.dart': '../../../lib/src/core/metadata.dart', - 'angular2|lib/src/core/application.dart': '../common/application.dart', - 'angular2|lib/src/core/reflection/reflection_capabilities.dart': - '../common/reflection_capabilities.dart', - 'angular2|lib/core.dart': '../../../lib/core.dart', - 'angular2|lib/src/core/di/decorators.dart': - '../../../lib/src/core/di/decorators.dart', -}; - -class IntegrationTestConfig { - final String name; - final Map assetPathToInputPath; - final Map assetPathToExpectedOutputPath; - final bool isolate; - - IntegrationTestConfig(this.name, - {Map inputs, - Map outputs, - this.isolate: false}) - : this.assetPathToInputPath = inputs, - this.assetPathToExpectedOutputPath = outputs; -} - -void allTests() { - Html5LibDomAdapter.makeCurrent(); - - var tests = [ - new IntegrationTestConfig('should generate proper code for a Component defining only a selector.', - inputs: { - 'a|web/index.dart': 'simple_annotation_files/index.dart', - 'a|web/bar.dart': 'simple_annotation_files/bar.dart' - }, - outputs: { - 'a|web/bar.ngfactory.dart': - 'simple_annotation_files/expected/bar.ngfactory.dart', - 'a|web/index.ngfactory.dart': - 'simple_annotation_files/expected/index.ngfactory.dart' - }), - new IntegrationTestConfig('should generate proper code for a Component with multiple deps.', - inputs: { - 'a|web/index.dart': 'two_deps_files/index.dart', - 'a|web/foo.dart': 'two_deps_files/foo.dart', - 'a|web/bar.dart': 'two_deps_files/bar.dart' - }, - outputs: { - 'a|web/bar.ngfactory.dart': 'two_deps_files/expected/bar.ngfactory.dart' - }), - new IntegrationTestConfig( - 'should generate proper code for a Component declaring a ' - 'componentService defined in another file.', - inputs: { - 'a|web/index.dart': 'list_of_types_files/index.dart', - 'a|web/foo.dart': 'list_of_types_files/foo.dart', - 'a|web/bar.dart': 'list_of_types_files/bar.dart' - }, - outputs: { - 'a|web/bar.ngfactory.dart': - 'list_of_types_files/expected/bar.ngfactory.dart' - }), - new IntegrationTestConfig('should generate a factory for a class with no declared ctor.', - inputs: { - 'a|web/index.dart': 'synthetic_ctor_files/index.dart', - 'a|web/bar.dart': 'synthetic_ctor_files/bar.dart' - }, - outputs: { - 'a|web/bar.ngfactory.dart': - 'synthetic_ctor_files/expected/bar.ngfactory.dart' - }), - new IntegrationTestConfig('should preserve multiple annotations.', inputs: { - 'a|web/index.dart': 'two_annotations_files/index.dart', - 'a|web/bar.dart': 'two_annotations_files/bar.dart', - 'angular2|lib/src/core/metadata.dart': - '../../../lib/src/core/metadata.dart' - }, outputs: { - 'a|web/bar.ngfactory.dart': - 'two_annotations_files/expected/bar.ngfactory.dart' - }), - new IntegrationTestConfig( - 'should handle Directive dependencies declared on a View.', - inputs: { - 'a|web/index.dart': 'directive_dep_files/index.dart', - 'a|web/foo.dart': 'directive_dep_files/foo.dart', - 'a|web/bar.dart': 'directive_dep_files/bar.dart' - }, - outputs: { - 'a|web/bar.ngfactory.dart': - 'directive_dep_files/expected/bar.ngfactory.dart' - }), - new IntegrationTestConfig('should handle chained Directive dependencies declared on a View.', - inputs: { - 'a|web/index.dart': 'directive_chain_files/index.dart', - 'a|web/foo.dart': 'directive_chain_files/foo.dart', - 'a|web/bar.dart': 'directive_chain_files/bar.dart', - 'a|web/baz.dart': 'directive_chain_files/baz.dart' - }, - outputs: { - 'a|web/bar.ngfactory.dart': - 'directive_chain_files/expected/bar.ngfactory.dart' - }), - new IntegrationTestConfig('should handle empty template files that define directive aliases.', - inputs: { - 'a|web/foo.dart': 'empty_ng_deps_files/foo.dart', - 'a|web/bar.dart': 'empty_ng_deps_files/bar.dart' - }, - outputs: { - 'a|web/foo.ngfactory.dart': - 'empty_ng_deps_files/expected/foo.ngfactory.dart', - 'a|web/bar.ngfactory.dart': - 'empty_ng_deps_files/expected/bar.ngfactory.dart' - }) - ]; - - var cache = {}; - - var isolateAny = tests.any((t) => t.isolate); - - for (var config in tests) { - // Read in input & output files. - config.assetPathToInputPath - ..addAll(commonInputs) - ..forEach((key, value) { - config.assetPathToInputPath[key] = - cache.putIfAbsent(value, () => _readFile(value)); - }); - config.assetPathToExpectedOutputPath.forEach((key, value) { - config.assetPathToExpectedOutputPath[key] = cache.putIfAbsent(value, () { - var code = _readFile(value); - if (code == null) { - throw 'Failed to read $value'; - } - return value.endsWith('dart') ? formatter.format(code) : code; - }); - }); - if (!isolateAny || config.isolate) { - testPhases( - config.name, - [ - [transform] - ], - config.assetPathToInputPath, - config.assetPathToExpectedOutputPath); - } - } - - _testDeferredRewriter(); -} - -void _testDeferredRewriter() { - var inputs = { - 'a|web/bar.dart': 'deferred_files/bar.dart', - 'a|web/dep.dart': 'deferred_files/dep.dart', - 'a|web/index.dart': 'deferred_files/index.dart' - }; - inputs.addAll(commonInputs); - inputs.keys.forEach((k) => inputs[k] = _readFile(inputs[k])); - var outputs = { - 'a|web/bar.ngfactory.dart': - _readFile('deferred_files/expected/bar.ngfactory.dart'), - 'a|web/bar.dart': deferredOuts.barContents, - 'a|web/index.dart': deferredOuts.indexContents - }; - testPhases( - 'should handle deferred imports in input files.', - [ - [transform] - ], - inputs, - outputs); -} - -/// Smooths over differences in CWD between IDEs and running tests in Travis. -String _readFile(String path) => readFile('integration/$path'); diff --git a/modules_dart/transform/test/transform/integration/deferred_files/bar.dart b/modules_dart/transform/test/transform/integration/deferred_files/bar.dart deleted file mode 100644 index 8ebf3294b8..0000000000 --- a/modules_dart/transform/test/transform/integration/deferred_files/bar.dart +++ /dev/null @@ -1,17 +0,0 @@ -library bar; - -import 'package:angular2/src/core/metadata.dart'; - -import 'dep.dart' deferred as dep; - -@Component(selector: '[soup]') -@View(template: '') -class MyComponent { - void doDeferredThing() { - dep.loadLibrary().then((_) { - dep.doImmediateThing(); - }); - } -} - -void execImmediate() {} diff --git a/modules_dart/transform/test/transform/integration/deferred_files/dep.dart b/modules_dart/transform/test/transform/integration/deferred_files/dep.dart deleted file mode 100644 index ba8d5563e4..0000000000 --- a/modules_dart/transform/test/transform/integration/deferred_files/dep.dart +++ /dev/null @@ -1,6 +0,0 @@ -library dep; - -import 'package:angular2/src/core/metadata.dart'; - -@Injectable() -void doImmediateThing() {} diff --git a/modules_dart/transform/test/transform/integration/deferred_files/expected/bar.ngfactory.dart b/modules_dart/transform/test/transform/integration/deferred_files/expected/bar.ngfactory.dart deleted file mode 100644 index 26fadd6c95..0000000000 --- a/modules_dart/transform/test/transform/integration/deferred_files/expected/bar.ngfactory.dart +++ /dev/null @@ -1,19 +0,0 @@ -library bar.ngfactory.dart; - -import 'bar.dart'; -import 'package:angular2/src/core/reflection/reflection.dart' as _ngRef; -import 'package:angular2/src/core/metadata.dart'; -import 'package:angular2/src/core/metadata.ngfactory.dart' as i0; -export 'bar.dart'; - -var _visited = false; -void initReflector() { - if (_visited) return; - _visited = true; - _ngRef.reflector - ..registerType( - MyComponent, - new _ngRef.ReflectionInfo( - const [MyComponentNgFactory], const [], () => new MyComponent())); - i0.initReflector(); -} diff --git a/modules_dart/transform/test/transform/integration/deferred_files/expected/output.dart b/modules_dart/transform/test/transform/integration/deferred_files/expected/output.dart deleted file mode 100644 index 93ea0f9cc8..0000000000 --- a/modules_dart/transform/test/transform/integration/deferred_files/expected/output.dart +++ /dev/null @@ -1,38 +0,0 @@ -library angular2.test.transform.integration.deferred; - -// This stored as a constant because we need to be careful to avoid modifying -// source lines for files we rewrite. -// That is, we expect that modifications we make to input files do not change -// line numbers, and storing this expected output as code would allow it to be -// formatted, breaking our tests. -const indexContents = ''' -library web_foo; - -import 'index.ngfactory.dart' as ngStaticInit;import 'bar.ngfactory.dart' deferred as bar; - -void main() { - bar.loadLibrary().then((_) {bar.initReflector();}).then((_) { - bar.execImmediate(); - }); -} -'''; - -const barContents = ''' -library bar; - -import 'package:angular2/src/core/metadata.dart'; - -import 'dep.ngfactory.dart' deferred as dep; - -@Component(selector: '[soup]') -@View(template: '') -class MyComponent { - void doDeferredThing() { - dep.loadLibrary().then((_) {dep.initReflector();}).then((_) { - dep.doImmediateThing(); - }); - } -} - -void execImmediate() {} -'''; diff --git a/modules_dart/transform/test/transform/integration/deferred_files/index.dart b/modules_dart/transform/test/transform/integration/deferred_files/index.dart deleted file mode 100644 index 1ed56aacd7..0000000000 --- a/modules_dart/transform/test/transform/integration/deferred_files/index.dart +++ /dev/null @@ -1,9 +0,0 @@ -library web_foo; - -import 'bar.dart' deferred as bar; - -void main() { - bar.loadLibrary().then((_) { - bar.execImmediate(); - }); -} diff --git a/modules_dart/transform/test/transform/integration/directive_chain_files/bar.dart b/modules_dart/transform/test/transform/integration/directive_chain_files/bar.dart deleted file mode 100644 index 1282709fda..0000000000 --- a/modules_dart/transform/test/transform/integration/directive_chain_files/bar.dart +++ /dev/null @@ -1,10 +0,0 @@ -library bar; - -import 'package:angular2/src/core/metadata.dart'; -import 'baz.dart'; - -@Component(selector: 'soup') -@View(template: 'foo', directives: [Foo]) -class MyComponent { - MyComponent(); -} diff --git a/modules_dart/transform/test/transform/integration/directive_chain_files/baz.dart b/modules_dart/transform/test/transform/integration/directive_chain_files/baz.dart deleted file mode 100644 index 946cb3f2a3..0000000000 --- a/modules_dart/transform/test/transform/integration/directive_chain_files/baz.dart +++ /dev/null @@ -1,3 +0,0 @@ -library baz; - -export 'foo.dart'; diff --git a/modules_dart/transform/test/transform/integration/directive_chain_files/expected/bar.ngfactory.dart b/modules_dart/transform/test/transform/integration/directive_chain_files/expected/bar.ngfactory.dart deleted file mode 100644 index 7e5d99886c..0000000000 --- a/modules_dart/transform/test/transform/integration/directive_chain_files/expected/bar.ngfactory.dart +++ /dev/null @@ -1,22 +0,0 @@ -library bar.ngfactory.dart; - -import 'bar.dart'; -import 'package:angular2/src/core/reflection/reflection.dart' as _ngRef; -import 'package:angular2/src/core/metadata.dart'; -import 'baz.dart'; -import 'package:angular2/src/core/metadata.ngfactory.dart' as i0; -import 'baz.ngfactory.dart' as i1; -export 'bar.dart'; - -var _visited = false; -void initReflector() { - if (_visited) return; - _visited = true; - _ngRef.reflector - ..registerType( - MyComponent, - new _ngRef.ReflectionInfo( - const [MyComponentNgFactory], const [], () => new MyComponent())); - i0.initReflector(); - i1.initReflector(); -} diff --git a/modules_dart/transform/test/transform/integration/directive_chain_files/foo.dart b/modules_dart/transform/test/transform/integration/directive_chain_files/foo.dart deleted file mode 100644 index 681db2bebe..0000000000 --- a/modules_dart/transform/test/transform/integration/directive_chain_files/foo.dart +++ /dev/null @@ -1,6 +0,0 @@ -library foo; - -import 'package:angular2/src/core/metadata.dart'; - -@Directive(selector: 'foo') -class Foo {} diff --git a/modules_dart/transform/test/transform/integration/directive_chain_files/index.dart b/modules_dart/transform/test/transform/integration/directive_chain_files/index.dart deleted file mode 100644 index 7acd07896f..0000000000 --- a/modules_dart/transform/test/transform/integration/directive_chain_files/index.dart +++ /dev/null @@ -1,10 +0,0 @@ -library web_foo; - -import 'package:angular2/platform/browser.dart'; -import 'package:angular2/src/core/reflection/reflection_capabilities.dart'; -import 'bar.dart'; - -void main() { - reflector.reflectionCapabilities = new ReflectionCapabilities(); - bootstrap(MyComponent); -} diff --git a/modules_dart/transform/test/transform/integration/directive_dep_files/bar.dart b/modules_dart/transform/test/transform/integration/directive_dep_files/bar.dart deleted file mode 100644 index 99c25ce160..0000000000 --- a/modules_dart/transform/test/transform/integration/directive_dep_files/bar.dart +++ /dev/null @@ -1,10 +0,0 @@ -library bar; - -import 'package:angular2/src/core/metadata.dart'; -import 'foo.dart' as prefix; - -@Component(selector: 'soup') -@View(template: 'foo', directives: [prefix.Foo]) -class MyComponent { - MyComponent(); -} diff --git a/modules_dart/transform/test/transform/integration/directive_dep_files/expected/bar.ngfactory.dart b/modules_dart/transform/test/transform/integration/directive_dep_files/expected/bar.ngfactory.dart deleted file mode 100644 index eb2d3cb173..0000000000 --- a/modules_dart/transform/test/transform/integration/directive_dep_files/expected/bar.ngfactory.dart +++ /dev/null @@ -1,22 +0,0 @@ -library bar.ngfactory.dart; - -import 'bar.dart'; -import 'package:angular2/src/core/reflection/reflection.dart' as _ngRef; -import 'package:angular2/src/core/metadata.dart'; -import 'foo.dart' as prefix; -import 'package:angular2/src/core/metadata.ngfactory.dart' as i0; -import 'foo.ngfactory.dart' as i1; -export 'bar.dart'; - -var _visited = false; -void initReflector() { - if (_visited) return; - _visited = true; - _ngRef.reflector - ..registerType( - MyComponent, - new _ngRef.ReflectionInfo( - const [MyComponentNgFactory], const [], () => new MyComponent())); - i0.initReflector(); - i1.initReflector(); -} diff --git a/modules_dart/transform/test/transform/integration/directive_dep_files/foo.dart b/modules_dart/transform/test/transform/integration/directive_dep_files/foo.dart deleted file mode 100644 index 681db2bebe..0000000000 --- a/modules_dart/transform/test/transform/integration/directive_dep_files/foo.dart +++ /dev/null @@ -1,6 +0,0 @@ -library foo; - -import 'package:angular2/src/core/metadata.dart'; - -@Directive(selector: 'foo') -class Foo {} diff --git a/modules_dart/transform/test/transform/integration/directive_dep_files/index.dart b/modules_dart/transform/test/transform/integration/directive_dep_files/index.dart deleted file mode 100644 index 7acd07896f..0000000000 --- a/modules_dart/transform/test/transform/integration/directive_dep_files/index.dart +++ /dev/null @@ -1,10 +0,0 @@ -library web_foo; - -import 'package:angular2/platform/browser.dart'; -import 'package:angular2/src/core/reflection/reflection_capabilities.dart'; -import 'bar.dart'; - -void main() { - reflector.reflectionCapabilities = new ReflectionCapabilities(); - bootstrap(MyComponent); -} diff --git a/modules_dart/transform/test/transform/integration/empty_ng_deps_files/bar.dart b/modules_dart/transform/test/transform/integration/empty_ng_deps_files/bar.dart deleted file mode 100644 index 1366238d86..0000000000 --- a/modules_dart/transform/test/transform/integration/empty_ng_deps_files/bar.dart +++ /dev/null @@ -1,3 +0,0 @@ -library bar; - -const directiveAlias = const []; diff --git a/modules_dart/transform/test/transform/integration/empty_ng_deps_files/expected/bar.ngfactory.dart b/modules_dart/transform/test/transform/integration/empty_ng_deps_files/expected/bar.ngfactory.dart deleted file mode 100644 index b03ae1c795..0000000000 --- a/modules_dart/transform/test/transform/integration/empty_ng_deps_files/expected/bar.ngfactory.dart +++ /dev/null @@ -1 +0,0 @@ -initReflector() {} diff --git a/modules_dart/transform/test/transform/integration/empty_ng_deps_files/expected/foo.ngfactory.dart b/modules_dart/transform/test/transform/integration/empty_ng_deps_files/expected/foo.ngfactory.dart deleted file mode 100644 index 946e4f54fd..0000000000 --- a/modules_dart/transform/test/transform/integration/empty_ng_deps_files/expected/foo.ngfactory.dart +++ /dev/null @@ -1,22 +0,0 @@ -library bar.ngfactory.dart; - -import 'foo.dart'; -import 'package:angular2/src/core/reflection/reflection.dart' as _ngRef; -import 'package:angular2/src/core/metadata.dart'; -import 'bar.dart'; -import 'package:angular2/src/core/metadata.ngfactory.dart' as i0; -import 'bar.ngfactory.dart' as i1; -export 'foo.dart'; - -var _visited = false; -void initReflector() { - if (_visited) return; - _visited = true; - _ngRef.reflector - ..registerType( - MyComponent, - new _ngRef.ReflectionInfo( - const [MyComponentNgFactory], const [], () => new MyComponent())); - i0.initReflector(); - i1.initReflector(); -} diff --git a/modules_dart/transform/test/transform/integration/empty_ng_deps_files/foo.dart b/modules_dart/transform/test/transform/integration/empty_ng_deps_files/foo.dart deleted file mode 100644 index 4184acbdb9..0000000000 --- a/modules_dart/transform/test/transform/integration/empty_ng_deps_files/foo.dart +++ /dev/null @@ -1,8 +0,0 @@ -library bar; - -import 'package:angular2/src/core/metadata.dart'; -import 'bar.dart'; - -@Component(selector: '[soup]') -@View(template: '', directives: const [directiveAlias]) -class MyComponent {} diff --git a/modules_dart/transform/test/transform/integration/list_of_types_files/bar.dart b/modules_dart/transform/test/transform/integration/list_of_types_files/bar.dart deleted file mode 100644 index 5422f073a0..0000000000 --- a/modules_dart/transform/test/transform/integration/list_of_types_files/bar.dart +++ /dev/null @@ -1,11 +0,0 @@ -library bar; - -import 'package:angular2/src/core/metadata.dart'; -import 'foo.dart'; - -@Component(selector: 'my', providers: const [MyContext]) -@View(template: '') -class MyComponent { - final MyContext c; - MyComponent(this.c); -} diff --git a/modules_dart/transform/test/transform/integration/list_of_types_files/expected/bar.ngfactory.dart b/modules_dart/transform/test/transform/integration/list_of_types_files/expected/bar.ngfactory.dart deleted file mode 100644 index d8703aa8a7..0000000000 --- a/modules_dart/transform/test/transform/integration/list_of_types_files/expected/bar.ngfactory.dart +++ /dev/null @@ -1,23 +0,0 @@ -library bar.ngfactory.dart; - -import 'bar.dart'; -import 'package:angular2/src/core/reflection/reflection.dart' as _ngRef; -import 'package:angular2/src/core/metadata.dart'; -import 'foo.dart'; -import 'package:angular2/src/core/metadata.ngfactory.dart' as i0; -import 'foo.ngfactory.dart' as i1; -export 'bar.dart'; - -var _visited = false; -void initReflector() { - if (_visited) return; - _visited = true; - _ngRef.reflector - ..registerType( - MyComponent, - new _ngRef.ReflectionInfo(const [MyComponentNgFactory], const [ - const [MyContext] - ], (MyContext c) => new MyComponent(c))); - i0.initReflector(); - i1.initReflector(); -} diff --git a/modules_dart/transform/test/transform/integration/list_of_types_files/foo.dart b/modules_dart/transform/test/transform/integration/list_of_types_files/foo.dart deleted file mode 100644 index 5579612e44..0000000000 --- a/modules_dart/transform/test/transform/integration/list_of_types_files/foo.dart +++ /dev/null @@ -1,6 +0,0 @@ -library foo; - -class MyContext { - final String s; - const MyContext(this.s); -} diff --git a/modules_dart/transform/test/transform/integration/list_of_types_files/index.dart b/modules_dart/transform/test/transform/integration/list_of_types_files/index.dart deleted file mode 100644 index 7acd07896f..0000000000 --- a/modules_dart/transform/test/transform/integration/list_of_types_files/index.dart +++ /dev/null @@ -1,10 +0,0 @@ -library web_foo; - -import 'package:angular2/platform/browser.dart'; -import 'package:angular2/src/core/reflection/reflection_capabilities.dart'; -import 'bar.dart'; - -void main() { - reflector.reflectionCapabilities = new ReflectionCapabilities(); - bootstrap(MyComponent); -} diff --git a/modules_dart/transform/test/transform/integration/simple_annotation_files/bar.dart b/modules_dart/transform/test/transform/integration/simple_annotation_files/bar.dart deleted file mode 100644 index afd8ab284e..0000000000 --- a/modules_dart/transform/test/transform/integration/simple_annotation_files/bar.dart +++ /dev/null @@ -1,8 +0,0 @@ -library bar; - -import 'package:angular2/src/core/metadata.dart'; - -@Component(selector: '[soup]', template: 'aa') -class MyComponent { - MyComponent(); -} diff --git a/modules_dart/transform/test/transform/integration/simple_annotation_files/expected/bar.ngfactory.dart b/modules_dart/transform/test/transform/integration/simple_annotation_files/expected/bar.ngfactory.dart deleted file mode 100644 index 26fadd6c95..0000000000 --- a/modules_dart/transform/test/transform/integration/simple_annotation_files/expected/bar.ngfactory.dart +++ /dev/null @@ -1,19 +0,0 @@ -library bar.ngfactory.dart; - -import 'bar.dart'; -import 'package:angular2/src/core/reflection/reflection.dart' as _ngRef; -import 'package:angular2/src/core/metadata.dart'; -import 'package:angular2/src/core/metadata.ngfactory.dart' as i0; -export 'bar.dart'; - -var _visited = false; -void initReflector() { - if (_visited) return; - _visited = true; - _ngRef.reflector - ..registerType( - MyComponent, - new _ngRef.ReflectionInfo( - const [MyComponentNgFactory], const [], () => new MyComponent())); - i0.initReflector(); -} diff --git a/modules_dart/transform/test/transform/integration/simple_annotation_files/expected/index.ngfactory.dart b/modules_dart/transform/test/transform/integration/simple_annotation_files/expected/index.ngfactory.dart deleted file mode 100644 index 8c73ed055e..0000000000 --- a/modules_dart/transform/test/transform/integration/simple_annotation_files/expected/index.ngfactory.dart +++ /dev/null @@ -1,16 +0,0 @@ -library web_foo.ngfactory.dart; - -import 'index.dart'; -import 'package:angular2/src/core/reflection/reflection.dart' as _ngRef; -import 'package:angular2/platform/browser_static.dart' show bootstrapStatic; -import 'package:angular2/src/core/reflection/reflection.dart'; -import 'bar.dart'; -import 'bar.ngfactory.dart' as i0; -export 'index.dart'; - -var _visited = false; -void initReflector() { - if (_visited) return; - _visited = true; - i0.initReflector(); -} diff --git a/modules_dart/transform/test/transform/integration/simple_annotation_files/index.dart b/modules_dart/transform/test/transform/integration/simple_annotation_files/index.dart deleted file mode 100644 index a9ccef3f11..0000000000 --- a/modules_dart/transform/test/transform/integration/simple_annotation_files/index.dart +++ /dev/null @@ -1,11 +0,0 @@ -library web_foo; - -import 'package:angular2/platform/browser.dart' show bootstrap; -import 'package:angular2/src/core/reflection/reflection.dart'; -import 'package:angular2/src/core/reflection/reflection_capabilities.dart'; -import 'bar.dart'; - -void main() { - reflector.reflectionCapabilities = new ReflectionCapabilities(); - bootstrap(MyComponent); -} diff --git a/modules_dart/transform/test/transform/integration/synthetic_ctor_files/bar.dart b/modules_dart/transform/test/transform/integration/synthetic_ctor_files/bar.dart deleted file mode 100644 index fe8e864935..0000000000 --- a/modules_dart/transform/test/transform/integration/synthetic_ctor_files/bar.dart +++ /dev/null @@ -1,7 +0,0 @@ -library bar; - -import 'package:angular2/src/core/metadata.dart'; - -@Component(selector: '[soup]') -@View(template: '') -class MyComponent {} diff --git a/modules_dart/transform/test/transform/integration/synthetic_ctor_files/expected/bar.ngfactory.dart b/modules_dart/transform/test/transform/integration/synthetic_ctor_files/expected/bar.ngfactory.dart deleted file mode 100644 index 26fadd6c95..0000000000 --- a/modules_dart/transform/test/transform/integration/synthetic_ctor_files/expected/bar.ngfactory.dart +++ /dev/null @@ -1,19 +0,0 @@ -library bar.ngfactory.dart; - -import 'bar.dart'; -import 'package:angular2/src/core/reflection/reflection.dart' as _ngRef; -import 'package:angular2/src/core/metadata.dart'; -import 'package:angular2/src/core/metadata.ngfactory.dart' as i0; -export 'bar.dart'; - -var _visited = false; -void initReflector() { - if (_visited) return; - _visited = true; - _ngRef.reflector - ..registerType( - MyComponent, - new _ngRef.ReflectionInfo( - const [MyComponentNgFactory], const [], () => new MyComponent())); - i0.initReflector(); -} diff --git a/modules_dart/transform/test/transform/integration/synthetic_ctor_files/index.dart b/modules_dart/transform/test/transform/integration/synthetic_ctor_files/index.dart deleted file mode 100644 index 7acd07896f..0000000000 --- a/modules_dart/transform/test/transform/integration/synthetic_ctor_files/index.dart +++ /dev/null @@ -1,10 +0,0 @@ -library web_foo; - -import 'package:angular2/platform/browser.dart'; -import 'package:angular2/src/core/reflection/reflection_capabilities.dart'; -import 'bar.dart'; - -void main() { - reflector.reflectionCapabilities = new ReflectionCapabilities(); - bootstrap(MyComponent); -} diff --git a/modules_dart/transform/test/transform/integration/two_annotations_files/bar.dart b/modules_dart/transform/test/transform/integration/two_annotations_files/bar.dart deleted file mode 100644 index a84732815c..0000000000 --- a/modules_dart/transform/test/transform/integration/two_annotations_files/bar.dart +++ /dev/null @@ -1,12 +0,0 @@ -library bar; - -import 'package:angular2/core.dart'; - -@Annotation1(prop1: 'value1') -@Annotation2(prop2: 'value2') -@Component(selector: 'xyz', template: '') -class MyComponent { - int myNum; - - MyComponent(); -} diff --git a/modules_dart/transform/test/transform/integration/two_annotations_files/expected/bar.ngfactory.dart b/modules_dart/transform/test/transform/integration/two_annotations_files/expected/bar.ngfactory.dart deleted file mode 100644 index c2b77e16e0..0000000000 --- a/modules_dart/transform/test/transform/integration/two_annotations_files/expected/bar.ngfactory.dart +++ /dev/null @@ -1,22 +0,0 @@ -library bar.ngfactory.dart; - -import 'bar.dart'; -import 'package:angular2/src/core/reflection/reflection.dart' as _ngRef; -import 'package:angular2/core.dart'; -import 'package:angular2/core.ngfactory.dart' as i0; -export 'bar.dart'; - -var _visited = false; -void initReflector() { - if (_visited) return; - _visited = true; - _ngRef.reflector - ..registerType( - MyComponent, - new _ngRef.ReflectionInfo(const [ - const Annotation1(prop1: 'value1'), - const Annotation2(prop2: 'value2'), - MyComponentNgFactory - ], const [], () => new MyComponent())); - i0.initReflector(); -} diff --git a/modules_dart/transform/test/transform/integration/two_annotations_files/index.dart b/modules_dart/transform/test/transform/integration/two_annotations_files/index.dart deleted file mode 100644 index 7acd07896f..0000000000 --- a/modules_dart/transform/test/transform/integration/two_annotations_files/index.dart +++ /dev/null @@ -1,10 +0,0 @@ -library web_foo; - -import 'package:angular2/platform/browser.dart'; -import 'package:angular2/src/core/reflection/reflection_capabilities.dart'; -import 'bar.dart'; - -void main() { - reflector.reflectionCapabilities = new ReflectionCapabilities(); - bootstrap(MyComponent); -} diff --git a/modules_dart/transform/test/transform/integration/two_deps_files/bar.dart b/modules_dart/transform/test/transform/integration/two_deps_files/bar.dart deleted file mode 100644 index b8aee72d6a..0000000000 --- a/modules_dart/transform/test/transform/integration/two_deps_files/bar.dart +++ /dev/null @@ -1,14 +0,0 @@ -library bar; - -import 'package:angular2/src/core/metadata.dart'; -import 'foo.dart' as prefix; - -@Component(selector: 'soup') -@View(template: '') -class MyComponent { - final prefix.MyContext c; - final prefix.MyDep generatedValue; - MyComponent(this.c, prefix.MyDep inValue) { - generatedValue = inValue; - } -} diff --git a/modules_dart/transform/test/transform/integration/two_deps_files/expected/bar.ngfactory.dart b/modules_dart/transform/test/transform/integration/two_deps_files/expected/bar.ngfactory.dart deleted file mode 100644 index 918c37e2fb..0000000000 --- a/modules_dart/transform/test/transform/integration/two_deps_files/expected/bar.ngfactory.dart +++ /dev/null @@ -1,28 +0,0 @@ -library bar.ngfactory.dart; - -import 'bar.dart'; -import 'package:angular2/src/core/reflection/reflection.dart' as _ngRef; -import 'package:angular2/src/core/metadata.dart'; -import 'foo.dart' as prefix; -import 'package:angular2/src/core/metadata.ngfactory.dart' as i0; -import 'foo.ngfactory.dart' as i1; -export 'bar.dart'; - -var _visited = false; -void initReflector() { - if (_visited) return; - _visited = true; - _ngRef.reflector - ..registerType( - MyComponent, - new _ngRef.ReflectionInfo( - const [MyComponentNgFactory], - const [ - const [prefix.MyContext], - const [prefix.MyDep] - ], - (prefix.MyContext c, prefix.MyDep inValue) => - new MyComponent(c, inValue))); - i0.initReflector(); - i1.initReflector(); -} diff --git a/modules_dart/transform/test/transform/integration/two_deps_files/foo.dart b/modules_dart/transform/test/transform/integration/two_deps_files/foo.dart deleted file mode 100644 index f472170871..0000000000 --- a/modules_dart/transform/test/transform/integration/two_deps_files/foo.dart +++ /dev/null @@ -1,11 +0,0 @@ -library foo; - -import 'package:angular2/angular2.dart'; - -@Injectable() -class MyDep {} - -class MyContext { - final MyDep selector; - const MyContext(this.selector); -} diff --git a/modules_dart/transform/test/transform/integration/two_deps_files/index.dart b/modules_dart/transform/test/transform/integration/two_deps_files/index.dart deleted file mode 100644 index 7acd07896f..0000000000 --- a/modules_dart/transform/test/transform/integration/two_deps_files/index.dart +++ /dev/null @@ -1,10 +0,0 @@ -library web_foo; - -import 'package:angular2/platform/browser.dart'; -import 'package:angular2/src/core/reflection/reflection_capabilities.dart'; -import 'bar.dart'; - -void main() { - reflector.reflectionCapabilities = new ReflectionCapabilities(); - bootstrap(MyComponent); -} diff --git a/modules_dart/transform/test/transform/reflection_remover/abstract_method_annotation_files/index.dart b/modules_dart/transform/test/transform/reflection_remover/abstract_method_annotation_files/index.dart deleted file mode 100644 index 85896503b8..0000000000 --- a/modules_dart/transform/test/transform/reflection_remover/abstract_method_annotation_files/index.dart +++ /dev/null @@ -1,8 +0,0 @@ -library web_foo; - -import 'package:angular2/platform/browser.dart'; - -abstract class TestBootstrapper { - @AngularEntrypoint() - void testBootstrap(); -} diff --git a/modules_dart/transform/test/transform/reflection_remover/all_tests.dart b/modules_dart/transform/test/transform/reflection_remover/all_tests.dart deleted file mode 100644 index d6063b39cb..0000000000 --- a/modules_dart/transform/test/transform/reflection_remover/all_tests.dart +++ /dev/null @@ -1,150 +0,0 @@ -library angular2.test.transform.reflection_remover; - -import 'package:analyzer/analyzer.dart'; -import 'package:barback/barback.dart'; -import 'package:guinness/guinness.dart'; - -import 'package:angular2/src/transform/common/annotation_matcher.dart'; -import 'package:angular2/src/transform/common/mirror_mode.dart'; -import 'package:angular2/src/transform/reflection_remover/codegen.dart'; -import 'package:angular2/src/transform/reflection_remover/entrypoint_matcher.dart'; -import 'package:angular2/src/transform/reflection_remover/rewriter.dart'; - -import '../common/read_file.dart'; -import 'bootstrap_files/expected/index.dart' as bootstrap_expected; -import 'combinator_files/expected/index.dart' as combinator_expected; -import 'debug_mirrors_files/expected/index.dart' as debug_mirrors; -import 'deferred_bootstrap_files/expected/index.dart' - as deferred_bootstrap_expected; -import 'function_annotation_files/expected/index.dart' - as func_annotation_expected; -import 'log_mirrors_files/expected/index.dart' as log_mirrors; -import 'method_annotation_files/expected/index.dart' - as method_annotation_expected; -import 'reflection_remover_files/expected/index.dart' as expected; -import 'verbose_files/expected/index.dart' as verbose_mirrors; - -main() => allTests(); - -void allTests() { - var entrypointMatcher, assetId, codegen, code; - - beforeEach(() { - assetId = new AssetId('a', 'web/index.dart'); - codegen = new Codegen(assetId); - code = readFile('reflection_remover/index.dart').replaceAll('\r\n', '\n'); - entrypointMatcher = new EntrypointMatcher(assetId, new AnnotationMatcher()); - }); - - it( - 'should remove uses of mirrors & ' - 'insert calls to generated code by default.', () { - var output = new Rewriter(code, codegen, entrypointMatcher) - .rewrite(parseCompilationUnit(code)); - expect(output).toEqual(expected.code); - }); - - it( - 'should replace uses of mirrors with the debug implementation & ' - 'insert calls to generated code in `MirrorMode.debug`.', () { - var output = new Rewriter(code, codegen, entrypointMatcher, - mirrorMode: MirrorMode.debug) - .rewrite(parseCompilationUnit(code)); - expect(output).toEqual(debug_mirrors.code); - }); - - it( - 'should replace uses of mirrors with the verbose implementation ' - 'in `MirrorMode.verbose`.', () { - var output = new Rewriter(code, codegen, entrypointMatcher, - mirrorMode: MirrorMode.verbose) - .rewrite(parseCompilationUnit(code)); - expect(output).toEqual(verbose_mirrors.code); - }); - - it('should not initialize the reflector when `writeStaticInit` is `false`.', - () { - var output = - new Rewriter(code, codegen, entrypointMatcher, writeStaticInit: false) - .rewrite(parseCompilationUnit(code)); - expect(output).toEqual(log_mirrors.code); - }); - - describe('`bootstrap` import and call', () { - it('should be rewritten to `bootstrapStatic`.', () { - final bootstrapCode = - readFile('reflection_remover/bootstrap_files/index.dart') - .replaceAll('\r\n', '\n'); - var output = new Rewriter(bootstrapCode, codegen, entrypointMatcher, - writeStaticInit: true) - .rewrite(parseCompilationUnit(bootstrapCode)); - expect(output).toEqual(bootstrap_expected.code); - }); - - it('should be rewritten correctly when deferred.', () { - final bootstrapCode = - readFile('reflection_remover/deferred_bootstrap_files/index.dart'); - var output = new Rewriter(bootstrapCode, codegen, entrypointMatcher, - writeStaticInit: true) - .rewrite(parseCompilationUnit(bootstrapCode)); - expect(output).toEqual(deferred_bootstrap_expected.code); - }); - - it('should maintain any combinators.', () { - final bootstrapCode = - readFile('reflection_remover/combinator_files/index.dart'); - var output = new Rewriter(bootstrapCode, codegen, entrypointMatcher, - writeStaticInit: true) - .rewrite(parseCompilationUnit(bootstrapCode)); - expect(output).toEqual(combinator_expected.code); - }); - }); - - describe('AngularEntrypoint annotation', () { - it('should add a call to `initReflector` at the beginning of the function', - () { - code = readFile('reflection_remover/function_annotation_files/index.dart') - .replaceAll('\r\n', '\n'); - final output = new Rewriter(code, codegen, entrypointMatcher) - .rewrite(parseCompilationUnit(code)); - expect(output).toEqual(func_annotation_expected.code); - }); - - it('should `throw` for entrypoints implemented as arrow functions', () { - code = readFile('reflection_remover/arrow_annotation_files/index.dart') - .replaceAll('\r\n', '\n'); - expect(() { - new Rewriter(code, codegen, entrypointMatcher) - .rewrite(parseCompilationUnit(code)); - }).toThrowWith(anInstanceOf: ArgumentError); - }); - - it('should `throw` for native functions annotated as entry points', () { - code = readFile('reflection_remover/native_annotation_files/index.dart') - .replaceAll('\r\n', '\n'); - expect(() { - new Rewriter(code, codegen, entrypointMatcher) - .rewrite(parseCompilationUnit(code)); - }).toThrowWith(anInstanceOf: ArgumentError); - }); - - it('should `throw` for abstract functions annotated as entry points', () { - code = readFile( - 'reflection_remover/abstract_method_annotation_files/index.dart') - .replaceAll('\r\n', '\n'); - expect(() { - new Rewriter(code, codegen, entrypointMatcher) - .rewrite(parseCompilationUnit(code)); - }).toThrowWith(anInstanceOf: ArgumentError); - }); - - it('should add a call to `initReflector` at the beginning of the method', - () { - code = readFile('reflection_remover/method_annotation_files/index.dart') - .replaceAll('\r\n', '\n'); - final output = new Rewriter(code, codegen, entrypointMatcher) - .rewrite(parseCompilationUnit(code)); - expect(output).toEqual(method_annotation_expected.code); - }); - }); -} diff --git a/modules_dart/transform/test/transform/reflection_remover/arrow_annotation_files/index.dart b/modules_dart/transform/test/transform/reflection_remover/arrow_annotation_files/index.dart deleted file mode 100644 index fa922d389c..0000000000 --- a/modules_dart/transform/test/transform/reflection_remover/arrow_annotation_files/index.dart +++ /dev/null @@ -1,8 +0,0 @@ -library web_foo; - -import 'package:angular2/platform/browser.dart'; -import 'package:angular2/src/core/reflection/reflection.dart'; -import 'package:angular2/src/core/reflection/reflection_capabilities.dart'; - -@AngularEntrypoint() -main() => bootstrap(MyComponent); diff --git a/modules_dart/transform/test/transform/reflection_remover/bootstrap_files/README.md b/modules_dart/transform/test/transform/reflection_remover/bootstrap_files/README.md deleted file mode 100644 index 6a55dc7bf5..0000000000 --- a/modules_dart/transform/test/transform/reflection_remover/bootstrap_files/README.md +++ /dev/null @@ -1,5 +0,0 @@ -Tests that the reflection removal step: - 1. Comments out reflective `bootstrap.dart` import - 1. Adds `bootstrap_static.dart` import - 1. Adds the call to `initReflector` - 1. Handles bootstrap return values properly diff --git a/modules_dart/transform/test/transform/reflection_remover/bootstrap_files/expected/index.dart b/modules_dart/transform/test/transform/reflection_remover/bootstrap_files/expected/index.dart deleted file mode 100644 index 907fc0bb46..0000000000 --- a/modules_dart/transform/test/transform/reflection_remover/bootstrap_files/expected/index.dart +++ /dev/null @@ -1,19 +0,0 @@ -library angular2.test.transform.reflection_remover.reflection_remover_files; - -// This file is intentionally formatted as a string to avoid having the -// automatic transformer prettify it. -// -// This file represents transformed user code. Because this code will be -// linked to output by a source map, we cannot change line numbers from the -// original code and we therefore add our generated code on the same line as -// those we are removing. - -var code = """ -library web_foo; - -import 'package:angular2/platform/browser_static.dart';import 'index.ngfactory.dart' as ngStaticInit; - -void main() async { - var appRef = await bootstrapStatic(MyComponent, null, () { ngStaticInit.initReflector(); }); -} -"""; diff --git a/modules_dart/transform/test/transform/reflection_remover/bootstrap_files/index.dart b/modules_dart/transform/test/transform/reflection_remover/bootstrap_files/index.dart deleted file mode 100644 index ecd8bf7640..0000000000 --- a/modules_dart/transform/test/transform/reflection_remover/bootstrap_files/index.dart +++ /dev/null @@ -1,7 +0,0 @@ -library web_foo; - -import 'package:angular2/platform/browser.dart'; - -void main() async { - var appRef = await bootstrap(MyComponent); -} diff --git a/modules_dart/transform/test/transform/reflection_remover/combinator_files/expected/index.dart b/modules_dart/transform/test/transform/reflection_remover/combinator_files/expected/index.dart deleted file mode 100644 index b109e6a362..0000000000 --- a/modules_dart/transform/test/transform/reflection_remover/combinator_files/expected/index.dart +++ /dev/null @@ -1,17 +0,0 @@ -library angular2.test.transform.reflection_remover.combinator_files; - -// This file is intentionally formatted as a string to avoid having the -// automatic transformer prettify it. -// -// This file represents transformed user code. Because this code will be -// linked to output by a source map, we cannot change line numbers from the -// original code and we therefore add our generated code on the same line as -// those we are removing. - -var code = """ -import 'package:angular2/platform/browser_static.dart' show bootstrapStatic, initReflector;import 'index.ngfactory.dart' as ngStaticInit; - -void main() { - bootstrapStatic(MyComponent, null, () { ngStaticInit.initReflector(); }); -} -"""; diff --git a/modules_dart/transform/test/transform/reflection_remover/combinator_files/index.dart b/modules_dart/transform/test/transform/reflection_remover/combinator_files/index.dart deleted file mode 100644 index b29269950a..0000000000 --- a/modules_dart/transform/test/transform/reflection_remover/combinator_files/index.dart +++ /dev/null @@ -1,5 +0,0 @@ -import 'package:angular2/platform/browser.dart' show bootstrap; - -void main() { - bootstrap(MyComponent); -} diff --git a/modules_dart/transform/test/transform/reflection_remover/debug_files/README.md b/modules_dart/transform/test/transform/reflection_remover/debug_files/README.md deleted file mode 100644 index b277f0c237..0000000000 --- a/modules_dart/transform/test/transform/reflection_remover/debug_files/README.md +++ /dev/null @@ -1,5 +0,0 @@ -Tests that the reflection removal step: - * Adds the appropriate ng_deps import. - * Adds the call to `initReflector` - * Does not change line numbers in the source. - * Makes minimal changes to source offsets. diff --git a/modules_dart/transform/test/transform/reflection_remover/debug_files/expected/index.dart b/modules_dart/transform/test/transform/reflection_remover/debug_files/expected/index.dart deleted file mode 100644 index 5f4ee58134..0000000000 --- a/modules_dart/transform/test/transform/reflection_remover/debug_files/expected/index.dart +++ /dev/null @@ -1,22 +0,0 @@ -library angular2.test.transform.debug_reflection_remover_files; - -// This file is intentionally formatted as a string to avoid having the -// automatic transformer prettify it. -// -// This file represents transformed user code. Because this code will be -// linked to output by a source map, we cannot change line numbers from the -// original code and we therefore add our generated code on the same line as -// those we are removing. - -var code = """ -library web_foo; - -import 'package:angular2/platform/browser.dart';import 'index.ngfactory.dart' as ngStaticInit; -import 'package:angular2/src/core/reflection/reflection.dart'; -import 'package:angular2/src/core/reflection/debug_reflection_capabilities.dart'; - -void main() { - reflector.reflectionCapabilities = new ReflectionCapabilities(); - ngStaticInit.initReflector();bootstrap(MyComponent); -} -"""; diff --git a/modules_dart/transform/test/transform/reflection_remover/debug_files/index.dart b/modules_dart/transform/test/transform/reflection_remover/debug_files/index.dart deleted file mode 100644 index ff3d436729..0000000000 --- a/modules_dart/transform/test/transform/reflection_remover/debug_files/index.dart +++ /dev/null @@ -1,10 +0,0 @@ -library web_foo; - -import 'package:angular2/platform/browser.dart'; -import 'package:angular2/src/core/reflection/reflection.dart'; -import 'package:angular2/src/core/reflection/reflection_capabilities.dart'; - -void main() { - reflector.reflectionCapabilities = new ReflectionCapabilities(); - bootstrap(MyComponent); -} diff --git a/modules_dart/transform/test/transform/reflection_remover/debug_mirrors_files/README.md b/modules_dart/transform/test/transform/reflection_remover/debug_mirrors_files/README.md deleted file mode 100644 index db2313dfb0..0000000000 --- a/modules_dart/transform/test/transform/reflection_remover/debug_mirrors_files/README.md +++ /dev/null @@ -1,7 +0,0 @@ -Tests that the reflection removal step: - 1. Comments out the import of reflection_capabilities.dart - 2. Comments out the instantiation of `ReflectionCapabilities` - 3. Adds the appropriate import. - 4. Adds the call to `initReflector` - 5. Does not change line numbers in the source. - 6. Makes minimal changes to source offsets. \ No newline at end of file diff --git a/modules_dart/transform/test/transform/reflection_remover/debug_mirrors_files/expected/index.dart b/modules_dart/transform/test/transform/reflection_remover/debug_mirrors_files/expected/index.dart deleted file mode 100644 index c20b1c4d9d..0000000000 --- a/modules_dart/transform/test/transform/reflection_remover/debug_mirrors_files/expected/index.dart +++ /dev/null @@ -1,22 +0,0 @@ -library angular2.test.transform.reflection_remover.debug_mirrors_files.expected; - -// This file is intentionally formatted as a string to avoid having the -// automatic transformer prettify it. -// -// This file represents transformed user code. Because this code will be -// linked to output by a source map, we cannot change line numbers from the -// original code and we therefore add our generated code on the same line as -// those we are removing. - -var code = """ -library web_foo; - -import 'package:angular2/platform/browser_static.dart';import 'index.ngfactory.dart' as ngStaticInit; -import 'package:angular2/src/core/reflection/reflection.dart'; -import 'package:angular2/src/core/reflection/debug_reflection_capabilities.dart'; - -void main() { - ngStaticInit.initReflector();reflector.reflectionCapabilities = new ReflectionCapabilities(); - bootstrapStatic(MyComponent); -} -"""; diff --git a/modules_dart/transform/test/transform/reflection_remover/debug_mirrors_files/index.dart b/modules_dart/transform/test/transform/reflection_remover/debug_mirrors_files/index.dart deleted file mode 100644 index ff3d436729..0000000000 --- a/modules_dart/transform/test/transform/reflection_remover/debug_mirrors_files/index.dart +++ /dev/null @@ -1,10 +0,0 @@ -library web_foo; - -import 'package:angular2/platform/browser.dart'; -import 'package:angular2/src/core/reflection/reflection.dart'; -import 'package:angular2/src/core/reflection/reflection_capabilities.dart'; - -void main() { - reflector.reflectionCapabilities = new ReflectionCapabilities(); - bootstrap(MyComponent); -} diff --git a/modules_dart/transform/test/transform/reflection_remover/deferred_bootstrap_files/expected/index.dart b/modules_dart/transform/test/transform/reflection_remover/deferred_bootstrap_files/expected/index.dart deleted file mode 100644 index 94f7a0bca4..0000000000 --- a/modules_dart/transform/test/transform/reflection_remover/deferred_bootstrap_files/expected/index.dart +++ /dev/null @@ -1,19 +0,0 @@ -library angular2.test.transform.reflection_remover.deferred_bootstrap_files; - -// This file is intentionally formatted as a string to avoid having the -// automatic transformer prettify it. -// -// This file represents transformed user code. Because this code will be -// linked to output by a source map, we cannot change line numbers from the -// original code and we therefore add our generated code on the same line as -// those we are removing. - -var code = """ -import 'package:angular2/platform/browser_static.dart' deferred as ng;import 'index.ngfactory.dart' as ngStaticInit; - -void main() { - ng.loadLibrary().then((_) { - ng.bootstrapStatic(MyComponent, null, () { ngStaticInit.initReflector(); }); - }); -} -"""; diff --git a/modules_dart/transform/test/transform/reflection_remover/deferred_bootstrap_files/index.dart b/modules_dart/transform/test/transform/reflection_remover/deferred_bootstrap_files/index.dart deleted file mode 100644 index 7bbcb9fabe..0000000000 --- a/modules_dart/transform/test/transform/reflection_remover/deferred_bootstrap_files/index.dart +++ /dev/null @@ -1,7 +0,0 @@ -import 'package:angular2/platform/browser.dart' deferred as ng; - -void main() { - ng.loadLibrary().then((_) { - ng.bootstrap(MyComponent); - }); -} diff --git a/modules_dart/transform/test/transform/reflection_remover/function_annotation_files/expected/index.dart b/modules_dart/transform/test/transform/reflection_remover/function_annotation_files/expected/index.dart deleted file mode 100644 index 55c757148d..0000000000 --- a/modules_dart/transform/test/transform/reflection_remover/function_annotation_files/expected/index.dart +++ /dev/null @@ -1,23 +0,0 @@ -library angular2.test.transform.reflection_remover.function_annotation_files; - -// This file is intentionally formatted as a string to avoid having the -// automatic transformer prettify it. -// -// This file represents transformed user code. Because this code will be -// linked to output by a source map, we cannot change line numbers from the -// original code and we therefore add our generated code on the same line as -// those we are removing. - -const code = """ -library web_foo; - -import 'package:angular2/platform/browser_static.dart';import 'index.ngfactory.dart' as ngStaticInit; -import 'package:angular2/src/core/reflection/reflection.dart'; -/*import 'package:angular2/src/core/reflection/reflection_capabilities.dart';*/ - -@AngularEntrypoint() -void main() {ngStaticInit.initReflector(); - /*reflector.reflectionCapabilities = new ReflectionCapabilities();*/ - bootstrapStatic(MyComponent); -} -"""; diff --git a/modules_dart/transform/test/transform/reflection_remover/function_annotation_files/index.dart b/modules_dart/transform/test/transform/reflection_remover/function_annotation_files/index.dart deleted file mode 100644 index cc1bce0d0e..0000000000 --- a/modules_dart/transform/test/transform/reflection_remover/function_annotation_files/index.dart +++ /dev/null @@ -1,11 +0,0 @@ -library web_foo; - -import 'package:angular2/platform/browser.dart'; -import 'package:angular2/src/core/reflection/reflection.dart'; -import 'package:angular2/src/core/reflection/reflection_capabilities.dart'; - -@AngularEntrypoint() -void main() { - reflector.reflectionCapabilities = new ReflectionCapabilities(); - bootstrap(MyComponent); -} diff --git a/modules_dart/transform/test/transform/reflection_remover/index.dart b/modules_dart/transform/test/transform/reflection_remover/index.dart deleted file mode 100644 index ff3d436729..0000000000 --- a/modules_dart/transform/test/transform/reflection_remover/index.dart +++ /dev/null @@ -1,10 +0,0 @@ -library web_foo; - -import 'package:angular2/platform/browser.dart'; -import 'package:angular2/src/core/reflection/reflection.dart'; -import 'package:angular2/src/core/reflection/reflection_capabilities.dart'; - -void main() { - reflector.reflectionCapabilities = new ReflectionCapabilities(); - bootstrap(MyComponent); -} diff --git a/modules_dart/transform/test/transform/reflection_remover/log_mirrors_files/README.md b/modules_dart/transform/test/transform/reflection_remover/log_mirrors_files/README.md deleted file mode 100644 index db2313dfb0..0000000000 --- a/modules_dart/transform/test/transform/reflection_remover/log_mirrors_files/README.md +++ /dev/null @@ -1,7 +0,0 @@ -Tests that the reflection removal step: - 1. Comments out the import of reflection_capabilities.dart - 2. Comments out the instantiation of `ReflectionCapabilities` - 3. Adds the appropriate import. - 4. Adds the call to `initReflector` - 5. Does not change line numbers in the source. - 6. Makes minimal changes to source offsets. \ No newline at end of file diff --git a/modules_dart/transform/test/transform/reflection_remover/log_mirrors_files/expected/index.dart b/modules_dart/transform/test/transform/reflection_remover/log_mirrors_files/expected/index.dart deleted file mode 100644 index c157c41957..0000000000 --- a/modules_dart/transform/test/transform/reflection_remover/log_mirrors_files/expected/index.dart +++ /dev/null @@ -1,22 +0,0 @@ -library angular2.test.transform.log_mirrors_files.expected; - -// This file is intentionally formatted as a string to avoid having the -// automatic transformer prettify it. -// -// This file represents transformed user code. Because this code will be -// linked to output by a source map, we cannot change line numbers from the -// original code and we therefore add our generated code on the same line as -// those we are removing. - -var code = """ -library web_foo; - -import 'package:angular2/platform/browser.dart'; -import 'package:angular2/src/core/reflection/reflection.dart'; -/*import 'package:angular2/src/core/reflection/reflection_capabilities.dart';*/ - -void main() { - /*reflector.reflectionCapabilities = new ReflectionCapabilities();*/ - bootstrap(MyComponent); -} -"""; diff --git a/modules_dart/transform/test/transform/reflection_remover/log_mirrors_files/index.dart b/modules_dart/transform/test/transform/reflection_remover/log_mirrors_files/index.dart deleted file mode 100644 index ff3d436729..0000000000 --- a/modules_dart/transform/test/transform/reflection_remover/log_mirrors_files/index.dart +++ /dev/null @@ -1,10 +0,0 @@ -library web_foo; - -import 'package:angular2/platform/browser.dart'; -import 'package:angular2/src/core/reflection/reflection.dart'; -import 'package:angular2/src/core/reflection/reflection_capabilities.dart'; - -void main() { - reflector.reflectionCapabilities = new ReflectionCapabilities(); - bootstrap(MyComponent); -} diff --git a/modules_dart/transform/test/transform/reflection_remover/method_annotation_files/expected/index.dart b/modules_dart/transform/test/transform/reflection_remover/method_annotation_files/expected/index.dart deleted file mode 100644 index 3feccd74fc..0000000000 --- a/modules_dart/transform/test/transform/reflection_remover/method_annotation_files/expected/index.dart +++ /dev/null @@ -1,20 +0,0 @@ -library angular2.test.transform.reflection_remover.method_annotation_files; - -// This file is intentionally formatted as a string to avoid having the -// automatic transformer prettify it. -// -// This file represents transformed user code. Because this code will be -// linked to output by a source map, we cannot change line numbers from the -// original code and we therefore add our generated code on the same line as -// those we are removing. - -const code = """ -library web_foo; - -import 'package:angular2/platform/browser_static.dart';import 'index.ngfactory.dart' as ngStaticInit; - -class TestBootstrapper { - @AngularEntrypoint("Method entrypoint") - void testBootstrap() {ngStaticInit.initReflector();} -} -"""; diff --git a/modules_dart/transform/test/transform/reflection_remover/method_annotation_files/index.dart b/modules_dart/transform/test/transform/reflection_remover/method_annotation_files/index.dart deleted file mode 100644 index 524dda1c24..0000000000 --- a/modules_dart/transform/test/transform/reflection_remover/method_annotation_files/index.dart +++ /dev/null @@ -1,8 +0,0 @@ -library web_foo; - -import 'package:angular2/platform/browser.dart'; - -class TestBootstrapper { - @AngularEntrypoint("Method entrypoint") - void testBootstrap() {} -} diff --git a/modules_dart/transform/test/transform/reflection_remover/native_annotation_files/index.dart b/modules_dart/transform/test/transform/reflection_remover/native_annotation_files/index.dart deleted file mode 100644 index c7a0b1ac63..0000000000 --- a/modules_dart/transform/test/transform/reflection_remover/native_annotation_files/index.dart +++ /dev/null @@ -1,8 +0,0 @@ -library web_foo; - -import 'package:angular2/platform/browser.dart'; -import 'package:angular2/src/core/reflection/reflection.dart'; -import 'package:angular2/src/core/reflection/reflection_capabilities.dart'; - -@AngularEntrypoint() -main() native "MainMethod"; diff --git a/modules_dart/transform/test/transform/reflection_remover/reflection_remover_files/README.md b/modules_dart/transform/test/transform/reflection_remover/reflection_remover_files/README.md deleted file mode 100644 index db2313dfb0..0000000000 --- a/modules_dart/transform/test/transform/reflection_remover/reflection_remover_files/README.md +++ /dev/null @@ -1,7 +0,0 @@ -Tests that the reflection removal step: - 1. Comments out the import of reflection_capabilities.dart - 2. Comments out the instantiation of `ReflectionCapabilities` - 3. Adds the appropriate import. - 4. Adds the call to `initReflector` - 5. Does not change line numbers in the source. - 6. Makes minimal changes to source offsets. \ No newline at end of file diff --git a/modules_dart/transform/test/transform/reflection_remover/reflection_remover_files/expected/index.dart b/modules_dart/transform/test/transform/reflection_remover/reflection_remover_files/expected/index.dart deleted file mode 100644 index 4a2109821d..0000000000 --- a/modules_dart/transform/test/transform/reflection_remover/reflection_remover_files/expected/index.dart +++ /dev/null @@ -1,22 +0,0 @@ -library angular2.test.transform.reflection_remover.reflection_remover_files; - -// This file is intentionally formatted as a string to avoid having the -// automatic transformer prettify it. -// -// This file represents transformed user code. Because this code will be -// linked to output by a source map, we cannot change line numbers from the -// original code and we therefore add our generated code on the same line as -// those we are removing. - -var code = """ -library web_foo; - -import 'package:angular2/platform/browser_static.dart';import 'index.ngfactory.dart' as ngStaticInit; -import 'package:angular2/src/core/reflection/reflection.dart'; -/*import 'package:angular2/src/core/reflection/reflection_capabilities.dart';*/ - -void main() { - ngStaticInit.initReflector();/*reflector.reflectionCapabilities = new ReflectionCapabilities();*/ - bootstrapStatic(MyComponent); -} -"""; diff --git a/modules_dart/transform/test/transform/reflection_remover/reflection_remover_files/index.dart b/modules_dart/transform/test/transform/reflection_remover/reflection_remover_files/index.dart deleted file mode 100644 index ff3d436729..0000000000 --- a/modules_dart/transform/test/transform/reflection_remover/reflection_remover_files/index.dart +++ /dev/null @@ -1,10 +0,0 @@ -library web_foo; - -import 'package:angular2/platform/browser.dart'; -import 'package:angular2/src/core/reflection/reflection.dart'; -import 'package:angular2/src/core/reflection/reflection_capabilities.dart'; - -void main() { - reflector.reflectionCapabilities = new ReflectionCapabilities(); - bootstrap(MyComponent); -} diff --git a/modules_dart/transform/test/transform/reflection_remover/verbose_files/expected/index.dart b/modules_dart/transform/test/transform/reflection_remover/verbose_files/expected/index.dart deleted file mode 100644 index d11db29357..0000000000 --- a/modules_dart/transform/test/transform/reflection_remover/verbose_files/expected/index.dart +++ /dev/null @@ -1,22 +0,0 @@ -library angular2.test.transform.reflection_remover.verbose_files.expected; - -// This file is intentionally formatted as a string to avoid having the -// automatic transformer prettify it. -// -// This file represents transformed user code. Because this code will be -// linked to output by a source map, we cannot change line numbers from the -// original code and we therefore add our generated code on the same line as -// those we are removing. - -var code = """ -library web_foo; - -import 'package:angular2/platform/browser_static.dart';import 'index.ngfactory.dart' as ngStaticInit; -import 'package:angular2/src/core/reflection/reflection.dart'; -import 'package:angular2/src/core/reflection/debug_reflection_capabilities.dart'; - -void main() { - ngStaticInit.initReflector();reflector.reflectionCapabilities = new ReflectionCapabilities(verbose: true); - bootstrapStatic(MyComponent); -} -"""; diff --git a/modules_dart/transform/test/transform/stylesheet_compiler/all_tests.dart b/modules_dart/transform/test/transform/stylesheet_compiler/all_tests.dart deleted file mode 100644 index 7986f34ee8..0000000000 --- a/modules_dart/transform/test/transform/stylesheet_compiler/all_tests.dart +++ /dev/null @@ -1,107 +0,0 @@ -library angular2.test.transform.stylesheet_compiler.all_tests; - -import 'dart:async'; -import 'dart:convert'; - -import 'package:angular2/src/transform/stylesheet_compiler/transformer.dart'; - -import 'package:barback/barback.dart'; -import 'package:guinness/guinness.dart'; - -import '../common/recording_logger.dart'; - -const SIMPLE_CSS = ''' -.foo { - width: 10px; -} -'''; - -const HTTP_IMPORT = 'https://fonts.googleapis.com/css?family=Roboto'; -const CSS_WITH_IMPORT = '@import url(${HTTP_IMPORT});'; - -main() { - Html5LibDomAdapter.makeCurrent(); - allTests(); -} - -allTests() { - StylesheetCompiler subject; - - beforeEach(() { - subject = new StylesheetCompiler(); - }); - - it('should accept CSS assets', () { - expect(subject.isPrimary(new AssetId('somepackage', 'lib/style.css'))) - .toBe(true); - }); - - it('should reject non-CSS assets', () { - expect(subject.isPrimary(new AssetId('somepackage', 'lib/style.scss'))) - .toBe(false); - }); - - it('should compile stylesheets', () async { - var cssFile = new Asset.fromString( - new AssetId('somepackage', 'lib/style.css'), SIMPLE_CSS); - var transform = new FakeTransform()..primaryInput = cssFile; - await subject.apply(transform); - expect(transform.outputs.length).toBe(2); - expect(transform.outputs[0].id.toString()) - .toEqual('somepackage|lib/style.css.dart'); - expect(transform.outputs[1].id.toString()) - .toEqual('somepackage|lib/style.css.shim.dart'); - }); - - it('should compile stylesheets with imports', () async { - var cssFile = new Asset.fromString( - new AssetId('somepackage', 'lib/style.css'), CSS_WITH_IMPORT); - var transform = new FakeTransform()..primaryInput = cssFile; - await subject.apply(transform); - expect(transform.outputs.length).toBe(2); - expect(transform.outputs[0].id.toString()) - .toEqual('somepackage|lib/style.css.dart'); - expect(transform.outputs[1].id.toString()) - .toEqual('somepackage|lib/style.css.shim.dart'); - expect(await transform.outputs[0].readAsString()).toContain(HTTP_IMPORT); - expect(await transform.outputs[1].readAsString()).toContain(HTTP_IMPORT); - }); -} - -@proxy -class FakeTransform implements Transform { - final outputs = []; - Asset primaryInput; - final _logger = new RecordingLogger(); - - get logger => _logger; - - addOutput(Asset output) { - this.outputs.add(output); - } - - readInputAsString(AssetId id, {Encoding encoding}) { - if (id == primaryInput.id) { - return primaryInput.readAsString(encoding: encoding); - } - throw 'Could not read input $id'; - } - - noSuchMethod(Invocation i) { - throw '${i.memberName} not implemented'; - } -} - -@proxy -class FakeDeclaringTransform implements DeclaringTransform { - final outputs = []; - AssetId primaryId; - - declareOutput(AssetId output) { - this.outputs.add(output); - } - - noSuchMethod(Invocation i) { - throw '${i.memberName} not implemented'; - } -} diff --git a/modules_dart/transform/test/transform/template_compiler/all_tests.dart b/modules_dart/transform/test/transform/template_compiler/all_tests.dart deleted file mode 100644 index 9c16786c58..0000000000 --- a/modules_dart/transform/test/transform/template_compiler/all_tests.dart +++ /dev/null @@ -1,395 +0,0 @@ -library angular2.test.transform.template_compiler.all_tests; - -import 'dart:async'; -import 'dart:convert'; - -import 'package:barback/barback.dart'; -import 'package:dart_style/dart_style.dart'; -import 'package:path/path.dart' as path; -import 'package:guinness/guinness.dart'; - -import 'package:angular2/src/platform/server/html_adapter.dart'; -import 'package:angular2/src/transform/common/code/ng_deps_code.dart'; -import 'package:angular2/src/transform/common/code/source_module.dart'; -import 'package:angular2/src/transform/common/zone.dart' as zone; -import 'package:angular2/src/transform/template_compiler/generator.dart'; -import 'package:angular2/src/transform/template_compiler/compile_data_creator.dart'; -import 'package:angular2/i18n.dart'; - -import 'package:angular2/src/transform/common/model/parameter_model.pb.dart'; -import '../common/compile_directive_metadata/ng_for.ng_meta.dart' as ngMeta; -import '../common/ng_meta_helper.dart'; -import '../common/read_file.dart'; -import '../common/recording_logger.dart'; - -var formatter = new DartFormatter(); -TestAssetReader reader; -RecordingLogger logger; -const CONTEXT_ACCESSOR = 'context'; - -main() => allTests(); - -var fooComponentMeta, fooNgMeta, fooAssetId; -var barComponentMeta, barPipeMeta, barNgMeta, barAssetId; -var bazComponentMeta, bazNgMeta, bazAssetId; - -/// Call after making changes to `fooNgMeta`, `barNgMeta`, or `bazNgMeta` and -/// before trying to read them from `reader`. -TestAssetReader updateReader() => reader - ..addAsset(fooAssetId, JSON.encode(fooNgMeta.toJson())) - ..addAsset(barAssetId, JSON.encode(barNgMeta.toJson())) - ..addAsset(bazAssetId, JSON.encode(bazNgMeta.toJson())); - -void allTests() { - Html5LibDomAdapter.makeCurrent(); - - final moduleBase = 'asset:a'; - - beforeEach(() { - reader = new TestAssetReader() - ..addAsset( - new AssetId('angular2', 'lib/src/directives/ng_for.ng_meta.json'), - JSON.encode(ngMeta.ngFor)); - - // Establish some test NgMeta objects with one Component each. - // NOTE(kegluneq): For simplicity, the NgDepsModel objects created here are - // lacking some details that would be created by DirectiveProcessor but - // which are not used in the template compiler. - fooComponentMeta = createFoo(moduleBase); - fooNgMeta = new NgMeta( - ngDeps: new NgDepsModel() - ..libraryUri = 'test.foo' - ..reflectables.add( - new ReflectionInfoModel()..name = fooComponentMeta.type.name)); - fooNgMeta.identifiers[fooComponentMeta.type.name] = fooComponentMeta; - - barComponentMeta = createBar(moduleBase); - barPipeMeta = createBarPipe(moduleBase); - barNgMeta = new NgMeta( - ngDeps: new NgDepsModel() - ..libraryUri = 'test.bar' - ..reflectables - .add(new ReflectionInfoModel()..name = barPipeMeta.type.name) - ..reflectables.add( - new ReflectionInfoModel()..name = barComponentMeta.type.name)); - barNgMeta.identifiers[barComponentMeta.type.name] = barComponentMeta; - barNgMeta.identifiers[barPipeMeta.type.name] = barPipeMeta; - - bazComponentMeta = createBaz(moduleBase); - bazNgMeta = new NgMeta( - ngDeps: new NgDepsModel() - ..libraryUri = 'test.baz' - ..reflectables.add( - new ReflectionInfoModel()..name = bazComponentMeta.type.name)); - barNgMeta.identifiers[bazComponentMeta.type.name] = bazComponentMeta; - - fooAssetId = new AssetId('a', 'lib/foo.ng_meta.json'); - barAssetId = new AssetId('a', 'lib/bar.ng_meta.json'); - bazAssetId = new AssetId('a', 'lib/baz.ng_meta.json'); - updateReader(); - }); - - Future process(AssetId assetId, - {List platformDirectives, List platformPipes, Map resolvedIdentifiers, - XmbDeserializationResult translations}) { - logger = new RecordingLogger(); - return zone.exec( - () => processTemplates(reader, assetId, - platformDirectives: platformDirectives, - platformPipes: platformPipes, - resolvedIdentifiers: resolvedIdentifiers, - translations: translations - ), - log: logger); - } - - it('should parse simple expressions in inline templates.', () async { - fooComponentMeta.template = new CompileTemplateMetadata( - template: '
{{greeting}}
', - templateUrl: 'template.html'); - updateReader(); - - final outputs = await process(fooAssetId); - final ngDeps = outputs.ngDeps; - expect(ngDeps).toBeNotNull(); - expect(ngDeps.reflectables.first.annotations) - .toContain(new AnnotationModel() - ..name = 'FooComponentNgFactory' - ..isConstObject = true); - expect(_generatedCode(outputs)) - ..toContain('$CONTEXT_ACCESSOR.greeting') - ..toContain('$CONTEXT_ACCESSOR.b'); - }); - - it('should parse simple methods in inline templates.', () async { - fooComponentMeta.template = new CompileTemplateMetadata( - template: '', - templateUrl: 'template.html'); - updateReader(); - - final outputs = await process(fooAssetId); - final ngDeps = outputs.ngDeps; - expect(ngDeps).toBeNotNull(); - expect(ngDeps.reflectables.first.annotations) - .toContain(new AnnotationModel() - ..name = 'FooComponentNgFactory' - ..isConstObject = true); - expect(_generatedCode(outputs))..toContain('$CONTEXT_ACCESSOR.action()'); - }); - - it('should parse `View` directives with a single dependency.', () async { - fooComponentMeta.template = - new CompileTemplateMetadata(template: '<${barComponentMeta.selector}>'); - final viewAnnotation = new AnnotationModel() - ..name = 'View'; - viewAnnotation.namedParameters.add(new NamedParameter() - ..name = 'directives' - ..value = 'const [${barComponentMeta.type.name}]'); - fooNgMeta.ngDeps.reflectables.first.annotations.add(viewAnnotation); - fooNgMeta.ngDeps.reflectables.first.directives - .add(new PrefixedType()..name = barComponentMeta.type.name); - fooNgMeta.ngDeps.imports.add(new ImportModel()..uri = 'bar.dart'); - barComponentMeta.template = - new CompileTemplateMetadata(template: 'BarTemplate'); - updateReader(); - - final outputs = await process(fooAssetId); - final ngDeps = outputs.ngDeps; - expect(ngDeps).toBeNotNull(); - expect(ngDeps.reflectables.first.annotations) - .toContain(new AnnotationModel() - ..name = 'FooComponentNgFactory' - ..isConstObject = true); - - expect(_generatedCode(outputs)) - ..toContain("import 'bar.dart'") - ..toContain("import 'bar.ngfactory.dart'"); - }); - - it('should parse `View` directives with a single prefixed dependency.', - () async { - fooComponentMeta.template = - new CompileTemplateMetadata(template: '<${barComponentMeta.selector}>'); - final componentAnnotation = new AnnotationModel() - ..name = 'View'; - fooNgMeta.ngDeps.reflectables.first.annotations.add(componentAnnotation); - fooNgMeta.ngDeps.reflectables.first.directives.add(new PrefixedType() - ..name = barComponentMeta.type.name - ..prefix = 'prefix'); - fooNgMeta.ngDeps.imports.add(new ImportModel() - ..uri = 'bar.dart' - ..prefix = 'prefix'); - barComponentMeta.template = - new CompileTemplateMetadata(template: 'BarTemplate'); - updateReader(); - - final outputs = await process(fooAssetId); - final ngDeps = outputs.ngDeps; - expect(ngDeps).toBeNotNull(); - expect(ngDeps.reflectables.first.annotations) - .toContain(new AnnotationModel() - ..name = 'FooComponentNgFactory' - ..isConstObject = true); - - expect(_generatedCode(outputs)) - ..toContain("import 'bar.dart'") - ..toContain("import 'bar.ngfactory.dart'"); - }); - - it('should include directives mentioned in directive aliases.', () async { - fooComponentMeta.template = - new CompileTemplateMetadata(template: '<${barComponentMeta.selector}>'); - final componentAnnotation = new AnnotationModel() - ..name = 'View'; - fooNgMeta.ngDeps.reflectables.first.annotations.add(componentAnnotation); - fooNgMeta.ngDeps.reflectables.first.directives - .add(new PrefixedType()..name = 'directiveAlias'); - fooNgMeta.ngDeps.imports.add(new ImportModel()..uri = 'bar.dart'); - - fooNgMeta.aliases['directiveAlias'] = [barComponentMeta.type.name]; - barComponentMeta.template = - new CompileTemplateMetadata(template: 'BarTemplate'); - updateReader(); - - final outputs = await process(fooAssetId); - final ngDeps = outputs.ngDeps; - expect(ngDeps).toBeNotNull(); - expect(ngDeps.reflectables.first.annotations) - .toContain(new AnnotationModel() - ..name = 'FooComponentNgFactory' - ..isConstObject = true); - - expect(_generatedCode(outputs)) - ..toContain("import 'bar.dart'") - ..toContain("import 'bar.ngfactory.dart'"); - }); - - it('should create the same output for multiple calls.', () async { - fooComponentMeta.template = new CompileTemplateMetadata( - template: '
{{greeting}}
', - templateUrl: 'template.html'); - updateReader(); - - final firstOutputs = await process(fooAssetId); - final secondOutputs = await process(fooAssetId); - expect(firstOutputs.ngDeps).toEqual(secondOutputs.ngDeps); - expect(_generatedCode(firstOutputs)).toEqual(_generatedCode(secondOutputs)); - }); - - it('should gracefully handle null .ng_meta.json files', () async { - final dne = - new AssetId('package', 'lib/file_that_does_not_exist.ng_meta.json'); - - var didThrow = false; - await process(dne).then((out) { - expect(out).toBeNull(); - }).catchError((_) { - didThrow = true; - }); - - expect(didThrow).toBeFalse(); - }); - - it('should gracefully handle empty .ng_meta.json files', () async { - final emptyId = new AssetId('package', 'lib/empty.ng_meta.json'); - reader.addAsset(emptyId, ''); - - var didThrow = false; - await process(emptyId).then((out) { - expect(out).toBeNull(); - }).catchError((_) { - didThrow = true; - }); - - expect(didThrow).toBeFalse(); - }); - - it('should include platform directives.', () async { - fooComponentMeta.template = - new CompileTemplateMetadata(template: ''); - final viewAnnotation = new AnnotationModel() - ..name = 'View'; - - barNgMeta.aliases['PLATFORM'] = [barComponentMeta.type.name]; - updateReader(); - - final outputs = await process(fooAssetId, - platformDirectives: ['package:a/bar.dart#PLATFORM']); - final ngDeps = outputs.ngDeps; - expect(ngDeps).toBeNotNull(); - expect(_generatedCode(outputs)) - ..toBeNotNull() - ..toContain(barComponentMeta.template.template); - }); - - it('should include platform directives when it is a list.', () async { - fooComponentMeta.template = - new CompileTemplateMetadata(template: ''); - final viewAnnotation = new AnnotationModel() - ..name = 'View'; - - barNgMeta.identifiers['PLATFORM'] = barComponentMeta; - updateReader(); - - final outputs = await process(fooAssetId, - platformDirectives: ['package:a/bar.dart#PLATFORM']); - final ngDeps = outputs.ngDeps; - expect(ngDeps).toBeNotNull(); - expect(_generatedCode(outputs)) - ..toBeNotNull() - ..toContain(barComponentMeta.template.template); - }); - - it('should work when platform directives config is null.', () async { - final outputs = await process(fooAssetId, platformDirectives: null); - final ngDeps = outputs.ngDeps; - expect(ngDeps).toBeNotNull(); - }); - - it('should work when the platform directives config is not formatted properly.', - () async { - final outputs = await process(fooAssetId, platformDirectives: ['INVALID']); - final ngDeps = outputs.ngDeps; - expect(ngDeps).toBeNotNull(); - }); - - it('should work when the file with platform directives cannot be found.', - () async { - final outputs = await process(fooAssetId, - platformDirectives: ['package:a/invalid.dart#PLATFORM']); - final ngDeps = outputs.ngDeps; - expect(ngDeps).toBeNotNull(); - }); - - it('should work when the platform directives token cannot be found.', - () async { - final outputs = await process(fooAssetId, - platformDirectives: ['package:a/bar.dart#PLATFORM']); - final ngDeps = outputs.ngDeps; - expect(ngDeps).toBeNotNull(); - }); - - it('should parse `View` pipes with a single dependency.', () async { - fooComponentMeta.template = - new CompileTemplateMetadata(template: '{{1 | bar}}'); - final viewAnnotation = new AnnotationModel() - ..name = 'View'; - viewAnnotation.namedParameters.add(new NamedParameter() - ..name = 'pipes' - ..value = 'const [${barPipeMeta.type.name}]'); - fooNgMeta.ngDeps.reflectables.first.annotations.add(viewAnnotation); - fooNgMeta.ngDeps.reflectables.first.pipes - .add(new PrefixedType()..name = barPipeMeta.type.name); - fooNgMeta.ngDeps.imports.add(new ImportModel()..uri = 'bar.dart'); - updateReader(); - - final outputs = await process(fooAssetId); - - expect(_generatedCode(outputs)) - ..toContain("import 'bar.dart'") - ..toContain(barPipeMeta.name); - }); - - it('should include platform pipes.', () async { - fooComponentMeta.template = - new CompileTemplateMetadata(template: '{{1 | bar}}'); - - barNgMeta.aliases['PLATFORM'] = [barPipeMeta.type.name]; - updateReader(); - - final outputs = await process(fooAssetId, - platformPipes: ['package:a/bar.dart#PLATFORM']); - - expect(_generatedCode(outputs)) - ..toContain("import 'bar.dart'") - ..toContain(barPipeMeta.name); - }); - - it('should use i18n parser when translations are provided.', () async { - fooComponentMeta.template = new CompileTemplateMetadata( - template: '
content
', - templateUrl: 'template.html'); - updateReader(); - - final translations = deserializeXmb(""" - - another - - """, "someUrl"); - - final outputs = await process(fooAssetId, translations: translations); - expect(_generatedCode(outputs)).toContain('another'); - expect(_generatedCode(outputs)).not.toContain('content'); - }); -} - -String _generatedCode(Outputs outputs) { - final StringBuffer buf = new StringBuffer(); - final writer = new NgDepsWriter(buf); - writeTemplateFile(writer, outputs.ngDeps, outputs.templatesSource); - return buf.toString(); -} - -void _formatThenExpectEquals(String actual, String expected) { - expect(formatter.format(actual)).toEqual(formatter.format(expected)); -} diff --git a/modules_dart/transform/test/transform/template_compiler/directive_aliases_files/hello1.ng_deps.dart b/modules_dart/transform/test/transform/template_compiler/directive_aliases_files/hello1.ng_deps.dart deleted file mode 100644 index e0aa325fa5..0000000000 --- a/modules_dart/transform/test/transform/template_compiler/directive_aliases_files/hello1.ng_deps.dart +++ /dev/null @@ -1,28 +0,0 @@ -library playground.hello_world.index_common_dart.ng_deps.dart; - -import 'hello.dart'; -import 'package:angular2/angular2.dart' - show bootstrap, Component, Directive, View, NgElement; - -var _visited = false; -void initReflector(reflector) { - if (_visited) return; - _visited = true; - reflector - ..registerType( - HelloCmp, - new ReflectionInfo(const [ - const Component(selector: 'hello-app'), - const View(template: 'goodbye-app', directives: const [alias1]) - ], const [ - const [] - ], () => new HelloCmp())) - ..registerType( - GoodbyeCmp, - new ReflectionInfo(const [ - const Component(selector: 'goodbye-app'), - const View(template: 'Goodbye') - ], const [ - const [] - ], () => new GoodbyeCmp())); -} diff --git a/modules_dart/transform/test/transform/template_compiler/directive_aliases_files/hello2.ng_deps.dart b/modules_dart/transform/test/transform/template_compiler/directive_aliases_files/hello2.ng_deps.dart deleted file mode 100644 index 14dea497fe..0000000000 --- a/modules_dart/transform/test/transform/template_compiler/directive_aliases_files/hello2.ng_deps.dart +++ /dev/null @@ -1,28 +0,0 @@ -library playground.hello_world.index_common_dart.ng_deps.dart; - -import 'hello.dart'; -import 'package:angular2/angular2.dart' - show bootstrap, Component, Directive, View, NgElement; - -var _visited = false; -void initReflector(reflector) { - if (_visited) return; - _visited = true; - reflector - ..registerType( - HelloCmp, - new ReflectionInfo(const [ - const Component(selector: 'hello-app'), - const View(template: 'goodbye-app', directives: const [GoodbyeCmp]) - ], const [ - const [] - ], () => new HelloCmp())) - ..registerType( - GoodbyeCmp, - new ReflectionInfo(const [ - const Component(selector: 'goodbye-app'), - const View(template: 'Goodbye') - ], const [ - const [] - ], () => new GoodbyeCmp())); -} diff --git a/modules_dart/transform/test/transform/template_compiler/directive_event_files/expected/hello.ng_deps.dart b/modules_dart/transform/test/transform/template_compiler/directive_event_files/expected/hello.ng_deps.dart deleted file mode 100644 index a829f48268..0000000000 --- a/modules_dart/transform/test/transform/template_compiler/directive_event_files/expected/hello.ng_deps.dart +++ /dev/null @@ -1,19 +0,0 @@ -library playground.hello_world.index_common_dart.ng_deps.dart; - -import 'hello.dart'; -import 'package:angular2/angular2.dart' - show Component, Directive, View, NgElement; - -var _visited = false; -void initReflector(reflector) { - if (_visited) return; - _visited = true; - reflector - ..registerType( - HelloDirective, - new ReflectionInfo(const [ - const Directive(selector: 'hello', outputs: const ['eventName']) - ], const [ - const [] - ], () => new HelloDirective())); -} diff --git a/modules_dart/transform/test/transform/template_compiler/directive_event_files/hello.ng_deps.dart b/modules_dart/transform/test/transform/template_compiler/directive_event_files/hello.ng_deps.dart deleted file mode 100644 index a829f48268..0000000000 --- a/modules_dart/transform/test/transform/template_compiler/directive_event_files/hello.ng_deps.dart +++ /dev/null @@ -1,19 +0,0 @@ -library playground.hello_world.index_common_dart.ng_deps.dart; - -import 'hello.dart'; -import 'package:angular2/angular2.dart' - show Component, Directive, View, NgElement; - -var _visited = false; -void initReflector(reflector) { - if (_visited) return; - _visited = true; - reflector - ..registerType( - HelloDirective, - new ReflectionInfo(const [ - const Directive(selector: 'hello', outputs: const ['eventName']) - ], const [ - const [] - ], () => new HelloDirective())); -} diff --git a/modules_dart/transform/test/transform/template_compiler/event_files/expected/hello.ng_deps.dart b/modules_dart/transform/test/transform/template_compiler/event_files/expected/hello.ng_deps.dart deleted file mode 100644 index d5b9b5902a..0000000000 --- a/modules_dart/transform/test/transform/template_compiler/event_files/expected/hello.ng_deps.dart +++ /dev/null @@ -1,23 +0,0 @@ -library playground.hello_world.index_common_dart.ng_deps.dart; - -import 'hello.ngfactory.dart' as _templates; - -import 'hello.dart'; -import 'package:angular2/angular2.dart' - show Component, Directive, View, NgElement; - -var _visited = false; -void initReflector(reflector) { - if (_visited) return; - _visited = true; - reflector - ..registerType( - HelloCmp, - new ReflectionInfo(const [ - const Component(selector: 'hello-app', outputs: const ['eventName']), - const View(template: ''), - _templates.HostHelloCmpTemplate - ], const [ - const [] - ], () => new HelloCmp())); -} diff --git a/modules_dart/transform/test/transform/template_compiler/event_files/hello.ng_deps.dart b/modules_dart/transform/test/transform/template_compiler/event_files/hello.ng_deps.dart deleted file mode 100644 index 4a4dc4e330..0000000000 --- a/modules_dart/transform/test/transform/template_compiler/event_files/hello.ng_deps.dart +++ /dev/null @@ -1,20 +0,0 @@ -library playground.hello_world.index_common_dart.ng_deps.dart; - -import 'hello.dart'; -import 'package:angular2/angular2.dart' - show Component, Directive, View, NgElement; - -var _visited = false; -void initReflector(reflector) { - if (_visited) return; - _visited = true; - reflector - ..registerType( - HelloCmp, - new ReflectionInfo(const [ - const Component(selector: 'hello-app', outputs: const ['eventName']), - const View(template: '') - ], const [ - const [] - ], () => new HelloCmp())); -} diff --git a/modules_dart/transform/test/transform/template_compiler/inline_expression_files/expected/hello.ng_deps.dart b/modules_dart/transform/test/transform/template_compiler/inline_expression_files/expected/hello.ng_deps.dart deleted file mode 100644 index 4f4146ec47..0000000000 --- a/modules_dart/transform/test/transform/template_compiler/inline_expression_files/expected/hello.ng_deps.dart +++ /dev/null @@ -1,23 +0,0 @@ -library playground.hello_world.index_common_dart.ng_deps.dart; - -import 'hello.ngfactory.dart' as _templates; - -import 'hello.dart'; -import 'package:angular2/angular2.dart' - show Component, Directive, View, NgElement; - -var _visited = false; -void initReflector(reflector) { - if (_visited) return; - _visited = true; - reflector - ..registerType( - HelloCmp, - new ReflectionInfo(const [ - const Component(selector: 'hello-app'), - const View(template: '
{{greeting}}
'), - _templates.HostHelloCmpTemplate - ], const [ - const [] - ], () => new HelloCmp())); -} diff --git a/modules_dart/transform/test/transform/template_compiler/inline_expression_files/hello.ng_deps.dart b/modules_dart/transform/test/transform/template_compiler/inline_expression_files/hello.ng_deps.dart deleted file mode 100644 index 6100e0ce13..0000000000 --- a/modules_dart/transform/test/transform/template_compiler/inline_expression_files/hello.ng_deps.dart +++ /dev/null @@ -1,20 +0,0 @@ -library playground.hello_world.index_common_dart.ng_deps.dart; - -import 'hello.dart'; -import 'package:angular2/angular2.dart' - show Component, Directive, View, NgElement; - -var _visited = false; -void initReflector(reflector) { - if (_visited) return; - _visited = true; - reflector - ..registerType( - HelloCmp, - new ReflectionInfo(const [ - const Component(selector: 'hello-app'), - const View(template: '
{{greeting}}
') - ], const [ - const [] - ], () => new HelloCmp())); -} diff --git a/modules_dart/transform/test/transform/template_compiler/inline_method_files/expected/hello.ng_deps.dart b/modules_dart/transform/test/transform/template_compiler/inline_method_files/expected/hello.ng_deps.dart deleted file mode 100644 index c1fbb1d1b8..0000000000 --- a/modules_dart/transform/test/transform/template_compiler/inline_method_files/expected/hello.ng_deps.dart +++ /dev/null @@ -1,23 +0,0 @@ -library playground.hello_world.index_common_dart.ng_deps.dart; - -import 'hello.ngfactory.dart' as _templates; - -import 'hello.dart'; -import 'package:angular2/angular2.dart' - show Component, Directive, View, NgElement; - -var _visited = false; -void initReflector(reflector) { - if (_visited) return; - _visited = true; - reflector - ..registerType( - HelloCmp, - new ReflectionInfo(const [ - const Component(selector: 'hello-app'), - const View(template: ''), - _templates.HostHelloCmpTemplate - ], const [ - const [] - ], () => new HelloCmp())); -} diff --git a/modules_dart/transform/test/transform/template_compiler/inline_method_files/hello.ng_deps.dart b/modules_dart/transform/test/transform/template_compiler/inline_method_files/hello.ng_deps.dart deleted file mode 100644 index ed508cfe68..0000000000 --- a/modules_dart/transform/test/transform/template_compiler/inline_method_files/hello.ng_deps.dart +++ /dev/null @@ -1,20 +0,0 @@ -library playground.hello_world.index_common_dart.ng_deps.dart; - -import 'hello.dart'; -import 'package:angular2/angular2.dart' - show Component, Directive, View, NgElement; - -var _visited = false; -void initReflector(reflector) { - if (_visited) return; - _visited = true; - reflector - ..registerType( - HelloCmp, - new ReflectionInfo(const [ - const Component(selector: 'hello-app'), - const View(template: '') - ], const [ - const [] - ], () => new HelloCmp())); -} diff --git a/modules_dart/transform/test/transform/template_compiler/one_directive_files/expected/hello.ng_deps.dart b/modules_dart/transform/test/transform/template_compiler/one_directive_files/expected/hello.ng_deps.dart deleted file mode 100644 index 2310fcb6fa..0000000000 --- a/modules_dart/transform/test/transform/template_compiler/one_directive_files/expected/hello.ng_deps.dart +++ /dev/null @@ -1,32 +0,0 @@ -library playground.hello_world.index_common_dart.ng_deps.dart; - -import 'hello.ngfactory.dart' as _templates; - -import 'hello.dart'; -import 'package:angular2/angular2.dart' - show Component, Directive, View, NgElement; - -var _visited = false; -void initReflector(reflector) { - if (_visited) return; - _visited = true; - reflector - ..registerType( - HelloCmp, - new ReflectionInfo(const [ - const Component(selector: 'hello-app'), - const View(template: 'goodbye-app', directives: const [GoodbyeCmp]), - _templates.HostHelloCmpTemplate - ], const [ - const [] - ], () => new HelloCmp())) - ..registerType( - GoodbyeCmp, - new ReflectionInfo(const [ - const Component(selector: 'goodbye-app'), - const View(template: 'Goodbye'), - _templates.HostGoodbyeCmpTemplate - ], const [ - const [] - ], () => new GoodbyeCmp())); -} diff --git a/modules_dart/transform/test/transform/template_compiler/one_directive_files/hello.ng_deps.dart b/modules_dart/transform/test/transform/template_compiler/one_directive_files/hello.ng_deps.dart deleted file mode 100644 index a83eb2bef2..0000000000 --- a/modules_dart/transform/test/transform/template_compiler/one_directive_files/hello.ng_deps.dart +++ /dev/null @@ -1,28 +0,0 @@ -library playground.hello_world.index_common_dart.ng_deps.dart; - -import 'hello.dart'; -import 'package:angular2/angular2.dart' - show Component, Directive, View, NgElement; - -var _visited = false; -void initReflector(reflector) { - if (_visited) return; - _visited = true; - reflector - ..registerType( - HelloCmp, - new ReflectionInfo(const [ - const Component(selector: 'hello-app'), - const View(template: 'goodbye-app', directives: const [GoodbyeCmp]) - ], const [ - const [] - ], () => new HelloCmp())) - ..registerType( - GoodbyeCmp, - new ReflectionInfo(const [ - const Component(selector: 'goodbye-app'), - const View(template: 'Goodbye') - ], const [ - const [] - ], () => new GoodbyeCmp())); -} diff --git a/modules_dart/transform/test/transform/template_compiler/registrations_files/expected/registrations.ng_deps.dart b/modules_dart/transform/test/transform/template_compiler/registrations_files/expected/registrations.ng_deps.dart deleted file mode 100644 index aee27fd102..0000000000 --- a/modules_dart/transform/test/transform/template_compiler/registrations_files/expected/registrations.ng_deps.dart +++ /dev/null @@ -1,88 +0,0 @@ -library playground.hello_world.index_common_dart.ng_deps.dart; - -import 'dependency.dart'; -import 'dependency.ng_deps.dart' as i0; -import 'hello.dart'; -import 'package:angular2/angular2.dart' - show Component, Directive, View, NgElement; - -var _visited = false; -void initReflector(reflector) { - if (_visited) return; - _visited = true; - reflector - ..registerType( - TextBindingsCmp, - new ReflectionInfo(const [ - const Component(selector: 'text'), - const View(template: '{{textBindings}}') - ], const [ - const [] - ], () => new TextBindingsCmp())) - ..registerType( - PropertyBindingsCmp, - new ReflectionInfo(const [ - const Component(selector: 'props'), - const View(template: '
') - ], const [ - const [] - ], () => new PropertyBindingsCmp())) - ..registerType( - EventsCmp, - new ReflectionInfo(const [ - const Component(selector: 'events', outputs: const ['eventName']), - const View(template: 'Hi') - ], const [ - const [] - ], () => new EventsCmp())) - ..registerType( - SubEventsCmp, - new ReflectionInfo(const [ - const Component(selector: 'sub-events'), - const View( - template: '', - directives: const [DependencyCmp]) - ], const [ - const [] - ], () => new SubEventsCmp())) - ..registerType( - TemplateEventsCmp, - new ReflectionInfo(const [ - const Component(selector: 'template-events'), - const View(template: '
') - ], const [ - const [] - ], () => new TemplateEventsCmp())) - ..registerType( - DirectivePropsCmp, - new ReflectionInfo(const [ - const Component(selector: 'directive-props-cmp'), - const View( - template: '
', - directives: const [DirectiveProps]) - ], const [ - const [] - ], () => new DirectivePropsCmp())) - ..registerType( - DirectiveEventsCmp, - new ReflectionInfo(const [ - const Component(selector: 'directive-events-cmp'), - const View( - template: '
', - directives: const [DirectiveEvents]) - ], const [ - const [] - ], () => new DirectiveEventsCmp())) - ..registerType( - RecursiveCmp, - new ReflectionInfo(const [ - const Component(selector: 'recursive-cmp'), - const View( - template: - '
  • test
  • ', - directives: const [NgFor]) - ], const [ - const [] - ], () => new RecursiveCmp())); - i0.initReflector(); -} diff --git a/modules_dart/transform/test/transform/template_compiler/registrations_files/registrations.ng_deps.dart b/modules_dart/transform/test/transform/template_compiler/registrations_files/registrations.ng_deps.dart deleted file mode 100644 index aee27fd102..0000000000 --- a/modules_dart/transform/test/transform/template_compiler/registrations_files/registrations.ng_deps.dart +++ /dev/null @@ -1,88 +0,0 @@ -library playground.hello_world.index_common_dart.ng_deps.dart; - -import 'dependency.dart'; -import 'dependency.ng_deps.dart' as i0; -import 'hello.dart'; -import 'package:angular2/angular2.dart' - show Component, Directive, View, NgElement; - -var _visited = false; -void initReflector(reflector) { - if (_visited) return; - _visited = true; - reflector - ..registerType( - TextBindingsCmp, - new ReflectionInfo(const [ - const Component(selector: 'text'), - const View(template: '{{textBindings}}') - ], const [ - const [] - ], () => new TextBindingsCmp())) - ..registerType( - PropertyBindingsCmp, - new ReflectionInfo(const [ - const Component(selector: 'props'), - const View(template: '
    ') - ], const [ - const [] - ], () => new PropertyBindingsCmp())) - ..registerType( - EventsCmp, - new ReflectionInfo(const [ - const Component(selector: 'events', outputs: const ['eventName']), - const View(template: 'Hi') - ], const [ - const [] - ], () => new EventsCmp())) - ..registerType( - SubEventsCmp, - new ReflectionInfo(const [ - const Component(selector: 'sub-events'), - const View( - template: '', - directives: const [DependencyCmp]) - ], const [ - const [] - ], () => new SubEventsCmp())) - ..registerType( - TemplateEventsCmp, - new ReflectionInfo(const [ - const Component(selector: 'template-events'), - const View(template: '
    ') - ], const [ - const [] - ], () => new TemplateEventsCmp())) - ..registerType( - DirectivePropsCmp, - new ReflectionInfo(const [ - const Component(selector: 'directive-props-cmp'), - const View( - template: '
    ', - directives: const [DirectiveProps]) - ], const [ - const [] - ], () => new DirectivePropsCmp())) - ..registerType( - DirectiveEventsCmp, - new ReflectionInfo(const [ - const Component(selector: 'directive-events-cmp'), - const View( - template: '
    ', - directives: const [DirectiveEvents]) - ], const [ - const [] - ], () => new DirectiveEventsCmp())) - ..registerType( - RecursiveCmp, - new ReflectionInfo(const [ - const Component(selector: 'recursive-cmp'), - const View( - template: - '
  • test
  • ', - directives: const [NgFor]) - ], const [ - const [] - ], () => new RecursiveCmp())); - i0.initReflector(); -} diff --git a/modules_dart/transform/test/transform/template_compiler/url_expression_files/expected/hello.ng_deps.dart b/modules_dart/transform/test/transform/template_compiler/url_expression_files/expected/hello.ng_deps.dart deleted file mode 100644 index ab2d9a6172..0000000000 --- a/modules_dart/transform/test/transform/template_compiler/url_expression_files/expected/hello.ng_deps.dart +++ /dev/null @@ -1,23 +0,0 @@ -library playground.src.hello_world.index_common_dart; - -import 'hello.ngfactory.dart' as _templates; - -import 'hello.dart'; -import 'package:angular2/angular2.dart' - show Component, Directive, View, NgElement; - -var _visited = false; -void initReflector(reflector) { - if (_visited) return; - _visited = true; - reflector - ..registerType( - HelloCmp, - new ReflectionInfo(const [ - const Component(selector: 'hello-app'), - const View(templateUrl: 'template.html'), - _templates.HostHelloCmpTemplate - ], const [ - const [] - ], () => new HelloCmp())); -} diff --git a/modules_dart/transform/test/transform/template_compiler/url_expression_files/hello.ng_deps.dart b/modules_dart/transform/test/transform/template_compiler/url_expression_files/hello.ng_deps.dart deleted file mode 100644 index 8d9def4686..0000000000 --- a/modules_dart/transform/test/transform/template_compiler/url_expression_files/hello.ng_deps.dart +++ /dev/null @@ -1,20 +0,0 @@ -library playground.src.hello_world.index_common_dart; - -import 'hello.dart'; -import 'package:angular2/angular2.dart' - show Component, Directive, View, NgElement; - -var _visited = false; -void initReflector(reflector) { - if (_visited) return; - _visited = true; - reflector - ..registerType( - HelloCmp, - new ReflectionInfo(const [ - const Component(selector: 'hello-app'), - const View(templateUrl: 'template.html') - ], const [ - const [] - ], () => new HelloCmp())); -} diff --git a/modules_dart/transform/test/transform/template_compiler/url_method_files/expected/hello.ng_deps.dart b/modules_dart/transform/test/transform/template_compiler/url_method_files/expected/hello.ng_deps.dart deleted file mode 100644 index ab2d9a6172..0000000000 --- a/modules_dart/transform/test/transform/template_compiler/url_method_files/expected/hello.ng_deps.dart +++ /dev/null @@ -1,23 +0,0 @@ -library playground.src.hello_world.index_common_dart; - -import 'hello.ngfactory.dart' as _templates; - -import 'hello.dart'; -import 'package:angular2/angular2.dart' - show Component, Directive, View, NgElement; - -var _visited = false; -void initReflector(reflector) { - if (_visited) return; - _visited = true; - reflector - ..registerType( - HelloCmp, - new ReflectionInfo(const [ - const Component(selector: 'hello-app'), - const View(templateUrl: 'template.html'), - _templates.HostHelloCmpTemplate - ], const [ - const [] - ], () => new HelloCmp())); -} diff --git a/modules_dart/transform/test/transform/template_compiler/url_method_files/hello.ng_deps.dart b/modules_dart/transform/test/transform/template_compiler/url_method_files/hello.ng_deps.dart deleted file mode 100644 index 8d9def4686..0000000000 --- a/modules_dart/transform/test/transform/template_compiler/url_method_files/hello.ng_deps.dart +++ /dev/null @@ -1,20 +0,0 @@ -library playground.src.hello_world.index_common_dart; - -import 'hello.dart'; -import 'package:angular2/angular2.dart' - show Component, Directive, View, NgElement; - -var _visited = false; -void initReflector(reflector) { - if (_visited) return; - _visited = true; - reflector - ..registerType( - HelloCmp, - new ReflectionInfo(const [ - const Component(selector: 'hello-app'), - const View(templateUrl: 'template.html') - ], const [ - const [] - ], () => new HelloCmp())); -} diff --git a/modules_dart/transform/test/transform/template_compiler/with_prefix_files/expected/goodbye.ng_deps.dart b/modules_dart/transform/test/transform/template_compiler/with_prefix_files/expected/goodbye.ng_deps.dart deleted file mode 100644 index 94cf6b5691..0000000000 --- a/modules_dart/transform/test/transform/template_compiler/with_prefix_files/expected/goodbye.ng_deps.dart +++ /dev/null @@ -1,23 +0,0 @@ -library playground.hello_world.index_common_dart.ng_deps.dart; - -import 'goodbye.ngfactory.dart' as _templates; - -import 'goodbye.dart'; -import 'package:angular2/angular2.dart' - show Component, Directive, View, NgElement; - -var _visited = false; -void initReflector(reflector) { - if (_visited) return; - _visited = true; - reflector - ..registerType( - GoodbyeCmp, - new ReflectionInfo(const [ - const Component(selector: 'goodbye-app'), - const View(template: 'Goodbye {{name}}'), - _templates.HostGoodbyeCmpTemplate - ], const [ - const [] - ], () => new GoodbyeCmp())); -} diff --git a/modules_dart/transform/test/transform/template_compiler/with_prefix_files/expected/hello.ng_deps.dart b/modules_dart/transform/test/transform/template_compiler/with_prefix_files/expected/hello.ng_deps.dart deleted file mode 100644 index 85d4211b59..0000000000 --- a/modules_dart/transform/test/transform/template_compiler/with_prefix_files/expected/hello.ng_deps.dart +++ /dev/null @@ -1,27 +0,0 @@ -library playground.hello_world.index_common_dart.ng_deps.dart; - -import 'hello.ngfactory.dart' as _templates; - -import 'hello.dart'; -import 'goodbye.dart' as prefix; -import 'goodbye.ng_deps.dart' as i0; -import 'package:angular2/angular2.dart' - show Component, Directive, View, NgElement; - -var _visited = false; -void initReflector(reflector) { - if (_visited) return; - _visited = true; - reflector - ..registerType( - HelloCmp, - new ReflectionInfo(const [ - const Component(selector: 'hello-app'), - const View( - template: 'goodbye-app', directives: const [prefix.GoodbyeCmp]), - _templates.HostHelloCmpTemplate - ], const [ - const [] - ], () => new HelloCmp())); - i0.initReflector(reflector); -} diff --git a/modules_dart/transform/test/transform/template_compiler/with_prefix_files/goodbye.ng_deps.dart b/modules_dart/transform/test/transform/template_compiler/with_prefix_files/goodbye.ng_deps.dart deleted file mode 100644 index 087c88aa55..0000000000 --- a/modules_dart/transform/test/transform/template_compiler/with_prefix_files/goodbye.ng_deps.dart +++ /dev/null @@ -1,20 +0,0 @@ -library playground.hello_world.index_common_dart.ng_deps.dart; - -import 'goodbye.dart'; -import 'package:angular2/angular2.dart' - show Component, Directive, View, NgElement; - -var _visited = false; -void initReflector(reflector) { - if (_visited) return; - _visited = true; - reflector - ..registerType( - GoodbyeCmp, - new ReflectionInfo(const [ - const Component(selector: 'goodbye-app'), - const View(template: 'Goodbye {{name}}') - ], const [ - const [] - ], () => new GoodbyeCmp())); -} diff --git a/modules_dart/transform/test/transform/template_compiler/with_prefix_files/hello.ng_deps.dart b/modules_dart/transform/test/transform/template_compiler/with_prefix_files/hello.ng_deps.dart deleted file mode 100644 index 60e4734629..0000000000 --- a/modules_dart/transform/test/transform/template_compiler/with_prefix_files/hello.ng_deps.dart +++ /dev/null @@ -1,24 +0,0 @@ -library playground.hello_world.index_common_dart.ng_deps.dart; - -import 'hello.dart'; -import 'goodbye.dart' as prefix; -import 'goodbye.ng_deps.dart' as i0; -import 'package:angular2/angular2.dart' - show Component, Directive, View, NgElement; - -var _visited = false; -void initReflector(reflector) { - if (_visited) return; - _visited = true; - reflector - ..registerType( - HelloCmp, - new ReflectionInfo(const [ - const Component(selector: 'hello-app'), - const View( - template: 'goodbye-app', directives: const [prefix.GoodbyeCmp]) - ], const [ - const [] - ], () => new HelloCmp())); - i0.initReflector(reflector); -} diff --git a/modules_dart/transform/test/transform/transform.e2e.server.spec.dart b/modules_dart/transform/test/transform/transform.e2e.server.spec.dart deleted file mode 100644 index 1e0d4482ad..0000000000 --- a/modules_dart/transform/test/transform/transform.e2e.server.spec.dart +++ /dev/null @@ -1,11 +0,0 @@ -library angular2.test.transform.transform.e2e.spec; - -import 'package:test/test.dart'; - -import 'inliner_for_test/all_tests.dart' as inliner; -import 'integration/all_tests.dart' as integration; - -main() { - group('Inliner For Test e2e', inliner.endToEndTests); - group('Transformer Pipeline', integration.allTests); -} diff --git a/modules_dart/transform/test/transform/transform.server.spec.dart b/modules_dart/transform/test/transform/transform.server.spec.dart deleted file mode 100644 index c59b1b49b2..0000000000 --- a/modules_dart/transform/test/transform/transform.server.spec.dart +++ /dev/null @@ -1,26 +0,0 @@ -@TestOn('vm') -library angular2.test.transform.transform.server.spec; - -import 'package:test/test.dart'; - -import 'common/annotation_matcher_test.dart' as annotationMatcher; -import 'common/async_string_writer_tests.dart' as asyncStringWriter; -import 'common/code/ng_deps_code_tests.dart' as ngDepsCode; -import 'common/ng_meta_test.dart' as ngMetaTest; -import 'common/url_resolver_tests.dart' as urlResolver; -import 'deferred_rewriter/all_tests.dart' as deferredRewriter; -import 'directive_metadata_linker/all_tests.dart' as directiveMeta; -import 'directive_processor/all_tests.dart' as directiveProcessor; -import 'inliner_for_test/all_tests.dart' as inliner; - -main() { - group('AnnotationMatcher', annotationMatcher.allTests); - group('AsyncStringWriter', asyncStringWriter.allTests); - group('Deferred Rewriter', deferredRewriter.allTests); - group('Directive Metadata Linker', directiveMeta.allTests); - group('Directive Processor', directiveProcessor.allTests); - group('Inliner For Test', inliner.allTests); - group('NgDepsCode', ngDepsCode.allTests); - group('NgMeta', ngMetaTest.allTests); - group('Url Resolver', urlResolver.allTests); -} diff --git a/modules_dart/transform/test/transform/transform.unittest.server.spec.dart b/modules_dart/transform/test/transform/transform.unittest.server.spec.dart deleted file mode 100644 index 0f9b51a58f..0000000000 --- a/modules_dart/transform/test/transform/transform.unittest.server.spec.dart +++ /dev/null @@ -1,18 +0,0 @@ -library angular2.test.transform.transform.old.spec; - -import 'package:guinness/guinness.dart'; -import 'package:unittest/unittest.dart' hide expect; -import 'package:unittest/vm_config.dart'; - -import 'reflection_remover/all_tests.dart' as reflectionRemover; -import 'template_compiler/all_tests.dart' as templateCompiler; -import 'stylesheet_compiler/all_tests.dart' as stylesheetCompiler; - -main() { - useVMConfiguration(); - describe('Reflection Remover', reflectionRemover.allTests); - describe('Template Compiler', templateCompiler.allTests); - describe('Stylesheet Compiler', stylesheetCompiler.allTests); -} - - diff --git a/protractor-dart2js.conf.js b/protractor-dart2js.conf.js deleted file mode 100644 index 20bba31013..0000000000 --- a/protractor-dart2js.conf.js +++ /dev/null @@ -1,18 +0,0 @@ -var data = module.exports = require('./protractor-shared.js'); -var config = data.config; - -config.baseUrl = 'http://localhost:8002/'; - -config.exclude.push( - 'dist/js/cjs/playground/e2e_test/sourcemap/sourcemap_spec.js', - 'dist/js/cjs/playground/e2e_test/http/http_spec.js', - 'dist/js/cjs/playground/e2e_test/jsonp/jsonp_spec.js', - // TODO: remove this line when largetable dart has been added - 'dist/js/cjs/benchmarks_external/e2e_test/largetable_perf.js', - 'dist/js/cjs/benchmarks_external/e2e_test/polymer_tree_perf.js', - 'dist/js/cjs/benchmarks_external/e2e_test/react_tree_perf.js' - -); - -data.createBenchpressRunner({ lang: 'dart' }); - diff --git a/protractor-ddc.conf.js b/protractor-ddc.conf.js deleted file mode 100644 index cb0413456e..0000000000 --- a/protractor-ddc.conf.js +++ /dev/null @@ -1,3 +0,0 @@ -var data = module.exports = require('./protractor-shared.js'); -var config = data.config; -config.baseUrl = 'http://localhost:8003/'; diff --git a/pubspec.yaml b/pubspec.yaml deleted file mode 100644 index 527fd76836..0000000000 --- a/pubspec.yaml +++ /dev/null @@ -1,10 +0,0 @@ -name: angular -environment: - sdk: '>=1.12.0-dev.5.10 <2.0.0' -dependencies: - observe: '^0.13.1' -dev_dependencies: - guinness2: '0.0.5' - intl: '^0.12.4' - unittest: '^0.11.5+4' - quiver: '^0.21.4'