Skip to content

Commit b6f99ab

Browse files
rbucktonsnovader
authored andcommitted
Emit source positions for open/close braces (microsoft#47924)
1 parent d16906e commit b6f99ab

File tree

114 files changed

+5037
-2478
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

114 files changed

+5037
-2478
lines changed

Diff for: src/compiler/emitter.ts

+14-1
Original file line numberDiff line numberDiff line change
@@ -926,6 +926,7 @@ export function emitFiles(resolver: EmitResolver, host: EmitHost, targetSourceFi
926926
inlineSourceMap: compilerOptions.inlineSourceMap,
927927
extendedDiagnostics: compilerOptions.extendedDiagnostics,
928928
onlyPrintJsDocStyle: true,
929+
omitBraceSourceMapPositions: true,
929930
writeBundleFileInfo: !!bundleBuildInfo,
930931
recordInternalSection: !!bundleBuildInfo,
931932
relativeToBuildInfo,
@@ -1390,6 +1391,7 @@ export function createPrinter(printerOptions: PrinterOptions = {}, handlers: Pri
13901391
} = handlers;
13911392

13921393
var extendedDiagnostics = !!printerOptions.extendedDiagnostics;
1394+
var omitBraceSourcePositions = !!printerOptions.omitBraceSourceMapPositions;
13931395
var newLine = getNewLineCharacter(printerOptions);
13941396
var moduleKind = getEmitModuleKind(printerOptions);
13951397
var bundledHelpers = new Map<string, boolean>();
@@ -3577,7 +3579,18 @@ export function createPrinter(printerOptions: PrinterOptions = {}, handlers: Pri
35773579
decreaseIndent();
35783580
}
35793581
}
3580-
pos = writeTokenText(token, writer, pos);
3582+
3583+
// We don't emit source positions for most tokens as it tends to be quite noisy, however
3584+
// we need to emit source positions for open and close braces so that tools like istanbul
3585+
// can map branches for code coverage. However, we still omit brace source positions when
3586+
// the output is a declaration file.
3587+
if (!omitBraceSourcePositions && (token === SyntaxKind.OpenBraceToken || token === SyntaxKind.CloseBraceToken)) {
3588+
pos = writeToken(token, pos, writer, contextNode);
3589+
}
3590+
else {
3591+
pos = writeTokenText(token, writer, pos);
3592+
}
3593+
35813594
if (isSimilarNode && contextNode.end !== pos) {
35823595
const isJsxExprContext = contextNode.kind === SyntaxKind.JsxExpression;
35833596
emitTrailingCommentsOfPosition(pos, /*prefixSpace*/ !isJsxExprContext, /*forceNoNewline*/ isJsxExprContext);

Diff for: src/compiler/types.ts

+1
Original file line numberDiff line numberDiff line change
@@ -9476,6 +9476,7 @@ export interface PrinterOptions {
94769476
/** @internal */ sourceMap?: boolean;
94779477
/** @internal */ inlineSourceMap?: boolean;
94789478
/** @internal */ inlineSources?: boolean;
9479+
/** @internal*/ omitBraceSourceMapPositions?: boolean;
94799480
/** @internal */ extendedDiagnostics?: boolean;
94809481
/** @internal */ onlyPrintJsDocStyle?: boolean;
94819482
/** @internal */ neverAsciiEscape?: boolean;

Diff for: tests/baselines/reference/ES5For-of1.js.map

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: tests/baselines/reference/ES5For-of1.sourcemap.txt

+10-4
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ sourceFile:ES5For-of1.ts
2525
14> ^^
2626
15> ^^^^
2727
16> ^^
28+
17> ^
2829
1 >
2930
2 >for (var v of
3031
3 > ['a', 'b', 'c']
@@ -41,6 +42,7 @@ sourceFile:ES5For-of1.ts
4142
14>
4243
15> ['a', 'b', 'c']
4344
16> )
45+
17> {
4446
1 >Emitted(1, 1) Source(1, 1) + SourceIndex(0)
4547
2 >Emitted(1, 6) Source(1, 15) + SourceIndex(0)
4648
3 >Emitted(1, 16) Source(1, 30) + SourceIndex(0)
@@ -57,6 +59,7 @@ sourceFile:ES5For-of1.ts
5759
14>Emitted(1, 56) Source(1, 15) + SourceIndex(0)
5860
15>Emitted(1, 60) Source(1, 30) + SourceIndex(0)
5961
16>Emitted(1, 62) Source(1, 32) + SourceIndex(0)
62+
17>Emitted(1, 63) Source(1, 33) + SourceIndex(0)
6063
---
6164
>>> var v = _a[_i];
6265
1 >^^^^
@@ -101,10 +104,13 @@ sourceFile:ES5For-of1.ts
101104
8 >Emitted(3, 20) Source(2, 20) + SourceIndex(0)
102105
---
103106
>>>}
104-
1 >^
105-
2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^->
107+
1 >
108+
2 >^
109+
3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^->
106110
1 >
107-
>}
108-
1 >Emitted(4, 2) Source(3, 2) + SourceIndex(0)
111+
>
112+
2 >}
113+
1 >Emitted(4, 1) Source(3, 1) + SourceIndex(0)
114+
2 >Emitted(4, 2) Source(3, 2) + SourceIndex(0)
109115
---
110116
>>>//# sourceMappingURL=ES5For-of1.js.map

Diff for: tests/baselines/reference/ES5For-of13.js.map

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: tests/baselines/reference/ES5For-of13.sourcemap.txt

+10-4
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ sourceFile:ES5For-of13.ts
2525
14> ^^
2626
15> ^^^^
2727
16> ^^
28+
17> ^
2829
1 >
2930
2 >for (let v of
3031
3 > ['a', 'b', 'c']
@@ -41,6 +42,7 @@ sourceFile:ES5For-of13.ts
4142
14>
4243
15> ['a', 'b', 'c']
4344
16> )
45+
17> {
4446
1 >Emitted(1, 1) Source(1, 1) + SourceIndex(0)
4547
2 >Emitted(1, 6) Source(1, 15) + SourceIndex(0)
4648
3 >Emitted(1, 16) Source(1, 30) + SourceIndex(0)
@@ -57,6 +59,7 @@ sourceFile:ES5For-of13.ts
5759
14>Emitted(1, 56) Source(1, 15) + SourceIndex(0)
5860
15>Emitted(1, 60) Source(1, 30) + SourceIndex(0)
5961
16>Emitted(1, 62) Source(1, 32) + SourceIndex(0)
62+
17>Emitted(1, 63) Source(1, 33) + SourceIndex(0)
6063
---
6164
>>> var v = _a[_i];
6265
1 >^^^^
@@ -94,10 +97,13 @@ sourceFile:ES5For-of13.ts
9497
6 >Emitted(3, 15) Source(2, 15) + SourceIndex(0)
9598
---
9699
>>>}
97-
1 >^
98-
2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^->
100+
1 >
101+
2 >^
102+
3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^->
99103
1 >
100-
>}
101-
1 >Emitted(4, 2) Source(3, 2) + SourceIndex(0)
104+
>
105+
2 >}
106+
1 >Emitted(4, 1) Source(3, 1) + SourceIndex(0)
107+
2 >Emitted(4, 2) Source(3, 2) + SourceIndex(0)
102108
---
103109
>>>//# sourceMappingURL=ES5For-of13.js.map

Diff for: tests/baselines/reference/ES5For-of25.js.map

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: tests/baselines/reference/ES5For-of25.sourcemap.txt

+10-4
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ sourceFile:ES5For-of25.ts
5858
8 > ^^
5959
9 > ^^^^
6060
10> ^^
61+
11> ^
6162
1->
6263
>
6364
2 >for (var v of
@@ -69,6 +70,7 @@ sourceFile:ES5For-of25.ts
6970
8 >
7071
9 > a
7172
10> )
73+
11> {
7274
1->Emitted(2, 1) Source(2, 1) + SourceIndex(0)
7375
2 >Emitted(2, 6) Source(2, 15) + SourceIndex(0)
7476
3 >Emitted(2, 16) Source(2, 16) + SourceIndex(0)
@@ -79,6 +81,7 @@ sourceFile:ES5For-of25.ts
7981
8 >Emitted(2, 44) Source(2, 15) + SourceIndex(0)
8082
9 >Emitted(2, 48) Source(2, 16) + SourceIndex(0)
8183
10>Emitted(2, 50) Source(2, 18) + SourceIndex(0)
84+
11>Emitted(2, 51) Source(2, 19) + SourceIndex(0)
8285
---
8386
>>> var v = a_1[_i];
8487
1 >^^^^
@@ -120,10 +123,13 @@ sourceFile:ES5For-of25.ts
120123
3 >Emitted(5, 7) Source(4, 7) + SourceIndex(0)
121124
---
122125
>>>}
123-
1 >^
124-
2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^->
126+
1 >
127+
2 >^
128+
3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^->
125129
1 >
126-
>}
127-
1 >Emitted(6, 2) Source(5, 2) + SourceIndex(0)
130+
>
131+
2 >}
132+
1 >Emitted(6, 1) Source(5, 1) + SourceIndex(0)
133+
2 >Emitted(6, 2) Source(5, 2) + SourceIndex(0)
128134
---
129135
>>>//# sourceMappingURL=ES5For-of25.js.map

Diff for: tests/baselines/reference/ES5For-of26.js.map

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: tests/baselines/reference/ES5For-of26.sourcemap.txt

+11-5
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ sourceFile:ES5For-of26.ts
2323
12> ^^
2424
13> ^^^^
2525
14> ^^
26-
15> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^->
26+
15> ^
27+
16> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^->
2728
1 >
2829
2 >for (var [a = 0, b = 1] of
2930
3 > [2, 3]
@@ -38,6 +39,7 @@ sourceFile:ES5For-of26.ts
3839
12>
3940
13> [2, 3]
4041
14> )
42+
15> {
4143
1 >Emitted(1, 1) Source(1, 1) + SourceIndex(0)
4244
2 >Emitted(1, 6) Source(1, 28) + SourceIndex(0)
4345
3 >Emitted(1, 16) Source(1, 34) + SourceIndex(0)
@@ -52,6 +54,7 @@ sourceFile:ES5For-of26.ts
5254
12>Emitted(1, 47) Source(1, 28) + SourceIndex(0)
5355
13>Emitted(1, 51) Source(1, 34) + SourceIndex(0)
5456
14>Emitted(1, 53) Source(1, 36) + SourceIndex(0)
57+
15>Emitted(1, 54) Source(1, 37) + SourceIndex(0)
5558
---
5659
>>> var _b = _a[_i], _c = _b[0], a = _c === void 0 ? 0 : _c, _d = _b[1], b = _d === void 0 ? 1 : _d;
5760
1->^^^^
@@ -132,10 +135,13 @@ sourceFile:ES5For-of26.ts
132135
3 >Emitted(4, 7) Source(3, 7) + SourceIndex(0)
133136
---
134137
>>>}
135-
1 >^
136-
2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^->
138+
1 >
139+
2 >^
140+
3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^->
137141
1 >
138-
>}
139-
1 >Emitted(5, 2) Source(4, 2) + SourceIndex(0)
142+
>
143+
2 >}
144+
1 >Emitted(5, 1) Source(4, 1) + SourceIndex(0)
145+
2 >Emitted(5, 2) Source(4, 2) + SourceIndex(0)
140146
---
141147
>>>//# sourceMappingURL=ES5For-of26.js.map

0 commit comments

Comments
 (0)