2015-03-20 15:37:09 -07:00
|
|
|
library angular2.transform.reflection_remover.transformer;
|
2015-02-27 14:42:21 -08:00
|
|
|
|
|
|
|
|
import 'dart:async';
|
2015-04-09 17:49:11 -07:00
|
|
|
import 'package:angular2/src/transform/common/asset_reader.dart';
|
2015-02-27 14:42:21 -08:00
|
|
|
import 'package:angular2/src/transform/common/logging.dart' as log;
|
2015-04-17 11:12:35 -07:00
|
|
|
import 'package:angular2/src/transform/common/mirror_mode.dart';
|
2015-02-27 14:42:21 -08:00
|
|
|
import 'package:angular2/src/transform/common/names.dart';
|
|
|
|
|
import 'package:angular2/src/transform/common/options.dart';
|
|
|
|
|
import 'package:barback/barback.dart';
|
|
|
|
|
|
|
|
|
|
import 'remove_reflection_capabilities.dart';
|
|
|
|
|
|
|
|
|
|
/// Transformer responsible for removing the import and instantiation of
|
2015-04-17 13:01:07 -07:00
|
|
|
/// {@link ReflectionCapabilities}.
|
2015-02-27 14:42:21 -08:00
|
|
|
///
|
|
|
|
|
/// The goal of this is to break the app's dependency on dart:mirrors.
|
|
|
|
|
///
|
2015-04-17 13:01:07 -07:00
|
|
|
/// This transformer assumes that {@link DirectiveProcessor} and {@link DirectiveLinker}
|
2015-03-16 13:32:29 -07:00
|
|
|
/// have already been run and that a .ng_deps.dart file has been generated for
|
2015-04-17 13:01:07 -07:00
|
|
|
/// {@link options.entryPoint}. The instantiation of {@link ReflectionCapabilities} is
|
2015-03-16 13:32:29 -07:00
|
|
|
/// replaced by calling `setupReflection` in that .ng_deps.dart file.
|
2015-02-27 14:42:21 -08:00
|
|
|
class ReflectionRemover extends Transformer {
|
|
|
|
|
final TransformerOptions options;
|
|
|
|
|
|
|
|
|
|
ReflectionRemover(this.options);
|
|
|
|
|
|
|
|
|
|
@override
|
2015-04-09 17:49:11 -07:00
|
|
|
bool isPrimary(AssetId id) => options.reflectionEntryPoints != null &&
|
|
|
|
|
options.reflectionEntryPoints.contains(id.path);
|
2015-02-27 14:42:21 -08:00
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Future apply(Transform transform) async {
|
|
|
|
|
log.init(transform);
|
|
|
|
|
|
|
|
|
|
try {
|
2015-04-09 17:49:11 -07:00
|
|
|
var newEntryPoints = options.entryPoints.map((entryPoint) {
|
|
|
|
|
return new AssetId(transform.primaryInput.id.package, entryPoint)
|
|
|
|
|
.changeExtension(DEPS_EXTENSION);
|
|
|
|
|
});
|
|
|
|
|
var reader = new AssetReader.fromTransform(transform);
|
2015-02-27 14:42:21 -08:00
|
|
|
|
2015-04-17 11:12:35 -07:00
|
|
|
var mirrorMode = options.mirrorMode;
|
|
|
|
|
var writeStaticInit = options.initReflector;
|
|
|
|
|
if (options.modeName == TRANSFORM_DYNAMIC_MODE) {
|
|
|
|
|
mirrorMode = MirrorMode.debug;
|
|
|
|
|
writeStaticInit = false;
|
|
|
|
|
log.logger.info('Running in "${options.modeName}", '
|
|
|
|
|
'mirrorMode: ${mirrorMode}, '
|
|
|
|
|
'writeStaticInit: ${writeStaticInit}.');
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-09 17:49:11 -07:00
|
|
|
var transformedCode = await removeReflectionCapabilities(
|
2015-04-17 11:12:35 -07:00
|
|
|
reader, transform.primaryInput.id, newEntryPoints,
|
|
|
|
|
mirrorMode: mirrorMode, writeStaticInit: writeStaticInit);
|
2015-04-09 17:49:11 -07:00
|
|
|
transform.addOutput(
|
|
|
|
|
new Asset.fromString(transform.primaryInput.id, transformedCode));
|
2015-02-27 14:42:21 -08:00
|
|
|
} catch (ex, stackTrace) {
|
|
|
|
|
log.logger.error('Removing reflection failed.\n'
|
|
|
|
|
'Exception: $ex\n'
|
|
|
|
|
'Stack Trace: $stackTrace');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|