Skip to content

Commit

Permalink
Add error for using jsx factory pragma with fragments
Browse files Browse the repository at this point in the history
  • Loading branch information
weswigham committed Jan 18, 2018
1 parent f4d3143 commit 28a1178
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14523,8 +14523,10 @@ namespace ts {
function checkJsxFragment(node: JsxFragment, checkMode: CheckMode): Type {
checkJsxOpeningLikeElementOrOpeningFragment(node.openingFragment, checkMode);

if (compilerOptions.jsx === JsxEmit.React && compilerOptions.jsxFactory) {
error(node, Diagnostics.JSX_fragment_is_not_supported_when_using_jsxFactory);
if (compilerOptions.jsx === JsxEmit.React && (compilerOptions.jsxFactory || getSourceFileOfNode(node).pragmas.get("jsx"))) {
error(node, compilerOptions.jsxFactory
? Diagnostics.JSX_fragment_is_not_supported_when_using_jsxFactory
: Diagnostics.JSX_fragment_is_not_supported_when_using_an_inline_JSX_factory_pragma);
}

return getJsxGlobalElementType() || anyType;
Expand Down
4 changes: 4 additions & 0 deletions src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -3767,6 +3767,10 @@
"category": "Error",
"code": 17016
},
"JSX fragment is not supported when using an inline JSX factory pragma": {
"category": "Error",
"code": 17017
},

"Circularity detected while resolving configuration: {0}": {
"category": "Error",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
tests/cases/conformance/jsx/inline/index.tsx(3,1): error TS17017: JSX fragment is not supported when using an inline JSX factory pragma


==== tests/cases/conformance/jsx/inline/renderer.d.ts (0 errors) ====
declare global {
namespace JSX {
interface IntrinsicElements {
[e: string]: any;
}
}
}
export function dom(): void;
==== tests/cases/conformance/jsx/inline/index.tsx (1 errors) ====
/** @jsx dom */
import { dom } from "./renderer";
<><h></h></>
~~~~~~~~~~~~
!!! error TS17017: JSX fragment is not supported when using an inline JSX factory pragma
23 changes: 23 additions & 0 deletions tests/baselines/reference/inlineJsxFactoryWithFragmentIsError.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//// [tests/cases/conformance/jsx/inline/inlineJsxFactoryWithFragmentIsError.tsx] ////

//// [renderer.d.ts]
declare global {
namespace JSX {
interface IntrinsicElements {
[e: string]: any;
}
}
}
export function dom(): void;
//// [index.tsx]
/** @jsx dom */
import { dom } from "./renderer";
<><h></h></>

//// [index.js]
"use strict";
exports.__esModule = true;
/** @jsx dom */
var renderer_1 = require("./renderer");
renderer_1.dom(React.Fragment, null,
renderer_1.dom("h", null));
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
=== tests/cases/conformance/jsx/inline/renderer.d.ts ===
declare global {
>global : Symbol(global, Decl(renderer.d.ts, 0, 0))

namespace JSX {
>JSX : Symbol(JSX, Decl(renderer.d.ts, 0, 16))

interface IntrinsicElements {
>IntrinsicElements : Symbol(IntrinsicElements, Decl(renderer.d.ts, 1, 19))

[e: string]: any;
>e : Symbol(e, Decl(renderer.d.ts, 3, 13))
}
}
}
export function dom(): void;
>dom : Symbol(dom, Decl(renderer.d.ts, 6, 1))

=== tests/cases/conformance/jsx/inline/index.tsx ===
/** @jsx dom */
import { dom } from "./renderer";
>dom : Symbol(dom, Decl(index.tsx, 1, 8))

<><h></h></>
>h : Symbol(JSX.IntrinsicElements, Decl(renderer.d.ts, 1, 19))
>h : Symbol(JSX.IntrinsicElements, Decl(renderer.d.ts, 1, 19))

Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
=== tests/cases/conformance/jsx/inline/renderer.d.ts ===
declare global {
>global : any

namespace JSX {
>JSX : any

interface IntrinsicElements {
>IntrinsicElements : IntrinsicElements

[e: string]: any;
>e : string
}
}
}
export function dom(): void;
>dom : () => void

=== tests/cases/conformance/jsx/inline/index.tsx ===
/** @jsx dom */
import { dom } from "./renderer";
>dom : () => void

<><h></h></>
><><h></h></> : any
><h></h> : any
>h : any
>h : any

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// @jsx: react
// @filename: renderer.d.ts
declare global {
namespace JSX {
interface IntrinsicElements {
[e: string]: any;
}
}
}
export function dom(): void;
// @filename: index.tsx
/** @jsx dom */
import { dom } from "./renderer";
<><h></h></>

0 comments on commit 28a1178

Please sign in to comment.