mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-06-16 07:13:43 -05:00
Fix leading line separator calculation and JSX bug
This commit is contained in:
@@ -2365,16 +2365,10 @@ namespace ts {
|
||||
|
||||
function emitParenthesizedExpression(node: ParenthesizedExpression) {
|
||||
const openParenPos = emitTokenWithComment(SyntaxKind.OpenParenToken, node.pos, writePunctuation, node);
|
||||
const leadingNewlines = preserveSourceNewlines && getLeadingLineTerminatorCount(node, [node.expression], ListFormat.None);
|
||||
if (leadingNewlines) {
|
||||
writeLinesAndIndent(leadingNewlines, /*writeLinesIfNotIndenting*/ false);
|
||||
}
|
||||
const indented = writeLineSeparatorsAndIndentBefore(node.expression, node);
|
||||
emitExpression(node.expression);
|
||||
const trailingNewlines = preserveSourceNewlines && getClosingLineTerminatorCount(node, [node.expression], ListFormat.None);
|
||||
if (trailingNewlines) {
|
||||
writeLine(trailingNewlines);
|
||||
}
|
||||
decreaseIndentIf(leadingNewlines);
|
||||
writeLineSeparatorsAfter(node.expression, node);
|
||||
decreaseIndentIf(indented);
|
||||
emitTokenWithComment(SyntaxKind.CloseParenToken, node.expression ? node.expression.end : openParenPos, writePunctuation, node);
|
||||
}
|
||||
|
||||
@@ -3292,12 +3286,15 @@ namespace ts {
|
||||
writePunctuation("<");
|
||||
|
||||
if (isJsxOpeningElement(node)) {
|
||||
const indented = writeLineSeparatorsAndIndentBefore(node.tagName, node);
|
||||
emitJsxTagName(node.tagName);
|
||||
emitTypeArguments(node, node.typeArguments);
|
||||
if (node.attributes.properties && node.attributes.properties.length > 0) {
|
||||
writeSpace();
|
||||
}
|
||||
emit(node.attributes);
|
||||
writeLineSeparatorsAfter(node.attributes, node);
|
||||
decreaseIndentIf(indented);
|
||||
}
|
||||
|
||||
writePunctuation(">");
|
||||
@@ -4399,6 +4396,21 @@ namespace ts {
|
||||
return lines;
|
||||
}
|
||||
|
||||
function writeLineSeparatorsAndIndentBefore(node: Node, parent: Node): boolean {
|
||||
const leadingNewlines = preserveSourceNewlines && getLeadingLineTerminatorCount(parent, [node], ListFormat.None);
|
||||
if (leadingNewlines) {
|
||||
writeLinesAndIndent(leadingNewlines, /*writeLinesIfNotIndenting*/ false);
|
||||
}
|
||||
return !!leadingNewlines;
|
||||
}
|
||||
|
||||
function writeLineSeparatorsAfter(node: Node, parent: Node) {
|
||||
const trailingNewlines = preserveSourceNewlines && getClosingLineTerminatorCount(parent, [node], ListFormat.None);
|
||||
if (trailingNewlines) {
|
||||
writeLine(trailingNewlines);
|
||||
}
|
||||
}
|
||||
|
||||
function synthesizedNodeStartsOnNewLine(node: Node, format: ListFormat) {
|
||||
if (nodeIsSynthesized(node)) {
|
||||
const startsOnNewLine = getStartsOnNewLine(node);
|
||||
|
||||
@@ -4779,7 +4779,7 @@ namespace ts {
|
||||
export function getLinesBetweenPositionAndPrecedingNonWhitespaceCharacter(pos: number, stopPos: number, sourceFile: SourceFile, includeComments?: boolean) {
|
||||
const startPos = skipTrivia(sourceFile.text, pos, /*stopAfterLineBreak*/ false, includeComments);
|
||||
const prevPos = getPreviousNonWhitespacePosition(startPos, stopPos, sourceFile);
|
||||
return getLinesBetweenPositions(sourceFile, prevPos || 0, startPos);
|
||||
return getLinesBetweenPositions(sourceFile, prevPos ?? stopPos, startPos);
|
||||
}
|
||||
|
||||
export function getLinesBetweenPositionAndNextNonWhitespaceCharacter(pos: number, stopPos: number, sourceFile: SourceFile, includeComments?: boolean) {
|
||||
|
||||
Reference in New Issue
Block a user