chore: add code generation for @types/deno (#25545)

This commit is contained in:
David Sherret 2024-09-23 15:18:52 -04:00 committed by GitHub
parent e1c8d2755e
commit 33f169beb9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
19 changed files with 485 additions and 356 deletions

View file

@ -45,33 +45,39 @@ for (const file of project.getSourceFiles()) {
}
const parent = node.getFirstAncestorByKind(ts.SyntaxKind.ModuleDeclaration);
const isInterfaceOrType =
node.getKind() === ts.SyntaxKind.InterfaceDeclaration ||
node.getKind() === ts.SyntaxKind.TypeAliasDeclaration;
if (parent) {
if (!node.isExported()) {
errors.push(getErrorPrefix(node) + "export keyword");
errors.push(getMissingErrorPrefix(node) + "export keyword");
continue;
}
} else if (!node.hasDeclareKeyword()) {
errors.push(getErrorPrefix(node) + "declare keyword");
} else if (!isInterfaceOrType && !node.hasDeclareKeyword()) {
errors.push(getMissingErrorPrefix(node) + "declare keyword");
continue;
} else if (isInterfaceOrType && node.hasDeclareKeyword()) {
errors.push(getErrorPrefix(node) + "has incorrect declare keyword");
continue;
}
const jsDoc = node.getFirstChildIfKind(ts.SyntaxKind.JSDoc);
if (!jsDoc) {
errors.push(getErrorPrefix(node) + "JSDoc comment");
errors.push(getMissingErrorPrefix(node) + "JSDoc comment");
continue;
}
const tags = jsDoc.getTags();
if (!tags.find((tag) => tag.getTagName() === "category")) {
errors.push(getErrorPrefix(node) + "JSDoc @category tag");
errors.push(getMissingErrorPrefix(node) + "JSDoc @category tag");
continue;
}
if (unstableFiles.includes(file)) {
if (!tags.find((tag) => tag.getTagName() === "experimental")) {
errors.push(getErrorPrefix(node) + "JSDoc @experimental tag");
errors.push(getMissingErrorPrefix(node) + "JSDoc @experimental tag");
}
}
}
@ -81,6 +87,10 @@ if (errors.length > 0) {
throw new AggregateError(errors);
}
function getErrorPrefix(node) {
return `Symbol at file://${node.getSourceFile().getFilePath()}:${node.getStartLineNumber()} is missing a `;
function getMissingErrorPrefix(node) {
return getErrorPrefix(node) + `is missing a `;
}
function getErrorPrefix(node) {
return `Symbol at file://${node.getSourceFile().getFilePath()}:${node.getStartLineNumber()} `;
}