Chromium Code Reviews| Index: pkg/compiler/lib/src/js/js.dart |
| diff --git a/pkg/compiler/lib/src/js/js.dart b/pkg/compiler/lib/src/js/js.dart |
| index 1a08cfbeb0798072ea178fd3993b134183c5c718..7cf2873ff03f4527d5e5e19a05265a3303744ade 100644 |
| --- a/pkg/compiler/lib/src/js/js.dart |
| +++ b/pkg/compiler/lib/src/js/js.dart |
| @@ -162,4 +162,27 @@ class UnparsedNode extends DeferredString |
| @override |
| String get value => _literal.value; |
| -} |
| +} |
| + |
| +/// Returns `true` if [template] will immediately give a TypeError if the first |
| +/// placeholder is `null` or `undefined`. |
| +bool isNullGuardOnFirstArgument(Template template) { |
| + // We look for a template of the form |
| + // |
| + // #.something |
| + // #.something() |
| + // |
|
asgerf
2016/01/11 16:28:25
Would be it be worthwhile to unfold all the way to
sra1
2016/01/11 19:25:27
I will see if it makes a difference.
|
| + Node node = template.ast; |
| + if (node is Call) { |
| + Call call = node; |
| + node = node.target; |
| + } |
| + if (node is PropertyAccess) { |
| + PropertyAccess access = node; |
| + if (access.receiver is InterpolatedExpression) { |
| + InterpolatedExpression hole = access.receiver; |
| + return hole.isPositional && hole.nameOrPosition == 0; |
| + } |
| + } |
| + return false; |
| +} |