tsgen updates

This commit is contained in:
Richard Davey 2024-02-02 13:58:08 +00:00
parent dd16a081b8
commit 003dbe0d47
3 changed files with 59 additions and 9 deletions

View file

@ -20,6 +20,9 @@ class Parser {
// overridden) members globally from the parsed DB
this.resolveInheritance(docs);
this.resolveParents(docs);
console.log('------------------------------------------------------------------');
console.log('Add Integer Alias and Declare Module');
console.log('------------------------------------------------------------------');
// add integer alias
this.topLevel.push(dom.create.alias('integer', dom.type.number));
// add declare module
@ -28,6 +31,9 @@ class Parser {
this.topLevel.push(phaserPkgModuleDOM);
}
emit() {
console.log('------------------------------------------------------------------');
console.log('Parser Emit');
console.log('------------------------------------------------------------------');
let ignored = [];
let result = '// DO NOT EDIT THIS FILE! It was generated by running `npm run tsgen`\n/// <reference types="./matter" />\n\n';
result = result.concat(this.topLevel.reduce((out, obj) => {
@ -150,6 +156,7 @@ class Parser {
let allTypes = new Set();
for (let doclet of docs) {
let obj = (doclet.kind === 'namespace') ? this.namespaces[doclet.longname] : this.objects[doclet.longname];
// console.log(`${doclet.longname} - Kind: ${doclet.kind}`);
if (!obj) {
console.log(`${doclet.longname} - Kind: ${doclet.kind}`);
console.log(`Warning: Didn't find object`);
@ -165,6 +172,9 @@ class Parser {
console.log(`${doclet.longname} - Kind: ${doclet.kind}`);
console.log(`PARENT WARNING: ${doclet.longname} in ${doclet.meta.filename}@${doclet.meta.lineno} has parent '${doclet.memberof}' that is not defined.`);
}
if (!parent.kind) {
console.log(`PARENT KIND WARNING: ${doclet.longname} in ${doclet.meta.filename}@${doclet.meta.lineno} has parent '${doclet.memberof}' that is not defined.`);
}
if (parent.members) {
parent.members.push(obj);
}
@ -191,6 +201,9 @@ class Parser {
}
}
resolveInheritance(docs) {
console.log('------------------------------------------------------------------');
console.log('Resolve Inheritance');
console.log('------------------------------------------------------------------');
for (let doclet of docs) {
let obj = doclet.kind === 'namespace' ? this.namespaces[doclet.longname] : this.objects[doclet.longname];
if (!obj) {
@ -213,6 +226,9 @@ class Parser {
}
}
resolveParents(docs) {
console.log('------------------------------------------------------------------');
console.log('Resolve Parents');
console.log('------------------------------------------------------------------');
for (let doclet of docs) {
let obj = this.objects[doclet.longname];
if (!obj || doclet.kind !== 'class')

File diff suppressed because one or more lines are too long

View file

@ -31,6 +31,10 @@ export class Parser {
this.resolveParents(docs);
console.log('------------------------------------------------------------------');
console.log('Add Integer Alias and Declare Module');
console.log('------------------------------------------------------------------');
// add integer alias
this.topLevel.push(dom.create.alias('integer', dom.type.number));
@ -44,6 +48,10 @@ export class Parser {
emit(): string {
console.log('------------------------------------------------------------------');
console.log('Parser Emit');
console.log('------------------------------------------------------------------');
let ignored = [];
let result = '// DO NOT EDIT THIS FILE! It was generated by running `npm run tsgen`\n/// <reference types="./matter" />\n\n';
@ -197,6 +205,8 @@ export class Parser {
{
let obj = (doclet.kind === 'namespace') ? this.namespaces[doclet.longname] : this.objects[doclet.longname];
// console.log(`${doclet.longname} - Kind: ${doclet.kind}`);
if (!obj)
{
console.log(`${doclet.longname} - Kind: ${doclet.kind}`);
@ -221,6 +231,11 @@ export class Parser {
console.log(`PARENT WARNING: ${doclet.longname} in ${doclet.meta.filename}@${doclet.meta.lineno} has parent '${doclet.memberof}' that is not defined.`);
}
if (!(parent as any).kind)
{
console.log(`PARENT KIND WARNING: ${doclet.longname} in ${doclet.meta.filename}@${doclet.meta.lineno} has parent '${doclet.memberof}' that is not defined.`);
}
if ((<any>parent).members)
{
(<any>parent).members.push(obj);
@ -258,6 +273,10 @@ export class Parser {
private resolveInheritance(docs: any[])
{
console.log('------------------------------------------------------------------');
console.log('Resolve Inheritance');
console.log('------------------------------------------------------------------');
for (let doclet of docs)
{
let obj = doclet.kind === 'namespace' ? this.namespaces[doclet.longname] : this.objects[doclet.longname];
@ -289,28 +308,43 @@ export class Parser {
}
}
private resolveParents(docs: any[]) {
for (let doclet of docs) {
private resolveParents(docs: any[])
{
console.log('------------------------------------------------------------------');
console.log('Resolve Parents');
console.log('------------------------------------------------------------------');
for (let doclet of docs)
{
let obj = this.objects[doclet.longname];
if (!obj || doclet.kind !== 'class') continue;
let o = obj as dom.ClassDeclaration;
// resolve augments
if (doclet.augments && doclet.augments.length) {
for (let augment of doclet.augments) {
if (doclet.augments && doclet.augments.length)
{
for (let augment of doclet.augments)
{
let name: string = this.prepareTypeName(augment);
let wrappingName = name.match(/[^<]+/s)[0];//gets everything up to a first < (to handle augments with type parameters)
let baseType = this.objects[wrappingName] as dom.ClassDeclaration | dom.InterfaceDeclaration;
if (!baseType) {
if (!baseType)
{
console.log(`ERROR: Did not find base type: ${augment} for ${doclet.longname}`);
} else {
if (baseType.kind == 'class') {
}
else
{
if (baseType.kind == 'class')
{
o.baseType = dom.create.class(name);
} else {
}
else
{
o.implements.push(dom.create.interface(name));
}
}