-
Notifications
You must be signed in to change notification settings - Fork 27.3k
PR to review transformer changes from tbosch https://github.com/angular/angular/pull/5993 #6171
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -79,26 +79,34 @@ class ReflectionInfoVisitor extends RecursiveAstVisitor<ReflectionInfoModel> { | |
| } | ||
|
|
||
| if (node.metadata != null) { | ||
| var componentDirectives, viewDirectives; | ||
| var componentDirectives = []; | ||
| var componentPipes = []; | ||
| var viewDirectives, viewPipes; | ||
| node.metadata.forEach((node) { | ||
| if (_annotationMatcher.isComponent(node, assetId)) { | ||
| componentDirectives = _extractDirectives(node); | ||
| componentDirectives = _extractReferencedTypes(node, 'directives'); | ||
| componentPipes = _extractReferencedTypes(node, 'pipes'); | ||
| } else if (_annotationMatcher.isView(node, assetId)) { | ||
| viewDirectives = _extractDirectives(node); | ||
| viewDirectives = _extractReferencedTypes(node, 'directives'); | ||
| viewPipes = _extractReferencedTypes(node, 'pipes'); | ||
| } | ||
| model.annotations.add(_annotationVisitor.visitAnnotation(node)); | ||
| }); | ||
| if (componentDirectives != null && componentDirectives.isNotEmpty) { | ||
| if (viewDirectives != null) { | ||
| log.warning( | ||
| 'Cannot specify view parameters on @Component when a @View ' | ||
| 'is present. Component name: ${model.name}', | ||
| asset: assetId); | ||
| } | ||
| model.directives.addAll(componentDirectives); | ||
| } else if (viewDirectives != null) { | ||
| if ((componentDirectives.isNotEmpty || componentPipes.isNotEmpty) && | ||
| (viewDirectives != null || viewPipes != null)) { | ||
| log.warning( | ||
| 'Cannot specify view parameters on @Component when a @View ' | ||
| 'is present. Component name: ${model.name}', | ||
| asset: assetId); | ||
| } | ||
| model.directives.addAll(componentDirectives); | ||
| model.pipes.addAll(componentPipes); | ||
| if (viewDirectives != null) { | ||
| model.directives.addAll(viewDirectives); | ||
| } | ||
| if (viewPipes != null) { | ||
| model.pipes.addAll(viewPipes); | ||
| } | ||
| } | ||
| if (ctor != null && | ||
| ctor.parameters != null && | ||
|
|
@@ -151,43 +159,43 @@ class ReflectionInfoVisitor extends RecursiveAstVisitor<ReflectionInfoModel> { | |
| } | ||
| } | ||
|
|
||
| /// Returns [PrefixedDirective] values parsed from the value of the | ||
| /// `directives` parameter of the provided `node`. | ||
| /// Returns [PrefixedType] values parsed from the value of the | ||
| /// `directives`/`pipes` parameter of the provided `node`. | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: This method will parse from any provided
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
| /// This will always return a non-null value, so if there are no `directives` | ||
| /// specified on `node`, it will return an empty iterable. | ||
| Iterable<PrefixedDirective> _extractDirectives(Annotation node) { | ||
| /// nor `pipes` specified on `node`, it will return an empty iterable. | ||
| Iterable<PrefixedType> _extractReferencedTypes(Annotation node, String fieldName) { | ||
| assert(_annotationMatcher.isComponent(node, assetId) || | ||
| _annotationMatcher.isView(node, assetId)); | ||
|
|
||
| if (node.arguments == null && node.arguments.arguments == null) { | ||
| return const []; | ||
| } | ||
| final directivesNode = node.arguments.arguments.firstWhere((arg) { | ||
| return arg is NamedExpression && '${arg.name.label}' == 'directives'; | ||
| final typesNode = node.arguments.arguments.firstWhere((arg) { | ||
| return arg is NamedExpression && '${arg.name.label}' == fieldName; | ||
| }, orElse: () => null); | ||
| if (directivesNode == null) return const []; | ||
| if (typesNode == null) return const []; | ||
|
|
||
| if (directivesNode.expression is! ListLiteral) { | ||
| if (typesNode.expression is! ListLiteral) { | ||
| log.warning( | ||
| 'Angular 2 expects a list literal for `directives` ' | ||
| 'but found a ${directivesNode.expression.runtimeType}', | ||
| 'Angular 2 expects a list literal for `${fieldName}` ' | ||
| 'but found a ${typesNode.expression.runtimeType}', | ||
| asset: assetId); | ||
| return const []; | ||
| } | ||
| final directives = <PrefixedDirective>[]; | ||
| for (var dep in (directivesNode.expression as ListLiteral).elements) { | ||
| final types = <PrefixedType>[]; | ||
| for (var dep in (typesNode.expression as ListLiteral).elements) { | ||
| if (dep is PrefixedIdentifier) { | ||
| directives.add(new PrefixedDirective() | ||
| types.add(new PrefixedType() | ||
| ..prefix = '${dep.prefix}' | ||
| ..name = '${dep.identifier}'); | ||
| } else if (dep is Identifier) { | ||
| directives.add(new PrefixedDirective()..name = '${dep}'); | ||
| types.add(new PrefixedType()..name = '${dep}'); | ||
| } else { | ||
| log.warning('Found unexpected value $dep in `directives`.', | ||
| log.warning('Found unexpected value $dep in `types`.', | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Also, would you change "Found" to "Ignoring" in this message?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
| asset: assetId); | ||
| } | ||
| } | ||
| return directives; | ||
| return types; | ||
| } | ||
|
|
||
| @override | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,7 +34,7 @@ class NgMeta { | |
| static const _VALUE_KEY = 'value'; | ||
|
|
||
| /// Directive metadata for each type annotated as a directive. | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please update this comment & explain the expected value types.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
| final Map<String, CompileDirectiveMetadata> types; | ||
| final Map<String, dynamic> types; | ||
|
|
||
| /// List of other types and names associated with a given name. | ||
| final Map<String, List<String>> aliases; | ||
|
|
@@ -43,7 +43,7 @@ class NgMeta { | |
| final NgDepsModel ngDeps; | ||
|
|
||
| NgMeta( | ||
| {Map<String, CompileDirectiveMetadata> types, | ||
| {Map<String, dynamic> types, | ||
| Map<String, List<String>> aliases, | ||
| this.ngDeps: null}) | ||
| : this.types = types != null ? types : {}, | ||
|
|
@@ -91,7 +91,7 @@ class NgMeta { | |
| continue; | ||
| } | ||
| if (entry[_KIND_KEY] == _TYPE_VALUE) { | ||
| types[key] = CompileDirectiveMetadata.fromJson(entry[_VALUE_KEY]); | ||
| types[key] = CompileMetadataWithType.fromJson(entry[_VALUE_KEY]); | ||
| } else if (entry[_KIND_KEY] == _ALIAS_VALUE) { | ||
| aliases[key] = entry[_VALUE_KEY]; | ||
| } | ||
|
|
@@ -123,8 +123,8 @@ class NgMeta { | |
| } | ||
|
|
||
| /// Returns the metadata for every type associated with the given [alias]. | ||
| List<CompileDirectiveMetadata> flatten(String alias) { | ||
| var result = <CompileDirectiveMetadata>[]; | ||
| List<dynamic> flatten(String alias) { | ||
| var result = []; | ||
| var seen = new Set(); | ||
| helper(name) { | ||
| if (!seen.add(name)) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,7 @@ const ENTRY_POINT_PARAM = 'entry_points'; | |
| const FORMAT_CODE_PARAM = 'format_code'; | ||
| const REFLECT_PROPERTIES_AS_ATTRIBUTES = 'reflect_properties_as_attributes'; | ||
| const PLATFORM_DIRECTIVES = 'platform_directives'; | ||
| const PLATFORM_PIPES = 'platform_pipes'; | ||
| const INIT_REFLECTOR_PARAM = 'init_reflector'; | ||
| const INLINE_VIEWS_PARAM = 'inline_views'; | ||
| const MIRROR_MODE_PARAM = 'mirror_mode'; | ||
|
|
@@ -47,6 +48,10 @@ class TransformerOptions { | |
| /// Format of an item in the list: angular2/lib/src/common/directives.dart#CORE_DIRECTIVES | ||
| final List<String> platformDirectives; | ||
|
|
||
| /// A set of pipes that will be automatically passed-in to the template compiler | ||
| /// Format of an item in the list: angular2/lib/src/common/directives.dart#CORE_DIRECTIVES | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
| final List<String> platformPipes; | ||
|
|
||
| /// Whether to format generated code. | ||
| /// Code that is only modified will never be formatted because doing so may | ||
| /// invalidate the source maps generated by `dart2js` and/or other tools. | ||
|
|
@@ -76,6 +81,7 @@ class TransformerOptions { | |
| {this.genChangeDetectionDebugInfo, | ||
| this.reflectPropertiesAsAttributes, | ||
| this.platformDirectives, | ||
| this.platformPipes, | ||
| this.inlineViews, | ||
| this.lazyTransformers, | ||
| this.formatCode}); | ||
|
|
@@ -89,6 +95,7 @@ class TransformerOptions { | |
| bool genChangeDetectionDebugInfo: false, | ||
| bool reflectPropertiesAsAttributes: false, | ||
| List<String> platformDirectives, | ||
| List<String> platformPipes, | ||
| bool lazyTransformers: false, | ||
| bool formatCode: false}) { | ||
| var annotationMatcher = new AnnotationMatcher() | ||
|
|
@@ -101,6 +108,7 @@ class TransformerOptions { | |
| genChangeDetectionDebugInfo: genChangeDetectionDebugInfo, | ||
| reflectPropertiesAsAttributes: reflectPropertiesAsAttributes, | ||
| platformDirectives: platformDirectives, | ||
| platformPipes: platformPipes, | ||
| inlineViews: inlineViews, | ||
| lazyTransformers: lazyTransformers, | ||
| formatCode: formatCode); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Since
_extractReferencedTypereturnsIterable, consider usingnew Iterable.empty()here rather than a list literal to maintain consistent typeThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done