chore(transform): move transform module to modules_dart

The build/pure-packages.dart gulp task has also been updated to move the files into the angular2 tree.
Closes #3729
This commit is contained in:
Jeff Cross
2015-08-19 10:36:52 -07:00
parent 92da5430e7
commit 88a5b8da0f
245 changed files with 16 additions and 3 deletions

View File

@ -1,51 +0,0 @@
library angular2.test.transform.bind_generator.all_tests;
import 'package:barback/barback.dart';
import 'package:angular2/src/transform/bind_generator/generator.dart';
import 'package:dart_style/dart_style.dart';
import 'package:guinness/guinness.dart';
import '../common/read_file.dart';
var formatter = new DartFormatter();
main() => allTests();
void allTests() {
var reader = new TestAssetReader();
it('should generate a setter for a `properties` property in an annotation.',
() async {
var inputPath = 'bind_generator/basic_bind_files/bar.ng_deps.dart';
var expected = formatter.format(
readFile('bind_generator/basic_bind_files/expected/bar.ng_deps.dart'));
var output = formatter.format(
await createNgSettersAndGetters(reader, new AssetId('a', inputPath)));
expect(output).toEqual(expected);
});
it(
'should generate a single setter when multiple annotations bind to the '
'same property.', () async {
var inputPath =
'bind_generator/duplicate_bind_name_files/soup.ng_deps.dart';
var expected = formatter.format(readFile(
'bind_generator/duplicate_bind_name_files/expected/soup.ng_deps.dart'));
var output = formatter.format(
await createNgSettersAndGetters(reader, new AssetId('a', inputPath)));
expect(output).toEqual(expected);
});
it('should generate a getter for a `events` property in an annotation.',
() async {
var inputPath = 'bind_generator/events_files/bar.ng_deps.dart';
var expected = formatter.format(
readFile('bind_generator/events_files/expected/bar.ng_deps.dart'));
var output = formatter.format(
await createNgSettersAndGetters(reader, new AssetId('a', inputPath)));
expect(output).toEqual(expected);
});
}

View File

@ -1,17 +0,0 @@
library bar.ng_deps.dart;
import 'bar.dart';
import 'package:angular2/src/core/metadata.dart';
var _visited = false;
void initReflector(reflector) {
if (_visited) return;
_visited = true;
reflector
..registerType(
ToolTip,
new ReflectionInfo(const [
const Directive(
selector: '[tool-tip]', properties: const ['text: tool-tip'])
], const [], () => new ToolTip()));
}

View File

@ -1,18 +0,0 @@
library bar.ng_deps.dart;
import 'bar.dart';
import 'package:angular2/src/core/metadata.dart';
var _visited = false;
void initReflector(reflector) {
if (_visited) return;
_visited = true;
reflector
..registerType(
ToolTip,
new ReflectionInfo(const [
const Directive(
selector: '[tool-tip]', properties: const ['text: tool-tip'])
], const [], () => new ToolTip()))
..registerSetters({'text': (o, v) => o.text = v});
}

View File

@ -1,24 +0,0 @@
library dinner.soup.ng_deps.dart;
import 'package:angular2/src/core/metadata.dart';
import 'soup.dart';
var _visited = false;
void initReflector(reflector) {
if (_visited) return;
_visited = true;
reflector
..registerType(
SoupComponent,
new ReflectionInfo(const [
const Component(
componentServices: const [SaladComponent],
properties: const ['menu'])
], const [], () => new SoupComponent()))
..registerType(
SaladComponent,
new ReflectionInfo(const [
const Component(properties: const ['menu'])
], const [], () => new SaladComponent()))
..registerSetters({'menu': (o, v) => o.menu = v});
}

View File

@ -1,23 +0,0 @@
library dinner.soup.ng_deps.dart;
import 'package:angular2/src/core/metadata.dart';
import 'soup.dart';
var _visited = false;
void initReflector(reflector) {
if (_visited) return;
_visited = true;
reflector
..registerType(
SoupComponent,
new ReflectionInfo(const [
const Component(
componentServices: const [SaladComponent],
properties: const ['menu'])
], const [], () => new SoupComponent()))
..registerType(
SaladComponent,
new ReflectionInfo(const [
const Component(properties: const ['menu'])
], const [], () => new SaladComponent()));
}

View File

@ -1,18 +0,0 @@
library bar.ng_deps.dart;
import 'bar.dart';
import 'package:angular2/src/core/metadata.dart';
var _visited = false;
void initReflector(reflector) {
if (_visited) return;
_visited = true;
reflector
..registerType(
ToolTip,
new ReflectionInfo(const [
const Directive(
selector: '[tool-tip]',
events: const ['onOpen', 'close: onClose'])
], const [], () => new ToolTip()));
}

View File

@ -1,19 +0,0 @@
library bar.ng_deps.dart;
import 'bar.dart';
import 'package:angular2/src/core/metadata.dart';
var _visited = false;
void initReflector(reflector) {
if (_visited) return;
_visited = true;
reflector
..registerType(
ToolTip,
new ReflectionInfo(const [
const Directive(
selector: '[tool-tip]',
events: const ['onOpen', 'close: onClose'])
], const [], () => new ToolTip()))
..registerGetters({'onOpen': (o) => o.onOpen, 'close': (o) => o.close});
}

View File

@ -1,104 +0,0 @@
library angular2.test.transform.common.annotation_matcher_test;
import 'dart:async';
import 'package:analyzer/analyzer.dart';
import 'package:angular2/src/transform/common/annotation_matcher.dart';
import 'package:barback/barback.dart' show AssetId;
import 'package:guinness/guinness.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() {
it('should be able to match basic annotations.', () {
var matcher = new AnnotationMatcher()
..add(const AnnotationDescriptor('Test', 'package:test/test.dart', null));
var visitor = new MatchRecordingVisitor(matcher);
simpleAst.accept(visitor);
expect(visitor.matches.length).toBe(1);
});
it('should be able to match namespaced annotations.', () {
var matcher = new AnnotationMatcher()
..add(const AnnotationDescriptor('Test', 'package:test/test.dart', null));
var visitor = new MatchRecordingVisitor(matcher);
namespacedAst.accept(visitor);
expect(visitor.matches.length).toBe(1);
});
it('should be able to match relative imports.', () {
var matcher = new AnnotationMatcher()
..add(const AnnotationDescriptor('Test', 'package:test/test.dart', null));
var visitor =
new MatchRecordingVisitor(matcher, new AssetId('test', 'lib/foo.dart'));
relativePathAst.accept(visitor);
expect(visitor.matches.length).toBe(1);
});
it('should be able to match relative imports with a namespace.', () {
var matcher = new AnnotationMatcher()
..add(const AnnotationDescriptor('Test', 'package:test/test.dart', null));
var visitor =
new MatchRecordingVisitor(matcher, new AssetId('test', 'lib/foo.dart'));
namespacedRelativePathAst.accept(visitor);
expect(visitor.matches.length).toBe(1);
});
it('should not match annotations if the import is missing.', () {
var matcher = new AnnotationMatcher()
..add(const AnnotationDescriptor('Test', 'package:test/foo.dart', null));
var visitor = new MatchRecordingVisitor(matcher);
simpleAst.accept(visitor);
expect(visitor.matches.isEmpty).toBeTrue();
});
it('should not match annotations if the name is different.', () {
var matcher = new AnnotationMatcher()
..add(const AnnotationDescriptor('Foo', 'package:test/test.dart', null));
var visitor = new MatchRecordingVisitor(matcher);
simpleAst.accept(visitor);
expect(visitor.matches.isEmpty).toBeTrue();
});
}
class MatchRecordingVisitor extends RecursiveAstVisitor {
final AssetId assetId;
final AnnotationMatcher matcher;
final List<Annotation> matches = [];
MatchRecordingVisitor(this.matcher, [this.assetId]) : super();
@override
void visitAnnotation(Annotation annotation) {
if (matcher.hasMatch(annotation, assetId)) matches.add(annotation);
}
}

View File

@ -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;
}

View File

