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