| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 import "package:expect/expect.dart"; | 5 import "package:expect/expect.dart"; |
| 6 import 'dart:async'; | 6 import 'dart:async'; |
| 7 import "package:async_helper/async_helper.dart"; | 7 import "package:async_helper/async_helper.dart"; |
| 8 import 'parser_helper.dart'; | |
| 9 import 'mock_compiler.dart'; | 8 import 'mock_compiler.dart'; |
| 10 import '../../../sdk/lib/_internal/compiler/compiler.dart'; | 9 import '../../../sdk/lib/_internal/compiler/compiler.dart'; |
| 11 import '../../../sdk/lib/_internal/compiler/implementation/dart2jslib.dart' as l
eg; | 10 import '../../../sdk/lib/_internal/compiler/implementation/dart2jslib.dart' as l
eg; |
| 12 import '../../../sdk/lib/_internal/compiler/implementation/dart_backend/dart_bac
kend.dart'; | 11 import '../../../sdk/lib/_internal/compiler/implementation/dart_backend/dart_bac
kend.dart'; |
| 13 import '../../../sdk/lib/_internal/compiler/implementation/elements/elements.dar
t'; | 12 import '../../../sdk/lib/_internal/compiler/implementation/elements/elements.dar
t'; |
| 14 import '../../../sdk/lib/_internal/compiler/implementation/tree/tree.dart'; | 13 import '../../../sdk/lib/_internal/compiler/implementation/tree/tree.dart'; |
| 15 | 14 |
| 16 const coreLib = r''' | 15 const coreLib = r''' |
| 17 library corelib; | 16 library corelib; |
| 18 class Object { | 17 class Object { |
| (...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 444 testDart2Dart('main(){new A().field;}class B{}class A{B field;}'); | 443 testDart2Dart('main(){new A().field;}class B{}class A{B field;}'); |
| 445 } | 444 } |
| 446 | 445 |
| 447 class DynoMap implements Map<Element, ElementAst> { | 446 class DynoMap implements Map<Element, ElementAst> { |
| 448 final compiler; | 447 final compiler; |
| 449 DynoMap(this.compiler); | 448 DynoMap(this.compiler); |
| 450 | 449 |
| 451 get resolvedElements => compiler.enqueuer.resolution.resolvedElements; | 450 get resolvedElements => compiler.enqueuer.resolution.resolvedElements; |
| 452 ElementAst operator[](Element element) => | 451 ElementAst operator[](Element element) => |
| 453 new ElementAst(element.parseNode(compiler), resolvedElements[element]); | 452 new ElementAst(element.parseNode(compiler), resolvedElements[element]); |
| 453 |
| 454 noSuchMethod(Invocation invocation) => throw 'unimplemented method'; |
| 454 } | 455 } |
| 455 | 456 |
| 456 PlaceholderCollector collectPlaceholders(compiler, element) => | 457 PlaceholderCollector collectPlaceholders(compiler, element) => |
| 457 new PlaceholderCollector(compiler, new Set<String>(), new DynoMap(compiler)) | 458 new PlaceholderCollector(compiler, new Set<String>(), new DynoMap(compiler)) |
| 458 ..collect(element); | 459 ..collect(element); |
| 459 | 460 |
| 460 testLocalFunctionPlaceholder() { | 461 testLocalFunctionPlaceholder() { |
| 461 var src = ''' | 462 var src = ''' |
| 462 main() { | 463 main() { |
| 463 function localfoo() {} | 464 function localfoo() {} |
| 464 localfoo(); | 465 localfoo(); |
| 465 } | 466 } |
| 466 '''; | 467 '''; |
| 467 MockCompiler compiler = new MockCompiler(emitJavaScript: false); | 468 MockCompiler compiler = new MockCompiler(emitJavaScript: false); |
| 468 assert(compiler.backend is DartBackend); | 469 assert(compiler.backend is DartBackend); |
| 469 compiler.parseScript(src); | 470 compiler.parseScript(src); |
| 470 FunctionElement mainElement = compiler.mainApp.find(leg.Compiler.MAIN); | 471 FunctionElement mainElement = compiler.mainApp.find(leg.Compiler.MAIN); |
| 471 compiler.processQueue(compiler.enqueuer.resolution, mainElement); | 472 compiler.processQueue(compiler.enqueuer.resolution, mainElement); |
| 472 PlaceholderCollector collector = collectPlaceholders(compiler, mainElement); | 473 PlaceholderCollector collector = collectPlaceholders(compiler, mainElement); |
| 473 FunctionExpression mainNode = mainElement.parseNode(compiler); | 474 FunctionExpression mainNode = mainElement.parseNode(compiler); |
| 474 FunctionExpression fooNode = mainNode.body.statements.nodes.head.function; | 475 Block body = mainNode.body; |
| 476 FunctionDeclaration functionDeclaration = body.statements.nodes.head; |
| 477 FunctionExpression fooNode = functionDeclaration.function; |
| 475 LocalPlaceholder fooPlaceholder = | 478 LocalPlaceholder fooPlaceholder = |
| 476 collector.functionScopes[mainElement].localPlaceholders.first; | 479 collector.functionScopes[mainElement].localPlaceholders.first; |
| 477 Expect.isTrue(fooPlaceholder.nodes.contains(fooNode.name)); | 480 Expect.isTrue(fooPlaceholder.nodes.contains(fooNode.name)); |
| 478 } | 481 } |
| 479 | 482 |
| 480 testTypeVariablesAreRenamed() { | 483 testTypeVariablesAreRenamed() { |
| 481 // Somewhat a hack: we require all the references of the identifier | 484 // Somewhat a hack: we require all the references of the identifier |
| 482 // to be renamed in the same way for the whole library. Hence | 485 // to be renamed in the same way for the whole library. Hence |
| 483 // if we have a class and type variable with the same name, they | 486 // if we have a class and type variable with the same name, they |
| 484 // both should be renamed. | 487 // both should be renamed. |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 736 testStaticAccessIoLib(); | 739 testStaticAccessIoLib(); |
| 737 testLocalFunctionPlaceholder(); | 740 testLocalFunctionPlaceholder(); |
| 738 testMinification(); | 741 testMinification(); |
| 739 testClosureLocalsMinified(); | 742 testClosureLocalsMinified(); |
| 740 testParametersMinified(); | 743 testParametersMinified(); |
| 741 testDeclarationTypePlaceholders(); | 744 testDeclarationTypePlaceholders(); |
| 742 testPlatformLibraryMemberNamesAreFixed(); | 745 testPlatformLibraryMemberNamesAreFixed(); |
| 743 testConflictsWithCoreLib(); | 746 testConflictsWithCoreLib(); |
| 744 testUnresolvedNamedConstructor(); | 747 testUnresolvedNamedConstructor(); |
| 745 } | 748 } |
| OLD | NEW |