@ -1,107 +0,0 @@
library angular2.test.transform.common.async_string_writer;
import 'dart:async';
import 'package:angular2/src/transform/common/async_string_writer.dart';
import 'package:guinness/guinness.dart';
void allTests() {
it('should function as a basic Writer without async calls.', () {
var writer = new AsyncStringWriter();
writer.print('hello');
expect('$writer').toEqual('hello');
writer.println(', world');
expect('$writer').toEqual('hello, world\n');
});
it('should concatenate futures added with `asyncPrint`.', () async {
var writer = new AsyncStringWriter();
writer.print('hello');
expect('$writer').toEqual('hello');
writer.asyncPrint(new Future.value(', world.'));
writer.print(' It is a beautiful day.');
expect(await writer.asyncToString())
.toEqual('hello, world. It is a beautiful day.');
});
it('should concatenate multiple futures regardless of order.', () async {
var completer1 = new Completer<String>();
var completer2 = new Completer<String>();
var writer = new AsyncStringWriter();
writer.print('hello');
expect('$writer').toEqual('hello');
writer.asyncPrint(completer1.future);
writer.asyncPrint(completer2.future);
completer2.complete(' It is a beautiful day.');
completer1.complete(', world.');
expect(await writer.asyncToString())
.toEqual('hello, world. It is a beautiful day.');
});
it('should allow multiple "rounds" of `asyncPrint`.', () async {
var writer = new AsyncStringWriter();
writer.print('hello');
expect('$writer').toEqual('hello');
writer.asyncPrint(new Future.value(', world.'));
expect(await writer.asyncToString()).toEqual('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())
.toEqual('hello, world. It is a beautiful day.');
});
it('should handle calls to async methods while waiting.', () {
var completer1 = new Completer<String>();
var completer2 = new Completer<String>();
var writer = new AsyncStringWriter();
writer.print('hello');
expect('$writer').toEqual('hello');
writer.asyncPrint(completer1.future);
var f1 = writer.asyncToString().then((result) {
expect(result).toEqual('hello, world.');
});
writer.asyncPrint(completer2.future);
var f2 = writer.asyncToString().then((result) {
expect(result).toEqual('hello, world. It is a beautiful day.');
});
completer1.complete(', world.');
completer2.complete(' It is a beautiful day.');
return Future.wait([f1, f2]);
});
it(
'should handle calls to async methods that complete in reverse '
'order while waiting.', () {
var completer1 = new Completer<String>();
var completer2 = new Completer<String>();
var writer = new AsyncStringWriter();
writer.print('hello');
expect('$writer').toEqual('hello');
writer.asyncPrint(completer1.future);
var f1 = writer.asyncToString().then((result) {
expect(result).toEqual('hello, world.');
});
writer.asyncPrint(completer2.future);
var f2 = writer.asyncToString().then((result) {
expect(result).toEqual('hello, world. It is a beautiful day.');
});
completer2.complete(' It is a beautiful day.');
completer1.complete(', world.');
return Future.wait([f1, f2]);
});
}

View File

@ -1,101 +0,0 @@
library angular2.test.transform.common.annotation_matcher_test;
import 'package:angular2/src/render/api.dart';
import 'package:angular2/src/transform/common/ng_meta.dart';
import 'package:guinness/guinness.dart';
main() => allTests();
void allTests() {
var mockData = [
new RenderDirectiveMetadata(id: 'm1'),
new RenderDirectiveMetadata(id: 'm2'),
new RenderDirectiveMetadata(id: 'm3'),
new RenderDirectiveMetadata(id: 'm4')
];
it('should allow empty data.', () {
var ngMeta = new NgMeta.empty();
expect(ngMeta.isEmpty).toBeTrue();
});
describe('serialization', () {
it('should parse empty data correctly.', () {
var ngMeta = new NgMeta.fromJson({});
expect(ngMeta.isEmpty).toBeTrue();
});
it('should be lossless', () {
var a = new NgMeta.empty();
a.types['T0'] = mockData[0];
a.types['T1'] = mockData[1];
a.types['T2'] = mockData[2];
a.types['T3'] = mockData[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()));
});
});
describe('flatten', () {
it('should include recursive aliases.', () {
var a = new NgMeta.empty();
a.types['T0'] = mockData[0];
a.types['T1'] = mockData[1];
a.types['T2'] = mockData[2];
a.types['T3'] = mockData[3];
a.aliases['a1'] = ['T1'];
a.aliases['a2'] = ['a1'];
a.aliases['a3'] = ['T3', 'a2'];
a.aliases['a4'] = ['a3', 'T0'];
expect(a.flatten('a4')).toEqual([mockData[3], mockData[1], mockData[0]]);
});
it('should detect cycles.', () {
var a = new NgMeta.empty();
a.types['T0'] = mockData[0];
a.aliases['a1'] = ['T0', 'a1'];
a.aliases['a2'] = ['a1'];
expect(a.flatten('a1')).toEqual([mockData[0]]);
});
});
describe('merge', () {
it('should merge all types on addAll', () {
var a = new NgMeta.empty();
var b = new NgMeta.empty();
a.types['T0'] = mockData[0];
b.types['T1'] = mockData[1];
a.addAll(b);
expect(a.types).toContain('T1');
expect(a.types['T1']).toEqual(mockData[1]);
});
it('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).toContain('b');
expect(a.aliases['b']).toEqual(['y']);
});
});
}
_checkSimilar(NgMeta a, NgMeta b) {
expect(a.types.length).toEqual(b.types.length);
expect(a.aliases.length).toEqual(b.aliases.length);
for (var k in a.types.keys) {
expect(b.types).toContain(k);
var at = a.types[k];
var bt = b.types[k];
expect(at.id).toEqual(bt.id);
}
for (var k in a.aliases.keys) {
expect(b.aliases).toContain(k);
expect(b.aliases[k]).toEqual(a.aliases[k]);
}
}

View File

@ -1,47 +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<AssetId, String> _overrideAssets = <AssetId, String>{};
Future<String> readAsString(AssetId id, {Encoding encoding}) {
if (_overrideAssets.containsKey(id)) {
return new Future.value(_overrideAssets[id]);
} else {
return new Future.value(readFile(id.path));
}
}
Future<bool> 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 addAsset(AssetId id, String contents) {
_overrideAssets[id] = contents;
}
}

View File

@ -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/reflection/reflection_capabilities.dart. Importing the actual file in
/// tests causes issues with resolution due to transitive dependencies.
class ReflectionCapabilities {}

View File

@ -1,58 +0,0 @@
library angular2.test.transform.deferred_rewriter.all_tests;
import 'package:barback/barback.dart';
import 'package:angular2/src/transform/deferred_rewriter/transformer.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/logging.dart' as log;
import 'package:code_transformers/messages/build_logger.dart';
import 'package:dart_style/dart_style.dart';
import 'package:guinness/guinness.dart';
import 'package:path/path.dart' as path;
import '../common/read_file.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) {
it(name, () 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 output = await rewriteDeferredLibraries(reader, inputId);
var input = await reader.readAsString(expectedId);
if (input == null) {
// Null input signals no output. Ensure that is true.
expect(output).toBeNull();
} else {
expect(formatter.format(output)).toEqual(formatter.format(input));
}
});
}
AssetId _assetIdForPath(String path) =>
new AssetId('angular2', 'test/transform/deferred_rewriter/$path');

View File

@ -1,17 +0,0 @@
library web_foo;
import 'package:angular2/src/core/application.dart';
import 'package:angular2/src/reflection/reflection.dart';
import 'package:angular2/src/reflection/reflection_capabilities.dart';
import 'hello.ng_deps.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();
}

View File

@ -1,8 +0,0 @@
library examples.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 {}

View File

@ -1,22 +0,0 @@
library examples.src.hello_world.absolute_url_expression_files.ng_deps.dart;
import 'hello.dart';
export 'hello.dart';
import 'package:angular2/src/reflection/reflection.dart' as _ngRef;
import 'package:angular2/angular2.dart'
show bootstrap, Component, Directive, View, NgElement;
var _visited = false;
void initReflector() {
if (_visited) return;
_visited = true;
_ngRef.reflector
..registerType(
HelloCmp,
new _ngRef.ReflectionInfo(const [
const Component(selector: 'hello-app'),
const View(
template: r'''{{greeting}}''',
templateUrl: r'package:other_package/template.html')
], const [], () => new HelloCmp()));
}

View File

@ -1,15 +0,0 @@
library web_foo;
import 'package:angular2/src/core/application.dart';
import 'package:angular2/src/reflection/reflection.dart';
import 'package:angular2/src/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();
}

