OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 part of js_ast; | 5 part of js_ast; |
6 | 6 |
7 class TemplateManager { | 7 class TemplateManager { |
8 Map<String, Template> expressionTemplates = new Map<String, Template>(); | 8 Map<String, Template> expressionTemplates = new Map<String, Template>(); |
9 Map<String, Template> statementTemplates = new Map<String, Template>(); | 9 Map<String, Template> statementTemplates = new Map<String, Template>(); |
10 | 10 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 | 52 |
53 // Null, unless there are named holes. | 53 // Null, unless there are named holes. |
54 List<String> holeNames; | 54 List<String> holeNames; |
55 bool get isPositional => holeNames == null; | 55 bool get isPositional => holeNames == null; |
56 | 56 |
57 Template(this.source, this.ast, | 57 Template(this.source, this.ast, |
58 {this.isExpression: true, this.forceCopy: false}) { | 58 {this.isExpression: true, this.forceCopy: false}) { |
59 _compile(); | 59 _compile(); |
60 } | 60 } |
61 | 61 |
62 Template.withExpressionResult(this.ast) | 62 Template.withExpressionResult(this.ast, {hasPlaceholders : false}) |
63 : source = null, isExpression = true, forceCopy = false { | 63 : source = null, isExpression = true, forceCopy = false { |
64 assert(ast is Expression); | 64 assert(ast is Expression); |
65 assert(_checkNoPlaceholders()); | 65 if (hasPlaceholders) { |
66 positionalArgumentCount = 0; | 66 _compile(); |
67 instantiator = (arguments) => ast; | 67 } else { |
| 68 assert(_checkNoPlaceholders()); |
| 69 positionalArgumentCount = 0; |
| 70 instantiator = (arguments) => ast; |
| 71 } |
68 } | 72 } |
69 | 73 |
70 Template.withStatementResult(this.ast) | 74 Template.withStatementResult(this.ast, {hasPlaceholders : false}) |
71 : source = null, isExpression = false, forceCopy = false { | 75 : source = null, isExpression = false, forceCopy = false { |
72 assert(ast is Statement); | 76 assert(ast is Statement); |
73 assert(_checkNoPlaceholders()); | 77 |
74 positionalArgumentCount = 0; | 78 if (hasPlaceholders) { |
75 instantiator = (arguments) => ast; | 79 _compile(); |
| 80 } else { |
| 81 assert(_checkNoPlaceholders()); |
| 82 positionalArgumentCount = 0; |
| 83 instantiator = (arguments) => ast; |
| 84 } |
76 } | 85 } |
77 | 86 |
78 bool _checkNoPlaceholders() { | 87 bool _checkNoPlaceholders() { |
79 InstantiatorGeneratorVisitor generator = | 88 InstantiatorGeneratorVisitor generator = |
80 new InstantiatorGeneratorVisitor(false); | 89 new InstantiatorGeneratorVisitor(false); |
81 generator.compile(ast); | 90 generator.compile(ast); |
82 return generator.analysis.count == 0; | 91 return generator.analysis.count == 0; |
83 } | 92 } |
84 | 93 |
85 void _compile() { | 94 void _compile() { |
(...skipping 659 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
745 if (count != before) containsInterpolatedNode.add(node); | 754 if (count != before) containsInterpolatedNode.add(node); |
746 return null; | 755 return null; |
747 } | 756 } |
748 | 757 |
749 visitInterpolatedNode(InterpolatedNode node) { | 758 visitInterpolatedNode(InterpolatedNode node) { |
750 containsInterpolatedNode.add(node); | 759 containsInterpolatedNode.add(node); |
751 if (node.isNamed) holeNames.add(node.nameOrPosition); | 760 if (node.isNamed) holeNames.add(node.nameOrPosition); |
752 ++count; | 761 ++count; |
753 } | 762 } |
754 } | 763 } |
OLD | NEW |