| OLD | NEW |
| 1 library angular.html_parser; | 1 library angular.html_parser; |
| 2 | 2 |
| 3 import 'package:html5lib/parser.dart'; | 3 import 'package:html5lib/parser.dart'; |
| 4 import 'package:html5lib/dom.dart'; | 4 import 'package:html5lib/dom.dart'; |
| 5 | 5 |
| 6 import 'package:angular/tools/selector.dart'; | 6 import 'package:angular/tools/selector.dart'; |
| 7 import 'package:angular/tools/io.dart'; | 7 import 'package:angular/tools/io.dart'; |
| 8 import 'package:angular/tools/common.dart'; | 8 import 'package:angular/tools/common.dart'; |
| 9 | 9 |
| 10 typedef NodeVisitor(Node node); | 10 typedef NodeVisitor(Node node); |
| 11 | 11 |
| 12 RegExp _MUSTACHE_REGEXP = new RegExp(r'{{([^}]*)}}'); | 12 RegExp _MUSTACHE_REGEXP = new RegExp(r'{{([^}]*)}}'); |
| 13 RegExp _NG_REPEAT_SYNTAX = new RegExp(r'^\s*(.+)\s+in\s+(.*?)\s*(\s+track\s+by\s
+(.+)\s*)?$'); | 13 RegExp _NG_REPEAT_SYNTAX = new RegExp(r'^\s*(.+)\s+in\s+(.*?)\s*(\s+track\s+by\s
+(.+)\s*)?$'); |
| 14 | 14 |
| 15 class HtmlExpressionExtractor { | 15 class HtmlExpressionExtractor { |
| 16 Iterable<DirectiveInfo> directiveInfos; | 16 List<DirectiveInfo> directiveInfos; |
| 17 | 17 |
| 18 HtmlExpressionExtractor(this.directiveInfos) { | 18 HtmlExpressionExtractor(this.directiveInfos) { |
| 19 for (DirectiveInfo directiveInfo in directiveInfos) { | 19 for (DirectiveInfo directiveInfo in directiveInfos) { |
| 20 expressions.addAll(directiveInfo.expressions); | 20 expressions.addAll(directiveInfo.expressions); |
| 21 if (directiveInfo.template != null) { | 21 if (directiveInfo.template != null) { |
| 22 parseHtml(directiveInfo.template); | 22 parseHtml(directiveInfo.template); |
| 23 } | 23 } |
| 24 } | 24 } |
| 25 } | 25 } |
| 26 | 26 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 37 var document = parse(html); | 37 var document = parse(html); |
| 38 visitNodes([document], (Node node) { | 38 visitNodes([document], (Node node) { |
| 39 if (matchesNode(node, r'[*=/{{.*}}/]')) { | 39 if (matchesNode(node, r'[*=/{{.*}}/]')) { |
| 40 node.attributes.forEach((attrName, attrValue) { | 40 node.attributes.forEach((attrName, attrValue) { |
| 41 _MUSTACHE_REGEXP.allMatches(attrValue).forEach((match) { | 41 _MUSTACHE_REGEXP.allMatches(attrValue).forEach((match) { |
| 42 expressions.add(match.group(1)); | 42 expressions.add(match.group(1)); |
| 43 }); | 43 }); |
| 44 }); | 44 }); |
| 45 } | 45 } |
| 46 if (matchesNode(node, r':contains(/{{.*}}/)')) { | 46 if (matchesNode(node, r':contains(/{{.*}}/)')) { |
| 47 _MUSTACHE_REGEXP.allMatches(node.text).forEach((match) { | 47 _MUSTACHE_REGEXP.allMatches(node.value).forEach((match) { |
| 48 expressions.add(match.group(1)); | 48 expressions.add(match.group(1)); |
| 49 }); | 49 }); |
| 50 } | 50 } |
| 51 if (matchesNode(node, r'[ng-repeat]')) { | 51 if (matchesNode(node, r'[ng-repeat]')) { |
| 52 var expr = _NG_REPEAT_SYNTAX. | 52 var expr = _NG_REPEAT_SYNTAX. |
| 53 firstMatch(node.attributes['ng-repeat']).group(2); | 53 firstMatch(node.attributes['ng-repeat']).group(2); |
| 54 expressions.add(expr); | 54 expressions.add(expr); |
| 55 } | 55 } |
| 56 | 56 |
| 57 for (DirectiveInfo directiveInfo in directiveInfos) { | 57 for (DirectiveInfo directiveInfo in directiveInfos) { |
| 58 if (directiveInfo.selector != null && | 58 if (matchesNode(node, directiveInfo.selector)) { |
| 59 matchesNode(node, directiveInfo.selector)) { | |
| 60 directiveInfo.expressionAttrs.forEach((attr) { | 59 directiveInfo.expressionAttrs.forEach((attr) { |
| 61 if (node.attributes[attr] != null && attr != 'ng-repeat') { | 60 if (node.attributes[attr] != null && attr != 'ng-repeat') { |
| 62 expressions.add(node.attributes[attr]); | 61 expressions.add(node.attributes[attr]); |
| 63 } | 62 } |
| 64 }); | 63 }); |
| 65 } | 64 } |
| 66 } | 65 } |
| 67 }); | 66 }); |
| 68 } | 67 } |
| 69 | 68 |
| 70 visitNodes(List<Node> nodes, NodeVisitor visitor) { | 69 visitNodes(List<Node> nodes, NodeVisitor visitor) { |
| 71 for (Node node in nodes) { | 70 for (Node node in nodes) { |
| 72 visitor(node); | 71 visitor(node); |
| 73 if (node.nodes.isNotEmpty) { | 72 if (node.nodes.length > 0) { |
| 74 visitNodes(node.nodes, visitor); | 73 visitNodes(node.nodes, visitor); |
| 75 } | 74 } |
| 76 } | 75 } |
| 77 } | 76 } |
| 78 } | 77 } |
| 79 | 78 |
| OLD | NEW |