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:
vsavkin
2015-11-09 14:33:22 -08:00
committed by Victor Savkin
parent 2618becaa5
commit e27665c368
16 changed files with 72 additions and 72 deletions

View File

@ -11,7 +11,7 @@ const FORMAT_CODE_PARAM = 'format_code';
const REFLECT_PROPERTIES_AS_ATTRIBUTES = 'reflect_properties_as_attributes';
// TODO(kegluenq): Remove this after 30 Nov (i/5108).
const REFLECT_PROPERTIES_AS_ATTRIBUTES_OLD = 'reflectPropertiesAsAttributes';
const AMBIENT_DIRECTIVES = 'ambient_directives';
const PLATFORM_DIRECTIVES = 'platform_directives';
const INIT_REFLECTOR_PARAM = 'init_reflector';
const INLINE_VIEWS_PARAM = 'inline_views';
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
/// 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.
/// Code that is only modified will never be formatted because doing so may
@ -64,7 +64,7 @@ class TransformerOptions {
this.initReflector,
this.annotationMatcher,
{this.reflectPropertiesAsAttributes,
this.ambientDirectives,
this.platformDirectives,
this.inlineViews,
this.formatCode});
@ -75,7 +75,7 @@ class TransformerOptions {
List<ClassDescriptor> customAnnotationDescriptors: const [],
bool inlineViews: false,
bool reflectPropertiesAsAttributes: true,
List<String> ambientDirectives,
List<String> platformDirectives,
bool formatCode: false}) {
var annotationMatcher = new AnnotationMatcher()
..addAll(customAnnotationDescriptors);
@ -85,7 +85,7 @@ class TransformerOptions {
return new TransformerOptions._internal(entryPoints, entryPointGlobs,
modeName, mirrorMode, initReflector, annotationMatcher,
reflectPropertiesAsAttributes: reflectPropertiesAsAttributes,
ambientDirectives: ambientDirectives,
platformDirectives: platformDirectives,
inlineViews: inlineViews,
formatCode: formatCode);
}

View File

@ -18,7 +18,7 @@ TransformerOptions parseBarbackSettings(BarbackSettings settings) {
config, REFLECT_PROPERTIES_AS_ATTRIBUTES_OLD,
defaultValue: false);
}
var ambientDirectives = _readStringList(config, AMBIENT_DIRECTIVES);
var platformDirectives = _readStringList(config, PLATFORM_DIRECTIVES);
var formatCode = _readBool(config, FORMAT_CODE_PARAM, defaultValue: false);
String mirrorModeVal =
config.containsKey(MIRROR_MODE_PARAM) ? config[MIRROR_MODE_PARAM] : '';
@ -40,7 +40,7 @@ TransformerOptions parseBarbackSettings(BarbackSettings settings) {
initReflector: initReflector,
customAnnotationDescriptors: _readCustomAnnotations(config),
reflectPropertiesAsAttributes: reflectPropertiesAsAttributes,
ambientDirectives: ambientDirectives,
platformDirectives: platformDirectives,
inlineViews: _readBool(config, INLINE_VIEWS_PARAM, defaultValue: false),
formatCode: formatCode);
}

View File

