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 499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
510 | 510 |
511 if (export is TypeDefiningElement || | 511 if (export is TypeDefiningElement || |
512 export is FunctionElement || | 512 export is FunctionElement || |
513 _eagerTopLevelFields.contains(export)) { | 513 _eagerTopLevelFields.contains(export)) { |
514 // classes, typedefs, functions, and eager init fields can be assigned | 514 // classes, typedefs, functions, and eager init fields can be assigned |
515 // directly. | 515 // directly. |
516 // TODO(jmesserly): we don't know about eager init fields from other | 516 // TODO(jmesserly): we don't know about eager init fields from other |
517 // modules we import, so we will never go down this code path for them. | 517 // modules we import, so we will never go down this code path for them. |
518 _moduleItems | 518 _moduleItems |
519 .add(js.statement('#.# = #;', [libraryName, name.selector, name])); | 519 .add(js.statement('#.# = #;', [libraryName, name.selector, name])); |
520 } else { | |
521 // top-level fields, getters, setters need to copy the property | |
522 // descriptor. | |
523 _moduleItems.add(_callHelperStatement( | |
524 'export(#, #, #);', [libraryName, name.receiver, name.selector])); | |
525 } | 520 } |
526 } | 521 } |
527 | 522 |
528 for (var export in exportedNames.definedNames.values) { | 523 // We only need to export main as it is the only method party of the |
529 if (export is PropertyAccessorElement) { | 524 // publicly exposed JS API for a library. |
530 export = (export as PropertyAccessorElement).variable; | 525 // TODO(jacobr): add a library level annotation indicating that all |
531 } | 526 // contents of a library need to be exposed to JS. |
| 527 // https://github.com/dart-lang/sdk/issues/26368 |
532 | 528 |
533 // Don't allow redefining names from this library. | 529 var export = exportedNames.get('main'); |
534 if (currentNames.containsKey(export.name)) continue; | |
535 | 530 |
536 if (export.isSynthetic && export is PropertyInducingElement) { | 531 if (export == null) return; |
537 _emitDeclaration(export.getter); | 532 if (export is PropertyAccessorElement) { |
538 _emitDeclaration(export.setter); | 533 export = (export as PropertyAccessorElement).variable; |
539 } else { | |
540 _emitDeclaration(export); | |
541 } | |
542 if (export is ClassElement && export.typeParameters.isNotEmpty) { | |
543 // Export the generic name as well. | |
544 // TODO(jmesserly): revisit generic classes | |
545 emitExport(export, suffix: r'$'); | |
546 } | |
547 emitExport(export); | |
548 } | 534 } |
| 535 |
| 536 // Don't allow redefining names from this library. |
| 537 if (currentNames.containsKey(export.name)) return; |
| 538 |
| 539 if (export.isSynthetic && export is PropertyInducingElement) { |
| 540 _emitDeclaration(export.getter); |
| 541 _emitDeclaration(export.setter); |
| 542 } else { |
| 543 _emitDeclaration(export); |
| 544 } |
| 545 emitExport(export); |
549 } | 546 } |
550 | 547 |
551 @override | 548 @override |
552 visitAsExpression(AsExpression node) { | 549 visitAsExpression(AsExpression node) { |
553 Expression fromExpr = node.expression; | 550 Expression fromExpr = node.expression; |
554 var from = getStaticType(fromExpr); | 551 var from = getStaticType(fromExpr); |
555 var to = node.type.type; | 552 var to = node.type.type; |
556 | 553 |
557 JS.Expression jsFrom = _visit(fromExpr); | 554 JS.Expression jsFrom = _visit(fromExpr); |
558 if (_inWhitelistCode(node)) return jsFrom; | 555 if (_inWhitelistCode(node)) return jsFrom; |
(...skipping 5037 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5596 var targetIdentifier = target as SimpleIdentifier; | 5593 var targetIdentifier = target as SimpleIdentifier; |
5597 | 5594 |
5598 if (targetIdentifier.staticElement is! PrefixElement) return false; | 5595 if (targetIdentifier.staticElement is! PrefixElement) return false; |
5599 var prefix = targetIdentifier.staticElement as PrefixElement; | 5596 var prefix = targetIdentifier.staticElement as PrefixElement; |
5600 | 5597 |
5601 // The library the prefix is referring to must come from a deferred import. | 5598 // The library the prefix is referring to must come from a deferred import. |
5602 var containingLibrary = (target.root as CompilationUnit).element.library; | 5599 var containingLibrary = (target.root as CompilationUnit).element.library; |
5603 var imports = containingLibrary.getImportsWithPrefix(prefix); | 5600 var imports = containingLibrary.getImportsWithPrefix(prefix); |
5604 return imports.length == 1 && imports[0].isDeferred; | 5601 return imports.length == 1 && imports[0].isDeferred; |
5605 } | 5602 } |
OLD | NEW |