| 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 | 2 |
| 3 // for details. All rights reserved. Use of this source code is governed by a | 3 // for details. All rights reserved. Use of this source code is governed by a |
| 4 // BSD-style license that can be found in the LICENSE file. | 4 // BSD-style license that can be found in the LICENSE file. |
| 5 | 5 |
| 6 import 'dart:collection' show HashMap, HashSet; | 6 import 'dart:collection' show HashMap, HashSet; |
| 7 import 'dart:math' show min, max; | 7 import 'dart:math' show min, max; |
| 8 | 8 |
| 9 import 'package:analyzer/analyzer.dart' hide ConstantEvaluator; | 9 import 'package:analyzer/analyzer.dart' hide ConstantEvaluator; |
| 10 import 'package:analyzer/dart/ast/ast.dart'; | 10 import 'package:analyzer/dart/ast/ast.dart'; |
| (...skipping 3854 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3865 | 3865 |
| 3866 JS.Expression _emitInstanceCreationExpression( | 3866 JS.Expression _emitInstanceCreationExpression( |
| 3867 ConstructorElement element, | 3867 ConstructorElement element, |
| 3868 DartType type, | 3868 DartType type, |
| 3869 SimpleIdentifier name, | 3869 SimpleIdentifier name, |
| 3870 ArgumentList argumentList, | 3870 ArgumentList argumentList, |
| 3871 bool isConst) { | 3871 bool isConst) { |
| 3872 JS.Expression emitNew() { | 3872 JS.Expression emitNew() { |
| 3873 JS.Expression ctor; | 3873 JS.Expression ctor; |
| 3874 bool isFactory = false; | 3874 bool isFactory = false; |
| 3875 bool isNative = false; |
| 3875 if (element == null) { | 3876 if (element == null) { |
| 3876 // TODO(jmesserly): this only happens if we had a static error. | 3877 // TODO(jmesserly): this only happens if we had a static error. |
| 3877 // Should we generate a throw instead? | 3878 // Should we generate a throw instead? |
| 3878 ctor = _emitType(type, | 3879 ctor = _emitType(type, |
| 3879 nameType: options.hoistInstanceCreation, | 3880 nameType: options.hoistInstanceCreation, |
| 3880 hoistType: options.hoistInstanceCreation); | 3881 hoistType: options.hoistInstanceCreation); |
| 3881 if (name != null) { | 3882 if (name != null) { |
| 3882 ctor = new JS.PropertyAccess(ctor, _propertyName(name.name)); | 3883 ctor = new JS.PropertyAccess(ctor, _propertyName(name.name)); |
| 3883 } | 3884 } |
| 3884 } else { | 3885 } else { |
| 3885 ctor = _emitConstructorName(element, type, name); | 3886 ctor = _emitConstructorName(element, type, name); |
| 3886 isFactory = element.isFactory; | 3887 isFactory = element.isFactory; |
| 3888 var classElem = element.enclosingElement; |
| 3889 isNative = _isJSNative(classElem); |
| 3887 } | 3890 } |
| 3888 var args = _visit(argumentList) as List<JS.Expression>; | 3891 var args = _visit(argumentList) as List<JS.Expression>; |
| 3889 return isFactory ? new JS.Call(ctor, args) : new JS.New(ctor, args); | 3892 // Native factory constructors are JS constructors - use new here. |
| 3893 return isFactory && !isNative ? new JS.Call(ctor, args) : new JS.New(ctor,
args); |
| 3890 } | 3894 } |
| 3891 | 3895 |
| 3892 if (element != null && _isObjectLiteral(element.enclosingElement)) { | 3896 if (element != null && _isObjectLiteral(element.enclosingElement)) { |
| 3893 return _emitObjectLiteral(argumentList); | 3897 return _emitObjectLiteral(argumentList); |
| 3894 } | 3898 } |
| 3895 if (isConst) return _emitConst(emitNew); | 3899 if (isConst) return _emitConst(emitNew); |
| 3896 return emitNew(); | 3900 return emitNew(); |
| 3897 } | 3901 } |
| 3898 | 3902 |
| 3899 bool _isObjectLiteral(ClassElement classElem) { | 3903 bool _isObjectLiteral(ClassElement classElem) { |
| 3900 return findAnnotation(classElem, isPublicJSAnnotation) != null && | 3904 return findAnnotation(classElem, isPublicJSAnnotation) != null && |
| 3901 findAnnotation(classElem, isJSAnonymousAnnotation) != null; | 3905 findAnnotation(classElem, isJSAnonymousAnnotation) != null; |
| 3902 } | 3906 } |
| 3903 | 3907 |
| 3908 bool _isJSNative(ClassElement classElem) => |
| 3909 findAnnotation(classElem, isPublicJSAnnotation) != null; |
| 3910 |
| 3904 JS.Expression _emitObjectLiteral(ArgumentList argumentList) { | 3911 JS.Expression _emitObjectLiteral(ArgumentList argumentList) { |
| 3905 var args = _visit(argumentList) as List<JS.Expression>; | 3912 var args = _visit(argumentList) as List<JS.Expression>; |
| 3906 if (args.isEmpty) { | 3913 if (args.isEmpty) { |
| 3907 return js.call('{}'); | 3914 return js.call('{}'); |
| 3908 } | 3915 } |
| 3909 assert(args.single is JS.ObjectInitializer); | 3916 assert(args.single is JS.ObjectInitializer); |
| 3910 return args.single; | 3917 return args.single; |
| 3911 } | 3918 } |
| 3912 | 3919 |
| 3913 @override | 3920 @override |
| (...skipping 1573 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5487 } | 5494 } |
| 5488 | 5495 |
| 5489 bool isLibraryPrefix(Expression node) => | 5496 bool isLibraryPrefix(Expression node) => |
| 5490 node is SimpleIdentifier && node.staticElement is PrefixElement; | 5497 node is SimpleIdentifier && node.staticElement is PrefixElement; |
| 5491 | 5498 |
| 5492 LibraryElement _getLibrary(AnalysisContext c, String uri) => | 5499 LibraryElement _getLibrary(AnalysisContext c, String uri) => |
| 5493 c.computeLibraryElement(c.sourceFactory.forUri(uri)); | 5500 c.computeLibraryElement(c.sourceFactory.forUri(uri)); |
| 5494 | 5501 |
| 5495 bool _isDartRuntime(LibraryElement l) => | 5502 bool _isDartRuntime(LibraryElement l) => |
| 5496 l.isInSdk && l.source.uri.toString() == 'dart:_runtime'; | 5503 l.isInSdk && l.source.uri.toString() == 'dart:_runtime'; |
| OLD | NEW |