Skip to content

Commit edc34e8

Browse files
committed
Emit source positions for open/close braces
1 parent 8ddead5 commit edc34e8

File tree

110 files changed

+4737
-2244
lines changed

Some content is hidden

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

110 files changed

+4737
-2244
lines changed

Diff for: src/compiler/emitter.ts

+14-1
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,7 @@ namespace ts {
455455
inlineSourceMap: compilerOptions.inlineSourceMap,
456456
extendedDiagnostics: compilerOptions.extendedDiagnostics,
457457
onlyPrintJsDocStyle: true,
458+
omitBraceSourceMapPositions: true,
458459
writeBundleFileInfo: !!bundleBuildInfo,
459460
recordInternalSection: !!bundleBuildInfo,
460461
relativeToBuildInfo
@@ -864,6 +865,7 @@ namespace ts {
864865
} = handlers;
865866

866867
const extendedDiagnostics = !!printerOptions.extendedDiagnostics;
868+
const omitBraceSourcePositions = !!printerOptions.omitBraceSourceMapPositions;
867869
const newLine = getNewLineCharacter(printerOptions);
868870
const moduleKind = getEmitModuleKind(printerOptions);
869871
const bundledHelpers = new Map<string, boolean>();
@@ -2987,7 +2989,18 @@ namespace ts {
29872989
decreaseIndent();
29882990
}
29892991
}
2990-
pos = writeTokenText(token, writer, pos);
2992+
2993+
// We don't emit source positions for most tokens as it tends to be quite noisy, however
2994+
// we need to emit source positions for open and close braces so that tools like istanbul
2995+
// can map branches for code coverage. However, we still omit brace source positions when
2996+
// the output is a declaration file.
2997+
if (!omitBraceSourcePositions && (token === SyntaxKind.OpenBraceToken || token === SyntaxKind.CloseBraceToken)) {
2998+
pos = writeToken(token, pos, writer, contextNode);
2999+
}
3000+
else {
3001+
pos = writeTokenText(token, writer, pos);
3002+
}
3003+
29913004
if (isSimilarNode && contextNode.end !== pos) {
29923005
const isJsxExprContext = contextNode.kind === SyntaxKind.JsxExpression;
29933006
emitTrailingCommentsOfPosition(pos, /*prefixSpace*/ !isJsxExprContext, /*forceNoNewline*/ isJsxExprContext);

Diff for: src/compiler/types.ts

+1
Original file line numberDiff line numberDiff line change
@@ -8223,6 +8223,7 @@ namespace ts {
82238223
/*@internal*/ sourceMap?: boolean;
82248224
/*@internal*/ inlineSourceMap?: boolean;
82258225
/*@internal*/ inlineSources?: boolean;
8226+
/*@internal*/ omitBraceSourceMapPositions?: boolean;
82268227
/*@internal*/ extendedDiagnostics?: boolean;
82278228
/*@internal*/ onlyPrintJsDocStyle?: boolean;
82288229
/*@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)