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 814 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
825 _defineClass(classElem, className, classExpr, isCallable, body); | 825 _defineClass(classElem, className, classExpr, isCallable, body); |
826 | 826 |
827 // Emit things that come after the ES6 `class ... { ... }`. | 827 // Emit things that come after the ES6 `class ... { ... }`. |
828 var jsPeerNames = _getJSPeerNames(classElem); | 828 var jsPeerNames = _getJSPeerNames(classElem); |
829 JS.Statement deferredBaseClass = | 829 JS.Statement deferredBaseClass = |
830 _setBaseClass(classElem, className, jsPeerNames, body); | 830 _setBaseClass(classElem, className, jsPeerNames, body); |
831 | 831 |
832 _emitClassTypeTests(classElem, className, body); | 832 _emitClassTypeTests(classElem, className, body); |
833 | 833 |
834 _defineNamedConstructors(ctors, body, className, isCallableTransitive); | 834 _defineNamedConstructors(ctors, body, className, isCallableTransitive); |
835 _emitVirtualFieldSymbols(className, body); | 835 _emitVirtualFieldSymbols(classElem, body); |
836 _emitClassSignature( | 836 _emitClassSignature( |
837 methods, allFields, classElem, ctors, extensions, className, body); | 837 methods, allFields, classElem, ctors, extensions, className, body); |
838 _defineExtensionMembers(extensions, className, body); | 838 _defineExtensionMembers(extensions, className, body); |
839 _emitClassMetadata(node.metadata, className, body); | 839 _emitClassMetadata(node.metadata, className, body); |
840 | 840 |
841 JS.Statement classDef = _statement(body); | 841 JS.Statement classDef = _statement(body); |
842 | 842 |
843 var typeFormals = classElem.typeParameters; | 843 var typeFormals = classElem.typeParameters; |
844 if (typeFormals.isNotEmpty) { | 844 if (typeFormals.isNotEmpty) { |
845 classDef = _defineClassTypeArguments( | 845 classDef = _defineClassTypeArguments( |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1083 | 1083 |
1084 void _emitSuperHelperSymbols( | 1084 void _emitSuperHelperSymbols( |
1085 List<JS.TemporaryId> superHelperSymbols, List<JS.Statement> body) { | 1085 List<JS.TemporaryId> superHelperSymbols, List<JS.Statement> body) { |
1086 for (var id in superHelperSymbols) { | 1086 for (var id in superHelperSymbols) { |
1087 body.add(js.statement('const # = Symbol(#)', [id, js.string(id.name)])); | 1087 body.add(js.statement('const # = Symbol(#)', [id, js.string(id.name)])); |
1088 } | 1088 } |
1089 superHelperSymbols.clear(); | 1089 superHelperSymbols.clear(); |
1090 } | 1090 } |
1091 | 1091 |
1092 void _emitVirtualFieldSymbols( | 1092 void _emitVirtualFieldSymbols( |
1093 JS.Expression className, List<JS.Statement> body) { | 1093 ClassElement classElement, List<JS.Statement> body) { |
1094 _classProperties.virtualFields.forEach((field, virtualField) { | 1094 _classProperties.virtualFields.forEach((field, virtualField) { |
1095 body.add(js.statement('const # = Symbol(#.name + "." + #.toString());', | 1095 body.add(js.statement('const # = Symbol(#);', |
1096 [virtualField, className, _declareMemberName(field.getter)])); | 1096 [virtualField, js.string('${classElement.name}.${field.name}')])); |
1097 }); | 1097 }); |
1098 } | 1098 } |
1099 | 1099 |
1100 void _defineClass(ClassElement classElem, JS.Expression className, | 1100 void _defineClass(ClassElement classElem, JS.Expression className, |
1101 JS.ClassExpression classExpr, bool isCallable, List<JS.Statement> body) { | 1101 JS.ClassExpression classExpr, bool isCallable, List<JS.Statement> body) { |
1102 JS.Expression callableClass; | 1102 JS.Expression callableClass; |
1103 if (isCallable && classElem.unnamedConstructor != null) { | 1103 if (isCallable && classElem.unnamedConstructor != null) { |
1104 callableClass = | 1104 callableClass = |
1105 _emitCallableClass(classExpr, classElem.unnamedConstructor); | 1105 _emitCallableClass(classExpr, classElem.unnamedConstructor); |
1106 } | 1106 } |
(...skipping 4783 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5890 if (targetIdentifier.staticElement is! PrefixElement) return false; | 5890 if (targetIdentifier.staticElement is! PrefixElement) return false; |
5891 var prefix = targetIdentifier.staticElement as PrefixElement; | 5891 var prefix = targetIdentifier.staticElement as PrefixElement; |
5892 | 5892 |
5893 // The library the prefix is referring to must come from a deferred import. | 5893 // The library the prefix is referring to must come from a deferred import. |
5894 var containingLibrary = resolutionMap | 5894 var containingLibrary = resolutionMap |
5895 .elementDeclaredByCompilationUnit(target.root as CompilationUnit) | 5895 .elementDeclaredByCompilationUnit(target.root as CompilationUnit) |
5896 .library; | 5896 .library; |
5897 var imports = containingLibrary.getImportsWithPrefix(prefix); | 5897 var imports = containingLibrary.getImportsWithPrefix(prefix); |
5898 return imports.length == 1 && imports[0].isDeferred; | 5898 return imports.length == 1 && imports[0].isDeferred; |
5899 } | 5899 } |
OLD | NEW |