Skip to content

Commit c4deacf

Browse files
committed
fix static
1 parent 1e3198e commit c4deacf

File tree

1 file changed

+20
-19
lines changed

1 file changed

+20
-19
lines changed

utils/generate-types.js

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,18 @@ function getEntries(entry) {
2222
function getAllEntries(arr) {
2323
return arr.flatMap(getEntries);
2424
}
25-
26-
// Organize data into structured format
27-
function organizeData(data) {
28-
const allData = getAllEntries(data);
29-
const organized = {
25+
const organized = {
3026
modules: {},
3127
classes: {},
3228
classitems: [],
3329
consts: {}
3430
};
3531

32+
// Organize data into structured format
33+
function organizeData(data) {
34+
const allData = getAllEntries(data);
35+
36+
3637
// Process modules first
3738
allData.forEach(entry => {
3839
if (entry.tags?.some(tag => tag.title === 'module')) {
@@ -52,8 +53,9 @@ function organizeData(data) {
5253
allData.forEach(entry => {
5354
if (entry.kind === 'class') {
5455
const { module, submodule } = getModuleInfo(entry);
55-
organized.classes[entry.name] = {
56-
name: entry.name,
56+
const className = entry.name;
57+
organized.classes[className] = {
58+
name: className,
5759
description: extractDescription(entry.description),
5860
params: (entry.params || []).map(param => ({
5961
name: param.name,
@@ -70,9 +72,11 @@ function organizeData(data) {
7072
allData.forEach(entry => {
7173
if (entry.kind === 'function' || entry.kind === 'property') {
7274
const { module, submodule, forEntry } = getModuleInfo(entry);
73-
const className = forEntry || 'p5';
74-
75-
if (!organized.classes[className]) return;
75+
// Use memberof if available, fallback to forEntry, then default to 'p5'
76+
const className = entry.memberof || forEntry || 'p5';
77+
78+
// Create the class entry if it doesn't exist
79+
// if (!organized.classes[className]) {console.log(`returning for ${className}`); return};
7680

7781
// Check for static methods - directly check path[0].scope
7882
// Todo: handle static methods
@@ -117,6 +121,7 @@ function organizeData(data) {
117121
class: forEntry || 'p5'
118122
};
119123
}
124+
fs.writeFileSync("./consts.json", JSON.stringify(organized.consts, null, 2), 'utf8');
120125
});
121126

122127
return organized;
@@ -308,10 +313,6 @@ function generateClassDeclaration(classDoc, organizedData) {
308313
output += ' */\n';
309314
}
310315

311-
// Generate class declaration
312-
const isAbstract = classDoc.tags?.some(t => t.title === 'abstract');
313-
output += `${isAbstract ? 'abstract ' : ''}class ${classDoc.name.replace('p5.', '')} {\n`;
314-
315316
// Add constructor if there are parameters
316317
if (classDoc.params?.length > 0) {
317318
output += ' constructor(';
@@ -322,8 +323,8 @@ function generateClassDeclaration(classDoc, organizedData) {
322323
}
323324

324325
// Get all class items for this class
325-
const classItems = organizedData.classitems.filter(item => item.class === classDoc.name);
326-
326+
const classDocName = classDoc.name.startsWith('p5.') ? classDoc.name.substring(3) : classDoc.name;
327+
const classItems = organizedData.classitems.filter(item => item.class === classDocName);
327328

328329
// Separate static and instance members
329330
const staticItems = classItems.filter(item => item.isStatic);
@@ -362,14 +363,14 @@ function generateClassDeclaration(classDoc, organizedData) {
362363
const returnType = overload.returns?.[0]?.type
363364
? generateTypeFromTag(overload.returns[0])
364365
: 'void';
365-
output += ` static function ${item.name}(${params}): ${returnType};\n`;
366+
output += ` static ${item.name}(${params}): ${returnType};\n`;
366367
});
367368
output += '\n';
368369
} else {
369370
const params = (item.params || [])
370371
.map(param => generateParamDeclaration(param))
371372
.join(', ');
372-
output += ` static function ${item.name}(${params}): ${item.returnType};\n\n`;
373+
output += ` static ${item.name}(${params}): ${item.returnType};\n\n`;
373374
}
374375
} else {
375376
output += ` static ${item.name}: ${item.returnType};\n\n`;
@@ -538,7 +539,7 @@ function generateAllDeclarationFiles() {
538539
);
539540

540541
// Generate the declaration file content
541-
const declarationContent = generateDeclarationFile(items, filePath, organizedData);
542+
const declarationContent = generateDeclarationFile(items, filePath, organized);
542543

543544
// Create directory if it doesn't exist
544545
fs.mkdirSync(path.dirname(dtsPath), { recursive: true });

0 commit comments

Comments
 (0)