Skip to content

Commit

Permalink
Fix bug: Don't skip emitting JSX attributes (#21777)
Browse files Browse the repository at this point in the history
  • Loading branch information
Andy authored Mar 12, 2018
1 parent 9d6386c commit ac5a39c
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 39 deletions.
8 changes: 2 additions & 6 deletions src/compiler/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2220,10 +2220,7 @@ namespace ts {
writePunctuation("<");
emitJsxTagName(node.tagName);
writeSpace();
// We are checking here so we won't re-enter the emiting pipeline and emit extra sourcemap
if (node.attributes.properties && node.attributes.properties.length > 0) {
emit(node.attributes);
}
emit(node.attributes);
writePunctuation("/>");
}

Expand All @@ -2238,11 +2235,10 @@ namespace ts {

if (isJsxOpeningElement(node)) {
emitJsxTagName(node.tagName);
// We are checking here so we won't re-enter the emitting pipeline and emit extra sourcemap
if (node.attributes.properties && node.attributes.properties.length > 0) {
writeSpace();
emit(node.attributes);
}
emit(node.attributes);
}

writePunctuation(">");
Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/tsxEmit3.js.map

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

92 changes: 61 additions & 31 deletions tests/baselines/reference/tsxEmit3.sourcemap.txt
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,10 @@ sourceFile:file.tsx
5 > ^
6 > ^^
7 > ^^^
8 > ^^^
9 > ^
8 > ^
9 >
10> ^^
11> ^
1->
>
2 >
Expand All @@ -329,17 +331,21 @@ sourceFile:file.tsx
5 > <
6 >
7 > Foo
8 > />
9 > ;
8 >
9 >
10> />
11> ;
1->Emitted(23, 5) Source(18, 2) + SourceIndex(0)
2 >Emitted(23, 7) Source(18, 2) + SourceIndex(0)
3 >Emitted(23, 10) Source(18, 5) + SourceIndex(0)
4 >Emitted(23, 12) Source(18, 7) + SourceIndex(0)
5 >Emitted(23, 13) Source(18, 8) + SourceIndex(0)
6 >Emitted(23, 15) Source(18, 8) + SourceIndex(0)
7 >Emitted(23, 18) Source(18, 11) + SourceIndex(0)
8 >Emitted(23, 21) Source(18, 14) + SourceIndex(0)
9 >Emitted(23, 22) Source(18, 15) + SourceIndex(0)
8 >Emitted(23, 19) Source(18, 12) + SourceIndex(0)
9 >Emitted(23, 19) Source(18, 11) + SourceIndex(0)
10>Emitted(23, 21) Source(18, 14) + SourceIndex(0)
11>Emitted(23, 22) Source(18, 15) + SourceIndex(0)
---
>>> var S;
1 >^^^^
Expand Down Expand Up @@ -394,8 +400,10 @@ sourceFile:file.tsx
5 > ^
6 > ^^
7 > ^^^
8 > ^^^
9 > ^
8 > ^
9 >
10> ^^
11> ^
1->
>
2 >
Expand All @@ -404,17 +412,21 @@ sourceFile:file.tsx
5 > <
6 >
7 > Foo
8 > />
9 > ;
8 >
9 >
10> />
11> ;
1->Emitted(27, 9) Source(22, 3) + SourceIndex(0)
2 >Emitted(27, 11) Source(22, 3) + SourceIndex(0)
3 >Emitted(27, 14) Source(22, 6) + SourceIndex(0)
4 >Emitted(27, 16) Source(22, 8) + SourceIndex(0)
5 >Emitted(27, 17) Source(22, 9) + SourceIndex(0)
6 >Emitted(27, 19) Source(22, 9) + SourceIndex(0)
7 >Emitted(27, 22) Source(22, 12) + SourceIndex(0)
8 >Emitted(27, 25) Source(22, 15) + SourceIndex(0)
9 >Emitted(27, 26) Source(22, 16) + SourceIndex(0)
8 >Emitted(27, 23) Source(22, 13) + SourceIndex(0)
9 >Emitted(27, 23) Source(22, 12) + SourceIndex(0)
10>Emitted(27, 25) Source(22, 15) + SourceIndex(0)
11>Emitted(27, 26) Source(22, 16) + SourceIndex(0)
---
>>> // Emit S.Bar
1 >^^^^^^^^
Expand All @@ -435,9 +447,11 @@ sourceFile:file.tsx
5 > ^
6 > ^^
7 > ^^^
8 > ^^^
9 > ^
10> ^^^^^^->
8 > ^
9 >
10> ^^
11> ^
12> ^^^^^^->
1->
>
2 >
Expand All @@ -446,17 +460,21 @@ sourceFile:file.tsx
5 > <
6 >
7 > Bar
8 > />
9 > ;
8 >
9 >
10> />
11> ;
1->Emitted(29, 9) Source(25, 3) + SourceIndex(0)
2 >Emitted(29, 11) Source(25, 3) + SourceIndex(0)
3 >Emitted(29, 14) Source(25, 6) + SourceIndex(0)
4 >Emitted(29, 16) Source(25, 8) + SourceIndex(0)
5 >Emitted(29, 17) Source(25, 9) + SourceIndex(0)
6 >Emitted(29, 19) Source(25, 9) + SourceIndex(0)
7 >Emitted(29, 22) Source(25, 12) + SourceIndex(0)
8 >Emitted(29, 25) Source(25, 15) + SourceIndex(0)
9 >Emitted(29, 26) Source(25, 16) + SourceIndex(0)
8 >Emitted(29, 23) Source(25, 13) + SourceIndex(0)
9 >Emitted(29, 23) Source(25, 12) + SourceIndex(0)
10>Emitted(29, 25) Source(25, 15) + SourceIndex(0)
11>Emitted(29, 26) Source(25, 16) + SourceIndex(0)
---
>>> })(S = M.S || (M.S = {}));
1->^^^^
Expand Down Expand Up @@ -567,8 +585,10 @@ sourceFile:file.tsx
9 > ^
10> ^
11> ^^^
12> ^^^
13> ^
12> ^
13>
14> ^^
15> ^
1->
>
2 >
Expand All @@ -581,8 +601,10 @@ sourceFile:file.tsx
9 > S
10> .
11> Bar
12> />
13> ;
12>
13>
14> />
15> ;
1->Emitted(34, 5) Source(32, 2) + SourceIndex(0)
2 >Emitted(34, 7) Source(32, 2) + SourceIndex(0)
3 >Emitted(34, 8) Source(32, 3) + SourceIndex(0)
Expand All @@ -594,8 +616,10 @@ sourceFile:file.tsx
9 >Emitted(34, 18) Source(32, 11) + SourceIndex(0)
10>Emitted(34, 19) Source(32, 12) + SourceIndex(0)
11>Emitted(34, 22) Source(32, 15) + SourceIndex(0)
12>Emitted(34, 25) Source(32, 18) + SourceIndex(0)
13>Emitted(34, 26) Source(32, 19) + SourceIndex(0)
12>Emitted(34, 23) Source(32, 16) + SourceIndex(0)
13>Emitted(34, 23) Source(32, 15) + SourceIndex(0)
14>Emitted(34, 25) Source(32, 18) + SourceIndex(0)
15>Emitted(34, 26) Source(32, 19) + SourceIndex(0)
---
>>>})(M || (M = {}));
1 >
Expand Down Expand Up @@ -678,8 +702,10 @@ sourceFile:file.tsx
5 > ^
6 > ^^^^
7 > ^^^
8 > ^^^
9 > ^
8 > ^
9 >
10> ^^
11> ^
1->
>
2 >
Expand All @@ -688,17 +714,21 @@ sourceFile:file.tsx
5 > <
6 >
7 > Foo
8 > />
9 > ;
8 >
9 >
10> />
11> ;
1->Emitted(39, 5) Source(38, 2) + SourceIndex(0)
2 >Emitted(39, 9) Source(38, 2) + SourceIndex(0)
3 >Emitted(39, 12) Source(38, 5) + SourceIndex(0)
4 >Emitted(39, 14) Source(38, 7) + SourceIndex(0)
5 >Emitted(39, 15) Source(38, 8) + SourceIndex(0)
6 >Emitted(39, 19) Source(38, 8) + SourceIndex(0)
7 >Emitted(39, 22) Source(38, 11) + SourceIndex(0)
8 >Emitted(39, 25) Source(38, 14) + SourceIndex(0)
9 >Emitted(39, 26) Source(38, 15) + SourceIndex(0)
8 >Emitted(39, 23) Source(38, 12) + SourceIndex(0)
9 >Emitted(39, 23) Source(38, 11) + SourceIndex(0)
10>Emitted(39, 25) Source(38, 14) + SourceIndex(0)
11>Emitted(39, 26) Source(38, 15) + SourceIndex(0)
---
>>>})(M || (M = {}));
1 >
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,9 @@
/////*a*/<div></div>/*b*/

goTo.select("a", "b");
verify.refactorAvailable("Extract Symbol", "constant_scope_0");
edit.applyRefactor({
refactorName: "Extract Symbol",
actionName: "constant_scope_0",
actionDescription: "Extract to constant in enclosing scope",
newContent: "const /*RENAME*/newLocal = <div></div>;",
});

0 comments on commit ac5a39c

Please sign in to comment.