|
1 | 1 | part of angular.core.dom;
|
2 | 2 |
|
3 | 3 | abstract class Compiler implements Function {
|
4 |
| - WalkingViewFactory call(List<dom.Node> elements, DirectiveMap directives); |
5 |
| -} |
6 |
| - |
7 |
| -@NgInjectableService() |
8 |
| -class WalkingCompiler implements Compiler { |
9 |
| - final Profiler _perf; |
10 |
| - final Expando _expando; |
11 |
| - |
12 |
| - WalkingCompiler(this._perf, this._expando); |
13 |
| - |
14 |
| - List<ElementBinderTreeRef> _compileView(NodeCursor domCursor, NodeCursor templateCursor, |
15 |
| - ElementBinder existingElementBinder, |
16 |
| - DirectiveMap directives) { |
17 |
| - if (domCursor.current == null) return null; |
18 |
| - |
19 |
| - List<ElementBinderTreeRef> elementBinders = null; // don't pre-create to create sparse tree and prevent GC pressure. |
20 |
| - |
21 |
| - do { |
22 |
| - var subtrees, binder; |
23 |
| - |
24 |
| - ElementBinder elementBinder = existingElementBinder == null |
25 |
| - ? directives.selector(domCursor.current) |
26 |
| - : existingElementBinder; |
27 |
| - |
28 |
| - if (elementBinder.hasTemplate) { |
29 |
| - elementBinder.templateViewFactory = _compileTransclusion( |
30 |
| - domCursor, templateCursor, |
31 |
| - elementBinder.template, elementBinder.templateBinder, directives); |
32 |
| - } |
33 |
| - |
34 |
| - if (elementBinder.shouldCompileChildren) { |
35 |
| - if (domCursor.descend()) { |
36 |
| - templateCursor.descend(); |
37 |
| - |
38 |
| - subtrees = |
39 |
| - _compileView(domCursor, templateCursor, null, directives); |
40 |
| - |
41 |
| - domCursor.ascend(); |
42 |
| - templateCursor.ascend(); |
43 |
| - } |
44 |
| - } |
45 |
| - |
46 |
| - if (elementBinder.hasDirectives) { |
47 |
| - binder = elementBinder; |
48 |
| - } |
49 |
| - |
50 |
| - if (elementBinders == null) elementBinders = []; |
51 |
| - elementBinders.add(new ElementBinderTreeRef(templateCursor.index, new ElementBinderTree(binder, subtrees))); |
52 |
| - } while (templateCursor.moveNext() && domCursor.moveNext()); |
53 |
| - |
54 |
| - return elementBinders; |
55 |
| - } |
56 |
| - |
57 |
| - WalkingViewFactory _compileTransclusion( |
58 |
| - NodeCursor domCursor, NodeCursor templateCursor, |
59 |
| - DirectiveRef directiveRef, |
60 |
| - ElementBinder transcludedElementBinder, |
61 |
| - DirectiveMap directives) { |
62 |
| - var anchorName = directiveRef.annotation.selector + |
63 |
| - (directiveRef.value != null ? '=' + directiveRef.value : ''); |
64 |
| - var viewFactory; |
65 |
| - var views; |
66 |
| - |
67 |
| - var transcludeCursor = templateCursor.replaceWithAnchor(anchorName); |
68 |
| - var domCursorIndex = domCursor.index; |
69 |
| - var elementBinders = |
70 |
| - _compileView(domCursor, transcludeCursor, transcludedElementBinder, directives); |
71 |
| - if (elementBinders == null) elementBinders = []; |
72 |
| - |
73 |
| - viewFactory = new WalkingViewFactory(transcludeCursor.elements, elementBinders, _perf, _expando); |
74 |
| - domCursor.index = domCursorIndex; |
75 |
| - |
76 |
| - if (domCursor.isInstance) { |
77 |
| - domCursor.insertAnchorBefore(anchorName); |
78 |
| - views = [viewFactory([domCursor.current])]; |
79 |
| - templateCursor.moveNext(); |
80 |
| - while (domCursor.moveNext() && domCursor.isInstance) { |
81 |
| - views.add(viewFactory([domCursor.current])); |
82 |
| - templateCursor.remove(); |
83 |
| - } |
84 |
| - } else { |
85 |
| - domCursor.replaceWithAnchor(anchorName); |
86 |
| - } |
87 |
| - |
88 |
| - return viewFactory; |
89 |
| - } |
90 |
| - |
91 |
| - WalkingViewFactory call(List<dom.Node> elements, DirectiveMap directives) { |
92 |
| - var timerId; |
93 |
| - assert((timerId = _perf.startTimer('ng.compile', _html(elements))) != false); |
94 |
| - final List<dom.Node> domElements = elements; |
95 |
| - final List<dom.Node> templateElements = cloneElements(domElements); |
96 |
| - var elementBinders = _compileView( |
97 |
| - new NodeCursor(domElements), new NodeCursor(templateElements), |
98 |
| - null, directives); |
99 |
| - |
100 |
| - var viewFactory = new WalkingViewFactory(templateElements, |
101 |
| - elementBinders == null ? [] : elementBinders, _perf, _expando); |
102 |
| - |
103 |
| - assert(_perf.stopTimer(timerId) != false); |
104 |
| - return viewFactory; |
105 |
| - } |
| 4 | + ViewFactory call(List<dom.Node> elements, DirectiveMap directives); |
106 | 5 | }
|
0 commit comments