fix(compiler): allow --noImplicitAny
This commit is contained in:
@ -60,6 +60,13 @@ class _TsEmitterVisitor extends AbstractEmitterVisitor implements o.TypeVisitor
|
|||||||
|
|
||||||
importsWithPrefixes = new Map<string, string>();
|
importsWithPrefixes = new Map<string, string>();
|
||||||
|
|
||||||
|
visitType(t: o.Type, ctx: EmitterVisitorContext, defaultType: string = 'any') {
|
||||||
|
if (isPresent(t)) {
|
||||||
|
t.visitType(this, ctx);
|
||||||
|
} else {
|
||||||
|
ctx.print(defaultType);
|
||||||
|
}
|
||||||
|
}
|
||||||
visitExternalExpr(ast: o.ExternalExpr, ctx: EmitterVisitorContext): any {
|
visitExternalExpr(ast: o.ExternalExpr, ctx: EmitterVisitorContext): any {
|
||||||
this._visitIdentifier(ast.value, ast.typeParams, ctx);
|
this._visitIdentifier(ast.value, ast.typeParams, ctx);
|
||||||
return null;
|
return null;
|
||||||
@ -73,11 +80,8 @@ class _TsEmitterVisitor extends AbstractEmitterVisitor implements o.TypeVisitor
|
|||||||
} else {
|
} else {
|
||||||
ctx.print(`var`);
|
ctx.print(`var`);
|
||||||
}
|
}
|
||||||
ctx.print(` ${stmt.name}`);
|
ctx.print(` ${stmt.name}:`);
|
||||||
if (isPresent(stmt.type)) {
|
this.visitType(stmt.type, ctx);
|
||||||
ctx.print(`:`);
|
|
||||||
stmt.type.visitType(this, ctx);
|
|
||||||
}
|
|
||||||
ctx.print(` = `);
|
ctx.print(` = `);
|
||||||
stmt.value.visitExpression(this, ctx);
|
stmt.value.visitExpression(this, ctx);
|
||||||
ctx.println(`;`);
|
ctx.println(`;`);
|
||||||
@ -119,12 +123,8 @@ class _TsEmitterVisitor extends AbstractEmitterVisitor implements o.TypeVisitor
|
|||||||
ctx.print(`private `);
|
ctx.print(`private `);
|
||||||
}
|
}
|
||||||
ctx.print(field.name);
|
ctx.print(field.name);
|
||||||
if (isPresent(field.type)) {
|
ctx.print(':');
|
||||||
ctx.print(`:`);
|
this.visitType(field.type, ctx);
|
||||||
field.type.visitType(this, ctx);
|
|
||||||
} else {
|
|
||||||
ctx.print(`: any`);
|
|
||||||
}
|
|
||||||
ctx.println(`;`);
|
ctx.println(`;`);
|
||||||
}
|
}
|
||||||
private _visitClassGetter(getter: o.ClassGetter, ctx: EmitterVisitorContext) {
|
private _visitClassGetter(getter: o.ClassGetter, ctx: EmitterVisitorContext) {
|
||||||
@ -132,10 +132,8 @@ class _TsEmitterVisitor extends AbstractEmitterVisitor implements o.TypeVisitor
|
|||||||
ctx.print(`private `);
|
ctx.print(`private `);
|
||||||
}
|
}
|
||||||
ctx.print(`get ${getter.name}()`);
|
ctx.print(`get ${getter.name}()`);
|
||||||
if (isPresent(getter.type)) {
|
ctx.print(':');
|
||||||
ctx.print(`:`);
|
this.visitType(getter.type, ctx);
|
||||||
getter.type.visitType(this, ctx);
|
|
||||||
}
|
|
||||||
ctx.println(` {`);
|
ctx.println(` {`);
|
||||||
ctx.incIndent();
|
ctx.incIndent();
|
||||||
this.visitAllStatements(getter.body, ctx);
|
this.visitAllStatements(getter.body, ctx);
|
||||||
@ -158,11 +156,7 @@ class _TsEmitterVisitor extends AbstractEmitterVisitor implements o.TypeVisitor
|
|||||||
ctx.print(`${method.name}(`);
|
ctx.print(`${method.name}(`);
|
||||||
this._visitParams(method.params, ctx);
|
this._visitParams(method.params, ctx);
|
||||||
ctx.print(`):`);
|
ctx.print(`):`);
|
||||||
if (isPresent(method.type)) {
|
this.visitType(method.type, ctx, 'void');
|
||||||
method.type.visitType(this, ctx);
|
|
||||||
} else {
|
|
||||||
ctx.print(`void`);
|
|
||||||
}
|
|
||||||
ctx.println(` {`);
|
ctx.println(` {`);
|
||||||
ctx.incIndent();
|
ctx.incIndent();
|
||||||
this.visitAllStatements(method.body, ctx);
|
this.visitAllStatements(method.body, ctx);
|
||||||
@ -173,11 +167,7 @@ class _TsEmitterVisitor extends AbstractEmitterVisitor implements o.TypeVisitor
|
|||||||
ctx.print(`(`);
|
ctx.print(`(`);
|
||||||
this._visitParams(ast.params, ctx);
|
this._visitParams(ast.params, ctx);
|
||||||
ctx.print(`):`);
|
ctx.print(`):`);
|
||||||
if (isPresent(ast.type)) {
|
this.visitType(ast.type, ctx, 'void');
|
||||||
ast.type.visitType(this, ctx);
|
|
||||||
} else {
|
|
||||||
ctx.print(`void`);
|
|
||||||
}
|
|
||||||
ctx.println(` => {`);
|
ctx.println(` => {`);
|
||||||
ctx.incIndent();
|
ctx.incIndent();
|
||||||
this.visitAllStatements(ast.statements, ctx);
|
this.visitAllStatements(ast.statements, ctx);
|
||||||
@ -192,11 +182,7 @@ class _TsEmitterVisitor extends AbstractEmitterVisitor implements o.TypeVisitor
|
|||||||
ctx.print(`function ${stmt.name}(`);
|
ctx.print(`function ${stmt.name}(`);
|
||||||
this._visitParams(stmt.params, ctx);
|
this._visitParams(stmt.params, ctx);
|
||||||
ctx.print(`):`);
|
ctx.print(`):`);
|
||||||
if (isPresent(stmt.type)) {
|
this.visitType(stmt.type, ctx, 'void');
|
||||||
stmt.type.visitType(this, ctx);
|
|
||||||
} else {
|
|
||||||
ctx.print(`void`);
|
|
||||||
}
|
|
||||||
ctx.println(` {`);
|
ctx.println(` {`);
|
||||||
ctx.incIndent();
|
ctx.incIndent();
|
||||||
this.visitAllStatements(stmt.statements, ctx);
|
this.visitAllStatements(stmt.statements, ctx);
|
||||||
@ -253,21 +239,13 @@ class _TsEmitterVisitor extends AbstractEmitterVisitor implements o.TypeVisitor
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
visitArrayType(type: o.ArrayType, ctx: EmitterVisitorContext): any {
|
visitArrayType(type: o.ArrayType, ctx: EmitterVisitorContext): any {
|
||||||
if (isPresent(type.of)) {
|
this.visitType(type.of, ctx);
|
||||||
type.of.visitType(this, ctx);
|
|
||||||
} else {
|
|
||||||
ctx.print(`any`);
|
|
||||||
}
|
|
||||||
ctx.print(`[]`);
|
ctx.print(`[]`);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
visitMapType(type: o.MapType, ctx: EmitterVisitorContext): any {
|
visitMapType(type: o.MapType, ctx: EmitterVisitorContext): any {
|
||||||
ctx.print(`{[key: string]:`);
|
ctx.print(`{[key: string]:`);
|
||||||
if (isPresent(type.valueType)) {
|
this.visitType(type.valueType, ctx);
|
||||||
type.valueType.visitType(this, ctx);
|
|
||||||
} else {
|
|
||||||
ctx.print(`any`);
|
|
||||||
}
|
|
||||||
ctx.print(`}`);
|
ctx.print(`}`);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -294,10 +272,8 @@ class _TsEmitterVisitor extends AbstractEmitterVisitor implements o.TypeVisitor
|
|||||||
private _visitParams(params: o.FnParam[], ctx: EmitterVisitorContext): void {
|
private _visitParams(params: o.FnParam[], ctx: EmitterVisitorContext): void {
|
||||||
this.visitAllObjects((param) => {
|
this.visitAllObjects((param) => {
|
||||||
ctx.print(param.name);
|
ctx.print(param.name);
|
||||||
if (isPresent(param.type)) {
|
ctx.print(':');
|
||||||
ctx.print(`:`);
|
this.visitType(param.type, ctx);
|
||||||
param.type.visitType(this, ctx);
|
|
||||||
}
|
|
||||||
}, params, ctx, ',');
|
}, params, ctx, ',');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,11 +46,11 @@ export function main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
it('should declare variables', () => {
|
it('should declare variables', () => {
|
||||||
expect(emitStmt(someVar.set(o.literal(1)).toDeclStmt())).toEqual(`var someVar = 1;`);
|
expect(emitStmt(someVar.set(o.literal(1)).toDeclStmt())).toEqual(`var someVar:any = 1;`);
|
||||||
expect(emitStmt(someVar.set(o.literal(1)).toDeclStmt(null, [o.StmtModifier.Final])))
|
expect(emitStmt(someVar.set(o.literal(1)).toDeclStmt(null, [o.StmtModifier.Final])))
|
||||||
.toEqual(`const someVar = 1;`);
|
.toEqual(`const someVar:any = 1;`);
|
||||||
expect(emitStmt(someVar.set(o.literal(1)).toDeclStmt(), ['someVar']))
|
expect(emitStmt(someVar.set(o.literal(1)).toDeclStmt(), ['someVar']))
|
||||||
.toEqual(`export var someVar = 1;`);
|
.toEqual(`export var someVar:any = 1;`);
|
||||||
expect(emitStmt(someVar.set(o.literal(1)).toDeclStmt(o.INT_TYPE)))
|
expect(emitStmt(someVar.set(o.literal(1)).toDeclStmt(o.INT_TYPE)))
|
||||||
.toEqual(`var someVar:number = 1;`);
|
.toEqual(`var someVar:number = 1;`);
|
||||||
});
|
});
|
||||||
@ -186,7 +186,7 @@ export function main() {
|
|||||||
'try {',
|
'try {',
|
||||||
' body();',
|
' body();',
|
||||||
'} catch (error) {',
|
'} catch (error) {',
|
||||||
' const stack = error.stack;',
|
' const stack:any = error.stack;',
|
||||||
' catchFn(error,stack);',
|
' catchFn(error,stack);',
|
||||||
'}'
|
'}'
|
||||||
].join('\n'));
|
].join('\n'));
|
||||||
@ -235,7 +235,7 @@ export function main() {
|
|||||||
it('should support declaring fields', () => {
|
it('should support declaring fields', () => {
|
||||||
expect(emitStmt(new o.ClassStmt('SomeClass', null, [new o.ClassField('someField')], [],
|
expect(emitStmt(new o.ClassStmt('SomeClass', null, [new o.ClassField('someField')], [],
|
||||||
null, [])))
|
null, [])))
|
||||||
.toEqual(['class SomeClass {', ' someField: any;', '}'].join('\n'));
|
.toEqual(['class SomeClass {', ' someField:any;', '}'].join('\n'));
|
||||||
expect(emitStmt(new o.ClassStmt('SomeClass', null,
|
expect(emitStmt(new o.ClassStmt('SomeClass', null,
|
||||||
[new o.ClassField('someField', o.INT_TYPE)], [], null, [])))
|
[new o.ClassField('someField', o.INT_TYPE)], [], null, [])))
|
||||||
.toEqual(['class SomeClass {', ' someField:number;', '}'].join('\n'));
|
.toEqual(['class SomeClass {', ' someField:number;', '}'].join('\n'));
|
||||||
@ -249,7 +249,7 @@ export function main() {
|
|||||||
it('should support declaring getters', () => {
|
it('should support declaring getters', () => {
|
||||||
expect(emitStmt(new o.ClassStmt('SomeClass', null, [],
|
expect(emitStmt(new o.ClassStmt('SomeClass', null, [],
|
||||||
[new o.ClassGetter('someGetter', [])], null, [])))
|
[new o.ClassGetter('someGetter', [])], null, [])))
|
||||||
.toEqual(['class SomeClass {', ' get someGetter() {', ' }', '}'].join('\n'));
|
.toEqual(['class SomeClass {', ' get someGetter():any {', ' }', '}'].join('\n'));
|
||||||
expect(
|
expect(
|
||||||
emitStmt(new o.ClassStmt('SomeClass', null, [],
|
emitStmt(new o.ClassStmt('SomeClass', null, [],
|
||||||
[new o.ClassGetter('someGetter', [], o.INT_TYPE)], null, [])))
|
[new o.ClassGetter('someGetter', [], o.INT_TYPE)], null, [])))
|
||||||
@ -258,13 +258,13 @@ export function main() {
|
|||||||
[new o.ClassGetter('someGetter', [callSomeMethod])], null,
|
[new o.ClassGetter('someGetter', [callSomeMethod])], null,
|
||||||
[])))
|
[])))
|
||||||
.toEqual(
|
.toEqual(
|
||||||
['class SomeClass {', ' get someGetter() {', ' this.someMethod();', ' }', '}']
|
['class SomeClass {', ' get someGetter():any {', ' this.someMethod();', ' }', '}']
|
||||||
.join('\n'));
|
.join('\n'));
|
||||||
expect(
|
expect(
|
||||||
emitStmt(new o.ClassStmt(
|
emitStmt(new o.ClassStmt(
|
||||||
'SomeClass', null, [],
|
'SomeClass', null, [],
|
||||||
[new o.ClassGetter('someGetter', [], null, [o.StmtModifier.Private])], null, [])))
|
[new o.ClassGetter('someGetter', [], null, [o.StmtModifier.Private])], null, [])))
|
||||||
.toEqual(['class SomeClass {', ' private get someGetter() {', ' }', '}'].join('\n'));
|
.toEqual(['class SomeClass {', ' private get someGetter():any {', ' }', '}'].join('\n'));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should support methods', () => {
|
it('should support methods', () => {
|
||||||
|
@ -14,7 +14,7 @@ export const SOME_OPAQUE_TOKEN = new OpaqueToken('opaqueToken');
|
|||||||
]
|
]
|
||||||
})
|
})
|
||||||
export class CompWithProviders {
|
export class CompWithProviders {
|
||||||
constructor(@Inject('strToken') public ctxProp) {}
|
constructor(@Inject('strToken') public ctxProp: string) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"target": "es5",
|
"target": "es5",
|
||||||
"experimentalDecorators": true,
|
"experimentalDecorators": true,
|
||||||
"noImplicitAny": false,
|
"noImplicitAny": true,
|
||||||
"moduleResolution": "node",
|
"moduleResolution": "node",
|
||||||
"outDir": "../../../../dist/all/@angular/compiler_cli/integrationtest",
|
"outDir": "../../../../dist/all/@angular/compiler_cli/integrationtest",
|
||||||
"rootDir": "",
|
"rootDir": "",
|
||||||
|
Reference in New Issue
Block a user