angular / angular Goto Github PK
View Code? Open in Web Editor NEWDeliver web apps with confidence ๐
Home Page: https://angular.dev
License: MIT License
Deliver web apps with confidence ๐
Home Page: https://angular.dev
License: MIT License
E.g.
compile(component:Type, element:Element = null){}
==>
compile(Type component, [Element element = null]){}
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.
This could probably be solved at the writer level, the only difference seems to be of
-> in
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 ?
Implement change detection on properties only. (This is needed to allow work on the HTML compiler to proceed.)
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
class Parent {
constructor(arg:List){}
}
class Child extends Parent {
constructor(arg:List){
super(arg);
}
}
What about testing with more browsers:
I had been working on testing angular.dart on those platforms with SauceLabs, ref dart-archive/angular.dart#1288
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:
Cons:
jquery.js
; you'd have to preprocess it first.['setTimeout'].forEach(function (fn) { ... }};
Before starting on this, revisit whether we need to full test suite for benchmark proof of concept or not. May need to break this into subtasks.
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)
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.
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.
Fat arrow functions in JS need to be transpiled to () {}
in Dart.
E.g.
JS:
var fn = () => { var y = 1 };
Dart:
var fn = () { var y = 1 };
// this will fail: var fn = () => { var y = 1 };
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:
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;
import {Foo} from 'bar';
export Foo;
Should be translated to dart as
export 'bar' show Foo;
"int" in ES6 code should translate to "int" in Dart code. For ES5 code, this could be number.
See https://github.com/angular/di.js for JS implementation.
pub.get only when buildspec.yaml changes,
dartanalyzer whenever a source file changes
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 :-)
E.g. method({a, b}:{a:String, b:boolean})
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';
var x:Array<SubType> = []
at runtime we would call
Array.of(SubType)
TBD: example
In file path/dom.dart
:
Add header
library path.dom;
It's allegedly faster; via โ> https://twitter.com/domenic/status/500106788814217216
JavaScript's "let" is the same as Dart's "var" -- this is needed to apply more semantically correct transpilation.
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);
});
}
export class Foo {
foo() {
return new Bar();
}
}
export class Bar {}
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:
library
statement in the source code (may be via @LIBRARY('name')
if possible),A short term solution could be to avoid "_" prefixed names but we should also have a longer term strategy IMO.
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);
});
For now run the following:
gulp build
: automatically runs dartanalyzer
, so we get early errors via the static type system of dartkarma run
: run some basic tests to ensure the JS modules are loading and have correct dependenciesNeeds to download dart environment...
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.
@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)
a.js:
import {B} from './b';
export class A {
constructor() { new B(); }
}
b.js:
import {A} from './a';
export class B {
}
@FIELD
annotationconst constructor
s in Dart through @CONST
annotationExample:
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 {}
Use the AngularDart parser/lexer as a starting point. (https://github.com/angular/angular.dart/tree/master/lib/core/parser)
At a minimum, should be able to parse simple a.b.c expression
Eval the expression
via @Raynos here: https://github.com/btford/zone.js/issues/10
Main IO interfaces to support:
There are probably others
Helps in rewriting method names for built ins like arrays, ...
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.
function f(a=99) {
}
should be compiled to
f([a=99]) {
}
E.g. error from writing method(String s)
(which should be method(s:string)
)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.