View File

@ -1,8 +0,0 @@
library examples.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 {}

View File

@ -1,13 +0,0 @@
library web_foo;
import 'package:angular2/src/core/application.dart';
import 'package:angular2/src/reflection/reflection.dart';
import 'package:angular2/src/reflection/reflection_capabilities.dart';
import 'hello.dart' deferred as a;
void main() {
reflector.reflectionCapabilities = new ReflectionCapabilities();
a.loadLibrary().then((_) {
bootstrap(a.HelloCmp);
});
}

View File

@ -1,10 +0,0 @@
library web_foo;
import 'package:angular2/src/core/application.dart';
import 'package:angular2/src/reflection/reflection.dart';
import 'package:angular2/src/reflection/reflection_capabilities.dart';
void main() {
reflector.reflectionCapabilities = new ReflectionCapabilities();
bootstrap(MyComponent);
}

View File

@ -1,11 +0,0 @@
library web_foo;
import 'package:angular2/src/core/application.dart';
import 'package:angular2/src/reflection/reflection.dart';
import 'package:angular2/src/reflection/reflection_capabilities.dart';
import 'a.dart' deferred as a;
void main() {
reflector.reflectionCapabilities = new ReflectionCapabilities();
bootstrap(MyComponent);
}

View File

@ -1,15 +0,0 @@
library web_foo;
import 'package:angular2/src/core/application.dart';
import 'package:angular2/src/reflection/reflection.dart';
import 'package:angular2/src/reflection/reflection_capabilities.dart';
import 'hello.ng_deps.dart' deferred as a;
void main() {
reflector.reflectionCapabilities = new ReflectionCapabilities();
a.loadLibrary().then((_) {
a.initReflector();
}).then((_) {
bootstrap(a.HelloCmp);
});
}

View File

@ -1,8 +0,0 @@
library examples.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 {}

View File

@ -1,22 +0,0 @@
library examples.src.hello_world.absolute_url_expression_files.ng_deps.dart;
import 'hello.dart';
export 'hello.dart';
import 'package:angular2/src/reflection/reflection.dart' as _ngRef;
import 'package:angular2/angular2.dart'
show bootstrap, Component, Directive, View, NgElement;
var _visited = false;
void initReflector() {
if (_visited) return;
_visited = true;
_ngRef.reflector
..registerType(
HelloCmp,
new _ngRef.RegistrationInfo(const [
const Component(selector: 'hello-app'),
const View(
template: r'''{{greeting}}''',
templateUrl: r'package:other_package/template.html')
], const [], () => new HelloCmp()));
}

View File

@ -1,13 +0,0 @@
library web_foo;
import 'package:angular2/src/core/application.dart';
import 'package:angular2/src/reflection/reflection.dart';
import 'package:angular2/src/reflection/reflection_capabilities.dart';
import 'hello.dart' deferred as a;
void main() {
reflector.reflectionCapabilities = new ReflectionCapabilities();
a.loadLibrary().then((_) {
bootstrap(a.HelloCmp);
});
}

View File

@ -1,47 +0,0 @@
library angular2.test.transform.directive_linker.all_tests;
import 'package:barback/barback.dart';
import 'package:angular2/src/transform/directive_linker/linker.dart';
import 'package:dart_style/dart_style.dart';
import 'package:guinness/guinness.dart';
import '../common/read_file.dart';
var formatter = new DartFormatter();
main() => allTests();
void allTests() {
var reader = new TestAssetReader();
it('should ensure that dependencies are property chained.', () async {
for (var inputPath in [
'bar.ng_deps.dart',
'foo.ng_deps.dart',
'index.ng_deps.dart'
]) {
var expected =
readFile('directive_linker/simple_files/expected/$inputPath');
inputPath = 'directive_linker/simple_files/$inputPath';
var actual = formatter
.format(await linkNgDeps(reader, new AssetId('a', inputPath)));
expect(actual).toEqual(formatter.format(expected));
}
});
it('should ensure that exported dependencies are property chained.',
() async {
for (var inputPath in [
'bar.ng_deps.dart',
'foo.ng_deps.dart',
'index.ng_deps.dart'
]) {
var expected =
readFile('directive_linker/simple_export_files/expected/$inputPath');
inputPath = 'directive_linker/simple_export_files/$inputPath';
var actual = formatter
.format(await linkNgDeps(reader, new AssetId('a', inputPath)));
expect(actual).toEqual(formatter.format(expected));
}
});
}

View File

@ -1,18 +0,0 @@
library bar.ng_deps.dart;
import 'bar.dart';
export 'bar.dart';
import 'package:angular2/src/reflection/reflection.dart' as _ngRef;
import 'package:angular2/src/core/metadata.dart';
export 'foo.dart';
var _visited = false;
void initReflector() {
if (_visited) return;
_visited = true;
_ngRef.reflector
..registerType(
MyComponent,
new _ngRef.ReflectionInfo(const [const Component(selector: '[soup]')],
const [], () => new MyComponent()));
}

View File

@ -1,20 +0,0 @@
library bar.ng_deps.dart;
import 'bar.dart';
export 'bar.dart';
import 'package:angular2/src/reflection/reflection.dart' as _ngRef;
import 'package:angular2/src/core/metadata.dart';
export 'foo.dart';
import 'foo.ng_deps.dart' as i0;
var _visited = false;
void initReflector() {
if (_visited) return;
_visited = true;
_ngRef.reflector
..registerType(
MyComponent,
new _ngRef.ReflectionInfo(const [const Component(selector: '[soup]')],
const [], () => new MyComponent()));
i0.initReflector();
}

View File

@ -1,17 +0,0 @@
library foo.ng_deps.dart;
import 'foo.dart';
export 'foo.dart';
import 'package:angular2/src/reflection/reflection.dart' as _ngRef;
import 'package:angular2/src/core/metadata.dart';
var _visited = false;
void initReflector() {
if (_visited) return;
_visited = true;
_ngRef.reflector
..registerType(
DependencyComponent,
new _ngRef.ReflectionInfo(const [const Component(selector: '[salad]')],
const [], () => new DependencyComponent()));
}

View File

@ -1,14 +0,0 @@
library web_foo.ng_deps.dart;
import 'package:angular2/src/reflection/reflection.dart' as _ngRef;
import 'package:angular2/bootstrap_static.dart';
import 'package:angular2/src/reflection/reflection_capabilities.dart';
import 'bar.dart';
import 'bar.ng_deps.dart' as i0;
var _visited = false;
void initReflector() {
if (_visited) return;
_visited = true;
i0.initReflector();
}

View File

@ -1,17 +0,0 @@
library foo.ng_deps.dart;
import 'foo.dart';
export 'foo.dart';
import 'package:angular2/src/reflection/reflection.dart' as _ngRef;
import 'package:angular2/src/core/metadata.dart';
var _visited = false;
void initReflector() {
if (_visited) return;
_visited = true;
_ngRef.reflector
..registerType(
DependencyComponent,
new _ngRef.ReflectionInfo(const [const Component(selector: '[salad]')],
const [], () => new DependencyComponent()));
}

View File

@ -1,12 +0,0 @@
library web_foo.ng_deps.dart;
import 'package:angular2/src/reflection/reflection.dart' as _ngRef;
import 'package:angular2/bootstrap_static.dart';
import 'package:angular2/src/reflection/reflection_capabilities.dart';
import 'bar.dart';
var _visited = false;
void initReflector() {
if (_visited) return;
_visited = true;
}

View File

@ -1,20 +0,0 @@
library bar.ng_deps.dart;
import 'bar.dart';
export 'bar.dart';
import 'package:angular2/src/reflection/reflection.dart' as _ngRef;
import 'package:angular2/src/core/metadata.dart';
import 'foo.dart' as dep;
var _visited = false;
void initReflector() {
if (_visited) return;
_visited = true;
_ngRef.reflector
..registerType(
MyComponent,
new ReflectionInfo(const [
const Component(
selector: '[soup]', viewBindings: const [dep.DependencyComponent])
], const [], () => new MyComponent()));
}

View File

