Skip to content
This repository was archived by the owner on Jun 20, 2019. It is now read-only.

Commit 5f9c265

Browse files
Remove all references to @view, which has been removed from angular (#462)
Fix all tests using it, remove tests testing it specifically, and remove it as a possibliity for the directives lookup strategy. Remove from test angular code as well, to confirm our code will run when that class is absent.
1 parent 082ac7b commit 5f9c265

File tree

7 files changed

+380
-605
lines changed

7 files changed

+380
-605
lines changed

angular_analyzer_plugin/lib/src/model.dart

+4-5
Original file line numberDiff line numberDiff line change
@@ -627,18 +627,17 @@ class UseConstValueStrategy implements DirectivesStrategy {
627627
T Function(DartObject, SourceRange) constStrategyHandler) =>
628628
constStrategyHandler(
629629
annotatedObject.metadata
630-
.where((m) => _isViewOrComponent(m.element?.enclosingElement))
630+
.where((m) => _isComponent(m.element?.enclosingElement))
631631
.map((m) => _getDirectives(m.computeConstantValue()))
632632
// TODO(mfairhurst): report error for double definition
633633
.firstWhere((directives) => !(directives?.isNull ?? true),
634634
orElse: () => null),
635635
sourceRange);
636636

637-
/// Check if an element is a View or Component
638-
bool _isViewOrComponent(dart.Element element) =>
637+
/// Check if an element is a Component
638+
bool _isComponent(dart.Element element) =>
639639
element is dart.ClassElement &&
640-
(element.type.isSubtypeOf(standardAngular.view.type) ||
641-
element.type.isSubtypeOf(standardAngular.component.type));
640+
element.type.isSubtypeOf(standardAngular.component.type);
642641

643642
/// Traverse the inheritance hierarchy in the constant value, looking for the
644643
/// 'directives' field at the highest level it occurs.

angular_analyzer_plugin/lib/src/standard_components.dart

-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ class StandardAngular {
2626
final ClassElement elementRef;
2727
final ClassElement queryList;
2828
final ClassElement pipeTransform;
29-
final ClassElement view;
3029
final ClassElement component;
3130
final SecuritySchema securitySchema;
3231

@@ -35,7 +34,6 @@ class StandardAngular {
3534
this.elementRef,
3635
this.queryList,
3736
this.pipeTransform,
38-
this.view,
3937
this.component,
4038
this.securitySchema});
4139

@@ -64,7 +62,6 @@ class StandardAngular {
6462
elementRef: ng.get("ElementRef"),
6563
templateRef: ng.get("TemplateRef"),
6664
pipeTransform: ng.get("PipeTransform"),
67-
view: ng.get("View"),
6865
component: ng.get("Component"),
6966
securitySchema: securitySchema);
7067
}

angular_analyzer_plugin/lib/src/view_extraction.dart

