Skip to content

Much better comment preservation #22141

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
f8bcc62
Retain comments on (and produce sourcemaps on) the equals token in in…
weswigham Feb 22, 2018
e9bca7e
Improved comments/sourcemaps for await, yield, while, and for
weswigham Feb 22, 2018
f7c3903
Retain comments on block curly-braces
weswigham Feb 22, 2018
4cd74f2
Emit comments for if statements
weswigham Feb 22, 2018
2a38005
Improved switch case comment emit
weswigham Feb 22, 2018
c4c73b5
Improve comment and sourcemap emit for try/catch, throw, and continue…
weswigham Feb 22, 2018
bf482e9
Improve sourcemap emit and comments for with statements
weswigham Feb 22, 2018
20d6f69
More accurate sourcemaps+comments emit for new, typeof, void, and delete
weswigham Feb 22, 2018
462c0b1
Improve comment emit for element access expressions
weswigham Feb 22, 2018
918f184
Preserve more comments on imports and exports
weswigham Feb 22, 2018
ec7be47
Make function a bit more defensive like other usages of emitTrailingC…
weswigham Feb 23, 2018
0d018f7
Support preserving comments within empty lists
weswigham Feb 23, 2018
b1b1718
Handle leading comments of tokens, conditionally indent leading comments
weswigham Feb 23, 2018
5c102a4
Stop heuristically sourcemapping tokens
weswigham Feb 23, 2018
fc0a6cc
Fix unneeded +1
weswigham Feb 23, 2018
89fef55
Tighten up element access comments
weswigham Feb 23, 2018
864f029
Handle comments on parenthesized expression tokens
weswigham Feb 23, 2018
62ccc9d
Merge branch 'master' into slightly-better-comment-preservation
weswigham Feb 26, 2018
c4c2f9b
Merge branch 'master' into slightly-better-comment-preservation
weswigham Mar 3, 2018
b6ebcfd
Fix nit
weswigham Mar 3, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
234 changes: 119 additions & 115 deletions src/compiler/emitter.ts

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tests/baselines/reference/ES5For-of1.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

