| commit | 2b3823f4a9309c23b0b1d1c0faa31df5f9a24c54 | [log] [tgz] |
|---|---|---|
| author | Olivier Chafik <ochafik@google.com> | Wed Feb 10 18:22:21 2016 |
| committer | Olivier Chafik <ochafik@google.com> | Wed Feb 10 18:22:21 2016 |
| tree | f9dd649fba376a087a273ed59d25911838e0b703 | |
| parent | 1a679da972494215f68067ce52f36fd5fcecfaef [diff] |
Emit TypeScript / Closure ES6_TYPED type annotations in --closure mode (instead of closure comments).
- Replaced ClosureType by a general JS.TypeRef, used in AST for identifier types, return types
- Convert DartType to JS.TypeRef (in mixin JsTypeRefCodegen), including type parameters (also added to AST in Fun & ClassExpression)
- Emit field declarations expected by TS
- Wrote a TypeScriptTypePrinter (mixed in by Printer) and a ClosureTypePrinter (might disappear soon)
- Simplified annotation code, called in more places (seems to gives more source info)
Example input:
List/*<T>*/ func/*<T>*/(List/*<T>*/ items, dynamic/*=T*/ seed) {}
class Foo<T> {
int i;
static var x;
Foo(this.i, o, {String v : "?"}) {}
}
Output:
function func<T>(items: core.List<T>, seed: T): core.List<T> {}
const Foo$ = dart.generic(function(T) {
class Foo<T> extends core.Object {
i: number;
static x;
Foo(i: number, o, {v = "?"}: {v?: string} = {}) {
this.i = i;
}
}
...
Foo.x = null;
return Foo;
});
Known remaining issues:
- typedefs expect a `type Callback = (...) => ...;` statement
- `exports` is a reserved keyword in TS (either we change the way we do exports, or we'll need a different temp + extra type annotations of the default-exported object).
- Generic type is currently locked inside the generic call. Might be able to solve by exporting signatures in .d.ts file, or changing the way we do generics.
BUG=
R=jmesserly@google.com
Review URL: https://codereview.chromium.org/1676463002 .
The Dart Dev Compiler (DDC) is an experimental development tool and transpiler. It is at a very early stage today. Its aims include the following:
DDC attempts to map to idiomatic EcmaScript 6 (ES6) as cleanly as possible. To do this while cohering to Dart semantics, DDC relies heavily on static type information, static checking, and runtime assertions.
DDC is intended to support a very large subset of Dart. If a program does not statically check, DDC will not result in valid generated code. Our goal is that a program execution (of a valid program) that runs without triggering runtime assertions should run the same on other Dart platforms under checked mode or production mode.
DDC does support untyped Dart code, but it will typically result in less readable and less efficient ES6 output.
DDC has the following project goals:
DDC is still in a very early stage as highlighted by our choice of ES6. ES6 itself is in active development across all modern browsers, but at various stages of support: kangax.github.io/compat-table/es6.
We are targeting the subset of ES6 supported in Chrome.
To try out DDC and/or give feedback, please read our usage page.