From 9e1997971e6abb3283567adb5480fbb0fb0cb040 Mon Sep 17 00:00:00 2001 From: Srujan Gaddam Date: Wed, 5 Apr 2023 23:20:15 +0000 Subject: [PATCH] Reland "[pkg:js/dart:js_interop] Move annotations to dart:_js_annotations" This is a reland of commit fbe9c2197221a9aca98ae4aaa766164e8ab12d78 This fixes the issue with the duplicate allowPlatformPrivateLibraryAccess. Original change's description: > [pkg:js/dart:js_interop] Move annotations to dart:_js_annotations > > This moves package:js annotations to the internal library that > Flutter has been using already. This gives us a single location > for all package:js annotations. We also introduce a @JS annotation > in dart:js_interop since we can no longer use dart:_js_annotations > to avoid the breaking change in semantics. > > CoreLibraryReviewExempt: Backend-specific internal library. > Change-Id: I9ca55c807d7d192004a6da99f63a72d598fe4f12 > Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/284760 > Commit-Queue: Srujan Gaddam > Reviewed-by: Samuel Rawlins > Reviewed-by: Johnni Winther > Reviewed-by: Joshua Litt CoreLibraryReviewExempt: Relanding. Change-Id: I40ff2a00682fccbd7dd44a364b5046aaac0f3bac Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/293203 Reviewed-by: Joshua Litt Commit-Queue: Srujan Gaddam Reviewed-by: Johnni Winther Reviewed-by: Samuel Rawlins --- .../lib/src/js_interop.dart | 62 ++++++------- .../transformations/js_util_optimizer.dart | 30 ++----- .../lib/src/dart/element/element.dart | 4 +- pkg/compiler/lib/src/common/elements.dart | 30 +------ pkg/compiler/lib/src/common/names.dart | 3 - pkg/compiler/lib/src/ir/annotations.dart | 18 ++-- .../lib/src/js_backend/native_data.dart | 3 +- .../lib/src/kernel/dart2js_target.dart | 3 +- .../lib/src/kernel/native_basic_data.dart | 6 +- pkg/dart2wasm/lib/js_runtime_generator.dart | 4 +- pkg/dart2wasm/lib/target.dart | 7 +- pkg/dev_compiler/lib/src/kernel/compiler.dart | 7 +- .../lib/src/kernel/js_interop.dart | 41 +++++---- .../lib/src/kernel/kernel_helpers.dart | 5 +- pkg/dev_compiler/lib/src/kernel/target.dart | 3 +- .../inline_class/external.dart.strong.expect | 6 +- .../external.dart.strong.transformed.expect | 6 +- .../inline_class/external.dart.weak.expect | 6 +- .../external.dart.weak.modular.expect | 6 +- .../external.dart.weak.outline.expect | 6 +- .../external.dart.weak.transformed.expect | 6 +- .../inline_class/external.dart.strong.expect | 6 +- .../external.dart.strong.transformed.expect | 6 +- .../inline_class/external.dart.weak.expect | 6 +- .../external.dart.weak.modular.expect | 6 +- .../external.dart.weak.outline.expect | 6 +- .../external.dart.weak.transformed.expect | 6 +- .../main.dart.strong.expect | 10 +-- .../main.dart.strong.transformed.expect | 10 +-- .../main.dart.weak.expect | 10 +-- .../main.dart.weak.outline.expect | 10 +-- .../main.dart.weak.transformed.expect | 10 +-- .../issue46123.dart.strong.expect | 8 +- .../issue46123.dart.strong.transformed.expect | 8 +- .../js_semantics/issue46123.dart.weak.expect | 8 +- .../issue46123.dart.weak.modular.expect | 8 +- .../issue46123.dart.weak.outline.expect | 6 +- .../issue46123.dart.weak.transformed.expect | 8 +- .../issue46123b.dart.strong.expect | 8 +- ...issue46123b.dart.strong.transformed.expect | 8 +- .../js_semantics/issue46123b.dart.weak.expect | 8 +- .../issue46123b.dart.weak.modular.expect | 8 +- .../issue46123b.dart.weak.outline.expect | 6 +- .../issue46123b.dart.weak.transformed.expect | 8 +- .../incremental/js_interop_change.yaml | 9 +- .../js_interop_change.yaml.world.1.expect | 40 +++------ .../js_interop_change.yaml.world.2.expect | 40 +++------ pkg/js/CHANGELOG.md | 1 + pkg/js/lib/js.dart | 86 +------------------ pkg/js/pubspec.yaml | 8 +- .../js_shared/lib/js_interop_patch.dart | 5 +- sdk/lib/js/_js_annotations.dart | 62 ++++++++++++- sdk/lib/js_interop/js_interop.dart | 29 +++++-- .../js/static_interop_test/js_types_test.dart | 6 +- .../factory_stub_test.dart | 2 +- .../static_interop_erasure/type_test.dart | 2 +- .../use_erased_type_members_test.dart | 2 +- tests/web/wasm/js_util_test.dart | 2 +- .../factory_stub_test.dart | 2 +- .../static_interop_erasure/type_test.dart | 2 +- .../use_erased_type_members_test.dart | 2 +- 61 files changed, 337 insertions(+), 403 deletions(-) diff --git a/pkg/_js_interop_checks/lib/src/js_interop.dart b/pkg/_js_interop_checks/lib/src/js_interop.dart index c3be7f194cc..5620e4c1654 100644 --- a/pkg/_js_interop_checks/lib/src/js_interop.dart +++ b/pkg/_js_interop_checks/lib/src/js_interop.dart @@ -5,33 +5,33 @@ import 'package:kernel/kernel.dart'; import 'package:kernel/util/graph.dart' as kernel_graph; -/// Returns true iff the node has an `@JS(...)` annotation from `package:js` or -/// from the internal `dart:_js_annotations`. -bool hasJSInteropAnnotation(Annotatable a) => - a.annotations.any(_isPublicJSAnnotation); - /// Returns true iff the node has an `@JS(...)` annotation from the internal -/// `dart:_js_annotations`. -bool hasInternalJSInteropAnnotation(Annotatable a) => - a.annotations.any(_isInternalJSAnnotation); +/// `dart:_js_annotations` or `dart:js_interop`. +bool hasJSInteropAnnotation(Annotatable a) => + a.annotations.any(_isJSInteropAnnotation); -/// Returns true iff the node has an `@anonymous` annotation from `package:js` -/// or from the internal `dart:_js_annotations`. +/// Returns true iff the node has an `@JS(...)` annotation from +/// `dart:js_interop`. +bool hasDartJSInteropAnnotation(Annotatable a) => + a.annotations.any(_isDartJSInteropAnnotation); + +/// Returns true iff the node has an `@anonymous` annotation from the internal +/// `dart:_js_annotations`. bool hasAnonymousAnnotation(Annotatable a) => a.annotations.any(_isAnonymousAnnotation); -/// Returns true iff the node has an `@staticInterop` annotation from -/// `package:js` or from the internal `dart:_js_annotations`. +/// Returns true iff the node has an `@staticInterop` annotation from the +/// internal `dart:_js_annotations`. bool hasStaticInteropAnnotation(Annotatable a) => a.annotations.any(_isStaticInteropAnnotation); -/// Returns true iff the node has an `@trustTypes` annotation from -/// `package:js` or from the internal `dart:_js_annotations`. +/// Returns true iff the node has an `@trustTypes` annotation from the internal +/// `dart:_js_annotations`. bool hasTrustTypesAnnotation(Annotatable a) => a.annotations.any(_isTrustTypesAnnotation); -/// Returns true iff the node has an `@JSExport(...)` annotation from -/// `package:js` or from the internal `dart:_js_annotations`. +/// Returns true iff the node has an `@JSExport(...)` annotation from the +/// internal `dart:_js_annotations`. bool hasJSExportAnnotation(Annotatable a) => a.annotations.any(_isJSExportAnnotation); @@ -53,7 +53,7 @@ bool hasObjectLiteralAnnotation(Annotatable a) => String getJSName(Annotatable a) { String jsClass = ''; for (var annotation in a.annotations) { - if (_isPublicJSAnnotation(annotation)) { + if (_isJSInteropAnnotation(annotation)) { var jsClasses = stringAnnotationValues(annotation); if (jsClasses.isNotEmpty) { jsClass = jsClasses[0]; @@ -102,31 +102,30 @@ String getJSExportName(Annotatable a) { return jsExportValue; } -final _packageJs = Uri.parse('package:js/js.dart'); final _internalJs = Uri.parse('dart:_js_annotations'); final _jsHelper = Uri.parse('dart:_js_helper'); final _jsInterop = Uri.parse('dart:js_interop'); /// Returns true if [value] is the interop annotation whose class is -/// [annotationClassName] from `package:js` or from `dart:_js_annotations`. +/// [annotationClassName] from `dart:_js_annotations` or `dart:js_interop`. /// -/// If [internalJsOnly] is true, we only check if it's the annotation from -/// `dart:_js_annotations`. +/// If [dartJsInteropOnly] is true, we only check if it's the annotation from +/// `dart:js_interop`. bool _isInteropAnnotation(Expression value, String annotationClassName, - {bool internalJsOnly = false}) { + {bool dartJsInteropOnly = false}) { var c = annotationClass(value); if (c == null || c.name != annotationClassName) return false; var importUri = c.enclosingLibrary.importUri; - if (internalJsOnly) return importUri == _internalJs; - return importUri == _packageJs || importUri == _internalJs; + if (dartJsInteropOnly) return importUri == _jsInterop; + return importUri == _internalJs || importUri == _jsInterop; } -bool _isInternalJSAnnotation(Expression value) => - _isInteropAnnotation(value, 'JS', internalJsOnly: true); - -bool _isPublicJSAnnotation(Expression value) => +bool _isJSInteropAnnotation(Expression value) => _isInteropAnnotation(value, 'JS'); +bool _isDartJSInteropAnnotation(Expression value) => + _isInteropAnnotation(value, 'JS', dartJsInteropOnly: true); + bool _isAnonymousAnnotation(Expression value) => _isInteropAnnotation(value, '_Anonymous'); @@ -160,9 +159,10 @@ bool _isObjectLiteralAnnotation(Expression value) { /// /// For example: /// -/// - `@JS()` would return the "JS" class in "package:js". -/// - `@anonymous` would return the "_Anonymous" class in "package:js". -/// - `@staticInterop` would return the "_StaticInterop" class in "package:js". +/// - `@JS()` would return the "JS" class in "dart:_js_annotations". +/// - `@anonymous` would return the "_Anonymous" class in "dart:_js_annotations". +/// - `@staticInterop` would return the "_StaticInterop" class in +/// "dart:_js_annotations". /// - `@Native` would return the "Native" class in "dart:_js_helper". /// /// This function works regardless of whether the CFE is evaluating constants, diff --git a/pkg/_js_interop_checks/lib/src/transformations/js_util_optimizer.dart b/pkg/_js_interop_checks/lib/src/transformations/js_util_optimizer.dart index fc58818e740..484a88746b3 100644 --- a/pkg/_js_interop_checks/lib/src/transformations/js_util_optimizer.dart +++ b/pkg/_js_interop_checks/lib/src/transformations/js_util_optimizer.dart @@ -11,7 +11,7 @@ import '../js_interop.dart' show getJSName, hasAnonymousAnnotation, - hasInternalJSInteropAnnotation, + hasDartJSInteropAnnotation, hasJSInteropAnnotation, hasNativeAnnotation, hasObjectLiteralAnnotation, @@ -69,11 +69,6 @@ class JsUtilOptimizer extends Transformer { late InlineExtensionIndex _inlineExtensionIndex; - static const Set _existingJsAnnotationsUsers = { - 'dart:_engine', - 'dart:ui' - }; - JsUtilOptimizer(this._coreTypes, ClassHierarchy hierarchy) : _callMethodTarget = _coreTypes.index.getTopLevelProcedure('dart:js_util', 'callMethod'), @@ -233,17 +228,8 @@ class JsUtilOptimizer extends Transformer { if (!node.isInlineClassMember && node.enclosingClass == null && - ((hasInternalJSInteropAnnotation(node) || - hasInternalJSInteropAnnotation(node.enclosingLibrary)) && - !_existingJsAnnotationsUsers - .contains(node.enclosingLibrary.importUri.toString()))) { - // Top-level external member. We only lower top-levels if we're using the - // `dart:_js_annotations`' `@JS` annotation to avoid a breaking change for - // `package:js` users. There are some internal libraries that already use - // this library, so we exclude them here. - // TODO(srujzs): When they're ready to migrate to sound semantics, we - // should remove this exception. - + (hasDartJSInteropAnnotation(node) || + hasDartJSInteropAnnotation(node.enclosingLibrary))) { // If the `@JS` value of the node has any '.'s, we take the entries // before the last '.' to determine the dotted prefix name. var jsName = getJSName(node); @@ -892,24 +878,24 @@ class InlineExtensionIndex { } bool isJSInteropMember(Procedure node) { - if (hasInternalJSInteropAnnotation(node) || - hasInternalJSInteropAnnotation(node.enclosingLibrary) || + if (hasDartJSInteropAnnotation(node) || + hasDartJSInteropAnnotation(node.enclosingLibrary) || (node.enclosingClass != null && - hasInternalJSInteropAnnotation(node.enclosingClass!))) { + hasDartJSInteropAnnotation(node.enclosingClass!))) { return true; } if (node.isExtensionMember) { final annotatable = getExtensionAnnotatable(node.reference); if (annotatable != null) { - return hasInternalJSInteropAnnotation(annotatable); + return hasDartJSInteropAnnotation(annotatable); } } if (node.isInlineClassMember) { final cls = getInlineClass(node.reference); if (cls != null) { - return hasInternalJSInteropAnnotation(cls); + return hasDartJSInteropAnnotation(cls); } } diff --git a/pkg/analyzer/lib/src/dart/element/element.dart b/pkg/analyzer/lib/src/dart/element/element.dart index e4c492f4b95..4a555ae2701 100644 --- a/pkg/analyzer/lib/src/dart/element/element.dart +++ b/pkg/analyzer/lib/src/dart/element/element.dart @@ -2014,8 +2014,8 @@ class ElementAnnotationImpl implements ElementAnnotation { /// The name of the class used to JS annotate an element. static const String _jsClassName = 'JS'; - /// The name of `js` library, used to define JS annotations. - static const String _jsLibName = 'js'; + /// The name of `_js_annotations` library, used to define JS annotations. + static const String _jsLibName = '_js_annotations'; /// The name of `meta` library, used to define analysis annotations. static const String _metaLibName = 'meta'; diff --git a/pkg/compiler/lib/src/common/elements.dart b/pkg/compiler/lib/src/common/elements.dart index b12713785e7..6d094e35a3a 100644 --- a/pkg/compiler/lib/src/common/elements.dart +++ b/pkg/compiler/lib/src/common/elements.dart @@ -143,10 +143,6 @@ abstract class CommonElements { late final LibraryEntity? dartJsUtilLibrary = _env.lookupLibrary(Uris.dart_js_util); - /// The package:js library. - late final LibraryEntity? packageJsLibrary = - _env.lookupLibrary(Uris.package_js); - /// The dart:_js_annotations library. late final LibraryEntity? dartJsAnnotationsLibrary = _env.lookupLibrary(Uris.dart__js_annotations); @@ -1053,35 +1049,17 @@ abstract class CommonElements { class KCommonElements extends CommonElements { KCommonElements(super.dartTypes, super.env); - // From package:js - - late final ClassEntity? jsAnnotationClass1 = - _findClassOrNull(packageJsLibrary, 'JS'); - - late final ClassEntity? jsAnonymousClass1 = - _findClassOrNull(packageJsLibrary, '_Anonymous'); - - // From dart:_js_annotations - - late final ClassEntity? jsAnnotationClass2 = + late final ClassEntity? jsAnnotationClass = _findClassOrNull(dartJsAnnotationsLibrary, 'JS'); - late final ClassEntity? jsAnonymousClass2 = + late final ClassEntity? jsAnonymousClass = _findClassOrNull(dartJsAnnotationsLibrary, '_Anonymous'); /// Returns `true` if [cls] is a @JS() annotation. - /// - /// The class can come from either `package:js` or `dart:_js_annotations`. - bool isJsAnnotationClass(ClassEntity cls) { - return cls == jsAnnotationClass1 || cls == jsAnnotationClass2; - } + bool isJsAnnotationClass(ClassEntity cls) => cls == jsAnnotationClass; /// Returns `true` if [cls] is an @anonymous annotation. - /// - /// The class can come from either `package:js` or `dart:_js_annotations`. - bool isJsAnonymousClass(ClassEntity cls) { - return cls == jsAnonymousClass1 || cls == jsAnonymousClass2; - } + bool isJsAnonymousClass(ClassEntity cls) => cls == jsAnonymousClass; late final ClassEntity pragmaClass = _findClass(coreLibrary, 'pragma'); diff --git a/pkg/compiler/lib/src/common/names.dart b/pkg/compiler/lib/src/common/names.dart index 6a05d788295..9eb29795c34 100644 --- a/pkg/compiler/lib/src/common/names.dart +++ b/pkg/compiler/lib/src/common/names.dart @@ -266,9 +266,6 @@ class Uris { /// The URI for 'dart:js_util'. static final Uri dart_js_util = Uri(scheme: 'dart', path: 'js_util'); - /// The URI for 'package:js'. - static final Uri package_js = Uri(scheme: 'package', path: 'js/js.dart'); - /// The URI for 'dart:_js_annotations'. static final Uri dart__js_annotations = Uri(scheme: 'dart', path: '_js_annotations'); diff --git a/pkg/compiler/lib/src/ir/annotations.dart b/pkg/compiler/lib/src/ir/annotations.dart index e52d0c5dc11..8c4b8ffd026 100644 --- a/pkg/compiler/lib/src/ir/annotations.dart +++ b/pkg/compiler/lib/src/ir/annotations.dart @@ -332,9 +332,13 @@ String? _getReturnsAnnotation(ir.Constant constant) { String? _getJsInteropName(ir.Constant constant) { if (constant is ir.InstanceConstant && constant.classNode.name == 'JS' && - (constant.classNode.enclosingLibrary.importUri == Uris.package_js || + (constant.classNode.enclosingLibrary.importUri == + Uris.dart__js_annotations || + // TODO(srujzs): For now, this allows using `dart:js_interop`'s `@JS` + // for `package:js` classes. In the future, we should either further + // dedup or disallow this. constant.classNode.enclosingLibrary.importUri == - Uris.dart__js_annotations)) { + Uris.dart__js_interop)) { assert(constant.fieldValues.length == 1); ir.Constant fieldValue = constant.fieldValues.values.single; if (fieldValue is ir.NullConstant) { @@ -349,17 +353,15 @@ String? _getJsInteropName(ir.Constant constant) { bool _isAnonymousJsInterop(ir.Constant constant) { return constant is ir.InstanceConstant && constant.classNode.name == '_Anonymous' && - (constant.classNode.enclosingLibrary.importUri == Uris.package_js || - constant.classNode.enclosingLibrary.importUri == - Uris.dart__js_annotations); + constant.classNode.enclosingLibrary.importUri == + Uris.dart__js_annotations; } bool _isStaticInterop(ir.Constant constant) { return constant is ir.InstanceConstant && constant.classNode.name == '_StaticInterop' && - (constant.classNode.enclosingLibrary.importUri == Uris.package_js || - constant.classNode.enclosingLibrary.importUri == - Uris.dart__js_annotations); + constant.classNode.enclosingLibrary.importUri == + Uris.dart__js_annotations; } bool _isJsInteropObjectLiteral(ir.Constant constant) { diff --git a/pkg/compiler/lib/src/js_backend/native_data.dart b/pkg/compiler/lib/src/js_backend/native_data.dart index faccfbce6d6..56af23be1b4 100644 --- a/pkg/compiler/lib/src/js_backend/native_data.dart +++ b/pkg/compiler/lib/src/js_backend/native_data.dart @@ -225,8 +225,9 @@ class NativeBasicData { // consider these valid JS members? if (memberIsIgnorable(node)) return; jsInteropMembers[map.getMember(node)] = name; - if (isJsInteropObjectLiteral) + if (isJsInteropObjectLiteral) { jsInteropObjectLiterals.add(map.getMember(node)); + } }); return NativeBasicData( diff --git a/pkg/compiler/lib/src/kernel/dart2js_target.dart b/pkg/compiler/lib/src/kernel/dart2js_target.dart index feba3447cf4..aaf045a064d 100644 --- a/pkg/compiler/lib/src/kernel/dart2js_target.dart +++ b/pkg/compiler/lib/src/kernel/dart2js_target.dart @@ -129,7 +129,8 @@ class Dart2jsTarget extends Target { super.allowPlatformPrivateLibraryAccess(importer, imported) || maybeEnableNative(importer) || (importer.isScheme('package') && - importer.path.startsWith('dart2js_runtime_metrics/')); + (importer.path.startsWith('dart2js_runtime_metrics/') || + importer.path == 'js/js.dart')); @override bool enableNative(Uri uri) => maybeEnableNative(uri); diff --git a/pkg/compiler/lib/src/kernel/native_basic_data.dart b/pkg/compiler/lib/src/kernel/native_basic_data.dart index 2276e605734..2887162f5ed 100644 --- a/pkg/compiler/lib/src/kernel/native_basic_data.dart +++ b/pkg/compiler/lib/src/kernel/native_basic_data.dart @@ -40,10 +40,8 @@ class KernelAnnotationProcessor { String? annotationName; for (ConstantValue value in metadata) { String? name = readAnnotationName(commonElements.dartTypes, spannable, - value, commonElements.jsAnnotationClass1!, defaultValue: '') ?? - readAnnotationName(commonElements.dartTypes, spannable, value, - commonElements.jsAnnotationClass2!, - defaultValue: ''); + value, commonElements.jsAnnotationClass!, + defaultValue: ''); if (annotationName == null) { annotationName = name; } else if (name != null) { diff --git a/pkg/dart2wasm/lib/js_runtime_generator.dart b/pkg/dart2wasm/lib/js_runtime_generator.dart index 0986daf8f40..5f81356adfa 100644 --- a/pkg/dart2wasm/lib/js_runtime_generator.dart +++ b/pkg/dart2wasm/lib/js_runtime_generator.dart @@ -902,12 +902,12 @@ class JSRuntimeFinalizer { JSRuntimeFinalizer createJSRuntimeFinalizer( Component component, CoreTypes coreTypes, ClassHierarchy classHierarchy) { Set transitiveImportingJSInterop = { - ...?calculateTransitiveImportsOfJsInteropIfUsed( - component, Uri.parse("package:js/js.dart")), ...?calculateTransitiveImportsOfJsInteropIfUsed( component, Uri.parse("dart:_js_annotations")), ...?calculateTransitiveImportsOfJsInteropIfUsed( component, Uri.parse("dart:_js_helper")), + ...?calculateTransitiveImportsOfJsInteropIfUsed( + component, Uri.parse("dart:js_interop")), }; Map jsInteropMethods = {}; jsInteropMethods = _performJSInteropTransformations( diff --git a/pkg/dart2wasm/lib/target.dart b/pkg/dart2wasm/lib/target.dart index 54194cfdbe0..a91718f7acd 100644 --- a/pkg/dart2wasm/lib/target.dart +++ b/pkg/dart2wasm/lib/target.dart @@ -87,7 +87,8 @@ class WasmTarget extends Target { bool allowPlatformPrivateLibraryAccess(Uri importer, Uri imported) => super.allowPlatformPrivateLibraryAccess(importer, imported) || - importer.path.contains('tests/web/wasm'); + importer.path.contains('tests/web/wasm') || + importer.isScheme('package') && importer.path == 'js/js.dart'; void _patchHostEndian(CoreTypes coreTypes) { // Fix Endian.host to be a const field equal to Endian.little instead of @@ -154,9 +155,9 @@ class WasmTarget extends Target { ChangedStructureNotifier? changedStructureNotifier}) { Set transitiveImportingJSInterop = { ...?jsInteropHelper.calculateTransitiveImportsOfJsInteropIfUsed( - component, Uri.parse("package:js/js.dart")), + component, Uri.parse("dart:_js_annotations")), ...?jsInteropHelper.calculateTransitiveImportsOfJsInteropIfUsed( - component, Uri.parse("dart:_js_annotations")) + component, Uri.parse("dart:js_interop")), }; if (transitiveImportingJSInterop.isEmpty) { logger?.call("Skipped JS interop transformations"); diff --git a/pkg/dev_compiler/lib/src/kernel/compiler.dart b/pkg/dev_compiler/lib/src/kernel/compiler.dart index 4b503fe9a78..1bf42d66e6a 100644 --- a/pkg/dev_compiler/lib/src/kernel/compiler.dart +++ b/pkg/dev_compiler/lib/src/kernel/compiler.dart @@ -2833,7 +2833,7 @@ class ProgramCompiler extends ComputeOnceConstantVisitor js_ast.LiteralString? _emitJSInteropExternalStaticMemberName(NamedNode n) { if (!usesJSInterop(n)) return null; if (n is Member && !n.isExternal) return null; - var name = _annotationName(n, isPublicJSAnnotation) ?? getTopLevelName(n); + var name = _annotationName(n, isJSInteropAnnotation) ?? getTopLevelName(n); assert(!name.contains('.'), 'JS interop checker rejects dotted names on static class members'); return js.escapedString(name, "'"); @@ -2909,8 +2909,9 @@ class ProgramCompiler extends ComputeOnceConstantVisitor String? _jsNameWithoutGlobal(NamedNode n) { if (!usesJSInterop(n)) return null; - var libraryJSName = _annotationName(getLibrary(n), isPublicJSAnnotation); - var jsName = _annotationName(n, isPublicJSAnnotation) ?? getTopLevelName(n); + var libraryJSName = _annotationName(getLibrary(n), isJSInteropAnnotation); + var jsName = + _annotationName(n, isJSInteropAnnotation) ?? getTopLevelName(n); return libraryJSName != null ? '$libraryJSName.$jsName' : jsName; } diff --git a/pkg/dev_compiler/lib/src/kernel/js_interop.dart b/pkg/dev_compiler/lib/src/kernel/js_interop.dart index a9663a53c83..e0172a48f85 100644 --- a/pkg/dev_compiler/lib/src/kernel/js_interop.dart +++ b/pkg/dev_compiler/lib/src/kernel/js_interop.dart @@ -7,7 +7,7 @@ import 'package:kernel/kernel.dart'; import 'kernel_helpers.dart'; /// Returns true if [library] is one of the [candidates]. -/// The latter should be a list, e.g.,: ['dart:js', 'package:js']. +/// The latter should be a list, e.g.,: ['dart:js', 'dart:_js_annotations']. bool _isLibrary(Library library, List candidates) { var uri = library.importUri; var scheme = uri.scheme; @@ -21,13 +21,17 @@ bool _isLibrary(Library library, List candidates) { return false; } -/// Returns true if [library] represents any library from `package:js` or is the -/// internal `dart:_js_helper` library. +/// Returns true if [library] represents any library from +/// `dart:_foreign_helper`, `dart:_js_annotations`, `dart:_js_helper`, or +/// `dart:js_interop`. bool _isJSLibrary(Library library) => _isLibrary(library, [ - 'package:js', - 'dart:_js_helper', 'dart:_foreign_helper', - 'dart:_js_annotations' + 'dart:_js_annotations', + 'dart:_js_helper', + // TODO(srujzs): For now, this allows using `dart:js_interop`'s `@JS` for + // `package:js` classes. In the future, we should either further dedup or + // disallow this. + 'dart:js_interop', ]); /// Whether [node] is a direct call to `allowInterop`. @@ -67,8 +71,9 @@ bool isJsRestAnnotation(Expression value) => bool isJSAnnotation(Expression value) => _annotationIsFromJSLibrary('JS', value) || isJSName(value); -/// Returns [true] if [value] is the `JS` annotation from `package:js`. -bool isPublicJSAnnotation(Expression value) => +/// Returns [true] if [value] is the `JS` annotation from +/// `dart:_js_annotations` or `dart:js_interop`. +bool isJSInteropAnnotation(Expression value) => _annotationIsFromJSLibrary('JS', value); bool _isJSAnonymousAnnotation(Expression value) => @@ -78,7 +83,7 @@ bool _isStaticInteropAnnotation(Expression value) => _annotationIsFromJSLibrary('_StaticInterop', value); /// Whether [value] is a `@JSExportName` (internal annotation used in SDK -/// instead of `@JS` from `package:js`). +/// instead of `@JS` from `dart:_js_annotations`). bool isJSExportNameAnnotation(Expression value) => isBuiltinAnnotation(value, '_foreign_helper', 'JSExportName'); @@ -125,18 +130,20 @@ bool isObjectLiteralAnnotation(Expression value) { bool hasObjectLiteralAnnotation(Annotatable a) => a.annotations.any(isObjectLiteralAnnotation); -/// Returns true iff the class has an `@JS(...)` annotation from `package:js`. +/// Returns true iff the class has an `@JS(...)` annotation from +/// `dart:_js_annotations` or `dart:js_interop`. /// -/// Note: usually [_usesJSInterop] should be used instead of this. +/// Note: usually [usesJSInterop] should be used instead of this. // // TODO(jmesserly): I think almost all uses of this should be replaced with -// [_usesJSInterop], which also checks that the library is marked with `@JS`. +// [usesJSInterop], which also checks that the library is marked with `@JS`. // // Right now we have inconsistencies: sometimes we'll respect `@JS` on the // class itself, other places we require it on the library. Also members are // inconsistent: sometimes they need to have `@JS` on them, other times they // need to be `external` in an `@JS` class. -bool hasJSInteropAnnotation(Class c) => c.annotations.any(isPublicJSAnnotation); +bool hasJSInteropAnnotation(Class c) => + c.annotations.any(isJSInteropAnnotation); /// Returns true iff this element is a JS interop member. /// @@ -147,11 +154,11 @@ bool hasJSInteropAnnotation(Class c) => c.annotations.any(isPublicJSAnnotation); /// the class or library. bool usesJSInterop(NamedNode n) { if (n is Member && n.isExternal) { - return n.enclosingLibrary.annotations.any(isPublicJSAnnotation) || - n.annotations.any(isPublicJSAnnotation) || - (n.enclosingClass?.annotations.any(isPublicJSAnnotation) ?? false); + return n.enclosingLibrary.annotations.any(isJSInteropAnnotation) || + n.annotations.any(isJSInteropAnnotation) || + (n.enclosingClass?.annotations.any(isJSInteropAnnotation) ?? false); } else if (n is Class) { - return n.annotations.any(isPublicJSAnnotation); + return n.annotations.any(isJSInteropAnnotation); } return false; } diff --git a/pkg/dev_compiler/lib/src/kernel/kernel_helpers.dart b/pkg/dev_compiler/lib/src/kernel/kernel_helpers.dart index 39026d47327..3182a207d64 100644 --- a/pkg/dev_compiler/lib/src/kernel/kernel_helpers.dart +++ b/pkg/dev_compiler/lib/src/kernel/kernel_helpers.dart @@ -101,8 +101,9 @@ bool isBuiltinAnnotation( /// /// For example: /// -/// - `@JS()` would return the "JS" class in "package:js". -/// - `@anonymous` would return the "_Anonymous" class in "package:js". +/// - `@JS()` would return the "JS" class in "dart:_js_annotations". +/// - `@anonymous` would return the "_Anonymous" class in +/// "dart:_js_annotations". /// /// This function works regardless of whether the CFE is evaluating constants, /// or whether the constant is a field reference (such as "anonymous" above). diff --git a/pkg/dev_compiler/lib/src/kernel/target.dart b/pkg/dev_compiler/lib/src/kernel/target.dart index f3dd50dee05..7dd162c4612 100644 --- a/pkg/dev_compiler/lib/src/kernel/target.dart +++ b/pkg/dev_compiler/lib/src/kernel/target.dart @@ -145,7 +145,8 @@ class DevCompilerTarget extends Target { super.allowPlatformPrivateLibraryAccess(importer, imported) || _allowedTestLibrary(importer) || (importer.isScheme('package') && - importer.path.startsWith('dart2js_runtime_metrics/')); + (importer.path.startsWith('dart2js_runtime_metrics/') || + importer.path == 'js/js.dart')); @override bool get nativeExtensionExpectsString => false; diff --git a/pkg/front_end/testcases/dart2js/inline_class/external.dart.strong.expect b/pkg/front_end/testcases/dart2js/inline_class/external.dart.strong.expect index d445d8138a5..4f4c762d31d 100644 --- a/pkg/front_end/testcases/dart2js/inline_class/external.dart.strong.expect +++ b/pkg/front_end/testcases/dart2js/inline_class/external.dart.strong.expect @@ -1,7 +1,7 @@ @#C2 library static_interop /*isNonNullableByDefault*/; import self as self; -import "package:js/js.dart" as js; +import "dart:_js_annotations" as _js; import "dart:core" as core; import "package:js/js.dart"; @@ -79,7 +79,7 @@ static method method(self::A a) → void { constants { #C1 = null - #C2 = js::JS {name:#C1} + #C2 = _js::JS {name:#C1} #C3 = static-tearoff self::B|staticMethod #C4 = static-tearoff self::B|staticGenericMethod #C5 = instantiation #C4 @@ -88,5 +88,5 @@ constants { Constructor coverage from constants: org-dartlang-testcase:///external.dart: -- JS. (from org-dartlang-testcase-sdk:///pkg/js/lib/js.dart:23:9) +- JS. (from org-dartlang-sdk:///lib/js/_js_annotations.dart) - Object. (from org-dartlang-sdk:///lib/core/object.dart) diff --git a/pkg/front_end/testcases/dart2js/inline_class/external.dart.strong.transformed.expect b/pkg/front_end/testcases/dart2js/inline_class/external.dart.strong.transformed.expect index 0b3b191d260..1ba02506c1b 100644 --- a/pkg/front_end/testcases/dart2js/inline_class/external.dart.strong.transformed.expect +++ b/pkg/front_end/testcases/dart2js/inline_class/external.dart.strong.transformed.expect @@ -1,7 +1,7 @@ @#C2 library static_interop /*isNonNullableByDefault*/; import self as self; -import "package:js/js.dart" as js; +import "dart:_js_annotations" as _js; import "dart:core" as core; import "dart:js_util" as js_; @@ -94,7 +94,7 @@ static method method(self::A a) → void { constants { #C1 = null - #C2 = js::JS {name:#C1} + #C2 = _js::JS {name:#C1} #C3 = static-tearoff self::B|staticMethod #C4 = static-tearoff self::B|staticGenericMethod #C5 = instantiation #C4 @@ -103,5 +103,5 @@ constants { Constructor coverage from constants: org-dartlang-testcase:///external.dart: -- JS. (from org-dartlang-testcase-sdk:///pkg/js/lib/js.dart:23:9) +- JS. (from org-dartlang-sdk:///lib/js/_js_annotations.dart) - Object. (from org-dartlang-sdk:///lib/core/object.dart) diff --git a/pkg/front_end/testcases/dart2js/inline_class/external.dart.weak.expect b/pkg/front_end/testcases/dart2js/inline_class/external.dart.weak.expect index f620a4848d7..9a283a7080d 100644 --- a/pkg/front_end/testcases/dart2js/inline_class/external.dart.weak.expect +++ b/pkg/front_end/testcases/dart2js/inline_class/external.dart.weak.expect @@ -1,7 +1,7 @@ @#C2 library static_interop /*isNonNullableByDefault*/; import self as self; -import "package:js/js.dart" as js; +import "dart:_js_annotations" as _js; import "dart:core" as core; import "package:js/js.dart"; @@ -79,7 +79,7 @@ static method method(self::A a) → void { constants { #C1 = null - #C2 = js::JS {name:#C1} + #C2 = _js::JS {name:#C1} #C3 = static-tearoff self::B|staticMethod #C4 = static-tearoff self::B|staticGenericMethod #C5 = instantiation #C4 @@ -88,5 +88,5 @@ constants { Constructor coverage from constants: org-dartlang-testcase:///external.dart: -- JS. (from org-dartlang-testcase-sdk:///pkg/js/lib/js.dart:23:9) +- JS. (from org-dartlang-sdk:///lib/js/_js_annotations.dart) - Object. (from org-dartlang-sdk:///lib/core/object.dart) diff --git a/pkg/front_end/testcases/dart2js/inline_class/external.dart.weak.modular.expect b/pkg/front_end/testcases/dart2js/inline_class/external.dart.weak.modular.expect index f620a4848d7..9a283a7080d 100644 --- a/pkg/front_end/testcases/dart2js/inline_class/external.dart.weak.modular.expect +++ b/pkg/front_end/testcases/dart2js/inline_class/external.dart.weak.modular.expect @@ -1,7 +1,7 @@ @#C2 library static_interop /*isNonNullableByDefault*/; import self as self; -import "package:js/js.dart" as js; +import "dart:_js_annotations" as _js; import "dart:core" as core; import "package:js/js.dart"; @@ -79,7 +79,7 @@ static method method(self::A a) → void { constants { #C1 = null - #C2 = js::JS {name:#C1} + #C2 = _js::JS {name:#C1} #C3 = static-tearoff self::B|staticMethod #C4 = static-tearoff self::B|staticGenericMethod #C5 = instantiation #C4 @@ -88,5 +88,5 @@ constants { Constructor coverage from constants: org-dartlang-testcase:///external.dart: -- JS. (from org-dartlang-testcase-sdk:///pkg/js/lib/js.dart:23:9) +- JS. (from org-dartlang-sdk:///lib/js/_js_annotations.dart) - Object. (from org-dartlang-sdk:///lib/core/object.dart) diff --git a/pkg/front_end/testcases/dart2js/inline_class/external.dart.weak.outline.expect b/pkg/front_end/testcases/dart2js/inline_class/external.dart.weak.outline.expect index e5052600441..d79dda29819 100644 --- a/pkg/front_end/testcases/dart2js/inline_class/external.dart.weak.outline.expect +++ b/pkg/front_end/testcases/dart2js/inline_class/external.dart.weak.outline.expect @@ -1,7 +1,7 @@ -@js::JS::•() +@_js_annotations::JS::•() library static_interop /*isNonNullableByDefault*/; import self as self; -import "package:js/js.dart" as js; +import "dart:_js_annotations" as _js; import "dart:core" as core; import "package:js/js.dart"; @@ -10,7 +10,7 @@ abstract class A extends core::Object { synthetic constructor •() → self::A ; } -@js::JS::•() +@_js::JS::•() inline class B /* declaredRepresentationType = self::A */ { get field = self::B|get#field; set field = self::B|set#field; diff --git a/pkg/front_end/testcases/dart2js/inline_class/external.dart.weak.transformed.expect b/pkg/front_end/testcases/dart2js/inline_class/external.dart.weak.transformed.expect index afecb082f0c..a02f5d2a73e 100644 --- a/pkg/front_end/testcases/dart2js/inline_class/external.dart.weak.transformed.expect +++ b/pkg/front_end/testcases/dart2js/inline_class/external.dart.weak.transformed.expect @@ -1,7 +1,7 @@ @#C2 library static_interop /*isNonNullableByDefault*/; import self as self; -import "package:js/js.dart" as js; +import "dart:_js_annotations" as _js; import "dart:core" as core; import "dart:js_util" as js_; @@ -94,7 +94,7 @@ static method method(self::A a) → void { constants { #C1 = null - #C2 = js::JS {name:#C1} + #C2 = _js::JS {name:#C1} #C3 = static-tearoff self::B|staticMethod #C4 = static-tearoff self::B|staticGenericMethod #C5 = instantiation #C4 @@ -103,5 +103,5 @@ constants { Constructor coverage from constants: org-dartlang-testcase:///external.dart: -- JS. (from org-dartlang-testcase-sdk:///pkg/js/lib/js.dart:23:9) +- JS. (from org-dartlang-sdk:///lib/js/_js_annotations.dart) - Object. (from org-dartlang-sdk:///lib/core/object.dart) diff --git a/pkg/front_end/testcases/dartdevc/inline_class/external.dart.strong.expect b/pkg/front_end/testcases/dartdevc/inline_class/external.dart.strong.expect index d445d8138a5..4f4c762d31d 100644 --- a/pkg/front_end/testcases/dartdevc/inline_class/external.dart.strong.expect +++ b/pkg/front_end/testcases/dartdevc/inline_class/external.dart.strong.expect @@ -1,7 +1,7 @@ @#C2 library static_interop /*isNonNullableByDefault*/; import self as self; -import "package:js/js.dart" as js; +import "dart:_js_annotations" as _js; import "dart:core" as core; import "package:js/js.dart"; @@ -79,7 +79,7 @@ static method method(self::A a) → void { constants { #C1 = null - #C2 = js::JS {name:#C1} + #C2 = _js::JS {name:#C1} #C3 = static-tearoff self::B|staticMethod #C4 = static-tearoff self::B|staticGenericMethod #C5 = instantiation #C4 @@ -88,5 +88,5 @@ constants { Constructor coverage from constants: org-dartlang-testcase:///external.dart: -- JS. (from org-dartlang-testcase-sdk:///pkg/js/lib/js.dart:23:9) +- JS. (from org-dartlang-sdk:///lib/js/_js_annotations.dart) - Object. (from org-dartlang-sdk:///lib/core/object.dart) diff --git a/pkg/front_end/testcases/dartdevc/inline_class/external.dart.strong.transformed.expect b/pkg/front_end/testcases/dartdevc/inline_class/external.dart.strong.transformed.expect index 0b3b191d260..1ba02506c1b 100644 --- a/pkg/front_end/testcases/dartdevc/inline_class/external.dart.strong.transformed.expect +++ b/pkg/front_end/testcases/dartdevc/inline_class/external.dart.strong.transformed.expect @@ -1,7 +1,7 @@ @#C2 library static_interop /*isNonNullableByDefault*/; import self as self; -import "package:js/js.dart" as js; +import "dart:_js_annotations" as _js; import "dart:core" as core; import "dart:js_util" as js_; @@ -94,7 +94,7 @@ static method method(self::A a) → void { constants { #C1 = null - #C2 = js::JS {name:#C1} + #C2 = _js::JS {name:#C1} #C3 = static-tearoff self::B|staticMethod #C4 = static-tearoff self::B|staticGenericMethod #C5 = instantiation #C4 @@ -103,5 +103,5 @@ constants { Constructor coverage from constants: org-dartlang-testcase:///external.dart: -- JS. (from org-dartlang-testcase-sdk:///pkg/js/lib/js.dart:23:9) +- JS. (from org-dartlang-sdk:///lib/js/_js_annotations.dart) - Object. (from org-dartlang-sdk:///lib/core/object.dart) diff --git a/pkg/front_end/testcases/dartdevc/inline_class/external.dart.weak.expect b/pkg/front_end/testcases/dartdevc/inline_class/external.dart.weak.expect index f620a4848d7..9a283a7080d 100644 --- a/pkg/front_end/testcases/dartdevc/inline_class/external.dart.weak.expect +++ b/pkg/front_end/testcases/dartdevc/inline_class/external.dart.weak.expect @@ -1,7 +1,7 @@ @#C2 library static_interop /*isNonNullableByDefault*/; import self as self; -import "package:js/js.dart" as js; +import "dart:_js_annotations" as _js; import "dart:core" as core; import "package:js/js.dart"; @@ -79,7 +79,7 @@ static method method(self::A a) → void { constants { #C1 = null - #C2 = js::JS {name:#C1} + #C2 = _js::JS {name:#C1} #C3 = static-tearoff self::B|staticMethod #C4 = static-tearoff self::B|staticGenericMethod #C5 = instantiation #C4 @@ -88,5 +88,5 @@ constants { Constructor coverage from constants: org-dartlang-testcase:///external.dart: -- JS. (from org-dartlang-testcase-sdk:///pkg/js/lib/js.dart:23:9) +- JS. (from org-dartlang-sdk:///lib/js/_js_annotations.dart) - Object. (from org-dartlang-sdk:///lib/core/object.dart) diff --git a/pkg/front_end/testcases/dartdevc/inline_class/external.dart.weak.modular.expect b/pkg/front_end/testcases/dartdevc/inline_class/external.dart.weak.modular.expect index f620a4848d7..9a283a7080d 100644 --- a/pkg/front_end/testcases/dartdevc/inline_class/external.dart.weak.modular.expect +++ b/pkg/front_end/testcases/dartdevc/inline_class/external.dart.weak.modular.expect @@ -1,7 +1,7 @@ @#C2 library static_interop /*isNonNullableByDefault*/; import self as self; -import "package:js/js.dart" as js; +import "dart:_js_annotations" as _js; import "dart:core" as core; import "package:js/js.dart"; @@ -79,7 +79,7 @@ static method method(self::A a) → void { constants { #C1 = null - #C2 = js::JS {name:#C1} + #C2 = _js::JS {name:#C1} #C3 = static-tearoff self::B|staticMethod #C4 = static-tearoff self::B|staticGenericMethod #C5 = instantiation #C4 @@ -88,5 +88,5 @@ constants { Constructor coverage from constants: org-dartlang-testcase:///external.dart: -- JS. (from org-dartlang-testcase-sdk:///pkg/js/lib/js.dart:23:9) +- JS. (from org-dartlang-sdk:///lib/js/_js_annotations.dart) - Object. (from org-dartlang-sdk:///lib/core/object.dart) diff --git a/pkg/front_end/testcases/dartdevc/inline_class/external.dart.weak.outline.expect b/pkg/front_end/testcases/dartdevc/inline_class/external.dart.weak.outline.expect index a0ccff27e70..159e93baff7 100644 --- a/pkg/front_end/testcases/dartdevc/inline_class/external.dart.weak.outline.expect +++ b/pkg/front_end/testcases/dartdevc/inline_class/external.dart.weak.outline.expect @@ -1,7 +1,7 @@ -@js::JS::•() +@_js_annotations::JS::•() library static_interop /*isNonNullableByDefault*/; import self as self; -import "package:js/js.dart" as js; +import "dart:_js_annotations" as _js; import "dart:core" as core; import "package:js/js.dart"; @@ -10,7 +10,7 @@ abstract class A extends core::Object { synthetic constructor •() → self::A ; } -@js::JS::•() +@_js::JS::•() inline class B /* declaredRepresentationType = self::A */ { get field = self::B|get#field; set field = self::B|set#field; diff --git a/pkg/front_end/testcases/dartdevc/inline_class/external.dart.weak.transformed.expect b/pkg/front_end/testcases/dartdevc/inline_class/external.dart.weak.transformed.expect index afecb082f0c..a02f5d2a73e 100644 --- a/pkg/front_end/testcases/dartdevc/inline_class/external.dart.weak.transformed.expect +++ b/pkg/front_end/testcases/dartdevc/inline_class/external.dart.weak.transformed.expect @@ -1,7 +1,7 @@ @#C2 library static_interop /*isNonNullableByDefault*/; import self as self; -import "package:js/js.dart" as js; +import "dart:_js_annotations" as _js; import "dart:core" as core; import "dart:js_util" as js_; @@ -94,7 +94,7 @@ static method method(self::A a) → void { constants { #C1 = null - #C2 = js::JS {name:#C1} + #C2 = _js::JS {name:#C1} #C3 = static-tearoff self::B|staticMethod #C4 = static-tearoff self::B|staticGenericMethod #C5 = instantiation #C4 @@ -103,5 +103,5 @@ constants { Constructor coverage from constants: org-dartlang-testcase:///external.dart: -- JS. (from org-dartlang-testcase-sdk:///pkg/js/lib/js.dart:23:9) +- JS. (from org-dartlang-sdk:///lib/js/_js_annotations.dart) - Object. (from org-dartlang-sdk:///lib/core/object.dart) diff --git a/pkg/front_end/testcases/dartdevc/static_interop_erasure/main.dart.strong.expect b/pkg/front_end/testcases/dartdevc/static_interop_erasure/main.dart.strong.expect index 8eff89218ca..c1d8d97f036 100644 --- a/pkg/front_end/testcases/dartdevc/static_interop_erasure/main.dart.strong.expect +++ b/pkg/front_end/testcases/dartdevc/static_interop_erasure/main.dart.strong.expect @@ -12,7 +12,7 @@ static method main() → void { @#C2 library static_interop /*isNonNullableByDefault*/; import self as sta; -import "package:js/js.dart" as js; +import "dart:_js_annotations" as _js; import "dart:core" as core; import "dart:js_util" as js_; @@ -39,14 +39,14 @@ static method setUp() → void { constants { #C1 = null - #C2 = js::JS {name:#C1} + #C2 = _js::JS {name:#C1} #C3 = "JSClass" - #C4 = js::JS {name:#C3} - #C5 = js::_StaticInterop {} + #C4 = _js::JS {name:#C3} + #C5 = _js::_StaticInterop {} } Constructor coverage from constants: org-dartlang-testcase:///main_lib.dart: -- JS. (from org-dartlang-testcase-sdk:///pkg/js/lib/js.dart:23:9) +- JS. (from org-dartlang-sdk:///lib/js/_js_annotations.dart) - Object. (from org-dartlang-sdk:///lib/core/object.dart) diff --git a/pkg/front_end/testcases/dartdevc/static_interop_erasure/main.dart.strong.transformed.expect b/pkg/front_end/testcases/dartdevc/static_interop_erasure/main.dart.strong.transformed.expect index 8eff89218ca..c1d8d97f036 100644 --- a/pkg/front_end/testcases/dartdevc/static_interop_erasure/main.dart.strong.transformed.expect +++ b/pkg/front_end/testcases/dartdevc/static_interop_erasure/main.dart.strong.transformed.expect @@ -12,7 +12,7 @@ static method main() → void { @#C2 library static_interop /*isNonNullableByDefault*/; import self as sta; -import "package:js/js.dart" as js; +import "dart:_js_annotations" as _js; import "dart:core" as core; import "dart:js_util" as js_; @@ -39,14 +39,14 @@ static method setUp() → void { constants { #C1 = null - #C2 = js::JS {name:#C1} + #C2 = _js::JS {name:#C1} #C3 = "JSClass" - #C4 = js::JS {name:#C3} - #C5 = js::_StaticInterop {} + #C4 = _js::JS {name:#C3} + #C5 = _js::_StaticInterop {} } Constructor coverage from constants: org-dartlang-testcase:///main_lib.dart: -- JS. (from org-dartlang-testcase-sdk:///pkg/js/lib/js.dart:23:9) +- JS. (from org-dartlang-sdk:///lib/js/_js_annotations.dart) - Object. (from org-dartlang-sdk:///lib/core/object.dart) diff --git a/pkg/front_end/testcases/dartdevc/static_interop_erasure/main.dart.weak.expect b/pkg/front_end/testcases/dartdevc/static_interop_erasure/main.dart.weak.expect index 8eff89218ca..c1d8d97f036 100644 --- a/pkg/front_end/testcases/dartdevc/static_interop_erasure/main.dart.weak.expect +++ b/pkg/front_end/testcases/dartdevc/static_interop_erasure/main.dart.weak.expect @@ -12,7 +12,7 @@ static method main() → void { @#C2 library static_interop /*isNonNullableByDefault*/; import self as sta; -import "package:js/js.dart" as js; +import "dart:_js_annotations" as _js; import "dart:core" as core; import "dart:js_util" as js_; @@ -39,14 +39,14 @@ static method setUp() → void { constants { #C1 = null - #C2 = js::JS {name:#C1} + #C2 = _js::JS {name:#C1} #C3 = "JSClass" - #C4 = js::JS {name:#C3} - #C5 = js::_StaticInterop {} + #C4 = _js::JS {name:#C3} + #C5 = _js::_StaticInterop {} } Constructor coverage from constants: org-dartlang-testcase:///main_lib.dart: -- JS. (from org-dartlang-testcase-sdk:///pkg/js/lib/js.dart:23:9) +- JS. (from org-dartlang-sdk:///lib/js/_js_annotations.dart) - Object. (from org-dartlang-sdk:///lib/core/object.dart) diff --git a/pkg/front_end/testcases/dartdevc/static_interop_erasure/main.dart.weak.outline.expect b/pkg/front_end/testcases/dartdevc/static_interop_erasure/main.dart.weak.outline.expect index 39440ebfe57..279a973799c 100644 --- a/pkg/front_end/testcases/dartdevc/static_interop_erasure/main.dart.weak.outline.expect +++ b/pkg/front_end/testcases/dartdevc/static_interop_erasure/main.dart.weak.outline.expect @@ -9,7 +9,7 @@ static method main() → void @#C2 library static_interop /*isNonNullableByDefault*/; import self as self2; -import "package:js/js.dart" as js; +import "dart:_js_annotations" as _js; import "dart:core" as core; import "dart:js_util" as js_; @@ -34,14 +34,14 @@ static method setUp() → void constants { #C1 = null - #C2 = js::JS {name:#C1} + #C2 = _js::JS {name:#C1} #C3 = "JSClass" - #C4 = js::JS {name:#C3} - #C5 = js::_StaticInterop {} + #C4 = _js::JS {name:#C3} + #C5 = _js::_StaticInterop {} } Constructor coverage from constants: org-dartlang-testcase:///main_lib.dart: -- JS. (from org-dartlang-testcase-sdk:///pkg/js/lib/js.dart:23:9) +- JS. (from org-dartlang-sdk:///lib/js/_js_annotations.dart) - Object. (from org-dartlang-sdk:///lib/core/object.dart) diff --git a/pkg/front_end/testcases/dartdevc/static_interop_erasure/main.dart.weak.transformed.expect b/pkg/front_end/testcases/dartdevc/static_interop_erasure/main.dart.weak.transformed.expect index 8eff89218ca..c1d8d97f036 100644 --- a/pkg/front_end/testcases/dartdevc/static_interop_erasure/main.dart.weak.transformed.expect +++ b/pkg/front_end/testcases/dartdevc/static_interop_erasure/main.dart.weak.transformed.expect @@ -12,7 +12,7 @@ static method main() → void { @#C2 library static_interop /*isNonNullableByDefault*/; import self as sta; -import "package:js/js.dart" as js; +import "dart:_js_annotations" as _js; import "dart:core" as core; import "dart:js_util" as js_; @@ -39,14 +39,14 @@ static method setUp() → void { constants { #C1 = null - #C2 = js::JS {name:#C1} + #C2 = _js::JS {name:#C1} #C3 = "JSClass" - #C4 = js::JS {name:#C3} - #C5 = js::_StaticInterop {} + #C4 = _js::JS {name:#C3} + #C5 = _js::_StaticInterop {} } Constructor coverage from constants: org-dartlang-testcase:///main_lib.dart: -- JS. (from org-dartlang-testcase-sdk:///pkg/js/lib/js.dart:23:9) +- JS. (from org-dartlang-sdk:///lib/js/_js_annotations.dart) - Object. (from org-dartlang-sdk:///lib/core/object.dart) diff --git a/pkg/front_end/testcases/general/constants/js_semantics/issue46123.dart.strong.expect b/pkg/front_end/testcases/general/constants/js_semantics/issue46123.dart.strong.expect index 899feae5df5..bafa6dc56a4 100644 --- a/pkg/front_end/testcases/general/constants/js_semantics/issue46123.dart.strong.expect +++ b/pkg/front_end/testcases/general/constants/js_semantics/issue46123.dart.strong.expect @@ -10,7 +10,7 @@ library /*isNonNullableByDefault*/; // ^ // import self as self; -import "package:js/js.dart" as js; +import "dart:_js_annotations" as _js; import "dart:core" as core; import "package:js/js.dart"; @@ -28,12 +28,12 @@ static method main() → dynamic {} constants { #C1 = null - #C2 = js::JS {name:#C1} - #C3 = js::_Anonymous {} + #C2 = _js::JS {name:#C1} + #C3 = _js::_Anonymous {} } Constructor coverage from constants: org-dartlang-testcase:///issue46123.dart: -- JS. (from org-dartlang-testcase-sdk:///pkg/js/lib/js.dart:23:9) +- JS. (from org-dartlang-sdk:///lib/js/_js_annotations.dart) - Object. (from org-dartlang-sdk:///lib/core/object.dart) diff --git a/pkg/front_end/testcases/general/constants/js_semantics/issue46123.dart.strong.transformed.expect b/pkg/front_end/testcases/general/constants/js_semantics/issue46123.dart.strong.transformed.expect index 899feae5df5..bafa6dc56a4 100644 --- a/pkg/front_end/testcases/general/constants/js_semantics/issue46123.dart.strong.transformed.expect +++ b/pkg/front_end/testcases/general/constants/js_semantics/issue46123.dart.strong.transformed.expect @@ -10,7 +10,7 @@ library /*isNonNullableByDefault*/; // ^ // import self as self; -import "package:js/js.dart" as js; +import "dart:_js_annotations" as _js; import "dart:core" as core; import "package:js/js.dart"; @@ -28,12 +28,12 @@ static method main() → dynamic {} constants { #C1 = null - #C2 = js::JS {name:#C1} - #C3 = js::_Anonymous {} + #C2 = _js::JS {name:#C1} + #C3 = _js::_Anonymous {} } Constructor coverage from constants: org-dartlang-testcase:///issue46123.dart: -- JS. (from org-dartlang-testcase-sdk:///pkg/js/lib/js.dart:23:9) +- JS. (from org-dartlang-sdk:///lib/js/_js_annotations.dart) - Object. (from org-dartlang-sdk:///lib/core/object.dart) diff --git a/pkg/front_end/testcases/general/constants/js_semantics/issue46123.dart.weak.expect b/pkg/front_end/testcases/general/constants/js_semantics/issue46123.dart.weak.expect index 899feae5df5..bafa6dc56a4 100644 --- a/pkg/front_end/testcases/general/constants/js_semantics/issue46123.dart.weak.expect +++ b/pkg/front_end/testcases/general/constants/js_semantics/issue46123.dart.weak.expect @@ -10,7 +10,7 @@ library /*isNonNullableByDefault*/; // ^ // import self as self; -import "package:js/js.dart" as js; +import "dart:_js_annotations" as _js; import "dart:core" as core; import "package:js/js.dart"; @@ -28,12 +28,12 @@ static method main() → dynamic {} constants { #C1 = null - #C2 = js::JS {name:#C1} - #C3 = js::_Anonymous {} + #C2 = _js::JS {name:#C1} + #C3 = _js::_Anonymous {} } Constructor coverage from constants: org-dartlang-testcase:///issue46123.dart: -- JS. (from org-dartlang-testcase-sdk:///pkg/js/lib/js.dart:23:9) +- JS. (from org-dartlang-sdk:///lib/js/_js_annotations.dart) - Object. (from org-dartlang-sdk:///lib/core/object.dart) diff --git a/pkg/front_end/testcases/general/constants/js_semantics/issue46123.dart.weak.modular.expect b/pkg/front_end/testcases/general/constants/js_semantics/issue46123.dart.weak.modular.expect index 899feae5df5..bafa6dc56a4 100644 --- a/pkg/front_end/testcases/general/constants/js_semantics/issue46123.dart.weak.modular.expect +++ b/pkg/front_end/testcases/general/constants/js_semantics/issue46123.dart.weak.modular.expect @@ -10,7 +10,7 @@ library /*isNonNullableByDefault*/; // ^ // import self as self; -import "package:js/js.dart" as js; +import "dart:_js_annotations" as _js; import "dart:core" as core; import "package:js/js.dart"; @@ -28,12 +28,12 @@ static method main() → dynamic {} constants { #C1 = null - #C2 = js::JS {name:#C1} - #C3 = js::_Anonymous {} + #C2 = _js::JS {name:#C1} + #C3 = _js::_Anonymous {} } Constructor coverage from constants: org-dartlang-testcase:///issue46123.dart: -- JS. (from org-dartlang-testcase-sdk:///pkg/js/lib/js.dart:23:9) +- JS. (from org-dartlang-sdk:///lib/js/_js_annotations.dart) - Object. (from org-dartlang-sdk:///lib/core/object.dart) diff --git a/pkg/front_end/testcases/general/constants/js_semantics/issue46123.dart.weak.outline.expect b/pkg/front_end/testcases/general/constants/js_semantics/issue46123.dart.weak.outline.expect index d79fbe575c1..f44a2d181b2 100644 --- a/pkg/front_end/testcases/general/constants/js_semantics/issue46123.dart.weak.outline.expect +++ b/pkg/front_end/testcases/general/constants/js_semantics/issue46123.dart.weak.outline.expect @@ -1,12 +1,12 @@ library /*isNonNullableByDefault*/; import self as self; -import "package:js/js.dart" as js; +import "dart:_js_annotations" as _js; import "dart:core" as core; import "package:js/js.dart"; -@js::JS::•() -@js::anonymous +@_js::JS::•() +@_js::anonymous class ParallaxOptions extends core::Object { external static factory •() → self::ParallaxOptions; static method _#new#tearOff() → self::ParallaxOptions diff --git a/pkg/front_end/testcases/general/constants/js_semantics/issue46123.dart.weak.transformed.expect b/pkg/front_end/testcases/general/constants/js_semantics/issue46123.dart.weak.transformed.expect index 899feae5df5..bafa6dc56a4 100644 --- a/pkg/front_end/testcases/general/constants/js_semantics/issue46123.dart.weak.transformed.expect +++ b/pkg/front_end/testcases/general/constants/js_semantics/issue46123.dart.weak.transformed.expect @@ -10,7 +10,7 @@ library /*isNonNullableByDefault*/; // ^ // import self as self; -import "package:js/js.dart" as js; +import "dart:_js_annotations" as _js; import "dart:core" as core; import "package:js/js.dart"; @@ -28,12 +28,12 @@ static method main() → dynamic {} constants { #C1 = null - #C2 = js::JS {name:#C1} - #C3 = js::_Anonymous {} + #C2 = _js::JS {name:#C1} + #C3 = _js::_Anonymous {} } Constructor coverage from constants: org-dartlang-testcase:///issue46123.dart: -- JS. (from org-dartlang-testcase-sdk:///pkg/js/lib/js.dart:23:9) +- JS. (from org-dartlang-sdk:///lib/js/_js_annotations.dart) - Object. (from org-dartlang-sdk:///lib/core/object.dart) diff --git a/pkg/front_end/testcases/general/constants/js_semantics/issue46123b.dart.strong.expect b/pkg/front_end/testcases/general/constants/js_semantics/issue46123b.dart.strong.expect index e249fb351eb..d51f34d230c 100644 --- a/pkg/front_end/testcases/general/constants/js_semantics/issue46123b.dart.strong.expect +++ b/pkg/front_end/testcases/general/constants/js_semantics/issue46123b.dart.strong.expect @@ -10,7 +10,7 @@ library /*isNonNullableByDefault*/; // ^ // import self as self; -import "package:js/js.dart" as js; +import "dart:_js_annotations" as _js; import "dart:core" as core; import "package:js/js.dart"; @@ -28,12 +28,12 @@ static method main() → dynamic {} constants { #C1 = null - #C2 = js::JS {name:#C1} - #C3 = js::_Anonymous {} + #C2 = _js::JS {name:#C1} + #C3 = _js::_Anonymous {} } Constructor coverage from constants: org-dartlang-testcase:///issue46123b.dart: -- JS. (from org-dartlang-testcase-sdk:///pkg/js/lib/js.dart:23:9) +- JS. (from org-dartlang-sdk:///lib/js/_js_annotations.dart) - Object. (from org-dartlang-sdk:///lib/core/object.dart) diff --git a/pkg/front_end/testcases/general/constants/js_semantics/issue46123b.dart.strong.transformed.expect b/pkg/front_end/testcases/general/constants/js_semantics/issue46123b.dart.strong.transformed.expect index e249fb351eb..d51f34d230c 100644 --- a/pkg/front_end/testcases/general/constants/js_semantics/issue46123b.dart.strong.transformed.expect +++ b/pkg/front_end/testcases/general/constants/js_semantics/issue46123b.dart.strong.transformed.expect @@ -10,7 +10,7 @@ library /*isNonNullableByDefault*/; // ^ // import self as self; -import "package:js/js.dart" as js; +import "dart:_js_annotations" as _js; import "dart:core" as core; import "package:js/js.dart"; @@ -28,12 +28,12 @@ static method main() → dynamic {} constants { #C1 = null - #C2 = js::JS {name:#C1} - #C3 = js::_Anonymous {} + #C2 = _js::JS {name:#C1} + #C3 = _js::_Anonymous {} } Constructor coverage from constants: org-dartlang-testcase:///issue46123b.dart: -- JS. (from org-dartlang-testcase-sdk:///pkg/js/lib/js.dart:23:9) +- JS. (from org-dartlang-sdk:///lib/js/_js_annotations.dart) - Object. (from org-dartlang-sdk:///lib/core/object.dart) diff --git a/pkg/front_end/testcases/general/constants/js_semantics/issue46123b.dart.weak.expect b/pkg/front_end/testcases/general/constants/js_semantics/issue46123b.dart.weak.expect index e249fb351eb..d51f34d230c 100644 --- a/pkg/front_end/testcases/general/constants/js_semantics/issue46123b.dart.weak.expect +++ b/pkg/front_end/testcases/general/constants/js_semantics/issue46123b.dart.weak.expect @@ -10,7 +10,7 @@ library /*isNonNullableByDefault*/; // ^ // import self as self; -import "package:js/js.dart" as js; +import "dart:_js_annotations" as _js; import "dart:core" as core; import "package:js/js.dart"; @@ -28,12 +28,12 @@ static method main() → dynamic {} constants { #C1 = null - #C2 = js::JS {name:#C1} - #C3 = js::_Anonymous {} + #C2 = _js::JS {name:#C1} + #C3 = _js::_Anonymous {} } Constructor coverage from constants: org-dartlang-testcase:///issue46123b.dart: -- JS. (from org-dartlang-testcase-sdk:///pkg/js/lib/js.dart:23:9) +- JS. (from org-dartlang-sdk:///lib/js/_js_annotations.dart) - Object. (from org-dartlang-sdk:///lib/core/object.dart) diff --git a/pkg/front_end/testcases/general/constants/js_semantics/issue46123b.dart.weak.modular.expect b/pkg/front_end/testcases/general/constants/js_semantics/issue46123b.dart.weak.modular.expect index e249fb351eb..d51f34d230c 100644 --- a/pkg/front_end/testcases/general/constants/js_semantics/issue46123b.dart.weak.modular.expect +++ b/pkg/front_end/testcases/general/constants/js_semantics/issue46123b.dart.weak.modular.expect @@ -10,7 +10,7 @@ library /*isNonNullableByDefault*/; // ^ // import self as self; -import "package:js/js.dart" as js; +import "dart:_js_annotations" as _js; import "dart:core" as core; import "package:js/js.dart"; @@ -28,12 +28,12 @@ static method main() → dynamic {} constants { #C1 = null - #C2 = js::JS {name:#C1} - #C3 = js::_Anonymous {} + #C2 = _js::JS {name:#C1} + #C3 = _js::_Anonymous {} } Constructor coverage from constants: org-dartlang-testcase:///issue46123b.dart: -- JS. (from org-dartlang-testcase-sdk:///pkg/js/lib/js.dart:23:9) +- JS. (from org-dartlang-sdk:///lib/js/_js_annotations.dart) - Object. (from org-dartlang-sdk:///lib/core/object.dart) diff --git a/pkg/front_end/testcases/general/constants/js_semantics/issue46123b.dart.weak.outline.expect b/pkg/front_end/testcases/general/constants/js_semantics/issue46123b.dart.weak.outline.expect index a49e2c0eb86..8e8875b221a 100644 --- a/pkg/front_end/testcases/general/constants/js_semantics/issue46123b.dart.weak.outline.expect +++ b/pkg/front_end/testcases/general/constants/js_semantics/issue46123b.dart.weak.outline.expect @@ -1,12 +1,12 @@ library /*isNonNullableByDefault*/; import self as self; -import "package:js/js.dart" as js; +import "dart:_js_annotations" as _js; import "dart:core" as core; import "package:js/js.dart"; -@js::JS::•() -@js::anonymous +@_js::JS::•() +@_js::anonymous class ParallaxOptions extends core::Object /*hasConstConstructor*/ { external const constructor •() → self::ParallaxOptions; static method _#new#tearOff() → self::ParallaxOptions diff --git a/pkg/front_end/testcases/general/constants/js_semantics/issue46123b.dart.weak.transformed.expect b/pkg/front_end/testcases/general/constants/js_semantics/issue46123b.dart.weak.transformed.expect index e249fb351eb..d51f34d230c 100644 --- a/pkg/front_end/testcases/general/constants/js_semantics/issue46123b.dart.weak.transformed.expect +++ b/pkg/front_end/testcases/general/constants/js_semantics/issue46123b.dart.weak.transformed.expect @@ -10,7 +10,7 @@ library /*isNonNullableByDefault*/; // ^ // import self as self; -import "package:js/js.dart" as js; +import "dart:_js_annotations" as _js; import "dart:core" as core; import "package:js/js.dart"; @@ -28,12 +28,12 @@ static method main() → dynamic {} constants { #C1 = null - #C2 = js::JS {name:#C1} - #C3 = js::_Anonymous {} + #C2 = _js::JS {name:#C1} + #C3 = _js::_Anonymous {} } Constructor coverage from constants: org-dartlang-testcase:///issue46123b.dart: -- JS. (from org-dartlang-testcase-sdk:///pkg/js/lib/js.dart:23:9) +- JS. (from org-dartlang-sdk:///lib/js/_js_annotations.dart) - Object. (from org-dartlang-sdk:///lib/core/object.dart) diff --git a/pkg/front_end/testcases/incremental/js_interop_change.yaml b/pkg/front_end/testcases/incremental/js_interop_change.yaml index 9b4a27613e1..78f20817f20 100644 --- a/pkg/front_end/testcases/incremental/js_interop_change.yaml +++ b/pkg/front_end/testcases/incremental/js_interop_change.yaml @@ -79,14 +79,7 @@ worlds: eval('''function JSClass() {}'''); } js/lib/js.dart: | - class JS { - final String? name; - const JS([this.name]); - } - class _StaticInterop { - const _StaticInterop(); - } - const _StaticInterop staticInterop = _StaticInterop(); + export 'dart:_js_annotations' show JS, staticInterop; .dart_tool/package_config.json: | { "configVersion": 2, diff --git a/pkg/front_end/testcases/incremental/js_interop_change.yaml.world.1.expect b/pkg/front_end/testcases/incremental/js_interop_change.yaml.world.1.expect index 531fc4cf0a3..863880dfc65 100644 --- a/pkg/front_end/testcases/incremental/js_interop_change.yaml.world.1.expect +++ b/pkg/front_end/testcases/incremental/js_interop_change.yaml.world.1.expect @@ -1,22 +1,10 @@ main = main::main; library from "package:js/js.dart" as js { +additionalExports = (_js::staticInterop, + _js::JS) + + export "dart:_js_annotations" show JS, staticInterop; - class JS extends dart.core::Object /*hasConstConstructor*/ { - final field dart.core::String? name; - const constructor •([dart.core::String? name = #C1]) → js::JS - : js::JS::name = name, super dart.core::Object::•() - ; - static method _#new#tearOff([dart.core::String? name = #C1]) → js::JS - return new js::JS::•(name); - } - class _StaticInterop extends dart.core::Object /*hasConstConstructor*/ { - const constructor •() → js::_StaticInterop - : super dart.core::Object::•() - ; - static method _#new#tearOff() → js::_StaticInterop - return new js::_StaticInterop::•(); - } - static const field js::_StaticInterop staticInterop = #C2; } library from "org-dartlang-test:///lib1.dart" as lib1 { @@ -45,13 +33,13 @@ library from "org-dartlang-test:///lib1.dart" as lib1 { return sta::StaticJSClass::•(); static set topLevelSetter((sta::StaticJSClass) → void f) → void {} } -@#C3 +@#C2 library static_interop from "org-dartlang-test:///lib2.dart" as sta { import "package:js/js.dart"; + @#C4 @#C5 - @#C2 class StaticJSClass extends dart.core::Object { static factory •() → sta::StaticJSClass return dart.js_util::_callConstructorUnchecked0(dart.js_util::_getPropertyTrustType(dart.js_util::globalThis, "JSClass")); @@ -63,7 +51,7 @@ library static_interop from "org-dartlang-test:///lib2.dart" as sta { static method _#factory#tearOff() → sta::StaticJSClass return sta::StaticJSClass::factory(); } - @#C3 + @#C2 external static method eval(dart.core::String code) → void; static method setUp() → void { sta::eval("function JSClass() {}"); @@ -105,10 +93,10 @@ library from "org-dartlang-test:///main.dart" as main { } constants { #C1 = null - #C2 = js::_StaticInterop {} - #C3 = js::JS {name:#C1} - #C4 = "JSClass" - #C5 = js::JS {name:#C4} + #C2 = _js_annotations::JS {name:#C1} + #C3 = "JSClass" + #C4 = _js_annotations::JS {name:#C3} + #C5 = _js_annotations::_StaticInterop {} #C6 = static-tearoff lib1::topLevelMethod #C7 = static-tearoff lib1::Class::staticMethod } @@ -116,10 +104,6 @@ constants { Constructor coverage from constants: org-dartlang-test:///lib2.dart: -- JS. (from org-dartlang-test:///js/lib/js.dart:3:9) -- Object. (from org-dartlang-sdk:///lib/core/object.dart) - -org-dartlang-test:///js/lib/js.dart: -- _StaticInterop. (from org-dartlang-test:///js/lib/js.dart:6:9) +- JS. (from org-dartlang-sdk:///lib/js/_js_annotations.dart) - Object. (from org-dartlang-sdk:///lib/core/object.dart) diff --git a/pkg/front_end/testcases/incremental/js_interop_change.yaml.world.2.expect b/pkg/front_end/testcases/incremental/js_interop_change.yaml.world.2.expect index 115e8c92514..52057131344 100644 --- a/pkg/front_end/testcases/incremental/js_interop_change.yaml.world.2.expect +++ b/pkg/front_end/testcases/incremental/js_interop_change.yaml.world.2.expect @@ -1,22 +1,10 @@ main = main::main; library from "package:js/js.dart" as js { +additionalExports = (_js::staticInterop, + _js::JS) + + export "dart:_js_annotations" show JS, staticInterop; - class JS extends dart.core::Object /*hasConstConstructor*/ { - final field dart.core::String? name; - const constructor •([dart.core::String? name = #C1]) → js::JS - : js::JS::name = name, super dart.core::Object::•() - ; - static method _#new#tearOff([dart.core::String? name = #C1]) → js::JS - return new js::JS::•(name); - } - class _StaticInterop extends dart.core::Object /*hasConstConstructor*/ { - const constructor •() → js::_StaticInterop - : super dart.core::Object::•() - ; - static method _#new#tearOff() → js::_StaticInterop - return new js::_StaticInterop::•(); - } - static const field js::_StaticInterop staticInterop = #C2; } library from "org-dartlang-test:///lib1.dart" as lib1 { @@ -45,13 +33,13 @@ library from "org-dartlang-test:///lib1.dart" as lib1 { return sta::StaticJSClass::•(); static set topLevelSetter((sta::StaticJSClass) → void f) → void {} } -@#C3 +@#C2 library static_interop from "org-dartlang-test:///lib2.dart" as sta { import "package:js/js.dart"; + @#C4 @#C5 - @#C2 class StaticJSClass extends dart.core::Object { static factory •() → sta::StaticJSClass return dart.js_util::_callConstructorUnchecked0(dart.js_util::_getPropertyTrustType(dart.js_util::globalThis, "JSClass")); @@ -63,7 +51,7 @@ library static_interop from "org-dartlang-test:///lib2.dart" as sta { static method _#factory#tearOff() → sta::StaticJSClass return sta::StaticJSClass::factory(); } - @#C3 + @#C2 external static method eval(dart.core::String code) → void; static method setUp() → void { sta::eval("function JSClass() {}"); @@ -106,10 +94,10 @@ library from "org-dartlang-test:///main.dart" as main { } constants { #C1 = null - #C2 = js::_StaticInterop {} - #C3 = js::JS {name:#C1} - #C4 = "JSClass" - #C5 = js::JS {name:#C4} + #C2 = _js_annotations::JS {name:#C1} + #C3 = "JSClass" + #C4 = _js_annotations::JS {name:#C3} + #C5 = _js_annotations::_StaticInterop {} #C6 = static-tearoff lib1::topLevelMethod #C7 = static-tearoff lib1::Class::staticMethod } @@ -117,10 +105,6 @@ constants { Constructor coverage from constants: org-dartlang-test:///lib2.dart: -- JS. (from org-dartlang-test:///js/lib/js.dart:3:9) -- Object. (from org-dartlang-sdk:///lib/core/object.dart) - -org-dartlang-test:///js/lib/js.dart: -- _StaticInterop. (from org-dartlang-test:///js/lib/js.dart:6:9) +- JS. (from org-dartlang-sdk:///lib/js/_js_annotations.dart) - Object. (from org-dartlang-sdk:///lib/core/object.dart) diff --git a/pkg/js/CHANGELOG.md b/pkg/js/CHANGELOG.md index b580d15281f..9bbfddfae2b 100644 --- a/pkg/js/CHANGELOG.md +++ b/pkg/js/CHANGELOG.md @@ -3,6 +3,7 @@ - Remove dependency on `dart:js`. - Update SDK lower constraint to 3.0.0-217.0.dev. - Update SDK upper constraint to 4.0.0. +- Moved annotations to single location in `dart:_js_annotations`. ## 0.6.7 diff --git a/pkg/js/lib/js.dart b/pkg/js/lib/js.dart index b6897c5f0f2..856a5b36cef 100644 --- a/pkg/js/lib/js.dart +++ b/pkg/js/lib/js.dart @@ -2,89 +2,9 @@ // 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. -/// Annotations to mark interfaces to JavaScript. library js; -import 'package:meta/meta.dart'; - +// ignore: EXPORT_INTERNAL_LIBRARY +export 'dart:_js_annotations' + show JS, anonymous, staticInterop, trustTypes, JSExport; export 'dart:js_util' show allowInterop, allowInteropCaptureThis; - -/// An annotation that indicates a library, class, or member is implemented -/// directly in JavaScript. -/// -/// All external members of a class or library with this annotation implicitly -/// have it as well. -/// -/// Specifying [name] customizes the JavaScript name to use. By default the -/// dart name is used. It is not valid to specify a custom [name] for class -/// instance members. -class JS { - final String? name; - const JS([this.name]); -} - -class _Anonymous { - const _Anonymous(); -} - -class _StaticInterop { - const _StaticInterop(); -} - -/// An annotation that indicates a [JS] annotated class is structural and does -/// not have a known JavaScript prototype. -/// -/// A class marked with [anonymous] must have an unnamed factory constructor -/// with no positional arguments, only named arguments. Invoking the constructor -/// desugars to creating a JavaScript object literal with name-value pairs -/// corresponding to the parameter names and values. -const _Anonymous anonymous = _Anonymous(); - -/// [staticInterop] enables the [JS] annotated class to be treated as a "static" -/// interop class. -/// -/// These classes allow interop with native types, like the ones in `dart:html`. -/// These classes should not contain any instance members, inherited or -/// otherwise, and should instead use static extension members. -const _StaticInterop staticInterop = _StaticInterop(); - -/// NOTE: [trustTypes] is an experimental annotation that may disappear at any -/// point in time. It exists solely to help users who wish to migrate classes -/// from the older style of JS interop to the new static interop model but wish -/// to preserve the older semantics for type checks. This annotation must be -/// used alongside [staticInterop] and it affects any external methods in any -/// extension to the static interop class. -@experimental -class _TrustTypes { - const _TrustTypes(); -} - -const _TrustTypes trustTypes = _TrustTypes(); - -/// Annotation to mark Dart classes as exportable and allow instance members to -/// be wrapped with an object literal. -/// -/// Dart classes with this annotation can be used for exporting in `js_util`'s -/// `createDartExport`, which returns a JS object that forwards to the Dart -/// class. You may either annotate specific instance members to only export -/// those members or you can annotate the entire class (which will export all -/// instance members) to mark the class as exportable. -/// -/// Classes and mixins in the hierarchy are included only if they are annotated -/// or specific members in them are annotated. If a superclass does not have an -/// annotation anywhere, its members are not included. Only concrete instance -/// members can and will be exported, and it's an error to annotate other -/// members with this annotation. In order to do renaming for members, you can -/// provide a name for the `@JSExport` on the members e.g. -/// ``` -/// class Export { -/// @JSExport('printHelloWorld') -/// void printMessage() => print('Hello World!'); -/// } -/// ``` -/// which will then set 'printHelloWorld' to forward to `printMessage` in the -/// object literal. -class JSExport { - final String name; - const JSExport([this.name = '']); -} diff --git a/pkg/js/pubspec.yaml b/pkg/js/pubspec.yaml index b746a97b10b..805522a7bb8 100644 --- a/pkg/js/pubspec.yaml +++ b/pkg/js/pubspec.yaml @@ -3,12 +3,14 @@ version: 0.6.9-dev description: Annotations to create static Dart interfaces for JavaScript APIs. repository: https://github.com/dart-lang/sdk/tree/main/pkg/js +# We export `dart:_js_annotations` in this library. +analyzer: + errors: + export_internal_library: ignore + environment: sdk: ">=3.0.0-217.0.dev <4.0.0" -dependencies: - meta: ^1.7.0 - # We use 'any' version constraints here as we get our package versions from # the dart-lang/sdk repo's DEPS file. Note that this is a special case; the # best practice for packages is to specify their compatible version ranges. diff --git a/sdk/lib/_internal/js_shared/lib/js_interop_patch.dart b/sdk/lib/_internal/js_shared/lib/js_interop_patch.dart index 7d5ffb18d1a..cdb7c82f6d9 100644 --- a/sdk/lib/_internal/js_shared/lib/js_interop_patch.dart +++ b/sdk/lib/_internal/js_shared/lib/js_interop_patch.dart @@ -2,7 +2,7 @@ // 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 'dart:_foreign_helper' show JS; +import 'dart:_foreign_helper' as foreign_helper; import 'dart:_internal' show patch; import 'dart:_js_types'; import 'dart:js_util'; @@ -15,7 +15,8 @@ extension NullableUndefineableJSAnyExtension on JSAny? { bool get isUndefined => this == null || typeofEquals(this, 'undefined'); @patch - bool get isNull => this == null || JS('bool', '# === null', this); + bool get isNull => + this == null || foreign_helper.JS('bool', '# === null', this); } /// [JSExportedDartFunction] <-> [Function] diff --git a/sdk/lib/js/_js_annotations.dart b/sdk/lib/js/_js_annotations.dart index f053d6e90d1..8733bcd681b 100644 --- a/sdk/lib/js/_js_annotations.dart +++ b/sdk/lib/js/_js_annotations.dart @@ -2,13 +2,21 @@ // 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. -// An implementation of the JS interop classes which are usable from the -// Dart SDK. These types need to stay in-sync with -// https://github.com/dart-lang/sdk/blob/master/pkg/js/lib/js.dart +/// Annotations to mark interfaces to JavaScript. All of these annotations are +/// exported via `package:js`. library _js_annotations; export 'dart:js_util' show allowInterop, allowInteropCaptureThis; +/// An annotation that indicates a library, class, or member is implemented +/// directly in JavaScript. +/// +/// All external members of a class or library with this annotation implicitly +/// have it as well. +/// +/// Specifying [name] customizes the JavaScript name to use. By default the +/// dart name is used. It is not valid to specify a custom [name] for class +/// instance members. class JS { final String? name; const JS([this.name]); @@ -22,10 +30,58 @@ class _StaticInterop { const _StaticInterop(); } +/// An annotation that indicates a [JS] annotated class is structural and does +/// not have a known JavaScript prototype. +/// +/// A class marked with [anonymous] must have an unnamed factory constructor +/// with no positional arguments, only named arguments. Invoking the constructor +/// desugars to creating a JavaScript object literal with name-value pairs +/// corresponding to the parameter names and values. const _Anonymous anonymous = _Anonymous(); +/// [staticInterop] enables the [JS] annotated class to be treated as a "static" +/// interop class. +/// +/// These classes allow interop with native types, like the ones in `dart:html`. +/// These classes should not contain any instance members, inherited or +/// otherwise, and should instead use static extension members. const _StaticInterop staticInterop = _StaticInterop(); +/// NOTE: [trustTypes] is an experimental annotation that may disappear at any +/// point in time. It exists solely to help users who wish to migrate classes +/// from the older style of JS interop to the new static interop model but wish +/// to preserve the older semantics for type checks. This annotation must be +/// used alongside [staticInterop] and it affects any external methods in any +/// extension to the static interop class. +class _TrustTypes { + const _TrustTypes(); +} + +const _TrustTypes trustTypes = _TrustTypes(); + +/// Annotation to mark Dart classes as exportable and allow instance members to +/// be wrapped with an object literal. +/// +/// Dart classes with this annotation can be used for exporting in `js_util`'s +/// `createDartExport`, which returns a JS object that forwards to the Dart +/// class. You may either annotate specific instance members to only export +/// those members or you can annotate the entire class (which will export all +/// instance members) to mark the class as exportable. +/// +/// Classes and mixins in the hierarchy are included only if they are annotated +/// or specific members in them are annotated. If a superclass does not have an +/// annotation anywhere, its members are not included. Only concrete instance +/// members can and will be exported, and it's an error to annotate other +/// members with this annotation. In order to do renaming for members, you can +/// provide a name for the `@JSExport` on the members e.g. +/// ``` +/// class Export { +/// @JSExport('printHelloWorld') +/// void printMessage() => print('Hello World!'); +/// } +/// ``` +/// which will then set 'printHelloWorld' to forward to `printMessage` in the +/// object literal. class JSExport { final String name; const JSExport([this.name = '']); diff --git a/sdk/lib/js_interop/js_interop.dart b/sdk/lib/js_interop/js_interop.dart index eeecbabb83c..539cd8751c1 100644 --- a/sdk/lib/js_interop/js_interop.dart +++ b/sdk/lib/js_interop/js_interop.dart @@ -21,11 +21,30 @@ library dart.js_interop; import 'dart:_js_types' as js_types; import 'dart:typed_data'; -/// Export the `dart:_js_annotations` version of the `@JS` annotation. This is -/// mostly identical to the `package:js` version, except this is meant to be used -/// for sound top-level external members and inline classes instead of the -/// `package:js` classes. -export 'dart:_js_annotations' show JS; +/// The annotation for JS interop members. +/// +/// This is meant to signify that a given library, top-level external member, or +/// inline class is a JS interop declaration. +/// +/// Specifying [name] customizes the JavaScript name to use. This can be used in +/// the following scenarios: +/// +/// - Namespacing all the external top-level members, static members, and +/// constructors of a library by annotating the library with a custom name. +/// - Namespacing all the external static members and constructors of an inline +/// class by annotating the inline class with a custom name. +/// - Renaming external members by annotating the member with a custom name. +/// +/// In the case where [name] is not specified, we default to the Dart name for +/// inline classes and external members. +/// +/// Note: `package:js` has a `@JS` annotation as well. Unlike that annotation, +/// this is meant for inline classes, and will result in more type-checking for +/// external top-level members. +class JS { + final String? name; + const JS([this.name]); +} /// The annotation for object literal constructors. /// diff --git a/tests/lib/js/static_interop_test/js_types_test.dart b/tests/lib/js/static_interop_test/js_types_test.dart index 9c27359f863..4a656ab7d5f 100644 --- a/tests/lib/js/static_interop_test/js_types_test.dart +++ b/tests/lib/js/static_interop_test/js_types_test.dart @@ -9,7 +9,7 @@ import 'dart:js_util'; import 'dart:typed_data'; import 'package:expect/minitest.dart'; -import 'package:js/js.dart'; +import 'package:js/js.dart' as js; @JS() external void eval(String code); @@ -20,8 +20,8 @@ external JSAny any; @JS() external JSObject obj; -@JS() -@staticInterop +@js.JS() +@js.staticInterop class SimpleObject {} extension SimpleObjectExtension on SimpleObject { diff --git a/tests/web/native/static_interop_erasure/factory_stub_test.dart b/tests/web/native/static_interop_erasure/factory_stub_test.dart index 121be04bbbd..997917011a9 100644 --- a/tests/web/native/static_interop_erasure/factory_stub_test.dart +++ b/tests/web/native/static_interop_erasure/factory_stub_test.dart @@ -12,7 +12,7 @@ import 'dart:_interceptors' show JavaScriptObject; import 'package:js/js.dart'; -import '../native_testing.dart'; +import '../native_testing.dart' hide JS; import '../native_testing.dart' as native_testing; import 'factory_stub_lib.dart'; diff --git a/tests/web/native/static_interop_erasure/type_test.dart b/tests/web/native/static_interop_erasure/type_test.dart index d0ed176a9f5..911a6100e2b 100644 --- a/tests/web/native/static_interop_erasure/type_test.dart +++ b/tests/web/native/static_interop_erasure/type_test.dart @@ -14,7 +14,7 @@ import 'package:expect/expect.dart' show hasUnsoundNullSafety; import 'package:expect/minitest.dart'; import 'package:js/js.dart'; -import '../native_testing.dart'; +import '../native_testing.dart' hide JS; import '../native_testing.dart' as native_testing; NativeClass makeNativeClass() native; diff --git a/tests/web/native/static_interop_erasure/use_erased_type_members_test.dart b/tests/web/native/static_interop_erasure/use_erased_type_members_test.dart index 061dbe35709..c05c740cf6e 100644 --- a/tests/web/native/static_interop_erasure/use_erased_type_members_test.dart +++ b/tests/web/native/static_interop_erasure/use_erased_type_members_test.dart @@ -13,7 +13,7 @@ import 'dart:_interceptors' show JavaScriptObject; import 'package:expect/minitest.dart'; import 'package:js/js.dart'; -import '../native_testing.dart'; +import '../native_testing.dart' hide JS; import '../native_testing.dart' as native_testing; NativeClass makeNativeClass() native; diff --git a/tests/web/wasm/js_util_test.dart b/tests/web/wasm/js_util_test.dart index 89ec2f1aafc..40829a3b539 100644 --- a/tests/web/wasm/js_util_test.dart +++ b/tests/web/wasm/js_util_test.dart @@ -8,7 +8,7 @@ import 'dart:typed_data'; import 'package:async_helper/async_helper.dart'; import 'package:expect/expect.dart'; -import 'package:js/js.dart'; +import 'package:js/js.dart' hide JS; @JS() external void eval(String code); diff --git a/tests/web_2/native/static_interop_erasure/factory_stub_test.dart b/tests/web_2/native/static_interop_erasure/factory_stub_test.dart index 215481aee6a..77b61cd40a6 100644 --- a/tests/web_2/native/static_interop_erasure/factory_stub_test.dart +++ b/tests/web_2/native/static_interop_erasure/factory_stub_test.dart @@ -14,7 +14,7 @@ import 'dart:_interceptors' show JavaScriptObject; import 'package:js/js.dart'; -import '../native_testing.dart'; +import '../native_testing.dart' hide JS; import '../native_testing.dart' as native_testing; import 'factory_stub_lib.dart'; diff --git a/tests/web_2/native/static_interop_erasure/type_test.dart b/tests/web_2/native/static_interop_erasure/type_test.dart index bd3c684cea6..8c0d3f8e471 100644 --- a/tests/web_2/native/static_interop_erasure/type_test.dart +++ b/tests/web_2/native/static_interop_erasure/type_test.dart @@ -15,7 +15,7 @@ import 'dart:_interceptors' show JavaScriptObject; import 'package:expect/minitest.dart'; import 'package:js/js.dart'; -import '../native_testing.dart'; +import '../native_testing.dart' hide JS; import '../native_testing.dart' as native_testing; NativeClass makeNativeClass() native; diff --git a/tests/web_2/native/static_interop_erasure/use_erased_type_members_test.dart b/tests/web_2/native/static_interop_erasure/use_erased_type_members_test.dart index b3b93034303..7675ad35726 100644 --- a/tests/web_2/native/static_interop_erasure/use_erased_type_members_test.dart +++ b/tests/web_2/native/static_interop_erasure/use_erased_type_members_test.dart @@ -15,7 +15,7 @@ import 'dart:_interceptors' show JavaScriptObject; import 'package:expect/minitest.dart'; import 'package:js/js.dart'; -import '../native_testing.dart'; +import '../native_testing.dart' hide JS; import '../native_testing.dart' as native_testing; NativeClass makeNativeClass() native;