Flutter Engine
The Flutter Engine
|
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.
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.
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.
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:
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
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.a._x
may map to a[_x]
where _x
is a symbol only defined in the scope of the generated library.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.
DDC currently supports Chrome stable (though users have had success running on FireFox and Safari).