Skip to content

Commit 54ceb51

Browse files
committed
Fix the emit when jsx attribute expression is empty
Fixes #12994
1 parent 88c6825 commit 54ceb51

File tree

4 files changed

+59
-0
lines changed

4 files changed

+59
-0
lines changed

src/compiler/transformers/jsx.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@ namespace ts {
150150
return decoded ? createLiteral(decoded, /*location*/ node) : node;
151151
}
152152
else if (node.kind === SyntaxKind.JsxExpression) {
153+
if (node.expression === undefined) {
154+
return createLiteral(true);
155+
}
153156
return visitJsxExpression(<JsxExpression>node);
154157
}
155158
else {
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
tests/cases/compiler/jsxAttributeWithoutExpressionReact.tsx(3,2): error TS2304: Cannot find name 'View'.
2+
tests/cases/compiler/jsxAttributeWithoutExpressionReact.tsx(4,6): error TS2304: Cannot find name 'ListView'.
3+
tests/cases/compiler/jsxAttributeWithoutExpressionReact.tsx(5,10): error TS2304: Cannot find name 'RefreshControl'.
4+
tests/cases/compiler/jsxAttributeWithoutExpressionReact.tsx(5,35): error TS17000: JSX attributes must only be assigned a non-empty 'expression'.
5+
tests/cases/compiler/jsxAttributeWithoutExpressionReact.tsx(6,44): error TS17000: JSX attributes must only be assigned a non-empty 'expression'.
6+
tests/cases/compiler/jsxAttributeWithoutExpressionReact.tsx(7,7): error TS2304: Cannot find name 'ListView'.
7+
tests/cases/compiler/jsxAttributeWithoutExpressionReact.tsx(8,3): error TS2304: Cannot find name 'View'.
8+
9+
10+
==== tests/cases/compiler/jsxAttributeWithoutExpressionReact.tsx (7 errors) ====
11+
12+
declare var React: any;
13+
<View>
14+
~~~~
15+
!!! error TS2304: Cannot find name 'View'.
16+
<ListView refreshControl={
17+
~~~~~~~~
18+
!!! error TS2304: Cannot find name 'ListView'.
19+
<RefreshControl onRefresh={} refreshing={} />
20+
~~~~~~~~~~~~~~
21+
!!! error TS2304: Cannot find name 'RefreshControl'.
22+
~~
23+
!!! error TS17000: JSX attributes must only be assigned a non-empty 'expression'.
24+
} dataSource={this.state.ds} renderRow={}>
25+
~~
26+
!!! error TS17000: JSX attributes must only be assigned a non-empty 'expression'.
27+
</ListView>
28+
~~~~~~~~
29+
!!! error TS2304: Cannot find name 'ListView'.
30+
</View>
31+
~~~~
32+
!!! error TS2304: Cannot find name 'View'.
33+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//// [jsxAttributeWithoutExpressionReact.tsx]
2+
3+
declare var React: any;
4+
<View>
5+
<ListView refreshControl={
6+
<RefreshControl onRefresh={} refreshing={} />
7+
} dataSource={this.state.ds} renderRow={}>
8+
</ListView>
9+
</View>
10+
11+
12+
//// [jsxAttributeWithoutExpressionReact.js]
13+
React.createElement(View, null,
14+
React.createElement(ListView, { refreshControl: React.createElement(RefreshControl, { onRefresh: true, refreshing: true }), dataSource: this.state.ds, renderRow: true }));
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//@jsx: react
2+
3+
declare var React: any;
4+
<View>
5+
<ListView refreshControl={
6+
<RefreshControl onRefresh={} refreshing={} />
7+
} dataSource={this.state.ds} renderRow={}>
8+
</ListView>
9+
</View>

0 commit comments

Comments
 (0)