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 library dev_compiler.src.codegen.js_codegen; | 5 library dev_compiler.src.codegen.js_codegen; |
6 | 6 |
7 import 'dart:collection' show HashSet, HashMap, SplayTreeSet; | 7 import 'dart:collection' show HashSet, HashMap, SplayTreeSet; |
8 | 8 |
9 import 'package:analyzer/analyzer.dart' hide ConstantEvaluator; | 9 import 'package:analyzer/analyzer.dart' hide ConstantEvaluator; |
10 import 'package:analyzer/src/generated/ast.dart' hide ConstantEvaluator; | 10 import 'package:analyzer/src/generated/ast.dart' hide ConstantEvaluator; |
(...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
562 /// Emit class members that need to come after the class declaration, such | 562 /// Emit class members that need to come after the class declaration, such |
563 /// as static fields. See [_emitClassMethods] for things that are emitted | 563 /// as static fields. See [_emitClassMethods] for things that are emitted |
564 /// inside the ES6 `class { ... }` node. | 564 /// inside the ES6 `class { ... }` node. |
565 JS.Statement _finishClassMembers(ClassElement classElem, | 565 JS.Statement _finishClassMembers(ClassElement classElem, |
566 JS.ClassExpression cls, List<ConstructorDeclaration> ctors, | 566 JS.ClassExpression cls, List<ConstructorDeclaration> ctors, |
567 List<FieldDeclaration> fields, List<MethodDeclaration> methods, | 567 List<FieldDeclaration> fields, List<MethodDeclaration> methods, |
568 List<Annotation> metadata, String jsPeerName) { | 568 List<Annotation> metadata, String jsPeerName) { |
569 var name = classElem.name; | 569 var name = classElem.name; |
570 var body = <JS.Statement>[]; | 570 var body = <JS.Statement>[]; |
571 | 571 |
572 if (jsPeerName != null) { | 572 if (_extensionTypes.contains(classElem)) { |
573 var dartxNames = []; | 573 var dartxNames = []; |
574 for (var m in methods) { | 574 for (var m in methods) { |
575 if (!m.isAbstract && !m.isStatic && m.element.isPublic) { | 575 if (!m.isAbstract && !m.isStatic && m.element.isPublic) { |
576 dartxNames.add(_elementMemberName(m.element, allowExtensions: false)); | 576 dartxNames.add(_elementMemberName(m.element, allowExtensions: false)); |
577 } | 577 } |
578 } | 578 } |
579 body.add(js.statement('dart.defineExtensionNames(#)', | 579 if (dartxNames.isNotEmpty) { |
580 [new JS.ArrayInitializer(dartxNames, multiline: true)])); | 580 body.add(js.statement('dart.defineExtensionNames(#)', |
| 581 [new JS.ArrayInitializer(dartxNames, multiline: true)])); |
| 582 } |
581 } | 583 } |
582 | 584 |
583 body.add(new JS.ClassDeclaration(cls)); | 585 body.add(new JS.ClassDeclaration(cls)); |
584 | 586 |
585 // TODO(jmesserly): we should really just extend native Array. | 587 // TODO(jmesserly): we should really just extend native Array. |
586 if (jsPeerName != null && classElem.typeParameters.isNotEmpty) { | 588 if (jsPeerName != null && classElem.typeParameters.isNotEmpty) { |
587 body.add(js.statement('dart.setBaseClass(#, dart.global.#);', [ | 589 body.add(js.statement('dart.setBaseClass(#, dart.global.#);', [ |
588 classElem.name, | 590 classElem.name, |
589 _propertyName(jsPeerName) | 591 _propertyName(jsPeerName) |
590 ])); | 592 ])); |
(...skipping 2187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2778 | 2780 |
2779 /// A special kind of element created by the compiler, signifying a temporary | 2781 /// A special kind of element created by the compiler, signifying a temporary |
2780 /// variable. These objects use instance equality, and should be shared | 2782 /// variable. These objects use instance equality, and should be shared |
2781 /// everywhere in the tree where they are treated as the same variable. | 2783 /// everywhere in the tree where they are treated as the same variable. |
2782 class TemporaryVariableElement extends LocalVariableElementImpl { | 2784 class TemporaryVariableElement extends LocalVariableElementImpl { |
2783 TemporaryVariableElement.forNode(Identifier name) : super.forNode(name); | 2785 TemporaryVariableElement.forNode(Identifier name) : super.forNode(name); |
2784 | 2786 |
2785 int get hashCode => identityHashCode(this); | 2787 int get hashCode => identityHashCode(this); |
2786 bool operator ==(Object other) => identical(this, other); | 2788 bool operator ==(Object other) => identical(this, other); |
2787 } | 2789 } |
OLD | NEW |