90 changes: 42 additions & 48 deletions tests/baselines/reference/ES5For-of1.sourcemap.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,56 +10,50 @@ sourceFile:ES5For-of1.ts
-------------------------------------------------------------------
>>>for (var _i = 0, _a = ['a', 'b', 'c']; _i < _a.length; _i++) {
1 >
2 >^^^
3 > ^
4 > ^
5 > ^^^^^^^^^^
6 > ^^
7 > ^^^^^^
8 > ^^^
9 > ^^
10> ^^^
11> ^^
12> ^^^
13> ^
14> ^^
15> ^^^^^^^^^^^^^^
16> ^^
17> ^^^^
2 >^^^^^
3 > ^^^^^^^^^^
4 > ^^
5 > ^^^^^^
6 > ^^^
7 > ^^
8 > ^^^
9 > ^^
10> ^^^
11> ^
12> ^^
13> ^^^^^^^^^^^^^^
14> ^^
15> ^^^^
1 >
2 >for
3 >
4 > (var v of
5 > ['a', 'b', 'c']
6 >
7 > [
8 > 'a'
9 > ,
10> 'b'
11> ,
12> 'c'
13> ]
14>
15> ['a', 'b', 'c']
16>
17> ['a', 'b', 'c']
2 >for (var v of
3 > ['a', 'b', 'c']
4 >
5 > [
6 > 'a'
7 > ,
8 > 'b'
9 > ,
10> 'c'
11> ]
12>
13> ['a', 'b', 'c']
14>
15> ['a', 'b', 'c']
1 >Emitted(1, 1) Source(1, 1) + SourceIndex(0)
2 >Emitted(1, 4) Source(1, 4) + SourceIndex(0)
3 >Emitted(1, 5) Source(1, 5) + SourceIndex(0)
4 >Emitted(1, 6) Source(1, 15) + SourceIndex(0)
5 >Emitted(1, 16) Source(1, 30) + SourceIndex(0)
6 >Emitted(1, 18) Source(1, 15) + SourceIndex(0)
7 >Emitted(1, 24) Source(1, 16) + SourceIndex(0)
8 >Emitted(1, 27) Source(1, 19) + SourceIndex(0)
9 >Emitted(1, 29) Source(1, 21) + SourceIndex(0)
10>Emitted(1, 32) Source(1, 24) + SourceIndex(0)
11>Emitted(1, 34) Source(1, 26) + SourceIndex(0)
12>Emitted(1, 37) Source(1, 29) + SourceIndex(0)
13>Emitted(1, 38) Source(1, 30) + SourceIndex(0)
14>Emitted(1, 40) Source(1, 15) + SourceIndex(0)
15>Emitted(1, 54) Source(1, 30) + SourceIndex(0)
16>Emitted(1, 56) Source(1, 15) + SourceIndex(0)
17>Emitted(1, 60) Source(1, 30) + SourceIndex(0)
2 >Emitted(1, 6) Source(1, 15) + SourceIndex(0)
3 >Emitted(1, 16) Source(1, 30) + SourceIndex(0)
4 >Emitted(1, 18) Source(1, 15) + SourceIndex(0)
5 >Emitted(1, 24) Source(1, 16) + SourceIndex(0)
6 >Emitted(1, 27) Source(1, 19) + SourceIndex(0)
7 >Emitted(1, 29) Source(1, 21) + SourceIndex(0)
8 >Emitted(1, 32) Source(1, 24) + SourceIndex(0)
9 >Emitted(1, 34) Source(1, 26) + SourceIndex(0)
10>Emitted(1, 37) Source(1, 29) + SourceIndex(0)
11>Emitted(1, 38) Source(1, 30) + SourceIndex(0)
12>Emitted(1, 40) Source(1, 15) + SourceIndex(0)
13>Emitted(1, 54) Source(1, 30) + SourceIndex(0)
14>Emitted(1, 56) Source(1, 15) + SourceIndex(0)
15>Emitted(1, 60) Source(1, 30) + SourceIndex(0)
---
>>> var v = _a[_i];
1 >^^^^
Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/ES5For-of13.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

90 changes: 42 additions & 48 deletions tests/baselines/reference/ES5For-of13.sourcemap.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,56 +10,50 @@ sourceFile:ES5For-of13.ts
-------------------------------------------------------------------
>>>for (var _i = 0, _a = ['a', 'b', 'c']; _i < _a.length; _i++) {
1 >
2 >^^^
3 > ^
4 > ^
5 > ^^^^^^^^^^
6 > ^^
7 > ^^^^^^
8 > ^^^
9 > ^^
10> ^^^
11> ^^
12> ^^^
13> ^
14> ^^
15> ^^^^^^^^^^^^^^
16> ^^
17> ^^^^
2 >^^^^^
3 > ^^^^^^^^^^
4 > ^^
5 > ^^^^^^
6 > ^^^
7 > ^^
8 > ^^^
9 > ^^
10> ^^^
11> ^
12> ^^
13> ^^^^^^^^^^^^^^
14> ^^
15> ^^^^
1 >
2 >for
3 >
4 > (let v of
5 > ['a', 'b', 'c']
6 >
7 > [
8 > 'a'
9 > ,
10> 'b'
11> ,
12> 'c'
13> ]
14>
15> ['a', 'b', 'c']
16>
17> ['a', 'b', 'c']
2 >for (let v of
3 > ['a', 'b', 'c']
4 >
5 > [
6 > 'a'
7 > ,
8 > 'b'
9 > ,
10> 'c'
11> ]
12>
13> ['a', 'b', 'c']
14>
15> ['a', 'b', 'c']
1 >Emitted(1, 1) Source(1, 1) + SourceIndex(0)
2 >Emitted(1, 4) Source(1, 4) + SourceIndex(0)
3 >Emitted(1, 5) Source(1, 5) + SourceIndex(0)
4 >Emitted(1, 6) Source(1, 15) + SourceIndex(0)
5 >Emitted(1, 16) Source(1, 30) + SourceIndex(0)
6 >Emitted(1, 18) Source(1, 15) + SourceIndex(0)
7 >Emitted(1, 24) Source(1, 16) + SourceIndex(0)
8 >Emitted(1, 27) Source(1, 19) + SourceIndex(0)
9 >Emitted(1, 29) Source(1, 21) + SourceIndex(0)
10>Emitted(1, 32) Source(1, 24) + SourceIndex(0)
11>Emitted(1, 34) Source(1, 26) + SourceIndex(0)
12>Emitted(1, 37) Source(1, 29) + SourceIndex(0)
13>Emitted(1, 38) Source(1, 30) + SourceIndex(0)
14>Emitted(1, 40) Source(1, 15) + SourceIndex(0)
15>Emitted(1, 54) Source(1, 30) + SourceIndex(0)
16>Emitted(1, 56) Source(1, 15) + SourceIndex(0)
17>Emitted(1, 60) Source(1, 30) + SourceIndex(0)
2 >Emitted(1, 6) Source(1, 15) + SourceIndex(0)
3 >Emitted(1, 16) Source(1, 30) + SourceIndex(0)
4 >Emitted(1, 18) Source(1, 15) + SourceIndex(0)
5 >Emitted(1, 24) Source(1, 16) + SourceIndex(0)
6 >Emitted(1, 27) Source(1, 19) + SourceIndex(0)
7 >Emitted(1, 29) Source(1, 21) + SourceIndex(0)
8 >Emitted(1, 32) Source(1, 24) + SourceIndex(0)
9 >Emitted(1, 34) Source(1, 26) + SourceIndex(0)
10>Emitted(1, 37) Source(1, 29) + SourceIndex(0)
11>Emitted(1, 38) Source(1, 30) + SourceIndex(0)
12>Emitted(1, 40) Source(1, 15) + SourceIndex(0)
13>Emitted(1, 54) Source(1, 30) + SourceIndex(0)
14>Emitted(1, 56) Source(1, 15) + SourceIndex(0)
15>Emitted(1, 60) Source(1, 30) + SourceIndex(0)
---
>>> var v = _a[_i];
1 >^^^^
Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/ES5For-of25.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

54 changes: 24 additions & 30 deletions tests/baselines/reference/ES5For-of25.sourcemap.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,39 +49,33 @@ sourceFile:ES5For-of25.ts
---
>>>for (var _i = 0, a_1 = a; _i < a_1.length; _i++) {
1->
2 >^^^
3 > ^
4 > ^
5 > ^^^^^^^^^^
6 > ^^
7 > ^^^^^^^
8 > ^^
9 > ^^^^^^^^^^^^^^^
10> ^^
11> ^^^^
2 >^^^^^
3 > ^^^^^^^^^^
4 > ^^
5 > ^^^^^^^
6 > ^^
7 > ^^^^^^^^^^^^^^^
8 > ^^
9 > ^^^^
1->
>
2 >for
3 >
4 > (var v of
5 > a
6 >
7 > a
8 >
9 > a
10>
11> a
2 >for (var v of
3 > a
4 >
5 > a
6 >
7 > a
8 >
9 > a
1->Emitted(2, 1) Source(2, 1) + SourceIndex(0)
2 >Emitted(2, 4) Source(2, 4) + SourceIndex(0)
3 >Emitted(2, 5) Source(2, 5) + SourceIndex(0)
4 >Emitted(2, 6) Source(2, 15) + SourceIndex(0)
5 >Emitted(2, 16) Source(2, 16) + SourceIndex(0)
6 >Emitted(2, 18) Source(2, 15) + SourceIndex(0)
7 >Emitted(2, 25) Source(2, 16) + SourceIndex(0)
8 >Emitted(2, 27) Source(2, 15) + SourceIndex(0)
9 >Emitted(2, 42) Source(2, 16) + SourceIndex(0)
10>Emitted(2, 44) Source(2, 15) + SourceIndex(0)
11>Emitted(2, 48) Source(2, 16) + SourceIndex(0)
2 >Emitted(2, 6) Source(2, 15) + SourceIndex(0)
3 >Emitted(2, 16) Source(2, 16) + SourceIndex(0)
4 >Emitted(2, 18) Source(2, 15) + SourceIndex(0)
5 >Emitted(2, 25) Source(2, 16) + SourceIndex(0)
6 >Emitted(2, 27) Source(2, 15) + SourceIndex(0)
7 >Emitted(2, 42) Source(2, 16) + SourceIndex(0)
8 >Emitted(2, 44) Source(2, 15) + SourceIndex(0)
9 >Emitted(2, 48) Source(2, 16) + SourceIndex(0)
---
>>> var v = a_1[_i];
1 >^^^^
Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/ES5For-of26.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

80 changes: 37 additions & 43 deletions tests/baselines/reference/ES5For-of26.sourcemap.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,51 +10,45 @@ sourceFile:ES5For-of26.ts
-------------------------------------------------------------------
>>>for (var _i = 0, _a = [2, 3]; _i < _a.length; _i++) {
1 >
2 >^^^
3 > ^
4 > ^
5 > ^^^^^^^^^^
6 > ^^
7 > ^^^^^^
8 > ^
9 > ^^
10> ^
11> ^
12> ^^
13> ^^^^^^^^^^^^^^
14> ^^
15> ^^^^
16> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^->
2 >^^^^^
3 > ^^^^^^^^^^
4 > ^^
5 > ^^^^^^
6 > ^
7 > ^^
8 > ^
9 > ^
10> ^^
11> ^^^^^^^^^^^^^^
12> ^^
13> ^^^^
14> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^->
1 >
2 >for
3 >
4 > (var [a = 0, b = 1] of
5 > [2, 3]
6 >
7 > [
8 > 2
9 > ,
10> 3
11> ]
12>
13> [2, 3]
14>
15> [2, 3]
2 >for (var [a = 0, b = 1] of
3 > [2, 3]
4 >
5 > [
6 > 2
7 > ,
8 > 3
9 > ]
10>
11> [2, 3]
12>
13> [2, 3]
1 >Emitted(1, 1) Source(1, 1) + SourceIndex(0)
2 >Emitted(1, 4) Source(1, 4) + SourceIndex(0)
3 >Emitted(1, 5) Source(1, 5) + SourceIndex(0)
4 >Emitted(1, 6) Source(1, 28) + SourceIndex(0)
5 >Emitted(1, 16) Source(1, 34) + SourceIndex(0)
6 >Emitted(1, 18) Source(1, 28) + SourceIndex(0)
7 >Emitted(1, 24) Source(1, 29) + SourceIndex(0)
8 >Emitted(1, 25) Source(1, 30) + SourceIndex(0)
9 >Emitted(1, 27) Source(1, 32) + SourceIndex(0)
10>Emitted(1, 28) Source(1, 33) + SourceIndex(0)
11>Emitted(1, 29) Source(1, 34) + SourceIndex(0)
12>Emitted(1, 31) Source(1, 28) + SourceIndex(0)
13>Emitted(1, 45) Source(1, 34) + SourceIndex(0)
14>Emitted(1, 47) Source(1, 28) + SourceIndex(0)
15>Emitted(1, 51) Source(1, 34) + SourceIndex(0)
2 >Emitted(1, 6) Source(1, 28) + SourceIndex(0)
3 >Emitted(1, 16) Source(1, 34) + SourceIndex(0)
4 >Emitted(1, 18) Source(1, 28) + SourceIndex(0)
5 >Emitted(1, 24) Source(1, 29) + SourceIndex(0)
6 >Emitted(1, 25) Source(1, 30) + SourceIndex(0)
7 >Emitted(1, 27) Source(1, 32) + SourceIndex(0)
8 >Emitted(1, 28) Source(1, 33) + SourceIndex(0)
9 >Emitted(1, 29) Source(1, 34) + SourceIndex(0)
10>Emitted(1, 31) Source(1, 28) + SourceIndex(0)
11>Emitted(1, 45) Source(1, 34) + SourceIndex(0)
12>Emitted(1, 47) Source(1, 28) + SourceIndex(0)
13>Emitted(1, 51) Source(1, 34) + SourceIndex(0)
---
>>> var _b = _a[_i], _c = _b[0], a = _c === void 0 ? 0 : _c, _d = _b[1], b = _d === void 0 ? 1 : _d;
1->^^^^
Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/ES5For-of3.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading