feat(dart/transform): Improve constant evaluation
Use `package:analyzer`'s `ConstantEvaluator` to read from the AST. This cleanly builds values for us from adjacent strings, interpolations, etc.
This commit is contained in:
+16
@@ -0,0 +1,16 @@
|
||||
library bar.ng_deps.dart;
|
||||
|
||||
import 'foo.dart';
|
||||
import 'package:angular2/src/core/annotations/annotations.dart';
|
||||
|
||||
var _visited = false;
|
||||
void initReflector(reflector) {
|
||||
if (_visited) return;
|
||||
_visited = true;
|
||||
reflector
|
||||
..registerType(FooComponent, {
|
||||
'factory': () => new FooComponent(),
|
||||
'parameters': const [],
|
||||
'annotations': const [const Component(selector: '[fo' 'o]')]
|
||||
});
|
||||
}
|
||||
@@ -101,6 +101,17 @@ void allTests() {
|
||||
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).toContain('FooComponent');
|
||||
|
||||
var extractedMeta = extracted['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'));
|
||||
|
||||
@@ -39,6 +39,9 @@ void allTests() {
|
||||
|
||||
_testNgDeps(
|
||||
'should inline `templateUrl` values.', 'url_expression_files/hello.dart');
|
||||
|
||||
_testNgDeps('should inline `templateUrl`s expressed as adjacent strings.',
|
||||
'split_url_expression_files/hello.dart');
|
||||
}
|
||||
|
||||
void _testNgDeps(String name, String inputPath,
|
||||
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
library examples.src.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, {
|
||||
'factory': () => new HelloCmp(),
|
||||
'parameters': const [],
|
||||
'annotations': const [
|
||||
const Component(selector: 'hello-app'),
|
||||
const View(template: r'''{{greeting}}''')
|
||||
]
|
||||
});
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
library examples.src.hello_world.index_common_dart;
|
||||
|
||||
import 'package:angular2/angular2.dart'
|
||||
show bootstrap, Component, Directive, View, NgElement;
|
||||
|
||||
@Component(selector: 'hello-app')
|
||||
@View(templateUrl: 'templ' 'ate.html')
|
||||
class HelloCmp {}
|
||||
+1
@@ -0,0 +1 @@
|
||||
{{greeting}}
|
||||
Reference in New Issue
Block a user