feat(compiler): add a pseudo $any() function to disable type checking (#20876)

`$any()` can now be used in a binding expression to disable type
checking for the rest of the expression. This similar to `as any` in
TypeScript and allows expression that work at runtime but do not
type-check.

PR Close #20876
This commit is contained in:
Chuck Jazdzewski
2017-12-06 10:32:39 -08:00
committed by Jason Aden
parent 7363b3d4b5
commit 70cd124ede
2 changed files with 121 additions and 6 deletions

View File

@ -340,6 +340,15 @@ class _AstToIrVisitor implements cdAst.AstVisitor {
private _getLocal(name: string): o.Expression|null { return this._localResolver.getLocal(name); }
visitMethodCall(ast: cdAst.MethodCall, mode: _Mode): any {
if (ast.receiver instanceof cdAst.ImplicitReceiver && ast.name == '$any') {
const args = this.visitAll(ast.args, _Mode.Expression) as any[];
if (args.length != 1) {
throw new Error(
`Invalid call to $any, expected 1 argument but received ${args.length || 'none'}`);
}
return (args[0] as o.Expression).cast(o.DYNAMIC_TYPE);
}
const leftMostSafe = this.leftMostSafeNode(ast);
if (leftMostSafe) {
return this.convertSafeAccess(ast, leftMostSafe, mode);