| 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 2793 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2804 } | 2804 } |
| 2805 return _callHelper('gbind(#, #)', [simpleId, typeArgs]); | 2805 return _callHelper('gbind(#, #)', [simpleId, typeArgs]); |
| 2806 } | 2806 } |
| 2807 | 2807 |
| 2808 /// Emits a simple identifier, handling implicit `this` as well as | 2808 /// Emits a simple identifier, handling implicit `this` as well as |
| 2809 /// going through the qualified library name if necessary, but *not* handling | 2809 /// going through the qualified library name if necessary, but *not* handling |
| 2810 /// inferred generic function instantiation. | 2810 /// inferred generic function instantiation. |
| 2811 JS.Expression _emitSimpleIdentifier(SimpleIdentifier node) { | 2811 JS.Expression _emitSimpleIdentifier(SimpleIdentifier node) { |
| 2812 var accessor = resolutionMap.staticElementForIdentifier(node); | 2812 var accessor = resolutionMap.staticElementForIdentifier(node); |
| 2813 if (accessor == null) { | 2813 if (accessor == null) { |
| 2814 return js.commentExpression( | 2814 return _callHelper('throw("compile error: unresolved identifier: " + #)', |
| 2815 'Unimplemented unknown name', new JS.Identifier(node.name)); | 2815 js.escapedString(node.name ?? '<null>')); |
| 2816 } | 2816 } |
| 2817 | 2817 |
| 2818 // Get the original declaring element. If we had a property accessor, this | 2818 // Get the original declaring element. If we had a property accessor, this |
| 2819 // indirects back to a (possibly synthetic) field. | 2819 // indirects back to a (possibly synthetic) field. |
| 2820 var element = accessor; | 2820 var element = accessor; |
| 2821 if (accessor is PropertyAccessorElement) element = accessor.variable; | 2821 if (accessor is PropertyAccessorElement) element = accessor.variable; |
| 2822 | 2822 |
| 2823 // type literal | 2823 // type literal |
| 2824 if (element is TypeDefiningElement) { | 2824 if (element is TypeDefiningElement) { |
| 2825 _declareBeforeUse(element); | 2825 _declareBeforeUse(element); |
| (...skipping 1268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4094 ConstructorElement element, | 4094 ConstructorElement element, |
| 4095 DartType type, | 4095 DartType type, |
| 4096 SimpleIdentifier name, | 4096 SimpleIdentifier name, |
| 4097 ArgumentList argumentList, | 4097 ArgumentList argumentList, |
| 4098 bool isConst) { | 4098 bool isConst) { |
| 4099 JS.Expression emitNew() { | 4099 JS.Expression emitNew() { |
| 4100 JS.Expression ctor; | 4100 JS.Expression ctor; |
| 4101 bool isFactory = false; | 4101 bool isFactory = false; |
| 4102 bool isNative = false; | 4102 bool isNative = false; |
| 4103 if (element == null) { | 4103 if (element == null) { |
| 4104 // TODO(jmesserly): this only happens if we had a static error. | 4104 ctor = _callHelper( |
| 4105 // Should we generate a throw instead? | 4105 'throw("compile error: unresolved constructor: " + # + "." + #)', [ |
| 4106 ctor = _emitConstructorAccess(type, | 4106 js.escapedString(type?.name ?? '<null>'), |
| 4107 nameType: options.hoistInstanceCreation, | 4107 js.escapedString(name?.name ?? '<unnamed>') |
| 4108 hoistType: options.hoistInstanceCreation); | 4108 ]); |
| 4109 if (name != null) { | |
| 4110 ctor = new JS.PropertyAccess(ctor, _propertyName(name.name)); | |
| 4111 } | |
| 4112 } else { | 4109 } else { |
| 4113 ctor = _emitConstructorName(element, type, name); | 4110 ctor = _emitConstructorName(element, type, name); |
| 4114 isFactory = element.isFactory; | 4111 isFactory = element.isFactory; |
| 4115 var classElem = element.enclosingElement; | 4112 var classElem = element.enclosingElement; |
| 4116 isNative = _isJSNative(classElem); | 4113 isNative = _isJSNative(classElem); |
| 4117 } | 4114 } |
| 4118 var args = _emitArgumentList(argumentList); | 4115 var args = _emitArgumentList(argumentList); |
| 4119 // Native factory constructors are JS constructors - use new here. | 4116 // Native factory constructors are JS constructors - use new here. |
| 4120 return isFactory && !isNative | 4117 return isFactory && !isNative |
| 4121 ? new JS.Call(ctor, args) | 4118 ? new JS.Call(ctor, args) |
| (...skipping 1869 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5991 if (targetIdentifier.staticElement is! PrefixElement) return false; | 5988 if (targetIdentifier.staticElement is! PrefixElement) return false; |
| 5992 var prefix = targetIdentifier.staticElement as PrefixElement; | 5989 var prefix = targetIdentifier.staticElement as PrefixElement; |
| 5993 | 5990 |
| 5994 // The library the prefix is referring to must come from a deferred import. | 5991 // The library the prefix is referring to must come from a deferred import. |
| 5995 var containingLibrary = resolutionMap | 5992 var containingLibrary = resolutionMap |
| 5996 .elementDeclaredByCompilationUnit(target.root as CompilationUnit) | 5993 .elementDeclaredByCompilationUnit(target.root as CompilationUnit) |
| 5997 .library; | 5994 .library; |
| 5998 var imports = containingLibrary.getImportsWithPrefix(prefix); | 5995 var imports = containingLibrary.getImportsWithPrefix(prefix); |
| 5999 return imports.length == 1 && imports[0].isDeferred; | 5996 return imports.length == 1 && imports[0].isDeferred; |
| 6000 } | 5997 } |
| OLD | NEW |