Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(433)

Side by Side Diff: pkg/compiler/lib/src/resolved_uri_translator.dart

Issue 2675023002: Temporarily allow to import dart:io in client apps. (Closed)
Patch Set: cl comments Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « pkg/compiler/lib/src/apiimpl.dart ('k') | sdk/lib/dart_client.platform » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 import 'common.dart'; 5 import 'common.dart';
6 import 'elements/elements.dart' show LibraryElement; 6 import 'elements/elements.dart' show LibraryElement;
7 import 'util/emptyset.dart'; 7 import 'util/emptyset.dart';
8 8
9 /// API used by the library loader to translate internal SDK URIs into file 9 /// API used by the library loader to translate internal SDK URIs into file
10 /// system readable URIs. 10 /// system readable URIs.
11 abstract class ResolvedUriTranslator { 11 abstract class ResolvedUriTranslator {
12 factory ResolvedUriTranslator( 12 factory ResolvedUriTranslator(
13 Map<String, Uri> sdkLibraries, DiagnosticReporter reporter) = 13 Map<String, Uri> sdkLibraries,
14 _ResolvedUriTranslator; 14 DiagnosticReporter reporter,
15 Uri platformConfigUri) = _ResolvedUriTranslator;
15 16
16 /// The set of platform libraries reported as unsupported. 17 /// The set of platform libraries reported as unsupported.
17 /// 18 ///
18 /// For instance when importing 'dart:io' without '--categories=Server'. 19 /// For instance when importing 'dart:io' without '--categories=Server'.
19 Set<Uri> get disallowedLibraryUris; 20 Set<Uri> get disallowedLibraryUris;
20 21
21 /// Whether or not a mockable library has been translated. 22 /// Whether or not a mockable library has been translated.
22 bool get mockableLibraryUsed; 23 bool get mockableLibraryUsed;
23 24
24 /// A mapping from dart: library names to their location. 25 /// A mapping from dart: library names to their location.
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 @override 70 @override
70 bool get mockableLibraryUsed => resolvedUriTranslator.mockableLibraryUsed; 71 bool get mockableLibraryUsed => resolvedUriTranslator.mockableLibraryUsed;
71 72
72 @override 73 @override
73 Map<String, Uri> get sdkLibraries => resolvedUriTranslator.sdkLibraries; 74 Map<String, Uri> get sdkLibraries => resolvedUriTranslator.sdkLibraries;
74 } 75 }
75 76
76 class _ResolvedUriTranslator implements ResolvedUriTranslator { 77 class _ResolvedUriTranslator implements ResolvedUriTranslator {
77 final Map<String, Uri> _sdkLibraries; 78 final Map<String, Uri> _sdkLibraries;
78 final DiagnosticReporter _reporter; 79 final DiagnosticReporter _reporter;
80 final Uri _platformConfigUri;
79 81
80 Set<Uri> disallowedLibraryUris = new Set<Uri>(); 82 Set<Uri> disallowedLibraryUris = new Set<Uri>();
81 bool mockableLibraryUsed = false; 83 bool mockableLibraryUsed = false;
82 84
83 _ResolvedUriTranslator(this._sdkLibraries, this._reporter); 85 _ResolvedUriTranslator(
86 this._sdkLibraries, this._reporter, this._platformConfigUri);
84 87
85 Map<String, Uri> get sdkLibraries => _sdkLibraries; 88 Map<String, Uri> get sdkLibraries => _sdkLibraries;
86 89
87 @override 90 @override
88 Uri translate(LibraryElement importingLibrary, Uri uri, Spannable spannable) { 91 Uri translate(LibraryElement importingLibrary, Uri uri, Spannable spannable) {
89 if (uri.scheme == 'dart') { 92 if (uri.scheme == 'dart') {
90 return translateDartUri(importingLibrary, uri, spannable); 93 return translateDartUri(importingLibrary, uri, spannable);
91 } 94 }
92 return uri; 95 return uri;
93 } 96 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 } else { 132 } else {
130 _reporter.reportErrorMessage(spannable, MessageKind.INTERNAL_LIBRARY, 133 _reporter.reportErrorMessage(spannable, MessageKind.INTERNAL_LIBRARY,
131 {'resolvedUri': resolvedUri}); 134 {'resolvedUri': resolvedUri});
132 registerDisallowedLibraryUse(resolvedUri); 135 registerDisallowedLibraryUse(resolvedUri);
133 } 136 }
134 return null; 137 return null;
135 } 138 }
136 } 139 }
137 140
138 if (location.scheme == "unsupported") { 141 if (location.scheme == "unsupported") {
139 _reporter.reportErrorMessage(spannable, MessageKind.LIBRARY_NOT_SUPPORTED, 142 if (location.path == "") {
140 {'resolvedUri': resolvedUri}); 143 _reporter.reportErrorMessage(spannable,
141 registerDisallowedLibraryUse(resolvedUri); 144 MessageKind.LIBRARY_NOT_SUPPORTED, {'resolvedUri': resolvedUri});
145 registerDisallowedLibraryUse(resolvedUri);
146 } else {
147 // If the specification includes a path, we treat it as "partially"
148 // unsupported: it is allowed to be imported unconditionally, but we
149 // will not expose it as being supported in the const variable
150 // `dart.library.name`.
151 //
152 // This is a stopgap measure to support packages like `http` that need
153 // to import `dart:io` conditionally. Once config-imports are supported
154 // in the language, we can make it an error again to import it
155 // unconditionally.
156 //
157 // The plaform configuration files contain a URI of the form
158 // `unsupported:path/to/library.dart` to indicate this partially
159 // supported mode. We resolve the path with respect to the configuration
160 // file.
161 return _platformConfigUri.resolve(location.path);
162 }
142 return null; 163 return null;
143 } 164 }
144 165
145 if (resolvedUri.path == 'html' || resolvedUri.path == 'io') { 166 if (resolvedUri.path == 'html' || resolvedUri.path == 'io') {
146 // TODO(ahe): Get rid of mockableLibraryUsed when test.dart 167 // TODO(ahe): Get rid of mockableLibraryUsed when test.dart
147 // supports this use case better. 168 // supports this use case better.
148 mockableLibraryUsed = true; 169 mockableLibraryUsed = true;
149 } 170 }
150 return location; 171 return location;
151 } 172 }
152 173
153 void registerDisallowedLibraryUse(Uri uri) { 174 void registerDisallowedLibraryUse(Uri uri) {
154 disallowedLibraryUris.add(uri); 175 disallowedLibraryUris.add(uri);
155 } 176 }
156 177
157 Uri lookupLibraryUri(String libraryName) { 178 Uri lookupLibraryUri(String libraryName) {
158 return _sdkLibraries[libraryName]; 179 return _sdkLibraries[libraryName];
159 } 180 }
160 } 181 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/apiimpl.dart ('k') | sdk/lib/dart_client.platform » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698