Commit Graph

272 Commits

Author SHA1 Message Date
John Messerly b8ae9f9b77 a few small refactorings to closure workarounds
* factor the class heritage workaround so it's out of the way & easier to remove later.
* always emit type parameters in the AST, and pass the flag to the printer to skip printing them.
* cleanup an unnecessary sync* method for closure field decls.
* also, reformats. I think I forgot to do that in previous CL.

R=vsm@google.com

Review URL: https://codereview.chromium.org/1767803002 .
2016-03-08 15:56:18 -08:00
Vijay Menon 883972e37a Fix deprecation message
TBR=jmesserly@google.com

Review URL: https://codereview.chromium.org/1775673002 .
2016-03-07 15:33:01 -08:00
John Messerly 93251ee241 upgrade to latest analyzer
fixes https://github.com/dart-lang/dev_compiler/issues/471

Changes here are:
* Analyzer now infers list/map literals
* Analyzer changed how isPotentiallyMutated* APIs work, so we need to track current function
* Another fix to arrow functions. We shouldn't skip generating covariant arg checks. If there were any, we use `=> { block }` form rather than `=> expr` form.

R=vsm@google.com

Review URL: https://codereview.chromium.org/1757343002 .
2016-03-03 11:32:54 -08:00
John Messerly d3932e1c50 Add a few more known non-null cases
Improves handling of identifiers and known elements, the `identical` function, and generative constructors.

R=ochafik@google.com, vsm@google.com

