Skip to content

Commit 8fa8de9

Browse files
committed
fix(interpolate): do not try to optimize by removing empty strings
To make sure a string is always returned
1 parent 2617bb7 commit 8fa8de9

File tree

4 files changed

+13
-13
lines changed

4 files changed

+13
-13
lines changed

lib/core/interpolate.dart

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,11 @@ class Interpolate implements Function {
2727

2828
String call(String template, [bool mustHaveExpression = false,
2929
String startSymbol = '{{', String endSymbol = '}}']) {
30+
if (template == null || template.isEmpty) return "";
3031

31-
int startLen = startSymbol.length;
32-
int endLen = endSymbol.length;
33-
int length = template.length;
32+
final startLen = startSymbol.length;
33+
final endLen = endSymbol.length;
34+
final length = template.length;
3435

3536
int startIdx;
3637
int endIdx;
@@ -45,9 +46,7 @@ class Interpolate implements Function {
4546
startIdx = template.indexOf(startSymbol, index);
4647
endIdx = template.indexOf(endSymbol, startIdx + startLen);
4748
if (startIdx != -1 && endIdx != -1) {
48-
if (index < startIdx) {
49-
expParts.add('"${template.substring(index, startIdx)}"');
50-
}
49+
expParts.add('"${template.substring(index, startIdx)}"');
5150
expParts.add('(${template.substring(startIdx + startLen, endIdx)})');
5251
index = endIdx + endLen;
5352
hasInterpolation = true;

lib/core_dom/ng_mustache.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class NgTextMustacheDirective {
1616
}
1717

1818
void _updateMarkup(text, previousText) {
19-
if (text != previousText) _element.text = text.toString();
19+
if (text != previousText) _element.text = text;
2020
}
2121
}
2222

@@ -48,7 +48,7 @@ class NgAttrMustacheDirective {
4848
}
4949

5050
void _updateMarkup(text, previousText) {
51-
if (previousText != text) _attrs[_attrName] = text.toString();
51+
if (previousText != text) _attrs[_attrName] = text;
5252
}
5353
}
5454

lib/directive/ng_pluralize.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,6 @@ class NgPluralizeDirective {
174174
}
175175

176176
void _updateMarkup(text, previousText) {
177-
if (text != previousText) element.text = text.toString();
177+
if (text != previousText) element.text = text;
178178
}
179179
}

test/core/interpolate_spec.dart

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@ main() {
1818
expect($interpolate('Hello {{name}}!')).toEqual('"Hello "+(name)+"!"');
1919
expect($interpolate('a{{b}}C')).toEqual('"a"+(b)+"C"');
2020
expect($interpolate('a{{b}}')).toEqual('"a"+(b)');
21-
expect($interpolate('{{a}}b')).toEqual('(a)+"b"');
22-
expect($interpolate('{{b}}')).toEqual('(b)');
23-
expect($interpolate('{{b}}+{{c}}')).toEqual('(b)+"+"+(c)');
24-
expect($interpolate('{{b}}x{{c}}')).toEqual('(b)+"x"+(c)');
21+
expect($interpolate('{{a}}b')).toEqual('""+(a)+"b"');
22+
expect($interpolate('{{a}}{{b}}')).toEqual('""+(a)+""+(b)');
23+
expect($interpolate('{{b}}')).toEqual('""+(b)');
24+
expect($interpolate('{{b}}+{{c}}')).toEqual('""+(b)+"+"+(c)');
25+
expect($interpolate('{{b}}x{{c}}')).toEqual('""+(b)+"x"+(c)');
2526
});
2627

2728
it('should Parse Multiline', (Interpolate $interpolate) {

0 commit comments

Comments
 (0)