Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit fecd20a

Browse filesBrowse files
committed
Fix sourcemaps for 'for...of' and no source maps for synthesized nodes
1 parent 946dc0e commit fecd20a
Copy full SHA for fecd20a

28 files changed

+865-141Lines changed: 865 additions & 141 deletions
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/compiler/emitter.ts‎

Copy file name to clipboardExpand all lines: src/compiler/emitter.ts
+30-15Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2067,6 +2067,9 @@ module ts {
20672067

20682068
function emitNodeWithMap(node: Node) {
20692069
if (node) {
2070+
if (nodeIsSynthesized(node)) {
2071+
return emitNode(node);
2072+
}
20702073
if (node.kind != SyntaxKind.SourceFile) {
20712074
recordEmitNodeStartSpan(node);
20722075
emitNode(node);
@@ -3517,9 +3520,6 @@ module ts {
35173520
var endPos = emitToken(SyntaxKind.ForKeyword, node.pos);
35183521
write(" ");
35193522
endPos = emitToken(SyntaxKind.OpenParenToken, endPos);
3520-
// This is the var keyword for the counter and rhsReference. The var keyword for
3521-
// the LHS will be emitted inside the body.
3522-
write("var ");
35233523

35243524
// Do not emit the LHS var declaration yet, because it might contain destructuring.
35253525

@@ -3533,29 +3533,42 @@ module ts {
35333533
var rhsIsIdentifier = node.expression.kind === SyntaxKind.Identifier;
35343534
var counter = createTempVariable(node, /*forLoopVariable*/ true);
35353535
var rhsReference = rhsIsIdentifier ? <Identifier>node.expression : createTempVariable(node, /*forLoopVariable*/ false);
3536+
3537+
// This is the var keyword for the counter and rhsReference. The var keyword for
3538+
// the LHS will be emitted inside the body.
3539+
emitStart(node.expression);
3540+
write("var ");
35363541

35373542
// _i = 0
3538-
emit(counter);
3543+
emitNode(counter);
35393544
write(" = 0");
3545+
emitEnd(node.expression);
35403546

35413547
if (!rhsIsIdentifier) {
35423548
// , _a = expr
35433549
write(", ");
3544-
emit(rhsReference);
3550+
emitStart(node.expression);
3551+
emitNode(rhsReference);
35453552
write(" = ");
3546-
emit(node.expression);
3553+
emitNode(node.expression);
3554+
emitEnd(node.expression);
35473555
}
35483556
write("; ");
35493557

35503558
// _i < _a.length;
3551-
emit(counter);
3559+
emitStart(node.initializer);
3560+
emitNode(counter);
35523561
write(" < ");
3553-
emit(rhsReference);
3554-
write(".length; ");
3562+
emitNode(rhsReference);
3563+
write(".length");
3564+
emitEnd(node.initializer);
3565+
write("; ");
35553566

35563567
// _i++)
3557-
emit(counter);
3568+
emitStart(node.initializer);
3569+
emitNode(counter);
35583570
write("++");
3571+
emitEnd(node.initializer);
35593572
emitToken(SyntaxKind.CloseParenToken, node.expression.end);
35603573

35613574
// Body
@@ -3566,6 +3579,7 @@ module ts {
35663579
// Initialize LHS
35673580
// var v = _a[_i];
35683581
var rhsIterationValue = createElementAccessExpression(rhsReference, counter);
3582+
emitStart(node.initializer);
35693583
if (node.initializer.kind === SyntaxKind.VariableDeclarationList) {
35703584
write("var ");
35713585
var variableDeclarationList = <VariableDeclarationList>node.initializer;
@@ -3579,18 +3593,18 @@ module ts {
35793593
else {
35803594
// The following call does not include the initializer, so we have
35813595
// to emit it separately.
3582-
emit(declaration);
3596+
emitNode(declaration);
35833597
write(" = ");
3584-
emit(rhsIterationValue);
3598+
emitNode(rhsIterationValue);
35853599
}
35863600
}
35873601
else {
35883602
// It's an empty declaration list. This can only happen in an error case, if the user wrote
35893603
// for (var of []) {}
35903604
var emptyDeclarationListTemp = createTempVariable(node, /*forLoopVariable*/ false);
3591-
emit(emptyDeclarationListTemp);
3605+
emitNode(emptyDeclarationListTemp);
35923606
write(" = ");
3593-
emit(rhsIterationValue);
3607+
emitNode(rhsIterationValue);
35943608
}
35953609
}
35963610
else {
@@ -3604,9 +3618,10 @@ module ts {
36043618
emitDestructuring(assignmentExpressionStatement);
36053619
}
36063620
else {
3607-
emit(assignmentExpression);
3621+
emitNode(assignmentExpression);
36083622
}
36093623
}
3624+
emitEnd(node.initializer);
36103625
write(";");
36113626

36123627
if (node.statement.kind === SyntaxKind.Block) {
Collapse file

‎tests/baselines/reference/ES5For-of1.js‎

Copy file name to clipboardExpand all lines: tests/baselines/reference/ES5For-of1.js
+6-2Lines changed: 6 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Collapse file

‎tests/baselines/reference/ES5For-of1.js.map‎

Copy file name to clipboardExpand all lines: tests/baselines/reference/ES5For-of1.js.map
+2Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Collapse file
+116Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
===================================================================
2+
JsFile: ES5For-of1.js
3+
mapUrl: ES5For-of1.js.map
4+
sourceRoot:
5+
sources: ES5For-of1.ts
6+
===================================================================
7+
-------------------------------------------------------------------
8+
emittedFile:tests/cases/conformance/statements/for-ofStatements/ES5For-of1.js
9+
sourceFile:ES5For-of1.ts
10+
-------------------------------------------------------------------
11+
>>>for (var _i = 0, _a = ['a', 'b', 'c']; _i < _a.length; _i++) {
12+
1 >
13+
2 >^^^
14+
3 > ^
15+
4 > ^
16+
5 > ^^^^^^^^^^
17+
6 > ^^
18+
7 > ^^^^^^
19+
8 > ^^^
20+
9 > ^^
21+
10> ^^^
22+
11> ^^
23+
12> ^^^
24+
13> ^
25+
14> ^^
26+
15> ^^^^^^^^^^^^^^
27+
16> ^^
28+
17> ^^^^
29+
18> ^
30+
1 >
31+
2 >for
32+
3 >
33+
4 > (var v of
34+
5 > ['a', 'b', 'c']
35+
6 >
36+
7 > [
37+
8 > 'a'
38+
9 > ,
39+
10> 'b'
40+
11> ,
41+
12> 'c'
42+
13> ]
43+
14>
44+
15> var v
45+
16>
46+
17> var v of ['a', 'b', 'c']
47+
18> )
48+
1 >Emitted(1, 1) Source(1, 1) + SourceIndex(0)
49+
2 >Emitted(1, 4) Source(1, 4) + SourceIndex(0)
50+
3 >Emitted(1, 5) Source(1, 5) + SourceIndex(0)
51+
4 >Emitted(1, 6) Source(1, 15) + SourceIndex(0)
52+
5 >Emitted(1, 16) Source(1, 30) + SourceIndex(0)
53+
6 >Emitted(1, 18) Source(1, 15) + SourceIndex(0)
54+
7 >Emitted(1, 24) Source(1, 16) + SourceIndex(0)
55+
8 >Emitted(1, 27) Source(1, 19) + SourceIndex(0)
56+
9 >Emitted(1, 29) Source(1, 21) + SourceIndex(0)
57+
10>Emitted(1, 32) Source(1, 24) + SourceIndex(0)
58+
11>Emitted(1, 34) Source(1, 26) + SourceIndex(0)
59+
12>Emitted(1, 37) Source(1, 29) + SourceIndex(0)
60+
13>Emitted(1, 38) Source(1, 30) + SourceIndex(0)
61+
14>Emitted(1, 40) Source(1, 6) + SourceIndex(0)
62+
15>Emitted(1, 54) Source(1, 11) + SourceIndex(0)
63+
16>Emitted(1, 56) Source(1, 6) + SourceIndex(0)
64+
17>Emitted(1, 60) Source(1, 30) + SourceIndex(0)
65+
18>Emitted(1, 61) Source(1, 31) + SourceIndex(0)
66+
---
67+
>>> var v = _a[_i];
68+
1 >^^^^
69+
2 > ^^^^
70+
3 > ^
71+
4 > ^^^^^^^^^
72+
5 > ^^->
73+
1 >
74+
2 > var
75+
3 > v
76+
4 >
77+
1 >Emitted(2, 5) Source(1, 6) + SourceIndex(0)
78+
2 >Emitted(2, 9) Source(1, 10) + SourceIndex(0)
79+
3 >Emitted(2, 10) Source(1, 11) + SourceIndex(0)
80+
4 >Emitted(2, 19) Source(1, 11) + SourceIndex(0)
81+
---
82+
>>> console.log(v);
83+
1->^^^^
84+
2 > ^^^^^^^
85+
3 > ^
86+
4 > ^^^
87+
5 > ^
88+
6 > ^
89+
7 > ^
90+
8 > ^
91+
1-> of ['a', 'b', 'c']) {
92+
>
93+
2 > console
94+
3 > .
95+
4 > log
96+
5 > (
97+
6 > v
98+
7 > )
99+
8 > ;
100+
1->Emitted(3, 5) Source(2, 5) + SourceIndex(0)
101+
2 >Emitted(3, 12) Source(2, 12) + SourceIndex(0)
102+
3 >Emitted(3, 13) Source(2, 13) + SourceIndex(0)
103+
4 >Emitted(3, 16) Source(2, 16) + SourceIndex(0)
104+
5 >Emitted(3, 17) Source(2, 17) + SourceIndex(0)
105+
6 >Emitted(3, 18) Source(2, 18) + SourceIndex(0)
106+
7 >Emitted(3, 19) Source(2, 19) + SourceIndex(0)
107+
8 >Emitted(3, 20) Source(2, 20) + SourceIndex(0)
108+
---
109+
>>>}
110+
1 >^
111+
2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^->
112+
1 >
113+
>}
114+
1 >Emitted(4, 2) Source(3, 2) + SourceIndex(0)
115+
---
116+
>>>//# sourceMappingURL=ES5For-of1.js.map
Collapse file

‎tests/baselines/reference/ES5For-of13.js‎

Copy file name to clipboardExpand all lines: tests/baselines/reference/ES5For-of13.js
+3-2Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Collapse file

‎tests/baselines/reference/ES5For-of13.js.map‎

Copy file name to clipboardExpand all lines: tests/baselines/reference/ES5For-of13.js.map
+2Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Collapse file
+109Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
===================================================================
2+
JsFile: ES5For-of13.js
3+
mapUrl: ES5For-of13.js.map
4+
sourceRoot:
5+
sources: ES5For-of13.ts
6+
===================================================================
7+
-------------------------------------------------------------------
8+
emittedFile:tests/cases/conformance/statements/for-ofStatements/ES5For-of13.js
9+
sourceFile:ES5For-of13.ts
10+
-------------------------------------------------------------------
11+
>>>for (var _i = 0, _a = ['a', 'b', 'c']; _i < _a.length; _i++) {
12+
1 >
13+
2 >^^^
14+
3 > ^
15+
4 > ^
16+
5 > ^^^^^^^^^^
17+
6 > ^^
18+
7 > ^^^^^^
19+
8 > ^^^
20+
9 > ^^
21+
10> ^^^
22+
11> ^^
23+
12> ^^^
24+
13> ^
25+
14> ^^
26+
15> ^^^^^^^^^^^^^^
27+
16> ^^
28+
17> ^^^^
29+
18> ^
30+
1 >
31+
2 >for
32+
3 >
33+
4 > (let v of
34+
5 > ['a', 'b', 'c']
35+
6 >
36+
7 > [
37+
8 > 'a'
38+
9 > ,
39+
10> 'b'
40+
11> ,
41+
12> 'c'
42+
13> ]
43+
14>
44+
15> let v
45+
16>
46+
17> let v of ['a', 'b', 'c']
47+
18> )
48+
1 >Emitted(1, 1) Source(1, 1) + SourceIndex(0)
49+
2 >Emitted(1, 4) Source(1, 4) + SourceIndex(0)
50+
3 >Emitted(1, 5) Source(1, 5) + SourceIndex(0)
51+
4 >Emitted(1, 6) Source(1, 15) + SourceIndex(0)
52+
5 >Emitted(1, 16) Source(1, 30) + SourceIndex(0)
53+
6 >Emitted(1, 18) Source(1, 15) + SourceIndex(0)
54+
7 >Emitted(1, 24) Source(1, 16) + SourceIndex(0)
55+
8 >Emitted(1, 27) Source(1, 19) + SourceIndex(0)
56+
9 >Emitted(1, 29) Source(1, 21) + SourceIndex(0)
57+
10>Emitted(1, 32) Source(1, 24) + SourceIndex(0)
58+
11>Emitted(1, 34) Source(1, 26) + SourceIndex(0)
59+
12>Emitted(1, 37) Source(1, 29) + SourceIndex(0)
60+
13>Emitted(1, 38) Source(1, 30) + SourceIndex(0)
61+
14>Emitted(1, 40) Source(1, 6) + SourceIndex(0)
62+
15>Emitted(1, 54) Source(1, 11) + SourceIndex(0)
63+
16>Emitted(1, 56) Source(1, 6) + SourceIndex(0)
64+
17>Emitted(1, 60) Source(1, 30) + SourceIndex(0)
65+
18>Emitted(1, 61) Source(1, 31) + SourceIndex(0)
66+
---
67+
>>> var v = _a[_i];
68+
1 >^^^^
69+
2 > ^^^^
70+
3 > ^
71+
4 > ^^^^^^^^^
72+
1 >
73+
2 > let
74+
3 > v
75+
4 >
76+
1 >Emitted(2, 5) Source(1, 6) + SourceIndex(0)
77+
2 >Emitted(2, 9) Source(1, 10) + SourceIndex(0)
78+
3 >Emitted(2, 10) Source(1, 11) + SourceIndex(0)
79+
4 >Emitted(2, 19) Source(1, 11) + SourceIndex(0)
80+
---
81+
>>> var x = v;
82+
1 >^^^^
83+
2 > ^^^^
84+
3 > ^
85+
4 > ^^^
86+
5 > ^
87+
6 > ^
88+
1 > of ['a', 'b', 'c']) {
89+
>
90+
2 > var
91+
3 > x
92+
4 > =
93+
5 > v
94+
6 > ;
95+
1 >Emitted(3, 5) Source(2, 5) + SourceIndex(0)
96+
2 >Emitted(3, 9) Source(2, 9) + SourceIndex(0)
97+
3 >Emitted(3, 10) Source(2, 10) + SourceIndex(0)
98+
4 >Emitted(3, 13) Source(2, 13) + SourceIndex(0)
99+
5 >Emitted(3, 14) Source(2, 14) + SourceIndex(0)
100+
6 >Emitted(3, 15) Source(2, 15) + SourceIndex(0)
101+
---
102+
>>>}
103+
1 >^
104+
2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^->
105+
1 >
106+
>}
107+
1 >Emitted(4, 2) Source(3, 2) + SourceIndex(0)
108+
---
109+
>>>//# sourceMappingURL=ES5For-of13.js.map
Collapse file

‎tests/baselines/reference/ES5For-of25.js‎

Copy file name to clipboardExpand all lines: tests/baselines/reference/ES5For-of25.js
+1Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Collapse file

‎tests/baselines/reference/ES5For-of25.js.map‎

Copy file name to clipboardExpand all lines: tests/baselines/reference/ES5For-of25.js.map
+2Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.