Review URL: https://codereview.chromium.org/1752193002 .
2016-03-02 13:32:27 -08:00
John Messerly 67b24939cd refactor/simplify nullable inference code
Some of the high level changes are:
* visit catch body, fixes #463
* handle temps created by the compiler. These were in some cases treated incorrectly as non-null (see tests diff)
* compute nullable in the same pass as visiting assignments
* simplify visiting += and ++, fix ++ (it was dead code, #463)
* simplify _isNullable
* if we fail to see a variable declaration, treat it as nullable
* stack trace in catch is treated as non-null

R=vsm@google.com

Review URL: https://codereview.chromium.org/1751963002 .
2016-03-01 16:44:05 -08:00
John Messerly abf6065dc2 more function refactoring
Two more small bug caught/fixed in the process:
* Dart lambdas must generate as `=>` functions or we'll get the wrong `this`
* Another case where generators we using destructuring in a mismatched way

R=vsm@google.com

Review URL: https://codereview.chromium.org/1736723002 .
2016-02-24 16:54:07 -08:00
John Messerly ca46b80811 simplify generation of functions
fixes incorrect destructuring codegen, and encapsulates type parameter comments better in _emitFunctionBody

R=vsm@google.com

Review URL: https://codereview.chromium.org/1729933002 .
2016-02-24 09:18:46 -08:00
John Messerly d959316526 refactor: avoid parts
we try to avoid "parts" except in js_ast (because that will be split out into its own package)

R=vsm@google.com

Review URL: https://codereview.chromium.org/1724463003 .
2016-02-22 16:01:35 -08:00
Vijay Menon ce985ef38d Support StackTrace.current
This was recently added to the Dart SDK.  Breaking Angular in DDC via stack_trace package.

R=jmesserly@google.com

Review URL: https://codereview.chromium.org/1720473002 .
2016-02-19 14:25:21 -08:00
Vijay Menon 93a627bf44 Wrapperless dart:html and friends
This reuses the dart2js code.

R=jacobr@google.com, jmesserly@google.com

Review URL: https://codereview.chromium.org/1700153002 .
2016-02-18 13:57:59 -08:00
Vijay Menon a9bcaf6c5b Fix travis
This also regens based on the latest analyzer.  Looks like most improvements on the code.

See #456

TBR=jmesserly@google.com

Review URL: https://codereview.chromium.org/1710583002 .
2016-02-17 13:12:52 -08:00
Olivier Chafik 8a28ce3c65 Introduce _emitParameterReferences to avoid mixing params with param references.
BUG=
R=vsm@google.com

Review URL: https://codereview.chromium.org/1701583003 .
2016-02-16 14:39:15 +00:00
Vijay Menon fce423e295 Get travis back to green
Just commenting out the pub run test step.

TBR=ochafik@google.com

Review URL: https://codereview.chromium.org/1690393003 .
2016-02-12 12:18:51 -08:00
Vijay Menon 3f85417199 Support for dart:typed_data
Fixes #441
Fixes #444

R=jmesserly@google.com

Review URL: https://codereview.chromium.org/1680263002 .
2016-02-11 14:36:27 -08:00
Olivier Chafik 4ad758998a 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 .
2016-02-10 18:22:21 +00:00
Olivier Chafik 0afdd61031 Improve --destructure-named-params:
- Destructure named params that clash with JS reserved names:
  `f({arguments = 1}) {}` becomes `function f({['arguments']: arguments$ = 1} = {}) {}`
- Use ES6 default params for positional & optional parameters
- Added simple tests

BUG=
R=jmesserly@google.com

Review URL: https://codereview.chromium.org/1677863002 .
2016-02-09 16:46:32 +00:00
Vijay Menon a4d4a8dd54 Infra for running lib tests
This is in prep for #441

R=jmesserly@google.com

Review URL: https://codereview.chromium.org/1673863002 .
2016-02-05 14:49:16 -08:00
Olivier Chafik 98b21b030e Revert "Use a symbol for static length/name (and other Function properties) for Closure, to avoid ES5->ES6 lowering bug (https://github.com/google/closure-compiler/issues/1460)."
This reverts commit a637e1b048487629d0d44620eb41e703531ce18d.
2016-02-03 20:35:59 +00:00
Olivier Chafik 84043ffd1e Use a symbol for static length/name (and other Function properties) for Closure, to avoid ES5->ES6 lowering bug (https://github.com/google/closure-compiler/issues/1460).
This is part of the overall "simple closure" effort (issue #312)

BUG=
R=jmesserly@google.com

Review URL: https://codereview.chromium.org/1630963003 .
2016-02-03 20:25:07 +00:00
Olivier Chafik f7f21ca65e Create local alias for super class in --closure mode (issue #312)
Closure compiler chokes on super classes that aren't qualified paths.

(example: http://goo.gl/5mHC7S)

BUG=
R=jmesserly@google.com

Review URL: https://codereview.chromium.org/1638533004 .
2016-02-03 20:21:12 +00:00
John Messerly dee054e23b fixes #415, correct type for map literals
Not sure why this wasn't implemented. Lists seem to be okay.

R=vsm@google.com

Review URL: https://codereview.chromium.org/1611753002 .
2016-02-01 15:39:54 -08:00
John Messerly f43b756b2f fix #43, remove => workaround
also fixes node.js test to use a temp directory, instead of creating "tmp" under dev_compiler checkout

R=vsm@google.com

Review URL: https://codereview.chromium.org/1643523008 .
2016-02-01 12:54:58 -08:00
Vijay Menon 0fbd992505 Builds / serves multiple HTML files.
With this, I can build multiple Angular samples simultaneously:

[dist/dart/playground/build/web] dart ~/git/dev_compiler/bin/dartdevc.dart -o /tmp/ddc-out --force-compile src/*/index.html

Fixes #430

R=jmesserly@google.com

Review URL: https://codereview.chromium.org/1645343002 .
2016-01-29 10:13:28 -08:00
Olivier Chafik edaf069dba Add --modules=node support
- Force import order in all sdk files + simplify module builders
- Stub a node_test.sh with hello world + DeltaBlue (to be expanded to language tests in a followup change)
- Use global_ from dart:_runtime in html lib
- Better export for symbols that node chokes upon: throw, const, void, implements, export... (define as throw_ locally, with proper local resolution, then export as throw).
- Cleanup node module builder

BUG=
R=jmesserly@google.com

Review URL: https://codereview.chromium.org/1633003002 .
2016-01-29 10:01:48 +00:00
Vijay Menon b56617b947 Add CustomEvent
This just mechanically adds CustomEvent.

Fixes #423

R=jacobr@google.com

Review URL: https://codereview.chromium.org/1616263005 .
2016-01-28 17:04:13 -08:00
Vijay Menon a693930830 Roll analyzer to 0.27.2-alpha.1
R=jmesserly@google.com

Review URL: https://codereview.chromium.org/1641643004 .
2016-01-28 15:35:59 -08:00
Vijay Menon c274b6f9e9 Regen tests
Forgot to do this after changing the flatten tests.  pkg:collection also updated with some file moves.

R=jmesserly@google.com

Review URL: https://codereview.chromium.org/1642903004 .
2016-01-28 14:39:15 -08:00
Vijay Menon bd34d574be Skip flatten tests
R=jmesserly@google.com

Review URL: https://codereview.chromium.org/1643003003 .
2016-01-28 14:24:05 -08:00
Olivier Chafik 04d4be0982 Less dart.notNull checks for local vars using flow-insensitive nullability inference.
Within some AST context (at library granularity, for convenience), we
collect all the assignments to local vars:
- Declaration with no initializer amounts to `null` assignment
- Assignment ops are expanded naively: `x++` yield an assigned value of
`x + 1`, etc

We detect "trivially nullable" variables (e.g. `var x;`, `x =
breaking.out;`) by spotting assigned values that are nullable under the
optimistic assumption that all known variables are non-nullable.

Then we build a nullability dependency graph in linear time: whenever
we see `x = y;`, we know that "y is nullable" implies "x is nullable".

Finally, we propagate "trivial nullabilities" through that graph: any
variable that wasn't reached is deemed not-nullable.

(this is similar to mark and sweep garbage collection, where the roots
are the "trivially nullable" variables; credits to leafpetersen@ for
linear solution)
2016-01-28 15:47:49 +00:00
Vijay Menon 731dc0633b Handle local files better in server mode
We're already serving sources from the original directory (for source
maps).  This lets us serve other resources as well.  Makes it simpler
to run angular todo and other apps with xhr'ed data.

R=jmesserly@google.com

Review URL: https://codereview.chromium.org/1644673002 .
2016-01-27 14:03:52 -08:00
John Messerly 0b646eb520 fixes #427, static fields emitted outside the scope of their class
mainly, this backs off of some readability optimizations around static and top-level fields that were too aggressive. On their own, they were okay, but they collide with the library-cycle issues. Once we can remove that issue, we could consider restoring some of this. In the meantime, simplicity is good.

The new operation in the declaration loader is to allow us to see if an initializer has all its dependencies satisfied, but without changing any ordering if they are not.

R=vsm@google.com

Review URL: https://codereview.chromium.org/1636233002 .
2016-01-27 09:35:40 -08:00
Vijay Menon d043d05544 Rebase on latest package:collection
pub get now pulls in a new one

TBR=jmesserly@google.com

Review URL: https://codereview.chromium.org/1645633002 .
2016-01-27 08:49:43 -08:00
Vijay Menon a2ced17c9a Run format
Looks like a recent commit missed a format / presubmit.

TBR=jmesserly@google.com,ochafik@google.com

Review URL: https://codereview.chromium.org/1631303003 .
2016-01-26 09:54:26 -08:00
Olivier Chafik 4eec9f5ff4 Resolve local paths in es6 modules (+ refactor ModuleBuilder) 2016-01-26 14:00:46 +00:00
Olivier Chafik adf6842f6c Initial --modules=es6 support
Known issues:
- Import syntax: using 'dart/core' right now, but should be
'./dart/core' or something else?
- _jsModuleValue not supported in es6 output yet (how is it meant to be
used?)

BUG=
R=jmesserly@google.com

Review URL: https://codereview.chromium.org/1612083002 .
2016-01-24 18:09:59 +00:00
John Messerly 8f83c969d2 rebase expectations
no changes here, just rebases against latest analyzer

R=ochafik@google.com, vsm@google.com

Review URL: https://codereview.chromium.org/1619483003 .
2016-01-22 13:16:09 -08:00
Olivier Chafik fc81df2f43 Rehab test dropped by mistake in c9d909ced98dea2aefe20322a59d18fbab2d93b2 2016-01-22 14:51:33 +00:00
Olivier Chafik 3886194414 Generate _runtime.js from dart (https://github.com/dart-lang/dev_compiler/issues/310)
The following part files were ported from the original .js (lib/runtime/dart/_foo.js -> input_sdk/private/foo.dart):
- input_sdk/private/rtti.dart
- input_sdk/private/types.dart
- input_sdk/private/classes.dart
- input_sdk/private/errors.dart
- input_sdk/private/generators.dart
- input_sdk/private/operations.dart
- input_sdk/private/runtime.dart

Notes:
- Introduced genericTypeConstructor intrinsic: `JS('', '#(type)', genericTypeConstructor(List))` generates `core.List$(type)`
- Used new JS quasiquotes everywhere
- Depends on new internal `@JSExportName` annotation to alias symbols like dart.{as, is, const, assert, export, implements, throw, async, dynamic, void} (see https://codereview.chromium.org/1580413002/)

BUG=
R=jmesserly@google.com

Review URL: https://codereview.chromium.org/1530563003 .
2016-01-21 00:45:31 +00:00
Vijay Menon 077465ddc8 Fixes #412
Adds Screen, Navigator.language, and HTMLHtmlElement to dart:html

R=jacobr@google.com

Review URL: https://codereview.chromium.org/1607073002 .
2016-01-19 13:31:12 -08:00
John Messerly 5b45c6ef87 partial fix for #414, avoid dcall in _convertToDart
this doesn't fix the root call, but still, it's nice to clean up this dead code

R=vsm@google.com

Review URL: https://codereview.chromium.org/1609843002 .
2016-01-19 12:02:06 -08:00
Vijay Menon e907ebb106 Fixes #408
This is a bug on JSON.decode.  This should match the hand fix in #404.

R=jmesserly@google.com

Review URL: https://codereview.chromium.org/1579223002 .
2016-01-12 14:17:40 -08:00
Vijay Menon 6e8375ed0d Added Comment to dart:html
R=jacobr@google.com

Review URL: https://codereview.chromium.org/1577423002 .
2016-01-12 14:16:32 -08:00
Vijay Menon 2a3549a8f5 Fixes #410
This generates calls to methods on may-be-native types property in generic methods.

R=jmesserly@google.com

Review URL: https://codereview.chromium.org/1580803002 .
2016-01-12 09:47:44 -08:00
Leaf Petersen 44f2cf3424 Bump the version number and re-baseline codegen/expect
BUG=
R=vsm@google.com

Review URL: https://codereview.chromium.org/1569783006 .
2016-01-08 13:29:08 -08:00
Vijay Menon 3006795312 Support source maps in server mode
R=jmesserly@google.com

Review URL: https://codereview.chromium.org/1530133003 .
2016-01-07 13:22:03 -08:00
Leaf Petersen 1c119bebb2 Update to latest analyzer
Fixes https://github.com/dart-lang/dev_compiler/issues/393

BUG=
R=jmesserly@google.com

Review URL: https://codereview.chromium.org/1554683002 .
2016-01-05 15:58:50 -08:00
Olivier Chafik 3307317454 JS: Format if statements with no else on a single line
To match Dart style:
https://www.dartlang.org/effective-dart/style/#do-use-curly-braces-for-all-flow-control-structures

(also, that's the style we use in our .js runtime files, so that will help with diffs of the js->dart runtime migration from https://github.com/dart-lang/dev_compiler/issues/310)

BUG=
R=jmesserly@google.com

Review URL: https://codereview.chromium.org/1524843002 .
2015-12-16 19:45:19 +00:00
Vijay Menon e29437a374 First cut of mini dart:html.
This gets us going on Angular.

Note, this is auto-generated from my hacked up versions of the dom scripts.  Still tackling the long tail of sdk errors.

R=jmesserly@google.com, leafp@google.com

Review URL: https://codereview.chromium.org/1528613004 .
2015-12-15 13:08:17 -08:00
Vijay Menon 6ecadc8c19 Run tests on Chrome stable by default
This also disables destructuring by default as Chrome 47 (current
stable) does not support.

R=jmesserly@google.com

Review URL: https://codereview.chromium.org/1507343013 .
2015-12-11 12:18:20 -08:00
Olivier Chafik c64b7bbe9e Pin analyzer version to 0.26.2+1 (newer versions break the build, see issue #393) 2015-12-09 13:29:58 +00:00