OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 fasta.import; | 5 library fasta.import; |
6 | 6 |
7 import 'builder/builder.dart' show Builder, LibraryBuilder, PrefixBuilder; | 7 import 'builder/builder.dart' show Builder, LibraryBuilder, PrefixBuilder; |
8 | 8 |
9 import 'combinator.dart' show Combinator; | 9 import 'combinator.dart' show Combinator; |
10 | 10 |
11 typedef void AddToScope(String name, Builder member); | 11 typedef void AddToScope(String name, Builder member); |
12 | 12 |
13 class Import { | 13 class Import { |
14 /// The library that is importing [imported]; | 14 /// The library that is importing [imported]; |
15 final LibraryBuilder importer; | 15 final LibraryBuilder importer; |
16 | 16 |
17 /// The library being imported. | 17 /// The library being imported. |
18 final LibraryBuilder imported; | 18 final LibraryBuilder imported; |
19 | 19 |
| 20 final bool deferred; |
| 21 |
20 final String prefix; | 22 final String prefix; |
21 | 23 |
22 final List<Combinator> combinators; | 24 final List<Combinator> combinators; |
23 | 25 |
24 final int charOffset; | 26 final int charOffset; |
25 | 27 |
26 final int prefixCharOffset; | 28 final int prefixCharOffset; |
27 | 29 |
28 Import(this.importer, this.imported, this.prefix, this.combinators, | 30 Import(this.importer, this.imported, this.deferred, this.prefix, |
29 this.charOffset, this.prefixCharOffset); | 31 this.combinators, this.charOffset, this.prefixCharOffset); |
30 | 32 |
31 Uri get fileUri => importer.fileUri; | 33 Uri get fileUri => importer.fileUri; |
32 | 34 |
33 void finalizeImports(LibraryBuilder importer) { | 35 void finalizeImports(LibraryBuilder importer) { |
34 AddToScope add; | 36 AddToScope add; |
35 PrefixBuilder prefix; | 37 PrefixBuilder prefix; |
36 if (this.prefix == null) { | 38 if (this.prefix == null) { |
37 add = (String name, Builder member) { | 39 add = (String name, Builder member) { |
38 importer.addToScope(name, member, charOffset, true); | 40 importer.addToScope(name, member, charOffset, true); |
39 }; | 41 }; |
40 } else { | 42 } else { |
41 prefix = new PrefixBuilder(this.prefix, importer, prefixCharOffset); | 43 prefix = |
| 44 new PrefixBuilder(this.prefix, deferred, importer, prefixCharOffset); |
42 add = (String name, Builder member) { | 45 add = (String name, Builder member) { |
43 if (member.isSetter) { | 46 if (member.isSetter) { |
44 prefix.exports.setters[name] = member; | 47 prefix.exports.setters[name] = member; |
45 } else { | 48 } else { |
46 prefix.exports.local[name] = member; | 49 prefix.exports.local[name] = member; |
47 } | 50 } |
48 }; | 51 }; |
49 } | 52 } |
50 imported.exports.forEach((String name, Builder member) { | 53 imported.exports.forEach((String name, Builder member) { |
51 if (combinators != null) { | 54 if (combinators != null) { |
52 for (Combinator combinator in combinators) { | 55 for (Combinator combinator in combinators) { |
53 if (combinator.isShow && !combinator.names.contains(name)) return; | 56 if (combinator.isShow && !combinator.names.contains(name)) return; |
54 if (combinator.isHide && combinator.names.contains(name)) return; | 57 if (combinator.isHide && combinator.names.contains(name)) return; |
55 } | 58 } |
56 } | 59 } |
57 add(name, member); | 60 add(name, member); |
58 }); | 61 }); |
59 if (prefix != null) { | 62 if (prefix != null) { |
60 Builder existing = importer.addBuilder(prefix.name, prefix, charOffset); | 63 Builder existing = importer.addBuilder(prefix.name, prefix, charOffset); |
61 if (existing == prefix) { | 64 if (existing == prefix) { |
62 importer.addToScope(prefix.name, prefix, prefixCharOffset, true); | 65 importer.addToScope(prefix.name, prefix, prefixCharOffset, true); |
63 } | 66 } |
64 } | 67 } |
65 } | 68 } |
66 } | 69 } |
OLD | NEW |