Improved fix from @JsonFreeman

This commit is contained in:
Ryan Cavanaugh 2015-07-07 14:27:57 -07:00
parent 311d20fa99
commit 99fc99f3bc
3 changed files with 26 additions and 22 deletions

View file

@ -7096,18 +7096,18 @@ namespace ts {
// Look up the value in the current scope
if (node.tagName.kind === SyntaxKind.Identifier) {
let tag = <Identifier>node.tagName;
valueSymbol = resolveName(tag, tag.text, SymbolFlags.Value, Diagnostics.Cannot_find_name_0, tag.text);
let maybeExportSymbol = getResolvedSymbol(<Identifier>node.tagName);
let valueDecl = maybeExportSymbol.valueDeclaration;
valueSymbol = (valueDecl && valueDecl.localSymbol) || maybeExportSymbol;
}
else {
valueSymbol = checkQualifiedName(<QualifiedName>node.tagName).symbol;
}
if (valueSymbol && valueSymbol !== unknownSymbol) {
let symbolLinks = getSymbolLinks(valueSymbol);
if (symbolLinks) {
symbolLinks.referenced = true;
}
links.jsxFlags |= JsxFlags.ClassElement;
getSymbolLinks(valueSymbol).referenced = true;
}
return valueSymbol || unknownSymbol;

View file

@ -1,45 +1,47 @@
=== tests/cases/conformance/jsx/tsxAttributeResolution9.tsx ===
=== tests/cases/conformance/jsx/react.d.ts ===
declare module JSX {
>JSX : Symbol(JSX, Decl(tsxAttributeResolution9.tsx, 0, 0))
>JSX : Symbol(JSX, Decl(react.d.ts, 0, 0))
interface Element { }
>Element : Symbol(Element, Decl(tsxAttributeResolution9.tsx, 0, 20))
>Element : Symbol(Element, Decl(react.d.ts, 1, 20))
interface IntrinsicElements {
>IntrinsicElements : Symbol(IntrinsicElements, Decl(tsxAttributeResolution9.tsx, 1, 22))
>IntrinsicElements : Symbol(IntrinsicElements, Decl(react.d.ts, 2, 22))
}
interface ElementAttributesProperty {
>ElementAttributesProperty : Symbol(ElementAttributesProperty, Decl(tsxAttributeResolution9.tsx, 3, 2))
>ElementAttributesProperty : Symbol(ElementAttributesProperty, Decl(react.d.ts, 4, 2))
props;
>props : Symbol(props, Decl(tsxAttributeResolution9.tsx, 4, 38))
>props : Symbol(props, Decl(react.d.ts, 5, 38))
}
}
interface Props {
>Props : Symbol(Props, Decl(tsxAttributeResolution9.tsx, 7, 1))
>Props : Symbol(Props, Decl(react.d.ts, 8, 1))
foo: string;
>foo : Symbol(foo, Decl(tsxAttributeResolution9.tsx, 9, 17))
>foo : Symbol(foo, Decl(react.d.ts, 10, 17))
}
=== tests/cases/conformance/jsx/file.tsx ===
export class MyComponent {
>MyComponent : Symbol(MyComponent, Decl(tsxAttributeResolution9.tsx, 11, 1))
>MyComponent : Symbol(MyComponent, Decl(file.tsx, 0, 0))
render() {
>render : Symbol(render, Decl(tsxAttributeResolution9.tsx, 13, 26))
>render : Symbol(render, Decl(file.tsx, 0, 26))
}
props: { foo: string; }
>props : Symbol(props, Decl(tsxAttributeResolution9.tsx, 15, 3))
>foo : Symbol(foo, Decl(tsxAttributeResolution9.tsx, 17, 10))
>props : Symbol(props, Decl(file.tsx, 2, 3))
>foo : Symbol(foo, Decl(file.tsx, 4, 10))
}
<MyComponent foo="bar" />; // ok
>MyComponent : Symbol(MyComponent, Decl(tsxAttributeResolution9.tsx, 11, 1))
>MyComponent : Symbol(MyComponent, Decl(file.tsx, 0, 0))
>foo : Symbol(unknown)
<MyComponent foo={0} />; // should be an error
>MyComponent : Symbol(MyComponent, Decl(tsxAttributeResolution9.tsx, 11, 1))
>MyComponent : Symbol(MyComponent, Decl(file.tsx, 0, 0))
>foo : Symbol(unknown)

View file

@ -1,4 +1,5 @@
=== tests/cases/conformance/jsx/tsxAttributeResolution9.tsx ===
=== tests/cases/conformance/jsx/react.d.ts ===
declare module JSX {
>JSX : any
@ -23,6 +24,7 @@ interface Props {
>foo : string
}
=== tests/cases/conformance/jsx/file.tsx ===
export class MyComponent {
>MyComponent : MyComponent
@ -36,12 +38,12 @@ export class MyComponent {
}
<MyComponent foo="bar" />; // ok
><MyComponent foo="bar" /> : any
><MyComponent foo="bar" /> : JSX.Element
>MyComponent : typeof MyComponent
>foo : any
<MyComponent foo={0} />; // should be an error
><MyComponent foo={0} /> : any
><MyComponent foo={0} /> : JSX.Element
>MyComponent : typeof MyComponent
>foo : any