Skip to content

Commit

Permalink
Fix the emit when jsx attribute expression is empty
Browse files Browse the repository at this point in the history
Fixes #12994
  • Loading branch information
sheetalkamat committed Jan 3, 2017
1 parent 32cec58 commit f412e10
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/compiler/transformers/jsx.ts
Expand Up @@ -150,6 +150,9 @@ namespace ts {
return decoded ? createLiteral(decoded, /*location*/ node) : node;
}
else if (node.kind === SyntaxKind.JsxExpression) {
if (node.expression === undefined) {
return createLiteral(true);
}
return visitJsxExpression(<JsxExpression>node);
}
else {
Expand Down
@@ -0,0 +1,33 @@
tests/cases/compiler/jsxAttributeWithoutExpressionReact.tsx(3,2): error TS2304: Cannot find name 'View'.
tests/cases/compiler/jsxAttributeWithoutExpressionReact.tsx(4,6): error TS2304: Cannot find name 'ListView'.
tests/cases/compiler/jsxAttributeWithoutExpressionReact.tsx(5,10): error TS2304: Cannot find name 'RefreshControl'.
tests/cases/compiler/jsxAttributeWithoutExpressionReact.tsx(5,35): error TS17000: JSX attributes must only be assigned a non-empty 'expression'.
tests/cases/compiler/jsxAttributeWithoutExpressionReact.tsx(6,44): error TS17000: JSX attributes must only be assigned a non-empty 'expression'.
tests/cases/compiler/jsxAttributeWithoutExpressionReact.tsx(7,7): error TS2304: Cannot find name 'ListView'.
tests/cases/compiler/jsxAttributeWithoutExpressionReact.tsx(8,3): error TS2304: Cannot find name 'View'.


==== tests/cases/compiler/jsxAttributeWithoutExpressionReact.tsx (7 errors) ====

declare var React: any;
<View>
~~~~
!!! error TS2304: Cannot find name 'View'.
<ListView refreshControl={
~~~~~~~~
!!! error TS2304: Cannot find name 'ListView'.
<RefreshControl onRefresh={} refreshing={} />
~~~~~~~~~~~~~~
!!! error TS2304: Cannot find name 'RefreshControl'.
~~
!!! error TS17000: JSX attributes must only be assigned a non-empty 'expression'.
} dataSource={this.state.ds} renderRow={}>
~~
!!! error TS17000: JSX attributes must only be assigned a non-empty 'expression'.
</ListView>
~~~~~~~~
!!! error TS2304: Cannot find name 'ListView'.
</View>
~~~~
!!! error TS2304: Cannot find name 'View'.

14 changes: 14 additions & 0 deletions tests/baselines/reference/jsxAttributeWithoutExpressionReact.js
@@ -0,0 +1,14 @@
//// [jsxAttributeWithoutExpressionReact.tsx]

declare var React: any;
<View>
<ListView refreshControl={
<RefreshControl onRefresh={} refreshing={} />
} dataSource={this.state.ds} renderRow={}>
</ListView>
</View>


//// [jsxAttributeWithoutExpressionReact.js]
React.createElement(View, null,
React.createElement(ListView, { refreshControl: React.createElement(RefreshControl, { onRefresh: true, refreshing: true }), dataSource: this.state.ds, renderRow: true }));
9 changes: 9 additions & 0 deletions tests/cases/compiler/jsxAttributeWithoutExpressionReact.tsx
@@ -0,0 +1,9 @@
//@jsx: react

declare var React: any;
<View>
<ListView refreshControl={
<RefreshControl onRefresh={} refreshing={} />
} dataSource={this.state.ds} renderRow={}>
</ListView>
</View>

0 comments on commit f412e10

Please sign in to comment.