Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(846)

Unified Diff: utils/template/codegen.dart

Issue 9791020: Fixed bug with template control statements as first node of template (each, with, call, etc.). (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: CL cleanup Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | utils/template/template.html » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: utils/template/codegen.dart
diff --git a/utils/template/codegen.dart b/utils/template/codegen.dart
index 648ec3ba87dcc44fbcb7fcf053c296586063b4fd..47865970d402b10202f196667d46d078135ee120 100644
--- a/utils/template/codegen.dart
+++ b/utils/template/codegen.dart
@@ -58,6 +58,8 @@ class CGBlock {
}
}
+ bool get anyStatements() => _stmts.length > 0;
+
CGStatement get last() => _stmts.last();
/**
@@ -570,7 +572,6 @@ class ElemCG {
bool pushBlock([int indent = 4, int blockType = CGBlock.CONSTRUCTOR,
String itemName = null]) {
- closeStatement();
if (itemName != null && matchBlocksLocalName(itemName)) {
world.error("Active block already exist with local name: ${itemName}.");
return false;
@@ -842,7 +843,7 @@ Nested #each or #with must have a localName;
// If nested each then we want to pass the parent otherwise we'll use the
// varName.
- var varName = nestedImmediateEach ? "parent" : lastBlock.last.variableName;
+ var varName = nestedImmediateEach ? "parent" : lastBlockVarName;
pushExactStatement(elem, parentVarOrIdx);
@@ -891,13 +892,25 @@ Nested #each or #with must have a localName;
withs[withIndex] = funcBuff.toString();
- var varName = lastBlock.last.variableName;
+ // Compute parent node variable before pushing with statement.
+ String parentVarName = lastBlockVarName;
pushExactStatement(elem, parentVarIndex);
// Setup call to each func as "each_n(xxxxx, " the parent param is filled
// in later when we known the parent variable.
- add("${funcName}(${withName}, ${varName})");
+ add("${funcName}(${withName}, ${parentVarName})");
+ }
+
+ String get lastBlockVarName() {
+ var varName;
+ if (lastBlock != null && lastBlock.anyStatements) {
+ varName = lastBlock.last.variableName;
+ } else {
+ varName = "_fragment";
+ }
+
+ return varName;
}
String injectParamName(String name) {
« no previous file with comments | « no previous file | utils/template/template.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698