Files
sdk/pkg/front_end/testcases/dartdevc/conditional_import.dart
T
Johnni Winther 8510f27d37 [cfe] Change encoding of supported dart: libraries
This CL changes the way dart: libraries are considered supported when
used in conditional imports or bool.fromEnvironment constant using
the "dart.library.*" values.

Library nodes now has an isUnsupported flag which is set according to
the "supported" property in the libraries specification. Furthermore
the Target now supplies a DartLibrarySupport interface that allows
targets to override whether dart: libraries are unsupported.

This allows the JIT/AOT to use the same platform file but still
consider dart:mirrors unsupported in AOT mode, and dart2js to consider
the internal library `dart:_dart2js_runtime_metrics` supported.

Furthermore, the internal handling is changed so that condition imports
and bool.fromEnvironments constants are computed through the same logic
for "dart.library.*" values, avoiding the need for passing these values
through the environment.

TEST=pkg/front_end/testcases/general/supported_libraries/main

Closes https://github.com/dart-lang/sdk/issues/48057
Closes https://github.com/dart-lang/sdk/issues/47814
Closes https://github.com/dart-lang/sdk/issues/47243
Closes https://github.com/dart-lang/sdk/issues/32657
Closes https://github.com/dart-lang/sdk/issues/36460

Change-Id: Ie8f8dff99167de64ced51b71d89918bf0f3bbd13
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/227020
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
2022-01-11 14:52:38 +00:00

49 lines
1.5 KiB
Dart

// Copyright (c) 2021, 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.
// All three libraries have an HttpRequest class.
import "conditional_import.dart"
if (dart.library.io) "dart:io"
if (dart.library.html) "dart:html" as a;
// All three libraries have an HttpRequest class.
import "conditional_import.dart"
if (dart.library.html) "dart:html"
if (dart.library.io) "dart:io" as b;
import "conditional_import.dart" if (dart.library.foo) "dart:foo" as c;
class HttpRequest {}
testA(a.HttpRequest request) {
request.certificate; // error (from dart:io)
request.response; // ok (from dart:io and dart:html)
request.readyState; // ok (from dart:html)
request.hashCode; // ok
}
testB(b.HttpRequest request) {
request.certificate; // error (from dart:io)
request.response; // ok (from dart:io and dart:html)
request.readyState; // ok (from dart:html)
request.hashCode; // ok
}
testC(c.HttpRequest request) {
request.certificate; // error
request.response; // error
request.readyState; // error
request.hashCode; // ok
}
void main() {
expect(false, const bool.fromEnvironment("dart.library.io"));
expect(true, const bool.fromEnvironment("dart.library.html"));
expect(false, const bool.fromEnvironment("dart.library.foo"));
}
expect(expected, actual) {
if (expected != actual) throw 'Expected $expected, actual $actual';
}