Skip to content

Commit 5043993

Browse files
fishythefishCommit Queue
authored andcommitted
[js_interop] Move annotations from _js_annotations to js_interop
We'd like to remove `dart:js_util` support from dart2wasm. However, `dart:js_interop` re-exports some annotation classes from `dart:_js_annotations`, which exports some members from `dart:js_util`. To break the dependency chain, we can instead move those classes into `dart:js_interop` and re-export them from `dart:_js_annotations`. Bug: #61550 CoreLibraryReviewExempt: code motion, no semantic/API change Change-Id: I6a6a696451cc1b968062317957fc7883b2242c4a Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/453647 Reviewed-by: Srujan Gaddam <[email protected]> Reviewed-by: Paul Berry <[email protected]>
1 parent 0947f85 commit 5043993

18 files changed

+155
-143
lines changed

pkg/_js_interop_checks/lib/src/js_interop.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ bool hasDartJSInteropAnnotation(Annotatable a) =>
2323
a.annotations.any(_isDartJSInteropAnnotation);
2424

2525
/// Returns true iff the node has an `@anonymous` annotation from `package:js`
26-
/// or `dart:_js_annotations`.
26+
/// or `dart:js_interop`.
2727
bool hasAnonymousAnnotation(Annotatable a) =>
2828
a.annotations.any(_isAnonymousAnnotation);
2929

3030
/// Returns true iff the node has an `@staticInterop` annotation from
31-
/// `package:js` or `dart:_js_annotations`.
31+
/// `package:js` or `dart:js_interop`.
3232
bool hasStaticInteropAnnotation(Annotatable a) =>
3333
a.annotations.any(_isStaticInteropAnnotation);
3434

@@ -38,7 +38,7 @@ bool hasTrustTypesAnnotation(Annotatable a) =>
3838
a.annotations.any(_isTrustTypesAnnotation);
3939

4040
/// Returns true iff the node has an `@JSExport(...)` annotation from
41-
/// `package:js` or `dart:_js_annotations`.
41+
/// `package:js` or `dart:js_interop`.
4242
bool hasJSExportAnnotation(Annotatable a) =>
4343
a.annotations.any(_isJSExportAnnotation);
4444

