Skip to content
This repository was archived by the owner on Sep 16, 2022. It is now read-only.

Commit 4b0c013

Browse files
leonsenftferhatb
authored andcommitted
Template anchor comments are now cloned rather than created.
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=149701321
1 parent 60579f3 commit 4b0c013

File tree

9 files changed

+24
-26
lines changed

9 files changed

+24
-26
lines changed

lib/src/compiler/identifiers.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,9 @@ var impEMPTY_MAP = EMPTY_MAP;
8181

8282
class Identifiers {
8383
static final appViewUtils = new CompileIdentifierMetadata(
84-
name: "appViewUtils",
85-
moduleUrl: 'asset:angular2/lib/src/core/linker/app_view_utils.dart');
84+
name: "appViewUtils", moduleUrl: APP_VIEW_UTILS_MODULE_URL);
85+
static final ngAnchor = new CompileIdentifierMetadata(
86+
name: 'ngAnchor', moduleUrl: APP_VIEW_MODULE_URL);
8687
static final AppView = new CompileIdentifierMetadata(
8788
name: "AppView", moduleUrl: APP_VIEW_MODULE_URL);
8889
static final DebugAppView = new CompileIdentifierMetadata(

lib/src/compiler/output/output_interpreter.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,7 @@ var CATCH_STACK_VAR = "stack";
670670
/// them dynamically.
671671
void _initializeInterpreter() {
672672
Identifiers.DebugAppView.runtime = DebugAppView;
673+
Identifiers.ngAnchor.runtime = ngAnchor;
673674
Identifiers.AppView.runtime = AppView;
674675
Identifiers.ViewContainer.runtime = ViewContainer;
675676
Identifiers.StaticNodeDebugInfo.runtime = StaticNodeDebugInfo;

lib/src/compiler/view_compiler/view_builder.dart

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,13 @@ import "view_compiler_utils.dart"
4848
createFlatArray,
4949
createDiTokenExpression,
5050
createSetAttributeParams,
51-
componentFromDirectives,
52-
TEMPLATE_COMMENT_TEXT;
51+
componentFromDirectives;
5352

5453
const IMPLICIT_TEMPLATE_VAR = "\$implicit";
5554
const CLASS_ATTR = "class";
5655
const STYLE_ATTR = "style";
56+
var cloneAnchorNodeExpr =
57+
o.importExpr(Identifiers.ngAnchor).callMethod('clone', [o.literal(false)]);
5758
var parentRenderNodeVar = o.variable("parentRenderNode");
5859
var rootSelectorVar = o.variable("rootSelector");
5960
var NOT_THROW_ON_CHANGES = o.not(o.importExpr(Identifiers.throwOnChanges));
@@ -432,25 +433,20 @@ class ViewBuilderVisitor implements TemplateAstVisitor {
432433
var nodeIndex = this.view.nodes.length;
433434
var fieldName = '_anchor_${nodeIndex}';
434435
o.Expression anchorVarExpr;
435-
// Create a comment to serve as anchor for template.
436+
// Clone template anchor.
436437
if (createFieldForAnchor) {
437438
view.fields.add(new o.ClassField(fieldName,
438439
outputType: o.importType(Identifiers.HTML_COMMENT_NODE),
439440
modifiers: const [o.StmtModifier.Private]));
440441
anchorVarExpr = new o.ReadClassMemberExpr(fieldName);
441-
var createAnchorNodeExpr = new o.WriteClassMemberExpr(
442-
fieldName,
443-
o
444-
.importExpr(Identifiers.HTML_COMMENT_NODE)
445-
.instantiate([o.literal(TEMPLATE_COMMENT_TEXT)]));
446-
view.createMethod.addStmt(createAnchorNodeExpr.toStmt());
442+
var assignCloneAnchorNodeExpr =
443+
new o.WriteClassMemberExpr(fieldName, cloneAnchorNodeExpr);
444+
view.createMethod.addStmt(assignCloneAnchorNodeExpr.toStmt());
447445
} else {
448-
var readVarExp = o.variable(fieldName);
449-
anchorVarExpr = readVarExp;
450-
var createAnchorNodeExpr = readVarExp.set(o
451-
.importExpr(Identifiers.HTML_COMMENT_NODE)
452-
.instantiate([o.literal(TEMPLATE_COMMENT_TEXT)]));
453-
view.createMethod.addStmt(createAnchorNodeExpr.toDeclStmt());
446+
var readVarExpr = o.variable(fieldName);
447+
anchorVarExpr = readVarExpr;
448+
var assignCloneAnchorNodeExpr = readVarExpr.set(cloneAnchorNodeExpr);
449+
view.createMethod.addStmt(assignCloneAnchorNodeExpr.toDeclStmt());
454450
}
455451
var addCommentStmt = _getParentRenderNode(parent)
456452
.callMethod('append', [anchorVarExpr], checked: true)

lib/src/compiler/view_compiler/view_compiler_utils.dart

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ import '../identifiers.dart' show Identifiers;
1010
import '../output/output_ast.dart' as o;
1111
import 'compile_view.dart' show CompileView;
1212

13-
// Template Anchor comment.
14-
const TEMPLATE_COMMENT_TEXT = 'template bindings={}';
15-
1613
// Creates method parameters list for AppView set attribute calls.
1714
List<o.Expression> createSetAttributeParams(
1815
String fieldName, String attrNs, String attrName, o.Expression valueExpr) {

lib/src/core/linker/app_view.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ import 'view_type.dart' show ViewType;
1919

2020
export 'package:angular2/src/core/change_detection/component_state.dart';
2121

22+
/// Template anchor comment for cloning.
23+
var ngAnchor = new Comment('template bindings={}');
24+
2225
const _UndefinedInjectorResult = const Object();
2326
const String appViewRootElementName = 'rootEl';
2427
bool domRootRendererIsDirty = false;

test/source_gen/template_compiler/test_files/core_directives.template_debug.golden

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class ViewTestFooComponent0 extends DebugAppView<import5.TestFooComponent> {
7474
Text _text_0 = new Text(' ');
7575
parentRenderNode.append(_text_0);
7676
dbgElm(_text_0, 0, 0, 0);
77-
var _anchor_1 = new Comment('template bindings={}');
77+
var _anchor_1 = ngAnchor.clone(false);
7878
parentRenderNode?.append(_anchor_1);
7979
dbgElm(_anchor_1, 1, 0, 4);
8080
_appEl_1 = new ViewContainer(1, null, this, _anchor_1);
@@ -84,7 +84,7 @@ class ViewTestFooComponent0 extends DebugAppView<import5.TestFooComponent> {
8484
Text _text_2 = new Text('\n ');
8585
parentRenderNode.append(_text_2);
8686
dbgElm(_text_2, 2, 0, 30);
87-
var _anchor_3 = new Comment('template bindings={}');
87+
var _anchor_3 = ngAnchor.clone(false);
8888
parentRenderNode?.append(_anchor_3);
8989
dbgElm(_anchor_3, 3, 1, 4);
9090
_appEl_3 = new ViewContainer(3, null, this, _anchor_3);

test/source_gen/template_compiler/test_files/core_directives.template_release.golden

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,15 @@ class ViewTestFooComponent0 extends AppView<import1.TestFooComponent> {
5555
final HtmlElement parentRenderNode = initViewRoot(rootEl);
5656
Text _text_0 = new Text(' ');
5757
parentRenderNode.append(_text_0);
58-
var _anchor_1 = new Comment('template bindings={}');
58+
var _anchor_1 = ngAnchor.clone(false);
5959
parentRenderNode?.append(_anchor_1);
6060
_appEl_1 = new ViewContainer(1, null, this, _anchor_1);
6161
TemplateRef _TemplateRef_1_4 =
6262
new TemplateRef(_appEl_1, viewFactory_TestFooComponent1);
6363
_NgIf_1_5 = new NgIf(_appEl_1, _TemplateRef_1_4);
6464
Text _text_2 = new Text('\n ');
6565
parentRenderNode.append(_text_2);
66-
var _anchor_3 = new Comment('template bindings={}');
66+
var _anchor_3 = ngAnchor.clone(false);
6767
parentRenderNode?.append(_anchor_3);
6868
_appEl_3 = new ViewContainer(3, null, this, _anchor_3);
6969
TemplateRef _TemplateRef_3_4 =

test/source_gen/template_compiler/test_files/view_annotation.template_debug.golden

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class ViewTestFooComponent0 extends DebugAppView<import4.TestFooComponent> {
6464
}
6565
ComponentRef build() {
6666
final HtmlElement parentRenderNode = initViewRoot(rootEl);
67-
var _anchor_0 = new Comment('template bindings={}');
67+
var _anchor_0 = ngAnchor.clone(false);
6868
parentRenderNode?.append(_anchor_0);
6969
dbgElm(_anchor_0, 0, 0, 0);
7070
_appEl_0 = new ViewContainer(0, null, this, _anchor_0);

test/source_gen/template_compiler/test_files/view_annotation.template_release.golden

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class ViewTestFooComponent0 extends AppView<import1.TestFooComponent> {
5050
}
5151
ComponentRef build() {
5252
final HtmlElement parentRenderNode = initViewRoot(rootEl);
53-
var _anchor_0 = new Comment('template bindings={}');
53+
var _anchor_0 = ngAnchor.clone(false);
5454
parentRenderNode?.append(_anchor_0);
5555
_appEl_0 = new ViewContainer(0, null, this, _anchor_0);
5656
TemplateRef _TemplateRef_0_4 =

0 commit comments

Comments
 (0)