| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 /// Encapsulates how to invoke the analyzer resolver and overrides how it | 5 /// Encapsulates how to invoke the analyzer resolver and overrides how it |
| 6 /// computes types on expressions to use our restricted set of types. | 6 /// computes types on expressions to use our restricted set of types. |
| 7 library dev_compiler.src.checker.resolver; | 7 library dev_compiler.src.checker.resolver; |
| 8 | 8 |
| 9 import 'package:analyzer/analyzer.dart'; | 9 import 'package:analyzer/analyzer.dart'; |
| 10 import 'package:analyzer/src/generated/ast.dart'; | 10 import 'package:analyzer/src/generated/ast.dart'; |
| (...skipping 589 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 600 e.name == 'JS') { | 600 e.name == 'JS') { |
| 601 // Fix types for JS builtin calls. | 601 // Fix types for JS builtin calls. |
| 602 // | 602 // |
| 603 // This code was taken from analyzer. It's not super sophisticated: | 603 // This code was taken from analyzer. It's not super sophisticated: |
| 604 // only looks for the type name in dart:core, so we just copy it here. | 604 // only looks for the type name in dart:core, so we just copy it here. |
| 605 // | 605 // |
| 606 // TODO(jmesserly): we'll likely need something that can handle a wider | 606 // TODO(jmesserly): we'll likely need something that can handle a wider |
| 607 // variety of types, especially when we get to JS interop. | 607 // variety of types, especially when we get to JS interop. |
| 608 var args = node.argumentList.arguments; | 608 var args = node.argumentList.arguments; |
| 609 if (args.isNotEmpty && args.first is SimpleStringLiteral) { | 609 if (args.isNotEmpty && args.first is SimpleStringLiteral) { |
| 610 var coreLib = _typeProvider.objectType.element.library; | 610 var typeStr = args.first.stringValue; |
| 611 var classElem = coreLib.getType(args.first.stringValue); | 611 if (typeStr == '-dynamic') { |
| 612 if (classElem != null) node.staticType = classElem.type; | 612 node.staticType = _typeProvider.bottomType; |
| 613 } else { |
| 614 var coreLib = _typeProvider.objectType.element.library; |
| 615 var classElem = coreLib.getType(typeStr); |
| 616 if (classElem != null) { |
| 617 var type = fillDynamicTypeArgs(classElem.type, _typeProvider); |
| 618 node.staticType = type; |
| 619 } |
| 620 } |
| 613 } | 621 } |
| 614 } | 622 } |
| 615 } | 623 } |
| 616 | 624 |
| 617 void _inferObjectAccess( | 625 void _inferObjectAccess( |
| 618 Expression node, Expression target, SimpleIdentifier id) { | 626 Expression node, Expression target, SimpleIdentifier id) { |
| 619 // Search for Object accesses. | 627 // Search for Object accesses. |
| 620 var name = id.name; | 628 var name = id.name; |
| 621 if (node.staticType.isDynamic && | 629 if (node.staticType.isDynamic && |
| 622 _objectMembers.containsKey(name) && | 630 _objectMembers.containsKey(name) && |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 665 } | 673 } |
| 666 } | 674 } |
| 667 | 675 |
| 668 // Review note: no longer need to override visitFunctionExpression, this is | 676 // Review note: no longer need to override visitFunctionExpression, this is |
| 669 // handled by the analyzer internally. | 677 // handled by the analyzer internally. |
| 670 // TODO(vsm): in visitbinaryExpression: check computeStaticReturnType result? | 678 // TODO(vsm): in visitbinaryExpression: check computeStaticReturnType result? |
| 671 // TODO(vsm): in visitFunctionDeclaration: Should we ever use the expression | 679 // TODO(vsm): in visitFunctionDeclaration: Should we ever use the expression |
| 672 // type in a (...) => expr or just the written type? | 680 // type in a (...) => expr or just the written type? |
| 673 | 681 |
| 674 } | 682 } |
| OLD | NEW |