-
Notifications
You must be signed in to change notification settings - Fork 12.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix 8549: Using variable as Jsx tagname (#9337)
* Parse JSXElement's name as property access instead of just entity name. So when one accesses property of the class through this, checker will check correctly * wip - just resolve to any type for now * Resolve string type to anytype and look up property in intrinsicElementsType of Jsx * Add tests and update baselines * Remove unneccessary comment * wip-address PR * Address PR * Add tets and update baselines * Fix linting error
- Loading branch information
Showing
40 changed files
with
836 additions
and
24 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
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
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,8 @@ | ||
//// [tsxDynamicTagName1.tsx] | ||
|
||
var CustomTag = "h1"; | ||
<CustomTag> Hello World </CustomTag> // No error | ||
|
||
//// [tsxDynamicTagName1.jsx] | ||
var CustomTag = "h1"; | ||
<CustomTag> Hello World </CustomTag>; // No error |
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,9 @@ | ||
=== tests/cases/conformance/jsx/tsxDynamicTagName1.tsx === | ||
|
||
var CustomTag = "h1"; | ||
>CustomTag : Symbol(CustomTag, Decl(tsxDynamicTagName1.tsx, 1, 3)) | ||
|
||
<CustomTag> Hello World </CustomTag> // No error | ||
>CustomTag : Symbol(CustomTag, Decl(tsxDynamicTagName1.tsx, 1, 3)) | ||
>CustomTag : Symbol(CustomTag, Decl(tsxDynamicTagName1.tsx, 1, 3)) | ||
|
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,11 @@ | ||
=== tests/cases/conformance/jsx/tsxDynamicTagName1.tsx === | ||
|
||
var CustomTag = "h1"; | ||
>CustomTag : string | ||
>"h1" : string | ||
|
||
<CustomTag> Hello World </CustomTag> // No error | ||
><CustomTag> Hello World </CustomTag> : any | ||
>CustomTag : string | ||
>CustomTag : string | ||
|
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 @@ | ||
tests/cases/conformance/jsx/tsxDynamicTagName2.tsx(10,1): error TS2339: Property 'customTag' does not exist on type 'JSX.IntrinsicElements'. | ||
tests/cases/conformance/jsx/tsxDynamicTagName2.tsx(10,25): error TS2339: Property 'customTag' does not exist on type 'JSX.IntrinsicElements'. | ||
|
||
|
||
==== tests/cases/conformance/jsx/tsxDynamicTagName2.tsx (2 errors) ==== | ||
|
||
declare module JSX { | ||
interface Element { } | ||
interface IntrinsicElements { | ||
div: any | ||
} | ||
} | ||
|
||
var customTag = "h1"; | ||
<customTag> Hello World </customTag> // This should be an error. The lower-case is look up as an intrinsic element name | ||
~~~~~~~~~~~ | ||
!!! error TS2339: Property 'customTag' does not exist on type 'JSX.IntrinsicElements'. | ||
~~~~~~~~~~~~ | ||
!!! error TS2339: Property 'customTag' does not exist on type 'JSX.IntrinsicElements'. |
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,15 @@ | ||
//// [tsxDynamicTagName2.tsx] | ||
|
||
declare module JSX { | ||
interface Element { } | ||
interface IntrinsicElements { | ||
div: any | ||
} | ||
} | ||
|
||
var customTag = "h1"; | ||
<customTag> Hello World </customTag> // This should be an error. The lower-case is look up as an intrinsic element name | ||
|
||
//// [tsxDynamicTagName2.jsx] | ||
var customTag = "h1"; | ||
<customTag> Hello World </customTag>; // This should be an error. The lower-case is look up as an intrinsic element name |
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,16 @@ | ||
tests/cases/conformance/jsx/tsxDynamicTagName3.tsx(10,1): error TS2339: Property 'h1' does not exist on type 'JSX.IntrinsicElements'. | ||
|
||
|
||
==== tests/cases/conformance/jsx/tsxDynamicTagName3.tsx (1 errors) ==== | ||
|
||
declare module JSX { | ||
interface Element { } | ||
interface IntrinsicElements { | ||
div: any | ||
} | ||
} | ||
|
||
var CustomTag: "h1" = "h1"; | ||
<CustomTag> Hello World </CustomTag> // This should be an error. we will try look up string literal type in JSX.IntrinsicElements | ||
~~~~~~~~~~~ | ||
!!! error TS2339: Property 'h1' does not exist on type 'JSX.IntrinsicElements'. |
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,15 @@ | ||
//// [tsxDynamicTagName3.tsx] | ||
|
||
declare module JSX { | ||
interface Element { } | ||
interface IntrinsicElements { | ||
div: any | ||
} | ||
} | ||
|
||
var CustomTag: "h1" = "h1"; | ||
<CustomTag> Hello World </CustomTag> // This should be an error. we will try look up string literal type in JSX.IntrinsicElements | ||
|
||
//// [tsxDynamicTagName3.jsx] | ||
var CustomTag = "h1"; | ||
<CustomTag> Hello World </CustomTag>; // This should be an error. we will try look up string literal type in JSX.IntrinsicElements |
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,16 @@ | ||
//// [tsxDynamicTagName4.tsx] | ||
|
||
declare module JSX { | ||
interface Element { } | ||
interface IntrinsicElements { | ||
div: any | ||
h1: any | ||
} | ||
} | ||
|
||
var CustomTag: "h1" = "h1"; | ||
<CustomTag> Hello World </CustomTag> | ||
|
||
//// [tsxDynamicTagName4.jsx] | ||
var CustomTag = "h1"; | ||
<CustomTag> Hello World </CustomTag>; |
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,26 @@ | ||
=== tests/cases/conformance/jsx/tsxDynamicTagName4.tsx === | ||
|
||
declare module JSX { | ||
>JSX : Symbol(JSX, Decl(tsxDynamicTagName4.tsx, 0, 0)) | ||
|
||
interface Element { } | ||
>Element : Symbol(Element, Decl(tsxDynamicTagName4.tsx, 1, 20)) | ||
|
||
interface IntrinsicElements { | ||
>IntrinsicElements : Symbol(IntrinsicElements, Decl(tsxDynamicTagName4.tsx, 2, 22)) | ||
|
||
div: any | ||
>div : Symbol(IntrinsicElements.div, Decl(tsxDynamicTagName4.tsx, 3, 30)) | ||
|
||
h1: any | ||
>h1 : Symbol(IntrinsicElements.h1, Decl(tsxDynamicTagName4.tsx, 4, 10)) | ||
} | ||
} | ||
|
||
var CustomTag: "h1" = "h1"; | ||
>CustomTag : Symbol(CustomTag, Decl(tsxDynamicTagName4.tsx, 9, 3)) | ||
|
||
<CustomTag> Hello World </CustomTag> | ||
>CustomTag : Symbol(CustomTag, Decl(tsxDynamicTagName4.tsx, 9, 3)) | ||
>CustomTag : Symbol(CustomTag, Decl(tsxDynamicTagName4.tsx, 9, 3)) | ||
|
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,28 @@ | ||
=== tests/cases/conformance/jsx/tsxDynamicTagName4.tsx === | ||
|
||
declare module JSX { | ||
>JSX : any | ||
|
||
interface Element { } | ||
>Element : Element | ||
|
||
interface IntrinsicElements { | ||
>IntrinsicElements : IntrinsicElements | ||
|
||
div: any | ||
>div : any | ||
|
||
h1: any | ||
>h1 : any | ||
} | ||
} | ||
|
||
var CustomTag: "h1" = "h1"; | ||
>CustomTag : "h1" | ||
>"h1" : "h1" | ||
|
||
<CustomTag> Hello World </CustomTag> | ||
><CustomTag> Hello World </CustomTag> : JSX.Element | ||
>CustomTag : "h1" | ||
>CustomTag : "h1" | ||
|
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,41 @@ | ||
//// [tests/cases/conformance/jsx/tsxDynamicTagName5.tsx] //// | ||
|
||
//// [react.d.ts] | ||
|
||
declare module 'react' { | ||
class Component<T, U> { } | ||
} | ||
|
||
//// [app.tsx] | ||
import * as React from 'react'; | ||
|
||
export class Text extends React.Component<{}, {}> { | ||
_tagName: string = 'div'; | ||
|
||
render() { | ||
return ( | ||
<this._tagName /> | ||
); | ||
} | ||
} | ||
|
||
//// [app.jsx] | ||
"use strict"; | ||
var __extends = (this && this.__extends) || function (d, b) { | ||
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
var React = require('react'); | ||
var Text = (function (_super) { | ||
__extends(Text, _super); | ||
function Text() { | ||
_super.apply(this, arguments); | ||
this._tagName = 'div'; | ||
} | ||
Text.prototype.render = function () { | ||
return (<this._tagName />); | ||
}; | ||
return Text; | ||
}(React.Component)); | ||
exports.Text = Text; |
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,34 @@ | ||
=== tests/cases/conformance/jsx/react.d.ts === | ||
|
||
declare module 'react' { | ||
class Component<T, U> { } | ||
>Component : Symbol(Component, Decl(react.d.ts, 1, 24)) | ||
>T : Symbol(T, Decl(react.d.ts, 2, 17)) | ||
>U : Symbol(U, Decl(react.d.ts, 2, 19)) | ||
} | ||
|
||
=== tests/cases/conformance/jsx/app.tsx === | ||
import * as React from 'react'; | ||
>React : Symbol(React, Decl(app.tsx, 0, 6)) | ||
|
||
export class Text extends React.Component<{}, {}> { | ||
>Text : Symbol(Text, Decl(app.tsx, 0, 31)) | ||
>React.Component : Symbol(React.Component, Decl(react.d.ts, 1, 24)) | ||
>React : Symbol(React, Decl(app.tsx, 0, 6)) | ||
>Component : Symbol(React.Component, Decl(react.d.ts, 1, 24)) | ||
|
||
_tagName: string = 'div'; | ||
>_tagName : Symbol(Text._tagName, Decl(app.tsx, 2, 51)) | ||
|
||
render() { | ||
>render : Symbol(Text.render, Decl(app.tsx, 3, 27)) | ||
|
||
return ( | ||
<this._tagName /> | ||
>this._tagName : Symbol(Text._tagName, Decl(app.tsx, 2, 51)) | ||
>this : Symbol(Text, Decl(app.tsx, 0, 31)) | ||
>_tagName : Symbol(Text._tagName, Decl(app.tsx, 2, 51)) | ||
|
||
); | ||
} | ||
} |
Oops, something went wrong.