@ -1,22 +0,0 @@
library bar.ng_deps.dart;
import 'bar.dart';
export 'bar.dart';
import 'package:angular2/src/reflection/reflection.dart' as _ngRef;
import 'package:angular2/src/core/metadata.dart';
import 'foo.dart' as dep;
import 'foo.ng_deps.dart' as i0;
var _visited = false;
void initReflector() {
if (_visited) return;
_visited = true;
_ngRef.reflector
..registerType(
MyComponent,
new ReflectionInfo(const [
const Component(
selector: '[soup]', viewBindings: const [dep.DependencyComponent])
], const [], () => new MyComponent()));
i0.initReflector();
}

View File

@ -1,17 +0,0 @@
library foo.ng_deps.dart;
import 'foo.dart';
export 'foo.dart';
import 'package:angular2/src/reflection/reflection.dart' as _ngRef;
import 'package:angular2/src/core/metadata.dart';
var _visited = false;
void initReflector() {
if (_visited) return;
_visited = true;
_ngRef.reflector
..registerType(
DependencyComponent,
new _ngRef.ReflectionInfo(const [const Component(selector: '[salad]')],
const [], () => new DependencyComponent()));
}

View File

@ -1,14 +0,0 @@
library web_foo.ng_deps.dart;
import 'package:angular2/src/reflection/reflection.dart' as _ngRef;
import 'package:angular2/bootstrap_static.dart';
import 'package:angular2/src/reflection/reflection_capabilities.dart';
import 'bar.dart';
import 'bar.ng_deps.dart' as i0;
var _visited = false;
void initReflector() {
if (_visited) return;
_visited = true;
i0.initReflector();
}

View File

@ -1,17 +0,0 @@
library foo.ng_deps.dart;
import 'foo.dart';
export 'foo.dart';
import 'package:angular2/src/reflection/reflection.dart' as _ngRef;
import 'package:angular2/src/core/metadata.dart';
var _visited = false;
void initReflector() {
if (_visited) return;
_visited = true;
_ngRef.reflector
..registerType(
DependencyComponent,
new _ngRef.ReflectionInfo(const [const Component(selector: '[salad]')],
const [], () => new DependencyComponent()));
}

View File

@ -1,12 +0,0 @@
library web_foo.ng_deps.dart;
import 'package:angular2/src/reflection/reflection.dart' as _ngRef;
import 'package:angular2/bootstrap_static.dart';
import 'package:angular2/src/reflection/reflection_capabilities.dart';
import 'bar.dart';
var _visited = false;
void initReflector() {
if (_visited) return;
_visited = true;
}

View File

@ -1,15 +0,0 @@
library foo.ng_deps.dart;
import 'bar.dart';
import 'package:angular2/src/core/metadata.dart';
var _visited = false;
void initReflector(reflector) {
if (_visited) return;
_visited = true;
reflector
..registerType(
BarComponent,
new ReflectionInfo(const [const Component(selector: '[bar]')], const [],
() => new BarComponent()));
}

View File

@ -1,19 +0,0 @@
library foo.ng_deps.dart;
import 'foo.dart';
import 'package:angular2/src/core/metadata.dart';
export 'package:bar/bar.dart';
import 'package:bar/bar.ng_deps.dart' as i0;
var _visited = false;
void initReflector(reflector) {
if (_visited) return;
_visited = true;
reflector
..registerType(
FooComponent,
new ReflectionInfo(const [const Component(selector: '[foo]')], const [],
() => new FooComponent()));
i0.initReflector(reflector);
}

View File

@ -1,15 +0,0 @@
library bar.ng_deps.dart;
import 'foo.dart';
import 'package:angular2/src/core/metadata.dart';
var _visited = false;
void initReflector(reflector) {
if (_visited) return;
_visited = true;
reflector
..registerType(
FooComponent,
new ReflectionInfo(const [const Component(selector: '[fo' 'o]')],
const [], () => new FooComponent()));
}

View File

@ -1,232 +0,0 @@
library angular2.test.transform.directive_metadata_extractor.all_tests;
import 'dart:async';
import 'package:angular2/src/render/api.dart';
import 'package:angular2/src/render/dom/convert.dart';
import 'package:angular2/src/transform/common/directive_metadata_reader.dart';
import 'package:angular2/src/transform/common/logging.dart';
import 'package:angular2/src/transform/common/ng_deps.dart';
import 'package:angular2/src/transform/directive_metadata_extractor/'
'extractor.dart';
import 'package:barback/barback.dart';
import 'package:dart_style/dart_style.dart';
import 'package:guinness/guinness.dart';
import '../common/read_file.dart';
var formatter = new DartFormatter();
main() => allTests();
void allTests() {
TestAssetReader reader = null;
beforeEach(() {
reader = new TestAssetReader();
});
Future<DirectiveMetadata> readMetadata(inputPath) async {
var ngDeps = await NgDeps.parse(reader, new AssetId('a', inputPath));
return ngDeps.registeredTypes.first.directiveMetadata;
}
describe('readMetadata', () {
it('should parse selectors', () async {
var metadata = await readMetadata(
'directive_metadata_extractor/directive_metadata_files/'
'selector.ng_deps.dart');
expect(metadata.selector).toEqual('hello-app');
});
it('should parse compile children values', () async {
var ngDeps = await NgDeps.parse(
reader,
new AssetId(
'a',
'directive_metadata_extractor/'
'directive_metadata_files/compile_children.ng_deps.dart'));
var it = ngDeps.registeredTypes.iterator;
// Unset value defaults to `true`.
it.moveNext();
expect('${it.current.typeName}').toEqual('UnsetComp');
var unsetComp = it.current.directiveMetadata;
expect(unsetComp.compileChildren).toBeTrue();
it.moveNext();
expect('${it.current.typeName}').toEqual('FalseComp');
var falseComp = it.current.directiveMetadata;
expect(falseComp.compileChildren).toBeFalse();
it.moveNext();
expect('${it.current.typeName}').toEqual('TrueComp');
var trueComp = it.current.directiveMetadata;
expect(trueComp.compileChildren).toBeTrue();
});
it('should parse properties.', () async {
var metadata = await readMetadata('directive_metadata_extractor/'
'directive_metadata_files/properties.ng_deps.dart');
expect(metadata.properties).toBeNotNull();
expect(metadata.properties.length).toBe(2);
expect(metadata.properties).toContain('key1: val1');
expect(metadata.properties).toContain('key2: val2');
});
it('should parse exportAs.', () async {
var metadata = await readMetadata('directive_metadata_extractor/'
'directive_metadata_files/directive_export_as.ng_deps.dart');
expect(metadata.exportAs).toEqual('exportAsName');
});
it('should parse host.', () async {
var metadata = await readMetadata('directive_metadata_extractor/'
'directive_metadata_files/host_listeners.ng_deps.dart');
expect(metadata.hostListeners).toBeNotNull();
expect(metadata.hostListeners.length).toBe(1);
expect(metadata.hostListeners).toContain('change');
expect(metadata.hostListeners['change']).toEqual('onChange(\$event)');
expect(metadata.hostProperties).toBeNotNull();
expect(metadata.hostProperties.length).toBe(1);
expect(metadata.hostProperties).toContain('value');
expect(metadata.hostProperties['value']).toEqual('value');
expect(metadata.hostAttributes).toBeNotNull();
expect(metadata.hostAttributes.length).toBe(1);
expect(metadata.hostAttributes).toContain('attName');
expect(metadata.hostAttributes['attName']).toEqual('attValue');
expect(metadata.hostActions).toBeNotNull();
expect(metadata.hostActions.length).toBe(1);
expect(metadata.hostActions).toContain('actionName');
expect(metadata.hostActions['actionName']).toEqual('actionValue');
});
it('should parse lifecycle events.', () async {
var metadata = await readMetadata('directive_metadata_extractor/'
'directive_metadata_files/lifecycle.ng_deps.dart');
expect(metadata.callOnDestroy).toBe(true);
expect(metadata.callOnChange).toBe(true);
expect(metadata.callOnCheck).toBe(true);
expect(metadata.callOnInit).toBe(true);
expect(metadata.callOnAllChangesDone).toBe(true);
});
it('should parse events.', () async {
var metadata = await readMetadata('directive_metadata_extractor/'
'directive_metadata_files/events.ng_deps.dart');
expect(metadata.events).toEqual(['onFoo', 'onBar']);
});
it('should parse changeDetection.', () async {
var metadata = await readMetadata('directive_metadata_extractor/'
'directive_metadata_files/changeDetection.ng_deps.dart');
expect(metadata.changeDetection).toEqual('CHECK_ONCE');
});
it('should fail when a class is annotated with multiple Directives.',
() async {
var ngDeps = await NgDeps.parse(
reader,
new AssetId(
'a',
'directive_metadata_extractor/'
'directive_metadata_files/too_many_directives.ng_deps.dart'));
expect(() => ngDeps.registeredTypes.first.directiveMetadata)
.toThrowWith(anInstanceOf: PrintLoggerError);
});
});
describe('extractMetadata', () {
it('should generate `DirectiveMetadata` from .ng_deps.dart files.',
() async {
var extracted = await extractDirectiveMetadata(
reader,
new AssetId('a',
'directive_metadata_extractor/simple_files/foo.ng_deps.dart'));
expect(extracted.types).toContain('FooComponent');
var extractedMeta = extracted.types['FooComponent'];
expect(extractedMeta.selector).toEqual('[foo]');
});
it(
'should generate `DirectiveMetadata` from .ng_deps.dart files that use '
'automatic adjacent string concatenation.', () async {
var extracted = await extractDirectiveMetadata(
reader,
new AssetId(
'a',
'directive_metadata_extractor/adjacent_strings_files/'
'foo.ng_deps.dart'));
expect(extracted.types).toContain('FooComponent');
var extractedMeta = extracted.types['FooComponent'];
expect(extractedMeta.selector).toEqual('[foo]');
});
it('should include `DirectiveMetadata` from exported files.', () async {
var extracted = await extractDirectiveMetadata(
reader,
new AssetId('a',
'directive_metadata_extractor/export_files/foo.ng_deps.dart'));
expect(extracted.types).toContain('FooComponent');
expect(extracted.types).toContain('BarComponent');
expect(extracted.types['FooComponent'].selector).toEqual('[foo]');
expect(extracted.types['BarComponent'].selector).toEqual('[bar]');
});
it('should include `DirectiveMetadata` recursively from exported files.',
() async {
var extracted = await extractDirectiveMetadata(
reader,
new AssetId('a',
'directive_metadata_extractor/recursive_export_files/foo.ng_deps.dart'));
expect(extracted.types).toContain('FooComponent');
expect(extracted.types).toContain('BarComponent');
expect(extracted.types).toContain('BazComponent');
expect(extracted.types['FooComponent'].selector).toEqual('[foo]');
expect(extracted.types['BarComponent'].selector).toEqual('[bar]');
expect(extracted.types['BazComponent'].selector).toEqual('[baz]');
});
it(
'should include `DirectiveMetadata` from exported files '
'expressed as absolute uris', () async {
reader.addAsset(
new AssetId('bar', 'lib/bar.ng_deps.dart'),
readFile(
'directive_metadata_extractor/absolute_export_files/bar.ng_deps.dart'));
var extracted = await extractDirectiveMetadata(
reader,
new AssetId('a',
'directive_metadata_extractor/absolute_export_files/foo.ng_deps.dart'));
expect(extracted.types).toContain('FooComponent');
expect(extracted.types).toContain('BarComponent');
expect(extracted.types['FooComponent'].selector).toEqual('[foo]');
expect(extracted.types['BarComponent'].selector).toEqual('[bar]');
});
it('should include directive aliases', () async {
reader.addAsset(
new AssetId('bar', 'lib/bar.ng_deps.dart'),
readFile(
'directive_metadata_extractor/directive_aliases_files/bar.ng_deps.dart'));
var extracted = await extractDirectiveMetadata(
reader,
new AssetId('a',
'directive_metadata_extractor/directive_aliases_files/foo.ng_deps.dart'));
expect(extracted.aliases).toContain('alias1');
expect(extracted.aliases).toContain('alias2');
expect(extracted.aliases['alias1']).toContain('BarComponent');
expect(extracted.aliases['alias2']).toContain('FooComponent');
expect(extracted.aliases['alias2']).toContain('alias1');
});
});
}

