Skip to content

Commit d982de6

Browse files
committed
1cebd31 docs(changelog): update changelog to beta.15
1 parent e45ac5f commit d982de6

14 files changed

Lines changed: 67 additions & 314 deletions

File tree

BUILD_INFO

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
Wed Apr 13 20:39:59 UTC 2016
2-
7bc9b19418e71bf76a196a8f4f5453157d69ee81
1+
Wed Apr 13 21:53:29 UTC 2016
2+
1cebd318e5b31df5491ef1017a6abf3444f901f4

lib/src/compiler/static_reflector.dart

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,6 @@ class StaticReflector {
9292
.toList()
9393
.where((decorator) => isPresent(decorator))
9494
.toList();
95-
} else {
96-
annotations = [];
9795
}
9896
this.annotationCache[type] = annotations;
9997
}
@@ -106,9 +104,6 @@ class StaticReflector {
106104
var classMetadata = this.getTypeMetadata(type);
107105
propMetadata =
108106
this.getPropertyMetadata(type.moduleId, classMetadata["members"]);
109-
if (!isPresent(propMetadata)) {
110-
propMetadata = {};
111-
}
112107
this.propertyCache[type] = propMetadata;
113108
}
114109
return propMetadata;
@@ -118,22 +113,14 @@ class StaticReflector {
118113
var parameters = this.parameterCache[type];
119114
if (!isPresent(parameters)) {
120115
var classMetadata = this.getTypeMetadata(type);
121-
if (isPresent(classMetadata)) {
122-
var members = classMetadata["members"];
123-
if (isPresent(members)) {
124-
var ctorData = members["___ctor__"];
125-
if (isPresent(ctorData)) {
126-
var ctor = ((ctorData as List<dynamic>)).firstWhere(
127-
(a) => identical(a["___symbolic"], "constructor"),
128-
orElse: () => null);
129-
parameters = this.simplify(type.moduleId, ctor["parameters"]);
130-
}
131-
}
116+
var ctorData = classMetadata["members"]["___ctor__"];
117+
if (isPresent(ctorData)) {
118+
var ctor = ((ctorData as List<dynamic>)).firstWhere(
119+
(a) => identical(a["___symbolic"], "constructor"),
120+
orElse: () => null);
121+
parameters = this.simplify(type.moduleId, ctor["parameters"]);
122+
this.parameterCache[type] = parameters;
132123
}
133-
if (!isPresent(parameters)) {
134-
parameters = [];
135-
}
136-
this.parameterCache[type] = parameters;
137124
}
138125
return parameters;
139126
}
@@ -317,7 +304,7 @@ class StaticReflector {
317304
});
318305
return result;
319306
}
320-
return {};
307+
return null;
321308
}
322309

323310
// clang-format off

lib/src/core/change_detection/parser/parser.dart

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ import "ast.dart"
5454
var _implicitReceiver = new ImplicitReceiver();
5555
// TODO(tbosch): Cannot make this const/final right now because of the transpiler...
5656
var INTERPOLATION_REGEXP = new RegExp(r'\{\{([\s\S]*?)\}\}');
57-
var COMMENT_REGEX = new RegExp(r'\/\/');
5857

