X Tutup
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
292 changes: 278 additions & 14 deletions modules/angular2/src/compiler/directive_metadata.ts

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions modules/angular2/src/compiler/template_compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ export class TemplateCompiler {
hostProperties: directive.hostProperties,
hostAttributes: directive.hostAttributes,
lifecycleHooks: directive.lifecycleHooks,
providers: directive.providers,
template: normalizedTemplate
}));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import {ChangeDetector} from './interfaces';
import {ChangeDetectionStrategy} from './constants';
import {Injectable} from 'angular2/src/core/di';

@Injectable()
export abstract class ChangeDetectorRef {
/**
* Marks all {@link ChangeDetectionStrategy#OnPush} ancestors as to be checked.
Expand Down
2 changes: 2 additions & 0 deletions modules/angular2/src/core/linker/element_ref.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {unimplemented} from 'angular2/src/facade/exceptions';
import {Injectable} from 'angular2/src/core/di';
import {AppElement} from './element';

/**
Expand All @@ -11,6 +12,7 @@ import {AppElement} from './element';
* An `ElementRef` is backed by a render-specific element. In the browser, this is usually a DOM
* element.
*/
@Injectable()
export abstract class ElementRef {
/**
* The underlying native element or `null` if direct access to native elements is not supported
Expand Down
2 changes: 2 additions & 0 deletions modules/angular2/src/core/linker/template_ref.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {ElementRef, ElementRef_} from './element_ref';
import {Injectable} from 'angular2/src/core/di';

/**
* Represents an Embedded Template that can be used to instantiate Embedded Views.
Expand All @@ -12,6 +13,7 @@ import {ElementRef, ElementRef_} from './element_ref';
* {@link ViewContainerRef#createEmbeddedView}, which will create the View and attach it to the
* View Container.
*/
@Injectable()
export abstract class TemplateRef {
/**
* The location in the View where the Embedded View logically belongs to.
Expand Down
3 changes: 2 additions & 1 deletion modules/angular2/src/core/linker/view_container_ref.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {ListWrapper} from 'angular2/src/facade/collection';
import {unimplemented} from 'angular2/src/facade/exceptions';
import {ResolvedProvider} from 'angular2/src/core/di';
import {ResolvedProvider, Injectable} from 'angular2/src/core/di';
import {isPresent, isBlank} from 'angular2/src/facade/lang';

import {AppElement} from './element';
Expand Down Expand Up @@ -36,6 +36,7 @@ import {
*
* <!-- TODO(i): we are also considering ElementRef#viewContainer api -->
*/
@Injectable()
export abstract class ViewContainerRef {
/**
* Anchor element that specifies the location of this container in the containing View.
Expand Down
3 changes: 2 additions & 1 deletion modules/angular2/src/core/render/api.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {ViewEncapsulation} from 'angular2/src/core/metadata/view';
import {Injector} from 'angular2/src/core/di/injector';
import {Injector, Injectable} from 'angular2/src/core/di';

export class RenderComponentType {
constructor(public id: string, public encapsulation: ViewEncapsulation,
Expand All @@ -13,6 +13,7 @@ export class RenderDebugInfo {

export interface ParentRenderer { renderComponent(componentType: RenderComponentType): Renderer; }

@Injectable()
export abstract class Renderer implements ParentRenderer {
abstract renderComponent(componentType: RenderComponentType): Renderer;

Expand Down
1 change: 1 addition & 0 deletions modules/angular2/src/router/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ let _resolveToFalse = PromiseWrapper.resolve(false);
* `Instruction`.
* The router uses the `RouteRegistry` to get an `Instruction`.
*/
@Injectable()
export class Router {
navigating: boolean = false;
lastNavigationAttempt: string;
Expand Down
10 changes: 6 additions & 4 deletions modules/angular2/test/compiler/directive_metadata_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import {
import {
CompileDirectiveMetadata,
CompileTypeMetadata,
CompileTemplateMetadata
CompileTemplateMetadata,
CompileProviderMetadata
} from 'angular2/src/compiler/directive_metadata';
import {ViewEncapsulation} from 'angular2/src/core/metadata/view';
import {ChangeDetectionStrategy} from 'angular2/src/core/change_detection';
Expand All @@ -28,8 +29,8 @@ export function main() {
var fullDirectiveMeta: CompileDirectiveMetadata;

beforeEach(() => {
fullTypeMeta =
new CompileTypeMetadata({name: 'SomeType', moduleUrl: 'someUrl', isHost: true});
fullTypeMeta = new CompileTypeMetadata(
{name: 'SomeType', moduleUrl: 'someUrl', isHost: true, diDeps: []});
fullTemplateMeta = new CompileTemplateMetadata({
encapsulation: ViewEncapsulation.Emulated,
template: '<a></a>',
Expand All @@ -48,7 +49,8 @@ export function main() {
inputs: ['someProp'],
outputs: ['someEvent'],
host: {'(event1)': 'handler1', '[prop1]': 'expr1', 'attr1': 'attrValue2'},
lifecycleHooks: [LifecycleHooks.OnChanges]
lifecycleHooks: [LifecycleHooks.OnChanges],
providers: [new CompileProviderMetadata({token: 'token', useClass: fullTypeMeta})]
});

});
Expand Down
17 changes: 17 additions & 0 deletions modules/angular2/test/public_api_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,15 @@ var NG_COMPILER = [
"CompileDirectiveMetadata.template=",
"CompileDirectiveMetadata.type",
"CompileDirectiveMetadata.type=",
"CompileDirectiveMetadata.identifier",
"CompileDirectiveMetadata.providers",
"CompileDirectiveMetadata.providers=",
"CompileDirectiveMetadata.queries",
"CompileDirectiveMetadata.queries=",
"CompileDirectiveMetadata.viewProviders",
"CompileDirectiveMetadata.viewProviders=",
"CompileDirectiveMetadata.viewQueries",
"CompileDirectiveMetadata.viewQueries=",
"CompileTemplateMetadata.encapsulation",
"CompileTemplateMetadata.encapsulation=",
"CompileTemplateMetadata.ngContentSelectors",
Expand All @@ -545,6 +554,14 @@ var NG_COMPILER = [
"CompileTypeMetadata.name=",
"CompileTypeMetadata.runtime",
"CompileTypeMetadata.runtime=",
"CompileTypeMetadata.diDeps",
"CompileTypeMetadata.diDeps=",
"CompileTypeMetadata.type",
"CompileTypeMetadata.identifier",
"CompileTypeMetadata.prefix",
"CompileTypeMetadata.prefix=",
"CompileTypeMetadata.constConstructor",
"CompileTypeMetadata.constConstructor=",
"DirectiveAst.directive",
"DirectiveAst.directive=",
"DirectiveAst.exportAsVars",
Expand Down
1 change: 1 addition & 0 deletions modules/angular2_material/src/components/dialog/dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ export class MdDialog {
/**
* Reference to an opened dialog.
*/
@Injectable()
export class MdDialogRef {
// Reference to the MdDialogContainer component.
containerRef: ComponentRef;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class ReflectionInfoVisitor extends RecursiveAstVisitor<ReflectionInfoModel> {

@override
ReflectionInfoModel visitClassDeclaration(ClassDeclaration node) {
if (node.isAbstract) return null;
if (!node.metadata
.any((a) => _annotationMatcher.hasMatch(a.name, assetId))) {
return null;
Expand Down
67 changes: 42 additions & 25 deletions modules_dart/transform/lib/src/transform/common/ng_meta.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,23 @@ class NgMeta {
static const _TYPE_VALUE = 'type';
static const _VALUE_KEY = 'value';

/// Metadata for each type annotated as a directive/pipe.
/// Type: [CompileDirectiveMetadata]/[CompilePipeMetadata]
final Map<String, dynamic> types;
/// Metadata for each identifier
/// Type: [CompileDirectiveMetadata]|[CompilePipeMetadata]|[CompileTypeMetadata]|[CompileIdentifierMetadata]
final Map<String, dynamic> identifiers;

/// List of other types and names associated with a given name.
final Map<String, List<String>> aliases;

// The NgDeps generated from
final NgDepsModel ngDeps;

NgMeta(
{Map<String, dynamic> types,
Map<String, List<String>> aliases,
this.ngDeps: null})
: this.types = types != null ? types : {},
this.aliases = aliases != null ? aliases : {};
bool definesAlias;

NgMeta({Map<String, List<String>> aliases,
Map<String, dynamic> identifiers,
this.ngDeps: null, this.definesAlias: false})
:this.aliases = aliases != null ? aliases : {},
this.identifiers = identifiers != null ? identifiers : {};

NgMeta.empty() : this();

Expand All @@ -69,13 +70,22 @@ class NgMeta {
return false;
}

bool get isEmpty => types.isEmpty && aliases.isEmpty && isNgDepsEmpty;
bool get isEmpty => identifiers.isEmpty && aliases.isEmpty && isNgDepsEmpty;

List<String> get linkingUris {
final r = ngDeps.exports.map((r) => r.uri).toList();
if (definesAlias) {
r.addAll(ngDeps.imports.map((r) => r.uri));
}
return r;
}

/// Parse from the serialized form produced by [toJson].
factory NgMeta.fromJson(Map json) {
var ngDeps = null;
final types = {};
final aliases = {};
final identifiers = {};
var definesAlias = false;
for (var key in json.keys) {
if (key == _NG_DEPS_KEY) {
var ngDepsJsonMap = json[key];
Expand All @@ -85,63 +95,70 @@ class NgMeta {
'Unexpected value $ngDepsJsonMap for key "$key" in NgMeta.');
continue;
}
ngDeps = new NgDepsModel()..mergeFromJsonMap(ngDepsJsonMap);
ngDeps = new NgDepsModel()
..mergeFromJsonMap(ngDepsJsonMap);
} else if (key == 'definesAlias') {
definesAlias = json[key];

} else {
var entry = json[key];
if (entry is! Map) {
log.warning('Unexpected value $entry for key "$key" in NgMeta.');
continue;
}
if (entry[_KIND_KEY] == _TYPE_VALUE) {
types[key] = CompileMetadataWithType.fromJson(entry[_VALUE_KEY]);
identifiers[key] = CompileMetadataWithIdentifier.fromJson(entry[_VALUE_KEY]);
} else if (entry[_KIND_KEY] == _ALIAS_VALUE) {
aliases[key] = entry[_VALUE_KEY];
}
}
}
return new NgMeta(types: types, aliases: aliases, ngDeps: ngDeps);
return new NgMeta(identifiers: identifiers, aliases: aliases, ngDeps: ngDeps, definesAlias: definesAlias);
}

/// Serialized representation of this instance.
Map toJson() {
var result = {};
result[_NG_DEPS_KEY] = isNgDepsEmpty ? null : ngDeps.writeToJsonMap();

types.forEach((k, v) {
identifiers.forEach((k, v) {
result[k] = {_KIND_KEY: _TYPE_VALUE, _VALUE_KEY: v.toJson()};
});

aliases.forEach((k, v) {
result[k] = {_KIND_KEY: _ALIAS_VALUE, _VALUE_KEY: v};
});

result['definesAlias'] = definesAlias;

return result;
}

/// Merge into this instance all information from [other].
/// This does not include `ngDeps`.
void addAll(NgMeta other) {
types.addAll(other.types);
aliases.addAll(other.aliases);
identifiers.addAll(other.identifiers);
}

/// Returns the metadata for every type associated with the given [alias].
List<dynamic> flatten(String alias) {
var result = [];
var seen = new Set();
helper(name) {
if (!seen.add(name)) {
log.warning('Circular alias dependency for "$name".');
helper(name, path) {
final newPath = []..addAll(path)..add(name);
if (path.contains(name)) {
log.error('Circular alias dependency for "$name". Cycle: ${newPath.join(' -> ')}.');
return;
}
if (types.containsKey(name)) {
result.add(types[name]);
if (identifiers.containsKey(name)) {
result.add(identifiers[name]);
} else if (aliases.containsKey(name)) {
aliases[name].forEach(helper);
aliases[name].forEach((n) => helper(n, newPath));
} else {
log.warning('Unknown alias: "$name".');
log.error('Unknown alias: ${newPath.join(' -> ')}. Make sure you export ${name} from the file where ${path.last} is defined.');
}
}
helper(alias);
helper(alias, []);
return result;
}
}
Loading
X Tutup