View File

@ -1,8 +0,0 @@
{
"alias1": {
"kind": "alias",
"value": [
"BarComponent"
]
}
}

View File

@ -1,15 +0,0 @@
library foo.ng_deps.dart;
import 'bar.dart';
import 'package:angular2/src/core/metadata.dart';
var _visited = false;
void initReflector(reflector) {
if (_visited) return;
_visited = true;
reflector
..registerType(
BarComponent,
new ReflectionInfo(const [const Component(selector: '[bar]')], const [],
() => new BarComponent()));
}

View File

@ -1,9 +0,0 @@
{
"alias2": {
"kind": "alias",
"value": [
"FooComponent",
"alias1"
]
}
}

View File

@ -1,19 +0,0 @@
library foo.ng_deps.dart;
import 'foo.dart';
import 'package:angular2/src/core/metadata.dart';
export 'bar.dart';
import 'bar.ng_deps.dart' as i0;
var _visited = false;
void initReflector(reflector) {
if (_visited) return;
_visited = true;
reflector
..registerType(
FooComponent,
new ReflectionInfo(const [const Component(selector: '[foo]')], const [],
() => new FooComponent()));
i0.initReflector(reflector);
}

View File

@ -1,18 +0,0 @@
library examples.hello_world.index_common_dart.ng_deps.dart;
import 'hello.dart';
import 'package:angular2/angular2.dart'
show Component, Directive, View, NgElement, LifecycleEvent;
var _visited = false;
void initReflector(reflector) {
if (_visited) return;
_visited = true;
reflector
..registerType(
HelloCmp,
new ReflectionInfo(
const [const Component(changeDetection: 'CHECK_ONCE')],
const [const []],
() => new HelloCmp()));
}

View File

@ -1,23 +0,0 @@
library examples.hello_world.index_common_dart.ng_deps.dart;
import 'hello.dart';
import 'package:angular2/angular2.dart';
var _visited = false;
void initReflector(reflector) {
if (_visited) return;
_visited = true;
reflector
..registerType(
UnsetComp,
new ReflectionInfo(
const [const Directive()], const [const []], () => new UnsetComp()))
..registerType(
FalseComp,
new ReflectionInfo(const [const Directive(compileChildren: false)],
const [const []], () => new FalseComp()))
..registerType(
TrueComp,
new ReflectionInfo(const [const Directive(compileChildren: true)],
const [const []], () => new TrueComp()));
}

View File

@ -1,16 +0,0 @@
library examples.hello_world.index_common_dart.ng_deps.dart;
import 'hello.dart';
import 'package:angular2/angular2.dart'
show Component, Directive, View, NgElement, LifecycleEvent;
var _visited = false;
void initReflector(reflector) {
if (_visited) return;
_visited = true;
reflector
..registerType(
HelloCmp,
new ReflectionInfo(const [const Directive(exportAs: 'exportAsName')],
const [const []], () => new HelloCmp()));
}

View File

@ -1,19 +0,0 @@
library examples.hello_world.index_common_dart.ng_deps.dart;
import 'hello.dart';
import 'package:angular2/angular2.dart'
show Component, Directive, View, NgElement, LifecycleEvent;
var _visited = false;
void initReflector(reflector) {
if (_visited) return;
_visited = true;
reflector
..registerType(
HelloCmp,
new ReflectionInfo(const [
const Component(events: ['onFoo', 'onBar'])
], const [
const []
], () => new HelloCmp()));
}

View File

@ -1,24 +0,0 @@
library examples.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(host: const {
'(change)': 'onChange(\$event)',
'[value]': 'value',
'@actionName': 'actionValue',
'attName': 'attValue'
})
], const [
const []
], () => new HelloCmp()));
}

View File

@ -1,25 +0,0 @@
library examples.hello_world.index_common_dart.ng_deps.dart;
import 'hello.dart';
import 'package:angular2/angular2.dart'
show Component, Directive, View, NgElement, LifecycleEvent;
var _visited = false;
void initReflector(reflector) {
if (_visited) return;
_visited = true;
reflector
..registerType(
HelloCmp,
new ReflectionInfo(const [
const Component(lifecycle: [
LifecycleEvent.onChange,
LifecycleEvent.onDestroy,
LifecycleEvent.onInit,
LifecycleEvent.onCheck,
LifecycleEvent.onAllChangesDone
])
], const [
const []
], () => new HelloCmp()));
}

View File

@ -1,19 +0,0 @@
library examples.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(properties: const ['key1: val1', 'key2: val2'])
], const [
const []
], () => new HelloCmp()));
}

