dart-sdk/pkg/dev_compiler
Nate Bosch 4c8654eb10 Revert "Sync packages from shelf mono repo"
This reverts commit 243ac04dbf.

Reason for revert: Breaks roll to flutter engine still.

Original change's description:
> Sync packages from shelf mono repo
>
> Keep the DEPS entries and directories for the old locations for these
> packages, but ignore them in `generate_package_config`. Removing the
> hashes and directories would invalidate the DEPS file in the flutter
> engine repository.
>
> Add the `shelf` repository to the specially handled directories with
> nested packages in `generate_package_config`.
>
> Update path dependencies in pubspecs to the new location.
>
> Reland of https://dart-review.googlesource.com/c/sdk/+/243929
> without the removal of the old directory locations.
>
> R=​devoncarew@google.com
>
> Change-Id: I3d3b3eb0722f3eba518a6a1034ed9c24f83c70f0
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/244300
> Reviewed-by: Devon Carew <devoncarew@google.com>
> Commit-Queue: Nate Bosch <nbosch@google.com>

TBR=devoncarew@google.com,nbosch@google.com

Change-Id: Ied6d9aa685208eddea6d82d04ca8876937651051
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/244302
Reviewed-by: Nate Bosch <nbosch@google.com>
Commit-Queue: Devon Carew <devoncarew@google.com>
Reviewed-by: Devon Carew <devoncarew@google.com>
2022-05-12 00:00:34 +00:00
..
bin [ddc] Move dartdevc.dart to lib/. 2021-11-16 18:50:52 +00:00
lib [ddc] Stubbing package:dart2js_runtime_metrics 2022-05-11 22:31:45 +00:00
test Read package_config.json in more tests 2022-05-11 18:58:44 +00:00
tool [ddc] Add flag to use the new runtime type system 2022-05-10 23:47:04 +00:00
web lints 2.0 fixes 2022-03-18 01:42:47 +00:00
.gitignore
analysis_options.yaml [dev_compiler] remove the dep on package:cli_util 2022-02-11 00:50:31 +00:00
codereview.settings
LICENSE Update LICENSE 2021-04-07 10:28:38 +00:00
OWNERS [infra] Add OWNERS to the Dart SDK 2022-02-14 14:06:34 +00:00
pubspec.yaml Revert "Sync packages from shelf mono repo" 2022-05-12 00:00:34 +00:00
README.md [ddc] update documentation 2022-01-27 21:13:41 +00:00
STRONG_MODE.md [dartdevc] add forwarding from old docs to new info 2019-12-10 22:53:26 +00:00

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 dynamic type), 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._x may map to a[_x] where _x is 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).