+3-8
Original file line numberDiff line numberDiff line change
@@ -33,24 +33,19 @@ class ViewExtractor extends AnnotationProcessorMixin {
3333
for (final unitMember in unit.declarations) {
3434
if (unitMember is ast.ClassDeclaration) {
3535
final classElement = unitMember.element;
36-
ast.Annotation viewAnnotation;
3736
ast.Annotation componentAnnotation;
3837

3938
for (final annotation in unitMember.metadata) {
40-
if (isAngularAnnotation(annotation, 'View')) {
41-
viewAnnotation = annotation;
42-
} else if (isAngularAnnotation(annotation, 'Component')) {
39+
if (isAngularAnnotation(annotation, 'Component')) {
4340
componentAnnotation = annotation;
4441
}
4542
}
4643

47-
if (viewAnnotation == null && componentAnnotation == null) {
44+
if (componentAnnotation == null) {
4845
continue;
4946
}
5047

51-
//@TODO when there's both a @View and @Component, handle edge cases
52-
final view =
53-
_createView(classElement, viewAnnotation ?? componentAnnotation);
48+
final view = _createView(classElement, componentAnnotation);
5449

5550
if (view != null) {
5651
views.add(view);

angular_analyzer_plugin/test/abstract_angular.dart

-13
Original file line numberDiff line numberDiff line change
@@ -243,19 +243,6 @@ class Pipe {
243243
const Pipe(this.name, {bool pure});
244244
}
245245
246-
class View {
247-
final List<Object> directives;
248-
const View(
249-
{String templateUrl,
250-
String template,
251-
this.directives,
252-
dynamic pipes,
253-
ViewEncapsulation encapsulation,
254-
List<String> exports,
255-
List<String> styles,
256-
List<String> styleUrls});
257-
}
258-
259246
class Input {
260247
final String bindingPropertyName;
261248
const Input([this.bindingPropertyName]);

angular_analyzer_plugin/test/angular_driver_test.dart

+2-109
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,6 @@ class BuildStandardAngularTest extends AbstractAngularTest {
286286
expect(ng.elementRef, isNotNull);
287287
expect(ng.queryList, isNotNull);
288288
expect(ng.pipeTransform, isNotNull);
289-
expect(ng.view, isNotNull);
290289
expect(ng.component, isNotNull);
291290
}
292291

@@ -2000,42 +1999,13 @@ class MyComponent {}
20001999
errorListener.assertNoErrors();
20012000
}
20022001

2003-
// ignore: non_constant_identifier_names
2004-
Future test_directives_not_list_syntax_view() async {
2005-
final code = r'''
2006-
import 'package:angular2/angular2.dart';
2007-
2008-
@Directive(selector: '[aaa]')
2009-
class DirectiveA {}
2010-
2011-
@Directive(selector: '[bbb]')
2012-
class DirectiveB {}
2013-
2014-
const VARIABLE = const [DirectiveA, DirectiveB];
2015-
2016-
@Component(selector: 'my-component')
2017-
@View(template: 'My template', directives: VARIABLE)
2018-
class MyComponent {}
2019-
''';
2020-
final source = newSource('/test.dart', code);
2021-
await getViews(source);
2022-
final view = getViewByClassName(views, 'MyComponent');
2023-
expect(
2024-
view.directivesStrategy, const isInstanceOf<UseConstValueStrategy>());
2025-
final directiveClassNames =
2026-
view.directives.map((directive) => directive.name).toList();
2027-
expect(directiveClassNames, unorderedEquals(['DirectiveA', 'DirectiveB']));
2028-
// no errors
2029-
errorListener.assertNoErrors();
2030-
}
2031-
20322002
// ignore: non_constant_identifier_names
20332003
Future test_directives_not_list_syntax_errorWithinVariable() async {
20342004
final code = r'''
20352005
import 'package:angular2/angular2.dart';
20362006
2037-
@Component(selector: 'my-component')
2038-
@View(template: 'My template', directives: VARIABLE)
2007+
@Component(selector: 'my-component', template: 'My template',
2008+
directives: VARIABLE)
20392009
class MyComponent {}
20402010
20412011
// A non-array is a type error in the analyzer; a non-component in an array is
@@ -2213,20 +2183,6 @@ class MyComponent {}
22132183
<ErrorCode>[AngularWarningCode.TYPE_IS_NOT_A_DIRECTIVE]);
22142184
}
22152185

2216-
// ignore: non_constant_identifier_names
2217-
Future test_hasError_ComponentAnnotationMissing() async {
2218-
final source = newSource('/test.dart', r'''
2219-
import 'package:angular2/angular2.dart';
2220-
2221-
@View(template: 'AAA')
2222-
class ComponentA {
2223-
}
2224-
''');
2225-
await getViews(source);
2226-
errorListener.assertErrorsWithCodes(
2227-
<ErrorCode>[AngularWarningCode.COMPONENT_ANNOTATION_MISSING]);
2228-
}
2229-
22302186
// ignore: non_constant_identifier_names
22312187
Future test_hasError_StringValueExpected() async {
22322188
final source = newSource('/test.dart', r'''
@@ -2357,33 +2313,6 @@ class MyComponent {}
23572313
}
23582314
}
23592315

2360-
// ignore: non_constant_identifier_names
2361-
Future test_templateExternalUsingViewAnnotation() async {
2362-
final code = r'''
2363-
import 'package:angular2/angular2.dart';
2364-
2365-
@Component(selector: 'my-component')
2366-
@View(templateUrl: 'my-template.html')
2367-
class MyComponent {}
2368-
''';
2369-
final dartSource = newSource('/test.dart', code);
2370-
final htmlSource = newSource('/my-template.html', '');
2371-
await getViews(dartSource);
2372-
expect(views, hasLength(1));
2373-
// MyComponent
2374-
final view = getViewByClassName(views, 'MyComponent');
2375-
expect(view.component, getComponentByName(directives, 'MyComponent'));
2376-
expect(view.templateText, isNull);
2377-
expect(view.templateUriSource, isNotNull);
2378-
expect(view.templateUriSource, htmlSource);
2379-
expect(view.templateSource, htmlSource);
2380-
{
2381-
final url = "'my-template.html'";
2382-
expect(view.templateUrlRange,
2383-
new SourceRange(code.indexOf(url), url.length));
2384-
}
2385-
}
2386-
23872316
// ignore: non_constant_identifier_names
23882317
Future test_templateInline() async {
23892318
final code = r'''
@@ -2419,42 +2348,6 @@ class MyComponent {}
24192348
}
24202349
}
24212350

2422-
// ignore: non_constant_identifier_names
2423-
Future test_templateInlineUsingViewAnnotation() async {
2424-
final code = r'''
2425-
import 'package:angular2/angular2.dart';
2426-
2427-
@Directive(selector: 'my-directive')
2428-
class MyDirective {}
2429-
2430-
@Component(selector: 'other-component')
2431-
@View(template: 'Other template')
2432-
class OtherComponent {}
2433-
2434-
@Component(selector: 'my-component')
2435-
@View(template: 'My template', directives: const [MyDirective, OtherComponent])
2436-
class MyComponent {}
2437-
''';
2438-
final source = newSource('/test.dart', code);
2439-
await getViews(source);
2440-
expect(views, hasLength(2));
2441-
{
2442-
final view = getViewByClassName(views, 'MyComponent');
2443-
expect(view.component, getComponentByName(directives, 'MyComponent'));
2444-
expect(view.templateText, ' My template '); // spaces preserve offsets
2445-
expect(view.templateOffset, code.indexOf('My template') - 1);
2446-
expect(view.templateUriSource, isNull);
2447-
expect(view.templateSource, source);
2448-
{
2449-
expect(view.directives, hasLength(2));
2450-
final directiveClassNames =
2451-
view.directives.map((directive) => directive.name).toList();
2452-
expect(directiveClassNames,
2453-
unorderedEquals(['OtherComponent', 'MyDirective']));
2454-
}
2455-
}
2456-
}
2457-
24582351
// ignore: non_constant_identifier_names
24592352
Future test_useFunctionalDirective() async {
24602353
final code = r'''

angular_analyzer_plugin/test/navigation_test.dart

+6-9
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,14 @@ class AngularNavigationTest extends AbstractAngularTest {
7272
code = r'''
7373
import '/angular/src/core/metadata.dart';
7474
75-
@Component(selector: 'text-panel', inputs: const ['text: my-text'])
76-
@View(template: r"<div>some text</div>")
75+
@Component(selector: 'text-panel', inputs: const ['text: my-text'],
76+
template: r"<div>some text</div>")
7777
class TextPanel {
7878
String text; // 1
7979
@Input() longform; // 4
8080
}
8181
82-
@Component(selector: 'UserPanel')
83-
@View(template: r"""
82+
@Component(selector: 'UserPanel', template: r"""
8483
<div>
8584
<text-panel [my-text]='user.name' [longform]='""'></text-panel> // close
8685
</div>
@@ -126,7 +125,7 @@ class User {
126125
_findRegionString('my-text', ']=');
127126
expect(region.targetKind, protocol.ElementKind.UNKNOWN);
128127
expect(targetLocation.file, '/test.dart');
129-
expect(targetLocation.offset, code.indexOf("my-text'])"));
128+
expect(targetLocation.offset, code.indexOf("my-text'],"));
130129
}
131130
// template references field
132131
{
@@ -156,8 +155,7 @@ class User {
156155
code = r'''
157156
import 'package:angular/src/core/metadata.dart';
158157
159-
@Component(selector: 'text-panel')
160-
@View(templateUrl: 'text_panel.html')
158+
@Component(selector: 'text-panel', templateUrl: 'text_panel.html')
161159
class TextPanel {}
162160
''';
163161
final dartSource = newSource('/test.dart', code);
@@ -180,8 +178,7 @@ class TextPanel {}
180178
final dartCode = r'''
181179
import 'package:angular/src/core/metadata.dart';
182180
183-
@Component(selector: 'text-panel')
184-
@View(templateUrl: 'text_panel.html')
181+
@Component(selector: 'text-panel', templateUrl: 'text_panel.html')
185182
class TextPanel {
186183
String text; // 1
187184
}

0 commit comments

Comments
 (0)