docs(*): Document a lot more symbols that are missing comments in our generated docs.

This commit is contained in:
Alex Rickabaugh
2015-12-03 15:49:09 -08:00
parent 5a04ffec3e
commit 80a5e47e61
65 changed files with 793 additions and 22 deletions

View File

@ -31,6 +31,10 @@ function _createChangeDetectorGenConfig() {
return new ChangeDetectorGenConfig(assertionsEnabled(), false, true);
}
/**
* A set of providers that provide `RuntimeCompiler` and its dependencies to use for
* template compilation.
*/
export const COMPILER_PROVIDERS: Array<Type | Provider | any[]> = CONST_EXPR([
Lexer,
Parser,

View File

@ -21,6 +21,9 @@ import {LifecycleHooks, LIFECYCLE_HOOKS_VALUES} from 'angular2/src/core/linker/i
// group 2: "event" from "(event)"
var HOST_REG_EXP = /^(?:(?:\[([^\]]+)\])|(?:\(([^\)]+)\)))$/g;
/**
* Metadata regarding compilation of a type.
*/
export class CompileTypeMetadata {
runtime: Type;
name: string;
@ -49,6 +52,9 @@ export class CompileTypeMetadata {
}
}
/**
* Metadata regarding compilation of a template.
*/
export class CompileTemplateMetadata {
encapsulation: ViewEncapsulation;
template: string;
@ -98,6 +104,9 @@ export class CompileTemplateMetadata {
}
}
/**
* Metadata regarding compilation of a directive.
*/
export class CompileDirectiveMetadata {
static create({type, isComponent, dynamicLoadable, selector, exportAs, changeDetection, inputs,
outputs, host, lifecycleHooks, template}: {
@ -250,6 +259,9 @@ export class CompileDirectiveMetadata {
}
}
/**
* Construct {@link CompileDirectiveMetadata} from {@link ComponentTypeMetadata} and a selector.
*/
export function createHostComponentMeta(componentType: CompileTypeMetadata,
componentSelector: string): CompileDirectiveMetadata {
var template = CssSelector.parse(componentSelector)[0].getMatchingElementTemplate();

View File

@ -6,6 +6,9 @@ export function moduleRef(moduleUrl): string {
return `#MODULE[${moduleUrl}]`;
}
/**
* Represents generated source code with module references. Internal to the Angular compiler.
*/
export class SourceModule {
constructor(public moduleUrl: string, public sourceWithModuleRefs: string) {}
@ -39,6 +42,9 @@ export class SourceExpressions {
constructor(public declarations: string[], public expressions: string[]) {}
}
/**
* Represents generated source code with imports. Internal to the Angular compiler.
*/
export class SourceWithImports {
constructor(public source: string, public imports: string[][]) {}
}

View File

@ -3,17 +3,33 @@ import {isPresent} from 'angular2/src/facade/lang';
import {CompileDirectiveMetadata} from './directive_metadata';
import {ParseSourceSpan} from './parse_util';
/**
* An Abstract Syntax Tree node representing part of a parsed Angular template.
*/
export interface TemplateAst {
/**
* The source span from which this node was parsed.
*/
sourceSpan: ParseSourceSpan;
/**
* Visit this node and possibly transform it.
*/
visit(visitor: TemplateAstVisitor, context: any): any;
}
/**
* A segment of text within the template.
*/
export class TextAst implements TemplateAst {
constructor(public value: string, public ngContentIndex: number,
public sourceSpan: ParseSourceSpan) {}
visit(visitor: TemplateAstVisitor, context: any): any { return visitor.visitText(this, context); }
}
/**
* A bound expression within the text of a template.
*/
export class BoundTextAst implements TemplateAst {
constructor(public value: AST, public ngContentIndex: number,
public sourceSpan: ParseSourceSpan) {}
@ -22,11 +38,17 @@ export class BoundTextAst implements TemplateAst {
}
}
/**
* A plain attribute on an element.
*/
export class AttrAst implements TemplateAst {
constructor(public name: string, public value: string, public sourceSpan: ParseSourceSpan) {}
visit(visitor: TemplateAstVisitor, context: any): any { return visitor.visitAttr(this, context); }
}
/**
* A binding for an element property (e.g. `[property]="expression"`).
*/
export class BoundElementPropertyAst implements TemplateAst {
constructor(public name: string, public type: PropertyBindingType, public value: AST,
public unit: string, public sourceSpan: ParseSourceSpan) {}
@ -35,6 +57,9 @@ export class BoundElementPropertyAst implements TemplateAst {
}
}
/**
* A binding for an element event (e.g. `(event)="handler()"`).
*/
export class BoundEventAst implements TemplateAst {
constructor(public name: string, public target: string, public handler: AST,
public sourceSpan: ParseSourceSpan) {}
@ -50,6 +75,9 @@ export class BoundEventAst implements TemplateAst {
}
}
/**
* A variable declaration on an element (e.g. `#var="expression"`).
*/
export class VariableAst implements TemplateAst {
constructor(public name: string, public value: string, public sourceSpan: ParseSourceSpan) {}
visit(visitor: TemplateAstVisitor, context: any): any {
@ -57,6 +85,9 @@ export class VariableAst implements TemplateAst {
}
}
/**
* An element declaration in a template.
*/
export class ElementAst implements TemplateAst {
constructor(public name: string, public attrs: AttrAst[],
public inputs: BoundElementPropertyAst[], public outputs: BoundEventAst[],
@ -67,11 +98,17 @@ export class ElementAst implements TemplateAst {
return visitor.visitElement(this, context);
}
/**
* Whether the element has any active bindings (inputs, outputs, vars, or directives).
*/
isBound(): boolean {
return (this.inputs.length > 0 || this.outputs.length > 0 || this.exportAsVars.length > 0 ||
this.directives.length > 0);
}
/**
* Get the component associated with this element, if any.
*/
getComponent(): CompileDirectiveMetadata {
return this.directives.length > 0 && this.directives[0].directive.isComponent ?
this.directives[0].directive :
@ -79,6 +116,9 @@ export class ElementAst implements TemplateAst {
}
}
/**
* A `<template>` element included in an Angular template.
*/
export class EmbeddedTemplateAst implements TemplateAst {
constructor(public attrs: AttrAst[], public outputs: BoundEventAst[], public vars: VariableAst[],
public directives: DirectiveAst[], public children: TemplateAst[],
@ -88,6 +128,9 @@ export class EmbeddedTemplateAst implements TemplateAst {
}
}
/**
* A directive property with a bound value (e.g. `*ngIf="condition").
*/
export class BoundDirectivePropertyAst implements TemplateAst {
constructor(public directiveName: string, public templateName: string, public value: AST,
public sourceSpan: ParseSourceSpan) {}
@ -96,6 +139,9 @@ export class BoundDirectivePropertyAst implements TemplateAst {
}
}
/**
* A directive declared on an element.
*/
export class DirectiveAst implements TemplateAst {
constructor(public directive: CompileDirectiveMetadata,
public inputs: BoundDirectivePropertyAst[],
@ -106,6 +152,9 @@ export class DirectiveAst implements TemplateAst {
}
}
/**
* Position where content is to be projected (instance of `<ng-content>` in a template).
*/
export class NgContentAst implements TemplateAst {
constructor(public index: number, public ngContentIndex: number,
public sourceSpan: ParseSourceSpan) {}
@ -114,13 +163,35 @@ export class NgContentAst implements TemplateAst {
}
}
/**
* Enumeration of types of property bindings.
*/
export enum PropertyBindingType {
/**
* A normal binding to a property (e.g. `[property]="expression"`).
*/
Property,
/**
* A binding to an element attribute (e.g. `[attr.name]="expression"`).
*/
Attribute,
/**
* A binding to a CSS class (e.g. `[class.name]="condition"`).
*/
Class,
/**
* A binding to a style rule (e.g. `[style.rule]="expression"`).
*/
Style
}
/**
* A visitor for {@link TemplateAst} trees that will process each node.
*/
export interface TemplateAstVisitor {
visitNgContent(ast: NgContentAst, context: any): any;
visitEmbeddedTemplate(ast: EmbeddedTemplateAst, context: any): any;
@ -135,7 +206,9 @@ export interface TemplateAstVisitor {
visitDirectiveProperty(ast: BoundDirectivePropertyAst, context: any): any;
}
/**
* Visit every node in a list of {@link TemplateAst}s with the given {@link TemplateAstVisitor}.
*/
export function templateVisitAll(visitor: TemplateAstVisitor, asts: TemplateAst[],
context: any = null): any[] {
var result = [];

View File

@ -32,6 +32,11 @@ import {
MODULE_SUFFIX
} from './util';
/**
* An internal module of the Angular compiler that begins with component types,
* extracts templates, and eventually produces a compiled version of the component
* ready for linking into an application.
*/
@Injectable()
export class TemplateCompiler {
private _hostCacheKeys = new Map<Type, any>();

View File

@ -69,6 +69,13 @@ const STYLE_PREFIX = 'style';
var TEXT_CSS_SELECTOR = CssSelector.parse('*')[0];
/**
* Provides an array of {@link TemplateAstVisitor}s which will be used to transform
* parsed templates before compilation is invoked, allowing custom expression syntax
* and other advanced transformations.
*
* This is currently an internal-only feature and not meant for general use.
*/
export const TEMPLATE_TRANSFORMS = CONST_EXPR(new OpaqueToken('TemplateTransforms'));
export class TemplateParseError extends ParseError {

View File

@ -11,18 +11,28 @@ import {ListWrapper} from 'angular2/src/facade/collection';
import {PACKAGE_ROOT_URL} from 'angular2/src/core/application_tokens';
import {Provider} from 'angular2/src/core/di';
/**
* Create a {@link UrlResolver} with no package prefix.
*/
export function createWithoutPackagePrefix(): UrlResolver {
return new UrlResolver();
}
/**
* A default provider for {@link PACKAGE_ROOT_URL} that maps to '/'.
*/
export var DEFAULT_PACKAGE_URL_PROVIDER = new Provider(PACKAGE_ROOT_URL, {useValue: "/"});
/**
* Used by the {@link Compiler} when resolving HTML and CSS template URLs.
*
* This interface can be overridden by the application developer to create custom behavior.
* This class can be overridden by the application developer to create custom behavior.
*
* See {@link Compiler}
*
* ## Example
*
* {@example compiler/ts/url_resolver/url_resolver.ts region='url_resolver'}
*/
@Injectable()
export class UrlResolver {
@ -58,6 +68,9 @@ export class UrlResolver {
}
}
/**
* Extract the scheme of a URL.
*/
export function getUrlScheme(url: string): string {
var match = _split(url);
return (match && match[_ComponentIndex.Scheme]) || "";

View File

@ -1,6 +1,10 @@
import {Promise} from 'angular2/src/facade/async';
// TODO: vsavkin rename it into TemplateLoader
/**
* An interface for retrieving documents by URL that the compiler uses
* to load templates.
*/
export class XHR {
get(url: string): Promise<string> { return null; }
}

View File

@ -4,6 +4,10 @@ import {isBlank, isPresent, normalizeBlank} from 'angular2/src/facade/lang';
import {BaseException, WrappedException} from 'angular2/src/facade/exceptions';
import {PromiseCompleter, PromiseWrapper, Promise} from 'angular2/src/facade/async';
/**
* A mock implemenation of {@link XHR} that allows outgoing requests to be mocked
* and responded to within a single test, without going to the network.
*/
export class MockXHR extends XHR {
private _expectations: _Expectation[] = [];
private _definitions = new Map<string, string>();
@ -15,13 +19,30 @@ export class MockXHR extends XHR {
return request.getPromise();
}
/**
* Add an expectation for the given URL. Incoming requests will be checked against
* the next expectation (in FIFO order). The `verifyNoOutstandingExpectations` method
* can be used to check if any expectations have not yet been met.
*
* The response given will be returned if the expectation matches.
*/
expect(url: string, response: string) {
var expectation = new _Expectation(url, response);
this._expectations.push(expectation);
}
/**
* Add a definition for the given URL to return the given response. Unlike expectations,
* definitions have no order and will satisfy any matching request at any time. Also
* unlike expectations, unused definitions do not cause `verifyNoOutstandingExpectations`
* to return an error.
*/
when(url: string, response: string) { this._definitions.set(url, response); }
/**
* Process pending requests and verify there are no outstanding expectations. Also fails
* if no requests are pending.
*/
flush() {
if (this._requests.length === 0) {
throw new BaseException('No pending requests to flush');
@ -34,6 +55,9 @@ export class MockXHR extends XHR {
this.verifyNoOutstandingExpectations();
}
/**
* Throw an exception if any expectations have not been satisfied.
*/
verifyNoOutstandingExpectations() {
if (this._expectations.length === 0) return;