feat(compiler): initial version of the compiler.

Supports:
- binds text nodes, element properties and directive properties
- locates decorator, component and template directives.
- inline templates of components

The compiler is built using a pipeline design,
see core/src/compiler/pipeline package.

Integration tests to show how the compiler, change_detection and DI work
together:
core/test/compiler/integration_spec.js
This commit is contained in:
Tobias Bosch
2014-11-11 17:33:47 -08:00
parent 62efb56b0a
commit 7a70f8f92d
53 changed files with 2877 additions and 386 deletions

View File

@ -1,4 +1,4 @@
import {describe, it, expect} from 'test_lib/test_lib';
import {describe, it, expect, iit} from 'test_lib/test_lib';
import {readFirstAnnotation} from './fixtures/annotations';
import {CONST} from 'facade/lang';
@ -35,6 +35,15 @@ class A {}
@AnnotateMe({maybe: 'yes'})
class B {}
@AnnotateMe({maybe: {'a': 'b'}})
class SomeClassWithMapInAnnotation {}
@AnnotateMe({maybe: [23]})
class SomeClassWithListInAnnotation {}
@AnnotateMe({maybe: new Provide(0)})
class SomeClassWithConstObject {}
function annotatedParams(@Inject(Foo) f, @Inject(Bar) b) {}
export function main() {
@ -49,5 +58,17 @@ export function main() {
expect(readFirstAnnotation(A).maybe).toBe('default');
expect(readFirstAnnotation(B).maybe).toBe('yes');
});
it('should work with maps in named arguments', () => {
expect(readFirstAnnotation(SomeClassWithMapInAnnotation).maybe).toEqual({'a': 'b'});
});
it('should work with lists in named arguments', () => {
expect(readFirstAnnotation(SomeClassWithListInAnnotation).maybe).toEqual([23]);
});
it('should work with new instances in named arguments', () => {
expect(readFirstAnnotation(SomeClassWithConstObject).maybe).toEqual(new Provide(0));
});
});
}

View File

@ -30,6 +30,7 @@ export class DartParseTreeWriter extends JavaScriptParseTreeWriter {
constructor(moduleName, outputPath) {
super(outputPath);
this.libName = moduleName.replace(/\//g, '.').replace(/[^\w.\/]/g, '_');
this.annotationContextCounter = 0;
}
// CLASS FIELDS
@ -377,9 +378,11 @@ export class DartParseTreeWriter extends JavaScriptParseTreeWriter {
this.visitAny(tree.name);
if (tree.args !== null) {
this.annotationContextCounter++;
this.write_(OPEN_PAREN);
this.writeList_(tree.args.args, COMMA, false);
this.write_(CLOSE_PAREN);
this.annotationContextCounter--;
}
this.writeSpace_()
@ -400,6 +403,31 @@ export class DartParseTreeWriter extends JavaScriptParseTreeWriter {
this.visitAny(tree.body);
}
visitObjectLiteralExpression(tree) {
if (this.annotationContextCounter) {
this.write_('const');
}
super.visitObjectLiteralExpression(tree);
}
visitArrayLiteralExpression(tree) {
if (this.annotationContextCounter) {
this.write_('const');
}
super.visitArrayLiteralExpression(tree);
}
visitNewExpression(tree) {
if (this.annotationContextCounter) {
this.write_('const');
this.writeSpace_();
this.visitAny(tree.operand);
this.visitAny(tree.args);
} else {
super.visitNewExpression(tree);
}
}
visitNamedParameterList(tree) {
this.writeList_(tree.parameterNameAndValues, COMMA, false);
}