Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 992114f

Browse files
petebacondarwinchirayuk
authored andcommittedApr 19, 2015
fix(ngMessageFormat): ensure bindings are valid for Protractor
Closes #11644 Closes #11649
1 parent 103a39c commit 992114f

6 files changed

+30
-17
lines changed
 

‎src/ngMessageFormat/messageFormatCommon.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ function parseTextLiteral(text) {
5151
return unwatch;
5252
};
5353
PARSE_CACHE_FOR_TEXT_LITERALS[text] = parsedFn;
54-
parsedFn.exp = text; // Needed to pretend to be $interpolate for tests copied from interpolateSpec.js
55-
parsedFn.expressions = []; // Require this to call $compile.$$addBindingInfo() which allows Protractor to find elements by binding.
54+
parsedFn['exp'] = text; // Needed to pretend to be $interpolate for tests copied from interpolateSpec.js
55+
parsedFn['expressions'] = []; // Require this to call $compile.$$addBindingInfo() which allows Protractor to find elements by binding.
5656
return parsedFn;
5757
}
5858

‎src/ngMessageFormat/messageFormatInterpolationParts.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,10 @@ InterpolationParts.prototype.toParsedFn = function toParsedFn(mustHaveExpression
9595
return self.watchDelegate(scope, listener, objectEquality);
9696
};
9797

98-
parsedFn.exp = originalText; // Needed to pretend to be $interpolate for tests copied from interpolateSpec.js
99-
parsedFn.expressions = new Array(this.expressionFns.length); // Require this to call $compile.$$addBindingInfo() which allows Protractor to find elements by binding.
98+
parsedFn['exp'] = originalText; // Needed to pretend to be $interpolate for tests copied from interpolateSpec.js
99+
parsedFn['expressions'] = new Array(this.expressionFns.length); // Require this to call $compile.$$addBindingInfo() which allows Protractor to find elements by binding.
100100
for (var i = 0; i < this.expressionFns.length; i++) {
101-
parsedFn.expressions[i] = this.expressionFns[i].exp;
101+
parsedFn['expressions'][i] = this.expressionFns[i]['exp'];
102102
}
103103

104104
return parsedFn;

‎src/ngMessageFormat/messageFormatParser.js

+8-5
Original file line numberDiff line numberDiff line change
@@ -412,8 +412,8 @@ MessageFormatParser.prototype.ruleEndMustache = function ruleEndMustache() {
412412
// such a case we do not want to unnecessarily stringify something if it's not going to be used
413413
// in a string context.
414414
this.parsedFn = this.$parse(this.expressionFn, this.stringifier);
415-
this.parsedFn.exp = this.expressionFn.exp; // Needed to pretend to be $interpolate for tests copied from interpolateSpec.js
416-
this.parsedFn.expressions = this.expressionFn.expressions; // Require this to call $compile.$$addBindingInfo() which allows Protractor to find elements by binding.
415+
this.parsedFn['exp'] = this.expressionFn['exp']; // Needed to pretend to be $interpolate for tests copied from interpolateSpec.js
416+
this.parsedFn['expressions'] = this.expressionFn['expressions']; // Require this to call $compile.$$addBindingInfo() which allows Protractor to find elements by binding.
417417
}
418418
this.rule = null;
419419
};
@@ -461,7 +461,8 @@ MessageFormatParser.prototype.ruleInAngularExpression = function ruleInAngularEx
461461
this.index = this.text.length;
462462
this.expressionFn = this.$parse(this.text.substring(this.expressionStartIndex, this.index));
463463
// Needed to pretend to be $interpolate for tests copied from interpolateSpec.js
464-
this.expressionFn.exp = this.text.substring(this.expressionStartIndex, this.index);
464+
this.expressionFn['exp'] = this.text.substring(this.expressionStartIndex, this.index);
465+
this.expressionFn['expressions'] = this.expressionFn['expressions'];
465466
this.rule = null;
466467
return;
467468
}
@@ -488,7 +489,8 @@ MessageFormatParser.prototype.ruleInAngularExpression = function ruleInAngularEx
488489
// todo: does this need to be trimmed?
489490
this.expressionFn = this.$parse(this.text.substring(this.expressionStartIndex, match.index));
490491
// Needed to pretend to be $interpolate for tests copied from interpolateSpec.js
491-
this.expressionFn.exp = this.text.substring(this.expressionStartIndex, match.index);
492+
this.expressionFn['exp'] = this.text.substring(this.expressionStartIndex, match.index);
493+
this.expressionFn['expressions'] = this.expressionFn['expressions'];
492494
this.rule = null;
493495
this.rule = this.rulePluralOrSelect;
494496
}
@@ -516,6 +518,7 @@ MessageFormatParser.prototype.ruleInAngularExpression = function ruleInAngularEx
516518
this.index = match.index;
517519
this.expressionFn = this.$parse(this.text.substring(this.expressionStartIndex, this.index));
518520
// Needed to pretend to be $interpolate for tests copied from interpolateSpec.js
519-
this.expressionFn.exp = this.text.substring(this.expressionStartIndex, this.index);
521+
this.expressionFn['exp'] = this.text.substring(this.expressionStartIndex, this.index);
522+
this.expressionFn['expressions'] = this.expressionFn['expressions'];
520523
this.rule = null;
521524
};