@ -20,10 +20,10 @@ import 'package:barback/barback.dart';
/// The returned value wraps the [NgDepsModel] at `assetId` as well as these
/// created objects.
Future<CompileDataResults> createCompileData(
AssetReader reader, AssetId assetId, List<String> ambientDirectives) async {
AssetReader reader, AssetId assetId, List<String> platformDirectives) async {
return logElapsedAsync(() async {
final creator =
await _CompileDataCreator.create(reader, assetId, ambientDirectives);
await _CompileDataCreator.create(reader, assetId, platformDirectives);
return creator != null ? creator.createCompileData() : null;
}, operationName: 'createCompileData', assetId: assetId);
}
@ -42,19 +42,19 @@ class _CompileDataCreator {
final AssetReader reader;
final AssetId entryPoint;
final NgMeta ngMeta;
final List<String> ambientDirectives;
final List<String> platformDirectives;
_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,
List<String> ambientDirectives) async {
List<String> platformDirectives) async {
if (!(await reader.hasInput(assetId))) return null;
final json = await reader.readAsString(assetId);
if (json == null || json.isEmpty) return null;
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;
@ -67,7 +67,7 @@ class _CompileDataCreator {
final compileData =
<ReflectionInfoModel, NormalizedComponentWithViewDirectives>{};
final ngMetaMap = await _extractNgMeta();
final ambientDirectives = await _readAmbientDirectives();
final platformDirectives = await _readPlatformDirectives();
for (var reflectable in ngDeps.reflectables) {
if (ngMeta.types.containsKey(reflectable.name)) {
@ -75,7 +75,7 @@ class _CompileDataCreator {
if (compileDirectiveMetadata.template != null) {
final compileDatum = new NormalizedComponentWithViewDirectives(
compileDirectiveMetadata, <CompileDirectiveMetadata>[]);
compileDatum.directives.addAll(ambientDirectives);
compileDatum.directives.addAll(platformDirectives);
for (var dep in reflectable.directives) {
if (!ngMetaMap.containsKey(dep.prefix)) {
@ -105,23 +105,23 @@ class _CompileDataCreator {
return new CompileDataResults._(ngMeta, compileData);
}
Future<List<CompileDirectiveMetadata>> _readAmbientDirectives() async {
if (ambientDirectives == null) return const [];
Future<List<CompileDirectiveMetadata>> _readPlatformDirectives() async {
if (platformDirectives == null) return const [];
final res = [];
for (var ad in ambientDirectives) {
for (var ad in platformDirectives) {
final parts = ad.split("#");
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"');
return const [];
}
res.addAll(await _readAmbientDirectivesFromUri(parts[0], parts[1]));
res.addAll(await _readPlatformDirectivesFromUri(parts[0], parts[1]));
}
return res;
}
Future<List<CompileDirectiveMetadata>> _readAmbientDirectivesFromUri(
Future<List<CompileDirectiveMetadata>> _readPlatformDirectivesFromUri(
String uri, String token) async {
final metaAssetId = fromUri(toMetaExtension(uri));
if (await reader.hasInput(metaAssetId)) {
@ -136,7 +136,7 @@ class _CompileDataCreator {
return newMetadata.flatten(token);
} else {
log.warning(
'Could not resolve ambient directive ${token} in ${uri}',
'Could not resolve platform directive ${token} in ${uri}',
asset: metaAssetId);
}
}

View File

@ -29,9 +29,9 @@ import 'compile_data_creator.dart';
/// This method assumes a {@link DomAdapter} has been registered.
Future<Outputs> processTemplates(AssetReader reader, AssetId assetId,
{bool reflectPropertiesAsAttributes: false,
List<String> ambientDirectives}) async {
List<String> platformDirectives}) async {
var viewDefResults =
await createCompileData(reader, assetId, ambientDirectives);
await createCompileData(reader, assetId, platformDirectives);
if (viewDefResults == null) return null;
final directiveMetadatas = viewDefResults.ngMeta.types.values;
if (directiveMetadatas.isNotEmpty) {

View File

@ -39,7 +39,7 @@ class TemplateCompiler extends Transformer {
var reader = new AssetReader.fromTransform(transform);
var outputs = await processTemplates(reader, primaryId,
reflectPropertiesAsAttributes: options.reflectPropertiesAsAttributes,
ambientDirectives: options.ambientDirectives);
platformDirectives: options.platformDirectives);
var ngDepsCode = _emptyNgDepsContents;
var templatesCode = '';
if (outputs != null) {

View File

@ -75,11 +75,11 @@ void allTests() {
updateReader();
});
Future<String> process(AssetId assetId, {List<String> ambientDirectives}) {
Future<String> process(AssetId assetId, {List<String> platformDirectives}) {
logger = new RecordingLogger();
return zone.exec(
() => processTemplates(reader, assetId,
ambientDirectives: ambientDirectives),
platformDirectives: platformDirectives),
log: logger);
}
@ -351,17 +351,17 @@ void allTests() {
expect(didThrow).toBeFalse();
});
it('should include ambient directives.', () async {
it('should include platform directives.', () async {
fooComponentMeta.template = new CompileTemplateMetadata(template: '<bar/>');
final viewAnnotation = new AnnotationModel()
..name = 'View'
..isView = true;
barNgMeta.aliases['AMBIENT'] = [barComponentMeta.type.name];
barNgMeta.aliases['PLATFORM'] = [barComponentMeta.type.name];
updateReader();
final outputs = await process(fooAssetId,
ambientDirectives: ['package:a/bar.dart#AMBIENT']);
platformDirectives: ['package:a/bar.dart#PLATFORM']);
final ngDeps = outputs.ngDeps;
expect(ngDeps).toBeNotNull();
expect(outputs.templatesCode)
@ -369,17 +369,17 @@ void allTests() {
..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/>');
final viewAnnotation = new AnnotationModel()
..name = 'View'
..isView = true;
barNgMeta.types['AMBIENT'] = barComponentMeta;
barNgMeta.types['PLATFORM'] = barComponentMeta;
updateReader();
final outputs = await process(fooAssetId,
ambientDirectives: ['package:a/bar.dart#AMBIENT']);
platformDirectives: ['package:a/bar.dart#PLATFORM']);
final ngDeps = outputs.ngDeps;
expect(ngDeps).toBeNotNull();
expect(outputs.templatesCode)
@ -387,31 +387,31 @@ void allTests() {
..toContain(barComponentMeta.template.template);
});
it('should work when ambient directives config is null.', () async {
final outputs = await process(fooAssetId, ambientDirectives: null);
it('should work when platform directives config is null.', () async {
final outputs = await process(fooAssetId, platformDirectives: null);
final ngDeps = outputs.ngDeps;
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 {
final outputs = await process(fooAssetId, ambientDirectives: ['INVALID']);
final outputs = await process(fooAssetId, platformDirectives: ['INVALID']);
final ngDeps = outputs.ngDeps;
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 {
final outputs = await process(fooAssetId,
ambientDirectives: ['package:a/invalid.dart#AMBIENT']);
platformDirectives: ['package:a/invalid.dart#PLATFORM']);
final ngDeps = outputs.ngDeps;
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 {
final outputs = await process(fooAssetId,
ambientDirectives: ['package:a/bar.dart#AMBIENT']);
platformDirectives: ['package:a/bar.dart#PLATFORM']);
final ngDeps = outputs.ngDeps;
expect(ngDeps).toBeNotNull();
});