fix(change_detect): Handle '$' in change detector strings

In Dart, '$' indicates the beginning of an interpolation.
- Escapes '$' in strings when generating change detector classes.
- Adds a unit test to cover this case.
This commit is contained in:
Tim Blasi
2015-07-16 11:08:47 -07:00
parent 621604dc66
commit f1e8176995
4 changed files with 14 additions and 5 deletions

View File

@ -142,7 +142,7 @@ class _CodegenState {
$_changeDetectorTypeName(
this.$_DISPATCHER_ACCESSOR,
this.$_PROTOS_ACCESSOR,
this.$_DIRECTIVES_ACCESSOR) : super(${JSON.encode(_changeDetectorDefId)});
this.$_DIRECTIVES_ACCESSOR) : super(${_encodeValue(_changeDetectorDefId)});
void detectChangesInRecords(throwOnChange) {
if (!hydrated()) {
@ -383,7 +383,7 @@ class _CodegenState {
break;
case RecordType.CONST:
rhs = JSON.encode(r.funcOrValue);
rhs = _encodeValue(r.funcOrValue);
break;
case RecordType.PROPERTY:
@ -435,9 +435,9 @@ class _CodegenState {
for (var i = 0; i < r.args.length; ++i) {
var name = _localNames[r.args[i]];
res.write(
'${JSON.encode(r.fixedArgs[i])} "\$\{$name == null ? "" : $name\}" ');
'${_encodeValue(r.fixedArgs[i])} "\$\{$name == null ? "" : $name\}" ');
}
res.write(JSON.encode(r.fixedArgs[r.args.length]));
res.write(_encodeValue(r.fixedArgs[r.args.length]));
return '$res';
}
@ -523,6 +523,9 @@ class _CodegenState {
}
''';
}
String _encodeValue(funcOrValue) =>
JSON.encode(funcOrValue).replaceAll(r'$', r'\$');
}
const PROTO_CHANGE_DETECTOR_FACTORY_METHOD = 'newProtoChangeDetector';