View File

@ -1,16 +0,0 @@
library examples.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 [const []], () => new HelloCmp()));
}

View File

@ -1,20 +0,0 @@
library examples.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 Component(selector: 'goodbye-app')
], const [
const []
], () => new HelloCmp()));
}

View File

@ -1,15 +0,0 @@
library foo.ng_deps.dart;
import 'bar.dart';
import 'package:angular2/src/core/metadata.dart';
var _visited = false;
void initReflector(reflector) {
if (_visited) return;
_visited = true;
reflector
..registerType(
BarComponent,
new ReflectionInfo(const [const Component(selector: '[bar]')], const [],
() => new BarComponent()));
}

View File

@ -1,19 +0,0 @@
library foo.ng_deps.dart;
import 'foo.dart';
import 'package:angular2/src/core/metadata.dart';
export 'bar.dart';
import 'bar.ng_deps.dart' as i0;
var _visited = false;
void initReflector(reflector) {
if (_visited) return;
_visited = true;
reflector
..registerType(
FooComponent,
new ReflectionInfo(const [const Component(selector: '[foo]')], const [],
() => new FooComponent()));
i0.initReflector(reflector);
}

View File

@ -1,19 +0,0 @@
library foo.ng_deps.dart;
import 'bar.dart';
import 'package:angular2/src/core/metadata.dart';
export 'baz.dart';
import 'baz.ng_deps.dart' as i0;
var _visited = false;
void initReflector(reflector) {
if (_visited) return;
_visited = true;
reflector
..registerType(
BarComponent,
new ReflectionInfo(const [const Component(selector: '[bar]')], const [],
() => new BarComponent()));
i0.initReflector(reflector);
}

View File

@ -1,15 +0,0 @@
library foo.ng_deps.dart;
import 'baz.dart';
import 'package:angular2/src/core/metadata.dart';
var _visited = false;
void initReflector(reflector) {
if (_visited) return;
_visited = true;
reflector
..registerType(
BazComponent,
new ReflectionInfo(const [const Component(selector: '[baz]')], const [],
() => new BazComponent()));
}

View File

@ -1,19 +0,0 @@
library foo.ng_deps.dart;
import 'foo.dart';
import 'package:angular2/src/core/metadata.dart';
export 'bar.dart';
import 'bar.ng_deps.dart' as i0;
var _visited = false;
void initReflector(reflector) {
if (_visited) return;
_visited = true;
reflector
..registerType(
FooComponent,
new ReflectionInfo(const [const Component(selector: '[foo]')], const [],
() => new FooComponent()));
i0.initReflector(reflector);
}

View File

@ -1,15 +0,0 @@
library bar.ng_deps.dart;
import 'foo.dart';
import 'package:angular2/src/core/metadata.dart';
var _visited = false;
void initReflector(reflector) {
if (_visited) return;
_visited = true;
reflector
..registerType(
FooComponent,
new ReflectionInfo(const [const Component(selector: '[foo]')], const [],
() => new FooComponent()));
}

View File

@ -1,25 +0,0 @@
library examples.src.hello_world.absolute_url_expression_files.ng_deps.dart;
import 'hello.dart';
export 'hello.dart';
import 'package:angular2/src/reflection/reflection.dart' as _ngRef;
import 'package:angular2/angular2.dart'
show Component, Directive, View, NgElement;
var _visited = false;
void initReflector() {
if (_visited) return;
_visited = true;
_ngRef.reflector
..registerType(
HelloCmp,
new _ngRef.ReflectionInfo(const [
const Component(selector: 'hello-app'),
const View(
template: r'''{{greeting}}''',
templateUrl: r'package:other_package/template.html',
styles: const [r'''.greeting { .color: blue; }''',])
], const [], () => new HelloCmp()))
..registerFunction(
hello, new _ngRef.ReflectionInfo(const [const Injectable()], const []));
}

View File

@ -1,13 +0,0 @@
library examples.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() {}

View File

@ -1,228 +0,0 @@
library angular2.test.transform.directive_processor.all_tests;
import 'dart:convert';
import 'package:barback/barback.dart';
import 'package:angular2/src/transform/directive_processor/rewriter.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/logging.dart' as log;
import 'package:angular2/src/transform/common/ng_meta.dart';
import 'package:code_transformers/messages/build_logger.dart';
import 'package:dart_style/dart_style.dart';
import 'package:guinness/guinness.dart';
import 'package:path/path.dart' as path;
import 'package:source_span/source_span.dart';
import '../common/read_file.dart';
var formatter = new DartFormatter();
main() {
allTests();
}
void allTests() {
_testProcessor('should preserve parameter annotations as const instances.',
'parameter_metadata/soup.dart');
_testProcessor('should handle `part` directives.', 'part_files/main.dart');
_testProcessor('should handle multiple `part` directives.',
'multiple_part_files/main.dart');
_testProcessor('should not generate .ng_deps.dart for `part` files.',
'part_files/part.dart');
_testProcessor('should recognize custom annotations with package: imports',
'custom_metadata/package_soup.dart',
customDescriptors: [
const ClassDescriptor('Soup', 'package:soup/soup.dart',
superClass: 'Component'),
]);
_testProcessor('should recognize custom annotations with relative imports',
'custom_metadata/relative_soup.dart',
assetId: new AssetId('soup', 'lib/relative_soup.dart'),
customDescriptors: [
const ClassDescriptor('Soup', 'package:soup/annotations/soup.dart',
superClass: 'Component'),
]);
_testProcessor(
'Requires the specified import.', 'custom_metadata/bad_soup.dart',
customDescriptors: [
const ClassDescriptor('Soup', 'package:soup/soup.dart',
superClass: 'Component'),
]);
_testProcessor(
'should inline `templateUrl` values.', 'url_expression_files/hello.dart');
var absoluteReader = new TestAssetReader();
absoluteReader.addAsset(
new AssetId('other_package', 'lib/template.html'),
readFile(
'directive_processor/absolute_url_expression_files/template.html'));
absoluteReader.addAsset(
new AssetId('other_package', 'lib/template.css'),
readFile(
'directive_processor/absolute_url_expression_files/template.css'));
_testProcessor(
'should inline `templateUrl` and `styleUrls` values expressed'
' as absolute urls.',
'absolute_url_expression_files/hello.dart',
reader: absoluteReader);
_testProcessor(
'should inline multiple `styleUrls` values expressed as absolute urls.',
'multiple_style_urls_files/hello.dart');
absoluteReader.addAsset(new AssetId('a', 'lib/template.html'),
readFile('directive_processor/multiple_style_urls_files/template.html'));
absoluteReader.addAsset(new AssetId('a', 'lib/template.css'),
readFile('directive_processor/multiple_style_urls_files/template.css'));
absoluteReader.addAsset(
new AssetId('a', 'lib/template_other.css'),
readFile(
'directive_processor/multiple_style_urls_files/template_other.css'));
_testProcessor(
'shouldn\'t inline multiple `styleUrls` values expressed as absolute '
'urls.',
'multiple_style_urls_not_inlined_files/hello.dart',
inlineViews: false,
reader: absoluteReader);
_testProcessor('should inline `templateUrl`s expressed as adjacent strings.',
'split_url_expression_files/hello.dart');
_testProcessor('should report implemented types as `interfaces`.',
'interfaces_files/soup.dart');
_testProcessor('should not include transitively implemented types.',
'interface_chain_files/soup.dart');
_testProcessor('should not include superclasses in `interfaces`.',
'superclass_files/soup.dart');
_testProcessor(
'should populate `lifecycle` when lifecycle interfaces are present.',
'interface_lifecycle_files/soup.dart');
_testProcessor('should populate multiple `lifecycle` values when necessary.',
'multiple_interface_lifecycle_files/soup.dart');
_testProcessor(
'should populate `lifecycle` when lifecycle superclass is present.',
'superclass_lifecycle_files/soup.dart');
_testProcessor('should populate `lifecycle` with prefix when necessary.',
'prefixed_interface_lifecycle_files/soup.dart');
_testProcessor(
'should not throw/hang on invalid urls', 'invalid_url_files/hello.dart',
expectedLogs: [
'ERROR: Uri /bad/absolute/url.html not supported from angular2|test/'
'transform/directive_processor/invalid_url_files/hello.dart, could not '
'build AssetId',
'ERROR: Could not read asset at uri package:invalid/package.css from '
'angular2|test/transform/directive_processor/invalid_url_files/'
'hello.dart',
'ERROR: Could not read asset at uri bad_relative_url.css from angular2|'
'test/transform/directive_processor/invalid_url_files/hello.dart'
]);
_testProcessor('should find and register static functions.',
'static_function_files/hello.dart');
_testProcessor('should find direcive aliases patterns.',
'directive_aliases_files/hello.dart',
reader: absoluteReader);
}
void _testProcessor(String name, String inputPath,
{List<AnnotationDescriptor> customDescriptors: const [],
AssetId assetId,
AssetReader reader,
List<String> expectedLogs,
bool inlineViews: true,
bool isolate: false}) {
var testFn = isolate ? iit : it;
testFn(name, () async {
var logger = new RecordingLogger();
await log.setZoned(logger, () async {
var inputId = _assetIdForPath(inputPath);
if (reader == null) {
reader = new TestAssetReader();
}
if (assetId != null) {
reader.addAsset(assetId, await reader.readAsString(inputId));
inputId = assetId;
}
var expectedNgDepsPath = path.join(path.dirname(inputPath), 'expected',
path.basename(inputPath).replaceFirst('.dart', '.ng_deps.dart'));
var expectedNgDepsId = _assetIdForPath(expectedNgDepsPath);
var expectedAliasesPath = path.join(path.dirname(inputPath), 'expected',
path.basename(inputPath).replaceFirst('.dart', '.aliases.json'));
var expectedAliasesId = _assetIdForPath(expectedAliasesPath);
var annotationMatcher = new AnnotationMatcher()
..addAll(customDescriptors);
var ngMeta = new NgMeta.empty();
var output = await createNgDeps(
reader, inputId, annotationMatcher, ngMeta,
inlineViews: inlineViews);
if (output == null) {
expect(await reader.hasInput(expectedNgDepsId)).toBeFalse();
} else {
var expectedOutput = await reader.readAsString(expectedNgDepsId);
expect(formatter.format(output))
.toEqual(formatter.format(expectedOutput));
}
if (ngMeta.isEmpty) {
expect(await reader.hasInput(expectedAliasesId)).toBeFalse();
} else {
var expectedJson = await reader.readAsString(expectedAliasesId);
expect(new JsonEncoder.withIndent(' ').convert(ngMeta.toJson()))
.toEqual(expectedJson.trim());
}
});
if (expectedLogs == null) {
expect(logger.hasErrors).toBeFalse();
} else {
expect(logger.logs, expectedLogs);
}
});
}
AssetId _assetIdForPath(String path) =>
new AssetId('angular2', 'test/transform/directive_processor/$path');
class RecordingLogger implements BuildLogger {
@override
final String detailsUri = '';
@override
final bool convertErrorsToWarnings = false;
bool hasErrors = false;
List<String> logs = [];
void _record(prefix, msg) => logs.add('$prefix: $msg');
void info(msg, {AssetId asset, SourceSpan span}) => _record('INFO', msg);
void fine(msg, {AssetId asset, SourceSpan span}) => _record('FINE', msg);
void warning(msg, {AssetId asset, SourceSpan span}) => _record('WARN', msg);
void error(msg, {AssetId asset, SourceSpan span}) {
hasErrors = true;
_record('ERROR', msg);
}
Future writeOutput() => throw new UnimplementedError();
Future addLogFilesFromAsset(AssetId id, [int nextNumber = 1]) =>
throw new UnimplementedError();
}

