Skip to content

Commit

Permalink
docs: deprecate factory function type declarations
Browse files Browse the repository at this point in the history
  • Loading branch information
zOadT committed Sep 30, 2024
1 parent 4b6d6ec commit 2bae4ab
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions build-utils/declarationTransformer.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ function createNodeWithFactories(factory, node) {
];
}

const FACTORY_DEPRECATION_COMMENT = `*
* @deprecated Use the 'new' keyword.
`;

function createFunctionDeclaration(factory, node, parameters) {
const result = factory.createFunctionDeclaration(
undefined,
Expand All @@ -147,11 +151,26 @@ function createFunctionDeclaration(factory, node, parameters) {
),
undefined
);
return copyComments(result, node);
return copyComments(result, node, FACTORY_DEPRECATION_COMMENT);
}

function copyComments(node, original) {
ts.setSyntheticLeadingComments(node, ts.getSyntheticLeadingComments(original));
function copyComments(node, original, deprecation) {
let leadingComment = ts.getSyntheticLeadingComments(original)
if (deprecation) {
leadingComment = leadingComment
?.map(comment => ({
...comment,
text: comment.text + deprecation,
}))
?? [{
kind: 3,
pos: -1,
end: -1,
hasTrailingNewLine: true,
text: deprecation,
}];
}
ts.setSyntheticLeadingComments(node, leadingComment);
ts.setSyntheticTrailingComments(node, ts.getSyntheticTrailingComments(original));
return node;
}

0 comments on commit 2bae4ab

Please sign in to comment.