fix(ngc): codegen allows --strictNullChecks (#10991)

This commit is contained in:
Alex Eagle
2016-08-22 15:30:18 -07:00
committed by Kara
parent 8560e1e4bf
commit 01111b04ff
3 changed files with 25 additions and 14 deletions

View File

@ -250,12 +250,13 @@ export abstract class AbstractEmitterVisitor implements o.StatementVisitor, o.Ex
ctx.print(`)`);
return null;
}
visitLiteralExpr(ast: o.LiteralExpr, ctx: EmitterVisitorContext): any {
visitLiteralExpr(ast: o.LiteralExpr, ctx: EmitterVisitorContext, absentValue: string = 'null'):
any {
var value = ast.value;
if (isString(value)) {
ctx.print(escapeSingleQuoteString(value, this._escapeDollarInStrings));
} else if (isBlank(value)) {
ctx.print('null');
ctx.print(absentValue);
} else {
ctx.print(`${value}`);
}

View File

@ -72,6 +72,10 @@ class _TsEmitterVisitor extends AbstractEmitterVisitor implements o.TypeVisitor
}
}
visitLiteralExpr(ast: o.LiteralExpr, ctx: EmitterVisitorContext): any {
super.visitLiteralExpr(ast, ctx, '(null as any)');
}
visitExternalExpr(ast: o.ExternalExpr, ctx: EmitterVisitorContext): any {
this._visitIdentifier(ast.value, ast.typeParams, ctx);
return null;