style(lint): re-format modules/@angular

This commit is contained in:
Alex Eagle
2016-06-08 16:38:52 -07:00
parent bbed364e7b
commit f39c9c9e75
589 changed files with 21829 additions and 24259 deletions

View File

@ -1,13 +1,4 @@
import {
beforeEach,
ddescribe,
describe,
expect,
iit,
inject,
it,
xit,
} from '@angular/core/testing/testing_internal';
import {beforeEach, ddescribe, describe, expect, iit, inject, it, xit,} from '@angular/core/testing/testing_internal';
import {escapeSingleQuoteString} from '@angular/compiler/src/output/abstract_emitter';

View File

@ -1,13 +1,4 @@
import {
beforeEach,
ddescribe,
describe,
expect,
iit,
inject,
it,
xit,
} from '@angular/core/testing/testing_internal';
import {beforeEach, ddescribe, describe, expect, iit, inject, it, xit,} from '@angular/core/testing/testing_internal';
import {isBlank} from '../../src/facade/lang';
import {DartEmitter} from '@angular/compiler/src/output/dart_emitter';
@ -52,8 +43,9 @@ export function main() {
expect(emitStmt(someVar.set(o.literal(1)).toDeclStmt())).toEqual(`var someVar = 1;`);
expect(emitStmt(someVar.set(o.literal(1)).toDeclStmt(null, [o.StmtModifier.Final])))
.toEqual(`final someVar = 1;`);
expect(emitStmt(someVar.set(o.literal(1, new o.BuiltinType(o.BuiltinTypeName.Int,
[o.TypeModifier.Const])))
expect(emitStmt(someVar
.set(o.literal(
1, new o.BuiltinType(o.BuiltinTypeName.Int, [o.TypeModifier.Const])))
.toDeclStmt(null, [o.StmtModifier.Final])))
.toEqual(`const int someVar = 1;`);
expect(emitStmt(someVar.set(o.literal(1)).toDeclStmt(), ['someVar']))
@ -123,8 +115,9 @@ export function main() {
it('should support external identifiers', () => {
expect(emitStmt(o.importExpr(sameModuleIdentifier).toStmt())).toEqual('someLocalId;');
expect(emitStmt(o.importExpr(externalModuleIdentifier).toStmt()))
.toEqual([`import 'someOtherPath' as import0;`, `import0.someExternalId;`].join('\n'));
expect(emitStmt(o.importExpr(externalModuleIdentifier).toStmt())).toEqual([
`import 'someOtherPath' as import0;`, `import0.someExternalId;`
].join('\n'));
});
it('should support operators', () => {
@ -155,40 +148,42 @@ export function main() {
it('should support function expressions', () => {
expect(emitStmt(o.fn([], []).toStmt())).toEqual(['() {', '};'].join('\n'));
expect(emitStmt(o.fn([new o.FnParam('param1', o.INT_TYPE)], []).toStmt()))
.toEqual(['(int param1) {', '};'].join('\n'));
expect(emitStmt(o.fn([new o.FnParam('param1', o.INT_TYPE)], []).toStmt())).toEqual([
'(int param1) {', '};'
].join('\n'));
});
it('should support function statements', () => {
expect(emitStmt(new o.DeclareFunctionStmt('someFn', [], [])))
.toEqual(['void someFn() {', '}'].join('\n'));
expect(emitStmt(new o.DeclareFunctionStmt('someFn', [], [new o.ReturnStatement(o.literal(1))],
o.INT_TYPE)))
expect(emitStmt(new o.DeclareFunctionStmt('someFn', [], [
]))).toEqual(['void someFn() {', '}'].join('\n'));
expect(emitStmt(new o.DeclareFunctionStmt(
'someFn', [], [new o.ReturnStatement(o.literal(1))], o.INT_TYPE)))
.toEqual(['int someFn() {', ' return 1;', '}'].join('\n'));
expect(
emitStmt(new o.DeclareFunctionStmt('someFn', [new o.FnParam('param1', o.INT_TYPE)], [])))
.toEqual(['void someFn(int param1) {', '}'].join('\n'));
expect(emitStmt(new o.DeclareFunctionStmt('someFn', [new o.FnParam('param1', o.INT_TYPE)], [
]))).toEqual(['void someFn(int param1) {', '}'].join('\n'));
});
it('should support comments',
() => { expect(emitStmt(new o.CommentStmt('a\nb'))).toEqual(['// a', '// b'].join('\n')); });
it('should support comments', () => {
expect(emitStmt(new o.CommentStmt('a\nb'))).toEqual(['// a', '// b'].join('\n'));
});
it('should support if stmt', () => {
var trueCase = o.variable('trueCase').callFn([]).toStmt();
var falseCase = o.variable('falseCase').callFn([]).toStmt();
expect(emitStmt(new o.IfStmt(o.variable('cond'), [trueCase])))
.toEqual(['if (cond) { trueCase(); }'].join('\n'));
expect(emitStmt(new o.IfStmt(o.variable('cond'), [trueCase], [falseCase])))
.toEqual(['if (cond) {', ' trueCase();', '} else {', ' falseCase();', '}'].join('\n'));
expect(emitStmt(new o.IfStmt(o.variable('cond'), [trueCase]))).toEqual([
'if (cond) { trueCase(); }'
].join('\n'));
expect(emitStmt(new o.IfStmt(o.variable('cond'), [trueCase], [falseCase]))).toEqual([
'if (cond) {', ' trueCase();', '} else {', ' falseCase();', '}'
].join('\n'));
});
it('should support try/catch', () => {
var bodyStmt = o.variable('body').callFn([]).toStmt();
var catchStmt = o.variable('catchFn').callFn([o.CATCH_ERROR_VAR, o.CATCH_STACK_VAR]).toStmt();
expect(emitStmt(new o.TryCatchStmt([bodyStmt], [catchStmt])))
.toEqual(
['try {', ' body();', '} catch (error, stack) {', ' catchFn(error,stack);', '}']
.join('\n'));
expect(emitStmt(new o.TryCatchStmt([bodyStmt], [catchStmt]))).toEqual([
'try {', ' body();', '} catch (error, stack) {', ' catchFn(error,stack);', '}'
].join('\n'));
});
it('should support support throwing',
@ -200,11 +195,10 @@ export function main() {
beforeEach(() => { callSomeMethod = o.THIS_EXPR.callMethod('someMethod', []).toStmt(); });
it('should support declaring classes', () => {
expect(emitStmt(new o.ClassStmt('SomeClass', null, [], [], null, [])))
.toEqual(['class SomeClass {', '}'].join('\n'));
expect(
emitStmt(new o.ClassStmt('SomeClass', o.variable('SomeSuperClass'), [], [], null, [])))
.toEqual(['class SomeClass extends SomeSuperClass {', '}'].join('\n'));
expect(emitStmt(new o.ClassStmt('SomeClass', null, [], [], null, [
]))).toEqual(['class SomeClass {', '}'].join('\n'));
expect(emitStmt(new o.ClassStmt('SomeClass', o.variable('SomeSuperClass'), [], [], null, [
]))).toEqual(['class SomeClass extends SomeSuperClass {', '}'].join('\n'));
});
it('should support declaring constructors', () => {
@ -216,23 +210,23 @@ export function main() {
'SomeClass', null, [], [],
new o.ClassMethod(null, [new o.FnParam('someParam', o.INT_TYPE)], []), [])))
.toEqual(['class SomeClass {', ' SomeClass(int someParam) {', ' }', '}'].join('\n'));
expect(emitStmt(new o.ClassStmt('SomeClass', null, [], [],
new o.ClassMethod(null, [], [superCall]), [])))
expect(emitStmt(new o.ClassStmt(
'SomeClass', null, [], [], new o.ClassMethod(null, [], [superCall]), [])))
.toEqual(
['class SomeClass {', ' SomeClass(): super(someParam) {', ' }', '}'].join('\n'));
expect(emitStmt(new o.ClassStmt('SomeClass', null, [], [],
new o.ClassMethod(null, [], [callSomeMethod]), [])))
.toEqual(
['class SomeClass {', ' SomeClass() {', ' this.someMethod();', ' }', '}'].join(
'\n'));
expect(emitStmt(new o.ClassStmt(
'SomeClass', null, [], [], new o.ClassMethod(null, [], [callSomeMethod]), [])))
.toEqual([
'class SomeClass {', ' SomeClass() {', ' this.someMethod();', ' }', '}'
].join('\n'));
});
it('should support declaring fields', () => {
expect(emitStmt(new o.ClassStmt('SomeClass', null, [new o.ClassField('someField')], [],
null, [])))
expect(emitStmt(new o.ClassStmt(
'SomeClass', null, [new o.ClassField('someField')], [], null, [])))
.toEqual(['class SomeClass {', ' var someField;', '}'].join('\n'));
expect(emitStmt(new o.ClassStmt('SomeClass', null,
[new o.ClassField('someField', o.INT_TYPE)], [], null, [])))
expect(emitStmt(new o.ClassStmt(
'SomeClass', null, [new o.ClassField('someField', o.INT_TYPE)], [], null, [])))
.toEqual(['class SomeClass {', ' int someField;', '}'].join('\n'));
expect(
emitStmt(new o.ClassStmt(
@ -242,39 +236,40 @@ export function main() {
});
it('should support declaring getters', () => {
expect(emitStmt(new o.ClassStmt('SomeClass', null, [],
[new o.ClassGetter('someGetter', [])], null, [])))
expect(emitStmt(new o.ClassStmt(
'SomeClass', null, [], [new o.ClassGetter('someGetter', [])], null, [])))
.toEqual(['class SomeClass {', ' get someGetter {', ' }', '}'].join('\n'));
expect(
emitStmt(new o.ClassStmt('SomeClass', null, [],
[new o.ClassGetter('someGetter', [], o.INT_TYPE)], null, [])))
expect(emitStmt(new o.ClassStmt(
'SomeClass', null, [], [new o.ClassGetter('someGetter', [], o.INT_TYPE)], null,
[])))
.toEqual(['class SomeClass {', ' int get someGetter {', ' }', '}'].join('\n'));
expect(emitStmt(new o.ClassStmt('SomeClass', null, [],
[new o.ClassGetter('someGetter', [callSomeMethod])], null,
[])))
.toEqual(
['class SomeClass {', ' get someGetter {', ' this.someMethod();', ' }', '}']
.join('\n'));
expect(emitStmt(new o.ClassStmt(
'SomeClass', null, [], [new o.ClassGetter('someGetter', [callSomeMethod])], null,
[])))
.toEqual([
'class SomeClass {', ' get someGetter {', ' this.someMethod();', ' }', '}'
].join('\n'));
});
it('should support methods', () => {
expect(emitStmt(new o.ClassStmt('SomeClass', null, [], [], null,
[new o.ClassMethod('someMethod', [], [])])))
.toEqual(['class SomeClass {', ' void someMethod() {', ' }', '}'].join('\n'));
expect(emitStmt(new o.ClassStmt('SomeClass', null, [], [], null,
[new o.ClassMethod('someMethod', [], [], o.INT_TYPE)])))
.toEqual(['class SomeClass {', ' int someMethod() {', ' }', '}'].join('\n'));
expect(emitStmt(new o.ClassStmt('SomeClass', null, [], [], null, [
new o.ClassMethod('someMethod', [], [])
]))).toEqual(['class SomeClass {', ' void someMethod() {', ' }', '}'].join('\n'));
expect(emitStmt(new o.ClassStmt('SomeClass', null, [], [], null, [
new o.ClassMethod('someMethod', [], [], o.INT_TYPE)
]))).toEqual(['class SomeClass {', ' int someMethod() {', ' }', '}'].join('\n'));
expect(
emitStmt(new o.ClassStmt(
'SomeClass', null, [], [], null,
[new o.ClassMethod('someMethod', [new o.FnParam('someParam', o.INT_TYPE)], [])])))
.toEqual(
['class SomeClass {', ' void someMethod(int someParam) {', ' }', '}'].join('\n'));
expect(emitStmt(new o.ClassStmt('SomeClass', null, [], [], null,
[new o.ClassMethod('someMethod', [], [callSomeMethod])])))
.toEqual(
['class SomeClass {', ' void someMethod() {', ' this.someMethod();', ' }', '}']
.join('\n'));
expect(emitStmt(new o.ClassStmt(
'SomeClass', null, [], [], null,
[new o.ClassMethod('someMethod', [], [callSomeMethod])])))
.toEqual([
'class SomeClass {', ' void someMethod() {', ' this.someMethod();', ' }', '}'
].join('\n'));
});
});
@ -292,9 +287,9 @@ export function main() {
var writeVarExpr = o.variable('a').set(o.NULL_EXPR);
expect(emitStmt(writeVarExpr.toDeclStmt(o.importType(sameModuleIdentifier))))
.toEqual('someLocalId a = null;');
expect(emitStmt(writeVarExpr.toDeclStmt(o.importType(externalModuleIdentifier))))
.toEqual([`import 'someOtherPath' as import0;`, `import0.someExternalId a = null;`].join(
'\n'));
expect(emitStmt(writeVarExpr.toDeclStmt(o.importType(externalModuleIdentifier)))).toEqual([
`import 'someOtherPath' as import0;`, `import0.someExternalId a = null;`
].join('\n'));
});
it('should support combined types', () => {

View File

@ -1,13 +1,4 @@
import {
beforeEach,
ddescribe,
describe,
expect,
iit,
inject,
it,
xit,
} from '@angular/core/testing/testing_internal';
import {beforeEach, ddescribe, describe, expect, iit, inject, it, xit,} from '@angular/core/testing/testing_internal';
import {DartImportGenerator} from '@angular/compiler/src/output/dart_imports';
@ -31,8 +22,8 @@ export function main() {
expect(
generator.getImportPath('asset:somePkg/lib/dir1/modPath', 'asset:somePkg/lib/impPath'))
.toEqual('../impPath');
expect(generator.getImportPath('asset:somePkg/lib/dir1/modPath',
'asset:somePkg/lib/dir2/impPath'))
expect(generator.getImportPath(
'asset:somePkg/lib/dir1/modPath', 'asset:somePkg/lib/dir2/impPath'))
.toEqual('../dir2/impPath');
});
@ -43,8 +34,9 @@ export function main() {
});
it('should not allow absolute imports of non lib modules', () => {
expect(() => generator.getImportPath('asset:somePkg/lib/modPath',
'asset:somePkg/test/impPath'))
expect(
() =>
generator.getImportPath('asset:somePkg/lib/modPath', 'asset:somePkg/test/impPath'))
.toThrowError(
`Can't import url asset:somePkg/test/impPath from asset:somePkg/lib/modPath`);
});

View File

@ -1,13 +1,4 @@
import {
beforeEach,
ddescribe,
describe,
expect,
iit,
inject,
it,
xit,
} from '@angular/core/testing/testing_internal';
import {beforeEach, ddescribe, describe, expect, iit, inject, it, xit,} from '@angular/core/testing/testing_internal';
import {isBlank} from '../../src/facade/lang';
import {JavaScriptEmitter} from '@angular/compiler/src/output/js_emitter';
@ -47,11 +38,10 @@ export function main() {
it('should declare variables', () => {
expect(emitStmt(someVar.set(o.literal(1)).toDeclStmt())).toEqual(`var someVar = 1;`);
expect(emitStmt(someVar.set(o.literal(1)).toDeclStmt(), ['someVar']))
.toEqual([
'var someVar = 1;',
`Object.defineProperty(exports, 'someVar', { get: function() { return someVar; }});`
].join('\n'));
expect(emitStmt(someVar.set(o.literal(1)).toDeclStmt(), ['someVar'])).toEqual([
'var someVar = 1;',
`Object.defineProperty(exports, 'someVar', { get: function() { return someVar; }});`
].join('\n'));
});
it('should read and write variables', () => {
@ -111,11 +101,11 @@ export function main() {
it('should support external identifiers', () => {
expect(emitStmt(o.importExpr(sameModuleIdentifier).toStmt())).toEqual('someLocalId;');
expect(emitStmt(o.importExpr(externalModuleIdentifier).toStmt()))
.toEqual([
`var import0 = re` + `quire('somePackage/someOtherPath');`,
`import0.someExternalId;`
].join('\n'));
expect(emitStmt(o.importExpr(externalModuleIdentifier).toStmt())).toEqual([
`var import0 = re` +
`quire('somePackage/someOtherPath');`,
`import0.someExternalId;`
].join('\n'));
});
it('should support operators', () => {
@ -145,52 +135,50 @@ export function main() {
it('should support function expressions', () => {
expect(emitStmt(o.fn([], []).toStmt())).toEqual(['function() {', '};'].join('\n'));
expect(emitStmt(o.fn([], [new o.ReturnStatement(o.literal(1))]).toStmt()))
.toEqual(['function() {', ' return 1;\n};'].join('\n'));
expect(emitStmt(o.fn([new o.FnParam('param1')], []).toStmt()))
.toEqual(['function(param1) {', '};'].join('\n'));
expect(emitStmt(o.fn([], [new o.ReturnStatement(o.literal(1))]).toStmt())).toEqual([
'function() {', ' return 1;\n};'
].join('\n'));
expect(emitStmt(o.fn([new o.FnParam('param1')], []).toStmt())).toEqual([
'function(param1) {', '};'
].join('\n'));
});
it('should support function statements', () => {
expect(emitStmt(new o.DeclareFunctionStmt('someFn', [], [])))
.toEqual(['function someFn() {', '}'].join('\n'));
expect(emitStmt(new o.DeclareFunctionStmt('someFn', [], []), ['someFn']))
.toEqual([
'function someFn() {',
'}',
`Object.defineProperty(exports, 'someFn', { get: function() { return someFn; }});`
].join('\n'));
expect(
emitStmt(new o.DeclareFunctionStmt('someFn', [], [new o.ReturnStatement(o.literal(1))])))
.toEqual(['function someFn() {', ' return 1;', '}'].join('\n'));
expect(emitStmt(new o.DeclareFunctionStmt('someFn', [new o.FnParam('param1')], [])))
.toEqual(['function someFn(param1) {', '}'].join('\n'));
expect(emitStmt(new o.DeclareFunctionStmt('someFn', [], [
]))).toEqual(['function someFn() {', '}'].join('\n'));
expect(emitStmt(new o.DeclareFunctionStmt('someFn', [], []), ['someFn'])).toEqual([
'function someFn() {', '}',
`Object.defineProperty(exports, 'someFn', { get: function() { return someFn; }});`
].join('\n'));
expect(emitStmt(new o.DeclareFunctionStmt('someFn', [], [
new o.ReturnStatement(o.literal(1))
]))).toEqual(['function someFn() {', ' return 1;', '}'].join('\n'));
expect(emitStmt(new o.DeclareFunctionStmt('someFn', [new o.FnParam('param1')], [
]))).toEqual(['function someFn(param1) {', '}'].join('\n'));
});
it('should support comments',
() => { expect(emitStmt(new o.CommentStmt('a\nb'))).toEqual(['// a', '// b'].join('\n')); });
it('should support comments', () => {
expect(emitStmt(new o.CommentStmt('a\nb'))).toEqual(['// a', '// b'].join('\n'));
});
it('should support if stmt', () => {
var trueCase = o.variable('trueCase').callFn([]).toStmt();
var falseCase = o.variable('falseCase').callFn([]).toStmt();
expect(emitStmt(new o.IfStmt(o.variable('cond'), [trueCase])))
.toEqual(['if (cond) { trueCase(); }'].join('\n'));
expect(emitStmt(new o.IfStmt(o.variable('cond'), [trueCase], [falseCase])))
.toEqual(['if (cond) {', ' trueCase();', '} else {', ' falseCase();', '}'].join('\n'));
expect(emitStmt(new o.IfStmt(o.variable('cond'), [trueCase]))).toEqual([
'if (cond) { trueCase(); }'
].join('\n'));
expect(emitStmt(new o.IfStmt(o.variable('cond'), [trueCase], [falseCase]))).toEqual([
'if (cond) {', ' trueCase();', '} else {', ' falseCase();', '}'
].join('\n'));
});
it('should support try/catch', () => {
var bodyStmt = o.variable('body').callFn([]).toStmt();
var catchStmt = o.variable('catchFn').callFn([o.CATCH_ERROR_VAR, o.CATCH_STACK_VAR]).toStmt();
expect(emitStmt(new o.TryCatchStmt([bodyStmt], [catchStmt])))
.toEqual([
'try {',
' body();',
'} catch (error) {',
' var stack = error.stack;',
' catchFn(error,stack);',
'}'
].join('\n'));
expect(emitStmt(new o.TryCatchStmt([bodyStmt], [catchStmt]))).toEqual([
'try {', ' body();', '} catch (error) {', ' var stack = error.stack;',
' catchFn(error,stack);', '}'
].join('\n'));
});
it('should support support throwing',
@ -202,19 +190,17 @@ export function main() {
beforeEach(() => { callSomeMethod = o.THIS_EXPR.callMethod('someMethod', []).toStmt(); });
it('should support declaring classes', () => {
expect(emitStmt(new o.ClassStmt('SomeClass', null, [], [], null, [])))
.toEqual(['function SomeClass() {', '}'].join('\n'));
expect(emitStmt(new o.ClassStmt('SomeClass', null, [], [], null, [
]))).toEqual(['function SomeClass() {', '}'].join('\n'));
expect(emitStmt(new o.ClassStmt('SomeClass', null, [], [], null, []), ['SomeClass']))
.toEqual([
'function SomeClass() {',
'}',
'function SomeClass() {', '}',
`Object.defineProperty(exports, 'SomeClass', { get: function() { return SomeClass; }});`
].join('\n'));
expect(
emitStmt(new o.ClassStmt('SomeClass', o.variable('SomeSuperClass'), [], [], null, [])))
.toEqual([
'function SomeClass() {',
'}',
'function SomeClass() {', '}',
'SomeClass.prototype = Object.create(SomeSuperClass.prototype);'
].join('\n'));
});
@ -224,75 +210,61 @@ export function main() {
expect(emitStmt(
new o.ClassStmt('SomeClass', null, [], [], new o.ClassMethod(null, [], []), [])))
.toEqual(['function SomeClass() {', '}'].join('\n'));
expect(emitStmt(new o.ClassStmt('SomeClass', null, [], [],
new o.ClassMethod(null, [new o.FnParam('someParam')], []),
[])))
expect(emitStmt(new o.ClassStmt(
'SomeClass', null, [], [],
new o.ClassMethod(null, [new o.FnParam('someParam')], []), [])))
.toEqual(['function SomeClass(someParam) {', '}'].join('\n'));
expect(emitStmt(new o.ClassStmt('SomeClass', o.variable('SomeSuperClass'), [], [],
new o.ClassMethod(null, [], [superCall]), [])))
expect(emitStmt(new o.ClassStmt(
'SomeClass', o.variable('SomeSuperClass'), [], [],
new o.ClassMethod(null, [], [superCall]), [])))
.toEqual([
'function SomeClass() {',
' var self = this;',
' SomeSuperClass.call(this, someParam);',
'}',
'function SomeClass() {', ' var self = this;',
' SomeSuperClass.call(this, someParam);', '}',
'SomeClass.prototype = Object.create(SomeSuperClass.prototype);'
].join('\n'));
expect(emitStmt(new o.ClassStmt('SomeClass', null, [], [],
new o.ClassMethod(null, [], [callSomeMethod]), [])))
.toEqual(
['function SomeClass() {', ' var self = this;', ' self.someMethod();', '}'].join(
'\n'));
expect(emitStmt(new o.ClassStmt(
'SomeClass', null, [], [], new o.ClassMethod(null, [], [callSomeMethod]), [])))
.toEqual([
'function SomeClass() {', ' var self = this;', ' self.someMethod();', '}'
].join('\n'));
});
it('should support declaring getters', () => {
expect(emitStmt(new o.ClassStmt('SomeClass', null, [],
[new o.ClassGetter('someGetter', [])], null, [])))
expect(emitStmt(new o.ClassStmt(
'SomeClass', null, [], [new o.ClassGetter('someGetter', [])], null, [])))
.toEqual([
'function SomeClass() {',
'}',
`Object.defineProperty(SomeClass.prototype, 'someGetter', { get: function() {`,
`}});`
'function SomeClass() {', '}',
`Object.defineProperty(SomeClass.prototype, 'someGetter', { get: function() {`, `}});`
].join('\n'));
expect(emitStmt(new o.ClassStmt('SomeClass', null, [],
[new o.ClassGetter('someGetter', [callSomeMethod])], null,
[])))
expect(emitStmt(new o.ClassStmt(
'SomeClass', null, [], [new o.ClassGetter('someGetter', [callSomeMethod])], null,
[])))
.toEqual([
'function SomeClass() {',
'}',
'function SomeClass() {', '}',
`Object.defineProperty(SomeClass.prototype, 'someGetter', { get: function() {`,
` var self = this;`,
` self.someMethod();`,
`}});`
` var self = this;`, ` self.someMethod();`, `}});`
].join('\n'));
});
it('should support methods', () => {
expect(emitStmt(new o.ClassStmt('SomeClass', null, [], [], null,
[new o.ClassMethod('someMethod', [], [])])))
expect(emitStmt(new o.ClassStmt(
'SomeClass', null, [], [], null, [new o.ClassMethod('someMethod', [], [])])))
.toEqual([
'function SomeClass() {',
'}',
'SomeClass.prototype.someMethod = function() {',
'};'
'function SomeClass() {', '}', 'SomeClass.prototype.someMethod = function() {', '};'
].join('\n'));
expect(emitStmt(new o.ClassStmt(
'SomeClass', null, [], [], null,
[new o.ClassMethod('someMethod', [new o.FnParam('someParam')], [])])))
.toEqual([
'function SomeClass() {',
'}',
'SomeClass.prototype.someMethod = function(someParam) {',
'};'
'function SomeClass() {', '}',
'SomeClass.prototype.someMethod = function(someParam) {', '};'
].join('\n'));
expect(emitStmt(new o.ClassStmt('SomeClass', null, [], [], null,
[new o.ClassMethod('someMethod', [], [callSomeMethod])])))
expect(emitStmt(new o.ClassStmt(
'SomeClass', null, [], [], null,
[new o.ClassMethod('someMethod', [], [callSomeMethod])])))
.toEqual([
'function SomeClass() {',
'}',
'SomeClass.prototype.someMethod = function() {',
' var self = this;',
' self.someMethod();',
'};'
'function SomeClass() {', '}', 'SomeClass.prototype.someMethod = function() {',
' var self = this;', ' self.someMethod();', '};'
].join('\n'));
});
});

View File

@ -1,14 +1,16 @@
// ATTENTION: This file will be overwritten with generated code by main()
import {print, IS_DART} from '../../src/facade/lang';
import {unimplemented} from '../../src/facade/exceptions';
import {codegenExportsVars, codegenStmts} from './output_emitter_util';
import {TypeScriptEmitter} from '@angular/compiler/src/output/ts_emitter';
import {DartEmitter} from '@angular/compiler/src/output/dart_emitter';
import {DartImportGenerator} from '@angular/compiler/src/output/dart_imports';
import * as o from '@angular/compiler/src/output/output_ast';
import {TypeScriptEmitter} from '@angular/compiler/src/output/ts_emitter';
import {unimplemented} from '../../src/facade/exceptions';
import {IS_DART, print} from '../../src/facade/lang';
import {assetUrl} from '../../src/util';
import {SimpleJsImportGenerator} from '../offline_compiler_util';
import {codegenExportsVars, codegenStmts} from './output_emitter_util';
export function getExpressions(): any {
return unimplemented();
}
@ -17,9 +19,9 @@ export function getExpressions(): any {
export function emit() {
var emitter = IS_DART ? new DartEmitter(new DartImportGenerator()) :
new TypeScriptEmitter(new SimpleJsImportGenerator());
var emittedCode =
emitter.emitStatements(assetUrl('compiler', 'output/output_emitter_codegen_typed', 'test'),
codegenStmts, codegenExportsVars);
var emittedCode = emitter.emitStatements(
assetUrl('compiler', 'output/output_emitter_codegen_typed', 'test'), codegenStmts,
codegenExportsVars);
return emittedCode;
}

View File

@ -1,11 +1,13 @@
// ATTENTION: This file will be overwritten with generated code by main()
import {print} from '../../src/facade/lang';
import {unimplemented} from '../../src/facade/exceptions';
import {codegenExportsVars, codegenStmts} from './output_emitter_util';
import {JavaScriptEmitter} from '@angular/compiler/src/output/js_emitter';
import {unimplemented} from '../../src/facade/exceptions';
import {print} from '../../src/facade/lang';
import {assetUrl} from '../../src/util';
import {SimpleJsImportGenerator} from '../offline_compiler_util';
import {codegenExportsVars, codegenStmts} from './output_emitter_util';
export function getExpressions(): any {
return unimplemented();
}
@ -13,9 +15,9 @@ export function getExpressions(): any {
// Generator
export function emit() {
var emitter = new JavaScriptEmitter(new SimpleJsImportGenerator());
var emittedCode =
emitter.emitStatements(assetUrl('compiler', 'output/output_emitter_codegen_untyped', 'test'),
codegenStmts, codegenExportsVars);
var emittedCode = emitter.emitStatements(
assetUrl('compiler', 'output/output_emitter_codegen_untyped', 'test'), codegenStmts,
codegenExportsVars);
return emittedCode;
}

View File

@ -1,13 +1,4 @@
import {
beforeEach,
ddescribe,
describe,
expect,
iit,
inject,
it,
xit,
} from '@angular/core/testing/testing_internal';
import {beforeEach, ddescribe, describe, expect, iit, inject, it, xit,} from '@angular/core/testing/testing_internal';
import {IS_DART} from '../../src/facade/lang';
@ -20,23 +11,18 @@ import {EventEmitter} from '@angular/core';
import {ViewType} from '@angular/core/src/linker/view_type';
import {BaseException} from '@angular/core';
import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter';
import {
browserDetection
} from '@angular/platform-browser/testing'
import {browserDetection} from '@angular/platform-browser/testing'
export function
main() {
var outputDefs: any[] /** TODO #9100 */ = [];
outputDefs.push({
'getExpressions': () => interpretStatements(codegenStmts, 'getExpressions',
new DynamicClassInstanceFactory()),
export function main() {
var outputDefs: any[] /** TODO #9100 */ = []; outputDefs.push({
'getExpressions': () => interpretStatements(
codegenStmts, 'getExpressions', new DynamicClassInstanceFactory()),
'name': 'interpreted'
});
if (IS_DART || !getDOM().supportsDOMEvents()) {
// Our generator only works on node.js and Dart...
outputDefs.push({'getExpressions': () => typed.getExpressions, 'name': 'typed'});
}
if (!IS_DART) {
} if (!IS_DART) {
// Our generator only works on node.js and Dart...
if (!getDOM().supportsDOMEvents()) {
outputDefs.push({'getExpressions': () => untyped.getExpressions, 'name': 'untyped'});
@ -47,155 +33,166 @@ import {
});
}
describe('output emitter', () => {
outputDefs.forEach((outputDef) => {
describe(`${outputDef['name']}`, () => {
var expressions: any /** TODO #9100 */;
beforeEach(() => { expressions = outputDef['getExpressions']()(); });
describe(
'output emitter',
() => {
outputDefs.forEach((outputDef) => {
describe(`${outputDef['name']}`, () => {
var expressions: any /** TODO #9100 */;
beforeEach(() => { expressions = outputDef['getExpressions']()(); });
it('should support literals', () => {
expect(expressions['stringLiteral']).toEqual('Hello World!');
expect(expressions['intLiteral']).toEqual(42);
expect(expressions['boolLiteral']).toEqual(true);
expect(expressions['arrayLiteral']).toEqual([0]);
expect(expressions['mapLiteral']).toEqual({'key0': 0});
});
it('should support literals', () => {
expect(expressions['stringLiteral']).toEqual('Hello World!');
expect(expressions['intLiteral']).toEqual(42);
expect(expressions['boolLiteral']).toEqual(true);
expect(expressions['arrayLiteral']).toEqual([0]);
expect(expressions['mapLiteral']).toEqual({'key0': 0});
});
it('should support reading vars/keys/props', () => {
expect(expressions['readVar']).toEqual('someValue');
expect(expressions['readKey']).toEqual('someValue');
expect(expressions['readPropExternalInstance']).toEqual('someValue');
expect(expressions['readPropDynamicInstance']).toEqual('dynamicValue');
expect(expressions['readGetterDynamicInstance'])
.toEqual({'data': 'someValue', 'dynamicProp': 'dynamicValue'});
});
it('should support reading vars/keys/props', () => {
expect(expressions['readVar']).toEqual('someValue');
expect(expressions['readKey']).toEqual('someValue');
expect(expressions['readPropExternalInstance']).toEqual('someValue');
expect(expressions['readPropDynamicInstance']).toEqual('dynamicValue');
expect(expressions['readGetterDynamicInstance'])
.toEqual({'data': 'someValue', 'dynamicProp': 'dynamicValue'});
});
it('should support writing to vars / keys / props', () => {
expect(expressions['changedVar']).toEqual('changedValue');
expect(expressions['changedKey']).toEqual('changedValue');
expect(expressions['changedPropExternalInstance']).toEqual('changedValue');
expect(expressions['changedPropDynamicInstance']).toEqual('changedValue');
});
it('should support writing to vars / keys / props', () => {
expect(expressions['changedVar']).toEqual('changedValue');
expect(expressions['changedKey']).toEqual('changedValue');
expect(expressions['changedPropExternalInstance']).toEqual('changedValue');
expect(expressions['changedPropDynamicInstance']).toEqual('changedValue');
});
it('should support declaring functions with parameters and return', () => {
expect(expressions['fn']('someParam')).toEqual({'param': 'someParam'});
expect(expressions['closureInDynamicInstance']('someParam'))
.toEqual({'param': 'someParam', 'data': 'someValue', 'dynamicProp': 'dynamicValue'});
});
it('should support declaring functions with parameters and return', () => {
expect(expressions['fn']('someParam')).toEqual({'param': 'someParam'});
expect(expressions['closureInDynamicInstance']('someParam')).toEqual({
'param': 'someParam',
'data': 'someValue',
'dynamicProp': 'dynamicValue'
});
});
it('should support invoking functions and methods', () => {
expect(expressions['invokeFn']).toEqual({'param': 'someParam'});
expect(expressions['concatedArray']).toEqual([0, 1]);
expect(expressions['invokeMethodExternalInstance'])
.toEqual({'data': 'someValue', 'param': 'someParam'});
expect(expressions['invokeMethodExternalInstanceViaBind'])
.toEqual({'data': 'someValue', 'param': 'someParam'});
expect(expressions['invokeMethodDynamicInstance'])
.toEqual({'data': 'someValue', 'dynamicProp': 'dynamicValue', 'param': 'someParam'});
expect(expressions['invokeMethodDynamicInstanceViaBind'])
.toEqual({'data': 'someValue', 'dynamicProp': 'dynamicValue', 'param': 'someParam'});
});
it('should support invoking functions and methods', () => {
expect(expressions['invokeFn']).toEqual({'param': 'someParam'});
expect(expressions['concatedArray']).toEqual([0, 1]);
expect(expressions['invokeMethodExternalInstance'])
.toEqual({'data': 'someValue', 'param': 'someParam'});
expect(expressions['invokeMethodExternalInstanceViaBind'])
.toEqual({'data': 'someValue', 'param': 'someParam'});
expect(expressions['invokeMethodDynamicInstance']).toEqual({
'data': 'someValue',
'dynamicProp': 'dynamicValue',
'param': 'someParam'
});
expect(expressions['invokeMethodDynamicInstanceViaBind']).toEqual({
'data': 'someValue',
'dynamicProp': 'dynamicValue',
'param': 'someParam'
});
});
it('should support conditionals', () => {
expect(expressions['conditionalTrue']).toEqual('true');
expect(expressions['conditionalFalse']).toEqual('false');
});
it('should support conditionals', () => {
expect(expressions['conditionalTrue']).toEqual('true');
expect(expressions['conditionalFalse']).toEqual('false');
});
it('should support not', () => { expect(expressions['not']).toEqual(true); });
it('should support not', () => { expect(expressions['not']).toEqual(true); });
it('should support reading external identifiers', () => {
expect(expressions['externalTestIdentifier']).toBe(ExternalClass);
expect(expressions['externalSrcIdentifier']).toBe(EventEmitter);
expect(expressions['externalEnumIdentifier']).toBe(ViewType.HOST);
});
it('should support reading external identifiers', () => {
expect(expressions['externalTestIdentifier']).toBe(ExternalClass);
expect(expressions['externalSrcIdentifier']).toBe(EventEmitter);
expect(expressions['externalEnumIdentifier']).toBe(ViewType.HOST);
});
it('should support instantiating classes', () => {
expect(expressions['externalInstance']).toBeAnInstanceOf(ExternalClass);
// Note: toBeAnInstanceOf does not check super classes in Dart...
expect(expressions['dynamicInstance'] instanceof ExternalClass).toBe(true);
});
it('should support instantiating classes', () => {
expect(expressions['externalInstance']).toBeAnInstanceOf(ExternalClass);
// Note: toBeAnInstanceOf does not check super classes in Dart...
expect(expressions['dynamicInstance'] instanceof ExternalClass).toBe(true);
});
describe('operators', () => {
var ops: any /** TODO #9100 */;
var aObj: any /** TODO #9100 */, bObj: any /** TODO #9100 */;
beforeEach(() => {
ops = expressions['operators'];
aObj = new Object();
bObj = new Object();
describe('operators', () => {
var ops: any /** TODO #9100 */;
var aObj: any /** TODO #9100 */, bObj: any /** TODO #9100 */;
beforeEach(() => {
ops = expressions['operators'];
aObj = new Object();
bObj = new Object();
});
it('should support ==', () => {
expect(ops['=='](aObj, aObj)).toBe(true);
expect(ops['=='](aObj, bObj)).toBe(false);
expect(ops['=='](1, 1)).toBe(true);
expect(ops['=='](0, 1)).toBe(false);
expect(ops['==']('a', 'a')).toBe(true);
expect(ops['==']('a', 'b')).toBe(false);
});
it('should support !=', () => {
expect(ops['!='](aObj, aObj)).toBe(false);
expect(ops['!='](aObj, bObj)).toBe(true);
expect(ops['!='](1, 1)).toBe(false);
expect(ops['!='](0, 1)).toBe(true);
expect(ops['!=']('a', 'a')).toBe(false);
expect(ops['!=']('a', 'b')).toBe(true);
});
it('should support ===', () => {
expect(ops['==='](aObj, aObj)).toBe(true);
expect(ops['==='](aObj, bObj)).toBe(false);
expect(ops['==='](1, 1)).toBe(true);
expect(ops['==='](0, 1)).toBe(false);
});
it('should support !==', () => {
expect(ops['!=='](aObj, aObj)).toBe(false);
expect(ops['!=='](aObj, bObj)).toBe(true);
expect(ops['!=='](1, 1)).toBe(false);
expect(ops['!=='](0, 1)).toBe(true);
});
it('should support -', () => { expect(ops['-'](3, 2)).toEqual(1); });
it('should support +', () => { expect(ops['+'](1, 2)).toEqual(3); });
it('should support /', () => { expect(ops['/'](6, 2)).toEqual(3); });
it('should support *', () => { expect(ops['*'](2, 3)).toEqual(6); });
it('should support %', () => { expect(ops['%'](3, 2)).toEqual(1); });
it('should support &&', () => {
expect(ops['&&'](true, true)).toBe(true);
expect(ops['&&'](true, false)).toBe(false);
});
it('should support ||', () => {
expect(ops['||'](true, false)).toBe(true);
expect(ops['||'](false, false)).toBe(false);
});
it('should support <', () => {
expect(ops['<'](1, 2)).toBe(true);
expect(ops['<'](1, 1)).toBe(false);
});
it('should support <=', () => {
expect(ops['<='](1, 2)).toBe(true);
expect(ops['<='](1, 1)).toBe(true);
});
it('should support >', () => {
expect(ops['>'](2, 1)).toBe(true);
expect(ops['>'](1, 1)).toBe(false);
});
it('should support >=', () => {
expect(ops['>='](2, 1)).toBe(true);
expect(ops['>='](1, 1)).toBe(true);
});
});
it('should support throwing errors',
() => { expect(expressions['throwError']).toThrowError('someError'); });
it('should support catching errors', () => {
function someOperation() { throw new BaseException('Boom!'); }
var errorAndStack = expressions['catchError'](someOperation);
expect(errorAndStack[0].message).toEqual('Boom!');
// Somehow we don't get stacktraces on ios7...
if (!browserDetection.isIOS7 && !browserDetection.isIE) {
expect(errorAndStack[1].toString()).toContain('someOperation');
}
});
});
it('should support ==', () => {
expect(ops['=='](aObj, aObj)).toBe(true);
expect(ops['=='](aObj, bObj)).toBe(false);
expect(ops['=='](1, 1)).toBe(true);
expect(ops['=='](0, 1)).toBe(false);
expect(ops['==']('a', 'a')).toBe(true);
expect(ops['==']('a', 'b')).toBe(false);
});
it('should support !=', () => {
expect(ops['!='](aObj, aObj)).toBe(false);
expect(ops['!='](aObj, bObj)).toBe(true);
expect(ops['!='](1, 1)).toBe(false);
expect(ops['!='](0, 1)).toBe(true);
expect(ops['!=']('a', 'a')).toBe(false);
expect(ops['!=']('a', 'b')).toBe(true);
});
it('should support ===', () => {
expect(ops['==='](aObj, aObj)).toBe(true);
expect(ops['==='](aObj, bObj)).toBe(false);
expect(ops['==='](1, 1)).toBe(true);
expect(ops['==='](0, 1)).toBe(false);
});
it('should support !==', () => {
expect(ops['!=='](aObj, aObj)).toBe(false);
expect(ops['!=='](aObj, bObj)).toBe(true);
expect(ops['!=='](1, 1)).toBe(false);
expect(ops['!=='](0, 1)).toBe(true);
});
it('should support -', () => { expect(ops['-'](3, 2)).toEqual(1); });
it('should support +', () => { expect(ops['+'](1, 2)).toEqual(3); });
it('should support /', () => { expect(ops['/'](6, 2)).toEqual(3); });
it('should support *', () => { expect(ops['*'](2, 3)).toEqual(6); });
it('should support %', () => { expect(ops['%'](3, 2)).toEqual(1); });
it('should support &&', () => {
expect(ops['&&'](true, true)).toBe(true);
expect(ops['&&'](true, false)).toBe(false);
});
it('should support ||', () => {
expect(ops['||'](true, false)).toBe(true);
expect(ops['||'](false, false)).toBe(false);
});
it('should support <', () => {
expect(ops['<'](1, 2)).toBe(true);
expect(ops['<'](1, 1)).toBe(false);
});
it('should support <=', () => {
expect(ops['<='](1, 2)).toBe(true);
expect(ops['<='](1, 1)).toBe(true);
});
it('should support >', () => {
expect(ops['>'](2, 1)).toBe(true);
expect(ops['>'](1, 1)).toBe(false);
});
it('should support >=', () => {
expect(ops['>='](2, 1)).toBe(true);
expect(ops['>='](1, 1)).toBe(true);
});
});
it('should support throwing errors',
() => { expect(expressions['throwError']).toThrowError('someError'); });
it('should support catching errors', () => {
function someOperation() { throw new BaseException('Boom!'); }
var errorAndStack = expressions['catchError'](someOperation);
expect(errorAndStack[0].message).toEqual('Boom!');
// Somehow we don't get stacktraces on ios7...
if (!browserDetection.isIOS7 && !browserDetection.isIE) {
expect(errorAndStack[1].toString()).toContain('someOperation');
}
});
});
});
});
}

View File

@ -1,11 +1,11 @@
import {CompileIdentifierMetadata} from '@angular/compiler/src/compile_metadata';
import * as o from '@angular/compiler/src/output/output_ast';
import {DynamicInstance, InstanceFactory} from '@angular/compiler/src/output/output_interpreter';
import {assetUrl} from '@angular/compiler/src/util';
import {EventEmitter} from '@angular/core';
import {ViewType} from '@angular/core/src/linker/view_type';
import {BaseException} from '../../src/facade/exceptions';
import {InstanceFactory, DynamicInstance} from '@angular/compiler/src/output/output_interpreter';
import {assetUrl} from '@angular/compiler/src/util';
import * as o from '@angular/compiler/src/output/output_ast';
import {BaseException} from '../../src/facade/exceptions';
export class ExternalClass {
changeable: any;
@ -37,9 +37,7 @@ export var codegenExportsVars = [
var _getExpressionsStmts: o.Statement[] = [
o.variable('readVar')
.set(o.literal('someValue'))
.toDeclStmt(),
o.variable('readVar').set(o.literal('someValue')).toDeclStmt(),
o.variable('changedVar').set(o.literal('initialValue')).toDeclStmt(),
o.variable('changedVar').set(o.literal('changedValue')).toStmt(),
@ -58,34 +56,29 @@ var _getExpressionsStmts: o.Statement[] = [
o.variable('externalInstance').prop('changeable').set(o.literal('changedValue')).toStmt(),
o.variable('fn')
.set(o.fn([new o.FnParam('param')],
[new o.ReturnStatement(o.literalMap([['param', o.variable('param')]]))],
o.DYNAMIC_TYPE))
.set(o.fn(
[new o.FnParam('param')],
[new o.ReturnStatement(o.literalMap([['param', o.variable('param')]]))], o.DYNAMIC_TYPE))
.toDeclStmt(),
o.variable('throwError')
.set(o.fn([],
[
new o.ThrowStmt(o.importExpr(baseExceptionIdentifier)
.instantiate([o.literal('someError')]))
]))
.set(o.fn([], [new o.ThrowStmt(o.importExpr(baseExceptionIdentifier).instantiate([o.literal(
'someError')]))]))
.toDeclStmt(),
o.variable('catchError')
.set(o.fn([new o.FnParam('runCb')],
[
new o.TryCatchStmt([o.variable('runCb').callFn([]).toStmt()],
[
new o.ReturnStatement(
o.literalArr([o.CATCH_ERROR_VAR, o.CATCH_STACK_VAR]))
])
],
o.DYNAMIC_TYPE))
.set(o.fn(
[new o.FnParam('runCb')],
[new o.TryCatchStmt(
[o.variable('runCb').callFn([]).toStmt()],
[new o.ReturnStatement(o.literalArr([o.CATCH_ERROR_VAR, o.CATCH_STACK_VAR]))])],
o.DYNAMIC_TYPE))
.toDeclStmt(),
o.variable('dynamicInstance')
.set(o.variable('DynamicClass')
.instantiate([o.literal('someValue'), o.literal('dynamicValue')]))
.set(o.variable('DynamicClass').instantiate([
o.literal('someValue'), o.literal('dynamicValue')
]))
.toDeclStmt(),
o.variable('dynamicInstance').prop('dynamicChangeable').set(o.literal('changedValue')).toStmt(),
@ -129,9 +122,8 @@ var _getExpressionsStmts: o.Statement[] = [
.callFn([o.literal('someParam')])
],
[
'concatedArray',
o.literalArr([o.literal(0)])
.callMethod(o.BuiltinMethod.ConcatArray, [o.literalArr([o.literal(1)])])
'concatedArray', o.literalArr([o.literal(0)])
.callMethod(o.BuiltinMethod.ConcatArray, [o.literalArr([o.literal(1)])])
],
['fn', o.variable('fn')],
@ -139,18 +131,16 @@ var _getExpressionsStmts: o.Statement[] = [
['invokeFn', o.variable('fn').callFn([o.literal('someParam')])],
[
'conditionalTrue',
o.literal('')
.prop('length')
.equals(o.literal(0))
.conditional(o.literal('true'), o.literal('false'))
'conditionalTrue', o.literal('')
.prop('length')
.equals(o.literal(0))
.conditional(o.literal('true'), o.literal('false'))
],
[
'conditionalFalse',
o.literal('')
.prop('length')
.notEquals(o.literal(0))
.conditional(o.literal('true'), o.literal('false'))
'conditionalFalse', o.literal('')
.prop('length')
.notEquals(o.literal(0))
.conditional(o.literal('true'), o.literal('false'))
],
['not', o.not(o.literal(false))],
@ -166,8 +156,7 @@ var _getExpressionsStmts: o.Statement[] = [
['catchError', o.variable('catchError')],
[
'operators',
o.literalMap([
'operators', o.literalMap([
['==', createOperatorFn(o.BinaryOperator.Equals)],
['!=', createOperatorFn(o.BinaryOperator.NotEquals)],
['===', createOperatorFn(o.BinaryOperator.Identical)],
@ -257,8 +246,9 @@ function createOperatorFn(op: o.BinaryOperator) {
}
export class DynamicClassInstanceFactory implements InstanceFactory {
createInstance(superClass: any, clazz: any, args: any[], props: Map<string, any>,
getters: Map<string, Function>, methods: Map<string, Function>): any {
createInstance(
superClass: any, clazz: any, args: any[], props: Map<string, any>,
getters: Map<string, Function>, methods: Map<string, Function>): any {
if (superClass === ExternalClass) {
return new _InterpretiveDynamicClass(args, clazz, props, getters, methods);
}
@ -267,8 +257,9 @@ export class DynamicClassInstanceFactory implements InstanceFactory {
}
class _InterpretiveDynamicClass extends ExternalClass implements DynamicInstance {
constructor(args: any[], public clazz: any, public props: Map<string, any>,
public getters: Map<string, Function>, public methods: Map<string, Function>) {
constructor(
args: any[], public clazz: any, public props: Map<string, any>,
public getters: Map<string, Function>, public methods: Map<string, Function>) {
super(args[0]);
}
childMethod(a: any /** TODO #9100 */) { return this.methods.get('childMethod')(a); }

View File

@ -1,13 +1,4 @@
import {
beforeEach,
ddescribe,
describe,
expect,
iit,
inject,
it,
xit,
} from '@angular/core/testing/testing_internal';
import {beforeEach, ddescribe, describe, expect, iit, inject, it, xit,} from '@angular/core/testing/testing_internal';
import {isBlank} from '../../src/facade/lang';
import {TypeScriptEmitter} from '@angular/compiler/src/output/ts_emitter';
@ -112,11 +103,9 @@ export function main() {
it('should support external identifiers', () => {
expect(emitStmt(o.importExpr(sameModuleIdentifier).toStmt())).toEqual('someLocalId;');
expect(emitStmt(o.importExpr(externalModuleIdentifier).toStmt()))
.toEqual([
`import * as import0 from 'somePackage/someOtherPath';`,
`import0.someExternalId;`
].join('\n'));
expect(emitStmt(o.importExpr(externalModuleIdentifier).toStmt())).toEqual([
`import * as import0 from 'somePackage/someOtherPath';`, `import0.someExternalId;`
].join('\n'));
});
it('should support operators', () => {
@ -149,47 +138,46 @@ export function main() {
expect(emitStmt(o.fn([], []).toStmt())).toEqual(['():void => {', '};'].join('\n'));
expect(emitStmt(o.fn([], [new o.ReturnStatement(o.literal(1))], o.INT_TYPE).toStmt()))
.toEqual(['():number => {', ' return 1;\n};'].join('\n'));
expect(emitStmt(o.fn([new o.FnParam('param1', o.INT_TYPE)], []).toStmt()))
.toEqual(['(param1:number):void => {', '};'].join('\n'));
expect(emitStmt(o.fn([new o.FnParam('param1', o.INT_TYPE)], []).toStmt())).toEqual([
'(param1:number):void => {', '};'
].join('\n'));
});
it('should support function statements', () => {
expect(emitStmt(new o.DeclareFunctionStmt('someFn', [], [])))
.toEqual(['function someFn():void {', '}'].join('\n'));
expect(emitStmt(new o.DeclareFunctionStmt('someFn', [], []), ['someFn']))
.toEqual(['export function someFn():void {', '}'].join('\n'));
expect(emitStmt(new o.DeclareFunctionStmt('someFn', [], [new o.ReturnStatement(o.literal(1))],
o.INT_TYPE)))
expect(emitStmt(new o.DeclareFunctionStmt('someFn', [], [
]))).toEqual(['function someFn():void {', '}'].join('\n'));
expect(emitStmt(new o.DeclareFunctionStmt('someFn', [], []), ['someFn'])).toEqual([
'export function someFn():void {', '}'
].join('\n'));
expect(emitStmt(new o.DeclareFunctionStmt(
'someFn', [], [new o.ReturnStatement(o.literal(1))], o.INT_TYPE)))
.toEqual(['function someFn():number {', ' return 1;', '}'].join('\n'));
expect(
emitStmt(new o.DeclareFunctionStmt('someFn', [new o.FnParam('param1', o.INT_TYPE)], [])))
.toEqual(['function someFn(param1:number):void {', '}'].join('\n'));
expect(emitStmt(new o.DeclareFunctionStmt('someFn', [new o.FnParam('param1', o.INT_TYPE)], [
]))).toEqual(['function someFn(param1:number):void {', '}'].join('\n'));
});
it('should support comments',
() => { expect(emitStmt(new o.CommentStmt('a\nb'))).toEqual(['// a', '// b'].join('\n')); });
it('should support comments', () => {
expect(emitStmt(new o.CommentStmt('a\nb'))).toEqual(['// a', '// b'].join('\n'));
});
it('should support if stmt', () => {
var trueCase = o.variable('trueCase').callFn([]).toStmt();
var falseCase = o.variable('falseCase').callFn([]).toStmt();
expect(emitStmt(new o.IfStmt(o.variable('cond'), [trueCase])))
.toEqual(['if (cond) { trueCase(); }'].join('\n'));
expect(emitStmt(new o.IfStmt(o.variable('cond'), [trueCase], [falseCase])))
.toEqual(['if (cond) {', ' trueCase();', '} else {', ' falseCase();', '}'].join('\n'));
expect(emitStmt(new o.IfStmt(o.variable('cond'), [trueCase]))).toEqual([
'if (cond) { trueCase(); }'
].join('\n'));
expect(emitStmt(new o.IfStmt(o.variable('cond'), [trueCase], [falseCase]))).toEqual([
'if (cond) {', ' trueCase();', '} else {', ' falseCase();', '}'
].join('\n'));
});
it('should support try/catch', () => {
var bodyStmt = o.variable('body').callFn([]).toStmt();
var catchStmt = o.variable('catchFn').callFn([o.CATCH_ERROR_VAR, o.CATCH_STACK_VAR]).toStmt();
expect(emitStmt(new o.TryCatchStmt([bodyStmt], [catchStmt])))
.toEqual([
'try {',
' body();',
'} catch (error) {',
' const stack:any = error.stack;',
' catchFn(error,stack);',
'}'
].join('\n'));
expect(emitStmt(new o.TryCatchStmt([bodyStmt], [catchStmt]))).toEqual([
'try {', ' body();', '} catch (error) {', ' const stack:any = error.stack;',
' catchFn(error,stack);', '}'
].join('\n'));
});
it('should support support throwing',
@ -202,13 +190,12 @@ export function main() {
it('should support declaring classes', () => {
expect(emitStmt(new o.ClassStmt('SomeClass', null, [], [], null, [])))
.toEqual(['class SomeClass {', '}'].join('\n'));
expect(emitStmt(new o.ClassStmt('SomeClass', null, [], [], null, [
]))).toEqual(['class SomeClass {', '}'].join('\n'));
expect(emitStmt(new o.ClassStmt('SomeClass', null, [], [], null, []), ['SomeClass']))
.toEqual(['export class SomeClass {', '}'].join('\n'));
expect(
emitStmt(new o.ClassStmt('SomeClass', o.variable('SomeSuperClass'), [], [], null, [])))
.toEqual(['class SomeClass extends SomeSuperClass {', '}'].join('\n'));
expect(emitStmt(new o.ClassStmt('SomeClass', o.variable('SomeSuperClass'), [], [], null, [
]))).toEqual(['class SomeClass extends SomeSuperClass {', '}'].join('\n'));
});
it('should support declaring constructors', () => {
@ -221,23 +208,24 @@ export function main() {
new o.ClassMethod(null, [new o.FnParam('someParam', o.INT_TYPE)], []), [])))
.toEqual(
['class SomeClass {', ' constructor(someParam:number) {', ' }', '}'].join('\n'));
expect(emitStmt(new o.ClassStmt('SomeClass', null, [], [],
new o.ClassMethod(null, [], [superCall]), [])))
.toEqual(['class SomeClass {', ' constructor() {', ' super(someParam);', ' }', '}']
.join('\n'));
expect(emitStmt(new o.ClassStmt('SomeClass', null, [], [],
new o.ClassMethod(null, [], [callSomeMethod]), [])))
.toEqual(
['class SomeClass {', ' constructor() {', ' this.someMethod();', ' }', '}']
.join('\n'));
expect(emitStmt(new o.ClassStmt(
'SomeClass', null, [], [], new o.ClassMethod(null, [], [superCall]), [])))
.toEqual([
'class SomeClass {', ' constructor() {', ' super(someParam);', ' }', '}'
].join('\n'));
expect(emitStmt(new o.ClassStmt(
'SomeClass', null, [], [], new o.ClassMethod(null, [], [callSomeMethod]), [])))
.toEqual([
'class SomeClass {', ' constructor() {', ' this.someMethod();', ' }', '}'
].join('\n'));
});
it('should support declaring fields', () => {
expect(emitStmt(new o.ClassStmt('SomeClass', null, [new o.ClassField('someField')], [],
null, [])))
expect(emitStmt(new o.ClassStmt(
'SomeClass', null, [new o.ClassField('someField')], [], null, [])))
.toEqual(['class SomeClass {', ' someField:any;', '}'].join('\n'));
expect(emitStmt(new o.ClassStmt('SomeClass', null,
[new o.ClassField('someField', o.INT_TYPE)], [], null, [])))
expect(emitStmt(new o.ClassStmt(
'SomeClass', null, [new o.ClassField('someField', o.INT_TYPE)], [], null, [])))
.toEqual(['class SomeClass {', ' someField:number;', '}'].join('\n'));
expect(emitStmt(new o.ClassStmt(
'SomeClass', null,
@ -247,45 +235,47 @@ export function main() {
});
it('should support declaring getters', () => {
expect(emitStmt(new o.ClassStmt('SomeClass', null, [],
[new o.ClassGetter('someGetter', [])], null, [])))
expect(emitStmt(new o.ClassStmt(
'SomeClass', null, [], [new o.ClassGetter('someGetter', [])], null, [])))
.toEqual(['class SomeClass {', ' get someGetter():any {', ' }', '}'].join('\n'));
expect(
emitStmt(new o.ClassStmt('SomeClass', null, [],
[new o.ClassGetter('someGetter', [], o.INT_TYPE)], null, [])))
expect(emitStmt(new o.ClassStmt(
'SomeClass', null, [], [new o.ClassGetter('someGetter', [], o.INT_TYPE)], null,
[])))
.toEqual(['class SomeClass {', ' get someGetter():number {', ' }', '}'].join('\n'));
expect(emitStmt(new o.ClassStmt('SomeClass', null, [],
[new o.ClassGetter('someGetter', [callSomeMethod])], null,
[])))
.toEqual(
['class SomeClass {', ' get someGetter():any {', ' this.someMethod();', ' }', '}']
.join('\n'));
expect(emitStmt(new o.ClassStmt(
'SomeClass', null, [], [new o.ClassGetter('someGetter', [callSomeMethod])], null,
[])))
.toEqual([
'class SomeClass {', ' get someGetter():any {', ' this.someMethod();', ' }', '}'
].join('\n'));
expect(
emitStmt(new o.ClassStmt(
'SomeClass', null, [],
[new o.ClassGetter('someGetter', [], null, [o.StmtModifier.Private])], null, [])))
.toEqual(['class SomeClass {', ' private get someGetter():any {', ' }', '}'].join('\n'));
.toEqual(
['class SomeClass {', ' private get someGetter():any {', ' }', '}'].join('\n'));
});
it('should support methods', () => {
expect(emitStmt(new o.ClassStmt('SomeClass', null, [], [], null,
[new o.ClassMethod('someMethod', [], [])])))
.toEqual(['class SomeClass {', ' someMethod():void {', ' }', '}'].join('\n'));
expect(emitStmt(new o.ClassStmt('SomeClass', null, [], [], null,
[new o.ClassMethod('someMethod', [], [], o.INT_TYPE)])))
.toEqual(['class SomeClass {', ' someMethod():number {', ' }', '}'].join('\n'));
expect(emitStmt(new o.ClassStmt('SomeClass', null, [], [], null, [
new o.ClassMethod('someMethod', [], [])
]))).toEqual(['class SomeClass {', ' someMethod():void {', ' }', '}'].join('\n'));
expect(emitStmt(new o.ClassStmt('SomeClass', null, [], [], null, [
new o.ClassMethod('someMethod', [], [], o.INT_TYPE)
]))).toEqual(['class SomeClass {', ' someMethod():number {', ' }', '}'].join('\n'));
expect(
emitStmt(new o.ClassStmt(
'SomeClass', null, [], [], null,
[new o.ClassMethod('someMethod', [new o.FnParam('someParam', o.INT_TYPE)], [])])))
.toEqual(
['class SomeClass {', ' someMethod(someParam:number):void {', ' }', '}'].join(
'\n'));
expect(emitStmt(new o.ClassStmt('SomeClass', null, [], [], null,
[new o.ClassMethod('someMethod', [], [callSomeMethod])])))
.toEqual(
['class SomeClass {', ' someMethod():void {', ' this.someMethod();', ' }', '}']
.join('\n'));
.toEqual([
'class SomeClass {', ' someMethod(someParam:number):void {', ' }', '}'
].join('\n'));
expect(emitStmt(new o.ClassStmt(
'SomeClass', null, [], [], null,
[new o.ClassMethod('someMethod', [], [callSomeMethod])])))
.toEqual([
'class SomeClass {', ' someMethod():void {', ' this.someMethod();', ' }', '}'
].join('\n'));
});
});
@ -303,11 +293,10 @@ export function main() {
var writeVarExpr = o.variable('a').set(o.NULL_EXPR);
expect(emitStmt(writeVarExpr.toDeclStmt(o.importType(sameModuleIdentifier))))
.toEqual('var a:someLocalId = null;');
expect(emitStmt(writeVarExpr.toDeclStmt(o.importType(externalModuleIdentifier))))
.toEqual([
`import * as import0 from 'somePackage/someOtherPath';`,
`var a:import0.someExternalId = null;`
].join('\n'));
expect(emitStmt(writeVarExpr.toDeclStmt(o.importType(externalModuleIdentifier)))).toEqual([
`import * as import0 from 'somePackage/someOtherPath';`,
`var a:import0.someExternalId = null;`
].join('\n'));
});
it('should support combined types', () => {