From 80a5e47e61241c2287b162d609f117ea6ae00515 Mon Sep 17 00:00:00 2001 From: Alex Rickabaugh Date: Thu, 3 Dec 2015 15:49:09 -0800 Subject: [PATCH] docs(*): Document a lot more symbols that are missing comments in our generated docs. --- .../common/forms/ts/validators/validators.ts | 30 +++++++ .../compiler/ts/url_resolver/url_resolver.ts | 19 +++++ .../debug/ts/debug_element/debug_element.ts | 16 ++++ .../examples/platform/dom/debug/ts/by/by.ts | 17 ++++ .../debug_element_view_listener/providers.ts | 10 +++ .../examples/testing/ts/fake_async.ts | 29 +++++++ .../angular2/examples/testing/ts/matchers.ts | 40 ++++++++++ modules/angular2/http.ts | 4 + modules/angular2/router.ts | 2 + .../common/directives/observable_list_diff.ts | 5 ++ .../directives/control_value_accessor.ts | 5 ++ .../forms/directives/ng_control_status.ts | 4 + .../src/common/forms/directives/validators.ts | 24 ++++++ .../angular2/src/common/forms/form_builder.ts | 2 + .../angular2/src/common/forms/validators.ts | 4 +- modules/angular2/src/common/pipes.ts | 7 ++ .../angular2/src/common/pipes/common_pipes.ts | 7 ++ modules/angular2/src/compiler/compiler.ts | 4 + .../src/compiler/directive_metadata.ts | 12 +++ .../angular2/src/compiler/source_module.ts | 6 ++ modules/angular2/src/compiler/template_ast.ts | 75 +++++++++++++++++- .../src/compiler/template_compiler.ts | 5 ++ .../angular2/src/compiler/template_parser.ts | 7 ++ modules/angular2/src/compiler/url_resolver.ts | 15 +++- modules/angular2/src/compiler/xhr.ts | 4 + modules/angular2/src/compiler/xhr_mock.ts | 24 ++++++ .../change_detection/change_detection_util.ts | 7 +- .../change_detection/change_detector_ref.ts | 2 +- .../src/core/change_detection/constants.ts | 13 ++++ .../differs/iterable_differs.ts | 4 + .../differs/keyvalue_differs.ts | 3 + .../angular2/src/core/debug/debug_element.ts | 59 +++++++++++++- modules/angular2/src/core/di/provider.ts | 11 ++- .../src/core/linker/component_url_mapper.ts | 8 +- modules/angular2/src/core/linker/view_ref.ts | 2 +- .../angular2/src/core/linker/view_resolver.ts | 3 + modules/angular2/src/core/metadata.ts | 12 +++ modules/angular2/src/core/profile/wtf_impl.ts | 3 + .../src/core/reflection/reflection.ts | 4 + .../angular2/src/core/reflection/reflector.ts | 7 ++ modules/angular2/src/core/render/api.ts | 33 +++++++- .../src/core/testability/testability.ts | 10 +++ modules/angular2/src/core/zone/ng_zone.ts | 6 ++ modules/angular2/src/facade/collection.ts | 4 + modules/angular2/src/facade/exceptions.ts | 3 + modules/angular2/src/facade/lang.ts | 4 + .../angular2/src/http/backends/browser_xhr.ts | 6 +- .../src/http/backends/jsonp_backend.ts | 22 ++++++ modules/angular2/src/http/http.ts | 2 +- .../src/mock/directive_resolver_mock.ts | 4 + modules/angular2/src/mock/location_mock.ts | 3 + .../angular2/src/mock/mock_application_ref.ts | 3 + .../src/mock/mock_location_strategy.ts | 4 + modules/angular2/src/mock/ng_zone_mock.ts | 3 + .../src/platform/browser/browser_adapter.ts | 3 + .../angular2/src/platform/browser_common.ts | 10 +++ modules/angular2/src/platform/dom/debug/by.ts | 27 ++++++- .../dom/debug/debug_element_view_listener.ts | 12 +++ .../src/router/route_config_decorator.ts | 7 ++ .../angular2/src/router/route_definition.ts | 6 ++ modules/angular2/src/testing/fake_async.ts | 19 ++++- modules/angular2/src/testing/matchers.ts | 78 ++++++++++++++++++- modules/angular2/src/testing/test_injector.ts | 14 +++- modules/angular2/src/testing/testing.ts | 14 +++- .../angular2/src/testing/testing_internal.ts | 3 + 65 files changed, 793 insertions(+), 22 deletions(-) create mode 100644 modules/angular2/examples/common/forms/ts/validators/validators.ts create mode 100644 modules/angular2/examples/compiler/ts/url_resolver/url_resolver.ts create mode 100644 modules/angular2/examples/core/debug/ts/debug_element/debug_element.ts create mode 100644 modules/angular2/examples/platform/dom/debug/ts/by/by.ts create mode 100644 modules/angular2/examples/platform/dom/debug/ts/debug_element_view_listener/providers.ts create mode 100644 modules/angular2/examples/testing/ts/fake_async.ts create mode 100644 modules/angular2/examples/testing/ts/matchers.ts diff --git a/modules/angular2/examples/common/forms/ts/validators/validators.ts b/modules/angular2/examples/common/forms/ts/validators/validators.ts new file mode 100644 index 0000000000..6744c8b5ed --- /dev/null +++ b/modules/angular2/examples/common/forms/ts/validators/validators.ts @@ -0,0 +1,30 @@ +import {Component} from 'angular2/core'; +import {MinLengthValidator, MaxLengthValidator} from 'angular2/common'; + +// #docregion min +@Component({ + selector: 'min-cmp', + directives: [MinLengthValidator], + template: ` +
+

