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

Commit 62c0849

Browse files
committed
Address review comments, add error docs, cleanup.
1 parent d91e802 commit 62c0849

27 files changed

+692
-509
lines changed

Gruntfile.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ module.exports = function(grunt) {
204204
src: util.wrap(files['angularModules']['ngResource'], 'module')
205205
},
206206
messageformat: {
207-
dest: 'build/angular-messageformat.js',
207+
dest: 'build/angular-messageFormat.js',
208208
src: util.wrap(files['angularModules']['ngMessageFormat'], 'module_closure')
209209
},
210210
messages: {
@@ -239,7 +239,7 @@ module.exports = function(grunt) {
239239
animate: 'build/angular-animate.js',
240240
cookies: 'build/angular-cookies.js',
241241
loader: 'build/angular-loader.js',
242-
messageformat: 'build/angular-messageformat.js',
242+
messageformat: 'build/angular-messageFormat.js',
243243
messages: 'build/angular-messages.js',
244244
touch: 'build/angular-touch.js',
245245
resource: 'build/angular-resource.js',

angularFiles.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,11 @@ var angularFiles = {
9292
'src/ngCookies/cookies.js'
9393
],
9494
'ngMessageFormat': [
95-
'src/ngMessageFormat/messageformat.js'
95+
'src/ngMessageFormat/messageFormatCommon.js',
96+
'src/ngMessageFormat/messageFormatSelector.js',
97+
'src/ngMessageFormat/messageFormatInterpolationParts.js',
98+
'src/ngMessageFormat/messageFormatParser.js',
99+
'src/ngMessageFormat/messageFormatService.js'
96100
],
97101
'ngMessages': [
98102
'src/ngMessages/messages.js'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
@ngdoc error
2+
@name $interpolate:badexpr
3+
@fullName Expecting end operator
4+
@description
5+
6+
The Angular expression is missing the corresponding closing operator.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
@ngdoc error
2+
@name $interpolate:dupvalue
3+
@fullName Duplicate choice in plural/select
4+
@description
5+
6+
You have repeated a match selection for your plural or select MessageFormat
7+
extension in your interpolation interpolation expression. The different
8+
choices have to be unique
9+
10+
For more information about the MessageFormat syntax in interpolation
11+
expressions, please refer to MessageFormat extensions section at
12+
{@link guide/i18n#MessageFormat Angular i18n MessageFormat}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
@ngdoc error
2+
@name $interpolate:logicbug
3+
@fullName Bug in ngMessageFormat module
4+
@description
5+
6+
You've just hit a bug in the ngMessageFormat module provided by provided by
7+
angular-messageFormat.min.js. Please file a github issue for this and provide the interpolation text that caused you to hit this bug mentioning the exact version of AngularJS used and we will fix it!
8+
9+
For more information about the MessageFormat syntax in interpolation
10+
expressions, please refer to MessageFormat extensions section at
11+
{@link guide/i18n#MessageFormat Angular i18n MessageFormat}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
@ngdoc error
2+
@name $interpolate:nochgmustache
3+
@fullName Redefinition of start/endSymbol incompatible with MessageFormat extensions
4+
@description
5+
6+
You have redefined `$interpolate.startSymbol`/`$interpolate.endSymbol` and also
7+
loaded the `ngMessageFormat` module (provided by angular-messageFormat.min.js)
8+
while creating your injector.
9+
10+
`ngMessageFormat` currently does not support redefinition of the
11+
startSymbol/endSymbol used by `$interpolate`. If this is affecting you, please
12+
file an issue and mention @chirayuk on it. This is intended to be fixed in a
13+
future commit and the github issue will help gauage urgency.
14+
15+
For more information about the MessageFormat syntax in interpolation
16+
expressions, please refer to MessageFormat extensions section at
17+
{@link guide/i18n#MessageFormat Angular i18n MessageFormat}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
@ngdoc error
2+
@name $interpolate:reqarg
3+
@fullName Missing required argument for MessageFormat
4+
@description
5+
6+
You must specify the MessageFormat function that you're using right after the
7+
comma following the Angular expression. Currently, the supported functions are
8+
"plural" and "select" (for gender selections.)
9+
10+
For more information about the MessageFormat syntax in interpolation
11+
expressions, please refer to MessageFormat extensions section at
12+
{@link guide/i18n#MessageFormat Angular i18n MessageFormat}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
@ngdoc error
2+
@name $interpolate:reqarg
3+
@fullName Missing comma following MessageFormat plural/select keyword
4+
@description
5+
6+
The MessageFormat syntax requires a comma following the "plural" or "select"
7+
extension keyword in the extended interpolation syntax.
8+
9+
For more information about the MessageFormat syntax in interpolation
10+
expressions, please refer to MessageFormat extensions section at
11+
{@link guide/i18n#MessageFormat Angular i18n MessageFormat}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
@ngdoc error
2+
@name $interpolate:reqendbrace
3+
@fullName Unterminated message for plural/select value
4+
@description
5+
6+
The plural or select message for a value or keyword choice has no matching end
7+
brace to mark the end of the message.
8+
9+
For more information about the MessageFormat syntax in interpolation
10+
expressions, please refer to MessageFormat extensions section at
11+
{@link guide/i18n#MessageFormat Angular i18n MessageFormat}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
@ngdoc error
2+
@name $interpolate:reqendinterp
3+
@fullName Unterminated interpolation
4+
@description
5+
6+
The interpolation text does not have an ending `endSymbol` ("}}" by default) and is unterminated.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
@ngdoc error
2+
@name $interpolate:reqopenbrace
3+
@fullName An opening brace was expected but not found
4+
@description
5+
6+
The plural or select extension keyword or values (such as "other", "male",
7+
"female", "=0", "one", "many", etc.) MUST be followed by a message enclosed in
8+
braces.
9+
10+
For more information about the MessageFormat syntax in interpolation
11+
expressions, please refer to MessageFormat extensions section at
12+
{@link guide/i18n#MessageFormat Angular i18n MessageFormat}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
@ngdoc error
2+
@name $interpolate:reqother
3+
@fullName Required choice "other" for select/plural in MessageFormat
4+
@description
5+
6+
Your interpolation expression with a MessageFormat extension for either
7+
"plural" or "select" (typically used for gender selection) does not contain a
8+
message for the choice "other". Using either select or plural MessageFormat
9+
extensions require that you provide a message for the selection "other".
10+
11+
For more information about the MessageFormat syntax in interpolation
12+
expressions, please refer to MessageFormat extensions section at
13+
{@link guide/i18n#MessageFormat Angular i18n MessageFormat}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
@ngdoc error
2+
@name $interpolate:unknarg
3+
@fullName Unrecognized MessageFormat extension
4+
@description
5+
6+
The MessageFormat extensions provided by `ngMessageFormat` are currently
7+
limited to "plural" and "select". The extension that you have used is either
8+
unsupported or invalid.
9+
10+
For more information about the MessageFormat syntax in interpolation
11+
expressions, please refer to MessageFormat extensions section at
12+
{@link guide/i18n#MessageFormat Angular i18n MessageFormat}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
@ngdoc error
2+
@name $interpolate:unsafe
3+
@fullName MessageFormat extensions not allowed in secure context
4+
@description
5+
6+
You have attempted to use a MessageFormat extension in your interpolation expression that is marked as a secure context. For security purposes, this is not supported.
7+
8+
Read more about secure contexts at {@link ng.$sce Strict Contextual Escaping
9+
(SCE)} and about the MessageFormat extensions at {@link
10+
guide/i18n#MessageFormat Angular i18n MessageFormat}.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
@ngdoc error
2+
@name $interpolate:untermstr
3+
@fullName Unterminated string literal
4+
@description
5+
6+
The string literal was not terminated in your Angular expression.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
@ngdoc error
2+
@name $interpolate:wantstring
3+
@fullName Expected the beginning of a string
4+
@description
5+
6+
We expected to see the beginning of a string (either a single quote or a double
7+
quote character) in the expression but it was not found. The expression is
8+
invalid. If this is incorrect, please file an issue on github.

docs/content/guide/i18n.ngdoc

+4
Original file line numberDiff line numberDiff line change
@@ -137,3 +137,7 @@ The Angular datetime filter uses the time zone settings of the browser. The same
137137
application will show different time information depending on the time zone settings of the
138138
computer that the application is running on. Neither JavaScript nor Angular currently supports
139139
displaying the date with a timezone specified by the developer.
140+
141+
142+
<a name="MessageFormat"></a>
143+
## MessageFormat extensions

lib/grunt/utils.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -186,10 +186,10 @@ module.exports = {
186186
var errorFileName = file.replace(/\.js$/, '-errors.json');
187187
var versionNumber = grunt.config('NG_VERSION').full;
188188
var compilationLevel = 'SIMPLE_OPTIMIZATIONS';
189-
var googDEBUG = '';
190-
if (file === 'build/angular-messageformat.js') {
191-
var compilationLevel = 'ADVANCED_OPTIMIZATIONS';
192-
var googDEBUG = '--define goog.DEBUG=false ';
189+
var googMINIFIED = '';
190+
if (file === 'build/angular-messageFormat.js') {
191+
compilationLevel = 'ADVANCED_OPTIMIZATIONS';
192+
googMINIFIED = '--define goog.MINIFIED=true ';
193193
}
194194
shell.exec(
195195
'java ' +
@@ -200,7 +200,7 @@ module.exports = {
200200
'org.angularjs.closurerunner.NgClosureRunner ' +
201201
'--compilation_level ' + compilationLevel + ' ' +
202202
'--language_in ECMASCRIPT5_STRICT ' +
203-
googDEBUG +
203+
googMINIFIED +
204204
'--minerr_pass ' +
205205
'--minerr_errors ' + errorFileName + ' ' +
206206
'--minerr_url http://errors.angularjs.org/' + versionNumber + '/ ' +

src/module_closure.prefix

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
/** @const */
77
var goog = goog || {};
88
/** @define {boolean} */
9-
goog.DEBUG = true;
9+
goog.MINIFIED = false;
1010
(function(window, angular, undefined) {

src/ng/interpolate.js

+14-11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
'use strict';
22

3-
var $interpolateMinErr = minErr('$interpolate');
3+
var $interpolateMinErr = angular.$interpolateMinErr = minErr('$interpolate');
4+
$interpolateMinErr.noconcat = function (text) {
5+
return $interpolateMinErr('noconcat',
6+
"Error while interpolating: {0}\nStrict Contextual Escaping disallows " +
7+
"interpolations that concatenate multiple expressions when a trusted value is " +
8+
"required. See http://docs.angularjs.org/api/ng.$sce", text);
9+
};
10+
11+
$interpolateMinErr.interr = function (text, err) {
12+
return $interpolateMinErr('interr', "Can't interpolate: {0}\n{1}", text, err.toString());
13+
};
414

515
/**
616
* @ngdoc provider
@@ -244,10 +254,7 @@ function $InterpolateProvider() {
244254
// make it obvious that you bound the value to some user controlled value. This helps reduce
245255
// the load when auditing for XSS issues.
246256
if (trustedContext && concat.length > 1) {
247-
throw $interpolateMinErr('noconcat',
248-
"Error while interpolating: {0}\nStrict Contextual Escaping disallows " +
249-
"interpolations that concatenate multiple expressions when a trusted value is " +
250-
"required. See http://docs.angularjs.org/api/ng.$sce", text);
257+
throw $interpolateMinErr.noconcat(text);
251258
}
252259

253260
if (!mustHaveExpression || expressions.length) {
@@ -277,9 +284,7 @@ function $InterpolateProvider() {
277284

278285
return compute(values);
279286
} catch (err) {
280-
var newErr = $interpolateMinErr('interr', "Can't interpolate: {0}\n{1}", text,
281-
err.toString());
282-
$exceptionHandler(newErr);
287+
$exceptionHandler($interpolateMinErr.interr(text, err));
283288
}
284289

285290
}, {
@@ -304,9 +309,7 @@ function $InterpolateProvider() {
304309
value = getValue(value);
305310
return allOrNothing && !isDefined(value) ? value : stringify(value);
306311
} catch (err) {
307-
var newErr = $interpolateMinErr('interr', "Can't interpolate: {0}\n{1}", text,
308-
err.toString());
309-
$exceptionHandler(newErr);
312+
$exceptionHandler($interpolateMinErr.interr(text, err));
310313
}
311314
}
312315
}

src/ngMessageFormat/.jshintrc

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"extends": "../../.jshintrc-base",
3+
"browser": true,
4+
"globals": {
5+
"angular": false,
6+
"goog": false // see src/module_closure.prefix
7+
}
8+
}
+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
'use strict';
2+
3+
// NOTE: ADVANCED_OPTIMIZATIONS mode.
4+
//
5+
// This file is compiled with Closure compiler's ADVANCED_OPTIMIZATIONS flag! Be wary of using
6+
// constructs incompatible with that mode.
7+
8+
var $interpolateMinErr = angular['$interpolateMinErr'];
9+
10+
var noop = angular['noop'],
11+
isFunction = angular['isFunction'],
12+
toJson = angular['toJson'];
13+
14+
function stringify(value) {
15+
if (value == null /* null/undefined */) { return ''; }
16+
switch (typeof value) {
17+
case 'string': return value;
18+
case 'number': return '' + value;
19+
default: return toJson(value);
20+
}
21+
}
22+
23+
// Convert an index into the string into line/column for use in error messages
24+
// As such, this doesn't have to be efficient.
25+
function indexToLineAndColumn(text, index) {
26+
var lines = text.split(/\n/g);
27+
for (var i=0; i < lines.length; i++) {
28+
var line=lines[i];
29+
if (index >= line.length) {
30+
index -= line.length;
31+
} else {
32+
return { line: i + 1, column: index + 1 };
33+
}
34+
}
35+
}
36+
var PARSE_CACHE_FOR_TEXT_LITERALS = Object.create(null);
37+
38+
function parseTextLiteral(text) {
39+
var cachedFn = PARSE_CACHE_FOR_TEXT_LITERALS[text];
40+
if (cachedFn != null) {
41+
return cachedFn;
42+
}
43+
function parsedFn(context) { return text; }
44+
parsedFn['$$watchDelegate'] = function watchDelegate(scope, listener, objectEquality) {
45+
var unwatch = scope['$watch'](noop,
46+
function textLiteralWatcher() {
47+
if (isFunction(listener)) { listener.call(null, text, text, scope); }
48+
unwatch();
49+
},
50+
objectEquality);
51+
return unwatch;
52+
};
53+
PARSE_CACHE_FOR_TEXT_LITERALS[text] = parsedFn;
54+
if (!goog.MINIFIED) {
55+
parsedFn.exp = text; // Needed to pretend to be $interpolate for tests copied from interpolateSpec.js
56+
parsedFn.expressions = []; // Unminified builds require this to call $compile.$$addBindingInfo() which allows Protractor to find elements by binding.
57+
}
58+
return parsedFn;
59+
}
60+
61+
function subtractOffset(expressionFn, offset) {
62+
if (offset === 0) {
63+
return expressionFn;
64+
}
65+
function minusOffset(value) {
66+
return (value == void 0) ? value : value - offset;
67+
}
68+
function parsedFn(context) { return minusOffset(expressionFn(context)); }
69+
var unwatch;
70+
parsedFn['$$watchDelegate'] = function watchDelegate(scope, listener, objectEquality) {
71+
unwatch = scope['$watch'](expressionFn,
72+
function pluralExpressionWatchListener(newValue, oldValue) {
73+
if (isFunction(listener)) { listener.call(null, minusOffset(newValue), minusOffset(oldValue), scope); }
74+
},
75+
objectEquality);
76+
return unwatch;
77+
};
78+
return parsedFn;
79+
}

0 commit comments

Comments
 (0)