Changes: ``` > git log --format="%C(auto) %h %s" 5c3e2c3..58b0a10 https://dart.googlesource.com/core.git/+/58b0a108 Make it possible to add default subcommand (925) https://dart.googlesource.com/core.git/+/e43ff949 feat(collection): Replace quickSort with pdqsort for performance and robustness (922) https://dart.googlesource.com/core.git/+/f2efaaf3 Bump actions/checkout from 5.0.0 to 6.0.0 in the github-actions group (924) https://dart.googlesource.com/core.git/+/33b52327 Add `separated`, `separatedList` and `separate` to iterables and lists. (919) https://dart.googlesource.com/core.git/+/20ed9668 Add use_null_aware_elements to recommended (923) https://dart.googlesource.com/core.git/+/e6c3810c [crypto] remove the -wip to release new version (921) https://dart.googlesource.com/core.git/+/f7a786ac Bump actions/stale from 10.0.0 to 10.1.0 in the github-actions group (920) https://dart.googlesource.com/core.git/+/018e1dc7 fix(crypto): update conditional import for js interop library (915) https://dart.googlesource.com/core.git/+/9fefb52b Make Int64 default constructor non-const in native mode (916) https://dart.googlesource.com/core.git/+/f00841de Bump the github-actions group with 2 updates (914) https://dart.googlesource.com/core.git/+/7fee9c06 Fix `Int64.operator ==` (911) https://dart.googlesource.com/core.git/+/a4dc8738 Implement `Int64` as a wrapper for `int` when targeting native and Wasm (905) https://dart.googlesource.com/core.git/+/1aa58ef5 [fixnum] update the min. required dart sdk (907) https://dart.googlesource.com/core.git/+/60f2b5d3 Run fixnum tests with dart2wasm (906) ``` Diff: https://dart.googlesource.com/core.git/+/5c3e2c38df268be2347f3aad30ced0147dd012bb..58b0a108b4d1310465e8482d6629357891df1cb1/ Change-Id: Ibde49f27d1d26b8fc1aad3fd7df3efd924796b33 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/467361 Reviewed-by: Martin Kustermann <kustermann@google.com> Commit-Queue: Slava Egorov <vegorov@google.com>
The Dart Dev Compiler (DDC) is a fast, modular compiler that generates modern JavaScript (EcmaScript 6). Its primary use today is to support fast, iterative development of Dart web applications for Chrome and other modern browsers.
Support
DDC is meant to be used by build systems like bazel, build_web_compilers and
flutter_tools under the hood. This compiler is not meant to be used by
application developers directly.
While at times the code generated by this compiler may be readable, the representation is not meant to be stable and can break with time. For that reason we do not recommend using this compiler to export Dart as a JavaScript module.
The recommended approach to compile Dart to JavaScript is to use dart compile js instead. If you intend to make a public JavaScript API based on a Dart
implementation, such API should be declared explicitly using the standard
Dart-JSInterop mechanisms.
Implementation details
Modularity
Unlike Dart2JS, DDC does not require an entire Dart application. Instead, it operates modularly: it compiles a set of Dart files into a JavaScript module. A DDC compilation step requires a set of input Dart files and a set of summaries of dependencies. It performs modular type checking as part of this compilation step, and, if the input type checks, it generates a JavaScript module. The browser (i.e., the JavaScript runtime) loads and links the generated modules when running the application. During development, a compilation step only needs to be rerun if the Dart files or summaries it relies upon change. For most changes, only a very small part of your code will require recompilation. Moreover, modules that are unchanged can be cached in the browser.
Representation
Currently Dart classes are mapped to ES6 classes, Dart fields to ES6 properties, Dart getters/setters to ES6 getters/setters, Dart methods to ES6 methods, and so on. Often names are preserved and calling conventions are natural JavaScript ones.
Some Dart concepts don't map directly:
-
Libraries. Multiple Dart libraries are mapped to a single JS module. Each library appears as a first class object in the generated JS module, with its top-level symbols as members. We currently use a heuristic (based upon file paths) to ensure unique naming of generated library objects.
-
Generics. Dart generics are reified, i.e., they are preserved at runtime. Generic classes are mapped to factories that, given one or more type parameters, return an actual ES6 class (e.g.,
HashMap$(core.String, core.int)produces a class that represents a HashMap from strings to ints). Similarly, generic methods are mapped to factories that, given one or more type parameters, return a method. -
Dynamic. DDC supports dynamically typed code (i.e., Dart's
dynamictype), but it will typically generate less readable and less efficient ES6 output as many type checks must be deferred to runtime. All dynamic operations are invoked via runtime helper code. -
Constructors. Dart supports multiple, named and factory constructors for a given class with a different initialization order for fields. Today, these are mapped to instance or static methods on the generated ES6 class.
-
Private members. Dart maps private members (e.g., private fields or methods) to ES6 symbols. For example,
a._xmay map toa[_x]where_xis a symbol only defined in the scope of the generated library. -
Scoping. Dart scoping rules and reserved words are slightly different than JavaScript. While we try to preserve names wherever possible, in certain cases, we are required to rename.
In general, the current conventions (i.e., the Application Binary Interface or ABI in compiler terminology) should not be considered stable. We reserve the right to change these in the future.
Browser support
DDC currently supports Chrome stable (though users have had success running on FireFox and Safari).