fix(dart/transform): Ensure template codegen is completed sync

Previously, template codegen was done asynchronously, which could result
in reflector state being overwritten and leading to compile errors.

Update the codegen to run synchronously to ensure this does not happen.

Closes #6603
This commit is contained in:
Tim Blasi 2016-01-20 17:56:29 -08:00 committed by Timothy Blasi
parent b5b6ece65a
commit 5f0baaac73
2 changed files with 22 additions and 2 deletions

View File

@ -22,13 +22,31 @@ Future logElapsedAsync(Future asyncOperation(),
final timer = new Stopwatch()..start();
final result = await asyncOperation();
timer.stop();
_logElapsed(timer, operationName, assetId);
return result;
}
/// Writes a log entry at `LogLevel.FINE` granularity with the time taken by
/// `operation`.
///
/// Returns the result of executing `operation`.
dynamic logElapsedSync(dynamic operation(),
{String operationName: 'unknown', AssetId assetId}) {
final timer = new Stopwatch()..start();
final result = operation();
timer.stop();
_logElapsed(timer, operationName, assetId);
return result;
}
/// Logs the time since `timer` was started.
void _logElapsed(Stopwatch timer, String operationName, AssetId assetId) {
final buf =
new StringBuffer('[$operationName] took ${timer.elapsedMilliseconds} ms');
if (assetId != null) {
buf.write(' on $assetId');
}
log.fine(buf.toString(), asset: assetId);
return result;
}
/// Prints logged messages to the console.

View File

@ -69,7 +69,9 @@ Future<Outputs> processTemplates(AssetReader reader, AssetId assetId,
var savedReflectionCapabilities = reflector.reflectionCapabilities;
reflector.reflectionCapabilities = const NullReflectionCapabilities();
final compiledTemplates = await logElapsedAsync(() async {
// Since we need global state to remain consistent here, make sure not to do
// any asynchronous operations here.
final compiledTemplates = logElapsedSync(() {
return templateCompiler.compileTemplatesCodeGen(compileData);
}, operationName: 'compileTemplatesCodegen', assetId: assetId);
reflector.reflectionCapabilities = savedReflectionCapabilities;