refactor(dart/transform): Separate log & zone code
- Move zone-related code out of logger.dart and into zone.dart. - Rename `logger` => `log`. - Add the ability to specify a zone-local `TemplateCompiler`.
This commit is contained in:
parent
4909feddde
commit
5d9b1e90dc
|
@ -4,7 +4,7 @@ import 'package:analyzer/src/generated/ast.dart';
|
||||||
import 'package:barback/barback.dart' show AssetId;
|
import 'package:barback/barback.dart' show AssetId;
|
||||||
import 'package:code_transformers/assets.dart';
|
import 'package:code_transformers/assets.dart';
|
||||||
import 'package:path/path.dart' as path;
|
import 'package:path/path.dart' as path;
|
||||||
import 'logging.dart' show logger;
|
import 'logging.dart' show log;
|
||||||
|
|
||||||
/// Checks if a given [Identifier] matches any of the given [ClassDescriptor]s.
|
/// Checks if a given [Identifier] matches any of the given [ClassDescriptor]s.
|
||||||
abstract class ClassMatcherBase {
|
abstract class ClassMatcherBase {
|
||||||
|
@ -53,7 +53,7 @@ abstract class ClassMatcherBase {
|
||||||
if (superClass == null) {
|
if (superClass == null) {
|
||||||
if (missingSuperClassWarning != null &&
|
if (missingSuperClassWarning != null &&
|
||||||
missingSuperClassWarning.isNotEmpty) {
|
missingSuperClassWarning.isNotEmpty) {
|
||||||
logger.warning(missingSuperClassWarning);
|
log.warning(missingSuperClassWarning);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -87,7 +87,7 @@ ImportDirective _getMatchingImport(
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
importMatch =
|
importMatch =
|
||||||
descriptor.assetId == uriToAssetId(assetId, uriString, logger, null);
|
descriptor.assetId == uriToAssetId(assetId, uriString, log, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!importMatch) return false;
|
if (!importMatch) return false;
|
||||||
|
|
|
@ -68,7 +68,7 @@ class ParameterVisitor extends SimpleAstVisitor<ParameterModel> {
|
||||||
@override
|
@override
|
||||||
ParameterModel visitFieldFormalParameter(FieldFormalParameter node) {
|
ParameterModel visitFieldFormalParameter(FieldFormalParameter node) {
|
||||||
if (node.parameters != null) {
|
if (node.parameters != null) {
|
||||||
logger.error('Parameters in ctor not supported '
|
log.error('Parameters in ctor not supported '
|
||||||
'(${node.toSource()})');
|
'(${node.toSource()})');
|
||||||
}
|
}
|
||||||
var type = node.type;
|
var type = node.type;
|
||||||
|
@ -82,7 +82,7 @@ class ParameterVisitor extends SimpleAstVisitor<ParameterModel> {
|
||||||
@override
|
@override
|
||||||
ParameterModel visitFunctionTypedFormalParameter(
|
ParameterModel visitFunctionTypedFormalParameter(
|
||||||
FunctionTypedFormalParameter node) {
|
FunctionTypedFormalParameter node) {
|
||||||
logger.error('Function typed formal parameters not supported '
|
log.error('Function typed formal parameters not supported '
|
||||||
'(${node.toSource()})');
|
'(${node.toSource()})');
|
||||||
return _visitNormalFormalParameter(node.metadata, null, node.identifier);
|
return _visitNormalFormalParameter(node.metadata, null, node.identifier);
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,7 +56,7 @@ class ReflectionInfoVisitor extends RecursiveAstVisitor<ReflectionInfoModel> {
|
||||||
if (numCtorsFound > 1) {
|
if (numCtorsFound > 1) {
|
||||||
var ctorName = ctor.name;
|
var ctorName = ctor.name;
|
||||||
if (ctorName != null) {
|
if (ctorName != null) {
|
||||||
logger.warning('Found ${numCtorsFound} constructors for class '
|
log.warning('Found ${numCtorsFound} constructors for class '
|
||||||
'${node.name}; using constructor ${ctorName}.');
|
'${node.name}; using constructor ${ctorName}.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -88,7 +88,7 @@ class ReflectionInfoVisitor extends RecursiveAstVisitor<ReflectionInfoModel> {
|
||||||
});
|
});
|
||||||
if (componentDirectives != null && componentDirectives.isNotEmpty) {
|
if (componentDirectives != null && componentDirectives.isNotEmpty) {
|
||||||
if (viewDirectives != null) {
|
if (viewDirectives != null) {
|
||||||
logger.warning(
|
log.warning(
|
||||||
'Cannot specify view parameters on @Component when a @View '
|
'Cannot specify view parameters on @Component when a @View '
|
||||||
'is present. Component name: ${model.name}',
|
'is present. Component name: ${model.name}',
|
||||||
asset: assetId);
|
asset: assetId);
|
||||||
|
@ -166,7 +166,7 @@ class ReflectionInfoVisitor extends RecursiveAstVisitor<ReflectionInfoModel> {
|
||||||
if (directivesNode == null) return const [];
|
if (directivesNode == null) return const [];
|
||||||
|
|
||||||
if (directivesNode.expression is! ListLiteral) {
|
if (directivesNode.expression is! ListLiteral) {
|
||||||
logger.warning('Angular 2 expects a list literal for `directives` '
|
log.warning('Angular 2 expects a list literal for `directives` '
|
||||||
'but found a ${directivesNode.expression.runtimeType}');
|
'but found a ${directivesNode.expression.runtimeType}');
|
||||||
return const [];
|
return const [];
|
||||||
}
|
}
|
||||||
|
@ -179,7 +179,7 @@ class ReflectionInfoVisitor extends RecursiveAstVisitor<ReflectionInfoModel> {
|
||||||
} else if (dep is Identifier) {
|
} else if (dep is Identifier) {
|
||||||
directives.add(new PrefixedDirective()..name = '${dep}');
|
directives.add(new PrefixedDirective()..name = '${dep}');
|
||||||
} else {
|
} else {
|
||||||
logger.warning('Found unexpected value $dep in `directives`.');
|
log.warning('Found unexpected value $dep in `directives`.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return directives;
|
return directives;
|
||||||
|
|
|
@ -182,7 +182,7 @@ class _DirectiveMetadataVisitor extends Object
|
||||||
if (_type != null && _type.name != null && _type.name.isNotEmpty) {
|
if (_type != null && _type.name != null && _type.name.isNotEmpty) {
|
||||||
name = _type.name;
|
name = _type.name;
|
||||||
}
|
}
|
||||||
logger.warning(
|
log.warning(
|
||||||
'Cannot specify view parameters on @Component when a @View '
|
'Cannot specify view parameters on @Component when a @View '
|
||||||
'is present. Component name: ${name}',
|
'is present. Component name: ${name}',
|
||||||
asset: _assetId);
|
asset: _assetId);
|
||||||
|
@ -264,7 +264,8 @@ class _DirectiveMetadataVisitor extends Object
|
||||||
Object visitMethodDeclaration(MethodDeclaration node) {
|
Object visitMethodDeclaration(MethodDeclaration node) {
|
||||||
for (var meta in node.metadata) {
|
for (var meta in node.metadata) {
|
||||||
if (_isAnnotation(meta, 'HostListener')) {
|
if (_isAnnotation(meta, 'HostListener')) {
|
||||||
if (meta.arguments.arguments.length == 0 || meta.arguments.arguments.length > 2) {
|
if (meta.arguments.arguments.length == 0 ||
|
||||||
|
meta.arguments.arguments.length > 2) {
|
||||||
throw new ArgumentError(
|
throw new ArgumentError(
|
||||||
'Incorrect value passed to HostListener. Expected 1 or 2.');
|
'Incorrect value passed to HostListener. Expected 1 or 2.');
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,53 +1,16 @@
|
||||||
library angular2.transform.common.logging;
|
library angular2.src.transform.common.logging;
|
||||||
|
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:analyzer/analyzer.dart';
|
|
||||||
import 'package:barback/barback.dart';
|
import 'package:barback/barback.dart';
|
||||||
import 'package:source_span/source_span.dart';
|
import 'package:source_span/source_span.dart';
|
||||||
|
|
||||||
typedef _SimpleCallback();
|
import 'zone.dart' as zone show log;
|
||||||
|
|
||||||
// The key used to store the logger on the current zone.
|
/// The [TransformLogger] for the current {@link Zone}.
|
||||||
final _key = #loggingZonedLoggerKey;
|
TransformLogger get log {
|
||||||
|
var log = zone.log;
|
||||||
/// Executes {@link fn} inside a new {@link Zone} with its own logger.
|
return log != null ? log : new PrintLogger();
|
||||||
Future<dynamic> initZoned(Transform t, _SimpleCallback fn) =>
|
|
||||||
setZoned(t.logger, fn);
|
|
||||||
|
|
||||||
Future<dynamic> setZoned(TransformLogger logger, _SimpleCallback fn) async {
|
|
||||||
return runZoned(() async {
|
|
||||||
try {
|
|
||||||
return await fn();
|
|
||||||
} on AnalyzerError catch (e) {
|
|
||||||
// Do not worry about printing the stack trace, barback will handle that
|
|
||||||
// on its own when it catches the rethrown exception.
|
|
||||||
logger
|
|
||||||
.error(' Failed with ${e.runtimeType}\n${_friendlyError(e.error)}');
|
|
||||||
rethrow;
|
|
||||||
} on AnalyzerErrorGroup catch (eGroup) {
|
|
||||||
// See above re: stack trace.
|
|
||||||
var numErrors = eGroup.errors.length;
|
|
||||||
if (numErrors == 1) {
|
|
||||||
logger.error(_friendlyError(eGroup.errors[0].error));
|
|
||||||
} else {
|
|
||||||
var buf = new StringBuffer();
|
|
||||||
buf.writeln(' Failed with ${numErrors} errors');
|
|
||||||
for (var i = 0; i < numErrors; ++i) {
|
|
||||||
buf.writeln(
|
|
||||||
'Error ${i + 1}: ${_friendlyError(eGroup.errors[i].error)}');
|
|
||||||
}
|
|
||||||
logger.error('$buf');
|
|
||||||
}
|
|
||||||
rethrow;
|
|
||||||
}
|
|
||||||
}, zoneValues: {_key: logger});
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The logger for the current {@link Zone}.
|
|
||||||
TransformLogger get logger {
|
|
||||||
var current = Zone.current[_key] as TransformLogger;
|
|
||||||
return current == null ? new PrintLogger() : current;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Writes a log entry at `LogLevel.FINE` granularity with the time taken by
|
/// Writes a log entry at `LogLevel.FINE` granularity with the time taken by
|
||||||
|
@ -64,10 +27,14 @@ Future logElapsedAsync(Future asyncOperation(),
|
||||||
if (assetId != null) {
|
if (assetId != null) {
|
||||||
buf.write(' on $assetId');
|
buf.write(' on $assetId');
|
||||||
}
|
}
|
||||||
logger.fine(buf.toString(), asset: assetId);
|
log.fine(buf.toString(), asset: assetId);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Prints logged messages to the console.
|
||||||
|
///
|
||||||
|
/// A simple implementation of [TransformLogger] that prints messages to the
|
||||||
|
/// console and discards `asset` and `span` information.
|
||||||
class PrintLogger implements TransformLogger {
|
class PrintLogger implements TransformLogger {
|
||||||
void _printWithPrefix(prefix, msg) => print('$prefix: $msg');
|
void _printWithPrefix(prefix, msg) => print('$prefix: $msg');
|
||||||
|
|
||||||
|
@ -103,17 +70,3 @@ class PrintLoggerError extends Error {
|
||||||
'Span: ${Error.safeToString(span)}.';
|
'Span: ${Error.safeToString(span)}.';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Generate a human-readable error message from `error`.
|
|
||||||
String _friendlyError(AnalysisError error) {
|
|
||||||
if (error.source != null) {
|
|
||||||
var file =
|
|
||||||
new SourceFile(error.source.contents.data, url: error.source.fullName);
|
|
||||||
|
|
||||||
return file
|
|
||||||
.span(error.offset, error.offset + error.length)
|
|
||||||
.message(error.message, color: false);
|
|
||||||
} else {
|
|
||||||
return '<unknown location>: ${error.message}';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -79,7 +79,7 @@ class NgMeta {
|
||||||
var ngDepsJsonMap = json[key];
|
var ngDepsJsonMap = json[key];
|
||||||
if (ngDepsJsonMap == null) continue;
|
if (ngDepsJsonMap == null) continue;
|
||||||
if (ngDepsJsonMap is! Map) {
|
if (ngDepsJsonMap is! Map) {
|
||||||
logger.warning(
|
log.warning(
|
||||||
'Unexpected value $ngDepsJsonMap for key "$key" in NgMeta.');
|
'Unexpected value $ngDepsJsonMap for key "$key" in NgMeta.');
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -87,7 +87,7 @@ class NgMeta {
|
||||||
} else {
|
} else {
|
||||||
var entry = json[key];
|
var entry = json[key];
|
||||||
if (entry is! Map) {
|
if (entry is! Map) {
|
||||||
logger.warning('Unexpected value $entry for key "$key" in NgMeta.');
|
log.warning('Unexpected value $entry for key "$key" in NgMeta.');
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (entry[_KIND_KEY] == _TYPE_VALUE) {
|
if (entry[_KIND_KEY] == _TYPE_VALUE) {
|
||||||
|
@ -128,7 +128,7 @@ class NgMeta {
|
||||||
var seen = new Set();
|
var seen = new Set();
|
||||||
helper(name) {
|
helper(name) {
|
||||||
if (!seen.add(name)) {
|
if (!seen.add(name)) {
|
||||||
logger.warning('Circular alias dependency for "$name".');
|
log.warning('Circular alias dependency for "$name".');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (types.containsKey(name)) {
|
if (types.containsKey(name)) {
|
||||||
|
@ -136,7 +136,7 @@ class NgMeta {
|
||||||
} else if (aliases.containsKey(name)) {
|
} else if (aliases.containsKey(name)) {
|
||||||
aliases[name].forEach(helper);
|
aliases[name].forEach(helper);
|
||||||
} else {
|
} else {
|
||||||
logger.warning('Unknown alias: "$name".');
|
log.warning('Unknown alias: "$name".');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
helper(alias);
|
helper(alias);
|
||||||
|
|
|
@ -20,7 +20,7 @@ class XhrImpl implements XHR {
|
||||||
Future<String> get(String url) async {
|
Future<String> get(String url) async {
|
||||||
final assetId = fromUri(url);
|
final assetId = fromUri(url);
|
||||||
if (!url.startsWith('asset:')) {
|
if (!url.startsWith('asset:')) {
|
||||||
logger.warning('XhrImpl received unexpected url: $url');
|
log.warning('XhrImpl received unexpected url: $url');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!await _reader.hasInput(assetId)) {
|
if (!await _reader.hasInput(assetId)) {
|
||||||
|
|
|
@ -0,0 +1,74 @@
|
||||||
|
library angular2.src.transform.common.zone;
|
||||||
|
|
||||||
|
import 'dart:async';
|
||||||
|
|
||||||
|
import 'package:analyzer/analyzer.dart';
|
||||||
|
import 'package:barback/barback.dart';
|
||||||
|
import 'package:source_span/source_span.dart';
|
||||||
|
|
||||||
|
import 'package:angular2/src/core/compiler/template_compiler.dart';
|
||||||
|
|
||||||
|
typedef _SimpleCallback();
|
||||||
|
|
||||||
|
// Keys used to store zone local values on the current zone.
|
||||||
|
final _loggerKey = #loggingZonedLoggerKey;
|
||||||
|
final _templateCompilerKey = #templateCompilerKey;
|
||||||
|
|
||||||
|
/// Executes `fn` inside a new `Zone` with the provided zone-local values.
|
||||||
|
Future<dynamic> exec(_SimpleCallback fn,
|
||||||
|
{TransformLogger log, TemplateCompiler templateCompiler}) async {
|
||||||
|
return runZoned(() async {
|
||||||
|
try {
|
||||||
|
return await fn();
|
||||||
|
} on AnalyzerError catch (e) {
|
||||||
|
// Do not worry about printing the stack trace, barback will handle
|
||||||
|
// that on its own when it catches the rethrown exception.
|
||||||
|
log.error(' Failed with ${e.runtimeType}\n${_friendlyError(e.error)}');
|
||||||
|
rethrow;
|
||||||
|
} on AnalyzerErrorGroup catch (eGroup) {
|
||||||
|
// See above re: stack trace.
|
||||||
|
var numErrors = eGroup.errors.length;
|
||||||
|
if (numErrors == 1) {
|
||||||
|
log.error(_friendlyError(eGroup.errors[0].error));
|
||||||
|
} else {
|
||||||
|
var buf = new StringBuffer();
|
||||||
|
buf.writeln(' Failed with ${numErrors} errors');
|
||||||
|
for (var i = 0; i < numErrors; ++i) {
|
||||||
|
buf.writeln(
|
||||||
|
'Error ${i + 1}: ${_friendlyError(eGroup.errors[i].error)}');
|
||||||
|
}
|
||||||
|
log.error('$buf');
|
||||||
|
}
|
||||||
|
rethrow;
|
||||||
|
}
|
||||||
|
}, zoneValues: {_loggerKey: log, _templateCompilerKey: templateCompiler});
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The [TransformLogger] for the current zone.
|
||||||
|
///
|
||||||
|
/// Typically, this should not be used directly, since it will return `null` if
|
||||||
|
/// there is no [TransformLogger] registered on the current zone. Instead,
|
||||||
|
/// import `logging.dart` and use the `log` value it exports, which defines a
|
||||||
|
/// reasonable default value.
|
||||||
|
TransformLogger get log => Zone.current[_loggerKey] as TransformLogger;
|
||||||
|
|
||||||
|
/// The [TemplateCompiler] for the current zone.
|
||||||
|
///
|
||||||
|
/// This will return `null` if there is no [TemplateCompiler] registered on the
|
||||||
|
/// current zone.
|
||||||
|
TemplateCompiler get templateCompiler =>
|
||||||
|
Zone.current[_templateCompilerKey] as TemplateCompiler;
|
||||||
|
|
||||||
|
/// Generate a human-readable error message from `error`.
|
||||||
|
String _friendlyError(AnalysisError error) {
|
||||||
|
if (error.source != null) {
|
||||||
|
var file =
|
||||||
|
new SourceFile(error.source.contents.data, url: error.source.fullName);
|
||||||
|
|
||||||
|
return file
|
||||||
|
.span(error.offset, error.offset + error.length)
|
||||||
|
.message(error.message, color: false);
|
||||||
|
} else {
|
||||||
|
return '<unknown location>: ${error.message}';
|
||||||
|
}
|
||||||
|
}
|
|
@ -99,11 +99,11 @@ class _FindDeferredLibraries extends Object with RecursiveAstVisitor<Object> {
|
||||||
|
|
||||||
bool hasDeferredLibrariesToRewrite() {
|
bool hasDeferredLibrariesToRewrite() {
|
||||||
if (deferredImports.isEmpty) {
|
if (deferredImports.isEmpty) {
|
||||||
logger.fine('There are no deferred library imports.');
|
log.fine('There are no deferred library imports.');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (loadLibraryInvocations.isEmpty) {
|
if (loadLibraryInvocations.isEmpty) {
|
||||||
logger.fine(
|
log.fine(
|
||||||
'There are no loadLibrary invocations that need to be rewritten.');
|
'There are no loadLibrary invocations that need to be rewritten.');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,11 +2,12 @@ library angular2.transform.deferred_rewriter.transformer;
|
||||||
|
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
|
||||||
|
import 'package:barback/barback.dart';
|
||||||
|
|
||||||
import 'package:angular2/src/transform/common/asset_reader.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/names.dart';
|
import 'package:angular2/src/transform/common/names.dart';
|
||||||
import 'package:angular2/src/transform/common/options.dart';
|
import 'package:angular2/src/transform/common/options.dart';
|
||||||
import 'package:barback/barback.dart';
|
import 'package:angular2/src/transform/common/zone.dart' as zone;
|
||||||
|
|
||||||
import 'rewriter.dart';
|
import 'rewriter.dart';
|
||||||
|
|
||||||
|
@ -24,14 +25,14 @@ class DeferredRewriter extends Transformer {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future apply(Transform transform) async {
|
Future apply(Transform transform) async {
|
||||||
await log.initZoned(transform, () async {
|
return zone.exec(() async {
|
||||||
var asset = transform.primaryInput;
|
var asset = transform.primaryInput;
|
||||||
var reader = new AssetReader.fromTransform(transform);
|
var reader = new AssetReader.fromTransform(transform);
|
||||||
var transformedCode = await rewriteDeferredLibraries(reader, asset.id);
|
var transformedCode = await rewriteDeferredLibraries(reader, asset.id);
|
||||||
if (transformedCode != null) {
|
if (transformedCode != null) {
|
||||||
transform.addOutput(new Asset.fromString(asset.id, transformedCode));
|
transform.addOutput(new Asset.fromString(asset.id, transformedCode));
|
||||||
}
|
}
|
||||||
});
|
}, log: transform.logger);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -84,7 +84,7 @@ Future<Map<String, String>> _processNgImports(NgDepsModel model,
|
||||||
retVal[directive.uri] = summaryJsonUri;
|
retVal[directive.uri] = summaryJsonUri;
|
||||||
}
|
}
|
||||||
}, onError: (err, stack) {
|
}, onError: (err, stack) {
|
||||||
logger.warning('Error while looking for $summaryJsonUri. '
|
log.warning('Error while looking for $summaryJsonUri. '
|
||||||
'Message: $err\n'
|
'Message: $err\n'
|
||||||
'Stack: $stack');
|
'Stack: $stack');
|
||||||
});
|
});
|
||||||
|
|
|
@ -77,7 +77,7 @@ Future _linkRecursive(NgMeta ngMeta, AssetReader reader, AssetId assetId,
|
||||||
}
|
}
|
||||||
} catch (err, st) {
|
} catch (err, st) {
|
||||||
// Log and continue.
|
// Log and continue.
|
||||||
logger.warning('Failed to fetch $uri. Message: $err.\n$st');
|
log.warning('Failed to fetch $uri. Message: $err.\n$st');
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,11 +3,12 @@ library angular2.transform.directive_metadata_linker.transformer;
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'dart:convert';
|
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/names.dart';
|
|
||||||
import 'package:barback/barback.dart';
|
import 'package:barback/barback.dart';
|
||||||
|
|
||||||
|
import 'package:angular2/src/transform/common/asset_reader.dart';
|
||||||
|
import 'package:angular2/src/transform/common/names.dart';
|
||||||
|
import 'package:angular2/src/transform/common/zone.dart' as zone;
|
||||||
|
|
||||||
import 'ng_meta_linker.dart';
|
import 'ng_meta_linker.dart';
|
||||||
|
|
||||||
/// Transformer responsible for processing .ng_summary.json files created by
|
/// Transformer responsible for processing .ng_summary.json files created by
|
||||||
|
@ -37,7 +38,7 @@ class DirectiveMetadataLinker extends Transformer {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future apply(Transform transform) {
|
Future apply(Transform transform) {
|
||||||
return log.initZoned(transform, () {
|
return zone.exec(() {
|
||||||
var primaryId = transform.primaryInput.id;
|
var primaryId = transform.primaryInput.id;
|
||||||
|
|
||||||
return linkDirectiveMetadata(
|
return linkDirectiveMetadata(
|
||||||
|
@ -53,7 +54,7 @@ class DirectiveMetadataLinker extends Transformer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
}, log: transform.logger);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -54,11 +54,11 @@ Future<String> _getAllDeclarations(AssetReader reader, AssetId assetId,
|
||||||
var asyncWriter = new AsyncStringWriter(code.substring(0, partsStart));
|
var asyncWriter = new AsyncStringWriter(code.substring(0, partsStart));
|
||||||
visitor.parts.forEach((partDirective) {
|
visitor.parts.forEach((partDirective) {
|
||||||
var uri = stringLiteralToString(partDirective.uri);
|
var uri = stringLiteralToString(partDirective.uri);
|
||||||
var partAssetId = uriToAssetId(assetId, uri, logger, null /* span */,
|
var partAssetId = uriToAssetId(assetId, uri, log, null /* span */,
|
||||||
errorOnAbsolute: false);
|
errorOnAbsolute: false);
|
||||||
asyncWriter.asyncPrint(reader.readAsString(partAssetId).then((partCode) {
|
asyncWriter.asyncPrint(reader.readAsString(partAssetId).then((partCode) {
|
||||||
if (partCode == null || partCode.isEmpty) {
|
if (partCode == null || partCode.isEmpty) {
|
||||||
logger.warning('Empty part at "${partDirective.uri}. Ignoring.',
|
log.warning('Empty part at "${partDirective.uri}. Ignoring.',
|
||||||
asset: partAssetId);
|
asset: partAssetId);
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
@ -66,7 +66,7 @@ Future<String> _getAllDeclarations(AssetReader reader, AssetId assetId,
|
||||||
var parsedDirectives = parseDirectives(partCode, name: uri).directives;
|
var parsedDirectives = parseDirectives(partCode, name: uri).directives;
|
||||||
return partCode.substring(parsedDirectives.last.end);
|
return partCode.substring(parsedDirectives.last.end);
|
||||||
}).catchError((err, stackTrace) {
|
}).catchError((err, stackTrace) {
|
||||||
logger.warning(
|
log.warning(
|
||||||
'Failed while reading part at ${partDirective.uri}. Ignoring.\n'
|
'Failed while reading part at ${partDirective.uri}. Ignoring.\n'
|
||||||
'Error: $err\n'
|
'Error: $err\n'
|
||||||
'Stack Trace: $stackTrace',
|
'Stack Trace: $stackTrace',
|
||||||
|
|
|
@ -3,6 +3,9 @@ library angular2.transform.directive_processor.rewriter;
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:analyzer/analyzer.dart';
|
import 'package:analyzer/analyzer.dart';
|
||||||
|
import 'package:barback/barback.dart' show AssetId;
|
||||||
|
|
||||||
|
import 'package:angular2/src/core/compiler/template_compiler.dart';
|
||||||
import 'package:angular2/src/transform/common/annotation_matcher.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/asset_reader.dart';
|
||||||
import 'package:angular2/src/transform/common/code/ng_deps_code.dart';
|
import 'package:angular2/src/transform/common/code/ng_deps_code.dart';
|
||||||
|
@ -11,8 +14,7 @@ import 'package:angular2/src/transform/common/interface_matcher.dart';
|
||||||
import 'package:angular2/src/transform/common/logging.dart';
|
import 'package:angular2/src/transform/common/logging.dart';
|
||||||
import 'package:angular2/src/transform/common/ng_compiler.dart';
|
import 'package:angular2/src/transform/common/ng_compiler.dart';
|
||||||
import 'package:angular2/src/transform/common/ng_meta.dart';
|
import 'package:angular2/src/transform/common/ng_meta.dart';
|
||||||
import 'package:barback/barback.dart' show AssetId;
|
import 'package:angular2/src/transform/common/zone.dart' as zone;
|
||||||
import 'package:angular2/src/core/compiler/template_compiler.dart';
|
|
||||||
|
|
||||||
import 'inliner.dart';
|
import 'inliner.dart';
|
||||||
|
|
||||||
|
@ -35,7 +37,10 @@ Future<NgMeta> createNgMeta(AssetReader reader, AssetId assetId,
|
||||||
return logElapsedAsync(() async {
|
return logElapsedAsync(() async {
|
||||||
var ngMeta = new NgMeta(ngDeps: ngDepsVisitor.model);
|
var ngMeta = new NgMeta(ngDeps: ngDepsVisitor.model);
|
||||||
|
|
||||||
var templateCompiler = createTemplateCompiler(reader);
|
var templateCompiler = zone.templateCompiler;
|
||||||
|
if (templateCompiler == null) {
|
||||||
|
templateCompiler = createTemplateCompiler(reader);
|
||||||
|
}
|
||||||
var ngMetaVisitor = new _NgMetaVisitor(ngMeta, assetId, annotationMatcher,
|
var ngMetaVisitor = new _NgMetaVisitor(ngMeta, assetId, annotationMatcher,
|
||||||
_interfaceMatcher, templateCompiler);
|
_interfaceMatcher, templateCompiler);
|
||||||
parsedCode.accept(ngMetaVisitor);
|
parsedCode.accept(ngMetaVisitor);
|
||||||
|
@ -91,7 +96,7 @@ class _NgMetaVisitor extends Object with SimpleAstVisitor<Object> {
|
||||||
compileDirectiveMetadata;
|
compileDirectiveMetadata;
|
||||||
}
|
}
|
||||||
}).catchError((err) {
|
}).catchError((err) {
|
||||||
logger.error('ERROR: $err');
|
log.error('ERROR: $err');
|
||||||
}));
|
}));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,12 +3,13 @@ library angular2.transform.directive_processor.transformer;
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
|
|
||||||
|
import 'package:barback/barback.dart';
|
||||||
|
|
||||||
import 'package:angular2/src/core/dom/html_adapter.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/asset_reader.dart';
|
||||||
import 'package:angular2/src/transform/common/logging.dart' as log;
|
|
||||||
import 'package:angular2/src/transform/common/names.dart';
|
import 'package:angular2/src/transform/common/names.dart';
|
||||||
import 'package:angular2/src/transform/common/options.dart';
|
import 'package:angular2/src/transform/common/options.dart';
|
||||||
import 'package:barback/barback.dart';
|
import 'package:angular2/src/transform/common/zone.dart' as zone;
|
||||||
|
|
||||||
import 'rewriter.dart';
|
import 'rewriter.dart';
|
||||||
|
|
||||||
|
@ -32,7 +33,7 @@ class DirectiveProcessor extends Transformer {
|
||||||
@override
|
@override
|
||||||
Future apply(Transform transform) async {
|
Future apply(Transform transform) async {
|
||||||
Html5LibDomAdapter.makeCurrent();
|
Html5LibDomAdapter.makeCurrent();
|
||||||
await log.initZoned(transform, () async {
|
return zone.exec(() async {
|
||||||
var primaryId = transform.primaryInput.id;
|
var primaryId = transform.primaryInput.id;
|
||||||
var reader = new AssetReader.fromTransform(transform);
|
var reader = new AssetReader.fromTransform(transform);
|
||||||
var ngMeta =
|
var ngMeta =
|
||||||
|
@ -42,7 +43,7 @@ class DirectiveProcessor extends Transformer {
|
||||||
}
|
}
|
||||||
transform.addOutput(new Asset.fromString(
|
transform.addOutput(new Asset.fromString(
|
||||||
_ngSummaryAssetId(primaryId), _encoder.convert(ngMeta.toJson())));
|
_ngSummaryAssetId(primaryId), _encoder.convert(ngMeta.toJson())));
|
||||||
});
|
}, log: transform.logger);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,18 +4,19 @@ import 'dart:async';
|
||||||
|
|
||||||
import 'package:analyzer/analyzer.dart';
|
import 'package:analyzer/analyzer.dart';
|
||||||
import 'package:analyzer/src/generated/ast.dart';
|
import 'package:analyzer/src/generated/ast.dart';
|
||||||
|
import 'package:barback/barback.dart';
|
||||||
|
import 'package:dart_style/dart_style.dart';
|
||||||
|
|
||||||
import 'package:angular2/src/core/compiler/xhr.dart' show XHR;
|
import 'package:angular2/src/core/compiler/xhr.dart' show XHR;
|
||||||
import 'package:angular2/src/transform/common/annotation_matcher.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/asset_reader.dart';
|
||||||
import 'package:angular2/src/transform/common/naive_eval.dart';
|
import 'package:angular2/src/transform/common/naive_eval.dart';
|
||||||
import 'package:angular2/src/transform/common/async_string_writer.dart';
|
import 'package:angular2/src/transform/common/async_string_writer.dart';
|
||||||
import 'package:angular2/src/transform/common/logging.dart';
|
|
||||||
import 'package:angular2/src/transform/common/options.dart';
|
import 'package:angular2/src/transform/common/options.dart';
|
||||||
import 'package:angular2/src/transform/common/url_resolver.dart';
|
import 'package:angular2/src/transform/common/url_resolver.dart';
|
||||||
import 'package:angular2/src/transform/common/xhr_impl.dart';
|
import 'package:angular2/src/transform/common/xhr_impl.dart';
|
||||||
|
import 'package:angular2/src/transform/common/zone.dart' as zone;
|
||||||
import 'package:angular2/src/transform/directive_processor/inliner.dart';
|
import 'package:angular2/src/transform/directive_processor/inliner.dart';
|
||||||
import 'package:barback/barback.dart';
|
|
||||||
import 'package:dart_style/dart_style.dart';
|
|
||||||
|
|
||||||
/// Processes .dart files and inlines `templateUrl` and styleUrls` values.
|
/// Processes .dart files and inlines `templateUrl` and styleUrls` values.
|
||||||
class InlinerForTest extends Transformer {
|
class InlinerForTest extends Transformer {
|
||||||
|
@ -31,7 +32,7 @@ class InlinerForTest extends Transformer {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future apply(Transform transform) async {
|
Future apply(Transform transform) async {
|
||||||
return initZoned(transform, () async {
|
return zone.exec(() async {
|
||||||
var primaryId = transform.primaryInput.id;
|
var primaryId = transform.primaryInput.id;
|
||||||
var inlinedCode = await inline(new AssetReader.fromTransform(transform),
|
var inlinedCode = await inline(new AssetReader.fromTransform(transform),
|
||||||
primaryId, _annotationMatcher);
|
primaryId, _annotationMatcher);
|
||||||
|
@ -43,7 +44,7 @@ class InlinerForTest extends Transformer {
|
||||||
}
|
}
|
||||||
transform.addOutput(new Asset.fromString(primaryId, inlinedCode));
|
transform.addOutput(new Asset.fromString(primaryId, inlinedCode));
|
||||||
}
|
}
|
||||||
});
|
}, log: transform.logger);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -144,7 +145,8 @@ class _ViewPropInliner extends RecursiveAstVisitor<Object> {
|
||||||
void _populateStyleUrls(NamedExpression node) {
|
void _populateStyleUrls(NamedExpression node) {
|
||||||
var urls = naiveEval(node.expression);
|
var urls = naiveEval(node.expression);
|
||||||
if (urls is! List) {
|
if (urls is! List) {
|
||||||
logger.warning('styleUrls is not a List of Strings (${node.expression})');
|
zone.log
|
||||||
|
.warning('styleUrls is not a List of Strings (${node.expression})');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_writer.print(_code.substring(_lastIndex, node.offset));
|
_writer.print(_code.substring(_lastIndex, node.offset));
|
||||||
|
@ -156,7 +158,7 @@ class _ViewPropInliner extends RecursiveAstVisitor<Object> {
|
||||||
_writer.asyncPrint(_readOrEmptyString(url));
|
_writer.asyncPrint(_readOrEmptyString(url));
|
||||||
_writer.print("''', ");
|
_writer.print("''', ");
|
||||||
} else {
|
} else {
|
||||||
logger.warning('style url is not a String (${url})');
|
zone.log.warning('style url is not a String (${url})');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_writer.println(']');
|
_writer.println(']');
|
||||||
|
@ -165,7 +167,7 @@ class _ViewPropInliner extends RecursiveAstVisitor<Object> {
|
||||||
void _populateTemplateUrl(NamedExpression node) {
|
void _populateTemplateUrl(NamedExpression node) {
|
||||||
var url = naiveEval(node.expression);
|
var url = naiveEval(node.expression);
|
||||||
if (url is! String) {
|
if (url is! String) {
|
||||||
logger.warning('template url is not a String (${node.expression})');
|
zone.log.warning('template url is not a String (${node.expression})');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_writer.print(_code.substring(_lastIndex, node.offset));
|
_writer.print(_code.substring(_lastIndex, node.offset));
|
||||||
|
@ -181,7 +183,7 @@ class _ViewPropInliner extends RecursiveAstVisitor<Object> {
|
||||||
final resolvedUri = _urlResolver.resolve(_baseUri.toString(), url);
|
final resolvedUri = _urlResolver.resolve(_baseUri.toString(), url);
|
||||||
|
|
||||||
return _xhr.get(resolvedUri).catchError((_) {
|
return _xhr.get(resolvedUri).catchError((_) {
|
||||||
logger.error('$_baseUri: could not read $url');
|
zone.log.error('$_baseUri: could not read $url');
|
||||||
return '';
|
return '';
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -91,7 +91,7 @@ class _RewriterVisitor extends Object with RecursiveAstVisitor<Object> {
|
||||||
Object visitInstanceCreationExpression(InstanceCreationExpression node) {
|
Object visitInstanceCreationExpression(InstanceCreationExpression node) {
|
||||||
if (_rewriter._mirrorMatcher.isNewReflectionCapabilities(node) &&
|
if (_rewriter._mirrorMatcher.isNewReflectionCapabilities(node) &&
|
||||||
!reflectionCapabilityAssignments.contains(node.parent)) {
|
!reflectionCapabilityAssignments.contains(node.parent)) {
|
||||||
logger.error('Unexpected format in creation of '
|
log.error('Unexpected format in creation of '
|
||||||
'${REFLECTION_CAPABILITIES_NAME}');
|
'${REFLECTION_CAPABILITIES_NAME}');
|
||||||
}
|
}
|
||||||
return super.visitInstanceCreationExpression(node);
|
return super.visitInstanceCreationExpression(node);
|
||||||
|
@ -132,7 +132,7 @@ class _RewriterVisitor extends Object with RecursiveAstVisitor<Object> {
|
||||||
var args = node.argumentList.arguments;
|
var args = node.argumentList.arguments;
|
||||||
int numArgs = node.argumentList.arguments.length;
|
int numArgs = node.argumentList.arguments.length;
|
||||||
if (numArgs < 1 || numArgs > 2) {
|
if (numArgs < 1 || numArgs > 2) {
|
||||||
logger.warning('`bootstrap` does not support $numArgs arguments. '
|
log.warning('`bootstrap` does not support $numArgs arguments. '
|
||||||
'Found bootstrap${node.argumentList}. Transform may not succeed.');
|
'Found bootstrap${node.argumentList}. Transform may not succeed.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -168,7 +168,7 @@ class _RewriterVisitor extends Object with RecursiveAstVisitor<Object> {
|
||||||
_rewriteReflectionCapabilitiesImport(ImportDirective node) {
|
_rewriteReflectionCapabilitiesImport(ImportDirective node) {
|
||||||
buf.write(_rewriter._code.substring(_currentIndex, node.offset));
|
buf.write(_rewriter._code.substring(_currentIndex, node.offset));
|
||||||
if ('${node.prefix}' == _rewriter._codegen.prefix) {
|
if ('${node.prefix}' == _rewriter._codegen.prefix) {
|
||||||
logger.warning(
|
log.warning(
|
||||||
'Found import prefix "${_rewriter._codegen.prefix}" in source file.'
|
'Found import prefix "${_rewriter._codegen.prefix}" in source file.'
|
||||||
' Transform may not succeed.');
|
' Transform may not succeed.');
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,14 @@
|
||||||
library angular2.transform.reflection_remover.transformer;
|
library angular2.transform.reflection_remover.transformer;
|
||||||
|
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
|
||||||
|
import 'package:barback/barback.dart';
|
||||||
|
|
||||||
import 'package:angular2/src/transform/common/asset_reader.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/mirror_mode.dart';
|
import 'package:angular2/src/transform/common/mirror_mode.dart';
|
||||||
import 'package:angular2/src/transform/common/names.dart';
|
import 'package:angular2/src/transform/common/names.dart';
|
||||||
import 'package:angular2/src/transform/common/options.dart';
|
import 'package:angular2/src/transform/common/options.dart';
|
||||||
import 'package:barback/barback.dart';
|
import 'package:angular2/src/transform/common/zone.dart' as zone;
|
||||||
|
|
||||||
import 'remove_reflection_capabilities.dart';
|
import 'remove_reflection_capabilities.dart';
|
||||||
|
|
||||||
|
@ -30,14 +32,14 @@ class ReflectionRemover extends Transformer {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future apply(Transform transform) async {
|
Future apply(Transform transform) async {
|
||||||
await log.initZoned(transform, () async {
|
return zone.exec(() async {
|
||||||
var primaryId = transform.primaryInput.id;
|
var primaryId = transform.primaryInput.id;
|
||||||
var mirrorMode = options.mirrorMode;
|
var mirrorMode = options.mirrorMode;
|
||||||
var writeStaticInit = options.initReflector;
|
var writeStaticInit = options.initReflector;
|
||||||
if (options.modeName == TRANSFORM_DYNAMIC_MODE) {
|
if (options.modeName == TRANSFORM_DYNAMIC_MODE) {
|
||||||
mirrorMode = MirrorMode.debug;
|
mirrorMode = MirrorMode.debug;
|
||||||
writeStaticInit = false;
|
writeStaticInit = false;
|
||||||
log.logger.info('Running in "${options.modeName}", '
|
zone.log.info('Running in "${options.modeName}", '
|
||||||
'mirrorMode: ${mirrorMode}, '
|
'mirrorMode: ${mirrorMode}, '
|
||||||
'writeStaticInit: ${writeStaticInit}.');
|
'writeStaticInit: ${writeStaticInit}.');
|
||||||
}
|
}
|
||||||
|
@ -46,6 +48,6 @@ class ReflectionRemover extends Transformer {
|
||||||
new AssetReader.fromTransform(transform), primaryId,
|
new AssetReader.fromTransform(transform), primaryId,
|
||||||
mirrorMode: mirrorMode, writeStaticInit: writeStaticInit);
|
mirrorMode: mirrorMode, writeStaticInit: writeStaticInit);
|
||||||
transform.addOutput(new Asset.fromString(primaryId, transformedCode));
|
transform.addOutput(new Asset.fromString(primaryId, transformedCode));
|
||||||
});
|
}, log: transform.logger);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,12 +2,13 @@ library angular2.transform.stylesheet_compiler.processor;
|
||||||
|
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
|
||||||
|
import 'package:angular2/src/core/compiler/source_module.dart';
|
||||||
import 'package:angular2/src/transform/common/asset_reader.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/code/source_module.dart';
|
||||||
import 'package:angular2/src/transform/common/logging.dart';
|
import 'package:angular2/src/transform/common/logging.dart';
|
||||||
import 'package:angular2/src/transform/common/names.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_compiler.dart';
|
||||||
import 'package:angular2/src/core/compiler/source_module.dart';
|
import 'package:angular2/src/transform/common/zone.dart' as zone;
|
||||||
|
|
||||||
import 'package:barback/barback.dart';
|
import 'package:barback/barback.dart';
|
||||||
|
|
||||||
|
@ -20,7 +21,10 @@ AssetId nonShimmedStylesheetAssetId(AssetId cssAssetId) => new AssetId(
|
||||||
Future<Iterable<Asset>> processStylesheet(
|
Future<Iterable<Asset>> processStylesheet(
|
||||||
AssetReader reader, AssetId stylesheetId) async {
|
AssetReader reader, AssetId stylesheetId) async {
|
||||||
final stylesheetUrl = '${stylesheetId.package}|${stylesheetId.path}';
|
final stylesheetUrl = '${stylesheetId.package}|${stylesheetId.path}';
|
||||||
final templateCompiler = createTemplateCompiler(reader);
|
var templateCompiler = zone.templateCompiler;
|
||||||
|
if (templateCompiler == null) {
|
||||||
|
templateCompiler = createTemplateCompiler(reader);
|
||||||
|
}
|
||||||
final cssText = await reader.readAsString(stylesheetId);
|
final cssText = await reader.readAsString(stylesheetId);
|
||||||
return logElapsedAsync(() async {
|
return logElapsedAsync(() async {
|
||||||
final sourceModules =
|
final sourceModules =
|
||||||
|
|
|
@ -2,12 +2,12 @@ library angular2.transform.stylesheet_compiler.transformer;
|
||||||
|
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
|
||||||
|
import 'package:barback/barback.dart';
|
||||||
|
|
||||||
import 'package:angular2/src/core/dom/html_adapter.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/asset_reader.dart';
|
||||||
import 'package:angular2/src/transform/common/logging.dart' as log;
|
|
||||||
import 'package:angular2/src/transform/common/names.dart';
|
import 'package:angular2/src/transform/common/names.dart';
|
||||||
|
import 'package:angular2/src/transform/common/zone.dart' as zone;
|
||||||
import 'package:barback/barback.dart';
|
|
||||||
|
|
||||||
import 'processor.dart';
|
import 'processor.dart';
|
||||||
|
|
||||||
|
@ -22,13 +22,13 @@ class StylesheetCompiler extends Transformer {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future apply(Transform transform) async {
|
Future apply(Transform transform) async {
|
||||||
await log.initZoned(transform, () async {
|
final reader = new AssetReader.fromTransform(transform);
|
||||||
|
return zone.exec(() async {
|
||||||
Html5LibDomAdapter.makeCurrent();
|
Html5LibDomAdapter.makeCurrent();
|
||||||
var reader = new AssetReader.fromTransform(transform);
|
|
||||||
var outputs = await processStylesheet(reader, transform.primaryInput.id);
|
var outputs = await processStylesheet(reader, transform.primaryInput.id);
|
||||||
outputs.forEach((Asset compiledStylesheet) {
|
outputs.forEach((Asset compiledStylesheet) {
|
||||||
transform.addOutput(compiledStylesheet);
|
transform.addOutput(compiledStylesheet);
|
||||||
});
|
});
|
||||||
});
|
}, log: transform.logger);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,7 +77,7 @@ class _CompileDataCreator {
|
||||||
|
|
||||||
for (var dep in reflectable.directives) {
|
for (var dep in reflectable.directives) {
|
||||||
if (!ngMetaMap.containsKey(dep.prefix)) {
|
if (!ngMetaMap.containsKey(dep.prefix)) {
|
||||||
logger.warning(
|
log.warning(
|
||||||
'Missing prefix "${dep.prefix}" '
|
'Missing prefix "${dep.prefix}" '
|
||||||
'needed by "${dep}" from metadata map',
|
'needed by "${dep}" from metadata map',
|
||||||
asset: entryPoint);
|
asset: entryPoint);
|
||||||
|
@ -90,7 +90,7 @@ class _CompileDataCreator {
|
||||||
} else if (depNgMeta.aliases.containsKey(dep.name)) {
|
} else if (depNgMeta.aliases.containsKey(dep.name)) {
|
||||||
compileDatum.directives.addAll(depNgMeta.flatten(dep.name));
|
compileDatum.directives.addAll(depNgMeta.flatten(dep.name));
|
||||||
} else {
|
} else {
|
||||||
logger.warning('Could not find Directive entry for $dep. '
|
log.warning('Could not find Directive entry for $dep. '
|
||||||
'Please be aware that Dart transformers have limited support for '
|
'Please be aware that Dart transformers have limited support for '
|
||||||
'reusable, pre-defined lists of Directives (aka '
|
'reusable, pre-defined lists of Directives (aka '
|
||||||
'"directive aliases"). See https://goo.gl/d8XPt0 for details.');
|
'"directive aliases"). See https://goo.gl/d8XPt0 for details.');
|
||||||
|
@ -110,7 +110,7 @@ class _CompileDataCreator {
|
||||||
for (var ad in ambientDirectives) {
|
for (var ad in ambientDirectives) {
|
||||||
final parts = ad.split("#");
|
final parts = ad.split("#");
|
||||||
if (parts.length != 2) {
|
if (parts.length != 2) {
|
||||||
logger.warning('The ambient directives configuration option '
|
log.warning('The ambient directives configuration option '
|
||||||
'must be in the following format: "URI#TOKEN"');
|
'must be in the following format: "URI#TOKEN"');
|
||||||
return const [];
|
return const [];
|
||||||
}
|
}
|
||||||
|
@ -134,13 +134,13 @@ class _CompileDataCreator {
|
||||||
return newMetadata.flatten(token);
|
return newMetadata.flatten(token);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
logger.warning('Could not resolve ambient directive ${token} in ${uri}',
|
log.warning('Could not resolve ambient directive ${token} in ${uri}',
|
||||||
asset: metaAssetId);
|
asset: metaAssetId);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
} catch (ex, stackTrace) {
|
} catch (ex, stackTrace) {
|
||||||
logger.warning('Failed to decode: $ex, $stackTrace',
|
log.warning('Failed to decode: $ex, $stackTrace',
|
||||||
asset: metaAssetId);
|
asset: metaAssetId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -214,7 +214,7 @@ class _CompileDataCreator {
|
||||||
ngMeta.addAll(newMetadata);
|
ngMeta.addAll(newMetadata);
|
||||||
}
|
}
|
||||||
} catch (ex, stackTrace) {
|
} catch (ex, stackTrace) {
|
||||||
logger.warning('Failed to decode: $ex, $stackTrace',
|
log.warning('Failed to decode: $ex, $stackTrace',
|
||||||
asset: metaAssetId);
|
asset: metaAssetId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,9 @@ library angular2.transform.template_compiler.generator;
|
||||||
|
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
|
||||||
|
import 'package:barback/barback.dart';
|
||||||
|
import 'package:path/path.dart' as path;
|
||||||
|
|
||||||
import 'package:angular2/src/core/change_detection/interfaces.dart';
|
import 'package:angular2/src/core/change_detection/interfaces.dart';
|
||||||
import 'package:angular2/src/core/facade/lang.dart';
|
import 'package:angular2/src/core/facade/lang.dart';
|
||||||
import 'package:angular2/src/core/reflection/reflection.dart';
|
import 'package:angular2/src/core/reflection/reflection.dart';
|
||||||
|
@ -13,8 +16,7 @@ import 'package:angular2/src/transform/common/model/import_export_model.pb.dart'
|
||||||
import 'package:angular2/src/transform/common/model/ng_deps_model.pb.dart';
|
import 'package:angular2/src/transform/common/model/ng_deps_model.pb.dart';
|
||||||
import 'package:angular2/src/transform/common/names.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_compiler.dart';
|
||||||
import 'package:barback/barback.dart';
|
import 'package:angular2/src/transform/common/zone.dart' as zone;
|
||||||
import 'package:path/path.dart' as path;
|
|
||||||
|
|
||||||
import 'reflection/processor.dart' as reg;
|
import 'reflection/processor.dart' as reg;
|
||||||
import 'reflection/reflection_capabilities.dart';
|
import 'reflection/reflection_capabilities.dart';
|
||||||
|
@ -40,9 +42,12 @@ Future<Outputs> processTemplates(AssetReader reader, AssetId assetId,
|
||||||
viewDefResults.ngMeta.ngDeps.methods
|
viewDefResults.ngMeta.ngDeps.methods
|
||||||
.addAll(processor.methodNames.map((e) => e.sanitizedName));
|
.addAll(processor.methodNames.map((e) => e.sanitizedName));
|
||||||
}
|
}
|
||||||
var templateCompiler = createTemplateCompiler(reader,
|
var templateCompiler = zone.templateCompiler;
|
||||||
changeDetectionConfig: new ChangeDetectorGenConfig(assertionsEnabled(),
|
if (templateCompiler == null) {
|
||||||
assertionsEnabled(), reflectPropertiesAsAttributes, false));
|
templateCompiler = createTemplateCompiler(reader,
|
||||||
|
changeDetectionConfig: new ChangeDetectorGenConfig(assertionsEnabled(),
|
||||||
|
assertionsEnabled(), reflectPropertiesAsAttributes, false));
|
||||||
|
}
|
||||||
|
|
||||||
final compileData =
|
final compileData =
|
||||||
viewDefResults.viewDefinitions.values.toList(growable: false);
|
viewDefResults.viewDefinitions.values.toList(growable: false);
|
||||||
|
|
|
@ -2,14 +2,15 @@ library angular2.transform.template_compiler.transformer;
|
||||||
|
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
|
||||||
|
import 'package:barback/barback.dart';
|
||||||
|
|
||||||
import 'package:angular2/src/core/dom/html_adapter.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/asset_reader.dart';
|
||||||
import 'package:angular2/src/transform/common/code/ng_deps_code.dart';
|
import 'package:angular2/src/transform/common/code/ng_deps_code.dart';
|
||||||
import 'package:angular2/src/transform/common/formatter.dart';
|
import 'package:angular2/src/transform/common/formatter.dart';
|
||||||
import 'package:angular2/src/transform/common/logging.dart' as log;
|
|
||||||
import 'package:angular2/src/transform/common/names.dart';
|
import 'package:angular2/src/transform/common/names.dart';
|
||||||
import 'package:angular2/src/transform/common/options.dart';
|
import 'package:angular2/src/transform/common/options.dart';
|
||||||
import 'package:barback/barback.dart';
|
import 'package:angular2/src/transform/common/zone.dart' as zone;
|
||||||
|
|
||||||
import 'generator.dart';
|
import 'generator.dart';
|
||||||
|
|
||||||
|
@ -32,7 +33,7 @@ class TemplateCompiler extends Transformer {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future apply(Transform transform) async {
|
Future apply(Transform transform) async {
|
||||||
await log.initZoned(transform, () async {
|
return zone.exec(() async {
|
||||||
Html5LibDomAdapter.makeCurrent();
|
Html5LibDomAdapter.makeCurrent();
|
||||||
var primaryId = transform.primaryInput.id;
|
var primaryId = transform.primaryInput.id;
|
||||||
var reader = new AssetReader.fromTransform(transform);
|
var reader = new AssetReader.fromTransform(transform);
|
||||||
|
@ -56,7 +57,7 @@ class TemplateCompiler extends Transformer {
|
||||||
new Asset.fromString(ngDepsAssetId(primaryId), ngDepsCode));
|
new Asset.fromString(ngDepsAssetId(primaryId), ngDepsCode));
|
||||||
transform.addOutput(
|
transform.addOutput(
|
||||||
new Asset.fromString(templatesAssetId(primaryId), templatesCode));
|
new Asset.fromString(templatesAssetId(primaryId), templatesCode));
|
||||||
});
|
}, log: transform.logger);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,13 @@
|
||||||
library angular2.test.transform.deferred_rewriter.all_tests;
|
library angular2.test.transform.deferred_rewriter.all_tests;
|
||||||
|
|
||||||
import 'package:barback/barback.dart';
|
import 'package:barback/barback.dart';
|
||||||
import 'package:angular2/src/transform/deferred_rewriter/transformer.dart';
|
|
||||||
import 'package:angular2/src/transform/common/logging.dart' as log;
|
|
||||||
import 'package:dart_style/dart_style.dart';
|
import 'package:dart_style/dart_style.dart';
|
||||||
import 'package:guinness/guinness.dart';
|
import 'package:guinness/guinness.dart';
|
||||||
import 'package:path/path.dart' as path;
|
import 'package:path/path.dart' as path;
|
||||||
|
|
||||||
|
import 'package:angular2/src/transform/common/zone.dart' as zone;
|
||||||
|
import 'package:angular2/src/transform/deferred_rewriter/transformer.dart';
|
||||||
|
|
||||||
import '../common/read_file.dart';
|
import '../common/read_file.dart';
|
||||||
import '../common/recording_logger.dart';
|
import '../common/recording_logger.dart';
|
||||||
|
|
||||||
|
@ -35,7 +37,7 @@ void allTests() {
|
||||||
|
|
||||||
void _testRewriteDeferredLibraries(String name, String inputPath) {
|
void _testRewriteDeferredLibraries(String name, String inputPath) {
|
||||||
it(name, () {
|
it(name, () {
|
||||||
return log.setZoned(new RecordingLogger(), () async {
|
return zone.exec(() async {
|
||||||
var inputId = _assetIdForPath(inputPath);
|
var inputId = _assetIdForPath(inputPath);
|
||||||
var reader = new TestAssetReader();
|
var reader = new TestAssetReader();
|
||||||
var expectedPath = path.join(
|
var expectedPath = path.join(
|
||||||
|
@ -50,7 +52,7 @@ void _testRewriteDeferredLibraries(String name, String inputPath) {
|
||||||
} else {
|
} else {
|
||||||
expect(formatter.format(output)).toEqual(formatter.format(input));
|
expect(formatter.format(output)).toEqual(formatter.format(input));
|
||||||
}
|
}
|
||||||
});
|
}, log: new RecordingLogger());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,15 +3,16 @@ library angular2.test.transform.directive_metadata_linker.all_tests;
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'dart:convert';
|
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/names.dart';
|
|
||||||
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';
|
import 'package:barback/barback.dart';
|
||||||
import 'package:dart_style/dart_style.dart';
|
import 'package:dart_style/dart_style.dart';
|
||||||
import 'package:guinness/guinness.dart';
|
import 'package:guinness/guinness.dart';
|
||||||
|
|
||||||
|
import 'package:angular2/src/transform/common/asset_reader.dart';
|
||||||
|
import 'package:angular2/src/transform/common/names.dart';
|
||||||
|
import 'package:angular2/src/transform/common/model/import_export_model.pb.dart';
|
||||||
|
import 'package:angular2/src/transform/common/zone.dart' as zone;
|
||||||
|
import 'package:angular2/src/transform/directive_metadata_linker/ng_meta_linker.dart';
|
||||||
|
|
||||||
import '../common/ng_meta_helper.dart';
|
import '../common/ng_meta_helper.dart';
|
||||||
import '../common/read_file.dart';
|
import '../common/read_file.dart';
|
||||||
import '../common/recording_logger.dart';
|
import '../common/recording_logger.dart';
|
||||||
|
@ -172,6 +173,6 @@ void allTests() {
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<NgMeta> _testLink(AssetReader reader, AssetId assetId) {
|
Future<NgMeta> _testLink(AssetReader reader, AssetId assetId) {
|
||||||
return log.setZoned(
|
return zone.exec(() => linkDirectiveMetadata(reader, assetId),
|
||||||
new RecordingLogger(), () => linkDirectiveMetadata(reader, assetId));
|
log: new RecordingLogger());
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,20 +2,22 @@ library angular2.test.transform.directive_processor.all_tests;
|
||||||
|
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
|
||||||
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';
|
|
||||||
import 'package:angular2/src/transform/directive_processor/rewriter.dart';
|
|
||||||
import 'package:angular2/src/transform/common/annotation_matcher.dart';
|
|
||||||
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/ng_deps_model.pb.dart';
|
|
||||||
import 'package:angular2/src/transform/common/model/reflection_info_model.pb.dart';
|
|
||||||
import 'package:angular2/src/transform/common/ng_meta.dart';
|
|
||||||
import 'package:barback/barback.dart';
|
import 'package:barback/barback.dart';
|
||||||
import 'package:dart_style/dart_style.dart';
|
import 'package:dart_style/dart_style.dart';
|
||||||
import 'package:guinness/guinness.dart';
|
import 'package:guinness/guinness.dart';
|
||||||
|
|
||||||
|
import 'package:angular2/src/core/change_detection/change_detection.dart';
|
||||||
|
import 'package:angular2/src/core/dom/html_adapter.dart';
|
||||||
|
import 'package:angular2/src/core/linker/interfaces.dart' show LifecycleHooks;
|
||||||
|
import 'package:angular2/src/transform/common/annotation_matcher.dart';
|
||||||
|
import 'package:angular2/src/transform/common/asset_reader.dart';
|
||||||
|
import 'package:angular2/src/transform/common/code/ng_deps_code.dart';
|
||||||
|
import 'package:angular2/src/transform/common/model/ng_deps_model.pb.dart';
|
||||||
|
import 'package:angular2/src/transform/common/model/reflection_info_model.pb.dart';
|
||||||
|
import 'package:angular2/src/transform/common/ng_meta.dart';
|
||||||
|
import 'package:angular2/src/transform/common/zone.dart' as zone;
|
||||||
|
import 'package:angular2/src/transform/directive_processor/rewriter.dart';
|
||||||
|
|
||||||
import '../common/read_file.dart';
|
import '../common/read_file.dart';
|
||||||
import '../common/recording_logger.dart';
|
import '../common/recording_logger.dart';
|
||||||
|
|
||||||
|
@ -494,32 +496,31 @@ void allTests() {
|
||||||
..prefix = 'dep2');
|
..prefix = 'dep2');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should merge `outputs` from the annotation and fields.',
|
it('should merge `outputs` from the annotation and fields.', () async {
|
||||||
() async {
|
|
||||||
var model = await _testCreateModel('directives_files/components.dart');
|
var model = await _testCreateModel('directives_files/components.dart');
|
||||||
expect(model.types['ComponentWithOutputs'].outputs).
|
expect(model.types['ComponentWithOutputs'].outputs)
|
||||||
toEqual({'a': 'a', 'b': 'b', 'c': 'renamed'});
|
.toEqual({'a': 'a', 'b': 'b', 'c': 'renamed'});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should merge `inputs` from the annotation and fields.',
|
it('should merge `inputs` from the annotation and fields.', () async {
|
||||||
() async {
|
|
||||||
var model = await _testCreateModel('directives_files/components.dart');
|
var model = await _testCreateModel('directives_files/components.dart');
|
||||||
expect(model.types['ComponentWithInputs'].inputs).
|
expect(model.types['ComponentWithInputs'].inputs)
|
||||||
toEqual({'a': 'a', 'b': 'b', 'c': 'renamed'});
|
.toEqual({'a': 'a', 'b': 'b', 'c': 'renamed'});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should merge host bindings from the annotation and fields.',
|
it('should merge host bindings from the annotation and fields.', () async {
|
||||||
() async {
|
|
||||||
var model = await _testCreateModel('directives_files/components.dart');
|
var model = await _testCreateModel('directives_files/components.dart');
|
||||||
expect(model.types['ComponentWithHostBindings'].hostProperties).
|
expect(model.types['ComponentWithHostBindings'].hostProperties)
|
||||||
toEqual({'a': 'a', 'b': 'b', 'renamed': 'c'});
|
.toEqual({'a': 'a', 'b': 'b', 'renamed': 'c'});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should merge host listeners from the annotation and fields.',
|
it('should merge host listeners from the annotation and fields.', () async {
|
||||||
() async {
|
|
||||||
var model = await _testCreateModel('directives_files/components.dart');
|
var model = await _testCreateModel('directives_files/components.dart');
|
||||||
expect(model.types['ComponentWithHostListeners'].hostListeners).
|
expect(model.types['ComponentWithHostListeners'].hostListeners).toEqual({
|
||||||
toEqual({'a': 'onA()', 'b': 'onB()', 'c': 'onC(\$event.target,\$event.target.value)'});
|
'a': 'onA()',
|
||||||
|
'b': 'onB()',
|
||||||
|
'c': 'onC(\$event.target,\$event.target.value)'
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should warn if @Component has a `template` and @View is present.',
|
it('should warn if @Component has a `template` and @View is present.',
|
||||||
|
@ -568,7 +569,7 @@ Future<NgMeta> _testCreateModel(String inputPath,
|
||||||
AssetReader reader,
|
AssetReader reader,
|
||||||
TransformLogger logger}) {
|
TransformLogger logger}) {
|
||||||
if (logger == null) logger = new RecordingLogger();
|
if (logger == null) logger = new RecordingLogger();
|
||||||
return log.setZoned(logger, () async {
|
return zone.exec(() async {
|
||||||
var inputId = _assetIdForPath(inputPath);
|
var inputId = _assetIdForPath(inputPath);
|
||||||
if (reader == null) {
|
if (reader == null) {
|
||||||
reader = new TestAssetReader();
|
reader = new TestAssetReader();
|
||||||
|
@ -580,7 +581,7 @@ Future<NgMeta> _testCreateModel(String inputPath,
|
||||||
|
|
||||||
var annotationMatcher = new AnnotationMatcher()..addAll(customDescriptors);
|
var annotationMatcher = new AnnotationMatcher()..addAll(customDescriptors);
|
||||||
return createNgMeta(reader, inputId, annotationMatcher);
|
return createNgMeta(reader, inputId, annotationMatcher);
|
||||||
});
|
}, log: logger);
|
||||||
}
|
}
|
||||||
|
|
||||||
AssetId _assetIdForPath(String path) =>
|
AssetId _assetIdForPath(String path) =>
|
||||||
|
|
|
@ -2,16 +2,17 @@ library angular2.test.transform.inliner_for_test.all_tests;
|
||||||
|
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
|
||||||
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:angular2/src/transform/common/options.dart';
|
|
||||||
import 'package:angular2/src/transform/inliner_for_test/transformer.dart';
|
|
||||||
import 'package:barback/barback.dart';
|
import 'package:barback/barback.dart';
|
||||||
import 'package:code_transformers/tests.dart';
|
import 'package:code_transformers/tests.dart';
|
||||||
import 'package:guinness/guinness.dart';
|
import 'package:guinness/guinness.dart';
|
||||||
import 'package:dart_style/dart_style.dart';
|
import 'package:dart_style/dart_style.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/options.dart';
|
||||||
|
import 'package:angular2/src/transform/common/zone.dart' as zone;
|
||||||
|
import 'package:angular2/src/transform/inliner_for_test/transformer.dart';
|
||||||
|
|
||||||
import '../common/read_file.dart';
|
import '../common/read_file.dart';
|
||||||
import '../common/recording_logger.dart';
|
import '../common/recording_logger.dart';
|
||||||
|
|
||||||
|
@ -118,8 +119,8 @@ void allTests() {
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<String> _testInline(AssetReader reader, AssetId assetId) {
|
Future<String> _testInline(AssetReader reader, AssetId assetId) {
|
||||||
return log.setZoned(
|
return zone.exec(() => inline(reader, assetId, annotationMatcher),
|
||||||
new RecordingLogger(), () => inline(reader, assetId, annotationMatcher));
|
log: new RecordingLogger());
|
||||||
}
|
}
|
||||||
|
|
||||||
AssetId _assetId(String path) => new AssetId('a', 'inliner_for_test/$path');
|
AssetId _assetId(String path) => new AssetId('a', 'inliner_for_test/$path');
|
||||||
|
|
|
@ -4,15 +4,16 @@ import 'dart:async';
|
||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
|
|
||||||
import 'package:barback/barback.dart';
|
import 'package:barback/barback.dart';
|
||||||
import 'package:angular2/src/core/change_detection/codegen_name_util.dart'
|
|
||||||
show CONTEXT_ACCESSOR;
|
|
||||||
import 'package:angular2/src/core/dom/html_adapter.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:dart_style/dart_style.dart';
|
||||||
import 'package:path/path.dart' as path;
|
import 'package:path/path.dart' as path;
|
||||||
import 'package:guinness/guinness.dart';
|
import 'package:guinness/guinness.dart';
|
||||||
|
|
||||||
|
import 'package:angular2/src/core/change_detection/codegen_name_util.dart'
|
||||||
|
show CONTEXT_ACCESSOR;
|
||||||
|
import 'package:angular2/src/core/dom/html_adapter.dart';
|
||||||
|
import 'package:angular2/src/transform/template_compiler/generator.dart';
|
||||||
|
import 'package:angular2/src/transform/common/zone.dart' as zone;
|
||||||
|
|
||||||
import '../common/compile_directive_metadata/ng_for.ng_meta.dart' as ngMeta;
|
import '../common/compile_directive_metadata/ng_for.ng_meta.dart' as ngMeta;
|
||||||
import '../common/ng_meta_helper.dart';
|
import '../common/ng_meta_helper.dart';
|
||||||
import '../common/read_file.dart';
|
import '../common/read_file.dart';
|
||||||
|
@ -76,8 +77,10 @@ void allTests() {
|
||||||
|
|
||||||
Future<String> process(AssetId assetId, {List<String> ambientDirectives}) {
|
Future<String> process(AssetId assetId, {List<String> ambientDirectives}) {
|
||||||
logger = new RecordingLogger();
|
logger = new RecordingLogger();
|
||||||
return log.setZoned(logger, () => processTemplates(reader, assetId,
|
return zone.exec(
|
||||||
ambientDirectives: ambientDirectives));
|
() => processTemplates(reader, assetId,
|
||||||
|
ambientDirectives: ambientDirectives),
|
||||||
|
log: logger);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(tbosch): This is just a temporary test that makes sure that the dart
|
// TODO(tbosch): This is just a temporary test that makes sure that the dart
|
||||||
|
@ -357,7 +360,8 @@ void allTests() {
|
||||||
barNgMeta.aliases['AMBIENT'] = [barComponentMeta.type.name];
|
barNgMeta.aliases['AMBIENT'] = [barComponentMeta.type.name];
|
||||||
updateReader();
|
updateReader();
|
||||||
|
|
||||||
final outputs = await process(fooAssetId, ambientDirectives: ['package:a/bar.dart#AMBIENT']);
|
final outputs = await process(fooAssetId,
|
||||||
|
ambientDirectives: ['package:a/bar.dart#AMBIENT']);
|
||||||
final ngDeps = outputs.ngDeps;
|
final ngDeps = outputs.ngDeps;
|
||||||
expect(ngDeps).toBeNotNull();
|
expect(ngDeps).toBeNotNull();
|
||||||
expect(outputs.templatesCode)
|
expect(outputs.templatesCode)
|
||||||
|
@ -374,7 +378,8 @@ void allTests() {
|
||||||
barNgMeta.types['AMBIENT'] = barComponentMeta;
|
barNgMeta.types['AMBIENT'] = barComponentMeta;
|
||||||
updateReader();
|
updateReader();
|
||||||
|
|
||||||
final outputs = await process(fooAssetId, ambientDirectives: ['package:a/bar.dart#AMBIENT']);
|
final outputs = await process(fooAssetId,
|
||||||
|
ambientDirectives: ['package:a/bar.dart#AMBIENT']);
|
||||||
final ngDeps = outputs.ngDeps;
|
final ngDeps = outputs.ngDeps;
|
||||||
expect(ngDeps).toBeNotNull();
|
expect(ngDeps).toBeNotNull();
|
||||||
expect(outputs.templatesCode)
|
expect(outputs.templatesCode)
|
||||||
|
@ -388,21 +393,25 @@ void allTests() {
|
||||||
expect(ngDeps).toBeNotNull();
|
expect(ngDeps).toBeNotNull();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should work when the ambient directives config is not formatted properly.', () async {
|
it('should work when the ambient directives config is not formatted properly.',
|
||||||
|
() async {
|
||||||
final outputs = await process(fooAssetId, ambientDirectives: ['INVALID']);
|
final outputs = await process(fooAssetId, ambientDirectives: ['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.', () async {
|
it('should work when the file with ambient directives cannot be found.',
|
||||||
final outputs = await process(
|
() async {
|
||||||
fooAssetId, ambientDirectives: ['package:a/invalid.dart#AMBIENT']);
|
final outputs = await process(fooAssetId,
|
||||||
|
ambientDirectives: ['package:a/invalid.dart#AMBIENT']);
|
||||||
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.', () async {
|
it('should work when the ambient directives token cannot be found.',
|
||||||
final outputs = await process(fooAssetId, ambientDirectives: ['package:a/bar.dart#AMBIENT']);
|
() async {
|
||||||
|
final outputs = await process(fooAssetId,
|
||||||
|
ambientDirectives: ['package:a/bar.dart#AMBIENT']);
|
||||||
final ngDeps = outputs.ngDeps;
|
final ngDeps = outputs.ngDeps;
|
||||||
expect(ngDeps).toBeNotNull();
|
expect(ngDeps).toBeNotNull();
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue