Skip to content

[package:js] @JS() Mixins can no longer be used with other @JS() classes since Dart SDK 2.12.0+Β #47536

Open
@ganigeorgiev

Description

@ganigeorgiev

@JS() annotated mixins (or classes used as mixins) can no longer be used together with other @JS() classes since Dart >= 2.12.0-stable (I'm testing with the Stable channel builds for Linux from https://dart.dev/get-dart/archive).

Consider the following example:

// pubspec.yaml
name: demo
version: 1.0.0
description: @JS() Mixins

environment:
  sdk: '>=2.7.0 <3.0.0'

dependencies:
  js: ^0.6.2

dev_dependencies:
  build_runner: ^1.10.0
  build_web_compilers: ^2.9.0
// web/main.dart
@JS()
library main;

import 'package:js/js.dart';

@JS()
@anonymous
mixin DemoMixin {
  external bool demo();
}

@JS()
@anonymous
class DemoClass with DemoMixin {
}

void main() {}

The above fails with the following error:

[SEVERE] build_web_compilers:entrypoint on web/main.dart (cached): AssetNotFoundException: demo|web/main.unsound.ddc.js.metadata

[SEVERE] build_web_compilers:ddc on web/main.ddc.module (cached): Error compiling dartdevc module:demo|web/main.unsound.ddc.js

web/main.dart:15:7: Error: JS interop class 'DemoClass' cannot extend Dart class 'Object with DemoMixin'.
Try removing the JS interop annotation or adding it to the parent class.
class DemoClass with DemoMixin {
      ^

Everything compiles OK and without errors when using Dart <= 2.10.5-stable.

After some digging through the commits history, It seems that the change was introduced with commit ed009af but as far as I understand it is intended to prevent extending JS interop classes with plain Dart classes (and the opposite - extending plain Dart classes with JS interop ones). Also note that the test case from the above commit doesn't take mixins in consideration.

Am I missing something? Is this an intended behavior?

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-web-jsIssues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop.web-js-interopIssues that impact all js interopweb-triage-0repro is available

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions