mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Emit source positions for open/close braces (#47924)
This commit is contained in:
+14
-1
@@ -927,6 +927,7 @@ export function emitFiles(resolver: EmitResolver, host: EmitHost, targetSourceFi
|
||||
inlineSourceMap: compilerOptions.inlineSourceMap,
|
||||
extendedDiagnostics: compilerOptions.extendedDiagnostics,
|
||||
onlyPrintJsDocStyle: true,
|
||||
omitBraceSourceMapPositions: true,
|
||||
writeBundleFileInfo: !!bundleBuildInfo,
|
||||
recordInternalSection: !!bundleBuildInfo,
|
||||
relativeToBuildInfo,
|
||||
@@ -1391,6 +1392,7 @@ export function createPrinter(printerOptions: PrinterOptions = {}, handlers: Pri
|
||||
} = handlers;
|
||||
|
||||
var extendedDiagnostics = !!printerOptions.extendedDiagnostics;
|
||||
var omitBraceSourcePositions = !!printerOptions.omitBraceSourceMapPositions;
|
||||
var newLine = getNewLineCharacter(printerOptions);
|
||||
var moduleKind = getEmitModuleKind(printerOptions);
|
||||
var bundledHelpers = new Map<string, boolean>();
|
||||
@@ -3578,7 +3580,18 @@ export function createPrinter(printerOptions: PrinterOptions = {}, handlers: Pri
|
||||
decreaseIndent();
|
||||
}
|
||||
}
|
||||
pos = writeTokenText(token, writer, pos);
|
||||
|
||||
// We don't emit source positions for most tokens as it tends to be quite noisy, however
|
||||
// we need to emit source positions for open and close braces so that tools like istanbul
|
||||
// can map branches for code coverage. However, we still omit brace source positions when
|
||||
// the output is a declaration file.
|
||||
if (!omitBraceSourcePositions && (token === SyntaxKind.OpenBraceToken || token === SyntaxKind.CloseBraceToken)) {
|
||||
pos = writeToken(token, pos, writer, contextNode);
|
||||
}
|
||||
else {
|
||||
pos = writeTokenText(token, writer, pos);
|
||||
}
|
||||
|
||||
if (isSimilarNode && contextNode.end !== pos) {
|
||||
const isJsxExprContext = contextNode.kind === SyntaxKind.JsxExpression;
|
||||
emitTrailingCommentsOfPosition(pos, /*prefixSpace*/ !isJsxExprContext, /*forceNoNewline*/ isJsxExprContext);
|
||||
|
||||
@@ -9476,6 +9476,7 @@ export interface PrinterOptions {
|
||||
/** @internal */ sourceMap?: boolean;
|
||||
/** @internal */ inlineSourceMap?: boolean;
|
||||
/** @internal */ inlineSources?: boolean;
|
||||
/** @internal*/ omitBraceSourceMapPositions?: boolean;
|
||||
/** @internal */ extendedDiagnostics?: boolean;
|
||||
/** @internal */ onlyPrintJsDocStyle?: boolean;
|
||||
/** @internal */ neverAsciiEscape?: boolean;
|
||||
|
||||
Reference in New Issue
Block a user