mirror of
https://github.com/dart-lang/sdk
synced 2024-09-19 20:51:50 +00:00
Allow dart:_wasm to be imported in appropriate packages
Change-Id: I606caf26e387b445662e8af9362e992f228d52c2 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/326727 Reviewed-by: Konstantin Shcheglov <scheglov@google.com> Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
This commit is contained in:
parent
807d1cf47b
commit
044be2ae6e
|
@ -3228,13 +3228,11 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
|
|||
|
||||
/// Check that if the visiting library is not system, then any given library
|
||||
/// should not be SDK internal library. The [importElement] is the
|
||||
/// [LibraryImportElement] retrieved from the node, if the element in the node was
|
||||
/// `null`, then this method is not called
|
||||
///
|
||||
/// See [CompileTimeErrorCode.IMPORT_INTERNAL_LIBRARY].
|
||||
/// [LibraryImportElement] retrieved from the node, if the element in the node
|
||||
/// was `null`, then this method is not called.
|
||||
void _checkForImportInternalLibrary(
|
||||
ImportDirective directive, LibraryImportElement importElement) {
|
||||
if (_isInSystemLibrary) {
|
||||
if (_isInSystemLibrary || _isWasm(importElement)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -5699,6 +5697,23 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
|
|||
return false;
|
||||
}
|
||||
|
||||
/// Return `true` if the [importElement] is the internal library `dart:_wasm`
|
||||
/// and the current library is either `package:js/js.dart` or is in
|
||||
/// `package:ui`.
|
||||
bool _isWasm(LibraryImportElement importElement) {
|
||||
var importedUri = importElement.importedLibrary?.source.uri.toString();
|
||||
if (importedUri != 'dart:_wasm') {
|
||||
return false;
|
||||
}
|
||||
var importingUri = _currentLibrary.source.uri.toString();
|
||||
if (importingUri == 'package:js/js.dart') {
|
||||
return true;
|
||||
} else if (importingUri.startsWith('package:ui/')) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// Checks whether a `final`, `base` or `interface` modifier can be ignored.
|
||||
///
|
||||
/// Checks whether a subclass in the current library
|
||||
|
|
|
@ -1349,6 +1349,10 @@ class Point<T extends num> {}
|
|||
],
|
||||
);
|
||||
|
||||
final MockSdkLibrary _LIB_WASM = MockSdkLibrary('_wasm', [
|
||||
MockSdkLibraryUnit('_wasm/wasm.dart', ''),
|
||||
]);
|
||||
|
||||
final List<MockSdkLibrary> _LIBRARIES = [
|
||||
_LIB_CORE,
|
||||
_LIB_ASYNC,
|
||||
|
@ -1362,6 +1366,7 @@ final List<MockSdkLibrary> _LIBRARIES = [
|
|||
_LIB_HTML_DART2JS,
|
||||
_LIB_INTERCEPTORS,
|
||||
_LIB_INTERNAL,
|
||||
_LIB_WASM,
|
||||
];
|
||||
|
||||
/// Create a reduced approximation of Dart SDK in the [path].
|
||||
|
|
|
@ -28,4 +28,39 @@ import 'dart:_internal';
|
|||
error(WarningCode.UNUSED_IMPORT, 7, 16),
|
||||
]);
|
||||
}
|
||||
|
||||
test_wasm_fromJs() async {
|
||||
var filePath = _inPackage('js');
|
||||
newFile(filePath, '''
|
||||
import 'dart:_wasm';
|
||||
''');
|
||||
await resolveFile2(filePath);
|
||||
assertErrorsInResolvedUnit(result, [
|
||||
error(WarningCode.UNUSED_IMPORT, 7, 12),
|
||||
]);
|
||||
}
|
||||
|
||||
test_wasm_fromUi() async {
|
||||
var filePath = _inPackage('ui');
|
||||
newFile(filePath, '''
|
||||
import 'dart:_wasm';
|
||||
''');
|
||||
await resolveFile2(filePath);
|
||||
assertErrorsInResolvedUnit(result, [
|
||||
error(WarningCode.UNUSED_IMPORT, 7, 12),
|
||||
]);
|
||||
}
|
||||
|
||||
String _inPackage(String packageName) {
|
||||
var packageRoot = '$workspaceRootPath/$packageName';
|
||||
var builder = PackageConfigFileBuilder();
|
||||
builder.add(
|
||||
name: packageName,
|
||||
rootPath: packageRoot,
|
||||
languageVersion: testPackageLanguageVersion,
|
||||
);
|
||||
var path = '$packageRoot/.dart_tool/package_config.json';
|
||||
writePackageConfig(path, builder);
|
||||
return convertPath('$packageRoot/lib/$packageName.dart');
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue