Chromium Code Reviews| Index: lib/src/codegen/js_codegen.dart |
| diff --git a/lib/src/codegen/js_codegen.dart b/lib/src/codegen/js_codegen.dart |
| index ab8d555d827b05ef5f41e18a4824d46e2e50037d..b952719eaf83fd958ce922f14cda57e66bdbf3f6 100644 |
| --- a/lib/src/codegen/js_codegen.dart |
| +++ b/lib/src/codegen/js_codegen.dart |
| @@ -1047,9 +1047,30 @@ class JSCodegenVisitor extends GeneralizingAstVisitor with ConversionVisitor { |
| bool unaryOperationIsPrimitive(DartType t) => typeIsPrimitiveInJS(t); |
| + bool _isNonNullableExpression(Expression expr) { |
|
Jennifer Messerly
2015/03/03 19:14:30
add a TODO that this will go away when we have not
vsm
2015/03/03 19:29:41
Done.
|
| + if (expr is Literal && expr is! NullLiteral) { |
| + return true; |
| + } |
| + if (expr is ParenthesizedExpression) { |
| + return _isNonNullableExpression(expr.expression); |
| + } |
| + DartType type = null; |
| + if (expr is BinaryExpression) { |
| + type = rules.getStaticType(expr.leftOperand); |
| + } else if (expr is PrefixExpression) { |
| + type = rules.getStaticType(expr.operand); |
| + } else if (expr is PostfixExpression) { |
| + type = rules.getStaticType(expr.operand); |
| + } |
| + if (type != null && typeIsPrimitiveInJS(type)) { |
| + return true; |
| + } |
| + return false; |
| + } |
| + |
| JS.Expression notNull(Expression expr) { |
| var type = rules.getStaticType(expr); |
| - if (rules.isNonNullableType(type)) { |
| + if (rules.isNonNullableType(type) || _isNonNullableExpression(expr)) { |
| return _visit(expr); |
| } else { |
| return js.call('dart.notNull(#)', _visit(expr)); |