Year:

+
+` +}) +class MinLengthTestComponent { +} +// #enddocregion + +// #docregion max +@Component({ + selector: 'max-cmp', + directives: [MaxLengthValidator], + template: ` +
+

Year:

+
+` +}) +class MaxLengthTestComponent { +} +// #enddocregion diff --git a/modules/angular2/examples/compiler/ts/url_resolver/url_resolver.ts b/modules/angular2/examples/compiler/ts/url_resolver/url_resolver.ts new file mode 100644 index 0000000000..3910a38a1a --- /dev/null +++ b/modules/angular2/examples/compiler/ts/url_resolver/url_resolver.ts @@ -0,0 +1,19 @@ +import {provide} from 'angular2/core'; +import {bootstrap} from 'angular2/bootstrap'; +import {UrlResolver} from 'angular2/compiler'; + +var MyApp; + +// #docregion url_resolver +class MyUrlResolver extends UrlResolver { + resolve(baseUrl: string, url: string): string { + // Serve CSS files from a special CDN. + if (url.substr(-4) === '.css') { + return super.resolve('http://cdn.myapp.com/css/', url); + } + return super.resolve(baseUrl, url); + } +} + +bootstrap(MyApp, [provide(UrlResolver, {useClass: MyUrlResolver})]); +// #enddocregion diff --git a/modules/angular2/examples/core/debug/ts/debug_element/debug_element.ts b/modules/angular2/examples/core/debug/ts/debug_element/debug_element.ts new file mode 100644 index 0000000000..ebda75d05c --- /dev/null +++ b/modules/angular2/examples/core/debug/ts/debug_element/debug_element.ts @@ -0,0 +1,16 @@ +import {DebugElement, Scope} from 'angular2/core'; + +var debugElement: DebugElement; +var predicate; + +// #docregion scope_all +debugElement.query(predicate, Scope.all); +// #enddocregion + +// #docregion scope_light +debugElement.query(predicate, Scope.light); +// #enddocregion + +// #docregion scope_view +debugElement.query(predicate, Scope.view); +// #enddocregion diff --git a/modules/angular2/examples/platform/dom/debug/ts/by/by.ts b/modules/angular2/examples/platform/dom/debug/ts/by/by.ts new file mode 100644 index 0000000000..58c888328c --- /dev/null +++ b/modules/angular2/examples/platform/dom/debug/ts/by/by.ts @@ -0,0 +1,17 @@ +import {By} from 'angular2/platform/browser'; +import {DebugElement, Scope} from 'angular2/core'; + +var debugElement: DebugElement; +class MyDirective {} + +// #docregion by_all +debugElement.query(By.all(), Scope.all); +// #enddocregion + +// #docregion by_css +debugElement.query(By.css('[attribute]'), Scope.all); +// #enddocregion + +// #docregion by_directive +debugElement.query(By.directive(MyDirective), Scope.all); +// #enddocregion diff --git a/modules/angular2/examples/platform/dom/debug/ts/debug_element_view_listener/providers.ts b/modules/angular2/examples/platform/dom/debug/ts/debug_element_view_listener/providers.ts new file mode 100644 index 0000000000..b9dec70aae --- /dev/null +++ b/modules/angular2/examples/platform/dom/debug/ts/debug_element_view_listener/providers.ts @@ -0,0 +1,10 @@ +import {Component} from 'angular2/core'; +import {bootstrap, ELEMENT_PROBE_PROVIDERS} from 'angular2/platform/browser'; + +@Component({selector: 'my-component'}) +class MyAppComponent { +} + +// #docregion providers +bootstrap(MyAppComponent, [ELEMENT_PROBE_PROVIDERS]); +// #enddocregion \ No newline at end of file diff --git a/modules/angular2/examples/testing/ts/fake_async.ts b/modules/angular2/examples/testing/ts/fake_async.ts new file mode 100644 index 0000000000..55bb766b91 --- /dev/null +++ b/modules/angular2/examples/testing/ts/fake_async.ts @@ -0,0 +1,29 @@ +import {describe, it, fakeAsync, expect, tick, clearPendingTimers} from 'angular2/testing'; + +// #docregion basic +describe('this test', () => { + it('looks async but is synchronous', fakeAsync((): void => { + var flag = false; + setTimeout(() => { flag = true; }, 100); + expect(flag).toBe(false); + tick(50); + expect(flag).toBe(false); + tick(50); + expect(flag).toBe(true); + })); +}); +// #enddocregion + +// #docregion pending +describe('this test', () => { + it('aborts a timer', fakeAsync((): void => { + // This timer is scheduled but doesn't need to complete for the + // test to pass (maybe it's a timeout for some operation). + // Leaving it will cause the test to fail... + setTimeout(() => {}, 100); + + // Unless we clean it up first. + clearPendingTimers(); + })); +}); +// #enddocregion \ No newline at end of file diff --git a/modules/angular2/examples/testing/ts/matchers.ts b/modules/angular2/examples/testing/ts/matchers.ts new file mode 100644 index 0000000000..f0bf7d2818 --- /dev/null +++ b/modules/angular2/examples/testing/ts/matchers.ts @@ -0,0 +1,40 @@ +import {expect} from 'angular2/testing'; + +var value: any; +var element: any; +var exception: any; + +abstract class OtherClass {} +class SomeClass {} + +// #docregion toBePromise +expect(value).toBePromise(); +// #enddocregion + +// #docregion toBeAnInstanceOf +expect(value).toBeAnInstanceOf(SomeClass); +// #enddocregion + +// #docregion toHaveText +expect(element).toHaveText('Hello world!'); +// #enddocregion + +// #docregion toHaveCssClass +expect(element).toHaveCssClass('current'); +// #enddocregion + +// #docregion toHaveCssStyle +expect(element).toHaveCssStyle({width: '100px', height: 'auto'}); +// #enddocregion + +// #docregion toContainError +expect(exception).toContainError('Failed to load'); +// #enddocregion + +// #docregion toThrowErrorWith +expect(() => { throw 'Failed to load'; }).toThrowErrorWith('Failed to load'); +// #enddocregion + +// #docregion toImplement +expect(SomeClass).toImplement(OtherClass); +// #enddocregion diff --git a/modules/angular2/http.ts b/modules/angular2/http.ts index 69c918d4ee..5341e23191 100644 --- a/modules/angular2/http.ts +++ b/modules/angular2/http.ts @@ -166,6 +166,8 @@ export const HTTP_PROVIDERS: any[] = [ ]; /** + * See {@link HTTP_PROVIDERS} instead. + * * @deprecated */ export const HTTP_BINDINGS = HTTP_PROVIDERS; @@ -291,6 +293,8 @@ export const JSONP_PROVIDERS: any[] = [ ]; /** + * See {@link JSONP_PROVIDERS} instead. + * * @deprecated */ export const JSON_BINDINGS = JSONP_PROVIDERS; diff --git a/modules/angular2/router.ts b/modules/angular2/router.ts index 8d5409952d..4cea18950a 100644 --- a/modules/angular2/router.ts +++ b/modules/angular2/router.ts @@ -98,6 +98,8 @@ export const ROUTER_PROVIDERS: any[] = CONST_EXPR([ ]); /** + * Use {@link ROUTER_PROVIDERS} instead. + * * @deprecated */ export const ROUTER_BINDINGS = ROUTER_PROVIDERS; diff --git a/modules/angular2/src/common/directives/observable_list_diff.ts b/modules/angular2/src/common/directives/observable_list_diff.ts index 08d07c5007..ee99cf4047 100644 --- a/modules/angular2/src/common/directives/observable_list_diff.ts +++ b/modules/angular2/src/common/directives/observable_list_diff.ts @@ -2,4 +2,9 @@ // I need to be here to make TypeScript think this is a module. import {} from 'angular2/src/facade/lang'; + +/** + * This module exists in Dart, but not in Typescript. This exported symbol + * is only here to help Typescript think this is a module. + */ export var workaround_empty_observable_list_diff: any; diff --git a/modules/angular2/src/common/forms/directives/control_value_accessor.ts b/modules/angular2/src/common/forms/directives/control_value_accessor.ts index 33a907ba62..90820f7d70 100644 --- a/modules/angular2/src/common/forms/directives/control_value_accessor.ts +++ b/modules/angular2/src/common/forms/directives/control_value_accessor.ts @@ -26,4 +26,9 @@ export interface ControlValueAccessor { registerOnTouched(fn: any): void; } +/** + * Used to provide a {@link ControlValueAccessor} for form controls. + * + * See {@link DefaultValueAccessor} for how to implement one. + */ export const NG_VALUE_ACCESSOR: OpaqueToken = CONST_EXPR(new OpaqueToken("NgValueAccessor")); \ No newline at end of file diff --git a/modules/angular2/src/common/forms/directives/ng_control_status.ts b/modules/angular2/src/common/forms/directives/ng_control_status.ts index 39f07e6ea4..38b7ccdabb 100644 --- a/modules/angular2/src/common/forms/directives/ng_control_status.ts +++ b/modules/angular2/src/common/forms/directives/ng_control_status.ts @@ -2,6 +2,10 @@ import {Directive, Self} from 'angular2/core'; import {NgControl} from './ng_control'; import {isBlank, isPresent} from 'angular2/src/facade/lang'; +/** + * Directive automatically applied to Angular forms that sets CSS classes + * based on control status (valid/invalid/dirty/etc). + */ @Directive({ selector: '[ngControl],[ngModel],[ngFormControl]', host: { diff --git a/modules/angular2/src/common/forms/directives/validators.ts b/modules/angular2/src/common/forms/directives/validators.ts index 53ca2ae56a..dcb3189bcc 100644 --- a/modules/angular2/src/common/forms/directives/validators.ts +++ b/modules/angular2/src/common/forms/directives/validators.ts @@ -45,8 +45,20 @@ const REQUIRED_VALIDATOR = export class RequiredValidator { } +/** + * Provivder which adds {@link MinLengthValidator} to {@link NG_VALIDATORS}. + * + * ## Example: + * + * {@example common/forms/ts/validators/validators.ts region='min'} + */ const MIN_LENGTH_VALIDATOR = CONST_EXPR( new Provider(NG_VALIDATORS, {useExisting: forwardRef(() => MinLengthValidator), multi: true})); + +/** + * A directive which installs the {@link MinLengthValidator} for any `ngControl`, + * `ngFormControl`, or control with `ngModel` that also has a `minlength` attribute. + */ @Directive({ selector: '[minlength][ngControl],[minlength][ngFormControl],[minlength][ngModel]', providers: [MIN_LENGTH_VALIDATOR] @@ -61,8 +73,20 @@ export class MinLengthValidator implements Validator { validate(c: Control): {[key: string]: any} { return this._validator(c); } } +/** + * Provider which adds {@link MaxLengthValidator} to {@link NG_VALIDATORS}. + * + * ## Example: + * + * {@example common/forms/ts/validators/validators.ts region='max'} + */ const MAX_LENGTH_VALIDATOR = CONST_EXPR( new Provider(NG_VALIDATORS, {useExisting: forwardRef(() => MaxLengthValidator), multi: true})); + +/** + * A directive which installs the {@link MaxLengthValidator} for any `ngControl, `ngFormControl`, + * or control with `ngModel` that also has a `maxlength` attribute. + */ @Directive({ selector: '[maxlength][ngControl],[maxlength][ngFormControl],[maxlength][ngModel]', providers: [MAX_LENGTH_VALIDATOR] diff --git a/modules/angular2/src/common/forms/form_builder.ts b/modules/angular2/src/common/forms/form_builder.ts index 11f415b335..b6ef3fdc7c 100644 --- a/modules/angular2/src/common/forms/form_builder.ts +++ b/modules/angular2/src/common/forms/form_builder.ts @@ -119,6 +119,8 @@ export class FormBuilder { export const FORM_PROVIDERS: Type[] = CONST_EXPR([FormBuilder]); /** + * See {@link FORM_PROVIDERS} instead. + * * @deprecated */ export const FORM_BINDINGS = FORM_PROVIDERS; diff --git a/modules/angular2/src/common/forms/validators.ts b/modules/angular2/src/common/forms/validators.ts index ee8bc60dad..f9cdc1c647 100644 --- a/modules/angular2/src/common/forms/validators.ts +++ b/modules/angular2/src/common/forms/validators.ts @@ -14,7 +14,6 @@ import * as modelModule from './model'; * ### Example * * {@example core/forms/ts/ng_validators/ng_validators.ts region='ng_validators'} - * ``` */ export const NG_VALIDATORS: OpaqueToken = CONST_EXPR(new OpaqueToken("NgValidators")); @@ -32,8 +31,7 @@ export const NG_ASYNC_VALIDATORS: OpaqueToken = CONST_EXPR(new OpaqueToken("NgAs * Provides a set of validators used by form controls. * * A validator is a function that processes a {@link Control} or collection of - * controls and returns a {@link StringMap} of errors. A null map means that - * validation has passed. + * controls and returns a map of errors. A null map means that validation has passed. * * ### Example * diff --git a/modules/angular2/src/common/pipes.ts b/modules/angular2/src/common/pipes.ts index 93950e9a9d..7c7a25c1ef 100644 --- a/modules/angular2/src/common/pipes.ts +++ b/modules/angular2/src/common/pipes.ts @@ -20,6 +20,13 @@ export {LowerCasePipe} from './pipes/lowercase_pipe'; export {NumberPipe, DecimalPipe, PercentPipe, CurrencyPipe} from './pipes/number_pipe'; export {UpperCasePipe} from './pipes/uppercase_pipe'; +/** + * A collection of Angular core pipes that are likely to be used in each and every + * application. + * + * This collection can be used to quickly enumerate all the built-in pipes in the `pipes` + * property of the `@Component` or `@View` decorators. + */ export const COMMON_PIPES = CONST_EXPR([ AsyncPipe, UpperCasePipe, diff --git a/modules/angular2/src/common/pipes/common_pipes.ts b/modules/angular2/src/common/pipes/common_pipes.ts index 7773c9332f..ac6dc36c09 100644 --- a/modules/angular2/src/common/pipes/common_pipes.ts +++ b/modules/angular2/src/common/pipes/common_pipes.ts @@ -12,6 +12,13 @@ import {DatePipe} from './date_pipe'; import {DecimalPipe, PercentPipe, CurrencyPipe} from './number_pipe'; import {CONST_EXPR} from 'angular2/src/facade/lang'; +/** + * A collection of Angular core pipes that are likely to be used in each and every + * application. + * + * This collection can be used to quickly enumerate all the built-in pipes in the `pipes` + * property of the `@Component` or `@View` decorators. + */ export const COMMON_PIPES = CONST_EXPR([ AsyncPipe, UpperCasePipe, diff --git a/modules/angular2/src/compiler/compiler.ts b/modules/angular2/src/compiler/compiler.ts index 76a112f879..c35bc9104c 100644 --- a/modules/angular2/src/compiler/compiler.ts +++ b/modules/angular2/src/compiler/compiler.ts @@ -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 = CONST_EXPR([ Lexer, Parser, diff --git a/modules/angular2/src/compiler/directive_metadata.ts b/modules/angular2/src/compiler/directive_metadata.ts index 5033a183cb..f82f6b031a 100644 --- a/modules/angular2/src/compiler/directive_metadata.ts +++ b/modules/angular2/src/compiler/directive_metadata.ts @@ -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(); diff --git a/modules/angular2/src/compiler/source_module.ts b/modules/angular2/src/compiler/source_module.ts index 4a5c8be44d..49dc23a9bf 100644 --- a/modules/angular2/src/compiler/source_module.ts +++ b/modules/angular2/src/compiler/source_module.ts @@ -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[][]) {} } diff --git a/modules/angular2/src/compiler/template_ast.ts b/modules/angular2/src/compiler/template_ast.ts index 8c31180f96..1b79d32be5 100644 --- a/modules/angular2/src/compiler/template_ast.ts +++ b/modules/angular2/src/compiler/template_ast.ts @@ -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 `