feat(core): renam AMBIENT_DIRECTIVES and AMBIENT_PIPES into PLATFORM_DIRECTIVES and PLATFORM_PIPES
After discussing it we decided that PLATFORM_ is a better prefix for directives available everywhere in the app. BREAKING CHANGE AMBIENT_DIRECTIVES -> PLATFORM_DIRECTIVES AMBIENT_PIPES -> PLATFORM_PIPES Closes #5201
This commit is contained in:
parent
2618becaa5
commit
e27665c368
|
@ -19,5 +19,5 @@ export * from './src/common/directives';
|
||||||
export * from './src/common/forms';
|
export * from './src/common/forms';
|
||||||
export * from './src/core/debug';
|
export * from './src/core/debug';
|
||||||
export * from './src/core/change_detection';
|
export * from './src/core/change_detection';
|
||||||
export * from './src/core/ambient';
|
export * from './src/core/platform_directives_and_pipes';
|
||||||
export * from './src/core/dev_mode';
|
export * from './src/core/dev_mode';
|
||||||
|
|
|
@ -6,7 +6,7 @@ export {
|
||||||
CompileTemplateMetadata
|
CompileTemplateMetadata
|
||||||
} from './directive_metadata';
|
} from './directive_metadata';
|
||||||
export {SourceModule, SourceWithImports} from './source_module';
|
export {SourceModule, SourceWithImports} from './source_module';
|
||||||
export {AMBIENT_DIRECTIVES, AMBIENT_PIPES} from 'angular2/src/core/ambient';
|
export {PLATFORM_DIRECTIVES, PLATFORM_PIPES} from 'angular2/src/core/platform_directives_and_pipes';
|
||||||
|
|
||||||
import {assertionsEnabled, Type} from 'angular2/src/facade/lang';
|
import {assertionsEnabled, Type} from 'angular2/src/facade/lang';
|
||||||
import {provide, Provider} from 'angular2/src/core/di';
|
import {provide, Provider} from 'angular2/src/core/di';
|
||||||
|
|
|
@ -18,7 +18,7 @@ import {hasLifecycleHook} from 'angular2/src/core/linker/directive_lifecycle_ref
|
||||||
import {LifecycleHooks, LIFECYCLE_HOOKS_VALUES} from 'angular2/src/core/linker/interfaces';
|
import {LifecycleHooks, LIFECYCLE_HOOKS_VALUES} from 'angular2/src/core/linker/interfaces';
|
||||||
import {reflector} from 'angular2/src/core/reflection/reflection';
|
import {reflector} from 'angular2/src/core/reflection/reflection';
|
||||||
import {Injectable, Inject, Optional} from 'angular2/src/core/di';
|
import {Injectable, Inject, Optional} from 'angular2/src/core/di';
|
||||||
import {AMBIENT_DIRECTIVES} from 'angular2/src/core/ambient';
|
import {PLATFORM_DIRECTIVES} from 'angular2/src/core/platform_directives_and_pipes';
|
||||||
import {MODULE_SUFFIX} from './util';
|
import {MODULE_SUFFIX} from './util';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
|
@ -26,7 +26,7 @@ export class RuntimeMetadataResolver {
|
||||||
private _cache = new Map<Type, cpl.CompileDirectiveMetadata>();
|
private _cache = new Map<Type, cpl.CompileDirectiveMetadata>();
|
||||||
|
|
||||||
constructor(private _directiveResolver: DirectiveResolver, private _viewResolver: ViewResolver,
|
constructor(private _directiveResolver: DirectiveResolver, private _viewResolver: ViewResolver,
|
||||||
@Optional() @Inject(AMBIENT_DIRECTIVES) private _ambientDirectives: Type[]) {}
|
@Optional() @Inject(PLATFORM_DIRECTIVES) private _platformDirectives: Type[]) {}
|
||||||
|
|
||||||
getMetadata(directiveType: Type): cpl.CompileDirectiveMetadata {
|
getMetadata(directiveType: Type): cpl.CompileDirectiveMetadata {
|
||||||
var meta = this._cache.get(directiveType);
|
var meta = this._cache.get(directiveType);
|
||||||
|
@ -69,7 +69,7 @@ export class RuntimeMetadataResolver {
|
||||||
|
|
||||||
getViewDirectivesMetadata(component: Type): cpl.CompileDirectiveMetadata[] {
|
getViewDirectivesMetadata(component: Type): cpl.CompileDirectiveMetadata[] {
|
||||||
var view = this._viewResolver.resolve(component);
|
var view = this._viewResolver.resolve(component);
|
||||||
var directives = flattenDirectives(view, this._ambientDirectives);
|
var directives = flattenDirectives(view, this._platformDirectives);
|
||||||
for (var i = 0; i < directives.length; i++) {
|
for (var i = 0; i < directives.length; i++) {
|
||||||
if (!isValidDirective(directives[i])) {
|
if (!isValidDirective(directives[i])) {
|
||||||
throw new BaseException(
|
throw new BaseException(
|
||||||
|
@ -87,10 +87,10 @@ function removeDuplicates(items: any[]): any[] {
|
||||||
return MapWrapper.keys(m);
|
return MapWrapper.keys(m);
|
||||||
}
|
}
|
||||||
|
|
||||||
function flattenDirectives(view: ViewMetadata, ambientDirectives: any[]): Type[] {
|
function flattenDirectives(view: ViewMetadata, platformDirectives: any[]): Type[] {
|
||||||
let directives = [];
|
let directives = [];
|
||||||
if (isPresent(ambientDirectives)) {
|
if (isPresent(platformDirectives)) {
|
||||||
flattenArray(ambientDirectives, directives);
|
flattenArray(platformDirectives, directives);
|
||||||
}
|
}
|
||||||
if (isPresent(view.directives)) {
|
if (isPresent(view.directives)) {
|
||||||
flattenArray(view.directives, directives);
|
flattenArray(view.directives, directives);
|
||||||
|
|
|
@ -47,7 +47,7 @@ import {AppViewManager_} from "./linker/view_manager";
|
||||||
import {Compiler_} from "./linker/compiler";
|
import {Compiler_} from "./linker/compiler";
|
||||||
import {wtfLeave, wtfCreateScope, WtfScopeFn} from './profile/profile';
|
import {wtfLeave, wtfCreateScope, WtfScopeFn} from './profile/profile';
|
||||||
import {ChangeDetectorRef} from 'angular2/src/core/change_detection/change_detector_ref';
|
import {ChangeDetectorRef} from 'angular2/src/core/change_detection/change_detector_ref';
|
||||||
import {AMBIENT_DIRECTIVES, AMBIENT_PIPES} from "angular2/src/core/ambient";
|
import {PLATFORM_DIRECTIVES, PLATFORM_PIPES} from "angular2/src/core/platform_directives_and_pipes";
|
||||||
import {lockDevMode} from 'angular2/src/facade/lang';
|
import {lockDevMode} from 'angular2/src/facade/lang';
|
||||||
import {COMMON_DIRECTIVES, COMMON_PIPES} from "angular2/common";
|
import {COMMON_DIRECTIVES, COMMON_PIPES} from "angular2/common";
|
||||||
|
|
||||||
|
@ -110,8 +110,8 @@ export function applicationCommonProviders(): Array<Type | Provider | any[]> {
|
||||||
provide(KeyValueDiffers, {useValue: defaultKeyValueDiffers}),
|
provide(KeyValueDiffers, {useValue: defaultKeyValueDiffers}),
|
||||||
DirectiveResolver,
|
DirectiveResolver,
|
||||||
PipeResolver,
|
PipeResolver,
|
||||||
provide(AMBIENT_PIPES, {useValue: COMMON_PIPES, multi: true}),
|
provide(PLATFORM_PIPES, {useValue: COMMON_PIPES, multi: true}),
|
||||||
provide(AMBIENT_DIRECTIVES, {useValue: COMMON_DIRECTIVES, multi: true}),
|
provide(PLATFORM_DIRECTIVES, {useValue: COMMON_DIRECTIVES, multi: true}),
|
||||||
provide(DynamicComponentLoader, {useClass: DynamicComponentLoader_})
|
provide(DynamicComponentLoader, {useClass: DynamicComponentLoader_})
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@ import {DirectiveResolver} from './directive_resolver';
|
||||||
import {ViewResolver} from './view_resolver';
|
import {ViewResolver} from './view_resolver';
|
||||||
import {PipeResolver} from './pipe_resolver';
|
import {PipeResolver} from './pipe_resolver';
|
||||||
import {ViewMetadata, ViewEncapsulation} from '../metadata/view';
|
import {ViewMetadata, ViewEncapsulation} from '../metadata/view';
|
||||||
import {AMBIENT_PIPES} from 'angular2/src/core/ambient';
|
import {PLATFORM_PIPES} from 'angular2/src/core/platform_directives_and_pipes';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
visitAllCommands,
|
visitAllCommands,
|
||||||
|
@ -40,7 +40,7 @@ export class ProtoViewFactory {
|
||||||
private _nextTemplateId: number = 0;
|
private _nextTemplateId: number = 0;
|
||||||
|
|
||||||
constructor(private _renderer: Renderer,
|
constructor(private _renderer: Renderer,
|
||||||
@Optional() @Inject(AMBIENT_PIPES) private _ambientPipes: Array<Type | any[]>,
|
@Optional() @Inject(PLATFORM_PIPES) private _platformPipes: Array<Type | any[]>,
|
||||||
private _directiveResolver: DirectiveResolver, private _viewResolver: ViewResolver,
|
private _directiveResolver: DirectiveResolver, private _viewResolver: ViewResolver,
|
||||||
private _pipeResolver: PipeResolver, @Inject(APP_ID) private _appId: string) {}
|
private _pipeResolver: PipeResolver, @Inject(APP_ID) private _appId: string) {}
|
||||||
|
|
||||||
|
@ -119,8 +119,8 @@ export class ProtoViewFactory {
|
||||||
|
|
||||||
private _flattenPipes(view: ViewMetadata): any[] {
|
private _flattenPipes(view: ViewMetadata): any[] {
|
||||||
let pipes = [];
|
let pipes = [];
|
||||||
if (isPresent(this._ambientPipes)) {
|
if (isPresent(this._platformPipes)) {
|
||||||
_flattenArray(this._ambientPipes, pipes);
|
_flattenArray(this._platformPipes, pipes);
|
||||||
}
|
}
|
||||||
if (isPresent(view.pipes)) {
|
if (isPresent(view.pipes)) {
|
||||||
_flattenArray(view.pipes, pipes);
|
_flattenArray(view.pipes, pipes);
|
||||||
|
|
|
@ -8,7 +8,7 @@ import {CONST_EXPR} from "angular2/src/facade/lang";
|
||||||
* ### Example
|
* ### Example
|
||||||
*
|
*
|
||||||
* ```typescript
|
* ```typescript
|
||||||
* import {AMBIENT_DIRECTIVES} from 'angular2/angular2';
|
* import {PLATFORM_DIRECTIVES} from 'angular2/angular2';
|
||||||
* import {OtherDirective} from './myDirectives';
|
* import {OtherDirective} from './myDirectives';
|
||||||
*
|
*
|
||||||
* @Component({
|
* @Component({
|
||||||
|
@ -22,10 +22,10 @@ import {CONST_EXPR} from "angular2/src/facade/lang";
|
||||||
* ...
|
* ...
|
||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
* bootstrap(MyComponent, [provide(AMBIENT_DIRECTIVES, {useValue: [OtherDirective], multi:true})]);
|
* bootstrap(MyComponent, [provide(PLATFORM_DIRECTIVES, {useValue: [OtherDirective], multi:true})]);
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
export const AMBIENT_DIRECTIVES: OpaqueToken = CONST_EXPR(new OpaqueToken("Ambient Directives"));
|
export const PLATFORM_DIRECTIVES: OpaqueToken = CONST_EXPR(new OpaqueToken("Platform Directives"));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A token that can be provided when bootstraping an application to make an array of pipes
|
* A token that can be provided when bootstraping an application to make an array of pipes
|
||||||
|
@ -34,7 +34,7 @@ export const AMBIENT_DIRECTIVES: OpaqueToken = CONST_EXPR(new OpaqueToken("Ambie
|
||||||
* ### Example
|
* ### Example
|
||||||
*
|
*
|
||||||
* ```typescript
|
* ```typescript
|
||||||
* import {AMBIENT_PIPES} from 'angular2/angular2';
|
* import {PLATFORM_PIPES} from 'angular2/angular2';
|
||||||
* import {OtherPipe} from './myPipe';
|
* import {OtherPipe} from './myPipe';
|
||||||
*
|
*
|
||||||
* @Component({
|
* @Component({
|
||||||
|
@ -47,7 +47,7 @@ export const AMBIENT_DIRECTIVES: OpaqueToken = CONST_EXPR(new OpaqueToken("Ambie
|
||||||
* ...
|
* ...
|
||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
* bootstrap(MyComponent, [provide(AMBIENT_PIPES, {useValue: [OtherPipe], multi:true})]);
|
* bootstrap(MyComponent, [provide(PLATFORM_PIPES, {useValue: [OtherPipe], multi:true})]);
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
export const AMBIENT_PIPES: OpaqueToken = CONST_EXPR(new OpaqueToken("Ambient Pipes"));
|
export const PLATFORM_PIPES: OpaqueToken = CONST_EXPR(new OpaqueToken("Platform Pipes"));
|
|
@ -61,7 +61,7 @@ import {
|
||||||
ClientMessageBrokerFactory,
|
ClientMessageBrokerFactory,
|
||||||
ClientMessageBrokerFactory_
|
ClientMessageBrokerFactory_
|
||||||
} from 'angular2/src/web_workers/shared/client_message_broker';
|
} from 'angular2/src/web_workers/shared/client_message_broker';
|
||||||
import {AMBIENT_DIRECTIVES, AMBIENT_PIPES} from "angular2/src/core/ambient";
|
import {PLATFORM_DIRECTIVES, PLATFORM_PIPES} from "angular2/src/core/platform_directives_and_pipes";
|
||||||
import {COMMON_DIRECTIVES, COMMON_PIPES} from "angular2/common";
|
import {COMMON_DIRECTIVES, COMMON_PIPES} from "angular2/common";
|
||||||
|
|
||||||
var _rootInjector: Injector;
|
var _rootInjector: Injector;
|
||||||
|
@ -95,8 +95,8 @@ function _injectorProviders(): any[] {
|
||||||
AppViewListener,
|
AppViewListener,
|
||||||
ProtoViewFactory,
|
ProtoViewFactory,
|
||||||
ViewResolver,
|
ViewResolver,
|
||||||
provide(AMBIENT_PIPES, {useValue: COMMON_PIPES, multi: true}),
|
provide(PLATFORM_PIPES, {useValue: COMMON_PIPES, multi: true}),
|
||||||
provide(AMBIENT_DIRECTIVES, {useValue: COMMON_DIRECTIVES, multi: true}),
|
provide(PLATFORM_DIRECTIVES, {useValue: COMMON_DIRECTIVES, multi: true}),
|
||||||
DirectiveResolver,
|
DirectiveResolver,
|
||||||
Parser,
|
Parser,
|
||||||
Lexer,
|
Lexer,
|
||||||
|
|
|
@ -37,7 +37,7 @@ import {
|
||||||
import {TEST_PROVIDERS} from './test_bindings';
|
import {TEST_PROVIDERS} from './test_bindings';
|
||||||
import {MODULE_SUFFIX} from 'angular2/src/compiler/util';
|
import {MODULE_SUFFIX} from 'angular2/src/compiler/util';
|
||||||
import {IS_DART} from 'angular2/src/facade/lang';
|
import {IS_DART} from 'angular2/src/facade/lang';
|
||||||
import {AMBIENT_DIRECTIVES} from 'angular2/src/core/ambient';
|
import {PLATFORM_DIRECTIVES} from 'angular2/src/core/platform_directives_and_pipes';
|
||||||
|
|
||||||
export function main() {
|
export function main() {
|
||||||
describe('RuntimeMetadataResolver', () => {
|
describe('RuntimeMetadataResolver', () => {
|
||||||
|
@ -85,10 +85,10 @@ export function main() {
|
||||||
.toEqual([resolver.getMetadata(DirectiveWithoutModuleId)]);
|
.toEqual([resolver.getMetadata(DirectiveWithoutModuleId)]);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
describe("ambient directives", () => {
|
describe("platform directives", () => {
|
||||||
beforeEachProviders(() => [provide(AMBIENT_DIRECTIVES, {useValue: [ADirective]})]);
|
beforeEachProviders(() => [provide(PLATFORM_DIRECTIVES, {useValue: [ADirective]})]);
|
||||||
|
|
||||||
it('should include ambient directives when available',
|
it('should include platform directives when available',
|
||||||
inject([RuntimeMetadataResolver], (resolver: RuntimeMetadataResolver) => {
|
inject([RuntimeMetadataResolver], (resolver: RuntimeMetadataResolver) => {
|
||||||
expect(resolver.getViewDirectivesMetadata(ComponentWithEverything))
|
expect(resolver.getViewDirectivesMetadata(ComponentWithEverything))
|
||||||
.toEqual([
|
.toEqual([
|
||||||
|
|
|
@ -147,7 +147,7 @@ var NG_ALL = [
|
||||||
'By',
|
'By',
|
||||||
'CORE_DIRECTIVES',
|
'CORE_DIRECTIVES',
|
||||||
'COMMON_DIRECTIVES',
|
'COMMON_DIRECTIVES',
|
||||||
'AMBIENT_DIRECTIVES:js',
|
'PLATFORM_DIRECTIVES:js',
|
||||||
'ChangeDetectionError',
|
'ChangeDetectionError',
|
||||||
'ChangeDetectionError.context',
|
'ChangeDetectionError.context',
|
||||||
'ChangeDetectionError.location',
|
'ChangeDetectionError.location',
|
||||||
|
@ -399,7 +399,7 @@ var NG_ALL = [
|
||||||
'CyclicDependencyError.message=',
|
'CyclicDependencyError.message=',
|
||||||
'CyclicDependencyError.stackTrace',
|
'CyclicDependencyError.stackTrace',
|
||||||
'COMMON_PIPES',
|
'COMMON_PIPES',
|
||||||
'AMBIENT_PIPES:js',
|
'PLATFORM_PIPES:js',
|
||||||
'DOCUMENT',
|
'DOCUMENT',
|
||||||
'DatePipe',
|
'DatePipe',
|
||||||
'DatePipe.supports()',
|
'DatePipe.supports()',
|
||||||
|
|
|
@ -17,7 +17,7 @@ dependency_overrides:
|
||||||
path: ../angular2_material
|
path: ../angular2_material
|
||||||
transformers:
|
transformers:
|
||||||
- angular2:
|
- angular2:
|
||||||
ambient_directives: 'package:angular2/src/common/directives.dart#CORE_DIRECTIVES'
|
platform_directives: 'package:angular2/src/common/directives.dart#CORE_DIRECTIVES'
|
||||||
entry_points:
|
entry_points:
|
||||||
- web/src/gestures/index.dart
|
- web/src/gestures/index.dart
|
||||||
- web/src/hello_world/index.dart
|
- web/src/hello_world/index.dart
|
||||||
|
|
|
@ -11,7 +11,7 @@ const FORMAT_CODE_PARAM = 'format_code';
|
||||||
const REFLECT_PROPERTIES_AS_ATTRIBUTES = 'reflect_properties_as_attributes';
|
const REFLECT_PROPERTIES_AS_ATTRIBUTES = 'reflect_properties_as_attributes';
|
||||||
// TODO(kegluenq): Remove this after 30 Nov (i/5108).
|
// TODO(kegluenq): Remove this after 30 Nov (i/5108).
|
||||||
const REFLECT_PROPERTIES_AS_ATTRIBUTES_OLD = 'reflectPropertiesAsAttributes';
|
const REFLECT_PROPERTIES_AS_ATTRIBUTES_OLD = 'reflectPropertiesAsAttributes';
|
||||||
const AMBIENT_DIRECTIVES = 'ambient_directives';
|
const PLATFORM_DIRECTIVES = 'platform_directives';
|
||||||
const INIT_REFLECTOR_PARAM = 'init_reflector';
|
const INIT_REFLECTOR_PARAM = 'init_reflector';
|
||||||
const INLINE_VIEWS_PARAM = 'inline_views';
|
const INLINE_VIEWS_PARAM = 'inline_views';
|
||||||
const MIRROR_MODE_PARAM = 'mirror_mode';
|
const MIRROR_MODE_PARAM = 'mirror_mode';
|
||||||
|
@ -42,7 +42,7 @@ class TransformerOptions {
|
||||||
|
|
||||||
/// A set of directives that will be automatically passed-in to the template compiler
|
/// A set of directives that will be automatically passed-in to the template compiler
|
||||||
/// Format of an item in the list: angular2/lib/src/common/directives.dart#CORE_DIRECTIVES
|
/// Format of an item in the list: angular2/lib/src/common/directives.dart#CORE_DIRECTIVES
|
||||||
final List<String> ambientDirectives;
|
final List<String> platformDirectives;
|
||||||
|
|
||||||
/// Whether to format generated code.
|
/// Whether to format generated code.
|
||||||
/// Code that is only modified will never be formatted because doing so may
|
/// Code that is only modified will never be formatted because doing so may
|
||||||
|
@ -64,7 +64,7 @@ class TransformerOptions {
|
||||||
this.initReflector,
|
this.initReflector,
|
||||||
this.annotationMatcher,
|
this.annotationMatcher,
|
||||||
{this.reflectPropertiesAsAttributes,
|
{this.reflectPropertiesAsAttributes,
|
||||||
this.ambientDirectives,
|
this.platformDirectives,
|
||||||
this.inlineViews,
|
this.inlineViews,
|
||||||
this.formatCode});
|
this.formatCode});
|
||||||
|
|
||||||
|
@ -75,7 +75,7 @@ class TransformerOptions {
|
||||||
List<ClassDescriptor> customAnnotationDescriptors: const [],
|
List<ClassDescriptor> customAnnotationDescriptors: const [],
|
||||||
bool inlineViews: false,
|
bool inlineViews: false,
|
||||||
bool reflectPropertiesAsAttributes: true,
|
bool reflectPropertiesAsAttributes: true,
|
||||||
List<String> ambientDirectives,
|
List<String> platformDirectives,
|
||||||
bool formatCode: false}) {
|
bool formatCode: false}) {
|
||||||
var annotationMatcher = new AnnotationMatcher()
|
var annotationMatcher = new AnnotationMatcher()
|
||||||
..addAll(customAnnotationDescriptors);
|
..addAll(customAnnotationDescriptors);
|
||||||
|
@ -85,7 +85,7 @@ class TransformerOptions {
|
||||||
return new TransformerOptions._internal(entryPoints, entryPointGlobs,
|
return new TransformerOptions._internal(entryPoints, entryPointGlobs,
|
||||||
modeName, mirrorMode, initReflector, annotationMatcher,
|
modeName, mirrorMode, initReflector, annotationMatcher,
|
||||||
reflectPropertiesAsAttributes: reflectPropertiesAsAttributes,
|
reflectPropertiesAsAttributes: reflectPropertiesAsAttributes,
|
||||||
ambientDirectives: ambientDirectives,
|
platformDirectives: platformDirectives,
|
||||||
inlineViews: inlineViews,
|
inlineViews: inlineViews,
|
||||||
formatCode: formatCode);
|
formatCode: formatCode);
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@ TransformerOptions parseBarbackSettings(BarbackSettings settings) {
|
||||||
config, REFLECT_PROPERTIES_AS_ATTRIBUTES_OLD,
|
config, REFLECT_PROPERTIES_AS_ATTRIBUTES_OLD,
|
||||||
defaultValue: false);
|
defaultValue: false);
|
||||||
}
|
}
|
||||||
var ambientDirectives = _readStringList(config, AMBIENT_DIRECTIVES);
|
var platformDirectives = _readStringList(config, PLATFORM_DIRECTIVES);
|
||||||
var formatCode = _readBool(config, FORMAT_CODE_PARAM, defaultValue: false);
|
var formatCode = _readBool(config, FORMAT_CODE_PARAM, defaultValue: false);
|
||||||
String mirrorModeVal =
|
String mirrorModeVal =
|
||||||
config.containsKey(MIRROR_MODE_PARAM) ? config[MIRROR_MODE_PARAM] : '';
|
config.containsKey(MIRROR_MODE_PARAM) ? config[MIRROR_MODE_PARAM] : '';
|
||||||
|
@ -40,7 +40,7 @@ TransformerOptions parseBarbackSettings(BarbackSettings settings) {
|
||||||
initReflector: initReflector,
|
initReflector: initReflector,
|
||||||
customAnnotationDescriptors: _readCustomAnnotations(config),
|
customAnnotationDescriptors: _readCustomAnnotations(config),
|
||||||
reflectPropertiesAsAttributes: reflectPropertiesAsAttributes,
|
reflectPropertiesAsAttributes: reflectPropertiesAsAttributes,
|
||||||
ambientDirectives: ambientDirectives,
|
platformDirectives: platformDirectives,
|
||||||
inlineViews: _readBool(config, INLINE_VIEWS_PARAM, defaultValue: false),
|
inlineViews: _readBool(config, INLINE_VIEWS_PARAM, defaultValue: false),
|
||||||
formatCode: formatCode);
|
formatCode: formatCode);
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,10 +20,10 @@ import 'package:barback/barback.dart';
|
||||||
/// The returned value wraps the [NgDepsModel] at `assetId` as well as these
|
/// The returned value wraps the [NgDepsModel] at `assetId` as well as these
|
||||||
/// created objects.
|
/// created objects.
|
||||||
Future<CompileDataResults> createCompileData(
|
Future<CompileDataResults> createCompileData(
|
||||||
AssetReader reader, AssetId assetId, List<String> ambientDirectives) async {
|
AssetReader reader, AssetId assetId, List<String> platformDirectives) async {
|
||||||
return logElapsedAsync(() async {
|
return logElapsedAsync(() async {
|
||||||
final creator =
|
final creator =
|
||||||
await _CompileDataCreator.create(reader, assetId, ambientDirectives);
|
await _CompileDataCreator.create(reader, assetId, platformDirectives);
|
||||||
return creator != null ? creator.createCompileData() : null;
|
return creator != null ? creator.createCompileData() : null;
|
||||||
}, operationName: 'createCompileData', assetId: assetId);
|
}, operationName: 'createCompileData', assetId: assetId);
|
||||||
}
|
}
|
||||||
|
@ -42,19 +42,19 @@ class _CompileDataCreator {
|
||||||
final AssetReader reader;
|
final AssetReader reader;
|
||||||
final AssetId entryPoint;
|
final AssetId entryPoint;
|
||||||
final NgMeta ngMeta;
|
final NgMeta ngMeta;
|
||||||
final List<String> ambientDirectives;
|
final List<String> platformDirectives;
|
||||||
|
|
||||||
_CompileDataCreator(
|
_CompileDataCreator(
|
||||||
this.reader, this.entryPoint, this.ngMeta, this.ambientDirectives);
|
this.reader, this.entryPoint, this.ngMeta, this.platformDirectives);
|
||||||
|
|
||||||
static Future<_CompileDataCreator> create(AssetReader reader, AssetId assetId,
|
static Future<_CompileDataCreator> create(AssetReader reader, AssetId assetId,
|
||||||
List<String> ambientDirectives) async {
|
List<String> platformDirectives) async {
|
||||||
if (!(await reader.hasInput(assetId))) return null;
|
if (!(await reader.hasInput(assetId))) return null;
|
||||||
final json = await reader.readAsString(assetId);
|
final json = await reader.readAsString(assetId);
|
||||||
if (json == null || json.isEmpty) return null;
|
if (json == null || json.isEmpty) return null;
|
||||||
|
|
||||||
final ngMeta = new NgMeta.fromJson(JSON.decode(json));
|
final ngMeta = new NgMeta.fromJson(JSON.decode(json));
|
||||||
return new _CompileDataCreator(reader, assetId, ngMeta, ambientDirectives);
|
return new _CompileDataCreator(reader, assetId, ngMeta, platformDirectives);
|
||||||
}
|
}
|
||||||
|
|
||||||
NgDepsModel get ngDeps => ngMeta.ngDeps;
|
NgDepsModel get ngDeps => ngMeta.ngDeps;
|
||||||
|
@ -67,7 +67,7 @@ class _CompileDataCreator {
|
||||||
final compileData =
|
final compileData =
|
||||||
<ReflectionInfoModel, NormalizedComponentWithViewDirectives>{};
|
<ReflectionInfoModel, NormalizedComponentWithViewDirectives>{};
|
||||||
final ngMetaMap = await _extractNgMeta();
|
final ngMetaMap = await _extractNgMeta();
|
||||||
final ambientDirectives = await _readAmbientDirectives();
|
final platformDirectives = await _readPlatformDirectives();
|
||||||
|
|
||||||
for (var reflectable in ngDeps.reflectables) {
|
for (var reflectable in ngDeps.reflectables) {
|
||||||
if (ngMeta.types.containsKey(reflectable.name)) {
|
if (ngMeta.types.containsKey(reflectable.name)) {
|
||||||
|
@ -75,7 +75,7 @@ class _CompileDataCreator {
|
||||||
if (compileDirectiveMetadata.template != null) {
|
if (compileDirectiveMetadata.template != null) {
|
||||||
final compileDatum = new NormalizedComponentWithViewDirectives(
|
final compileDatum = new NormalizedComponentWithViewDirectives(
|
||||||
compileDirectiveMetadata, <CompileDirectiveMetadata>[]);
|
compileDirectiveMetadata, <CompileDirectiveMetadata>[]);
|
||||||
compileDatum.directives.addAll(ambientDirectives);
|
compileDatum.directives.addAll(platformDirectives);
|
||||||
|
|
||||||
for (var dep in reflectable.directives) {
|
for (var dep in reflectable.directives) {
|
||||||
if (!ngMetaMap.containsKey(dep.prefix)) {
|
if (!ngMetaMap.containsKey(dep.prefix)) {
|
||||||
|
@ -105,23 +105,23 @@ class _CompileDataCreator {
|
||||||
return new CompileDataResults._(ngMeta, compileData);
|
return new CompileDataResults._(ngMeta, compileData);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<List<CompileDirectiveMetadata>> _readAmbientDirectives() async {
|
Future<List<CompileDirectiveMetadata>> _readPlatformDirectives() async {
|
||||||
if (ambientDirectives == null) return const [];
|
if (platformDirectives == null) return const [];
|
||||||
|
|
||||||
final res = [];
|
final res = [];
|
||||||
for (var ad in ambientDirectives) {
|
for (var ad in platformDirectives) {
|
||||||
final parts = ad.split("#");
|
final parts = ad.split("#");
|
||||||
if (parts.length != 2) {
|
if (parts.length != 2) {
|
||||||
log.warning('The ambient directives configuration option '
|
log.warning('The platform directives configuration option '
|
||||||
'must be in the following format: "URI#TOKEN"');
|
'must be in the following format: "URI#TOKEN"');
|
||||||
return const [];
|
return const [];
|
||||||
}
|
}
|
||||||
res.addAll(await _readAmbientDirectivesFromUri(parts[0], parts[1]));
|
res.addAll(await _readPlatformDirectivesFromUri(parts[0], parts[1]));
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<List<CompileDirectiveMetadata>> _readAmbientDirectivesFromUri(
|
Future<List<CompileDirectiveMetadata>> _readPlatformDirectivesFromUri(
|
||||||
String uri, String token) async {
|
String uri, String token) async {
|
||||||
final metaAssetId = fromUri(toMetaExtension(uri));
|
final metaAssetId = fromUri(toMetaExtension(uri));
|
||||||
if (await reader.hasInput(metaAssetId)) {
|
if (await reader.hasInput(metaAssetId)) {
|
||||||
|
@ -136,7 +136,7 @@ class _CompileDataCreator {
|
||||||
return newMetadata.flatten(token);
|
return newMetadata.flatten(token);
|
||||||
} else {
|
} else {
|
||||||
log.warning(
|
log.warning(
|
||||||
'Could not resolve ambient directive ${token} in ${uri}',
|
'Could not resolve platform directive ${token} in ${uri}',
|
||||||
asset: metaAssetId);
|
asset: metaAssetId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,9 +29,9 @@ import 'compile_data_creator.dart';
|
||||||
/// This method assumes a {@link DomAdapter} has been registered.
|
/// This method assumes a {@link DomAdapter} has been registered.
|
||||||
Future<Outputs> processTemplates(AssetReader reader, AssetId assetId,
|
Future<Outputs> processTemplates(AssetReader reader, AssetId assetId,
|
||||||
{bool reflectPropertiesAsAttributes: false,
|
{bool reflectPropertiesAsAttributes: false,
|
||||||
List<String> ambientDirectives}) async {
|
List<String> platformDirectives}) async {
|
||||||
var viewDefResults =
|
var viewDefResults =
|
||||||
await createCompileData(reader, assetId, ambientDirectives);
|
await createCompileData(reader, assetId, platformDirectives);
|
||||||
if (viewDefResults == null) return null;
|
if (viewDefResults == null) return null;
|
||||||
final directiveMetadatas = viewDefResults.ngMeta.types.values;
|
final directiveMetadatas = viewDefResults.ngMeta.types.values;
|
||||||
if (directiveMetadatas.isNotEmpty) {
|
if (directiveMetadatas.isNotEmpty) {
|
||||||
|
|
|
@ -39,7 +39,7 @@ class TemplateCompiler extends Transformer {
|
||||||
var reader = new AssetReader.fromTransform(transform);
|
var reader = new AssetReader.fromTransform(transform);
|
||||||
var outputs = await processTemplates(reader, primaryId,
|
var outputs = await processTemplates(reader, primaryId,
|
||||||
reflectPropertiesAsAttributes: options.reflectPropertiesAsAttributes,
|
reflectPropertiesAsAttributes: options.reflectPropertiesAsAttributes,
|
||||||
ambientDirectives: options.ambientDirectives);
|
platformDirectives: options.platformDirectives);
|
||||||
var ngDepsCode = _emptyNgDepsContents;
|
var ngDepsCode = _emptyNgDepsContents;
|
||||||
var templatesCode = '';
|
var templatesCode = '';
|
||||||
if (outputs != null) {
|
if (outputs != null) {
|
||||||
|
|
|
@ -75,11 +75,11 @@ void allTests() {
|
||||||
updateReader();
|
updateReader();
|
||||||
});
|
});
|
||||||
|
|
||||||
Future<String> process(AssetId assetId, {List<String> ambientDirectives}) {
|
Future<String> process(AssetId assetId, {List<String> platformDirectives}) {
|
||||||
logger = new RecordingLogger();
|
logger = new RecordingLogger();
|
||||||
return zone.exec(
|
return zone.exec(
|
||||||
() => processTemplates(reader, assetId,
|
() => processTemplates(reader, assetId,
|
||||||
ambientDirectives: ambientDirectives),
|
platformDirectives: platformDirectives),
|
||||||
log: logger);
|
log: logger);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -351,17 +351,17 @@ void allTests() {
|
||||||
expect(didThrow).toBeFalse();
|
expect(didThrow).toBeFalse();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should include ambient directives.', () async {
|
it('should include platform directives.', () async {
|
||||||
fooComponentMeta.template = new CompileTemplateMetadata(template: '<bar/>');
|
fooComponentMeta.template = new CompileTemplateMetadata(template: '<bar/>');
|
||||||
final viewAnnotation = new AnnotationModel()
|
final viewAnnotation = new AnnotationModel()
|
||||||
..name = 'View'
|
..name = 'View'
|
||||||
..isView = true;
|
..isView = true;
|
||||||
|
|
||||||
barNgMeta.aliases['AMBIENT'] = [barComponentMeta.type.name];
|
barNgMeta.aliases['PLATFORM'] = [barComponentMeta.type.name];
|
||||||
updateReader();
|
updateReader();
|
||||||
|
|
||||||
final outputs = await process(fooAssetId,
|
final outputs = await process(fooAssetId,
|
||||||
ambientDirectives: ['package:a/bar.dart#AMBIENT']);
|
platformDirectives: ['package:a/bar.dart#PLATFORM']);
|
||||||
final ngDeps = outputs.ngDeps;
|
final ngDeps = outputs.ngDeps;
|
||||||
expect(ngDeps).toBeNotNull();
|
expect(ngDeps).toBeNotNull();
|
||||||
expect(outputs.templatesCode)
|
expect(outputs.templatesCode)
|
||||||
|
@ -369,17 +369,17 @@ void allTests() {
|
||||||
..toContain(barComponentMeta.template.template);
|
..toContain(barComponentMeta.template.template);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should include ambient directives when it it a list.', () async {
|
it('should include platform directives when it it a list.', () async {
|
||||||
fooComponentMeta.template = new CompileTemplateMetadata(template: '<bar/>');
|
fooComponentMeta.template = new CompileTemplateMetadata(template: '<bar/>');
|
||||||
final viewAnnotation = new AnnotationModel()
|
final viewAnnotation = new AnnotationModel()
|
||||||
..name = 'View'
|
..name = 'View'
|
||||||
..isView = true;
|
..isView = true;
|
||||||
|
|
||||||
barNgMeta.types['AMBIENT'] = barComponentMeta;
|
barNgMeta.types['PLATFORM'] = barComponentMeta;
|
||||||
updateReader();
|
updateReader();
|
||||||
|
|
||||||
final outputs = await process(fooAssetId,
|
final outputs = await process(fooAssetId,
|
||||||
ambientDirectives: ['package:a/bar.dart#AMBIENT']);
|
platformDirectives: ['package:a/bar.dart#PLATFORM']);
|
||||||
final ngDeps = outputs.ngDeps;
|
final ngDeps = outputs.ngDeps;
|
||||||
expect(ngDeps).toBeNotNull();
|
expect(ngDeps).toBeNotNull();
|
||||||
expect(outputs.templatesCode)
|
expect(outputs.templatesCode)
|
||||||
|
@ -387,31 +387,31 @@ void allTests() {
|
||||||
..toContain(barComponentMeta.template.template);
|
..toContain(barComponentMeta.template.template);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should work when ambient directives config is null.', () async {
|
it('should work when platform directives config is null.', () async {
|
||||||
final outputs = await process(fooAssetId, ambientDirectives: null);
|
final outputs = await process(fooAssetId, platformDirectives: null);
|
||||||
final ngDeps = outputs.ngDeps;
|
final ngDeps = outputs.ngDeps;
|
||||||
expect(ngDeps).toBeNotNull();
|
expect(ngDeps).toBeNotNull();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should work when the ambient directives config is not formatted properly.',
|
it('should work when the platform directives config is not formatted properly.',
|
||||||
() async {
|
() async {
|
||||||
final outputs = await process(fooAssetId, ambientDirectives: ['INVALID']);
|
final outputs = await process(fooAssetId, platformDirectives: ['INVALID']);
|
||||||
final ngDeps = outputs.ngDeps;
|
final ngDeps = outputs.ngDeps;
|
||||||
expect(ngDeps).toBeNotNull();
|
expect(ngDeps).toBeNotNull();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should work when the file with ambient directives cannot be found.',
|
it('should work when the file with platform directives cannot be found.',
|
||||||
() async {
|
() async {
|
||||||
final outputs = await process(fooAssetId,
|
final outputs = await process(fooAssetId,
|
||||||
ambientDirectives: ['package:a/invalid.dart#AMBIENT']);
|
platformDirectives: ['package:a/invalid.dart#PLATFORM']);
|
||||||
final ngDeps = outputs.ngDeps;
|
final ngDeps = outputs.ngDeps;
|
||||||
expect(ngDeps).toBeNotNull();
|
expect(ngDeps).toBeNotNull();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should work when the ambient directives token cannot be found.',
|
it('should work when the platform directives token cannot be found.',
|
||||||
() async {
|
() async {
|
||||||
final outputs = await process(fooAssetId,
|
final outputs = await process(fooAssetId,
|
||||||
ambientDirectives: ['package:a/bar.dart#AMBIENT']);
|
platformDirectives: ['package:a/bar.dart#PLATFORM']);
|
||||||
final ngDeps = outputs.ngDeps;
|
final ngDeps = outputs.ngDeps;
|
||||||
expect(ngDeps).toBeNotNull();
|
expect(ngDeps).toBeNotNull();
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue