Giter Club home page Giter Club logo

angular's Issues

transpiler: add sourcemaps

when an exception is reported the stack trace is from transpiled file, but my code is in source file.

Need to generate source maps for debug code
Need to rewrite stack trace to have original line numbers.

transpiler: support let in dart

let a = 1; should work.

JavaScript's "let" is the same as Dart's "var" -- this is needed to apply more semantically correct transpilation.

Clarify what this project is about

Could you please clarify in the README.md what this project is there for? That is, of course, if you don't mind sharing it with the public :-)

transpiler: handle named parameters

 it('should compile named params when the last argument is a map', function() {
    function f(a, {b, c}) {return a + b + c;}

    expect(f(1, {b: 2, c: 3})).toBe(6);
  });

  it('should compile to a map when keys are quoted', function() {
    function f(m) {return m["a"] + m["b"];}

    expect(f({"a": 1, "b": 2})).toBe(3);
  });

Add throttle argument for $watch

So, I have a snippet of code that I keep copy and pasting all over my controllers for handling "auto-saving" functionality for objects:

var pendingPromise = null;
        //Set up watch to auto save CTA on changes, but throttled once every 500ms.
        $scope.$watch('myObject', function(nv, ov){
            if((nv && ov) && (!_.isEqual(nv, ov))){
                if (pendingPromise) {
                    $timeout.cancel(pendingPromise);
                }

                pendingPromise = $timeout(function () {
                    persistMyObject();
                }, 500, false);
            }
        }, true);

I do this so that the API the underlying service talks to doesn't get inundates w/ requests, especially for ui components like sliders that change the model incrementally very quickly. If would be wonderful if in some later release of Angular if this were condensed down to something like:

$scope.$throttledWatch('myObject', function(nv, ov){
    if(nv){
        persistMyObject();
    }
}, true, 500);

Where 500 is the time in milliseconds to set on the throttle.

window.onerror

Chrome recently landed an awesome new feature where an actual error object is passed to window.onerror. Without an actual error object, it is really difficult make use of the window.onerror because the original context is lost and no stack trace is available. Even libraries like stacktrace.js are unable to work around this.

Any idea if zone.js is able to work around this for IE and FF?

References:
https://code.google.com/p/chromium/issues/detail?id=147127
https://bugzilla.mozilla.org/show_bug.cgi?id=355430
stacktracejs/stacktrace.js#26

Transpiler: should we support Dart libraries ?

As of today each transpiled file as a library statement. The library name is unique and is derived from the file name.

Dart support private members (& functions & variables). Private members start with a "_" prefix.

A private member (/ function / variable) is visible to the entire library (whether it is accessed from the same class or file).

Currently dartanalyzer prints some warnings because "_" prefixed members are accessed from an other file (hence an other library).

What would be the right solution to support this:

  • Support librarystatement in the source code (may be via @LIBRARY('name') if possible),
  • Transform "_" prefixed names,
  • ?

A short term solution could be to avoid "_" prefixed names but we should also have a longer term strategy IMO.

Bare bones change detection

We would like to implement bare bones change detection so that we can unblock ourselves for other parts of the system and work on them in parallel.

https://github.com/mhevery/angular/blob/master/modules/change_detection/src/watch_group.js
https://github.com/mhevery/angular/blob/master/modules/change_detection/src/record.js

I would love to get a very simple change detection going which can only watch simple properties such as foo or bar ie no (foo.bar or foo().bar or anything of that sort)

We should be able to implement this without the need for parser.

class Person {
  var age;
}

var person = new Person();
var pwg = new ProtoWatchGroup();
pwg.watch('age');
var wg = pwg.instantiate();
wg.setContext(person);
var cd = new ChangeDetection(wg);
cd.detectChanges();

Make this test pass:

it('should do simple watching', function() {

Integrate dartanalyzer into build

this implies we need angular.dart file which looks something like this:

library angular.dom.main;

export "annotations/directive.dart";
export "annotations/component.dart";
export "annotations/property.dart";
export "annotations/template.dart";
export "annotations/event.dart";
export "directive_injector/annotations.dart";
export "directive_injector/directive_injector.dart";
export "directive_injector/query.dart";
export "view/view.dart";
export "view/view_ref.dart";
export "view/view_factory.dart";
export "view/view_port.dart";
export "view/view_port_ref.dart";

Don't generate that, but we need something like this as public API.

transpiler: constructor and typed field semantics

  1. Only allow assignments to fields in constructor and translate these assignment into constructor initializers
  2. Make field declaration explicit through @FIELD annotation
  3. Make const constructors in Dart through @CONST annotation

Example:

class Annotation {
  @FIELD('final name:String')
  @FIELD('final age:int')
  @CONST constructor(name:String, age:int) {
    this.name = 'Hello ' + name;
    this.age = age + 0;
  }
}

@Annotation('usage', 5)
class Foo {}

this needs to transpile to:

class Annotation {
  final String name;
  final int age;
  const Annotation(String name, int age): 
     name = 'Hello ' + name,
     age = age + 0;
}

@Annotation('usage', 5)
class Foo {}

transpiler: Error in assertion of return value of nested functions

E.g. in this method traceur says that the return value "true" does not match ArrayOfDirectiveClass. It seems to check the return value of the nested function against the return type of the method...

class Test {
someMethod(directive:Function):ArrayOfDirectiveClass {
    return annotations.filter((annotation) => {
      return annotation instanceof Directive;
    }).map((directiveAnnotation) => {
      return new DirecrtiveClass(directiveAnnotation, directive);
    });
  }

build: add travis-ci

For now run the following:

  • gulp build: automatically runs dartanalyzer, so we get early errors via the static type system of dart
  • karma run: run some basic tests to ensure the JS modules are loading and have correct dependencies

Needs to download dart environment...

transpiler: Refactor the transpiler

From #18 (which has been closed):

Some related question: today there is only one dart_class_transformer.js that has all the transformations.

To be more compliant with the original Traceur code, it would probably makes sense to have a DartTransformer that would be the main entry point and every single transformation defined in a separate class & file. All those files should be hosted in a codegeneration folder.

I'm not sure if GH is the best place to discuss this kind of thing. Should we create a "js2dart" room in flowdock ?

This could easily allow running some of the existing transformers which are required. As an example, hoisting is not handled today while a transformer (HoistVariableTransformer exists and can be used)

transpiler: Improve transpiler tests

As today we test the transpiler by running the spec in JS and Dart. While this is a good start, there is room for improvement.

Asserting that some code snippets fail (with a given error message) could also really help improving the test suite.

An example could be for the generation of const constructor: in Dart such constructor could not have a body (it can only have an initializer list). Asserting that this case fails with a comprehensible error message would be really helpful.

transpiler: reexport of facades

Often times it is useful to be able to re-export facade types. This requires the support of rexporting.

import {Foo} from 'bar';
export Foo;
export 'bar' show Foo;

Assert that all _ are not exported and non_ are not

export class _FOO {}
class BAR{}

should be an error because _FOO is private in Dart and BAR is exported regardless of export keyword in source file. For this reason we have to assert that all top level identifiers are exported unless they contain _ prefix.

Explore a compile-time step to add hooks

I'm mostly just brainstorming/documenting this idea. I'm not sure if it's worth taking a shot at implementing it.

Suggested by @mikeal over here.

Pros:

  • might be a smaller code size
  • might be faster since you can unwrap/inline hooks

Cons:

  • can't call any code that you didn't compile โ€“ you can't include jquery.js; you'd have to preprocess it first.
  • perhaps harder to implement than patching (probably can't use static analysis) โ€“ ['setTimeout'].forEach(function (fn) { ... }};

Should we infer class property types from ctor args ?

Currently we infer property types from from ctor args (by name) which could produce wrong results

// js
class A {
  constructor(a: Number, b: String) {
    // notice how property & arg name doesn't match
    this.b = a;
    this.a = b;
  } 
}

// -> dart
class A {
num a;
String b;
  A(num a, String b) {
    // it results in wrong types   
    this.b = a;
    this.a = b
  }
}

Things we can do:
1- Stop inferring property types from args (which would always produce valid code, but types are lost),
2- Write some logic to infer types (do not infer types based on names but get the type from the rhs, the types would always be correct but it requires more code),
3- Keep the current logic as it would probably be correct in 99% of the cases.

I would tend to go for something right (1) rather than something mostly right (3). We could implement 2 at a later point in time.

Thoughts ?

Run dartanalyzer an all files including on tests

Currently the dartanalyzer does not run on test files and it runs separately for each module. We should generate a single file which references all of the files across all of the modules and then run dartanalyzer only once.

generated file: _all_.dart

export './moduleA/file1.dart';
export './moduleA/file2.dart';

export './moduleB/file1.dart';
export './moduleB/file2.dart';

transpiler: Run transpiler tests

@tbosch from you last email:

all tests are written in jasmine/guinness and executed via karma, including the tests for the transpiler

I can not find a way to run the transpiler spec with the latest master.

I can generate the dart files by requiring the gulp-tasks file from the main gulpfile and install() it.
Then run_specs.dart is missing.

What is the correct way to do this ?

(I can not post on the ng mailing list which is why I create this issue here)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.