View File

@ -1,8 +0,0 @@
library dinner.bad_soup;
// No recognized import for [Soup]
@Soup()
class BadSoup {
BadSoup();
}

View File

@ -1,17 +0,0 @@
library dinner.package_soup.ng_deps.dart;
import 'package_soup.dart';
export 'package_soup.dart';
import 'package:angular2/src/reflection/reflection.dart' as _ngRef;
import 'package:soup/soup.dart';
var _visited = false;
void initReflector() {
if (_visited) return;
_visited = true;
_ngRef.reflector
..registerType(
PackageSoup,
new _ngRef.ReflectionInfo(
const [const Soup()], const [], () => new PackageSoup()));
}

View File

@ -1,17 +0,0 @@
library dinner.relative_soup.ng_deps.dart;
import 'relative_soup.dart';
export 'relative_soup.dart';
import 'package:angular2/src/reflection/reflection.dart' as _ngRef;
import 'annotations/soup.dart';
var _visited = false;
void initReflector() {
if (_visited) return;
_visited = true;
_ngRef.reflector
..registerType(
RelativeSoup,
new _ngRef.ReflectionInfo(
const [const Soup()], const [], () => new RelativeSoup()));
}

View File

@ -1,8 +0,0 @@
library dinner.package_soup;
import 'package:soup/soup.dart';
@Soup()
class PackageSoup {
PackageSoup();
}

View File

@ -1,8 +0,0 @@
library dinner.relative_soup;
import 'annotations/soup.dart';
@Soup()
class RelativeSoup {
RelativeSoup();
}

View File

@ -1,3 +0,0 @@
class Bar {}
const alias3 = const [Bar];

View File

@ -1,15 +0,0 @@
{
"alias1": {
"kind": "alias",
"value": [
"HelloCmp"
]
},
"alias2": {
"kind": "alias",
"value": [
"HelloCmp",
"Foo"
]
}
}

View File

@ -1,25 +0,0 @@
library examples.src.hello_world.absolute_url_expression_files.ng_deps.dart;
import 'hello.dart';
export 'hello.dart';
import 'package:angular2/src/reflection/reflection.dart' as _ngRef;
import 'package:angular2/angular2.dart'
show bootstrap, Component, Directive, View, NgElement;
export 'a.dart' show alias3;
import 'b.dart' as b;
var _visited = false;
void initReflector() {
if (_visited) return;
_visited = true;
_ngRef.reflector
..registerType(
HelloCmp,
new _ngRef.ReflectionInfo(const [
const Component(selector: 'hello-app'),
const View(
template: r'''{{greeting}}''',
templateUrl: r'template.html',
styles: const [r'''.greeting { .color: blue; }''',])
], const [], () => new HelloCmp()));
}

View File

@ -1,20 +0,0 @@
library examples.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];

View File

@ -1,26 +0,0 @@
library examples.src.hello_world.index_common_dart.ng_deps.dart;
import 'hello.dart';
export 'hello.dart';
import 'package:angular2/src/reflection/reflection.dart' as _ngRef;
import 'package:angular2/angular2.dart'
show Component, Directive, View, NgElement;
var _visited = false;
void initReflector() {
if (_visited) return;
_visited = true;
_ngRef.reflector
..registerType(
HelloCmp,
new _ngRef.ReflectionInfo(const [
const Component(selector: 'hello-app'),
const View(
template: r'''{{greeting}}''',
templateUrl: r'template.html',
styles: const [
r'''.greeting { .color: blue; }''',
r'''.hello { .color: red; }''',
])
], const [], () => new HelloCmp()));
}

View File

@ -1,20 +0,0 @@
library dinner.soup.ng_deps.dart;
import 'soup.dart';
export 'soup.dart';
import 'package:angular2/src/reflection/reflection.dart' as _ngRef;
import 'package:angular2/src/core/metadata.dart';
var _visited = false;
void initReflector() {
if (_visited) return;
_visited = true;
_ngRef.reflector
..registerType(
ChangingSoupComponent,
new _ngRef.ReflectionInfo(
const [const Component(selector: '[soup]')],
const [],
() => new ChangingSoupComponent(),
const [PrimaryInterface]));
}

View File

@ -1,12 +0,0 @@
library dinner.soup;
import 'package:angular2/src/core/metadata.dart';
@Component(selector: '[soup]')
class ChangingSoupComponent implements PrimaryInterface {}
class TernaryInterface {}
class SecondaryInterface implements TernaryInterface {}
class PrimaryInterface implements SecondaryInterface {}

View File

