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:

committed by
Jason Aden

parent
7363b3d4b5
commit
70cd124ede
@ -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);
|
||||
|
Reference in New Issue
Block a user