refactor: code cleanup
This commit is contained in:
parent
9af2d8b810
commit
93d0a01d3d
|
@ -7,12 +7,10 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {NgClass, NgFor} from '@angular/common';
|
import {NgClass, NgFor} from '@angular/common';
|
||||||
import {Component, provide} from '@angular/core';
|
import {Component} from '@angular/core';
|
||||||
import {ComponentFixture, TestComponentBuilder} from '@angular/core/testing';
|
import {ComponentFixture, TestComponentBuilder} from '@angular/core/testing';
|
||||||
import {beforeEach, beforeEachProviders, ddescribe, describe, expect, iit, inject, it, xdescribe, xit} from '@angular/core/testing/testing_internal';
|
import {AsyncTestCompleter, beforeEach, beforeEachProviders, ddescribe, describe, expect, iit, inject, it, xdescribe, xit} from '@angular/core/testing/testing_internal';
|
||||||
import {AsyncTestCompleter} from '@angular/core/testing/testing_internal';
|
import {ListWrapper, StringMapWrapper} from '../../src/facade/collection';
|
||||||
|
|
||||||
import {ListWrapper, SetWrapper, StringMapWrapper} from '../../src/facade/collection';
|
|
||||||
|
|
||||||
function detectChangesAndCheck(fixture: ComponentFixture<any>, classes: string) {
|
function detectChangesAndCheck(fixture: ComponentFixture<any>, classes: string) {
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
|
|
@ -7,14 +7,13 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {ComponentMetadata, DirectiveMetadata, HostBindingMetadata, HostListenerMetadata, Injectable, InputMetadata, OutputMetadata, QueryMetadata, resolveForwardRef} from '@angular/core';
|
import {ComponentMetadata, DirectiveMetadata, HostBindingMetadata, HostListenerMetadata, Injectable, InputMetadata, OutputMetadata, QueryMetadata, resolveForwardRef} from '@angular/core';
|
||||||
|
|
||||||
import {ReflectorReader, reflector} from '../core_private';
|
import {ReflectorReader, reflector} from '../core_private';
|
||||||
import {ListWrapper, StringMapWrapper} from '../src/facade/collection';
|
import {ListWrapper, StringMapWrapper} from '../src/facade/collection';
|
||||||
import {BaseException} from '../src/facade/exceptions';
|
import {BaseException} from '../src/facade/exceptions';
|
||||||
import {Type, isPresent, stringify} from '../src/facade/lang';
|
import {Type, isPresent, stringify} from '../src/facade/lang';
|
||||||
|
|
||||||
|
|
||||||
function _isDirectiveMetadata(type: any): boolean {
|
function _isDirectiveMetadata(type: any): type is DirectiveMetadata {
|
||||||
return type instanceof DirectiveMetadata;
|
return type instanceof DirectiveMetadata;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -142,5 +141,3 @@ export class DirectiveResolver {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export var CODEGEN_DIRECTIVE_RESOLVER = new DirectiveResolver(reflector);
|
|
||||||
|
|
|
@ -21,12 +21,8 @@ export function camelCaseToDashCase(input: string): string {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function splitAtColon(input: string, defaultValues: string[]): string[] {
|
export function splitAtColon(input: string, defaultValues: string[]): string[] {
|
||||||
var parts = StringWrapper.split(input.trim(), /\s*:\s*/g);
|
var parts = input.split(':', 2).map((s: string) => s.trim());
|
||||||
if (parts.length > 1) {
|
return parts.length > 1 ? parts : defaultValues;
|
||||||
return parts;
|
|
||||||
} else {
|
|
||||||
return defaultValues;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function sanitizeIdentifier(name: string): string {
|
export function sanitizeIdentifier(name: string): string {
|
||||||
|
|
|
@ -7,12 +7,13 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {Injectable, ViewMetadata, ComponentMetadata,} from '@angular/core';
|
import {Injectable, ViewMetadata, ComponentMetadata,} from '@angular/core';
|
||||||
|
|
||||||
import {ReflectorReader, reflector} from '../core_private';
|
import {ReflectorReader, reflector} from '../core_private';
|
||||||
|
|
||||||
import {Type, stringify, isBlank, isPresent} from '../src/facade/lang';
|
import {Type, stringify, isBlank, isPresent} from '../src/facade/lang';
|
||||||
import {BaseException} from '../src/facade/exceptions';
|
import {BaseException} from '../src/facade/exceptions';
|
||||||
import {Map} from '../src/facade/collection';
|
|
||||||
|
function _isComponentMetadata(obj: any): obj is ComponentMetadata {
|
||||||
|
return obj instanceof ComponentMetadata;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resolves types to {@link ViewMetadata}.
|
* Resolves types to {@link ViewMetadata}.
|
||||||
|
@ -22,13 +23,8 @@ export class ViewResolver {
|
||||||
constructor(private _reflector: ReflectorReader = reflector) {}
|
constructor(private _reflector: ReflectorReader = reflector) {}
|
||||||
|
|
||||||
resolve(component: Type): ViewMetadata {
|
resolve(component: Type): ViewMetadata {
|
||||||
var compMeta: ComponentMetadata;
|
const compMeta: ComponentMetadata =
|
||||||
|
this._reflector.annotations(component).find(_isComponentMetadata);
|
||||||
this._reflector.annotations(component).forEach(m => {
|
|
||||||
if (m instanceof ComponentMetadata) {
|
|
||||||
compMeta = m;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if (isPresent(compMeta)) {
|
if (isPresent(compMeta)) {
|
||||||
if (isBlank(compMeta.template) && isBlank(compMeta.templateUrl)) {
|
if (isBlank(compMeta.template) && isBlank(compMeta.templateUrl)) {
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {DirectiveResolver} from '@angular/compiler/src/directive_resolver';
|
import {DirectiveResolver} from '@angular/compiler/src/directive_resolver';
|
||||||
import {ContentChild, ContentChildMetadata, ContentChildren, ContentChildrenMetadata, Directive, DirectiveMetadata, HostBinding, HostListener, Input, Output, ViewChild, ViewChildMetadata, ViewChildren, ViewChildrenMetadata} from '@angular/core/src/metadata';
|
import {ContentChild, ContentChildren, Directive, DirectiveMetadata, HostBinding, HostListener, Input, Output, ViewChild, ViewChildren} from '@angular/core/src/metadata';
|
||||||
|
|
||||||
@Directive({selector: 'someDirective'})
|
@Directive({selector: 'someDirective'})
|
||||||
class SomeDirective {
|
class SomeDirective {
|
||||||
|
@ -19,49 +19,47 @@ class SomeChildDirective extends SomeDirective {
|
||||||
|
|
||||||
@Directive({selector: 'someDirective', inputs: ['c']})
|
@Directive({selector: 'someDirective', inputs: ['c']})
|
||||||
class SomeDirectiveWithInputs {
|
class SomeDirectiveWithInputs {
|
||||||
@Input() a: any /** TODO #9100 */;
|
@Input() a: any;
|
||||||
@Input('renamed') b: any /** TODO #9100 */;
|
@Input('renamed') b: any;
|
||||||
c: any /** TODO #9100 */;
|
c: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Directive({selector: 'someDirective', outputs: ['c']})
|
@Directive({selector: 'someDirective', outputs: ['c']})
|
||||||
class SomeDirectiveWithOutputs {
|
class SomeDirectiveWithOutputs {
|
||||||
@Output() a: any /** TODO #9100 */;
|
@Output() a: any;
|
||||||
@Output('renamed') b: any /** TODO #9100 */;
|
@Output('renamed') b: any;
|
||||||
c: any /** TODO #9100 */;
|
c: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Directive({selector: 'someDirective', outputs: ['a']})
|
@Directive({selector: 'someDirective', outputs: ['a']})
|
||||||
class SomeDirectiveWithDuplicateOutputs {
|
class SomeDirectiveWithDuplicateOutputs {
|
||||||
@Output() a: any /** TODO #9100 */;
|
@Output() a: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Directive({selector: 'someDirective', properties: ['a']})
|
@Directive({selector: 'someDirective', outputs: ['localA: a']})
|
||||||
class SomeDirectiveWithProperties {
|
class SomeDirectiveWithDuplicateRenamedOutputs {
|
||||||
}
|
@Output() a: any;
|
||||||
|
localA: any;
|
||||||
@Directive({selector: 'someDirective', events: ['a']})
|
|
||||||
class SomeDirectiveWithEvents {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Directive({selector: 'someDirective'})
|
@Directive({selector: 'someDirective'})
|
||||||
class SomeDirectiveWithSetterProps {
|
class SomeDirectiveWithSetterProps {
|
||||||
@Input('renamed')
|
@Input('renamed')
|
||||||
set a(value: any /** TODO #9100 */) {}
|
set a(value: any) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Directive({selector: 'someDirective'})
|
@Directive({selector: 'someDirective'})
|
||||||
class SomeDirectiveWithGetterOutputs {
|
class SomeDirectiveWithGetterOutputs {
|
||||||
@Output('renamed')
|
@Output('renamed')
|
||||||
get a(): any /** TODO #9100 */ { return null; }
|
get a(): any { return null; }
|
||||||
}
|
}
|
||||||
|
|
||||||
@Directive({selector: 'someDirective', host: {'[c]': 'c'}})
|
@Directive({selector: 'someDirective', host: {'[c]': 'c'}})
|
||||||
class SomeDirectiveWithHostBindings {
|
class SomeDirectiveWithHostBindings {
|
||||||
@HostBinding() a: any /** TODO #9100 */;
|
@HostBinding() a: any;
|
||||||
@HostBinding('renamed') b: any /** TODO #9100 */;
|
@HostBinding('renamed') b: any;
|
||||||
c: any /** TODO #9100 */;
|
c: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Directive({selector: 'someDirective', host: {'(c)': 'onC()'}})
|
@Directive({selector: 'someDirective', host: {'(c)': 'onC()'}})
|
||||||
|
@ -69,31 +67,31 @@ class SomeDirectiveWithHostListeners {
|
||||||
@HostListener('a')
|
@HostListener('a')
|
||||||
onA() {}
|
onA() {}
|
||||||
@HostListener('b', ['$event.value'])
|
@HostListener('b', ['$event.value'])
|
||||||
onB(value: any /** TODO #9100 */) {}
|
onB(value: any) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Directive({selector: 'someDirective', queries: {'cs': new ContentChildren('c')}})
|
@Directive({selector: 'someDirective', queries: {'cs': new ContentChildren('c')}})
|
||||||
class SomeDirectiveWithContentChildren {
|
class SomeDirectiveWithContentChildren {
|
||||||
@ContentChildren('a') as: any;
|
@ContentChildren('a') as: any;
|
||||||
c: any /** TODO #9100 */;
|
c: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Directive({selector: 'someDirective', queries: {'cs': new ViewChildren('c')}})
|
@Directive({selector: 'someDirective', queries: {'cs': new ViewChildren('c')}})
|
||||||
class SomeDirectiveWithViewChildren {
|
class SomeDirectiveWithViewChildren {
|
||||||
@ViewChildren('a') as: any;
|
@ViewChildren('a') as: any;
|
||||||
c: any /** TODO #9100 */;
|
c: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Directive({selector: 'someDirective', queries: {'c': new ContentChild('c')}})
|
@Directive({selector: 'someDirective', queries: {'c': new ContentChild('c')}})
|
||||||
class SomeDirectiveWithContentChild {
|
class SomeDirectiveWithContentChild {
|
||||||
@ContentChild('a') a: any;
|
@ContentChild('a') a: any;
|
||||||
c: any /** TODO #9100 */;
|
c: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Directive({selector: 'someDirective', queries: {'c': new ViewChild('c')}})
|
@Directive({selector: 'someDirective', queries: {'c': new ViewChild('c')}})
|
||||||
class SomeDirectiveWithViewChild {
|
class SomeDirectiveWithViewChild {
|
||||||
@ViewChild('a') a: any;
|
@ViewChild('a') a: any;
|
||||||
c: any /** TODO #9100 */;
|
c: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
class SomeDirectiveWithoutMetadata {}
|
class SomeDirectiveWithoutMetadata {}
|
||||||
|
|
|
@ -45,7 +45,7 @@ import {Router} from '../router';
|
||||||
*/
|
*/
|
||||||
@Directive({
|
@Directive({
|
||||||
selector: '[routerLink]',
|
selector: '[routerLink]',
|
||||||
inputs: ['routeParams: routerLink', 'target: target'],
|
inputs: ['routeParams: routerLink', 'target'],
|
||||||
host: {
|
host: {
|
||||||
'(click)': 'onClick()',
|
'(click)': 'onClick()',
|
||||||
'[attr.href]': 'visibleHref',
|
'[attr.href]': 'visibleHref',
|
||||||
|
|
Loading…
Reference in New Issue