Skip to content

Commit

Permalink
[dart2wasm] Make dart.library.js false in conditional imports (attemp…
Browse files Browse the repository at this point in the history
…t 2)

This change removes the implementation of `dart:js` for dart2wasm. The
code is no longer in use and the compiler already provides a static
error if you import `dart:js` internally.

By removing the implementation from the libraries.json spec, we also
show this as unaccessible on conditional imports. This will allow
developers to distinguish JS and Wasm backends

This adapts the original implementation in
https://dart-review.googlesource.com/c/sdk/+/368642 with a few small
changes, but keeps around the existing allowances on `package:js`. Those
can be addressed separately to reduce the disruption from this change.

Closes #55266.

Change-Id: I0d01a424f2fdb4f48879bd1a41c847a92439e74a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/380583
Reviewed-by: Ömer Ağacan <omersa@google.com>
Commit-Queue: Sigmund Cherem <sigmund@google.com>
  • Loading branch information
sigmundch authored and Commit Queue committed Aug 16, 2024
1 parent eb887c2 commit e8a049f
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 128 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,16 @@ number, like `.`, `x`, or the `e` in scientific notation.
- Added `toJSCaptureThis` so `this` is passed in from JavaScript to the
callback as the first parameter.

### Tools

#### Wasm compiler (dart2wasm)

- The condition `dart.library.js` is now false on conditional imports in
dart2wasm. Note that it was already a static error to import `dart:js`
directly (see [#55266][]).

[#55266]: https://github.com/dart-lang/sdk/issues/55266

## 3.5.0

### Language
Expand Down
1 change: 0 additions & 1 deletion pkg/_js_interop_checks/lib/js_interop_checks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ class JsInteropChecks extends RecursiveVisitor {
'package:js/js.dart',
'package:js/js_util.dart',
'dart:js_util',
'dart:js',
'dart:ffi',
];

Expand Down
3 changes: 1 addition & 2 deletions pkg/dart2wasm/lib/target.dart
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ class WasmTarget extends Target {
'dart:developer',
'dart:ffi',
'dart:io',
'dart:js',
'dart:js_interop',
'dart:js_interop_unsafe',
'dart:js_util',
Expand Down Expand Up @@ -202,7 +201,7 @@ class WasmTarget extends Target {
// Flutter's dart:ui is also package:ui (in test mode)
if (importerString.startsWith('package:ui/')) return true;

// package:js can import dart:js* & dart:_js_*
// package:js can import dart:js_util & dart:_js_*
if (importerString.startsWith('package:js/')) return true;

return false;
Expand Down
116 changes: 0 additions & 116 deletions sdk/lib/_internal/wasm/lib/js_patch.dart

This file was deleted.

4 changes: 0 additions & 4 deletions sdk/lib/libraries.json
Original file line number Diff line number Diff line change
Expand Up @@ -333,10 +333,6 @@
"_internal/wasm/lib/isolate_patch.dart"
]
},
"js": {
"uri": "js/js.dart",
"patches": "_internal/wasm/lib/js_patch.dart"
},
"js_interop": {
"uri": "js_interop/js_interop.dart",
"patches": "_internal/wasm/lib/js_interop_patch.dart"
Expand Down
3 changes: 0 additions & 3 deletions sdk/lib/libraries.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,6 @@ wasm_common:
uri: isolate/isolate.dart
patches:
- "_internal/wasm/lib/isolate_patch.dart"
js:
uri: js/js.dart
patches: _internal/wasm/lib/js_patch.dart
js_interop:
uri: js_interop/js_interop.dart
patches: _internal/wasm/lib/js_interop_patch.dart
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
// Check that dart2wasm disallows these interop libraries from being imported.

/**/ import 'dart:js';
// ^
// [web] JS interop library 'dart:js' can't be imported when compiling to Wasm.
// ^
// [web] Dart library 'dart:js' is not available on this platform.

/**/ import 'dart:js_util';
// ^
Expand Down

0 comments on commit e8a049f

Please sign in to comment.