forked from microsoft/TypeScript
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Baseline arity checks for jsx sfc tags
- Loading branch information
Showing
7 changed files
with
258 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
tests/baselines/reference/jsxIssuesErrorWhenTagExpectsTooManyArguments.errors.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
tests/cases/compiler/jsxIssuesErrorWhenTagExpectsTooManyArguments.tsx(13,12): error TS6229: Function-like tag expects more arguments than the JSX factory can provide. | ||
|
||
|
||
==== tests/cases/compiler/jsxIssuesErrorWhenTagExpectsTooManyArguments.tsx (1 errors) ==== | ||
/// <reference path="/.lib/react16.d.ts" /> | ||
|
||
import * as React from "react"; | ||
|
||
interface MyProps { | ||
x: number; | ||
} | ||
|
||
function MyComp(props: MyProps, context: any, bad: any, verybad: any) { | ||
return <div></div>; | ||
} | ||
|
||
const a = <MyComp x={2}/>; // using `MyComp` as a component should error - it expects more arguments than react provides | ||
~~~~~~ | ||
!!! error TS6229: Function-like tag expects more arguments than the JSX factory can provide. | ||
|
||
function MyComp2(props: MyProps, context: any) { | ||
return <div></div> | ||
} | ||
const b = <MyComp2 x={2}/>; // Should be OK, `context` is allowed, per react rules |
33 changes: 33 additions & 0 deletions
33
tests/baselines/reference/jsxIssuesErrorWhenTagExpectsTooManyArguments.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
//// [jsxIssuesErrorWhenTagExpectsTooManyArguments.tsx] | ||
/// <reference path="/.lib/react16.d.ts" /> | ||
|
||
import * as React from "react"; | ||
|
||
interface MyProps { | ||
x: number; | ||
} | ||
|
||
function MyComp(props: MyProps, context: any, bad: any, verybad: any) { | ||
return <div></div>; | ||
} | ||
|
||
const a = <MyComp x={2}/>; // using `MyComp` as a component should error - it expects more arguments than react provides | ||
|
||
function MyComp2(props: MyProps, context: any) { | ||
return <div></div> | ||
} | ||
const b = <MyComp2 x={2}/>; // Should be OK, `context` is allowed, per react rules | ||
//// [jsxIssuesErrorWhenTagExpectsTooManyArguments.js] | ||
"use strict"; | ||
/// <reference path="react16.d.ts" /> | ||
exports.__esModule = true; | ||
var React = require("react"); | ||
function MyComp(props, context, bad, verybad) { | ||
return React.createElement("div", null); | ||
} | ||
var a = React.createElement(MyComp, { x: 2 }); // using `MyComp` as a component should error - it expects more arguments than react provides | ||
function MyComp2(props, context) { | ||
return React.createElement("div", null); | ||
} | ||
var b = React.createElement(MyComp2, { x: 2 }); // Should be OK, `context` is allowed, per react rules |
46 changes: 46 additions & 0 deletions
46
tests/baselines/reference/jsxIssuesErrorWhenTagExpectsTooManyArguments.symbols
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
=== tests/cases/compiler/jsxIssuesErrorWhenTagExpectsTooManyArguments.tsx === | ||
/// <reference path="react16.d.ts" /> | ||
|
||
import * as React from "react"; | ||
>React : Symbol(React, Decl(jsxIssuesErrorWhenTagExpectsTooManyArguments.tsx, 2, 6)) | ||
|
||
interface MyProps { | ||
>MyProps : Symbol(MyProps, Decl(jsxIssuesErrorWhenTagExpectsTooManyArguments.tsx, 2, 31)) | ||
|
||
x: number; | ||
>x : Symbol(MyProps.x, Decl(jsxIssuesErrorWhenTagExpectsTooManyArguments.tsx, 4, 19)) | ||
} | ||
|
||
function MyComp(props: MyProps, context: any, bad: any, verybad: any) { | ||
>MyComp : Symbol(MyComp, Decl(jsxIssuesErrorWhenTagExpectsTooManyArguments.tsx, 6, 1)) | ||
>props : Symbol(props, Decl(jsxIssuesErrorWhenTagExpectsTooManyArguments.tsx, 8, 16)) | ||
>MyProps : Symbol(MyProps, Decl(jsxIssuesErrorWhenTagExpectsTooManyArguments.tsx, 2, 31)) | ||
>context : Symbol(context, Decl(jsxIssuesErrorWhenTagExpectsTooManyArguments.tsx, 8, 31)) | ||
>bad : Symbol(bad, Decl(jsxIssuesErrorWhenTagExpectsTooManyArguments.tsx, 8, 45)) | ||
>verybad : Symbol(verybad, Decl(jsxIssuesErrorWhenTagExpectsTooManyArguments.tsx, 8, 55)) | ||
|
||
return <div></div>; | ||
>div : Symbol(JSX.IntrinsicElements.div, Decl(react16.d.ts, 2420, 114)) | ||
>div : Symbol(JSX.IntrinsicElements.div, Decl(react16.d.ts, 2420, 114)) | ||
} | ||
|
||
const a = <MyComp x={2}/>; // using `MyComp` as a component should error - it expects more arguments than react provides | ||
>a : Symbol(a, Decl(jsxIssuesErrorWhenTagExpectsTooManyArguments.tsx, 12, 5)) | ||
>MyComp : Symbol(MyComp, Decl(jsxIssuesErrorWhenTagExpectsTooManyArguments.tsx, 6, 1)) | ||
>x : Symbol(x, Decl(jsxIssuesErrorWhenTagExpectsTooManyArguments.tsx, 12, 17)) | ||
|
||
function MyComp2(props: MyProps, context: any) { | ||
>MyComp2 : Symbol(MyComp2, Decl(jsxIssuesErrorWhenTagExpectsTooManyArguments.tsx, 12, 26)) | ||
>props : Symbol(props, Decl(jsxIssuesErrorWhenTagExpectsTooManyArguments.tsx, 14, 17)) | ||
>MyProps : Symbol(MyProps, Decl(jsxIssuesErrorWhenTagExpectsTooManyArguments.tsx, 2, 31)) | ||
>context : Symbol(context, Decl(jsxIssuesErrorWhenTagExpectsTooManyArguments.tsx, 14, 32)) | ||
|
||
return <div></div> | ||
>div : Symbol(JSX.IntrinsicElements.div, Decl(react16.d.ts, 2420, 114)) | ||
>div : Symbol(JSX.IntrinsicElements.div, Decl(react16.d.ts, 2420, 114)) | ||
} | ||
const b = <MyComp2 x={2}/>; // Should be OK, `context` is allowed, per react rules | ||
>b : Symbol(b, Decl(jsxIssuesErrorWhenTagExpectsTooManyArguments.tsx, 17, 5)) | ||
>MyComp2 : Symbol(MyComp2, Decl(jsxIssuesErrorWhenTagExpectsTooManyArguments.tsx, 12, 26)) | ||
>x : Symbol(x, Decl(jsxIssuesErrorWhenTagExpectsTooManyArguments.tsx, 17, 19)) | ||
|
48 changes: 48 additions & 0 deletions
48
tests/baselines/reference/jsxIssuesErrorWhenTagExpectsTooManyArguments.types
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
=== tests/cases/compiler/jsxIssuesErrorWhenTagExpectsTooManyArguments.tsx === | ||
/// <reference path="react16.d.ts" /> | ||
|
||
import * as React from "react"; | ||
>React : typeof React | ||
|
||
interface MyProps { | ||
x: number; | ||
>x : number | ||
} | ||
|
||
function MyComp(props: MyProps, context: any, bad: any, verybad: any) { | ||
>MyComp : (props: MyProps, context: any, bad: any, verybad: any) => JSX.Element | ||
>props : MyProps | ||
>context : any | ||
>bad : any | ||
>verybad : any | ||
|
||
return <div></div>; | ||
><div></div> : JSX.Element | ||
>div : any | ||
>div : any | ||
} | ||
|
||
const a = <MyComp x={2}/>; // using `MyComp` as a component should error - it expects more arguments than react provides | ||
>a : JSX.Element | ||
><MyComp x={2}/> : JSX.Element | ||
>MyComp : (props: MyProps, context: any, bad: any, verybad: any) => JSX.Element | ||
>x : number | ||
>2 : 2 | ||
|
||
function MyComp2(props: MyProps, context: any) { | ||
>MyComp2 : (props: MyProps, context: any) => JSX.Element | ||
>props : MyProps | ||
>context : any | ||
|
||
return <div></div> | ||
><div></div> : JSX.Element | ||
>div : any | ||
>div : any | ||
} | ||
const b = <MyComp2 x={2}/>; // Should be OK, `context` is allowed, per react rules | ||
>b : JSX.Element | ||
><MyComp2 x={2}/> : JSX.Element | ||
>MyComp2 : (props: MyProps, context: any) => JSX.Element | ||
>x : number | ||
>2 : 2 | ||
|
19 changes: 19 additions & 0 deletions
19
tests/cases/compiler/jsxIssuesErrorWhenTagExpectsTooManyArguments.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// @jsx: react | ||
/// <reference path="/.lib/react16.d.ts" /> | ||
|
||
import * as React from "react"; | ||
|
||
interface MyProps { | ||
x: number; | ||
} | ||
|
||
function MyComp(props: MyProps, context: any, bad: any, verybad: any) { | ||
return <div></div>; | ||
} | ||
|
||
const a = <MyComp x={2}/>; // using `MyComp` as a component should error - it expects more arguments than react provides | ||
|
||
function MyComp2(props: MyProps, context: any) { | ||
return <div></div> | ||
} | ||
const b = <MyComp2 x={2}/>; // Should be OK, `context` is allowed, per react rules |