fix(transformer): Fix string interpolation for bindings.

Previously it did not stringify properties and used `+` instead of ` `.
This commit is contained in:
Jacob MacDonald 2015-07-01 13:20:12 -07:00
parent 582551bea9
commit 311b47720b
12 changed files with 62 additions and 22 deletions

View File

@ -111,4 +111,3 @@ Map<String, String> _createEventsMap(NgDeps ngDeps) {
}); });
return bindMap; return bindMap;
} }

View File

@ -6,8 +6,8 @@ import 'package:angular2/src/transform/common/logging.dart';
/// Visitor responsible for crawling the "annotations" value in a /// Visitor responsible for crawling the "annotations" value in a
/// `registerType` call and pulling out the properties of any "bind" /// `registerType` call and pulling out the properties of any "bind"
/// values found. /// values found.
class ExtractNamedExpressionVisitor extends Object with class ExtractNamedExpressionVisitor extends Object
RecursiveAstVisitor<Object> { with RecursiveAstVisitor<Object> {
final ConstantEvaluator _evaluator = new ConstantEvaluator(); final ConstantEvaluator _evaluator = new ConstantEvaluator();
final List<String> bindConfig = []; final List<String> bindConfig = [];
final String nameToExtract; final String nameToExtract;

View File

@ -61,8 +61,7 @@ class TransformerOptions {
MirrorMode mirrorMode: MirrorMode.none, bool initReflector: true, MirrorMode mirrorMode: MirrorMode.none, bool initReflector: true,
List<AnnotationDescriptor> customAnnotationDescriptors: const [], List<AnnotationDescriptor> customAnnotationDescriptors: const [],
int optimizationPhases: DEFAULT_OPTIMIZATION_PHASES, int optimizationPhases: DEFAULT_OPTIMIZATION_PHASES,
bool inlineViews: true, bool inlineViews: true, bool generateChangeDetectors: true}) {
bool generateChangeDetectors: true}) {
if (reflectionEntryPoints == null || reflectionEntryPoints.isEmpty) { if (reflectionEntryPoints == null || reflectionEntryPoints.isEmpty) {
reflectionEntryPoints = entryPoints; reflectionEntryPoints = entryPoints;
} }

View File

@ -16,8 +16,9 @@ class Codegen {
Codegen(String reflectionEntryPointPath, Iterable<String> newEntryPointPaths, Codegen(String reflectionEntryPointPath, Iterable<String> newEntryPointPaths,
{String prefix}) {String prefix})
: this.prefix = prefix == null ? _PREFIX_BASE : prefix, : this.prefix = prefix == null ? _PREFIX_BASE : prefix,
importUris = newEntryPointPaths.map((p) => importUris = newEntryPointPaths.map((p) => path
path.relative(p, from: path.dirname(reflectionEntryPointPath)).replaceAll('\\', '/')) { .relative(p, from: path.dirname(reflectionEntryPointPath))
.replaceAll('\\', '/')) {
if (this.prefix.isEmpty) throw new ArgumentError.value('(empty)', 'prefix'); if (this.prefix.isEmpty) throw new ArgumentError.value('(empty)', 'prefix');
} }

View File

@ -113,7 +113,9 @@ class Rewriter {
String _importDebugReflectionCapabilities(ImportDirective node) { String _importDebugReflectionCapabilities(ImportDirective node) {
var uri = '${node.uri}'; var uri = '${node.uri}';
uri = path.join(path.dirname(uri), 'debug_${path.basename(uri)}').replaceAll('\\', '/'); uri = path
.join(path.dirname(uri), 'debug_${path.basename(uri)}')
.replaceAll('\\', '/');
var asClause = node.prefix != null ? ' as ${node.prefix}' : ''; var asClause = node.prefix != null ? ' as ${node.prefix}' : '';
return 'import $uri$asClause;'; return 'import $uri$asClause;';
} }

View File

@ -424,7 +424,9 @@ class _CodegenState {
String _genInterpolation(ProtoRecord r) { String _genInterpolation(ProtoRecord r) {
var res = new StringBuffer(); var res = new StringBuffer();
for (var i = 0; i < r.args.length; ++i) { for (var i = 0; i < r.args.length; ++i) {
res.write('${JSON.encode(r.fixedArgs[i])} + ${_localNames[r.args[i]]} +'); var name = _localNames[r.args[i]];
res.write(
'${JSON.encode(r.fixedArgs[i])} "\$\{$name == null ? "" : $name\}" ');
} }
res.write(JSON.encode(r.fixedArgs[r.args.length])); res.write(JSON.encode(r.fixedArgs[r.args.length]));
return '$res'; return '$res';

View File

@ -121,8 +121,8 @@ void _testNgDeps(String name, String inputPath,
if (output == null) { if (output == null) {
expect(await reader.hasInput(expectedId)).toBeFalse(); expect(await reader.hasInput(expectedId)).toBeFalse();
} else { } else {
expect(formatter.format(output)) expect(formatter.format(output)).toEqual(
.toEqual((await reader.readAsString(expectedId)).replaceAll('\r\n', '\n')); (await reader.readAsString(expectedId)).replaceAll('\r\n', '\n'));
} }
if (expectedLogs != null) { if (expectedLogs != null) {

View File

@ -6,8 +6,5 @@ show bootstrap, Component, Directive, View, NgElement;
@Component(selector: 'hello-app') @Component(selector: 'hello-app')
@View( @View(
templateUrl: '/bad/absolute/url.html', templateUrl: '/bad/absolute/url.html',
styleUrls: const [ styleUrls: const ['package:invalid/package.css', 'bad_relative_url.css'])
'package:invalid/package.css',
'bad_relative_url.css'
])
class HelloCmp {} class HelloCmp {}

View File

@ -4,7 +4,9 @@ import 'package:angular2/src/core/annotations_impl/annotations.dart';
import 'package:angular2/src/core/annotations_impl/view.dart'; import 'package:angular2/src/core/annotations_impl/view.dart';
@Component(selector: '[soup]') @Component(selector: '[soup]')
@View(template: 'Salad') @View(template: 'Salad: {{myNum}} is awesome')
class MyComponent { class MyComponent {
int myNum;
MyComponent(); MyComponent();
} }

View File

@ -17,9 +17,11 @@ void initReflector(reflector) {
'parameters': const [], 'parameters': const [],
'annotations': const [ 'annotations': const [
const Component(selector: '[soup]'), const Component(selector: '[soup]'),
const View(template: 'Salad') const View(template: 'Salad: {{myNum}} is awesome')
] ]
}); })
..registerGetters({'myNum': (o) => o.myNum})
..registerSetters({'myNum': (o, v) => o.myNum = v});
_gen.preGeneratedProtoDetectors['MyComponent_comp_0'] = _gen.preGeneratedProtoDetectors['MyComponent_comp_0'] =
_MyComponent_ChangeDetector0.newProtoChangeDetector; _MyComponent_ChangeDetector0.newProtoChangeDetector;
} }
@ -31,6 +33,8 @@ class _MyComponent_ChangeDetector0 extends _gen.AbstractChangeDetector {
dynamic _locals = null; dynamic _locals = null;
dynamic _alreadyChecked = false; dynamic _alreadyChecked = false;
MyComponent _context = null; MyComponent _context = null;
dynamic _myNum0 = _gen.ChangeDetectionUtil.uninitialized();
dynamic _interpolate1 = _gen.ChangeDetectionUtil.uninitialized();
_MyComponent_ChangeDetector0(this._dispatcher, this._pipeRegistry, _MyComponent_ChangeDetector0(this._dispatcher, this._pipeRegistry,
this._protos, this._directiveRecords) this._protos, this._directiveRecords)
@ -41,12 +45,44 @@ class _MyComponent_ChangeDetector0 extends _gen.AbstractChangeDetector {
_gen.ChangeDetectionUtil.throwDehydrated(); _gen.ChangeDetectionUtil.throwDehydrated();
} }
var context = null; var context = null;
var myNum0 = null;
var interpolate1 = null;
var change_context = false; var change_context = false;
var change_myNum0 = false;
var change_interpolate1 = false;
var isChanged = false; var isChanged = false;
var currentProto; var currentProto;
var changes = null; var changes = null;
context = _context; context = _context;
currentProto = _protos[0];
myNum0 = context.myNum;
if (!_gen.looseIdentical(myNum0, _myNum0)) {
change_myNum0 = true;
_myNum0 = myNum0;
}
if (change_myNum0) {
currentProto = _protos[1];
interpolate1 = "Salad: " "${myNum0 == null ? "" : myNum0}" " is awesome";
if (!_gen.looseIdentical(interpolate1, _interpolate1)) {
change_interpolate1 = true;
if (throwOnChange) {
_gen.ChangeDetectionUtil.throwOnChange(currentProto,
_gen.ChangeDetectionUtil.simpleChange(
_interpolate1, interpolate1));
}
_dispatcher.notifyOnBinding(currentProto.bindingRecord, interpolate1);
_interpolate1 = interpolate1;
}
} else {
interpolate1 = _interpolate1;
}
changes = null;
isChanged = false;
_alreadyChecked = true; _alreadyChecked = true;
} }
@ -65,6 +101,8 @@ class _MyComponent_ChangeDetector0 extends _gen.AbstractChangeDetector {
void dehydrate() { void dehydrate() {
_context = null; _context = null;
_myNum0 = _gen.ChangeDetectionUtil.uninitialized();
_interpolate1 = _gen.ChangeDetectionUtil.uninitialized();
_locals = null; _locals = null;
} }