| Index: third_party/pkg/angular/lib/core/interpolate.dart
|
| diff --git a/third_party/pkg/angular/lib/core/interpolate.dart b/third_party/pkg/angular/lib/core/interpolate.dart
|
| index aed34f53fff1ae041f7e59d640d14d588a23b6b9..28d09bee75654eba941bd4a4d44b4ebab811408a 100644
|
| --- a/third_party/pkg/angular/lib/core/interpolate.dart
|
| +++ b/third_party/pkg/angular/lib/core/interpolate.dart
|
| @@ -1,69 +1,86 @@
|
| -part of angular.core_internal;
|
| +part of angular.core;
|
| +
|
| +class Interpolation {
|
| + final String template;
|
| + final List<String> seperators;
|
| + final List<String> expressions;
|
| + Function setter = (_) => _;
|
| +
|
| + Interpolation(this.template, this.seperators, this.expressions);
|
| +
|
| + String call(List parts, [_]) {
|
| + if (parts == null) return seperators.join('');
|
| + var str = [];
|
| + for (var i = 0; i < parts.length; i++) {
|
| + str.add(seperators[i]);
|
| + var value = parts[i];
|
| + str.add(value == null ? '' : '$value');
|
| + }
|
| + str.add(seperators.last);
|
| + return setter(str.join(''));
|
| + }
|
| +}
|
|
|
| /**
|
| - * Compiles a string with markup into an expression. This service is used by the
|
| - * HTML [Compiler] service for data binding.
|
| + * Compiles a string with markup into an interpolation function. This service
|
| + * is used by the HTML [Compiler] service for data binding.
|
| + *
|
| *
|
| - * var interpolate = ...; // injected
|
| - * var exp = interpolate('Hello {{name}}!');
|
| - * expect(exp).toEqual('"Hello "+(name|stringify)+"!"');
|
| + * var $interpolate = ...; // injected
|
| + * var exp = $interpolate('Hello {{name}}!');
|
| + * expect(exp({name:'Angular'}).toEqual('Hello Angular!');
|
| */
|
| -@Injectable()
|
| -class Interpolate implements Function {
|
| +@NgInjectableService()
|
| +class Interpolate {
|
| + final Parser _parse;
|
| +
|
| + Interpolate(this._parse);
|
| +
|
| /**
|
| - * Compiles markup text into expression.
|
| + * Compiles markup text into interpolation function.
|
| *
|
| - * - [template]: The markup text to interpolate in form `foo {{expr}} bar`.
|
| - * - [mustHaveExpression]: if set to true then the interpolation string must
|
| - * have embedded expression in order to return an expression. Strings with
|
| - * no embedded expression will return null.
|
| - * - [startSymbol]: The symbol to start interpolation. '{{' by default.
|
| - * - [endSymbol]: The symbol to end interpolation. '}}' by default.
|
| + * - `text`: The markup text to interpolate in form `foo {{expr}} bar`.
|
| + * - `mustHaveExpression`: if set to true then the interpolation string must
|
| + * have embedded expression in order to return an interpolation function.
|
| + * Strings with no embedded expression will return null for the
|
| + * interpolation function.
|
| + * - `startSymbol`: The symbol to start interpolation. '{{' by default.
|
| + * - `endSymbol`: The symbol to end interpolation. '}}' by default.
|
| */
|
| -
|
| - String call(String template, [bool mustHaveExpression = false,
|
| - String startSymbol = '{{', String endSymbol = '}}']) {
|
| - if (template == null || template.isEmpty) return "";
|
| -
|
| - final startLen = startSymbol.length;
|
| - final endLen = endSymbol.length;
|
| - final length = template.length;
|
| -
|
| - int startIdx;
|
| - int endIdx;
|
| + Interpolation call(String template, [bool mustHaveExpression = false,
|
| + String startSymbol = '{{', String endSymbol = '}}']) {
|
| + int startSymbolLength = startSymbol.length;
|
| + int endSymbolLength = endSymbol.length;
|
| + int startIndex;
|
| + int endIndex;
|
| int index = 0;
|
| -
|
| + int length = template.length;
|
| bool hasInterpolation = false;
|
| -
|
| + bool shouldAddSeparator = true;
|
| String exp;
|
| - final expParts = <String>[];
|
| -
|
| - while (index < length) {
|
| - startIdx = template.indexOf(startSymbol, index);
|
| - endIdx = template.indexOf(endSymbol, startIdx + startLen);
|
| - if (startIdx != -1 && endIdx != -1) {
|
| - if (index < startIdx) {
|
| - // Empty strings could be stripped thanks to the stringify
|
| - // formatter
|
| - expParts.add(_wrapInQuotes(template.substring(index, startIdx)));
|
| - }
|
| - expParts.add('(' + template.substring(startIdx + startLen, endIdx) +
|
| - '|stringify)');
|
| + List<String> separators = [];
|
| + List<String> expressions = [];
|
|
|
| - index = endIdx + endLen;
|
| + while(index < length) {
|
| + if ( ((startIndex = template.indexOf(startSymbol, index)) != -1) &&
|
| + ((endIndex = template.indexOf(endSymbol, startIndex + startSymbolLength)) != -1) ) {
|
| + separators.add(template.substring(index, startIndex));
|
| + exp = template.substring(startIndex + startSymbolLength, endIndex);
|
| + expressions.add(exp);
|
| + index = endIndex + endSymbolLength;
|
| hasInterpolation = true;
|
| } else {
|
| - // we did not find any interpolation, so add the remainder
|
| - expParts.add(_wrapInQuotes(template.substring(index)));
|
| + // we did not find anything, so we have to add the remainder to the chunks array
|
| + separators.add(template.substring(index));
|
| + shouldAddSeparator = false;
|
| break;
|
| }
|
| }
|
| -
|
| - return !mustHaveExpression || hasInterpolation ? expParts.join('+') : null;
|
| - }
|
| -
|
| - String _wrapInQuotes(String s){
|
| - final escaped = s.replaceAll(r'\', r'\\').replaceAll(r'"', r'\"');
|
| - return '"$escaped"';
|
| + if (shouldAddSeparator) {
|
| + separators.add('');
|
| + }
|
| + return (!mustHaveExpression || hasInterpolation)
|
| + ? new Interpolation(template, separators, expressions)
|
| + : null;
|
| }
|
| }
|
|
|