chore(transformer): Use class for reflection info instead of a map

closes https://github.com/angular/angular/issues/906
This commit is contained in:
Jacob MacDonald
2015-07-23 15:18:30 -07:00
parent a8b75c3d41
commit 5b5de6662f
95 changed files with 550 additions and 890 deletions
@@ -11,15 +11,11 @@ void initReflector() {
if (_visited) return;
_visited = true;
_ngRef.reflector
..registerType(HelloCmp, {
'factory': () => new HelloCmp(),
'parameters': const [],
'annotations': const [
const Component(selector: 'hello-app'),
const View(
template: r'''{{greeting}}''',
templateUrl: r'package:other_package/template.html',
styles: const [r'''.greeting { .color: blue; }''',])
]
});
..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()));
}
@@ -35,9 +35,9 @@ void allTests() {
'custom_metadata/relative_soup.dart',
assetId: new AssetId('soup', 'lib/relative_soup.dart'),
customDescriptors: [
const ClassDescriptor('Soup', 'package:soup/annotations/soup.dart',
superClass: 'Component'),
]);
const ClassDescriptor('Soup', 'package:soup/annotations/soup.dart',
superClass: 'Component'),
]);
_testProcessor(
'Requires the specified import.', 'custom_metadata/bad_soup.dart',
@@ -50,18 +50,14 @@ void allTests() {
'should inline `templateUrl` values.', 'url_expression_files/hello.dart');
var absoluteReader = new TestAssetReader();
absoluteReader.addAsset(
new AssetId('other_package', 'lib/template.html'),
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'),
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',
_testProcessor('should inline `templateUrl` and `styleUrls` values expressed'
' as absolute urls.', 'absolute_url_expression_files/hello.dart',
reader: absoluteReader);
_testProcessor(
@@ -72,16 +68,12 @@ void allTests() {
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'));
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);
'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');
@@ -126,16 +118,12 @@ void allTests() {
'static_function_files/hello.dart');
_testProcessor('should find direcive aliases patterns.',
'directive_aliases_files/hello.dart',
reader: absoluteReader);
'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,
{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 {
@@ -161,8 +149,7 @@ void _testProcessor(String name, String inputPath,
..addAll(customDescriptors);
var ngMeta = new NgMeta.empty();
var output = await createNgDeps(
reader, inputId, annotationMatcher, ngMeta,
inlineViews: inlineViews);
reader, inputId, annotationMatcher, ngMeta, inlineViews: inlineViews);
if (output == null) {
expect(await reader.hasInput(expectedNgDepsId)).toBeFalse();
} else {
@@ -10,9 +10,6 @@ void initReflector() {
if (_visited) return;
_visited = true;
_ngRef.reflector
..registerType(PackageSoup, {
'factory': () => new PackageSoup(),
'parameters': const [],
'annotations': const [const Soup()]
});
..registerType(PackageSoup, new _ngRef.ReflectionInfo(
const [const Soup()], const [], () => new PackageSoup()));
}
@@ -10,9 +10,6 @@ void initReflector() {
if (_visited) return;
_visited = true;
_ngRef.reflector
..registerType(RelativeSoup, {
'factory': () => new RelativeSoup(),
'parameters': const [],
'annotations': const [const Soup()]
});
..registerType(RelativeSoup, new _ngRef.ReflectionInfo(
const [const Soup()], const [], () => new RelativeSoup()));
}
@@ -13,15 +13,11 @@ void initReflector() {
if (_visited) return;
_visited = true;
_ngRef.reflector
..registerType(HelloCmp, {
'factory': () => new HelloCmp(),
'parameters': const [],
'annotations': const [
const Component(selector: 'hello-app'),
const View(
template: r'''{{greeting}}''',
templateUrl: r'template.html',
styles: const [r'''.greeting { .color: blue; }''',])
]
});
..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()));
}
@@ -11,18 +11,14 @@ void initReflector() {
if (_visited) return;
_visited = true;
_ngRef.reflector
..registerType(HelloCmp, {
'factory': () => new HelloCmp(),
'parameters': const [],
'annotations': 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; }''',
])
]
});
..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()));
}
@@ -10,10 +10,7 @@ void initReflector() {
if (_visited) return;
_visited = true;
_ngRef.reflector
..registerType(ChangingSoupComponent, {
'factory': () => new ChangingSoupComponent(),
'parameters': const [],
'annotations': const [const Component(selector: '[soup]')],
'interfaces': const [PrimaryInterface]
});
..registerType(ChangingSoupComponent, new _ngRef.ReflectionInfo(
const [const Component(selector: '[soup]')], const [],
() => new ChangingSoupComponent(), const [PrimaryInterface]));
}
@@ -10,50 +10,27 @@ void initReflector() {
if (_visited) return;
_visited = true;
_ngRef.reflector
..registerType(OnChangeSoupComponent, {
'factory': () => new OnChangeSoupComponent(),
'parameters': const [],
'annotations': const [
const Component(
selector: '[soup]', lifecycle: const [LifecycleEvent.onChange])
],
'interfaces': const [OnChange]
})
..registerType(OnDestroySoupComponent, {
'factory': () => new OnDestroySoupComponent(),
'parameters': const [],
'annotations': const [
const Component(
selector: '[soup]', lifecycle: const [LifecycleEvent.onDestroy])
],
'interfaces': const [OnDestroy]
})
..registerType(OnCheckSoupComponent, {
'factory': () => new OnCheckSoupComponent(),
'parameters': const [],
'annotations': const [
const Component(
selector: '[soup]', lifecycle: const [LifecycleEvent.onCheck])
],
'interfaces': const [OnCheck]
})
..registerType(OnInitSoupComponent, {
'factory': () => new OnInitSoupComponent(),
'parameters': const [],
'annotations': const [
const Component(
selector: '[soup]', lifecycle: const [LifecycleEvent.onInit])
],
'interfaces': const [OnInit]
})
..registerType(OnAllChangesDoneSoupComponent, {
'factory': () => new OnAllChangesDoneSoupComponent(),
'parameters': const [],
'annotations': const [
const Component(
selector: '[soup]',
lifecycle: const [LifecycleEvent.onAllChangesDone])
],
'interfaces': const [OnAllChangesDone]
});
..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]));
}
@@ -10,10 +10,7 @@ void initReflector() {
if (_visited) return;
_visited = true;
_ngRef.reflector
..registerType(ChangingSoupComponent, {
'factory': () => new ChangingSoupComponent(),
'parameters': const [],
'annotations': const [const Component(selector: '[soup]')],
'interfaces': const [OnChange, AnotherInterface]
});
..registerType(ChangingSoupComponent, new _ngRef.ReflectionInfo(
const [const Component(selector: '[soup]')], const [],
() => new ChangingSoupComponent(), const [OnChange, AnotherInterface]));
}
@@ -11,15 +11,11 @@ void initReflector() {
if (_visited) return;
_visited = true;
_ngRef.reflector
..registerType(HelloCmp, {
'factory': () => new HelloCmp(),
'parameters': const [],
'annotations': const [
const Component(selector: 'hello-app'),
const View(
template: r'''''',
templateUrl: r'/bad/absolute/url.html',
styles: const [r'''''', r'''''',])
]
});
..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()));
}
@@ -10,18 +10,17 @@ void initReflector() {
if (_visited) return;
_visited = true;
_ngRef.reflector
..registerType(MultiSoupComponent, {
'factory': () => new MultiSoupComponent(),
'parameters': const [],
'annotations': const [
const Component(
selector: '[soup]',
lifecycle: const [
LifecycleEvent.onChange,
LifecycleEvent.onDestroy,
LifecycleEvent.onInit
])
],
'interfaces': const [OnChange, OnDestroy, OnInit]
});
..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
]));
}
@@ -11,18 +11,14 @@ void initReflector() {
if (_visited) return;
_visited = true;
_ngRef.reflector
..registerType(HelloCmp, {
'factory': () => new HelloCmp(),
'parameters': const [],
'annotations': 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; }''',
])
]
});
..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()));
}
@@ -11,17 +11,13 @@ void initReflector() {
if (_visited) return;
_visited = true;
_ngRef.reflector
..registerType(HelloCmp, {
'factory': () => new HelloCmp(),
'parameters': const [],
'annotations': const [
const Component(selector: 'hello-app'),
const View(
templateUrl: 'package:a/template.html',
styleUrls: const [
'package:a/template.css',
'package:a/template_other.css'
])
]
});
..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()));
}
@@ -10,10 +10,9 @@ void initReflector() {
if (_visited) return;
_visited = true;
_ngRef.reflector
..registerType(SoupComponent, {
'factory':
(String description, salt) => new SoupComponent(description, salt),
'parameters': const [const [String, Tasty], const [const Inject(Salt)]],
'annotations': const [const Component(selector: '[soup]')]
});
..registerType(SoupComponent, new _ngRef.ReflectionInfo(
const [const Component(selector: '[soup]')], const [
const [String, Tasty],
const [const Inject(Salt)]
], (String description, salt) => new SoupComponent(description, salt)));
}
@@ -10,14 +10,8 @@ void initReflector() {
if (_visited) return;
_visited = true;
_ngRef.reflector
..registerType(OnChangeSoupComponent, {
'factory': () => new OnChangeSoupComponent(),
'parameters': const [],
'annotations': const [
const prefix.Component(
selector: '[soup]',
lifecycle: const [prefix.LifecycleEvent.onChange])
],
'interfaces': const [prefix.OnChange]
});
..registerType(OnChangeSoupComponent, new _ngRef.ReflectionInfo(const [
const prefix.Component(
selector: '[soup]', lifecycle: const [prefix.LifecycleEvent.onChange])
], const [], () => new OnChangeSoupComponent(), const [prefix.OnChange]));
}
@@ -11,12 +11,8 @@ void initReflector() {
if (_visited) return;
_visited = true;
_ngRef.reflector
..registerType(HelloCmp, {
'factory': () => new HelloCmp(),
'parameters': const [],
'annotations': const [
const Component(selector: 'hello-app'),
const View(template: r'''{{greeting}}''', templateUrl: r'template.html')
]
});
..registerType(HelloCmp, new _ngRef.ReflectionInfo(const [
const Component(selector: 'hello-app'),
const View(template: r'''{{greeting}}''', templateUrl: r'template.html')
], const [], () => new HelloCmp()));
}
@@ -10,13 +10,8 @@ void initReflector() {
if (_visited) return;
_visited = true;
_ngRef.reflector
..registerFunction(getMessage, {
'parameters': const [const [const Inject(Message)]],
'annotations': const Injectable()
})
..registerType(Message, {
'factory': () => new Message(),
'parameters': const [],
'annotations': const [const Injectable()]
});
..registerFunction(getMessage, new _ngRef.ReflectionInfo(
const Injectable(), const [const [const Inject(Message)]]))
..registerType(Message, new _ngRef.ReflectionInfo(
const [const Injectable()], const [], () => new Message()));
}
@@ -10,9 +10,7 @@ void initReflector() {
if (_visited) return;
_visited = true;
_ngRef.reflector
..registerType(ChangingSoupComponent, {
'factory': () => new ChangingSoupComponent(),
'parameters': const [],
'annotations': const [const Component(selector: '[soup]')]
});
..registerType(ChangingSoupComponent, new _ngRef.ReflectionInfo(
const [const Component(selector: '[soup]')], const [],
() => new ChangingSoupComponent()));
}
@@ -10,12 +10,8 @@ void initReflector() {
if (_visited) return;
_visited = true;
_ngRef.reflector
..registerType(OnChangeSoupComponent, {
'factory': () => new OnChangeSoupComponent(),
'parameters': const [],
'annotations': const [
const Component(
selector: '[soup]', lifecycle: const [LifecycleEvent.onChange])
]
});
..registerType(OnChangeSoupComponent, new _ngRef.ReflectionInfo(const [
const Component(
selector: '[soup]', lifecycle: const [LifecycleEvent.onChange])
], const [], () => new OnChangeSoupComponent()));
}
@@ -11,12 +11,8 @@ void initReflector() {
if (_visited) return;
_visited = true;
_ngRef.reflector
..registerType(HelloCmp, {
'factory': () => new HelloCmp(),
'parameters': const [],
'annotations': const [
const Component(selector: 'hello-app'),
const View(template: r'''{{greeting}}''', templateUrl: r'template.html')
]
});
..registerType(HelloCmp, new _ngRef.ReflectionInfo(const [
const Component(selector: 'hello-app'),
const View(template: r'''{{greeting}}''', templateUrl: r'template.html')
], const [], () => new HelloCmp()));
}