diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 669a7f202e6..c6c3552cb4a 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -7088,7 +7088,7 @@ namespace ts { let jsxElementClassType: Type = undefined; function getJsxGlobalElementClassType(): Type { - if(!jsxElementClassType) { + if (!jsxElementClassType) { jsxElementClassType = getExportedTypeFromNamespace(JsxNames.JSX, JsxNames.ElementClass); } return jsxElementClassType; @@ -7107,7 +7107,7 @@ namespace ts { } if (jsxElementType === undefined) { - if(compilerOptions.noImplicitAny) { + if (compilerOptions.noImplicitAny) { error(errorNode, Diagnostics.JSX_element_implicitly_has_type_any_because_the_global_type_JSX_Element_does_not_exist); } } @@ -7119,6 +7119,15 @@ namespace ts { let targetAttributesType = getJsxElementAttributesType(node); + if (getNodeLinks(node).jsxFlags & JsxFlags.ClassElement) { + if (node.tagName.kind === SyntaxKind.Identifier) { + checkIdentifier(node.tagName); + } + else { + checkQualifiedName(node.tagName); + } + } + let nameTable: Map = {}; // Process this array in right-to-left order so we know which // attributes (mostly from spreads) are being overwritten and @@ -7131,7 +7140,7 @@ namespace ts { else { Debug.assert(node.attributes[i].kind === SyntaxKind.JsxSpreadAttribute); let spreadType = checkJsxSpreadAttribute((node.attributes[i]), targetAttributesType, nameTable); - if(isTypeAny(spreadType)) { + if (isTypeAny(spreadType)) { sawSpreadedAny = true; } } @@ -12336,7 +12345,7 @@ namespace ts { } function checkTypePredicate(node: TypePredicateNode) { - if(!isInLegalTypePredicatePosition(node)) { + if (!isInLegalTypePredicatePosition(node)) { error(node, Diagnostics.A_type_predicate_is_only_allowed_in_return_type_position_for_functions_and_methods); } } diff --git a/tests/baselines/reference/jsxEsprimaFbTestSuite.symbols b/tests/baselines/reference/jsxEsprimaFbTestSuite.symbols deleted file mode 100644 index 570bf89f0a4..00000000000 --- a/tests/baselines/reference/jsxEsprimaFbTestSuite.symbols +++ /dev/null @@ -1,92 +0,0 @@ -=== tests/cases/conformance/jsx/jsxEsprimaFbTestSuite.tsx === -declare var React: any; ->React : Symbol(React, Decl(jsxEsprimaFbTestSuite.tsx, 0, 11)) - -declare var 日本語; ->日本語 : Symbol(日本語, Decl(jsxEsprimaFbTestSuite.tsx, 1, 11)) - -declare var AbC_def; ->AbC_def : Symbol(AbC_def, Decl(jsxEsprimaFbTestSuite.tsx, 2, 11)) - -declare var LeftRight; ->LeftRight : Symbol(LeftRight, Decl(jsxEsprimaFbTestSuite.tsx, 3, 11)) - -declare var x; ->x : Symbol(x, Decl(jsxEsprimaFbTestSuite.tsx, 4, 11)) - -declare var a; ->a : Symbol(a, Decl(jsxEsprimaFbTestSuite.tsx, 5, 11)) - -declare var props; ->props : Symbol(props, Decl(jsxEsprimaFbTestSuite.tsx, 6, 11)) - -; - -//; Namespace unsuported - -// {value} ; Namespace unsuported - -; ->b : Symbol(unknown) ->c : Symbol(unknown) ->d : Symbol(unknown) ->e : Symbol(unknown) ->f : Symbol(unknown) ->g : Symbol(unknown) ->h : Symbol(unknown) - -; ->b : Symbol(unknown) - -; - -<日本語>; - -AbC_def : Symbol(AbC_def, Decl(jsxEsprimaFbTestSuite.tsx, 2, 11)) - - test="&&"> ->test : Symbol(unknown) - -bar -baz -; - - : } />; ->b : Symbol(unknown) ->x : Symbol(x, Decl(jsxEsprimaFbTestSuite.tsx, 4, 11)) - -{}; - -{/* this is a comment */}; - -
@test content
; - -

7x invalid-js-identifier
; - - right=monkeys /> gorillas />; ->LeftRight : Symbol(LeftRight, Decl(jsxEsprimaFbTestSuite.tsx, 3, 11)) ->left : Symbol(unknown) ->right : Symbol(unknown) - -; ->b : Symbol(unknown) - -; ->c : Symbol(unknown) - -(
) < x; ->x : Symbol(x, Decl(jsxEsprimaFbTestSuite.tsx, 4, 11)) - -
; - -
; ->post : Symbol(unknown) - -
; ->pre : Symbol(unknown) ->pre2 : Symbol(unknown) - - ; - diff --git a/tests/baselines/reference/jsxEsprimaFbTestSuite.types b/tests/baselines/reference/jsxEsprimaFbTestSuite.types deleted file mode 100644 index f32d62fd03f..00000000000 --- a/tests/baselines/reference/jsxEsprimaFbTestSuite.types +++ /dev/null @@ -1,160 +0,0 @@ -=== tests/cases/conformance/jsx/jsxEsprimaFbTestSuite.tsx === -declare var React: any; ->React : any - -declare var 日本語; ->日本語 : any - -declare var AbC_def; ->AbC_def : any - -declare var LeftRight; ->LeftRight : any - -declare var x; ->x : any - -declare var a; ->a : any - -declare var props; ->props : any - -; -> : any ->a : any - -//; Namespace unsuported - -// {value} ; Namespace unsuported - -; -> : any ->a : any ->b : any ->c : any ->d : any ->e : any ->f : any ->g : any ->h : any - -; -> : any ->a : any ->b : any - - : any ->a : any - -/>; - -<日本語>; -><日本語> : any ->日本語 : any ->日本語 : any - -barbaz : any ->AbC_def : any - - test="&&"> ->test : any - -bar -baz -; ->AbC_def : any - - : } />; -> : } /> : any ->a : any ->b : any ->x ? : : any ->x : any -> : any ->c : any -> : any ->d : any - -{}; ->{} : any ->a : any ->a : any - -{/* this is a comment */}; ->{/* this is a comment */} : any ->a : any ->a : any - -
@test content
; ->
@test content
: any ->div : any ->div : any - -

7x invalid-js-identifier
; ->

7x invalid-js-identifier
: any ->div : any ->
: any ->br : any ->div : any - - right=monkeys /> gorillas />; -> right=monkeys /> gorillas /> : any ->LeftRight : any ->left : any -> : any ->a : any ->right : any ->monkeys /> gorillas : any ->b : any ->b : any - -; -> : any ->a : any ->b : any ->a : any ->b : any - -; -> : any ->a : any ->b : any ->c : any ->a : any ->b : any ->c : any - -(
) < x; ->(
) < x : boolean ->(
) : any ->
: any ->div : any ->x : any - -
; ->
: any ->div : any ->props : any - -
; ->
: any ->div : any ->props : any ->post : any - -
; ->
: any ->div : any ->pre : any ->pre2 : any ->props : any ->div : any - - ; ->
: any ->a : any ->a : any - diff --git a/tests/baselines/reference/tsxElementResolution16.symbols b/tests/baselines/reference/tsxElementResolution16.symbols deleted file mode 100644 index e01f19b991f..00000000000 --- a/tests/baselines/reference/tsxElementResolution16.symbols +++ /dev/null @@ -1,18 +0,0 @@ -=== tests/cases/conformance/jsx/tsxElementResolution16.tsx === -declare module JSX { ->JSX : Symbol(JSX, Decl(tsxElementResolution16.tsx, 0, 0)) -} - -interface Obj1 { ->Obj1 : Symbol(Obj1, Decl(tsxElementResolution16.tsx, 1, 1)) - - new(n: string): {}; ->n : Symbol(n, Decl(tsxElementResolution16.tsx, 4, 5)) -} -var obj1: Obj1; ->obj1 : Symbol(obj1, Decl(tsxElementResolution16.tsx, 6, 3)) ->Obj1 : Symbol(Obj1, Decl(tsxElementResolution16.tsx, 1, 1)) - -; // Error (JSX.Element is missing) ->x : Symbol(unknown) - diff --git a/tests/baselines/reference/tsxElementResolution16.types b/tests/baselines/reference/tsxElementResolution16.types deleted file mode 100644 index 3b8604e737d..00000000000 --- a/tests/baselines/reference/tsxElementResolution16.types +++ /dev/null @@ -1,20 +0,0 @@ -=== tests/cases/conformance/jsx/tsxElementResolution16.tsx === -declare module JSX { ->JSX : any -} - -interface Obj1 { ->Obj1 : Obj1 - - new(n: string): {}; ->n : string -} -var obj1: Obj1; ->obj1 : Obj1 ->Obj1 : Obj1 - -; // Error (JSX.Element is missing) -> : any ->obj1 : Obj1 ->x : any - diff --git a/tests/baselines/reference/tsxExternalModuleEmit1.js b/tests/baselines/reference/tsxExternalModuleEmit1.js new file mode 100644 index 00000000000..3e486eacef8 --- /dev/null +++ b/tests/baselines/reference/tsxExternalModuleEmit1.js @@ -0,0 +1,71 @@ +//// [tests/cases/conformance/jsx/tsxExternalModuleEmit1.tsx] //// + +//// [react.d.ts] + +declare module 'react' { + class Component { } +} + +//// [app.tsx] +import * as React from 'react'; + +// Should see var button_1 = require('./button') here +import { Button } from './button'; + +export class App extends React.Component { + + render() { + return ; + } + +} + +//// [button.jsx] +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 Button = (function (_super) { + __extends(Button, _super); + function Button() { + _super.apply(this, arguments); + } + Button.prototype.render = function () { + return ; + }; + return Button; +})(React.Component); +exports.Button = Button; +//// [app.jsx] +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'); +// Should see var button_1 = require('./button') here +var button_1 = require('./button'); +var App = (function (_super) { + __extends(App, _super); + function App() { + _super.apply(this, arguments); + } + App.prototype.render = function () { + return ; + }; + return App; +})(React.Component); +exports.App = App; diff --git a/tests/baselines/reference/tsxExternalModuleEmit1.symbols b/tests/baselines/reference/tsxExternalModuleEmit1.symbols new file mode 100644 index 00000000000..5e8eb2fed4e --- /dev/null +++ b/tests/baselines/reference/tsxExternalModuleEmit1.symbols @@ -0,0 +1,49 @@ +=== tests/cases/conformance/jsx/react.d.ts === + +declare module 'react' { + class Component { } +>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)) + +// Should see var button_1 = require('./button') here +import { Button } from './button'; +>Button : Symbol(Button, Decl(app.tsx, 3, 8)) + +export class App extends React.Component { +>App : Symbol(App, Decl(app.tsx, 3, 34)) +>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)) + + render() { +>render : Symbol(render, Decl(app.tsx, 5, 52)) + + return ; + } + +} diff --git a/tests/baselines/reference/tsxExternalModuleEmit1.types b/tests/baselines/reference/tsxExternalModuleEmit1.types new file mode 100644 index 00000000000..7e28c35dd13 --- /dev/null +++ b/tests/baselines/reference/tsxExternalModuleEmit1.types @@ -0,0 +1,53 @@ +=== tests/cases/conformance/jsx/react.d.ts === + +declare module 'react' { + class Component { } +>Component : Component +>T : T +>U : U +} + +=== tests/cases/conformance/jsx/app.tsx === +import * as React from 'react'; +>React : typeof React + +// Should see var button_1 = require('./button') here +import { Button } from './button'; +>Button : typeof Button + +export class App extends React.Component { +>App : App +>React.Component : React.Component +>React : typeof React +>Component : typeof React.Component + + render() { +>render : () => any + + return ; +> : any +>button : any +>button : any + } + +} diff --git a/tests/cases/conformance/jsx/tsxExternalModuleEmit1.tsx b/tests/cases/conformance/jsx/tsxExternalModuleEmit1.tsx new file mode 100644 index 00000000000..bb7f5c3f361 --- /dev/null +++ b/tests/cases/conformance/jsx/tsxExternalModuleEmit1.tsx @@ -0,0 +1,32 @@ +//@jsx: preserve +//@module: commonjs + +//@filename: react.d.ts +declare module 'react' { + class Component { } +} + +//@filename: app.tsx +import * as React from 'react'; + +// Should see var button_1 = require('./button') here +import { Button } from './button'; + +export class App extends React.Component { + + render() { + return ; + } + +} \ No newline at end of file