in lib/generator.js [357:440]
visitModule(ast, filepath, main, level) {
assert.equal(ast.type, 'module');
this.ast = ast;
this.predefined = ast.models;
this.parentModule = ast.extends;
this.comments = ast.comments;
this.notes = ast.notes;
this.usedExternException = ast.usedExternException;
this.requires = {};
this.moduleTypedef = {};
ast.innerModule = new Map();
this.moduleClass = new Map();
this.clientName = new Map();
if(this.overwrite(ast, filepath) === false) {
return;
}
if(main) {
this.clientName.set(this.config.clientName, true);
}
this.builtin = getBuiltin(this);
this.eachImport(ast.imports, ast.usedExternModel, filepath, ast.innerModule, level);
this.namespace = this.config.package.split('.').join('\\');
this.visitModels(ast, filepath, level);
this.visitExceptions(ast, filepath, level);
const apis = ast.moduleBody.nodes.filter((item) => {
return item.type === 'api';
});
if(apis.length > 0) {
this.used.push(`use ${CORE};`);
this.clientName.set('Dara', true);
}
this.visitAnnotation(ast.annotation, level);
// // models definition
this.apiBefore(main, filepath, level);
const types = ast.moduleBody.nodes.filter((item) => {
return item.type === 'type';
});
const inits = ast.moduleBody.nodes.filter((item) => {
return item.type === 'init';
});
const [init] = inits;
if (init) {
this.visitInit(init, types, level);
}
let lastToken = 0;
for (let i = 0; i < apis.length; i++) {
if (i !== 0) {
this.emit('\n');
}
const apiNotes = DSL.note.getNotes(this.notes, lastToken, apis[i].tokenRange[0]);
const sse = apiNotes.find(note => note.note.lexeme === '@sse');
lastToken = apis[i].tokenRange[1];
this.eachAPI(apis[i], level + 1, sse && sse.arg.value);
}
this.functionBefore();
const functions = ast.moduleBody.nodes.filter((item) => {
return item.type === 'function';
});
for (let i = 0; i < functions.length; i++) {
if (i !== 0) {
this.emit('\n');
}
this.eachFunction(functions[i], level + 1);
}
this.moduleAfter();
if (this.config.exec) {
this.emitExec();
}
this.save(filepath);
this.saveInnerModule(ast, filepath);
}