Skip to content

Commit ac5a39c

Browse files
author
Andy
authored
Fix bug: Don't skip emitting JSX attributes (#21777)
1 parent 9d6386c commit ac5a39c

File tree

4 files changed

+70
-39
lines changed

4 files changed

+70
-39
lines changed

src/compiler/emitter.ts

+2-6
Original file line numberDiff line numberDiff line change
@@ -2220,10 +2220,7 @@ namespace ts {
22202220
writePunctuation("<");
22212221
emitJsxTagName(node.tagName);
22222222
writeSpace();
2223-
// We are checking here so we won't re-enter the emiting pipeline and emit extra sourcemap
2224-
if (node.attributes.properties && node.attributes.properties.length > 0) {
2225-
emit(node.attributes);
2226-
}
2223+
emit(node.attributes);
22272224
writePunctuation("/>");
22282225
}
22292226

@@ -2238,11 +2235,10 @@ namespace ts {
22382235

22392236
if (isJsxOpeningElement(node)) {
22402237
emitJsxTagName(node.tagName);
2241-
// We are checking here so we won't re-enter the emitting pipeline and emit extra sourcemap
22422238
if (node.attributes.properties && node.attributes.properties.length > 0) {
22432239
writeSpace();
2244-
emit(node.attributes);
22452240
}
2241+
emit(node.attributes);
22462242
}
22472243

22482244
writePunctuation(">");

tests/baselines/reference/tsxEmit3.js.map

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

tests/baselines/reference/tsxEmit3.sourcemap.txt

+61-31
Original file line numberDiff line numberDiff line change
@@ -319,8 +319,10 @@ sourceFile:file.tsx
319319
5 > ^
320320
6 > ^^
321321
7 > ^^^
322-
8 > ^^^
323-
9 > ^
322+
8 > ^
323+
9 >
324+
10> ^^
325+
11> ^
324326
1->
325327
>
326328
2 >
@@ -329,17 +331,21 @@ sourceFile:file.tsx
329331
5 > <
330332
6 >
331333
7 > Foo
332-
8 > />
333-
9 > ;
334+
8 >
335+
9 >
336+
10> />
337+
11> ;
334338
1->Emitted(23, 5) Source(18, 2) + SourceIndex(0)
335339
2 >Emitted(23, 7) Source(18, 2) + SourceIndex(0)
336340
3 >Emitted(23, 10) Source(18, 5) + SourceIndex(0)
337341
4 >Emitted(23, 12) Source(18, 7) + SourceIndex(0)
338342
5 >Emitted(23, 13) Source(18, 8) + SourceIndex(0)
339343
6 >Emitted(23, 15) Source(18, 8) + SourceIndex(0)
340344
7 >Emitted(23, 18) Source(18, 11) + SourceIndex(0)
341-
8 >Emitted(23, 21) Source(18, 14) + SourceIndex(0)
342-
9 >Emitted(23, 22) Source(18, 15) + SourceIndex(0)
345+
8 >Emitted(23, 19) Source(18, 12) + SourceIndex(0)
346+
9 >Emitted(23, 19) Source(18, 11) + SourceIndex(0)
347+
10>Emitted(23, 21) Source(18, 14) + SourceIndex(0)
348+
11>Emitted(23, 22) Source(18, 15) + SourceIndex(0)
343349
---
344350
>>> var S;
345351
1 >^^^^
@@ -394,8 +400,10 @@ sourceFile:file.tsx
394400
5 > ^
395401
6 > ^^
396402
7 > ^^^
397-
8 > ^^^
398-
9 > ^
403+
8 > ^
404+
9 >
405+
10> ^^
406+
11> ^
399407
1->
400408
>
401409
2 >
@@ -404,17 +412,21 @@ sourceFile:file.tsx
404412
5 > <
405413
6 >
406414
7 > Foo
407-
8 > />
408-
9 > ;
415+
8 >
416+
9 >
417+
10> />
418+
11> ;
409419
1->Emitted(27, 9) Source(22, 3) + SourceIndex(0)
410420
2 >Emitted(27, 11) Source(22, 3) + SourceIndex(0)
411421
3 >Emitted(27, 14) Source(22, 6) + SourceIndex(0)
412422
4 >Emitted(27, 16) Source(22, 8) + SourceIndex(0)
413423
5 >Emitted(27, 17) Source(22, 9) + SourceIndex(0)
414424
6 >Emitted(27, 19) Source(22, 9) + SourceIndex(0)
415425
7 >Emitted(27, 22) Source(22, 12) + SourceIndex(0)
416-
8 >Emitted(27, 25) Source(22, 15) + SourceIndex(0)
417-
9 >Emitted(27, 26) Source(22, 16) + SourceIndex(0)
426+
8 >Emitted(27, 23) Source(22, 13) + SourceIndex(0)
427+
9 >Emitted(27, 23) Source(22, 12) + SourceIndex(0)
428+
10>Emitted(27, 25) Source(22, 15) + SourceIndex(0)
429+
11>Emitted(27, 26) Source(22, 16) + SourceIndex(0)
418430
---
419431
>>> // Emit S.Bar
420432
1 >^^^^^^^^
@@ -435,9 +447,11 @@ sourceFile:file.tsx
435447
5 > ^
436448
6 > ^^
437449
7 > ^^^
438-
8 > ^^^
439-
9 > ^
440-
10> ^^^^^^->
450+
8 > ^
451+
9 >
452+
10> ^^
453+
11> ^
454+
12> ^^^^^^->
441455
1->
442456
>
443457
2 >
@@ -446,17 +460,21 @@ sourceFile:file.tsx
446460
5 > <
447461
6 >
448462
7 > Bar
449-
8 > />
450-
9 > ;
463+
8 >
464+
9 >
465+
10> />
466+
11> ;
451467
1->Emitted(29, 9) Source(25, 3) + SourceIndex(0)
452468
2 >Emitted(29, 11) Source(25, 3) + SourceIndex(0)
453469
3 >Emitted(29, 14) Source(25, 6) + SourceIndex(0)
454470
4 >Emitted(29, 16) Source(25, 8) + SourceIndex(0)
455471
5 >Emitted(29, 17) Source(25, 9) + SourceIndex(0)
456472
6 >Emitted(29, 19) Source(25, 9) + SourceIndex(0)
457473
7 >Emitted(29, 22) Source(25, 12) + SourceIndex(0)
458-
8 >Emitted(29, 25) Source(25, 15) + SourceIndex(0)
459-
9 >Emitted(29, 26) Source(25, 16) + SourceIndex(0)
474+
8 >Emitted(29, 23) Source(25, 13) + SourceIndex(0)
475+
9 >Emitted(29, 23) Source(25, 12) + SourceIndex(0)
476+
10>Emitted(29, 25) Source(25, 15) + SourceIndex(0)
477+
11>Emitted(29, 26) Source(25, 16) + SourceIndex(0)
460478
---
461479
>>> })(S = M.S || (M.S = {}));
462480
1->^^^^
@@ -567,8 +585,10 @@ sourceFile:file.tsx
567585
9 > ^
568586
10> ^
569587
11> ^^^
570-
12> ^^^
571-
13> ^
588+
12> ^
589+
13>
590+
14> ^^
591+
15> ^
572592
1->
573593
>
574594
2 >
@@ -581,8 +601,10 @@ sourceFile:file.tsx
581601
9 > S
582602
10> .
583603
11> Bar
584-
12> />
585-
13> ;
604+
12>
605+
13>
606+
14> />
607+
15> ;
586608
1->Emitted(34, 5) Source(32, 2) + SourceIndex(0)
587609
2 >Emitted(34, 7) Source(32, 2) + SourceIndex(0)
588610
3 >Emitted(34, 8) Source(32, 3) + SourceIndex(0)
@@ -594,8 +616,10 @@ sourceFile:file.tsx
594616
9 >Emitted(34, 18) Source(32, 11) + SourceIndex(0)
595617
10>Emitted(34, 19) Source(32, 12) + SourceIndex(0)
596618
11>Emitted(34, 22) Source(32, 15) + SourceIndex(0)
597-
12>Emitted(34, 25) Source(32, 18) + SourceIndex(0)
598-
13>Emitted(34, 26) Source(32, 19) + SourceIndex(0)
619+
12>Emitted(34, 23) Source(32, 16) + SourceIndex(0)
620+
13>Emitted(34, 23) Source(32, 15) + SourceIndex(0)
621+
14>Emitted(34, 25) Source(32, 18) + SourceIndex(0)
622+
15>Emitted(34, 26) Source(32, 19) + SourceIndex(0)
599623
---
600624
>>>})(M || (M = {}));
601625
1 >
@@ -678,8 +702,10 @@ sourceFile:file.tsx
678702
5 > ^
679703
6 > ^^^^
680704
7 > ^^^
681-
8 > ^^^
682-
9 > ^
705+
8 > ^
706+
9 >
707+
10> ^^
708+
11> ^
683709
1->
684710
>
685711
2 >
@@ -688,17 +714,21 @@ sourceFile:file.tsx
688714
5 > <
689715
6 >
690716
7 > Foo
691-
8 > />
692-
9 > ;
717+
8 >
718+
9 >
719+
10> />
720+
11> ;
693721
1->Emitted(39, 5) Source(38, 2) + SourceIndex(0)
694722
2 >Emitted(39, 9) Source(38, 2) + SourceIndex(0)
695723
3 >Emitted(39, 12) Source(38, 5) + SourceIndex(0)
696724
4 >Emitted(39, 14) Source(38, 7) + SourceIndex(0)
697725
5 >Emitted(39, 15) Source(38, 8) + SourceIndex(0)
698726
6 >Emitted(39, 19) Source(38, 8) + SourceIndex(0)
699727
7 >Emitted(39, 22) Source(38, 11) + SourceIndex(0)
700-
8 >Emitted(39, 25) Source(38, 14) + SourceIndex(0)
701-
9 >Emitted(39, 26) Source(38, 15) + SourceIndex(0)
728+
8 >Emitted(39, 23) Source(38, 12) + SourceIndex(0)
729+
9 >Emitted(39, 23) Source(38, 11) + SourceIndex(0)
730+
10>Emitted(39, 25) Source(38, 14) + SourceIndex(0)
731+
11>Emitted(39, 26) Source(38, 15) + SourceIndex(0)
702732
---
703733
>>>})(M || (M = {}));
704734
1 >

tests/cases/fourslash/extract-method_jsxIntrinsicTagSymbol.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,9 @@
77
/////*a*/<div></div>/*b*/
88

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

0 commit comments

Comments
 (0)