|
| 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