Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use a mapped type to enforce type-safety on forEachChild. #50409

Merged
merged 1 commit into from Aug 23, 2022

Conversation

DanielRosenwasser
Copy link
Member

Instead of waiting on implementations for these, I'd rather at least add two type aliases to make it easier to pare down. Also, a fix right now is kind of awful until #50382 is implemented and #50375 is fixed.

@DanielRosenwasser DanielRosenwasser merged commit 4605d89 into main Aug 23, 2022
@DanielRosenwasser DanielRosenwasser deleted the safeForEachChild branch August 23, 2022 00:30
@DanielRosenwasser
Copy link
Member Author

DanielRosenwasser commented Aug 23, 2022

In case I or someone else needs it in the future:

[SyntaxKind.JSDocTypeExpression]: function visitEachChildInJSDocTypeExpression(node, visitor, context, _nodesVisitor, nodeVisitor, _tokenVisitor) {
    return context.factory.updateJSDocTypeExpression(
        node,
        nodeVisitor(node.type, visitor, isTypeNode),
    );
},

[SyntaxKind.JSDocNonNullableType]: function visitEachChildInJSDocNonNullableType(node, visitor, context, _nodesVisitor, nodeVisitor, _tokenVisitor) {
    return context.factory.updateJSDocNonNullableType(
        node,
        nodeVisitor(node.type, visitor, isTypeNode),
    );
},

[SyntaxKind.JSDocNullableType]: function visitEachChildInJSDocNullableType(node, visitor, context, _nodesVisitor, nodeVisitor, _tokenVisitor) {
    return context.factory.updateJSDocNullableType(
        node,
        nodeVisitor(node.type, visitor, isTypeNode),
    );
},

[SyntaxKind.JSDocOptionalType]: function visitEachChildInJSDocOptionalType(node, visitor, context, _nodesVisitor, nodeVisitor, _tokenVisitor) {
    return context.factory.updateJSDocOptionalType(
        node,
        nodeVisitor(node.type, visitor, isTypeNode),
    );
},

[SyntaxKind.JSDocVariadicType]: function visitEachChildInJSDocVariadicType(node, visitor, context, _nodesVisitor, nodeVisitor, _tokenVisitor) {
    return context.factory.updateJSDocVariadicType(
        node,
        nodeVisitor(node.type, visitor, isTypeNode),
    );
},

[SyntaxKind.JSDocFunctionType]: function visitEachChildInJSDocFunctionType(node, visitor, context, nodesVisitor, nodeVisitor, _tokenVisitor) {
    return context.factory.updateJSDocFunctionType(
        node,
        nodesVisitor(node.parameters, visitor, isParameterDeclaration),
        nodeVisitor(node.type, visitor, isTypeNode),
    );
},

[SyntaxKind.JSDoc]: function visitEachChildInJSDoc(node, visitor, context, nodesVisitor, _nodeVisitor, _tokenVisitor) {
    return context.factory.updateJSDocComment(
        node,
        // TODO: what do we do with this
        typeof node.comment === "string" ? node.comment : nodesVisitor(node.comment, visitor),
        nodesVisitor(node.tags, visitor, isJSDocTag),
    );
},

[SyntaxKind.JSDocSeeTag]: function visitEachChildInJSDocSeeTag(node, visitor, context, _nodesVisitor, nodeVisitor, _tokenVisitor) {
    return context.factory.updateJSDocSeeTag(
        node,
        nodeVisitor(node.tagName, visitor, isIdentifier),
        nodeVisitor(node.name, visitor, isJSDocNameReference),
    );
},

[SyntaxKind.JSDocNameReference]: function visitEachChildInJSDocNameReference(node, visitor, context, _nodesVisitor, nodeVisitor, _tokenVisitor) {
    return context.factory.updateJSDocNameReference(
        node,
        nodeVisitor(node.name, visitor, or(isJSDocMemberName, isEntityName)),
    );
},

[SyntaxKind.JSDocMemberName]: function visitEachChildInJSDocMemberName(node, visitor, context, _nodesVisitor, nodeVisitor, _tokenVisitor) {
    return context.factory.updateJSDocMemberName(
        node,
        nodeVisitor(node.left, visitor, or(isJSDocMemberName, isEntityName)),
        nodeVisitor(node.right, visitor, isIdentifier),
    );
},

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Author: Team For Uncommitted Bug PR for untriaged, rejected, closed or missing bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants