2016-06-23 16:47:54 +00:00
|
|
|
/**
|
|
|
|
|
* @license
|
|
|
|
|
* Copyright Google Inc. All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
|
|
|
* found in the LICENSE file at https://angular.io/license
|
|
|
|
|
*/
|
|
|
|
|
|
2016-04-29 00:50:03 +00:00
|
|
|
import {DirectiveResolver} from '@angular/compiler';
|
2016-09-13 02:14:17 +00:00
|
|
|
import {Directive, Type} from '@angular/core';
|
2015-08-06 20:19:29 +00:00
|
|
|
|
2017-01-13 22:36:16 +00:00
|
|
|
import {PropertyBinding} from '../common/component_info';
|
|
|
|
|
|
|
|
|
|
|
2016-11-12 13:08:58 +00:00
|
|
|
const COMPONENT_SELECTOR = /^[\w|-]*$/;
|
|
|
|
|
const SKEWER_CASE = /-(\w)/g;
|
|
|
|
|
const directiveResolver = new DirectiveResolver();
|
2015-08-06 20:19:29 +00:00
|
|
|
|
2015-10-01 20:14:59 +00:00
|
|
|
export interface ComponentInfo {
|
2016-08-11 01:21:28 +00:00
|
|
|
type: Type<any>;
|
2015-10-01 20:14:59 +00:00
|
|
|
selector: string;
|
2017-01-13 22:36:16 +00:00
|
|
|
inputs?: PropertyBinding[];
|
|
|
|
|
outputs?: PropertyBinding[];
|
2015-10-01 20:14:59 +00:00
|
|
|
}
|
|
|
|
|
|
2016-08-11 01:21:28 +00:00
|
|
|
export function getComponentInfo(type: Type<any>): ComponentInfo {
|
2016-11-12 13:08:58 +00:00
|
|
|
const resolvedMetadata: Directive = directiveResolver.resolve(type);
|
2017-01-13 22:36:16 +00:00
|
|
|
const selector = resolvedMetadata.selector;
|
|
|
|
|
|
2015-10-01 20:14:59 +00:00
|
|
|
return {
|
2017-01-13 22:36:16 +00:00
|
|
|
type,
|
|
|
|
|
selector,
|
2015-10-01 20:14:59 +00:00
|
|
|
inputs: parseFields(resolvedMetadata.inputs),
|
|
|
|
|
outputs: parseFields(resolvedMetadata.outputs)
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-13 22:36:16 +00:00
|
|
|
export function parseFields(bindings: string[]): PropertyBinding[] {
|
|
|
|
|
return (bindings || []).map(binding => new PropertyBinding(binding));
|
2015-08-06 20:19:29 +00:00
|
|
|
}
|