feat(dart/transform): Track timing of transform tasks
This commit is contained in:
parent
aee176115b
commit
07572652ff
|
@ -51,6 +51,24 @@ BuildLogger get logger {
|
|||
return current == null ? new PrintLogger() : current;
|
||||
}
|
||||
|
||||
/// Writes a log entry at `LogLevel.FINE` granularity with the time taken by
|
||||
/// `asyncOperation`.
|
||||
///
|
||||
/// Returns the result of executing `asyncOperation`.
|
||||
Future logElapsedAsync(Future asyncOperation(),
|
||||
{String operationName: 'unknown', AssetId assetId}) async {
|
||||
final timer = new Stopwatch()..start();
|
||||
final result = await asyncOperation();
|
||||
timer.stop();
|
||||
final buf =
|
||||
new StringBuffer('[$operationName] took ${timer.elapsedMilliseconds} ms');
|
||||
if (assetId != null) {
|
||||
buf.write(' on $assetId');
|
||||
}
|
||||
logger.fine(buf.toString(), asset: assetId);
|
||||
return result;
|
||||
}
|
||||
|
||||
class PrintLogger implements BuildLogger {
|
||||
@override
|
||||
final String detailsUri = '';
|
||||
|
|
|
@ -30,40 +30,42 @@ class Rewriter {
|
|||
var node = parseCompilationUnit(code);
|
||||
if (node == null) return null;
|
||||
|
||||
var visitor = new _FindDeferredLibraries(_reader, _entryPoint);
|
||||
node.accept(visitor);
|
||||
// Look to see if we found any deferred libraries
|
||||
if (!visitor.hasDeferredLibrariesToRewrite()) return null;
|
||||
// Remove any libraries that don't need angular codegen.
|
||||
await visitor.cull();
|
||||
// Check again if there are any deferred libraries.
|
||||
if (!visitor.hasDeferredLibrariesToRewrite()) return null;
|
||||
return logElapsedAsync(() async {
|
||||
var visitor = new _FindDeferredLibraries(_reader, _entryPoint);
|
||||
node.accept(visitor);
|
||||
// Look to see if we found any deferred libraries
|
||||
if (!visitor.hasDeferredLibrariesToRewrite()) return null;
|
||||
// Remove any libraries that don't need angular codegen.
|
||||
await visitor.cull();
|
||||
// Check again if there are any deferred libraries.
|
||||
if (!visitor.hasDeferredLibrariesToRewrite()) return null;
|
||||
|
||||
var compare = (AstNode a, AstNode b) => a.offset - b.offset;
|
||||
visitor.deferredImports.sort(compare);
|
||||
visitor.loadLibraryInvocations.sort(compare);
|
||||
var compare = (AstNode a, AstNode b) => a.offset - b.offset;
|
||||
visitor.deferredImports.sort(compare);
|
||||
visitor.loadLibraryInvocations.sort(compare);
|
||||
|
||||
var buf = new StringBuffer();
|
||||
var idx =
|
||||
visitor.deferredImports.fold(0, (int lastIdx, ImportDirective node) {
|
||||
buf.write(code.substring(lastIdx, node.offset));
|
||||
var buf = new StringBuffer();
|
||||
var idx =
|
||||
visitor.deferredImports.fold(0, (int lastIdx, ImportDirective node) {
|
||||
buf.write(code.substring(lastIdx, node.offset));
|
||||
|
||||
var import = code.substring(node.offset, node.end);
|
||||
buf.write(import.replaceFirst('.dart', DEPS_EXTENSION));
|
||||
return node.end;
|
||||
});
|
||||
var import = code.substring(node.offset, node.end);
|
||||
buf.write(import.replaceFirst('.dart', DEPS_EXTENSION));
|
||||
return node.end;
|
||||
});
|
||||
|
||||
idx = visitor.loadLibraryInvocations.fold(idx,
|
||||
(int lastIdx, MethodInvocation node) {
|
||||
buf.write(code.substring(lastIdx, node.offset));
|
||||
var value = node.realTarget as SimpleIdentifier;
|
||||
var prefix = value.name;
|
||||
// Chain a future that initializes the reflector.
|
||||
buf.write('$prefix.loadLibrary().then((_) {$prefix.initReflector();})');
|
||||
return node.end;
|
||||
});
|
||||
if (idx < code.length) buf.write(code.substring(idx));
|
||||
return '$buf';
|
||||
idx = visitor.loadLibraryInvocations.fold(idx,
|
||||
(int lastIdx, MethodInvocation node) {
|
||||
buf.write(code.substring(lastIdx, node.offset));
|
||||
var value = node.realTarget as SimpleIdentifier;
|
||||
var prefix = value.name;
|
||||
// Chain a future that initializes the reflector.
|
||||
buf.write('$prefix.loadLibrary().then((_) {$prefix.initReflector();})');
|
||||
return node.end;
|
||||
});
|
||||
if (idx < code.length) buf.write(code.substring(idx));
|
||||
return '$buf';
|
||||
}, operationName: 'rewriteDeferredLibraries', assetId: _entryPoint);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -20,42 +20,43 @@ import 'package:barback/barback.dart';
|
|||
/// `isNgDeps` to `true` to signify that it is a dependency on which we need to
|
||||
/// call `initReflector`.
|
||||
Future<NgDepsModel> linkNgDeps(NgDepsModel ngDepsModel, AssetReader reader,
|
||||
AssetId entryPoint, UrlResolver resolver) async {
|
||||
AssetId assetId, UrlResolver resolver) async {
|
||||
if (ngDepsModel == null) return null;
|
||||
var linkedDepsMap =
|
||||
await _processNgImports(ngDepsModel, reader, entryPoint, resolver);
|
||||
return logElapsedAsync(() async {
|
||||
var linkedDepsMap =
|
||||
await _processNgImports(ngDepsModel, reader, assetId, resolver);
|
||||
|
||||
if (linkedDepsMap.isEmpty) {
|
||||
// We are not calling `initReflector` on any other libraries, but we still
|
||||
// return the model to ensure it is written to code.
|
||||
// TODO(kegluneq): Continue using the protobuf format after this phase.
|
||||
if (linkedDepsMap.isEmpty) {
|
||||
// We are not calling `initReflector` on any other libraries, but we still
|
||||
// return the model to ensure it is written to code.
|
||||
// TODO(kegluneq): Continue using the protobuf format after this phase.
|
||||
return ngDepsModel;
|
||||
}
|
||||
|
||||
for (var i = ngDepsModel.imports.length - 1; i >= 0; --i) {
|
||||
var import = ngDepsModel.imports[i];
|
||||
if (linkedDepsMap.containsKey(import.uri)) {
|
||||
var linkedModel = new ImportModel()
|
||||
..isNgDeps = true
|
||||
..uri = toDepsExtension(import.uri)
|
||||
..prefix = 'i$i';
|
||||
// TODO(kegluneq): Preserve combinators?
|
||||
ngDepsModel.imports.insert(i + 1, linkedModel);
|
||||
}
|
||||
}
|
||||
for (var i = 0, iLen = ngDepsModel.exports.length; i < iLen; ++i) {
|
||||
var export = ngDepsModel.exports[i];
|
||||
if (linkedDepsMap.containsKey(export.uri)) {
|
||||
var linkedModel = new ImportModel()
|
||||
..isNgDeps = true
|
||||
..uri = toDepsExtension(export.uri)
|
||||
..prefix = 'i${ngDepsModel.imports.length}';
|
||||
// TODO(kegluneq): Preserve combinators?
|
||||
ngDepsModel.imports.add(linkedModel);
|
||||
}
|
||||
}
|
||||
return ngDepsModel;
|
||||
}
|
||||
|
||||
for (var i = ngDepsModel.imports.length - 1; i >= 0; --i) {
|
||||
var import = ngDepsModel.imports[i];
|
||||
if (linkedDepsMap.containsKey(import.uri)) {
|
||||
var linkedModel = new ImportModel()
|
||||
..isNgDeps = true
|
||||
..uri = toDepsExtension(import.uri)
|
||||
..prefix = 'i$i';
|
||||
// TODO(kegluneq): Preserve combinators?
|
||||
ngDepsModel.imports.insert(i + 1, linkedModel);
|
||||
}
|
||||
}
|
||||
for (var i = 0, iLen = ngDepsModel.exports.length; i < iLen; ++i) {
|
||||
var export = ngDepsModel.exports[i];
|
||||
if (linkedDepsMap.containsKey(export.uri)) {
|
||||
var linkedModel = new ImportModel()
|
||||
..isNgDeps = true
|
||||
..uri = toDepsExtension(export.uri)
|
||||
..prefix = 'i${ngDepsModel.imports.length}';
|
||||
// TODO(kegluneq): Preserve combinators?
|
||||
ngDepsModel.imports.add(linkedModel);
|
||||
}
|
||||
}
|
||||
|
||||
return ngDepsModel;
|
||||
}, operationName: 'linkNgDeps', assetId: assetId);
|
||||
}
|
||||
|
||||
bool _isNotDartDirective(dynamic model) => !isDartCoreUri(model.uri);
|
||||
|
|
|
@ -27,14 +27,16 @@ import 'ng_deps_linker.dart';
|
|||
/// Returns an empty [NgMeta] if there are no `Directive`-annotated classes or
|
||||
/// `DirectiveAlias` annotated constants in `entryPoint`.
|
||||
Future<NgMeta> linkDirectiveMetadata(
|
||||
AssetReader reader, AssetId entryPoint) async {
|
||||
var ngMeta = await _readNgMeta(reader, entryPoint);
|
||||
AssetReader reader, AssetId assetId) async {
|
||||
var ngMeta = await _readNgMeta(reader, assetId);
|
||||
if (ngMeta == null || ngMeta.isEmpty) return null;
|
||||
|
||||
await Future.wait([
|
||||
linkNgDeps(ngMeta.ngDeps, reader, entryPoint, _urlResolver),
|
||||
_linkDirectiveMetadataRecursive(
|
||||
ngMeta, reader, entryPoint, new Set<String>())
|
||||
linkNgDeps(ngMeta.ngDeps, reader, assetId, _urlResolver),
|
||||
logElapsedAsync(() async {
|
||||
await _linkRecursive(ngMeta, reader, assetId, new Set<String>());
|
||||
return ngMeta;
|
||||
}, operationName: 'linkDirectiveMetadata', assetId: assetId)
|
||||
]);
|
||||
return ngMeta;
|
||||
}
|
||||
|
@ -50,8 +52,8 @@ Future<NgMeta> _readNgMeta(AssetReader reader, AssetId ngMetaAssetId) async {
|
|||
|
||||
final _urlResolver = const TransformerUrlResolver();
|
||||
|
||||
Future<NgMeta> _linkDirectiveMetadataRecursive(NgMeta ngMeta,
|
||||
AssetReader reader, AssetId assetId, Set<String> seen) async {
|
||||
Future _linkRecursive(NgMeta ngMeta, AssetReader reader, AssetId assetId,
|
||||
Set<String> seen) async {
|
||||
if (ngMeta == null ||
|
||||
ngMeta.ngDeps == null ||
|
||||
ngMeta.ngDeps.exports == null) {
|
||||
|
@ -59,30 +61,23 @@ Future<NgMeta> _linkDirectiveMetadataRecursive(NgMeta ngMeta,
|
|||
}
|
||||
var assetUri = toAssetUri(assetId);
|
||||
|
||||
return Future
|
||||
.wait(ngMeta.ngDeps.exports
|
||||
.where((export) => !isDartCoreUri(export.uri))
|
||||
.map((export) =>
|
||||
_urlResolver.resolve(assetUri, toMetaExtension(export.uri)))
|
||||
.where((uri) => !seen.contains(uri))
|
||||
.map((uri) async {
|
||||
return Future.wait(ngMeta.ngDeps.exports
|
||||
.where((export) => !isDartCoreUri(export.uri))
|
||||
.map((export) =>
|
||||
_urlResolver.resolve(assetUri, toMetaExtension(export.uri)))
|
||||
.where((uri) => !seen.contains(uri))
|
||||
.map((uri) async {
|
||||
seen.add(uri);
|
||||
try {
|
||||
final exportAssetId = fromUri(uri);
|
||||
if (await reader.hasInput(exportAssetId)) {
|
||||
var exportNgMetaJson = await reader.readAsString(exportAssetId);
|
||||
if (exportNgMetaJson == null) return null;
|
||||
var exportNgMeta = new NgMeta.fromJson(JSON.decode(exportNgMetaJson));
|
||||
await _linkDirectiveMetadataRecursive(
|
||||
exportNgMeta, reader, exportAssetId, seen);
|
||||
if (exportNgMeta != null) {
|
||||
ngMeta.addAll(exportNgMeta);
|
||||
}
|
||||
final exportNgMeta = await _readNgMeta(reader, exportAssetId);
|
||||
if (exportNgMeta != null) {
|
||||
await _linkRecursive(exportNgMeta, reader, exportAssetId, seen);
|
||||
ngMeta.addAll(exportNgMeta);
|
||||
}
|
||||
} catch (err, st) {
|
||||
// Log and continue.
|
||||
logger.warning('Failed to fetch $uri. Message: $err.\n$st');
|
||||
}
|
||||
}))
|
||||
.then((_) => ngMeta);
|
||||
}));
|
||||
}
|
||||
|
|
|
@ -37,7 +37,9 @@ Future<String> inlineParts(AssetReader reader, AssetId assetId) async {
|
|||
// parent, so it does not need its own `.ng_deps.dart` file.
|
||||
if (directivesVisitor.isPart) return null;
|
||||
|
||||
return _getAllDeclarations(reader, assetId, code, directivesVisitor);
|
||||
return logElapsedAsync(() {
|
||||
return _getAllDeclarations(reader, assetId, code, directivesVisitor);
|
||||
}, operationName: 'inlineParts', assetId: assetId);
|
||||
}
|
||||
|
||||
/// Processes `visitor.parts`, reading and appending their contents to the
|
||||
|
|
|
@ -17,7 +17,7 @@ import 'package:angular2/src/core/compiler/template_compiler.dart';
|
|||
import 'inliner.dart';
|
||||
|
||||
/// Generates an instance of [NgMeta] describing the file at `assetId`.
|
||||
Future<NgMeta> createNgDeps(AssetReader reader, AssetId assetId,
|
||||
Future<NgMeta> createNgMeta(AssetReader reader, AssetId assetId,
|
||||
AnnotationMatcher annotationMatcher) async {
|
||||
// TODO(kegluneq): Shortcut if we can determine that there are no
|
||||
// [Directive]s present, taking into account `export`s.
|
||||
|
@ -26,18 +26,22 @@ Future<NgMeta> createNgDeps(AssetReader reader, AssetId assetId,
|
|||
var parsedCode =
|
||||
parseCompilationUnit(codeWithParts, name: '${assetId.path} and parts');
|
||||
|
||||
var ngDepsVisitor = new NgDepsVisitor(assetId, annotationMatcher);
|
||||
parsedCode.accept(ngDepsVisitor);
|
||||
final ngDepsVisitor = await logElapsedAsync(() async {
|
||||
var ngDepsVisitor = new NgDepsVisitor(assetId, annotationMatcher);
|
||||
parsedCode.accept(ngDepsVisitor);
|
||||
return ngDepsVisitor;
|
||||
}, operationName: 'createNgDeps', assetId: assetId);
|
||||
|
||||
var ngMeta = new NgMeta(ngDeps: ngDepsVisitor.model);
|
||||
return logElapsedAsync(() async {
|
||||
var ngMeta = new NgMeta(ngDeps: ngDepsVisitor.model);
|
||||
|
||||
var templateCompiler = createTemplateCompiler(reader);
|
||||
var ngMetaVisitor = new _NgMetaVisitor(
|
||||
ngMeta, assetId, annotationMatcher, _interfaceMatcher, templateCompiler);
|
||||
parsedCode.accept(ngMetaVisitor);
|
||||
await ngMetaVisitor.whenDone();
|
||||
|
||||
return ngMeta;
|
||||
var templateCompiler = createTemplateCompiler(reader);
|
||||
var ngMetaVisitor = new _NgMetaVisitor(ngMeta, assetId, annotationMatcher,
|
||||
_interfaceMatcher, templateCompiler);
|
||||
parsedCode.accept(ngMetaVisitor);
|
||||
await ngMetaVisitor.whenDone();
|
||||
return ngMeta;
|
||||
}, operationName: 'createNgMeta', assetId: assetId);
|
||||
}
|
||||
|
||||
// TODO(kegluneq): Allow the caller to provide an InterfaceMatcher.
|
||||
|
|
|
@ -45,7 +45,7 @@ class DirectiveProcessor extends Transformer implements DeclaringTransformer {
|
|||
var primaryId = transform.primaryInput.id;
|
||||
var reader = new AssetReader.fromTransform(transform);
|
||||
var ngMeta =
|
||||
await createNgDeps(reader, primaryId, options.annotationMatcher);
|
||||
await createNgMeta(reader, primaryId, options.annotationMatcher);
|
||||
if (ngMeta == null || ngMeta.isEmpty) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import 'dart:async';
|
|||
|
||||
import 'package:angular2/src/transform/common/asset_reader.dart';
|
||||
import 'package:angular2/src/transform/common/code/source_module.dart';
|
||||
import 'package:angular2/src/transform/common/logging.dart';
|
||||
import 'package:angular2/src/transform/common/names.dart';
|
||||
import 'package:angular2/src/transform/common/ng_compiler.dart';
|
||||
import 'package:angular2/src/core/compiler/source_module.dart';
|
||||
|
@ -21,11 +22,11 @@ Future<Iterable<Asset>> processStylesheet(
|
|||
final stylesheetUrl = '${stylesheetId.package}|${stylesheetId.path}';
|
||||
final templateCompiler = createTemplateCompiler(reader);
|
||||
final cssText = await reader.readAsString(stylesheetId);
|
||||
final sourceModules =
|
||||
templateCompiler.compileStylesheetCodeGen(stylesheetUrl, cssText);
|
||||
return logElapsedAsync(() async {
|
||||
final sourceModules =
|
||||
templateCompiler.compileStylesheetCodeGen(stylesheetUrl, cssText);
|
||||
|
||||
return sourceModules.map((SourceModule module) => new Asset.fromString(
|
||||
new AssetId.parse('${module.moduleUrl}'),
|
||||
writeSourceModule(module)));
|
||||
return sourceModules.map((SourceModule module) => new Asset.fromString(
|
||||
new AssetId.parse('${module.moduleUrl}'), writeSourceModule(module)));
|
||||
}, operationName: 'processStylesheet', assetId: stylesheetId);
|
||||
}
|
||||
|
||||
|
|
|
@ -19,9 +19,11 @@ import 'package:code_transformers/assets.dart';
|
|||
///
|
||||
/// The returned value wraps the [NgDeps] at `entryPoint` as well as these
|
||||
/// created objects.
|
||||
Future<CompileDataResults> createCompileData(AssetReader reader,
|
||||
AssetId entryPoint) async {
|
||||
return new _CompileDataCreator(reader, entryPoint).createCompileData();
|
||||
Future<CompileDataResults> createCompileData(
|
||||
AssetReader reader, AssetId assetId) async {
|
||||
return logElapsedAsync(() {
|
||||
return new _CompileDataCreator(reader, assetId).createCompileData();
|
||||
}, operationName: 'createCompileData', assetId: assetId);
|
||||
}
|
||||
|
||||
class CompileDataResults {
|
||||
|
|
|
@ -10,6 +10,7 @@ import 'package:angular2/src/core/facade/lang.dart';
|
|||
import 'package:angular2/src/core/reflection/reflection.dart';
|
||||
import 'package:angular2/src/transform/common/asset_reader.dart';
|
||||
import 'package:angular2/src/transform/common/code/source_module.dart';
|
||||
import 'package:angular2/src/transform/common/logging.dart';
|
||||
import 'package:angular2/src/transform/common/names.dart';
|
||||
import 'package:angular2/src/transform/common/ng_compiler.dart';
|
||||
import 'package:angular2/src/transform/common/ng_deps.dart';
|
||||
|
@ -21,14 +22,14 @@ import 'reflection/processor.dart' as reg;
|
|||
import 'reflection/reflection_capabilities.dart';
|
||||
import 'compile_data_creator.dart';
|
||||
|
||||
/// Reads the `.ng_deps.dart` file represented by `entryPoint` and parses any
|
||||
/// Reads the `.ng_deps.dart` file represented by `assetId` and parses any
|
||||
/// Angular 2 `View` annotations it declares to generate `getter`s,
|
||||
/// `setter`s, and `method`s that would otherwise be reflectively accessed.
|
||||
///
|
||||
/// This method assumes a {@link DomAdapter} has been registered.
|
||||
Future<Outputs> processTemplates(AssetReader reader, AssetId entryPoint,
|
||||
Future<Outputs> processTemplates(AssetReader reader, AssetId assetId,
|
||||
{bool reflectPropertiesAsAttributes: false}) async {
|
||||
var viewDefResults = await createCompileData(reader, entryPoint);
|
||||
var viewDefResults = await createCompileData(reader, assetId);
|
||||
var codegen = null;
|
||||
if (viewDefResults.directiveMetadatas.isNotEmpty) {
|
||||
var processor = new reg.Processor();
|
||||
|
@ -44,16 +45,18 @@ Future<Outputs> processTemplates(AssetReader reader, AssetId entryPoint,
|
|||
var compileData =
|
||||
viewDefResults.viewDefinitions.values.toList(growable: false);
|
||||
if (compileData.isEmpty) {
|
||||
return new Outputs(entryPoint, ngDeps, codegen, null, null);
|
||||
return new Outputs(assetId, ngDeps, codegen, null, null);
|
||||
}
|
||||
|
||||
var savedReflectionCapabilities = reflector.reflectionCapabilities;
|
||||
reflector.reflectionCapabilities = const NullReflectionCapabilities();
|
||||
var compiledTemplates = templateCompiler.compileTemplatesCodeGen(compileData);
|
||||
final compiledTemplates = await logElapsedAsync(() async {
|
||||
return templateCompiler.compileTemplatesCodeGen(compileData);
|
||||
}, operationName: 'compileTemplatesCodegen', assetId: assetId);
|
||||
reflector.reflectionCapabilities = savedReflectionCapabilities;
|
||||
|
||||
return new Outputs(entryPoint, ngDeps, codegen,
|
||||
viewDefResults.viewDefinitions, compiledTemplates);
|
||||
return new Outputs(assetId, ngDeps, codegen, viewDefResults.viewDefinitions,
|
||||
compiledTemplates);
|
||||
}
|
||||
|
||||
AssetId templatesAssetId(AssetId ngDepsAssetId) =>
|
||||
|
@ -87,7 +90,8 @@ class Outputs {
|
|||
Map<RegisteredType,
|
||||
NormalizedComponentWithViewDirectives> compileDataMap) {
|
||||
var code = ngDeps.code;
|
||||
if (accessors == null && (compileDataMap == null || compileDataMap.isEmpty)) return code;
|
||||
if (accessors == null &&
|
||||
(compileDataMap == null || compileDataMap.isEmpty)) return code;
|
||||
|
||||
if (ngDeps.registeredTypes.isEmpty) return code;
|
||||
var beginRegistrationsIdx =
|
||||
|
@ -106,7 +110,8 @@ class Outputs {
|
|||
buf = new StringBuffer('${code.substring(0, beginRegistrationsIdx)}');
|
||||
}
|
||||
for (var registeredType in ngDeps.registeredTypes) {
|
||||
if (compileDataMap != null && compileDataMap.containsKey(registeredType)) {
|
||||
if (compileDataMap != null &&
|
||||
compileDataMap.containsKey(registeredType)) {
|
||||
// We generated a template for this type, so add the generated
|
||||
// `CompiledTemplate` value as the final annotation in the list.
|
||||
var annotations = registeredType.annotations as ListLiteral;
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
library angular2.test.transform.common.read_file;
|
||||
|
||||
import 'package:barback/barback.dart';
|
||||
import 'package:code_transformers/messages/build_logger.dart';
|
||||
import 'package:source_span/source_span.dart';
|
||||
|
||||
class RecordingLogger implements BuildLogger {
|
||||
@override
|
||||
final String detailsUri = '';
|
||||
@override
|
||||
final bool convertErrorsToWarnings = false;
|
||||
|
||||
bool hasErrors = false;
|
||||
|
||||
List<String> logs = [];
|
||||
|
||||
void _record(prefix, msg) => logs.add('$prefix: $msg');
|
||||
|
||||
void info(msg, {AssetId asset, SourceSpan span}) => _record('INFO', msg);
|
||||
|
||||
void fine(msg, {AssetId asset, SourceSpan span}) => _record('FINE', msg);
|
||||
|
||||
void warning(msg, {AssetId asset, SourceSpan span}) => _record('WARN', msg);
|
||||
|
||||
void error(msg, {AssetId asset, SourceSpan span}) {
|
||||
hasErrors = true;
|
||||
_record('ERROR', msg);
|
||||
}
|
||||
|
||||
Future writeOutput() => throw new UnimplementedError();
|
||||
Future addLogFilesFromAsset(AssetId id, [int nextNumber = 1]) =>
|
||||
throw new UnimplementedError();
|
||||
}
|
|
@ -2,14 +2,12 @@ library angular2.test.transform.deferred_rewriter.all_tests;
|
|||
|
||||
import 'package:barback/barback.dart';
|
||||
import 'package:angular2/src/transform/deferred_rewriter/transformer.dart';
|
||||
import 'package:angular2/src/transform/common/annotation_matcher.dart';
|
||||
import 'package:angular2/src/transform/common/asset_reader.dart';
|
||||
import 'package:angular2/src/transform/common/logging.dart' as log;
|
||||
import 'package:code_transformers/messages/build_logger.dart';
|
||||
import 'package:dart_style/dart_style.dart';
|
||||
import 'package:guinness/guinness.dart';
|
||||
import 'package:path/path.dart' as path;
|
||||
import '../common/read_file.dart';
|
||||
import '../common/recording_logger.dart';
|
||||
|
||||
var formatter = new DartFormatter();
|
||||
|
||||
|
@ -36,21 +34,23 @@ void allTests() {
|
|||
}
|
||||
|
||||
void _testRewriteDeferredLibraries(String name, String inputPath) {
|
||||
it(name, () async {
|
||||
var inputId = _assetIdForPath(inputPath);
|
||||
var reader = new TestAssetReader();
|
||||
var expectedPath = path.join(
|
||||
path.dirname(inputPath), 'expected', path.basename(inputPath));
|
||||
var expectedId = _assetIdForPath(expectedPath);
|
||||
it(name, () {
|
||||
return log.setZoned(new RecordingLogger(), () async {
|
||||
var inputId = _assetIdForPath(inputPath);
|
||||
var reader = new TestAssetReader();
|
||||
var expectedPath = path.join(
|
||||
path.dirname(inputPath), 'expected', path.basename(inputPath));
|
||||
var expectedId = _assetIdForPath(expectedPath);
|
||||
|
||||
var output = await rewriteDeferredLibraries(reader, inputId);
|
||||
var input = await reader.readAsString(expectedId);
|
||||
if (input == null) {
|
||||
// Null input signals no output. Ensure that is true.
|
||||
expect(output).toBeNull();
|
||||
} else {
|
||||
expect(formatter.format(output)).toEqual(formatter.format(input));
|
||||
}
|
||||
var output = await rewriteDeferredLibraries(reader, inputId);
|
||||
var input = await reader.readAsString(expectedId);
|
||||
if (input == null) {
|
||||
// Null input signals no output. Ensure that is true.
|
||||
expect(output).toBeNull();
|
||||
} else {
|
||||
expect(formatter.format(output)).toEqual(formatter.format(input));
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
library angular2.test.transform.directive_metadata_linker.all_tests;
|
||||
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:angular2/src/transform/common/asset_reader.dart';
|
||||
import 'package:angular2/src/transform/common/logging.dart' as log;
|
||||
import 'package:angular2/src/transform/common/model/import_export_model.pb.dart';
|
||||
import 'package:angular2/src/transform/directive_metadata_linker/ng_meta_linker.dart';
|
||||
import 'package:barback/barback.dart';
|
||||
|
@ -10,6 +13,7 @@ import 'package:guinness/guinness.dart';
|
|||
|
||||
import '../common/ng_meta_helper.dart';
|
||||
import '../common/read_file.dart';
|
||||
import '../common/recording_logger.dart';
|
||||
|
||||
var formatter = new DartFormatter();
|
||||
|
||||
|
@ -71,7 +75,7 @@ void allTests() {
|
|||
fooNgMeta.ngDeps.exports.add(new ExportModel()..uri = 'bar.dart');
|
||||
updateReader();
|
||||
|
||||
var extracted = await linkDirectiveMetadata(reader, fooAssetId);
|
||||
var extracted = await _testLink(reader, fooAssetId);
|
||||
expect(extracted.types).toContain('FooComponent');
|
||||
expect(extracted.types).toContain('BarComponent');
|
||||
|
||||
|
@ -85,7 +89,7 @@ void allTests() {
|
|||
barNgMeta.ngDeps.exports.add(new ExportModel()..uri = 'baz.dart');
|
||||
updateReader();
|
||||
|
||||
var extracted = await linkDirectiveMetadata(reader, fooAssetId);
|
||||
var extracted = await _testLink(reader, fooAssetId);
|
||||
expect(extracted.types).toContain('FooComponent');
|
||||
expect(extracted.types).toContain('BarComponent');
|
||||
expect(extracted.types).toContain('BazComponent');
|
||||
|
@ -101,7 +105,7 @@ void allTests() {
|
|||
bazNgMeta.ngDeps.exports.add(new ExportModel()..uri = 'foo.dart');
|
||||
updateReader();
|
||||
|
||||
var extracted = await linkDirectiveMetadata(reader, bazAssetId);
|
||||
var extracted = await _testLink(reader, bazAssetId);
|
||||
expect(extracted.types).toContain('FooComponent');
|
||||
expect(extracted.types).toContain('BarComponent');
|
||||
expect(extracted.types).toContain('BazComponent');
|
||||
|
@ -116,7 +120,7 @@ void allTests() {
|
|||
reader.addAsset(new AssetId('bar', 'lib/bar.ng_meta.json'),
|
||||
JSON.encode(barNgMeta.toJson()));
|
||||
|
||||
var extracted = await linkDirectiveMetadata(reader, fooAssetId);
|
||||
var extracted = await _testLink(reader, fooAssetId);
|
||||
|
||||
expect(extracted.types).toContain('FooComponent');
|
||||
expect(extracted.types).toContain('BarComponent');
|
||||
|
@ -136,7 +140,7 @@ void allTests() {
|
|||
barNgMeta.ngDeps.libraryUri = 'test.bar';
|
||||
updateReader();
|
||||
|
||||
var linked = (await linkDirectiveMetadata(reader, fooAssetId)).ngDeps;
|
||||
var linked = (await _testLink(reader, fooAssetId)).ngDeps;
|
||||
expect(linked).toBeNotNull();
|
||||
var linkedImport =
|
||||
linked.imports.firstWhere((i) => i.uri.endsWith('bar.ng_deps.dart'));
|
||||
|
@ -152,7 +156,7 @@ void allTests() {
|
|||
barNgMeta.ngDeps.libraryUri = 'test.bar';
|
||||
updateReader();
|
||||
|
||||
var linked = (await linkDirectiveMetadata(reader, fooAssetId)).ngDeps;
|
||||
var linked = (await _testLink(reader, fooAssetId)).ngDeps;
|
||||
expect(linked).toBeNotNull();
|
||||
var linkedImport =
|
||||
linked.imports.firstWhere((i) => i.uri.endsWith('bar.ng_deps.dart'));
|
||||
|
@ -162,3 +166,8 @@ void allTests() {
|
|||
});
|
||||
});
|
||||
}
|
||||
|
||||
Future<NgMeta> _testLink(AssetReader reader, AssetId assetId) {
|
||||
return log.setZoned(
|
||||
new RecordingLogger(), () => linkDirectiveMetadata(reader, assetId));
|
||||
}
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
library angular2.test.transform.directive_processor.all_tests;
|
||||
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:barback/barback.dart';
|
||||
import 'package:angular2/src/core/change_detection/change_detection.dart';
|
||||
import 'package:angular2/src/core/linker/interfaces.dart' show LifecycleHooks;
|
||||
import 'package:angular2/src/core/dom/html_adapter.dart';
|
||||
|
@ -13,13 +11,13 @@ import 'package:angular2/src/transform/common/code/ng_deps_code.dart';
|
|||
import 'package:angular2/src/transform/common/asset_reader.dart';
|
||||
import 'package:angular2/src/transform/common/logging.dart' as log;
|
||||
import 'package:angular2/src/transform/common/model/reflection_info_model.pb.dart';
|
||||
import 'package:angular2/src/transform/common/model/ng_deps_model.pb.dart';
|
||||
import 'package:angular2/src/transform/common/ng_meta.dart';
|
||||
import 'package:barback/barback.dart';
|
||||
import 'package:code_transformers/messages/build_logger.dart';
|
||||
import 'package:dart_style/dart_style.dart';
|
||||
import 'package:guinness/guinness.dart';
|
||||
import 'package:source_span/source_span.dart';
|
||||
import '../common/read_file.dart';
|
||||
import '../common/recording_logger.dart';
|
||||
|
||||
var formatter = new DartFormatter();
|
||||
|
||||
|
@ -442,37 +440,9 @@ Future<NgMeta> _testCreateModel(String inputPath,
|
|||
}
|
||||
|
||||
var annotationMatcher = new AnnotationMatcher()..addAll(customDescriptors);
|
||||
return createNgDeps(reader, inputId, annotationMatcher);
|
||||
return createNgMeta(reader, inputId, annotationMatcher);
|
||||
});
|
||||
}
|
||||
|
||||
AssetId _assetIdForPath(String path) =>
|
||||
new AssetId('angular2', 'test/transform/directive_processor/$path');
|
||||
|
||||
class RecordingLogger implements BuildLogger {
|
||||
@override
|
||||
final String detailsUri = '';
|
||||
@override
|
||||
final bool convertErrorsToWarnings = false;
|
||||
|
||||
bool hasErrors = false;
|
||||
|
||||
List<String> logs = [];
|
||||
|
||||
void _record(prefix, msg) => logs.add('$prefix: $msg');
|
||||
|
||||
void info(msg, {AssetId asset, SourceSpan span}) => _record('INFO', msg);
|
||||
|
||||
void fine(msg, {AssetId asset, SourceSpan span}) => _record('FINE', msg);
|
||||
|
||||
void warning(msg, {AssetId asset, SourceSpan span}) => _record('WARN', msg);
|
||||
|
||||
void error(msg, {AssetId asset, SourceSpan span}) {
|
||||
hasErrors = true;
|
||||
_record('ERROR', msg);
|
||||
}
|
||||
|
||||
Future writeOutput() => throw new UnimplementedError();
|
||||
Future addLogFilesFromAsset(AssetId id, [int nextNumber = 1]) =>
|
||||
throw new UnimplementedError();
|
||||
}
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
library angular2.test.transform.inliner_for_test.all_tests;
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:angular2/src/transform/common/asset_reader.dart';
|
||||
import 'package:angular2/src/transform/common/logging.dart' as log;
|
||||
import 'package:angular2/src/transform/inliner_for_test.dart';
|
||||
import 'package:barback/barback.dart';
|
||||
import 'package:code_transformers/tests.dart';
|
||||
|
@ -8,6 +11,7 @@ import 'package:guinness/guinness.dart';
|
|||
import 'package:dart_style/dart_style.dart';
|
||||
|
||||
import '../common/read_file.dart';
|
||||
import '../common/recording_logger.dart';
|
||||
|
||||
main() {
|
||||
allTests();
|
||||
|
@ -23,7 +27,7 @@ void allTests() {
|
|||
});
|
||||
|
||||
it('should inline `templateUrl` values', () async {
|
||||
var output = await inline(
|
||||
var output = await _testInline(
|
||||
absoluteReader, _assetId('url_expression_files/hello.dart'));
|
||||
expect(output).toBeNotNull();
|
||||
expect(() => formatter.format(output)).not.toThrow();
|
||||
|
@ -42,7 +46,7 @@ void allTests() {
|
|||
readFile(
|
||||
'inliner_for_test/absolute_url_expression_files/template.css'));
|
||||
|
||||
var output = await inline(
|
||||
var output = await _testInline(
|
||||
absoluteReader, _assetId('absolute_url_expression_files/hello.dart'));
|
||||
|
||||
expect(output).toBeNotNull();
|
||||
|
@ -58,7 +62,7 @@ void allTests() {
|
|||
absoluteReader
|
||||
..addAsset(new AssetId('other_package', 'lib/template.html'), '')
|
||||
..addAsset(new AssetId('other_package', 'lib/template.css'), '');
|
||||
var output = await inline(
|
||||
var output = await _testInline(
|
||||
absoluteReader, _assetId('multiple_style_urls_files/hello.dart'));
|
||||
|
||||
expect(output).toBeNotNull();
|
||||
|
@ -70,7 +74,7 @@ void allTests() {
|
|||
});
|
||||
|
||||
it('should inline `templateUrl`s expressed as adjacent strings.', () async {
|
||||
var output = await inline(
|
||||
var output = await _testInline(
|
||||
absoluteReader, _assetId('split_url_expression_files/hello.dart'));
|
||||
|
||||
expect(output).toBeNotNull();
|
||||
|
@ -83,6 +87,10 @@ void allTests() {
|
|||
_runMultiStylesEndToEndTest();
|
||||
}
|
||||
|
||||
Future<String> _testInline(AssetReader reader, AssetId assetId) {
|
||||
return log.setZoned(new RecordingLogger(), () => inline(reader, assetId));
|
||||
}
|
||||
|
||||
AssetId _assetId(String path) => new AssetId('a', 'inliner_for_test/$path');
|
||||
|
||||
void _runAbsoluteUrlEndToEndTest() {
|
||||
|
|
|
@ -8,6 +8,8 @@ import 'package:angular2/src/transform/stylesheet_compiler/transformer.dart';
|
|||
import 'package:barback/barback.dart';
|
||||
import 'package:guinness/guinness.dart';
|
||||
|
||||
import '../common/recording_logger.dart';
|
||||
|
||||
const SIMPLE_CSS = '''
|
||||
.foo {
|
||||
width: 10px;
|
||||
|
@ -64,6 +66,9 @@ allTests() {
|
|||
class FakeTransform implements Transform {
|
||||
final outputs = <Asset>[];
|
||||
Asset primaryInput;
|
||||
final _logger = new RecordingLogger();
|
||||
|
||||
get logger => _logger;
|
||||
|
||||
addOutput(Asset output) {
|
||||
this.outputs.add(output);
|
||||
|
|
|
@ -6,7 +6,7 @@ import 'dart:convert';
|
|||
import 'package:barback/barback.dart';
|
||||
import 'package:angular2/src/core/dom/html_adapter.dart';
|
||||
import 'package:angular2/src/transform/common/asset_reader.dart';
|
||||
import 'package:angular2/src/transform/common/logging.dart';
|
||||
import 'package:angular2/src/transform/common/logging.dart' as log;
|
||||
import 'package:angular2/src/transform/template_compiler/generator.dart';
|
||||
import 'package:dart_style/dart_style.dart';
|
||||
import 'package:path/path.dart' as path;
|
||||
|
@ -14,6 +14,7 @@ import 'package:guinness/guinness.dart';
|
|||
|
||||
import '../common/compile_directive_metadata/ng_for.ng_meta.dart' as ngMeta;
|
||||
import '../common/read_file.dart';
|
||||
import '../common/recording_logger.dart';
|
||||
|
||||
var formatter = new DartFormatter();
|
||||
AssetReader reader;
|
||||
|
@ -37,7 +38,10 @@ void allTests() {
|
|||
}
|
||||
|
||||
void changeDetectorTests() {
|
||||
Future<Outputs> process(AssetId assetId) => processTemplates(reader, assetId);
|
||||
Future<Outputs> process(AssetId assetId) {
|
||||
return log.setZoned(
|
||||
new RecordingLogger(), () => processTemplates(reader, assetId));
|
||||
}
|
||||
|
||||
// TODO(tbosch): This is just a temporary test that makes sure that the dart server and
|
||||
// dart browser is in sync. Change this to "not contains notifyBinding"
|
||||
|
@ -68,8 +72,12 @@ void changeDetectorTests() {
|
|||
}
|
||||
|
||||
void noChangeDetectorTests() {
|
||||
Future<String> process(AssetId assetId) =>
|
||||
processTemplates(reader, assetId).then((outputs) => outputs.ngDepsCode);
|
||||
Future<String> process(AssetId assetId) {
|
||||
return log.setZoned(
|
||||
new RecordingLogger(),
|
||||
() => processTemplates(reader, assetId)
|
||||
.then((outputs) => outputs.ngDepsCode));
|
||||
}
|
||||
|
||||
it('should parse simple expressions in inline templates.', () async {
|
||||
var inputPath =
|
||||
|
|
Loading…
Reference in New Issue