| 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; | 7 import 'dart:collection' show HashSet, HashMap; |
| 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 623 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 634 body.add(_overrideField(field)); | 634 body.add(_overrideField(field)); |
| 635 } | 635 } |
| 636 } | 636 } |
| 637 } | 637 } |
| 638 | 638 |
| 639 // Static fields | 639 // Static fields |
| 640 var lazyStatics = <VariableDeclaration>[]; | 640 var lazyStatics = <VariableDeclaration>[]; |
| 641 for (FieldDeclaration member in staticFields) { | 641 for (FieldDeclaration member in staticFields) { |
| 642 for (VariableDeclaration field in member.fields.variables) { | 642 for (VariableDeclaration field in member.fields.variables) { |
| 643 var fieldName = field.name.name; | 643 var fieldName = field.name.name; |
| 644 if (field.isConst || _isFieldInitConstant(field)) { | 644 if ((field.isConst || _isFieldInitConstant(field)) && |
| 645 !JS.invalidStaticFieldName(fieldName)) { |
| 645 var init = _visit(field.initializer); | 646 var init = _visit(field.initializer); |
| 646 if (init == null) init = new JS.LiteralNull(); | 647 if (init == null) init = new JS.LiteralNull(); |
| 647 body.add(js.statement('#.# = #;', [name, fieldName, init])); | 648 body.add(js.statement('#.# = #;', [name, fieldName, init])); |
| 648 } else { | 649 } else { |
| 649 lazyStatics.add(field); | 650 lazyStatics.add(field); |
| 650 } | 651 } |
| 651 } | 652 } |
| 652 } | 653 } |
| 653 var lazy = _emitLazyFields(new JS.Identifier(name), lazyStatics); | 654 var lazy = _emitLazyFields(new JS.Identifier(name), lazyStatics); |
| 654 if (lazy != null) body.add(lazy); | 655 if (lazy != null) body.add(lazy); |
| (...skipping 1701 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2356 /// | 2357 /// |
| 2357 /// Unary minus looks like: `x['unary-']()`. Note that [unary] must be passed | 2358 /// Unary minus looks like: `x['unary-']()`. Note that [unary] must be passed |
| 2358 /// for this transformation to happen, otherwise binary minus is assumed. | 2359 /// for this transformation to happen, otherwise binary minus is assumed. |
| 2359 /// | 2360 /// |
| 2360 /// Equality is a bit special, it is generated via the Dart `equals` runtime | 2361 /// Equality is a bit special, it is generated via the Dart `equals` runtime |
| 2361 /// helper, that checks for null. The user defined method is called '=='. | 2362 /// helper, that checks for null. The user defined method is called '=='. |
| 2362 /// | 2363 /// |
| 2363 JS.Expression _emitMemberName(String name, | 2364 JS.Expression _emitMemberName(String name, |
| 2364 {DartType type, bool unary: false, bool isStatic: false}) { | 2365 {DartType type, bool unary: false, bool isStatic: false}) { |
| 2365 | 2366 |
| 2366 // Static methods skip most of the rename steps. | 2367 // Static members skip the rename steps. |
| 2367 if (isStatic) { | 2368 if (isStatic) return _propertyName(name); |
| 2368 if (JS.invalidStaticMethodName(name)) { | |
| 2369 // Choose an string name. Use an invalid identifier so it won't conflict | |
| 2370 // with any valid member names. | |
| 2371 // TODO(jmesserly): this works around the problem, but I'm pretty sure w
e | |
| 2372 // don't need it, as static methods seemed to work. The only concrete | |
| 2373 // issue we saw was in the defineNamedConstructor helper function. | |
| 2374 name = '$name*'; | |
| 2375 } | |
| 2376 return _propertyName(name); | |
| 2377 } | |
| 2378 | 2369 |
| 2379 if (name.startsWith('_')) { | 2370 if (name.startsWith('_')) { |
| 2380 return _privateNames.putIfAbsent( | 2371 return _privateNames.putIfAbsent( |
| 2381 name, () => _initSymbol(new JS.TemporaryId(name))); | 2372 name, () => _initSymbol(new JS.TemporaryId(name))); |
| 2382 } | 2373 } |
| 2383 | 2374 |
| 2384 // Check for extension method: | 2375 // Check for extension method: |
| 2385 var extLibrary = _findExtensionLibrary(name, type); | 2376 var extLibrary = _findExtensionLibrary(name, type); |
| 2386 | 2377 |
| 2387 if (name == '[]') { | 2378 if (name == '[]') { |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2520 // TODO(jmesserly): validate the library. See issue #135. | 2511 // TODO(jmesserly): validate the library. See issue #135. |
| 2521 bool _isJsNameAnnotation(DartObjectImpl value) => value.type.name == 'JsName'; | 2512 bool _isJsNameAnnotation(DartObjectImpl value) => value.type.name == 'JsName'; |
| 2522 | 2513 |
| 2523 bool _isJsPeerInterface(DartObjectImpl value) => | 2514 bool _isJsPeerInterface(DartObjectImpl value) => |
| 2524 value.type.name == 'JsPeerInterface'; | 2515 value.type.name == 'JsPeerInterface'; |
| 2525 | 2516 |
| 2526 // TODO(jacobr): we would like to do something like the following | 2517 // TODO(jacobr): we would like to do something like the following |
| 2527 // but we don't have summary support yet. | 2518 // but we don't have summary support yet. |
| 2528 // bool _supportJsExtensionMethod(AnnotatedNode node) => | 2519 // bool _supportJsExtensionMethod(AnnotatedNode node) => |
| 2529 // _getAnnotation(node, "SupportJsExtensionMethod") != null; | 2520 // _getAnnotation(node, "SupportJsExtensionMethod") != null; |
| OLD | NEW |