Skip to content
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

refactor(compiler): remove obsolete @View-related code #9019

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
40 changes: 1 addition & 39 deletions modules/@angular/compiler/src/view_resolver.ts
Expand Up @@ -42,46 +42,18 @@ export class ViewResolver {
/** @internal */
_resolve(component: Type): ViewMetadata {
var compMeta: ComponentMetadata;
var viewMeta: ViewMetadata;

this._reflector.annotations(component).forEach(m => {
if (m instanceof ViewMetadata) {
viewMeta = m;
}
if (m instanceof ComponentMetadata) {
compMeta = m;
}
});

if (isPresent(compMeta)) {
if (isBlank(compMeta.template) && isBlank(compMeta.templateUrl) && isBlank(viewMeta)) {
if (isBlank(compMeta.template) && isBlank(compMeta.templateUrl)) {
throw new BaseException(
`Component '${stringify(component)}' must have either 'template' or 'templateUrl' set.`);

} else if (isPresent(compMeta.template) && isPresent(viewMeta)) {
this._throwMixingViewAndComponent("template", component);

} else if (isPresent(compMeta.templateUrl) && isPresent(viewMeta)) {
this._throwMixingViewAndComponent("templateUrl", component);

} else if (isPresent(compMeta.directives) && isPresent(viewMeta)) {
this._throwMixingViewAndComponent("directives", component);

} else if (isPresent(compMeta.pipes) && isPresent(viewMeta)) {
this._throwMixingViewAndComponent("pipes", component);

} else if (isPresent(compMeta.encapsulation) && isPresent(viewMeta)) {
this._throwMixingViewAndComponent("encapsulation", component);

} else if (isPresent(compMeta.styles) && isPresent(viewMeta)) {
this._throwMixingViewAndComponent("styles", component);

} else if (isPresent(compMeta.styleUrls) && isPresent(viewMeta)) {
this._throwMixingViewAndComponent("styleUrls", component);

} else if (isPresent(viewMeta)) {
return viewMeta;

} else {
return new ViewMetadata({
templateUrl: compMeta.templateUrl,
Expand All @@ -95,19 +67,9 @@ export class ViewResolver {
});
}
} else {
if (isBlank(viewMeta)) {
throw new BaseException(
`Could not compile '${stringify(component)}' because it is not a component.`);
} else {
return viewMeta;
}
}
return null;
}

/** @internal */
_throwMixingViewAndComponent(propertyName: string, component: Type): void {
throw new BaseException(
`Component '${stringify(component)}' cannot have both '${propertyName}' and '@View' set at the same time"`);
}
}
22 changes: 2 additions & 20 deletions modules/@angular/compiler/test/view_resolver_spec.ts
Expand Up @@ -5,16 +5,6 @@ import {Component, ViewMetadata} from '@angular/core/src/metadata';
class SomeDir {}
class SomePipe {}

@Component({
selector: 'sample',
template: "some template",
directives: [SomeDir],
pipes: [SomePipe],
styles: ["some styles"]
})
class ComponentWithView {
}

@Component({
selector: 'sample',
template: "some template",
Expand All @@ -25,14 +15,6 @@ class ComponentWithView {
class ComponentWithTemplate {
}

@Component({selector: 'sample', template: "some template"})
class ComponentWithViewTemplate {
}

@Component({selector: 'sample', templateUrl: "some template url", template: "some template"})
class ComponentWithViewTemplateUrl {
}

@Component({selector: 'sample'})
class ComponentWithoutView {
}
Expand All @@ -57,13 +39,13 @@ export function main() {
}));
});

it('should throw when Component has no View decorator and no template is set', () => {
it('should throw when Component has neither template nor templateUrl set', () => {
expect(() => resolver.resolve(ComponentWithoutView))
.toThrowErrorWith(
"Component 'ComponentWithoutView' must have either 'template' or 'templateUrl' set");
});

it('should throw when simple class has no View decorator and no template is set', () => {
it('should throw when simple class has no component decorator', () => {
expect(() => resolver.resolve(SimpleClass))
.toThrowErrorWith("Could not compile 'SimpleClass' because it is not a component.");
});
Expand Down