5958
class ParseException extends BaseException {
6059
ParseException(String message, String input, String errLocation,
@@ -82,7 +81,7 @@ class Parser {
8281
}
8382
ASTWithSource parseAction(String input, dynamic location) {
8483
this._checkNoInterpolation(input, location);
85-
var tokens = this._lexer.tokenize(this._stripComments(input));
84+
var tokens = this._lexer.tokenize(input);
8685
var ast = new _ParseAST(input, location, tokens, this._reflector, true)
8786
.parseChain();
8887
return new ASTWithSource(ast, input, location);
@@ -113,7 +112,7 @@ class Parser {
113112
return quote;
114113
}
115114
this._checkNoInterpolation(input, location);
116-
var tokens = this._lexer.tokenize(this._stripComments(input));
115+
var tokens = this._lexer.tokenize(input);
117116
return new _ParseAST(input, location, tokens, this._reflector, false)
118117
.parseChain();
119118
}
@@ -139,8 +138,7 @@ class Parser {
139138
if (split == null) return null;
140139
var expressions = [];
141140
for (var i = 0; i < split.expressions.length; ++i) {
142-
var tokens =
143-
this._lexer.tokenize(this._stripComments(split.expressions[i]));
141+
var tokens = this._lexer.tokenize(split.expressions[i]);
144142
var ast = new _ParseAST(input, location, tokens, this._reflector, false)
145143
.parseChain();
146144
expressions.add(ast);
@@ -178,10 +176,6 @@ class Parser {
178176
return new ASTWithSource(new LiteralPrimitive(input), input, location);
179177
}
180178

181-
String _stripComments(String input) {
182-
return StringWrapper.split(input, COMMENT_REGEX)[0].trim();
183-
}
184-
185179
void _checkNoInterpolation(String input, dynamic location) {
186180
var parts = StringWrapper.split(input, INTERPOLATION_REGEXP);
187181
if (parts.length > 1) {

lib/src/core/metadata/di.dart

Lines changed: 16 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -301,77 +301,23 @@ class ViewQueryMetadata extends QueryMetadata {
301301
}
302302

303303
/**
304-
* Declares a list of child element references.
304+
* Configures a view query.
305305
*
306-
* Angular automatically updates the list when the DOM was updated.
307-
*
308-
* `ViewChildren` takes an argument to select elements.
309-
*
310-
* - If the argument is a type, directives or components with the type will be bound.
311-
*
312-
* - If the argument is a string, the string behaviors as comma-separated selectors. For each
313-
* selector, an element matched template variables (e.g. `#child`) will be bound.
314-
*
315-
* View children are set before the `ngAfterViewInit` callback is called.
306+
* View queries are set before the `ngAfterViewInit` callback is called.
316307
*
317308
* ### Example
318309
*
319-
* With type selector:
320-
*
321-
* ```
322-
* @Component({
323-
* selector: 'child-cmp',
324-
* template: '<p>child</p>'
325-
* })
326-
* class ChildCmp {
327-
* doSomething() {}
328-
* }
329-
*
330-
* @Component({
331-
* selector: 'some-cmp',
332-
* template: `
333-
* <child-cmp></child-cmp>
334-
* <child-cmp></child-cmp>
335-
* <child-cmp></child-cmp>
336-
* `,
337-
* directives: [ChildCmp]
338-
* })
339-
* class SomeCmp {
340-
* @ViewChildren(ChildCmp) children:QueryList<ChildCmp>;
341-
*
342-
* ngAfterViewInit() {
343-
* // children are set
344-
* this.children.toArray().forEach((child)=>child.doSomething());
345-
* }
346-
* }
347-
* ```
348-
*
349-
* With string selector:
350-
*
351310
* ```
352311
* @Component({
353-
* selector: 'child-cmp',
354-
* template: '<p>child</p>'
312+
* selector: 'someDir',
313+
* templateUrl: 'someTemplate',
314+
* directives: [ItemDirective]
355315
* })
356-
* class ChildCmp {
357-
* doSomething() {}
358-
* }
359-
*
360-
* @Component({
361-
* selector: 'some-cmp',
362-
* template: `
363-
* <child-cmp #child1></child-cmp>
364-
* <child-cmp #child2></child-cmp>
365-
* <child-cmp #child3></child-cmp>
366-
* `,
367-
* directives: [ChildCmp]
368-
* })
369-
* class SomeCmp {
370-
* @ViewChildren('child1,child2,child3') children:QueryList<ChildCmp>;
316+
* class SomeDir {
317+
* @ViewChildren(ItemDirective) viewChildren: QueryList<ItemDirective>;
371318
*
372319
* ngAfterViewInit() {
373-
* // children are set
374-
* this.children.toArray().forEach((child)=>child.doSomething());
320+
* // viewChildren is set
375321
* }
376322
* }
377323
* ```
@@ -382,71 +328,23 @@ class ViewChildrenMetadata extends ViewQueryMetadata {
382328
}
383329

384330
/**
331+
* Configures a view query.
385332
*
386-
* Declares a reference of child element.
387-
*
388-
* `ViewChildren` takes an argument to select elements.
389-
*
390-
* - If the argument is a type, a directive or a component with the type will be bound.
391-
*
392-
* - If the argument is a string, the string behaviors as a selectors. An element matched template
393-
* variables (e.g. `#child`) will be bound.
394-
*
395-
* In either case, `@ViewChild()` assigns the first (looking from above) element if the result is
396-
* multiple.
397-
*
398-
* View child is set before the `ngAfterViewInit` callback is called.
333+
* View queries are set before the `ngAfterViewInit` callback is called.
399334
*
400335
* ### Example
401336
*
402-
* With type selector:
403-
*
404337
* ```
405338
* @Component({
406-
* selector: 'child-cmp',
407-
* template: '<p>child</p>'
339+
* selector: 'someDir',
340+
* templateUrl: 'someTemplate',
341+
* directives: [ItemDirective]
408342
* })
409-
* class ChildCmp {
410-
* doSomething() {}
411-
* }
412-
*
413-
* @Component({
414-
* selector: 'some-cmp',
415-
* template: '<child-cmp></child-cmp>',
416-
* directives: [ChildCmp]
417-
* })
418-
* class SomeCmp {
419-
* @ViewChild(ChildCmp) child:ChildCmp;
420-
*
421-
* ngAfterViewInit() {
422-
* // child is set
423-
* this.child.doSomething();
424-
* }
425-
* }
426-
* ```
427-
*
428-
* With string selector:
429-
*
430-
* ```
431-
* @Component({
432-
* selector: 'child-cmp',
433-
* template: '<p>child</p>'
434-
* })
435-
* class ChildCmp {
436-
* doSomething() {}
437-
* }
438-
*
439-
* @Component({
440-
* selector: 'some-cmp',
441-
* template: '<child-cmp #child></child-cmp>',
442-
* directives: [ChildCmp]
443-
* })
444-
* class SomeCmp {
445-
* @ViewChild('child') child:ChildCmp;
343+
* class SomeDir {
344+
* @ViewChild(ItemDirective) viewChild:ItemDirective;
446345
*
447346
* ngAfterViewInit() {
448-
* // child is set
449-
* this.child.doSomething();
347+
* // viewChild is set
450348
* }
451349
* }
452350
* ```

lib/src/i18n/i18n_html_parser.dart

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,14 @@ import "shared.dart"
3030
partition,
3131
Part,
3232
stringifyNodes,
33-
meaning,
34-
getPhNameFromBinding,
35-
dedupePhName;
33+
meaning;
3634

3735
const _I18N_ATTR = "i18n";
3836
const _PLACEHOLDER_ELEMENT = "ph";
3937
const _NAME_ATTR = "name";
4038
const _I18N_ATTR_PREFIX = "i18n-";
4139
var _PLACEHOLDER_EXPANDED_REGEXP =
42-
RegExpWrapper.create('''\\<ph(\\s)+name=("(\\w)+")\\>\\<\\/ph\\>''');
40+
RegExpWrapper.create('''\\<ph(\\s)+name=("(\\d)+")\\>\\<\\/ph\\>''');
4341

4442
/**
4543
* Creates an i18n-ed version of the parsed template.
@@ -325,32 +323,22 @@ class I18nHtmlParser implements HtmlParser {
325323

326324
String _replacePlaceholdersWithExpressions(
327325
String message, List<String> exps, ParseSourceSpan sourceSpan) {
328-
var expMap = this._buildExprMap(exps);
329326
return RegExpWrapper.replaceAll(_PLACEHOLDER_EXPANDED_REGEXP, message,
330327
(match) {
331328
var nameWithQuotes = match[2];
332329
var name = nameWithQuotes.substring(1, nameWithQuotes.length - 1);
333-
return this._convertIntoExpression(name, expMap, sourceSpan);
330+
var index = NumberWrapper.parseInt(name, 10);
331+
return this._convertIntoExpression(index, exps, sourceSpan);
334332
});
335333
}
336334

337-
Map<String, String> _buildExprMap(List<String> exps) {
338-
var expMap = new Map<String, String>();
339-
var usedNames = new Map<String, num>();
340-
for (var i = 0; i < exps.length; i++) {
341-
var phName = getPhNameFromBinding(exps[i], i);
342-
expMap[dedupePhName(usedNames, phName)] = exps[i];
343-
}
344-
return expMap;
345-
}
346-
347335
_convertIntoExpression(
348-
String name, Map<String, String> expMap, ParseSourceSpan sourceSpan) {
349-
if (expMap.containsKey(name)) {
350-
return '''{{${ expMap [ name ]}}}''';
336+
num index, List<String> exps, ParseSourceSpan sourceSpan) {
337+
if (index >= 0 && index < exps.length) {
338+
return '''{{${ exps [ index ]}}}''';
351339
} else {
352340
throw new I18nError(
353-
sourceSpan, '''Invalid interpolation name \'${ name}\'''');
341+
sourceSpan, '''Invalid interpolation index \'${ index}\'''');
354342
}
355343
}
356344
}

lib/src/i18n/shared.dart

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,13 @@ import "package:angular2/src/compiler/html_ast.dart"
1111
HtmlTextAst,
1212
HtmlCommentAst,
1313
htmlVisitAll;
14-
import "package:angular2/src/facade/lang.dart"
15-
show isPresent, isBlank, StringWrapper;
14+
import "package:angular2/src/facade/lang.dart" show isPresent, isBlank;
1615
import "message.dart" show Message;
1716
import "package:angular2/src/core/change_detection/parser/parser.dart"
1817
show Parser;
1918

2019
const I18N_ATTR = "i18n";
2120
const I18N_ATTR_PREFIX = "i18n-";
22-
var CUSTOM_PH_EXP = new RegExp(
23-
r'\/\/[\s\S]*i18n[\s\S]*\([\s\S]*ph[\s\S]*=[\s\S]*"([\s\S]*?)"[\s\S]*\)');
2421

2522
/**
2623
* An i18n error.
@@ -127,15 +124,12 @@ String removeInterpolation(
127124
String value, ParseSourceSpan source, Parser parser) {
128125
try {
129126
var parsed = parser.splitInterpolation(value, source.toString());
130-
var usedNames = new Map<String, num>();
131127
if (isPresent(parsed)) {
132128
var res = "";
133129
for (var i = 0; i < parsed.strings.length; ++i) {
134130
res += parsed.strings[i];
135131
if (i != parsed.strings.length - 1) {
136-
var customPhName = getPhNameFromBinding(parsed.expressions[i], i);
137-
customPhName = dedupePhName(usedNames, customPhName);
138-
res += '''<ph name="${ customPhName}"/>''';
132+
res += '''<ph name="${ i}"/>''';
139133
}
140134
}
141135
return res;
@@ -147,22 +141,6 @@ String removeInterpolation(
147141
}
148142
}
149143

150-
String getPhNameFromBinding(String input, num index) {
151-
var customPhMatch = StringWrapper.split(input, CUSTOM_PH_EXP);
152-
return customPhMatch.length > 1 ? customPhMatch[1] : '''${ index}''';
153-
}
154-
155-
String dedupePhName(Map<String, num> usedNames, String name) {
156-
var duplicateNameCount = usedNames[name];
157-
if (isPresent(duplicateNameCount)) {
158-
usedNames[name] = duplicateNameCount + 1;
159-
return '''${ name}_${ duplicateNameCount}''';
160-
} else {
161-
usedNames[name] = 1;
162-
return name;
163-
}
164-
}
165-
166144
String stringifyNodes(List<HtmlAst> nodes, Parser parser) {
167145
var visitor = new _StringifyVisitor(parser);
168146
return htmlVisitAll(visitor, nodes).join("");

0 commit comments

Comments
 (0)