mirror of
https://github.com/dart-lang/sdk
synced 2024-09-15 22:00:09 +00:00
[CFE] Get fragment from default package - use language version if any
Language versioning specifies that an empty-name-entry in .packages specifies a sort of "default package" that a non-package file should pretend to be a part of "for any purpose where that matters, including choosing the default language level." Change-Id: I16f4b2f5e4d3ca1e82d2189321e2be5c43e3b260 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/112089 Commit-Queue: Jens Johansen <jensj@google.com> Reviewed-by: Johnni Winther <johnniwinther@google.com>
This commit is contained in:
parent
27c8d8b7a8
commit
10e63b7840
2
DEPS
2
DEPS
|
@ -107,7 +107,7 @@ vars = {
|
|||
"mustache_tag" : "5e81b12215566dbe2473b2afd01a8a8aedd56ad9",
|
||||
"oauth2_tag": "1.2.1",
|
||||
"observatory_pub_packages_rev": "0894122173b0f98eb08863a7712e78407d4477bc",
|
||||
"package_config_tag": "1.0.5",
|
||||
"package_config_tag": "2453cd2e78c2db56ee2669ced17ce70dd00bf576", # should be 1.1.0
|
||||
"package_resolver_tag": "1.0.10",
|
||||
"path_tag": "1.6.2",
|
||||
"pedantic_tag": "v1.8.0",
|
||||
|
|
|
@ -58,4 +58,19 @@ class _MockPackages implements Packages {
|
|||
Uri resolve(Uri packageUri, {Uri notFound(Uri packageUri)}) {
|
||||
fail('Unexpected invocation of resolve');
|
||||
}
|
||||
|
||||
@override
|
||||
String get defaultPackageName {
|
||||
fail('Unexpected invocation of defaultPackageName');
|
||||
}
|
||||
|
||||
@override
|
||||
String libraryMetadata(Uri libraryUri, String key) {
|
||||
fail('Unexpected invocation of libraryMetadata');
|
||||
}
|
||||
|
||||
@override
|
||||
String packageMetadata(String packageName, String key) {
|
||||
fail('Unexpected invocation of packageMetadata');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -494,7 +494,8 @@ class ProcessedOptions {
|
|||
if (contents != null) {
|
||||
_packagesUri = file;
|
||||
try {
|
||||
Map<String, Uri> map = package_config.parse(contents, file);
|
||||
Map<String, Uri> map =
|
||||
package_config.parse(contents, file, allowDefaultPackage: true);
|
||||
return new MapPackages(map);
|
||||
} on FormatException catch (e) {
|
||||
report(
|
||||
|
|
|
@ -118,6 +118,9 @@ abstract class Loader {
|
|||
|
||||
default:
|
||||
fileUri = uri;
|
||||
// Check for empty package name entry (redirecting to package name
|
||||
// from which we should get the fragment part).
|
||||
packageFragment = target.uriTranslator?.getDefaultPackageFragment();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -50,6 +50,16 @@ class UriTranslator {
|
|||
return packageBaseUri.fragment;
|
||||
}
|
||||
|
||||
/// Get the fragment for the package specified as the default package, if any.
|
||||
String getDefaultPackageFragment() {
|
||||
Uri emptyPackageRedirect = packages.asMap()[""];
|
||||
if (emptyPackageRedirect == null) return null;
|
||||
String packageName = emptyPackageRedirect.toString();
|
||||
Uri packageBaseUri = packages.asMap()[packageName];
|
||||
if (packageBaseUri == null) return null;
|
||||
return packageBaseUri.fragment;
|
||||
}
|
||||
|
||||
bool isLibrarySupported(String libraryName) {
|
||||
// TODO(sigmund): change this to `?? false` when all backends provide the
|
||||
// `libraries.json` file by default (Issue #32657).
|
||||
|
|
|
@ -9,7 +9,7 @@ environment:
|
|||
sdk: '>=2.2.2 <3.0.0'
|
||||
dependencies:
|
||||
kernel: 0.3.22
|
||||
package_config: '^1.0.1'
|
||||
package_config: '^1.1.0'
|
||||
path: '^1.3.9'
|
||||
yaml: '^2.1.12'
|
||||
dev_dependencies:
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
foo:lib/#dart=2.5.3-dev.2
|
||||
:foo
|
|
@ -0,0 +1,9 @@
|
|||
// Copyright (c) 2019, 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: languageVersion=2.5*/
|
||||
|
||||
foo() {
|
||||
print("Hello from foo!");
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
// Copyright (c) 2019, 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.
|
||||
|
||||
import 'package:foo/foo.dart';
|
||||
|
||||
// Version comes from "default package" in .packages.
|
||||
|
||||
/*library: languageVersion=2.5*/
|
||||
|
||||
main() {
|
||||
foo();
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
# Copyright (c) 2019, 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.
|
||||
|
||||
# Analyzer workaround, see https://github.com/dart-lang/sdk/issues/37513
|
Loading…
Reference in a new issue