mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
fix(47158): Removes comments when line variable declaration (#47407)
Co-authored-by: Jake Bailey <5341706+jakebailey@users.noreply.github.com>
This commit is contained in:
@@ -3105,7 +3105,7 @@ namespace ts {
|
||||
emit(node.name);
|
||||
emit(node.exclamationToken);
|
||||
emitTypeAnnotation(node.type);
|
||||
emitInitializer(node.initializer, node.type ? node.type.end : node.name.end, node, parenthesizer.parenthesizeExpressionForDisallowedComma);
|
||||
emitInitializer(node.initializer, node.type?.end ?? node.name.emitNode?.typeNode?.end ?? node.name.end, node, parenthesizer.parenthesizeExpressionForDisallowedComma);
|
||||
}
|
||||
|
||||
function emitVariableDeclarationList(node: VariableDeclarationList) {
|
||||
@@ -5331,6 +5331,10 @@ namespace ts {
|
||||
commentsDisabled = false;
|
||||
}
|
||||
emitTrailingCommentsOfNode(node, emitFlags, commentRange.pos, commentRange.end, savedContainerPos, savedContainerEnd, savedDeclarationListContainerEnd);
|
||||
const typeNode = getTypeNode(node);
|
||||
if (typeNode) {
|
||||
emitTrailingCommentsOfNode(node, emitFlags, typeNode.pos, typeNode.end, savedContainerPos, savedContainerEnd, savedDeclarationListContainerEnd);
|
||||
}
|
||||
}
|
||||
|
||||
function emitLeadingCommentsOfNode(node: Node, emitFlags: EmitFlags, pos: number, end: number) {
|
||||
|
||||
@@ -279,4 +279,16 @@ namespace ts {
|
||||
getOrCreateEmitNode(node).flags |= EmitFlags.IgnoreSourceNewlines;
|
||||
return node;
|
||||
}
|
||||
}
|
||||
|
||||
/* @internal */
|
||||
export function setTypeNode<T extends Node>(node: T, type: TypeNode): T {
|
||||
const emitNode = getOrCreateEmitNode(node);
|
||||
emitNode.typeNode = type;
|
||||
return node;
|
||||
}
|
||||
|
||||
/* @internal */
|
||||
export function getTypeNode<T extends Node>(node: T): TypeNode | undefined {
|
||||
return node.emitNode?.typeNode;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2227,12 +2227,16 @@ namespace ts {
|
||||
}
|
||||
|
||||
function visitVariableDeclaration(node: VariableDeclaration) {
|
||||
return factory.updateVariableDeclaration(
|
||||
const updated = factory.updateVariableDeclaration(
|
||||
node,
|
||||
visitNode(node.name, visitor, isBindingName),
|
||||
/*exclamationToken*/ undefined,
|
||||
/*type*/ undefined,
|
||||
visitNode(node.initializer, visitor, isExpression));
|
||||
if (node.type) {
|
||||
setTypeNode(updated.name, node.type);
|
||||
}
|
||||
return updated;
|
||||
}
|
||||
|
||||
function visitParenthesizedExpression(node: ParenthesizedExpression): Expression {
|
||||
|
||||
@@ -6846,6 +6846,7 @@ namespace ts {
|
||||
helpers?: EmitHelper[]; // Emit helpers for the node
|
||||
startsOnNewLine?: boolean; // If the node should begin on a new line
|
||||
snippetElement?: SnippetElement; // Snippet element of the node
|
||||
typeNode?: TypeNode; // VariableDeclaration type
|
||||
}
|
||||
|
||||
/* @internal */
|
||||
|
||||
Reference in New Issue
Block a user