mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Fix bug #3737 (exported JSX classes props not validated)
This commit is contained in:
+7
-11
@@ -7095,13 +7095,18 @@ namespace ts {
|
||||
|
||||
// Look up the value in the current scope
|
||||
if (node.tagName.kind === SyntaxKind.Identifier) {
|
||||
valueSymbol = getResolvedSymbol(<Identifier>node.tagName);
|
||||
let tag = <Identifier>node.tagName;
|
||||
valueSymbol = resolveName(tag, tag.text, SymbolFlags.Value, Diagnostics.Cannot_find_name_0, tag.text);
|
||||
}
|
||||
else {
|
||||
valueSymbol = checkQualifiedName(<QualifiedName>node.tagName).symbol;
|
||||
}
|
||||
|
||||
if (valueSymbol !== unknownSymbol) {
|
||||
if (valueSymbol && valueSymbol !== unknownSymbol) {
|
||||
let symbolLinks = getSymbolLinks(valueSymbol);
|
||||
if (symbolLinks) {
|
||||
symbolLinks.referenced = true;
|
||||
}
|
||||
links.jsxFlags |= JsxFlags.ClassElement;
|
||||
}
|
||||
|
||||
@@ -7301,15 +7306,6 @@ namespace ts {
|
||||
|
||||
let targetAttributesType = getJsxElementAttributesType(node);
|
||||
|
||||
if (getNodeLinks(node).jsxFlags & JsxFlags.ClassElement) {
|
||||
if (node.tagName.kind === SyntaxKind.Identifier) {
|
||||
checkIdentifier(<Identifier>node.tagName);
|
||||
}
|
||||
else {
|
||||
checkQualifiedName(<QualifiedName>node.tagName);
|
||||
}
|
||||
}
|
||||
|
||||
let nameTable: Map<boolean> = {};
|
||||
// Process this array in right-to-left order so we know which
|
||||
// attributes (mostly from spreads) are being overwritten and
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
tests/cases/conformance/jsx/file.tsx(9,14): error TS2322: Type 'number' is not assignable to type 'string'.
|
||||
|
||||
|
||||
==== tests/cases/conformance/jsx/react.d.ts (0 errors) ====
|
||||
|
||||
declare module JSX {
|
||||
interface Element { }
|
||||
interface IntrinsicElements {
|
||||
}
|
||||
interface ElementAttributesProperty {
|
||||
props;
|
||||
}
|
||||
}
|
||||
|
||||
interface Props {
|
||||
foo: string;
|
||||
}
|
||||
|
||||
==== tests/cases/conformance/jsx/file.tsx (1 errors) ====
|
||||
export class MyComponent {
|
||||
render() {
|
||||
}
|
||||
|
||||
props: { foo: string; }
|
||||
}
|
||||
|
||||
<MyComponent foo="bar" />; // ok
|
||||
<MyComponent foo={0} />; // should be an error
|
||||
~~~~~~~
|
||||
!!! error TS2322: Type 'number' is not assignable to type 'string'.
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
//// [tests/cases/conformance/jsx/tsxAttributeResolution9.tsx] ////
|
||||
|
||||
//// [react.d.ts]
|
||||
|
||||
declare module JSX {
|
||||
interface Element { }
|
||||
interface IntrinsicElements {
|
||||
}
|
||||
interface ElementAttributesProperty {
|
||||
props;
|
||||
}
|
||||
}
|
||||
|
||||
interface Props {
|
||||
foo: string;
|
||||
}
|
||||
|
||||
//// [file.tsx]
|
||||
export class MyComponent {
|
||||
render() {
|
||||
}
|
||||
|
||||
props: { foo: string; }
|
||||
}
|
||||
|
||||
<MyComponent foo="bar" />; // ok
|
||||
<MyComponent foo={0} />; // should be an error
|
||||
|
||||
|
||||
//// [file.jsx]
|
||||
define(["require", "exports"], function (require, exports) {
|
||||
var MyComponent = (function () {
|
||||
function MyComponent() {
|
||||
}
|
||||
MyComponent.prototype.render = function () {
|
||||
};
|
||||
return MyComponent;
|
||||
})();
|
||||
exports.MyComponent = MyComponent;
|
||||
<MyComponent foo="bar"/>; // ok
|
||||
<MyComponent foo={0}/>; // should be an error
|
||||
});
|
||||
@@ -0,0 +1,45 @@
|
||||
=== tests/cases/conformance/jsx/tsxAttributeResolution9.tsx ===
|
||||
declare module JSX {
|
||||
>JSX : Symbol(JSX, Decl(tsxAttributeResolution9.tsx, 0, 0))
|
||||
|
||||
interface Element { }
|
||||
>Element : Symbol(Element, Decl(tsxAttributeResolution9.tsx, 0, 20))
|
||||
|
||||
interface IntrinsicElements {
|
||||
>IntrinsicElements : Symbol(IntrinsicElements, Decl(tsxAttributeResolution9.tsx, 1, 22))
|
||||
}
|
||||
interface ElementAttributesProperty {
|
||||
>ElementAttributesProperty : Symbol(ElementAttributesProperty, Decl(tsxAttributeResolution9.tsx, 3, 2))
|
||||
|
||||
props;
|
||||
>props : Symbol(props, Decl(tsxAttributeResolution9.tsx, 4, 38))
|
||||
}
|
||||
}
|
||||
|
||||
interface Props {
|
||||
>Props : Symbol(Props, Decl(tsxAttributeResolution9.tsx, 7, 1))
|
||||
|
||||
foo: string;
|
||||
>foo : Symbol(foo, Decl(tsxAttributeResolution9.tsx, 9, 17))
|
||||
}
|
||||
|
||||
export class MyComponent {
|
||||
>MyComponent : Symbol(MyComponent, Decl(tsxAttributeResolution9.tsx, 11, 1))
|
||||
|
||||
render() {
|
||||
>render : Symbol(render, Decl(tsxAttributeResolution9.tsx, 13, 26))
|
||||
}
|
||||
|
||||
props: { foo: string; }
|
||||
>props : Symbol(props, Decl(tsxAttributeResolution9.tsx, 15, 3))
|
||||
>foo : Symbol(foo, Decl(tsxAttributeResolution9.tsx, 17, 10))
|
||||
}
|
||||
|
||||
<MyComponent foo="bar" />; // ok
|
||||
>MyComponent : Symbol(MyComponent, Decl(tsxAttributeResolution9.tsx, 11, 1))
|
||||
>foo : Symbol(unknown)
|
||||
|
||||
<MyComponent foo={0} />; // should be an error
|
||||
>MyComponent : Symbol(MyComponent, Decl(tsxAttributeResolution9.tsx, 11, 1))
|
||||
>foo : Symbol(unknown)
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
=== tests/cases/conformance/jsx/tsxAttributeResolution9.tsx ===
|
||||
declare module JSX {
|
||||
>JSX : any
|
||||
|
||||
interface Element { }
|
||||
>Element : Element
|
||||
|
||||
interface IntrinsicElements {
|
||||
>IntrinsicElements : IntrinsicElements
|
||||
}
|
||||
interface ElementAttributesProperty {
|
||||
>ElementAttributesProperty : ElementAttributesProperty
|
||||
|
||||
props;
|
||||
>props : any
|
||||
}
|
||||
}
|
||||
|
||||
interface Props {
|
||||
>Props : Props
|
||||
|
||||
foo: string;
|
||||
>foo : string
|
||||
}
|
||||
|
||||
export class MyComponent {
|
||||
>MyComponent : MyComponent
|
||||
|
||||
render() {
|
||||
>render : () => void
|
||||
}
|
||||
|
||||
props: { foo: string; }
|
||||
>props : { foo: string; }
|
||||
>foo : string
|
||||
}
|
||||
|
||||
<MyComponent foo="bar" />; // ok
|
||||
><MyComponent foo="bar" /> : any
|
||||
>MyComponent : typeof MyComponent
|
||||
>foo : any
|
||||
|
||||
<MyComponent foo={0} />; // should be an error
|
||||
><MyComponent foo={0} /> : any
|
||||
>MyComponent : typeof MyComponent
|
||||
>foo : any
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
//@jsx: preserve
|
||||
//@module: amd
|
||||
|
||||
//@filename: react.d.ts
|
||||
declare module JSX {
|
||||
interface Element { }
|
||||
interface IntrinsicElements {
|
||||
}
|
||||
interface ElementAttributesProperty {
|
||||
props;
|
||||
}
|
||||
}
|
||||
|
||||
interface Props {
|
||||
foo: string;
|
||||
}
|
||||
|
||||
//@filename: file.tsx
|
||||
export class MyComponent {
|
||||
render() {
|
||||
}
|
||||
|
||||
props: { foo: string; }
|
||||
}
|
||||
|
||||
<MyComponent foo="bar" />; // ok
|
||||
<MyComponent foo={0} />; // should be an error
|
||||
Reference in New Issue
Block a user