in lib/semantic.js [1187:1225]
visitAPI(ast) {
assert.equal(ast.type, 'api');
const paramMap = this.visitParams(ast.params, {
needValidateParams: true
});
this.checkType(ast.returnType);
const returnType = ast.returnType;
if(returnType.type === 'iterator') {
this.error(`api return type must be asyncIterator`, ast.apiName);
}
const local = new Env();
// merge the parameters into local env
for (const [key, value] of paramMap) {
local.set(key, value);
}
const env = {
returnType,
isAsync: true,
local: local
};
env.local.set('__request', _model('$Request'));
this.visitAPIBody(ast.apiBody, env);
ast.isAsync = true;
if (ast.returns) {
env.inReturnsBlock = true;
env.local.set('__response', _model('$Response'));
this.visitReturnBody(ast.returns, env);
if (!(returnType.tag === Tag.TYPE && returnType.lexeme === 'void') &&
!this.hasReturnStmt(ast.returns.stmts)) {
this.error(`no return statement`, ast.apiName);
}
}
if (ast.runtimeBody) {
this.visitObject(ast.runtimeBody, env);
}
}