refactor(compiler): simplify metadata
This commit is contained in:
parent
3468f7cfd5
commit
0f4eb1b524
|
@ -1,3 +1,4 @@
|
|||
import {isPresent} from 'angular2/src/core/facade/lang';
|
||||
import {HtmlAst} from './html_ast';
|
||||
|
||||
export class TypeMeta {
|
||||
|
@ -54,18 +55,18 @@ export enum ViewEncapsulation {
|
|||
|
||||
export class DirectiveMetadata {
|
||||
type: TypeMeta;
|
||||
isComponent: boolean;
|
||||
selector: string;
|
||||
constructor({type, selector}: {type?: TypeMeta, selector?: string} = {}) {
|
||||
this.type = type;
|
||||
this.selector = selector;
|
||||
}
|
||||
}
|
||||
|
||||
export class ComponentMetadata extends DirectiveMetadata {
|
||||
template: TemplateMeta;
|
||||
constructor({type, selector, template}:
|
||||
{type?: TypeMeta, selector?: string, template?: TemplateMeta}) {
|
||||
super({type: type, selector: selector});
|
||||
constructor({type, isComponent, selector, template}: {
|
||||
type?: TypeMeta,
|
||||
isComponent?: boolean,
|
||||
selector?: string,
|
||||
template?: TemplateMeta
|
||||
} = {}) {
|
||||
this.type = type;
|
||||
this.isComponent = isPresent(isComponent) ? isComponent : false;
|
||||
this.selector = selector;
|
||||
this.template = template;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ import {
|
|||
|
||||
import {Parser, AST, ASTWithSource} from 'angular2/src/core/change_detection/change_detection';
|
||||
|
||||
import {DirectiveMetadata, ComponentMetadata} from './api';
|
||||
import {DirectiveMetadata} from './api';
|
||||
import {
|
||||
ElementAst,
|
||||
BoundPropertyAst,
|
||||
|
@ -279,8 +279,8 @@ class TemplateParseVisitor implements HtmlAstVisitor {
|
|||
// as selectorMatcher uses Maps inside.
|
||||
// Also need to make components the first directive in the array
|
||||
ListWrapper.sort(directives, (dir1: DirectiveMetadata, dir2: DirectiveMetadata) => {
|
||||
var dir1Comp = dir1 instanceof ComponentMetadata;
|
||||
var dir2Comp = dir2 instanceof ComponentMetadata;
|
||||
var dir1Comp = dir1.isComponent;
|
||||
var dir2Comp = dir2.isComponent;
|
||||
if (dir1Comp && !dir2Comp) {
|
||||
return -1;
|
||||
} else if (!dir1Comp && dir2Comp) {
|
||||
|
|
|
@ -3,7 +3,7 @@ import {ddescribe, describe, it, iit, xit, expect, beforeEach, afterEach} from '
|
|||
import {Parser, Lexer} from 'angular2/src/core/change_detection/change_detection';
|
||||
import {TemplateParser, splitClasses} from 'angular2/src/compiler/template_parser';
|
||||
import {HtmlParser} from 'angular2/src/compiler/html_parser';
|
||||
import {DirectiveMetadata, ComponentMetadata, TypeMeta} from 'angular2/src/compiler/api';
|
||||
import {DirectiveMetadata, TypeMeta} from 'angular2/src/compiler/api';
|
||||
import {
|
||||
templateVisitAll,
|
||||
TemplateAstVisitor,
|
||||
|
@ -192,8 +192,8 @@ export function main() {
|
|||
new DirectiveMetadata({selector: '[a=b]', type: new TypeMeta({typeName: 'DirA'})});
|
||||
var dirB =
|
||||
new DirectiveMetadata({selector: '[a]', type: new TypeMeta({typeName: 'DirB'})});
|
||||
var comp =
|
||||
new ComponentMetadata({selector: 'div', type: new TypeMeta({typeName: 'ZComp'})});
|
||||
var comp = new DirectiveMetadata(
|
||||
{selector: 'div', isComponent: true, type: new TypeMeta({typeName: 'ZComp'})});
|
||||
expect(humanizeTemplateAsts(parse('<div a="b">', [dirB, dirA, comp])))
|
||||
.toEqual([
|
||||
[ElementAst, [comp, dirA, dirB], 'TestComp > div:nth-child(0)'],
|
||||
|
|
Loading…
Reference in New Issue