feat(dart/transform) Allow ctor stubs to be tree shaken

Change the method used to discover Directive annotated classes to ensure
that the Dart code can be tree shaken.

Closes #497

Closes $\x23736
This commit is contained in:
Tim Blasi
2015-02-19 12:00:09 -08:00
committed by Misko Hevery
parent 0c4fbfc8e2
commit fb49946160
20 changed files with 461 additions and 142 deletions
@@ -0,0 +1,14 @@
// 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<Binding> bindings = null,
Function givenBootstrapErrorReporter = null]) {
return null;
}
@@ -1,5 +1,6 @@
library web_foo;
import 'package:angular2/src/core/annotations/annotations.dart';
import 'package:angular2/src/core/application.dart';
void main() {}
@@ -1,7 +1,8 @@
library web_foo;
import 'package:angular2/src/core/application.dart';
import 'bar.dart';
void main() {
new Component('Things');
bootstrap(MyComponent);
}
@@ -1,7 +1,8 @@
library web_foo;
import 'package:angular2/src/core/application.dart';
import 'bar.dart';
void main() {
new MyComponent('Things');
bootstrap(MyComponent);
}
@@ -1,7 +1,8 @@
library web_foo;
import 'package:angular2/src/core/application.dart';
import 'bar.dart';
void main() {
new MyComponent();
bootstrap(MyComponent);
}
@@ -17,7 +17,7 @@ main() {
}
var formatter = new DartFormatter();
var transform = new AngularTransformer(new TransformerOptions(
var transform = new AngularTransformer(new TransformerOptions('web/index.dart',
'web/index.dart', 'web/index.bootstrap.dart', 'web/index.html'));
class TestConfig {
@@ -40,7 +40,8 @@ void _runTests() {
'a|web/index.html': 'common.html',
'a|web/index.dart': 'html_entry_point_files/index.dart',
'angular2|lib/src/core/annotations/annotations.dart':
'../../lib/src/core/annotations/annotations.dart'
'../../lib/src/core/annotations/annotations.dart',
'angular2|lib/src/core/application.dart': 'common.dart'
},
outputs: {
'a|web/index.html': 'html_entry_point_files/expected/index.html'
@@ -51,7 +52,8 @@ void _runTests() {
'a|web/index.dart': 'simple_annotation_files/index.dart',
'a|web/bar.dart': 'simple_annotation_files/bar.dart',
'angular2|lib/src/core/annotations/annotations.dart':
'../../lib/src/core/annotations/annotations.dart'
'../../lib/src/core/annotations/annotations.dart',
'angular2|lib/src/core/application.dart': 'common.dart'
},
outputs: {
'a|web/index.bootstrap.dart':
@@ -64,7 +66,8 @@ void _runTests() {
'a|web/foo.dart': 'two_deps_files/foo.dart',
'a|web/bar.dart': 'two_deps_files/bar.dart',
'angular2|lib/src/core/annotations/annotations.dart':
'../../lib/src/core/annotations/annotations.dart'
'../../lib/src/core/annotations/annotations.dart',
'angular2|lib/src/core/application.dart': 'common.dart'
},
outputs: {
'a|web/index.bootstrap.dart':
@@ -77,7 +80,8 @@ void _runTests() {
'a|web/foo.dart': 'list_of_types_files/foo.dart',
'a|web/bar.dart': 'list_of_types_files/bar.dart',
'angular2|lib/src/core/annotations/annotations.dart':
'../../lib/src/core/annotations/annotations.dart'
'../../lib/src/core/annotations/annotations.dart',
'angular2|lib/src/core/application.dart': 'common.dart'
},
outputs: {
'a|web/index.bootstrap.dart':
@@ -89,12 +93,28 @@ void _runTests() {
'a|web/index.dart': 'synthetic_ctor_files/index.dart',
'a|web/bar.dart': 'synthetic_ctor_files/bar.dart',
'angular2|lib/src/core/annotations/annotations.dart':
'../../lib/src/core/annotations/annotations.dart'
'../../lib/src/core/annotations/annotations.dart',
'angular2|lib/src/core/application.dart': 'common.dart'
},
outputs: {
'a|web/index.bootstrap.dart':
'synthetic_ctor_files/expected/index.bootstrap.dart'
})
}),
new TestConfig('Component with two annotations',
inputs: {
'a|web/index.html': 'common.html',
'a|web/index.dart': 'two_annotations_files/index.dart',
'a|web/bar.dart': 'two_annotations_files/bar.dart',
'angular2|lib/src/core/annotations/annotations.dart':
'../../lib/src/core/annotations/annotations.dart',
'angular2|lib/src/core/annotations/template.dart':
'../../lib/src/core/annotations/template.dart',
'angular2|lib/src/core/application.dart': 'common.dart'
},
outputs: {
'a|web/index.bootstrap.dart':
'two_annotations_files/expected/index.bootstrap.dart'
}),
];
var cache = {};
@@ -0,0 +1,10 @@
library bar;
import 'package:angular2/src/core/annotations/annotations.dart';
import 'package:angular2/src/core/annotations/template.dart';
@Component(selector: '[soup]')
@Template(inline: 'Salad')
class MyComponent {
MyComponent();
}
@@ -0,0 +1,18 @@
import 'package:angular2/src/reflection/reflection.dart' show reflector;
import 'bar.dart' as i0;
import 'package:angular2/src/core/annotations/annotations.dart' as i1;
import 'package:angular2/src/core/annotations/template.dart' as i2;
import 'index.dart' as i3;
main() {
reflector
..registerType(i0.MyComponent, {
"factory": () => new i0.MyComponent(),
"parameters": const [const []],
"annotations": const [
const i1.Component(selector: '[soup]'),
const i2.Template(inline: 'Salad')
]
});
i3.main();
}
@@ -0,0 +1,8 @@
library web_foo;
import 'package:angular2/src/core/application.dart';
import 'bar.dart';
void main() {
bootstrap(MyComponent);
}
@@ -10,9 +10,7 @@ main() {
"factory":
(i1.MyContext c, String inValue) => new i0.MyComponent(c, inValue),
"parameters": const [const [i1.MyContext, String]],
"annotations": const [
const i2.Component(selector: i1.preDefinedSelector)
]
"annotations": const [const i2.Component(selector: i1.preDefinedSelector)]
});
i3.main();
}
@@ -1,7 +1,8 @@
library web_foo;
import 'package:angular2/src/core/application.dart';
import 'bar.dart';
void main() {
new MyComponent('Things');
bootstrap(MyComponent);
}