‎src/ngMessageFormat/messageFormatSelector.js

+2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ function MessageSelectorBase(expressionFn, choices) {
2424
this.parsedFn['$$watchDelegate'] = function $$watchDelegate(scope, listener, objectEquality) {
2525
return self.watchDelegate(scope, listener, objectEquality);
2626
};
27+
this.parsedFn['exp'] = expressionFn['exp'];
28+
this.parsedFn['expressions'] = expressionFn['expressions'];
2729
}
2830

2931
MessageSelectorBase.prototype.getMessageFn = function getMessageFn(value) {

‎src/ngMessageFormat/messageFormatService.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@
2424
* <file name="index.html">
2525
* <div ng-controller="AppController">
2626
* <button ng-click="decreaseRecipients()" id="decreaseRecipients">decreaseRecipients</button><br>
27-
* <span id="message">{{recipients.length, plural, offset:1
28-
* =0 {{{sender.name}} gave no gifts (\#=#)}
29-
* =1 {{{sender.name}} gave one gift to {{recipients[0].name}} (\#=#)}
30-
* one {{{sender.name}} gave {{recipients[0].name}} and one other person a gift (\#=#)}
31-
* other {{{sender.name}} gave {{recipients[0].name}} and # other people a gift (\#=#)}
32-
* }}</span>
27+
* <span>{{recipients.length, plural, offset:1
28+
* =0 {{{sender.name}} gave no gifts (\#=#)}
29+
* =1 {{{sender.name}} gave one gift to {{recipients[0].name}} (\#=#)}
30+
* one {{{sender.name}} gave {{recipients[0].name}} and one other person a gift (\#=#)}
31+
* other {{{sender.name}} gave {{recipients[0].name}} and # other people a gift (\#=#)}
32+
* }}</span>
3333
* </div>
3434
* </file>
3535
*
@@ -57,7 +57,7 @@
5757
* <file name="protractor.js" type="protractor">
5858
* describe('MessageFormat plural', function() {
5959
* it('should pluralize initial values', function() {
60-
* var messageElem = element(by.id('message')), decreaseRecipientsBtn = element(by.id('decreaseRecipients'));
60+
* var messageElem = element(by.binding('recipients.length')), decreaseRecipientsBtn = element(by.id('decreaseRecipients'));
6161
* expect(messageElem.getText()).toEqual('Harry Potter gave Alice and 2 other people a gift (#=2)');
6262
* decreaseRecipientsBtn.click();
6363
* expect(messageElem.getText()).toEqual('Harry Potter gave Alice and one other person a gift (#=1)');

‎test/ngMessageFormat/messageFormatSpec.js

+8
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ describe('$$ngMessageFormat', function() {
126126
" other {You gave some people gifts}\n" +
127127
"}}";
128128
var parsedFn = $interpolate(text, /*mustHaveExpression=*/true);
129+
expect(parsedFn.expressions.length).toBe(1);
130+
expect(parsedFn.expressions[0]).toEqual("recipients.length");
129131

130132
$rootScope.recipients.length=2;
131133
expect(parsedFn($rootScope)).toEqual("You gave some people gifts");
@@ -147,6 +149,8 @@ describe('$$ngMessageFormat', function() {
147149
" other {{{sender.name}} gave them a gift}\n" +
148150
"}}";
149151
var parsedFn = $interpolate(text, /*mustHaveExpression=*/true);
152+
expect(parsedFn.expressions.length).toBe(1);
153+
expect(parsedFn.expressions[0]).toEqual("recipients.length");
150154

151155
$rootScope.recipients.length=2;
152156
expect(parsedFn($rootScope)).toEqual("Harry Potter gave them a gift");
@@ -168,6 +172,8 @@ describe('$$ngMessageFormat', function() {
168172
" other {{{sender.name}} gave {{recipients[0].name}} and # other people a gift (\\#=#)}\n" +
169173
"}}";
170174
var parsedFn = $interpolate(text, /*mustHaveExpression=*/true);
175+
expect(parsedFn.expressions.length).toBe(1);
176+
expect(parsedFn.expressions[0]).toEqual("recipients.length");
171177

172178
$rootScope.recipients.length=3;
173179
// "#" should get replaced with the value of "recipients.length - offset"
@@ -197,6 +203,8 @@ describe('$$ngMessageFormat', function() {
197203
" other {You gave {{recipients.length}} people gifts. -{{sender.name}}}\n" +
198204
"}}";
199205
var parsedFn = $interpolate(text, /*mustHaveExpression=*/true);
206+
expect(parsedFn.expressions.length).toBe(1);
207+
expect(parsedFn.expressions[0]).toEqual("recipients.length");
200208
var result = parsedFn($rootScope);
201209
expect(result).toEqual("You gave 3 people gifts. -Harry Potter");
202210
});

0 commit comments

Comments
 (0)
This repository has been archived.