style(dart/transform): Do not format generated code by default
Formatting code requires time and memory during the build -- do not do it unless explicitly requested via a parameter to the transformer. Add an entry to the [wiki](https://github.com/angular/angular/wiki/Angular-2-Dart-Transformer) describing the added parameter.
This commit is contained in:
parent
3db0ae1dac
commit
40a3cd2ab1
|
@ -2,18 +2,31 @@ library angular2.transform.common.formatter;
|
|||
|
||||
import 'package:dart_style/dart_style.dart';
|
||||
|
||||
import 'logging.dart';
|
||||
|
||||
DartFormatter _formatter = null;
|
||||
AngularDartFormatter _formatter = null;
|
||||
|
||||
void init(DartFormatter formatter) {
|
||||
_formatter = formatter;
|
||||
_formatter = new _RealFormatter(formatter);
|
||||
}
|
||||
|
||||
DartFormatter get formatter {
|
||||
AngularDartFormatter get formatter {
|
||||
if (_formatter == null) {
|
||||
logger.info('Formatter never initialized, using default formatter.');
|
||||
_formatter = new DartFormatter();
|
||||
_formatter = new _PassThroughFormatter();
|
||||
}
|
||||
return _formatter;
|
||||
}
|
||||
|
||||
abstract class AngularDartFormatter {
|
||||
String format(String source, {uri});
|
||||
}
|
||||
|
||||
class _PassThroughFormatter implements AngularDartFormatter {
|
||||
String format(String source, {uri}) => source;
|
||||
}
|
||||
|
||||
class _RealFormatter implements AngularDartFormatter {
|
||||
final DartFormatter _formatter;
|
||||
|
||||
_RealFormatter(this._formatter);
|
||||
|
||||
String format(source, {uri}) => _formatter.format(source, uri: uri);
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ const DEFAULT_OPTIMIZATION_PHASES = 5;
|
|||
|
||||
const CUSTOM_ANNOTATIONS_PARAM = 'custom_annotations';
|
||||
const ENTRY_POINT_PARAM = 'entry_points';
|
||||
const FORMAT_CODE_PARAM = 'format_code';
|
||||
const GENERATE_CHANGE_DETECTORS_PARAM = 'generate_change_detectors';
|
||||
const INIT_REFLECTOR_PARAM = 'init_reflector';
|
||||
const INLINE_VIEWS_PARAM = 'inline_views';
|
||||
|
@ -51,6 +52,11 @@ class TransformerOptions {
|
|||
/// The "correct" number of phases varies with the structure of the app.
|
||||
final int optimizationPhases;
|
||||
|
||||
/// Whether to format generated code.
|
||||
/// Code that is only modified will never be formatted because doing so may
|
||||
/// invalidate the source maps generated by `dart2js` and/or other tools.
|
||||
final bool formatCode;
|
||||
|
||||
TransformerOptions._internal(
|
||||
this.entryPoints,
|
||||
this.reflectionEntryPoints,
|
||||
|
@ -59,8 +65,9 @@ class TransformerOptions {
|
|||
this.initReflector,
|
||||
this.annotationMatcher,
|
||||
this.optimizationPhases,
|
||||
this.generateChangeDetectors,
|
||||
this.inlineViews);
|
||||
{this.generateChangeDetectors,
|
||||
this.inlineViews,
|
||||
this.formatCode});
|
||||
|
||||
factory TransformerOptions(List<String> entryPoints,
|
||||
{List<String> reflectionEntryPoints,
|
||||
|
@ -70,7 +77,8 @@ class TransformerOptions {
|
|||
List<ClassDescriptor> customAnnotationDescriptors: const [],
|
||||
int optimizationPhases: DEFAULT_OPTIMIZATION_PHASES,
|
||||
bool inlineViews: true,
|
||||
bool generateChangeDetectors: true}) {
|
||||
bool generateChangeDetectors: true,
|
||||
bool formatCode: false}) {
|
||||
if (reflectionEntryPoints == null || reflectionEntryPoints.isEmpty) {
|
||||
reflectionEntryPoints = entryPoints;
|
||||
}
|
||||
|
@ -85,7 +93,8 @@ class TransformerOptions {
|
|||
initReflector,
|
||||
annotationMatcher,
|
||||
optimizationPhases,
|
||||
generateChangeDetectors,
|
||||
inlineViews);
|
||||
generateChangeDetectors: generateChangeDetectors,
|
||||
inlineViews: inlineViews,
|
||||
formatCode: formatCode);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ TransformerOptions parseBarbackSettings(BarbackSettings settings) {
|
|||
var inlineViews = _readBool(config, INLINE_VIEWS_PARAM, defaultValue: true);
|
||||
var generateChangeDetectors =
|
||||
_readBool(config, GENERATE_CHANGE_DETECTORS_PARAM, defaultValue: true);
|
||||
var formatCode = _readBool(config, FORMAT_CODE_PARAM, defaultValue: false);
|
||||
String mirrorModeVal =
|
||||
config.containsKey(MIRROR_MODE_PARAM) ? config[MIRROR_MODE_PARAM] : '';
|
||||
var mirrorMode = MirrorMode.none;
|
||||
|
@ -39,7 +40,8 @@ TransformerOptions parseBarbackSettings(BarbackSettings settings) {
|
|||
inlineViews: inlineViews,
|
||||
customAnnotationDescriptors: _readCustomAnnotations(config),
|
||||
optimizationPhases: optimizationPhases,
|
||||
generateChangeDetectors: generateChangeDetectors);
|
||||
generateChangeDetectors: generateChangeDetectors,
|
||||
formatCode: formatCode);
|
||||
}
|
||||
|
||||
bool _readBool(Map config, String paramName, {bool defaultValue}) {
|
||||
|
|
|
@ -18,8 +18,10 @@ export 'common/options.dart';
|
|||
|
||||
/// Replaces Angular 2 mirror use with generated code.
|
||||
class AngularTransformerGroup extends TransformerGroup {
|
||||
AngularTransformerGroup._(phases) : super(phases) {
|
||||
formatter.init(new DartFormatter());
|
||||
AngularTransformerGroup._(phases, {bool formatCode: false}) : super(phases) {
|
||||
if (formatCode) {
|
||||
formatter.init(new DartFormatter());
|
||||
}
|
||||
}
|
||||
|
||||
factory AngularTransformerGroup(TransformerOptions options) {
|
||||
|
@ -38,7 +40,8 @@ class AngularTransformerGroup extends TransformerGroup {
|
|||
[new BindGenerator(options)],
|
||||
[new TemplateCompiler(options)]
|
||||
]);
|
||||
return new AngularTransformerGroup._(phases);
|
||||
return new AngularTransformerGroup._(phases,
|
||||
formatCode: options.formatCode);
|
||||
}
|
||||
|
||||
factory AngularTransformerGroup.asPlugin(BarbackSettings settings) {
|
||||
|
|
|
@ -14,7 +14,8 @@ main() {
|
|||
var formatter = new DartFormatter();
|
||||
var transform = new AngularTransformerGroup(new TransformerOptions(
|
||||
['web/index.dart'],
|
||||
reflectionEntryPoints: ['web/index.dart']));
|
||||
reflectionEntryPoints: ['web/index.dart'],
|
||||
formatCode: true));
|
||||
|
||||
class IntegrationTestConfig {
|
||||
final String name;
|
||||
|
|
Loading…
Reference in New Issue