@@ -191,9 +191,9 @@ bool _isPatchAnnotation(Expression value) {
191191
///
192192
/// - `@JS()` would return the "JS" class in "dart:_js_annotations".
193193
/// - `@anonymous` would return the "_Anonymous" class in
194-
/// "dart:_js_annotations".
194+
/// "dart:js_interop".
195195
/// - `@staticInterop` would return the "_StaticInterop" class in
196-
/// "dart:_js_annotations".
196+
/// "dart:js_interop".
197197
/// - `@Native` would return the "Native" class in "dart:_js_helper".
198198
///
199199
/// This function works regardless of whether the CFE is evaluating constants,

pkg/compiler/lib/src/common/elements.dart

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1228,34 +1228,34 @@ abstract class CommonElements {
12281228
class KCommonElements extends CommonElements {
12291229
KCommonElements(super.dartTypes, super.env);
12301230

1231-
// From package:js
1231+
// From dart:js_interop
12321232

12331233
late final ClassEntity? jsAnnotationClass1 = _findClassOrNull(
1234-
packageJsLibrary,
1234+
dartJsInteropLibrary,
12351235
'JS',
12361236
);
12371237

12381238
late final ClassEntity? jsAnonymousClass1 = _findClassOrNull(
1239-
packageJsLibrary,
1239+
dartJsInteropLibrary,
12401240
'_Anonymous',
12411241
);
12421242

1243-
// From dart:_js_annotations
1243+
// From package:js
12441244

12451245
late final ClassEntity? jsAnnotationClass2 = _findClassOrNull(
1246-
dartJsAnnotationsLibrary,
1246+
packageJsLibrary,
12471247
'JS',
12481248
);
12491249

12501250
late final ClassEntity? jsAnonymousClass2 = _findClassOrNull(
1251-
dartJsAnnotationsLibrary,
1251+
packageJsLibrary,
12521252
'_Anonymous',
12531253
);
12541254

1255-
// From dart:js_interop
1255+
// From dart:_js_annotations
12561256

12571257
late final ClassEntity? jsAnnotationClass3 = _findClassOrNull(
1258-
dartJsInteropLibrary,
1258+
dartJsAnnotationsLibrary,
12591259
'JS',
12601260
);
12611261

pkg/compiler/lib/src/ir/annotations.dart

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -340,19 +340,21 @@ String? _getJsInteropName(ir.Constant constant) {
340340
}
341341

342342
bool _isAnonymousJsInterop(ir.Constant constant) {
343-
return constant is ir.InstanceConstant &&
344-
constant.classNode.name == '_Anonymous' &&
345-
(constant.classNode.enclosingLibrary.importUri == Uris.packageJS ||
346-
constant.classNode.enclosingLibrary.importUri ==
347-
Uris.dartJSAnnotations);
343+
if (constant is ir.InstanceConstant &&
344+
constant.classNode.name == '_Anonymous') {
345+
final importUri = constant.classNode.enclosingLibrary.importUri;
346+
return importUri == Uris.packageJS || importUri == Uris.dartJSInterop;
347+
}
348+
return false;
348349
}
349350

350351
bool _isStaticInterop(ir.Constant constant) {
351-
return constant is ir.InstanceConstant &&
352-
constant.classNode.name == '_StaticInterop' &&
353-
(constant.classNode.enclosingLibrary.importUri == Uris.packageJS ||
354-
constant.classNode.enclosingLibrary.importUri ==
355-
Uris.dartJSAnnotations);
352+
if (constant is ir.InstanceConstant &&
353+
constant.classNode.name == '_StaticInterop') {
354+
final importUri = constant.classNode.enclosingLibrary.importUri;
355+
return (importUri == Uris.packageJS || importUri == Uris.dartJSInterop);
356+
}
357+
return false;
356358
}
357359

358360
class PragmaAnnotationData {

pkg/front_end/testcases/dartdevc/static_interop_erasure/main.dart.strong.expect

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ static method main() → void {
1313
library static_interop;
1414
import self as sta;
1515
import "dart:_js_annotations" as _js;
16+
import "dart:js_interop" as js_;
1617
import "dart:core" as core;
17-
import "dart:js_util" as js_;
18+
import "dart:js_util" as js_2;
1819
import "dart:_js_helper" as _js2;
1920

2021
import "package:js/js.dart";
@@ -24,9 +25,9 @@ import "package:js/js.dart";
2425
class StaticJSClass extends core::Object {
2526
external static factory •() → sta::StaticJSClass;
2627
static synthetic method _#new#tearOff() → sta::StaticJSClass
27-
return js_::_callConstructorUnchecked0<sta::StaticJSClass>(js_::_getPropertyTrustType<core::Object>(_js2::staticInteropGlobalContext, "JSClass"));
28+
return js_2::_callConstructorUnchecked0<sta::StaticJSClass>(js_2::_getPropertyTrustType<core::Object>(_js2::staticInteropGlobalContext, "JSClass"));
2829
static factory factory() → sta::StaticJSClass {
29-
return js_::_callConstructorUnchecked0<sta::StaticJSClass>(js_::_getPropertyTrustType<core::Object>(_js2::staticInteropGlobalContext, "JSClass"));
30+
return js_2::_callConstructorUnchecked0<sta::StaticJSClass>(js_2::_getPropertyTrustType<core::Object>(_js2::staticInteropGlobalContext, "JSClass"));
3031
}
3132
static synthetic method _#factory#tearOff() → sta::StaticJSClass
3233
return sta::StaticJSClass::factory();
@@ -42,7 +43,7 @@ constants {
4243
#C2 = _js::JS {name:#C1}
4344
#C3 = "JSClass"
4445
#C4 = _js::JS {name:#C3}
45-
#C5 = _js::_StaticInterop {}
46+
#C5 = js_::_StaticInterop {}
4647
}
4748

4849

pkg/front_end/testcases/dartdevc/static_interop_erasure/main.dart.strong.outline.expect

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@ static method main() → void
1010
library static_interop;
1111
import self as self2;
1212
import "dart:_js_annotations" as _js;
13+
import "dart:js_interop" as js_;
1314
import "dart:core" as core;
1415

1516
import "package:js/js.dart";
1617

1718
@_js::JS::•("JSClass")
18-
@_js::staticInterop
19+
@js_::staticInterop
1920
class StaticJSClass extends core::Object {
2021
external static factory •() → self2::StaticJSClass;
2122
static synthetic method _#new#tearOff() → self2::StaticJSClass

pkg/front_end/testcases/dartdevc/static_interop_erasure/main.dart.strong.transformed.expect

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ static method main() → void {
1313
library static_interop;
1414
import self as sta;
1515
import "dart:_js_annotations" as _js;
16+
import "dart:js_interop" as js_;
1617
import "dart:core" as core;
17-
import "dart:js_util" as js_;
18+
import "dart:js_util" as js_2;
1819
import "dart:_js_helper" as _js2;
1920

2021
import "package:js/js.dart";
@@ -24,9 +25,9 @@ import "package:js/js.dart";
2425
class StaticJSClass extends core::Object {
2526
external static factory •() → sta::StaticJSClass;
2627
static synthetic method _#new#tearOff() → sta::StaticJSClass
27-
return js_::_callConstructorUnchecked0<sta::StaticJSClass>(js_::_getPropertyTrustType<core::Object>(_js2::staticInteropGlobalContext, "JSClass"));
28+
return js_2::_callConstructorUnchecked0<sta::StaticJSClass>(js_2::_getPropertyTrustType<core::Object>(_js2::staticInteropGlobalContext, "JSClass"));
2829
static factory factory() → sta::StaticJSClass {
29-
return js_::_callConstructorUnchecked0<sta::StaticJSClass>(js_::_getPropertyTrustType<core::Object>(_js2::staticInteropGlobalContext, "JSClass"));
30+
return js_2::_callConstructorUnchecked0<sta::StaticJSClass>(js_2::_getPropertyTrustType<core::Object>(_js2::staticInteropGlobalContext, "JSClass"));
3031
}
3132
static synthetic method _#factory#tearOff() → sta::StaticJSClass
3233
return sta::StaticJSClass::factory();
@@ -42,7 +43,7 @@ constants {
4243
#C2 = _js::JS {name:#C1}
4344
#C3 = "JSClass"
4445
#C4 = _js::JS {name:#C3}
45-
#C5 = _js::_StaticInterop {}
46+
#C5 = js_::_StaticInterop {}
4647
}
4748

4849

pkg/front_end/testcases/general/constants/js_semantics/issue46123.dart.strong.expect

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ library;
1111
//
1212
import self as self;
1313
import "dart:_js_annotations" as _js;
14+
import "dart:js_interop" as js_;
1415
import "dart:core" as core;
1516

1617
import "package:js/js.dart";
@@ -29,7 +30,7 @@ static method main() → dynamic {}
2930
constants {
3031
#C1 = null
3132
#C2 = _js::JS {name:#C1}
32-
#C3 = _js::_Anonymous {}
33+
#C3 = js_::_Anonymous {}
3334
}
3435

3536

pkg/front_end/testcases/general/constants/js_semantics/issue46123.dart.strong.modular.expect

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ library;
1111
//
1212
import self as self;
1313
import "dart:_js_annotations" as _js;
14+
import "dart:js_interop" as js_;
1415
import "dart:core" as core;
1516

1617
import "package:js/js.dart";
@@ -29,7 +30,7 @@ static method main() → dynamic {}
2930
constants {
3031
#C1 = null
3132
#C2 = _js::JS {name:#C1}
32-
#C3 = _js::_Anonymous {}
33+
#C3 = js_::_Anonymous {}
3334
}
3435

3536

pkg/front_end/testcases/general/constants/js_semantics/issue46123.dart.strong.outline.expect

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
library;
22
import self as self;
33
import "dart:_js_annotations" as _js;
4+
import "dart:js_interop" as js_;
45
import "dart:core" as core;
56

67
import "package:js/js.dart";
78

89
@_js::JS::•()
9-
@_js::anonymous
10+
@js_::anonymous
1011
class ParallaxOptions extends core::Object {
1112
external static factory •() → self::ParallaxOptions;
1213
static synthetic method _#new#tearOff() → self::ParallaxOptions

pkg/front_end/testcases/general/constants/js_semantics/issue46123.dart.strong.transformed.expect

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ library;
1111
//
1212
import self as self;
1313
import "dart:_js_annotations" as _js;
14+
import "dart:js_interop" as js_;
1415
import "dart:core" as core;
1516

1617
import "package:js/js.dart";
@@ -29,7 +30,7 @@ static method main() → dynamic {}
2930
constants {
3031
#C1 = null
3132
#C2 = _js::JS {name:#C1}
32-
#C3 = _js::_Anonymous {}
33+
#C3 = js_::_Anonymous {}
3334
}
3435

3536

0 commit comments

Comments
 (0)