UNPKG

sails-js-parser

Version:

Sails-IDL parser for TypeScript

90 lines (87 loc) 2.15 kB
var util = require('./util.cjs'); var visitor = require('./visitor.cjs'); class Program { _services; _types; _context; _ctor; constructor() { this._services = []; this._types = new Map(); this._context = new Map(); } addService(service) { this._services.push(service); } addType(type) { const id = type.rawPtr; this._types.set(id, type); this._context.set(id, type); return id; } get services() { return this._services; } get ctor() { return this._ctor; } getType(id) { return this._types.get(id); } getContext(id) { return this._context.get(id); } addContext(id, ctx) { this._context.set(id, ctx); } get types() { return [...this._types.values()]; } getTypeByName(name) { const types = this.types.filter((type) => type.name === name); if (types.length > 1) throw new Error(`multiple types found with name ${name}`); if (types.length === 0) throw new Error(`no type found with name ${name}`); return types[0]; } addCtor(ctor) { this._ctor = ctor; } } class Ctor extends visitor.Base { funcs; constructor(ptr, memory) { super(ptr, memory); this.funcs = []; } addFunc(func) { this.funcs.push(func); } } class CtorFunc extends visitor.Base { _params; name; docs; constructor(ptr, memory) { super(ptr, memory); const [name, nameOffset] = util.getName(ptr, this.offset, memory); this.name = name; this.offset += nameOffset; const [docs, docsOffset] = util.getDocs(ptr, this.offset, memory); this.docs = docs; this.offset += docsOffset; this._params = new Map(); } addFuncParam(ptr, param) { this._params.set(ptr, param); } get params() { if (this._params.size === 0) return []; return [...this._params.values()]; } } exports.Ctor = Ctor; exports.CtorFunc = CtorFunc; exports.Program = Program;