in lib/semantic.js [678:718]
postCheckInit(ast) {
const api = ast.moduleBody.nodes.find((item) => {
return item.type === 'api';
});
const func = ast.moduleBody.nodes.find((item) => {
// non-static function
return item.type === 'function' && item.isStatic === false;
});
const init = ast.moduleBody.nodes.find((item) => {
return item.type === 'init';
});
if (api || func) {
if (!init && !this.parentModuleId) {
this.error('Must have a init when there is a api or non-static function');
}
}
if (init) {
const paramMap = this.visitParams(init.params, {
needValidateParams: true
});
if (init.initBody) {
const local = new Env();
// merge the parameters into local env
for (const [key, value] of paramMap) {
local.set(key, value);
}
const env = {
isStatic: false,
isAsync: false,
isInitMethod: true,
local: local
};
this.visitStmts(init.initBody, env);
}
}
this.init = init;
}