@ -1,66 +0,0 @@
library dinner.soup.ng_deps.dart;
import 'soup.dart';
export 'soup.dart';
import 'package:angular2/src/reflection/reflection.dart' as _ngRef;
import 'package:angular2/metadata.dart';
var _visited = false;
void initReflector() {
if (_visited) return;
_visited = true;
_ngRef.reflector
..registerType(
OnChangeSoupComponent,
new _ngRef.ReflectionInfo(
const [
const Component(
selector: '[soup]',
lifecycle: const [LifecycleEvent.onChange])
],
const [],
() => new OnChangeSoupComponent(),
const [OnChange]))
..registerType(
OnDestroySoupComponent,
new _ngRef.ReflectionInfo(
const [
const Component(
selector: '[soup]',
lifecycle: const [LifecycleEvent.onDestroy])
],
const [],
() => new OnDestroySoupComponent(),
const [OnDestroy]))
..registerType(
OnCheckSoupComponent,
new _ngRef.ReflectionInfo(
const [
const Component(
selector: '[soup]', lifecycle: const [LifecycleEvent.onCheck])
],
const [],
() => new OnCheckSoupComponent(),
const [OnCheck]))
..registerType(
OnInitSoupComponent,
new _ngRef.ReflectionInfo(
const [
const Component(
selector: '[soup]', lifecycle: const [LifecycleEvent.onInit])
],
const [],
() => new OnInitSoupComponent(),
const [OnInit]))
..registerType(
OnAllChangesDoneSoupComponent,
new _ngRef.ReflectionInfo(
const [
const Component(
selector: '[soup]',
lifecycle: const [LifecycleEvent.onAllChangesDone])
],
const [],
() => new OnAllChangesDoneSoupComponent(),
const [OnAllChangesDone]));
}

View File

@ -1,18 +0,0 @@
library dinner.soup;
import 'package:angular2/metadata.dart';
@Component(selector: '[soup]')
class OnChangeSoupComponent implements OnChange {}
@Component(selector: '[soup]')
class OnDestroySoupComponent implements OnDestroy {}
@Component(selector: '[soup]')
class OnCheckSoupComponent implements OnCheck {}
@Component(selector: '[soup]')
class OnInitSoupComponent implements OnInit {}
@Component(selector: '[soup]')
class OnAllChangesDoneSoupComponent implements OnAllChangesDone {}

View File

@ -1,20 +0,0 @@
library dinner.soup.ng_deps.dart;
import 'soup.dart';
export 'soup.dart';
import 'package:angular2/src/reflection/reflection.dart' as _ngRef;
import 'package:angular2/src/core/metadata.dart';
var _visited = false;
void initReflector() {
if (_visited) return;
_visited = true;
_ngRef.reflector
..registerType(
ChangingSoupComponent,
new _ngRef.ReflectionInfo(
const [const Component(selector: '[soup]')],
const [],
() => new ChangingSoupComponent(),
const [OnChange, AnotherInterface]));
}

View File

@ -1,6 +0,0 @@
library dinner.soup;
import 'package:angular2/src/core/metadata.dart';
@Component(selector: '[soup]')
class ChangingSoupComponent implements OnChange, AnotherInterface {}

View File

@ -1,23 +0,0 @@
library test.transform.directive_processor.invalid_url_files.hello.ng_deps.dart;
import 'hello.dart';
export 'hello.dart';
import 'package:angular2/src/reflection/reflection.dart' as _ngRef;
import 'package:angular2/angular2.dart'
show Component, Directive, View, NgElement;
var _visited = false;
void initReflector() {
if (_visited) return;
_visited = true;
_ngRef.reflector
..registerType(
HelloCmp,
new _ngRef.ReflectionInfo(const [
const Component(selector: 'hello-app'),
const View(
template: r'''''',
templateUrl: r'/bad/absolute/url.html',
styles: const [r'''''', r'''''',])
], const [], () => new HelloCmp()));
}

View File

@ -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 {}

View File

@ -1,53 +0,0 @@
library dinner.soup.ng_deps.dart;
import 'soup.dart';
export 'soup.dart';
import 'package:angular2/src/reflection/reflection.dart' as _ngRef;
import 'package:angular2/metadata.dart';
var _visited = false;
void initReflector() {
if (_visited) return;
_visited = true;
_ngRef.reflector
..registerType(
MultiSoupComponent,
new _ngRef.ReflectionInfo(
const [
const Component(
selector: '[soup]',
lifecycle: const [
LifecycleEvent.onChange,
LifecycleEvent.onDestroy,
LifecycleEvent.onInit
])
],
const [],
() => new MultiSoupComponent(),
const [OnChange, OnDestroy, OnInit]))
..registerType(
MixedSoupComponent,
new _ngRef.ReflectionInfo(
const [
const Component(
selector: '[soup]',
lifecycle: const [
LifecycleEvent.onChange,
LifecycleEvent.onCheck
])
],
const [],
() => new MixedSoupComponent(),
const [OnChange]))
..registerType(
MatchedSoupComponent,
new _ngRef.ReflectionInfo(
const [
const Component(
selector: '[soup]',
lifecycle: const [LifecycleEvent.onChange])
],
const [],
() => new MatchedSoupComponent(),
const [OnChange]));
}

View File

@ -1,12 +0,0 @@
library dinner.soup;
import 'package:angular2/metadata.dart';
@Component(selector: '[soup]')
class MultiSoupComponent implements OnChange, OnDestroy, OnInit {}
@Component(selector: '[soup]', lifecycle: const [LifecycleEvent.onCheck])
class MixedSoupComponent implements OnChange {}
@Component(selector: '[soup]', lifecycle: const [LifecycleEvent.onChange])
class MatchedSoupComponent implements OnChange {}

View File

@ -1,25 +0,0 @@
library main.ng_deps.dart;
import 'main.dart';
export 'main.dart';
import 'package:angular2/src/reflection/reflection.dart' as _ngRef;
import 'package:angular2/src/core/metadata.dart';
var _visited = false;
void initReflector() {
if (_visited) return;
_visited = true;
_ngRef.reflector
..registerType(
Part1Component,
new _ngRef.ReflectionInfo(const [const Component(selector: '[part1]')],
const [], () => new Part1Component()))
..registerType(
Part2Component,
new _ngRef.ReflectionInfo(const [const Component(selector: '[part2]')],
const [], () => new Part2Component()))
..registerType(
MainComponent,
new _ngRef.ReflectionInfo(const [const Component(selector: '[main]')],
const [], () => new MainComponent()));
}

View File

@ -1,11 +0,0 @@
library main;
import 'package:angular2/src/core/metadata.dart';
part 'part1.dart';
part 'part2.dart';
@Component(selector: '[main]')
class MainComponent {
MainComponent();
}

View File

@ -1,6 +0,0 @@
part of main;
@Component(selector: '[part1]')
class Part1Component {
Part1Component();
}

View File

@ -1,6 +0,0 @@
part of main;
@Component(selector: '[part2]')
class Part2Component {
Part2Component();
}

View File

@ -1,26 +0,0 @@
library examples.src.hello_world.multiple_style_urls_files.ng_deps.dart;
import 'hello.dart';
export 'hello.dart';
import 'package:angular2/src/reflection/reflection.dart' as _ngRef;
import 'package:angular2/angular2.dart'
show Component, Directive, View, NgElement;
var _visited = false;
void initReflector() {
if (_visited) return;
_visited = true;
_ngRef.reflector
..registerType(
HelloCmp,
new _ngRef.ReflectionInfo(const [
const Component(selector: 'hello-app'),
const View(
template: r'''{{greeting}}''',
templateUrl: r'template.html',
styles: const [
r'''.greeting { .color: blue; }''',
r'''.hello { .color: red; }''',
])
], const [], () => new HelloCmp()));
}

View File

@ -1,10 +0,0 @@
library examples.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 {}

View File

@ -1,25 +0,0 @@
library examples.src.hello_world.multiple_style_urls_not_inlined_files.ng_deps.dart;
import 'hello.dart';
export 'hello.dart';
import 'package:angular2/src/reflection/reflection.dart' as _ngRef;
import 'package:angular2/angular2.dart'
show Component, Directive, View, NgElement;
var _visited = false;
void initReflector() {
if (_visited) return;
_visited = true;
_ngRef.reflector
..registerType(
HelloCmp,
new _ngRef.ReflectionInfo(const [
const Component(selector: 'hello-app'),
const View(
templateUrl: 'package:a/template.html',
styleUrls: const [
'package:a/template.css',
'package:a/template_other.css'
])
], const [], () => new HelloCmp()));
}

Some files were not shown because too many files have changed in this diff Show More