Process handled exports correctly.

This should solve the resolution bug in http://dartbug.com/7069

Review URL: https://codereview.chromium.org//11747010

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@17211 260f80e4-7a28-3924-810f-c04153c831b5
This commit is contained in:
johnniwinther@google.com 2013-01-17 14:29:03 +00:00
parent 7ca573ae90
commit 4299d2c6a2
5 changed files with 102 additions and 1 deletions

View file

@ -528,6 +528,16 @@ class LibraryDependencyNode {
pendingExportSet.addAll(library.getNonPrivateElementsInScope());
}
void registerHandledExports(LibraryElement exportedLibraryElement,
CombinatorFilter filter) {
assert(invariant(library, exportedLibraryElement.exportsHandled));
for (Element exportedElement in exportedLibraryElement.exports) {
if (!filter.exclude(exportedElement)) {
pendingExportSet.add(exportedElement);
}
}
}
/**
* Registers the compute export scope with the node library.
*/
@ -685,12 +695,14 @@ class LibraryDependencyHandler {
LibraryElement loadedLibrary) {
if (tag is Export) {
// [loadedLibrary] is exported by [library].
LibraryDependencyNode exportingNode = nodeMap[library];
if (loadedLibrary.exportsHandled) {
// Export scope already computed on [loadedLibrary].
var combinatorFilter = new CombinatorFilter.fromTag(tag);
exportingNode.registerHandledExports(loadedLibrary, combinatorFilter);
return;
}
LibraryDependencyNode exportedNode = nodeMap[loadedLibrary];
LibraryDependencyNode exportingNode = nodeMap[library];
assert(invariant(loadedLibrary, exportedNode != null,
message: "$loadedLibrary has not been registered"));
assert(invariant(library, exportingNode != null,

View file

@ -144,6 +144,14 @@ class MockCompiler extends Compiler {
objectClass.ensureResolved(this);
}
/**
* Registers the [source] with [uri] making it possible load [source] as a
* library.
*/
void registerSource(Uri uri, String source) {
sourceFiles[uri.toString()] = new MockFile(source);
}
/**
* Used internally to create a library from a source text. The created library
* is fixed to export its top-level declarations.

View file

@ -0,0 +1,53 @@
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
library reexport_handled_test;
import 'dart:uri';
import 'mock_compiler.dart';
import '../../../sdk/lib/_internal/compiler/implementation/elements/elements.dart'
show Element,
LibraryElement;
final exportingLibraryUri = new Uri('exporting.dart');
const String EXPORTING_LIBRARY_SOURCE = '''
library exporting;
var foo;
''';
final reexportingLibraryUri = new Uri('reexporting.dart');
const String REEXPORTING_LIBRARY_SOURCE = '''
library reexporting;
export 'exporting.dart';
''';
void main() {
var compiler = new MockCompiler();
compiler.registerSource(exportingLibraryUri, EXPORTING_LIBRARY_SOURCE);
compiler.registerSource(reexportingLibraryUri, REEXPORTING_LIBRARY_SOURCE);
// Load exporting library before the reexporting library.
var exportingLibrary = compiler.libraryLoader.loadLibrary(
exportingLibraryUri, null, exportingLibraryUri);
Expect.isTrue(exportingLibrary.exportsHandled);
var foo = findInExports(exportingLibrary, 'foo');
Expect.isNotNull(foo);
Expect.isTrue(foo.isField());
// Load reexporting library when exports are handled on the exporting library.
var reexportingLibrary = compiler.libraryLoader.loadLibrary(
reexportingLibraryUri, null, reexportingLibraryUri);
foo = findInExports(reexportingLibrary, 'foo');
Expect.isNotNull(foo);
Expect.isTrue(foo.isField());
}
Element findInExports(LibraryElement library, String name) {
for (var export in library.exports) {
if (export.name.slowToString() == name) {
return export;
}
}
return null;
}

View file

@ -0,0 +1,8 @@
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
library reexport_core_helper;
export 'dart:core';

View file

@ -0,0 +1,20 @@
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Tests that exports are handled for libraries loaded prior to the entry point
// library.
//
// This test uses the fact that dart2js loads dart:core before the
// reexport_core_helper and reexport_core_test libraries and the exports of
// dart:core is therefore computed before the exports of reexport_core_helper.
library reexport_core_test;
import 'reexport_core_helper.dart' as core;
void main() {
var o = new Object();
Expect.isTrue(o is core.Object);
}