Skip to content

Commit 311b477

Browse files
committed
fix(transformer): Fix string interpolation for bindings.
Previously it did not stringify properties and used `+` instead of ` `.
1 parent 582551b commit 311b477

File tree

12 files changed

+62
-22
lines changed

12 files changed

+62
-22
lines changed

modules/angular2/src/transform/bind_generator/generator.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,4 +111,3 @@ Map<String, String> _createEventsMap(NgDeps ngDeps) {
111111
});
112112
return bindMap;
113113
}
114-

modules/angular2/src/transform/bind_generator/visitor.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import 'package:angular2/src/transform/common/logging.dart';
66
/// Visitor responsible for crawling the "annotations" value in a
77
/// `registerType` call and pulling out the properties of any "bind"
88
/// values found.
9-
class ExtractNamedExpressionVisitor extends Object with
10-
RecursiveAstVisitor<Object> {
9+
class ExtractNamedExpressionVisitor extends Object
10+
with RecursiveAstVisitor<Object> {
1111
final ConstantEvaluator _evaluator = new ConstantEvaluator();
1212
final List<String> bindConfig = [];
1313
final String nameToExtract;

modules/angular2/src/transform/common/options.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,7 @@ class TransformerOptions {
6161
MirrorMode mirrorMode: MirrorMode.none, bool initReflector: true,
6262
List<AnnotationDescriptor> customAnnotationDescriptors: const [],
6363
int optimizationPhases: DEFAULT_OPTIMIZATION_PHASES,
64-
bool inlineViews: true,
65-
bool generateChangeDetectors: true}) {
64+
bool inlineViews: true, bool generateChangeDetectors: true}) {
6665
if (reflectionEntryPoints == null || reflectionEntryPoints.isEmpty) {
6766
reflectionEntryPoints = entryPoints;
6867
}

modules/angular2/src/transform/reflection_remover/codegen.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ class Codegen {
1616
Codegen(String reflectionEntryPointPath, Iterable<String> newEntryPointPaths,
1717
{String prefix})
1818
: this.prefix = prefix == null ? _PREFIX_BASE : prefix,
19-
importUris = newEntryPointPaths.map((p) =>
20-
path.relative(p, from: path.dirname(reflectionEntryPointPath)).replaceAll('\\', '/')) {
19+
importUris = newEntryPointPaths.map((p) => path
20+
.relative(p, from: path.dirname(reflectionEntryPointPath))
21+
.replaceAll('\\', '/')) {
2122
if (this.prefix.isEmpty) throw new ArgumentError.value('(empty)', 'prefix');
2223
}
2324

modules/angular2/src/transform/reflection_remover/rewriter.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,9 @@ class Rewriter {
113113

114114
String _importDebugReflectionCapabilities(ImportDirective node) {
115115
var uri = '${node.uri}';
116-
uri = path.join(path.dirname(uri), 'debug_${path.basename(uri)}').replaceAll('\\', '/');
116+
uri = path
117+
.join(path.dirname(uri), 'debug_${path.basename(uri)}')
118+
.replaceAll('\\', '/');
117119
var asClause = node.prefix != null ? ' as ${node.prefix}' : '';
118120
return 'import $uri$asClause;';
119121
}

modules/angular2/src/transform/template_compiler/change_detector_codegen.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,9 @@ class _CodegenState {
424424
String _genInterpolation(ProtoRecord r) {
425425
var res = new StringBuffer();
426426
for (var i = 0; i < r.args.length; ++i) {
427-
res.write('${JSON.encode(r.fixedArgs[i])} + ${_localNames[r.args[i]]} +');
427+
var name = _localNames[r.args[i]];
428+
res.write(
429+
'${JSON.encode(r.fixedArgs[i])} "\$\{$name == null ? "" : $name\}" ');
428430
}
429431
res.write(JSON.encode(r.fixedArgs[r.args.length]));
430432
return '$res';

modules/angular2/test/transform/bind_generator/all_tests.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ void allTests() {
4141
() async {
4242
var inputPath = 'bind_generator/events_files/bar.ng_deps.dart';
4343
var expected = formatter.format(
44-
readFile('bind_generator/events_files/expected/bar.ng_deps.dart'));
44+
readFile('bind_generator/events_files/expected/bar.ng_deps.dart'));
4545

4646
var output = formatter.format(
47-
await createNgSettersAndGetters(reader, new AssetId('a', inputPath)));
47+
await createNgSettersAndGetters(reader, new AssetId('a', inputPath)));
4848
expect(output).toEqual(expected);
4949
});
5050
}

modules/angular2/test/transform/bind_generator/events_files/bar.ng_deps.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ void initReflector(reflector) {
1313
'parameters': const [],
1414
'annotations': const [
1515
const Directive(
16-
selector: '[tool-tip]', events: ['onOpen', 'close: onClose'])
16+
selector: '[tool-tip]', events: ['onOpen', 'close: onClose'])
1717
]
1818
});
1919
}

modules/angular2/test/transform/directive_processor/all_tests.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@ void _testNgDeps(String name, String inputPath,
121121
if (output == null) {
122122
expect(await reader.hasInput(expectedId)).toBeFalse();
123123
} else {
124-
expect(formatter.format(output))
125-
.toEqual((await reader.readAsString(expectedId)).replaceAll('\r\n', '\n'));
124+
expect(formatter.format(output)).toEqual(
125+
(await reader.readAsString(expectedId)).replaceAll('\r\n', '\n'));
126126
}
127127

128128
if (expectedLogs != null) {
Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
library test.transform.directive_processor.url_expression_files.hello;
22

33
import 'package:angular2/angular2.dart'
4-
show bootstrap, Component, Directive, View, NgElement;
4+
show bootstrap, Component, Directive, View, NgElement;
55

66
@Component(selector: 'hello-app')
77
@View(
88
templateUrl: '/bad/absolute/url.html',
9-
styleUrls: const [
10-
'package:invalid/package.css',
11-
'bad_relative_url.css'
12-
])
9+
styleUrls: const ['package:invalid/package.css', 'bad_relative_url.css'])
1310
class HelloCmp {}

0 commit comments

Comments
 (0)