Merge pull request #6290 from RyanCavanaugh/fix5865

Tag 'react' import as used if it exists when targeting --jsx preserve
This commit is contained in:
Ryan Cavanaugh 2016-01-04 07:47:01 -08:00
commit 0debd2b6cd
10 changed files with 137 additions and 9 deletions

View file

@ -8363,14 +8363,12 @@ namespace ts {
checkGrammarJsxElement(node);
checkJsxPreconditions(node);
// If we're compiling under --jsx react, the symbol 'React' should
// be marked as 'used' so we don't incorrectly elide its import. And if there
// is no 'React' symbol in scope, we should issue an error.
if (compilerOptions.jsx === JsxEmit.React) {
const reactSym = resolveName(node.tagName, "React", SymbolFlags.Value, Diagnostics.Cannot_find_name_0, "React");
if (reactSym) {
getSymbolLinks(reactSym).referenced = true;
}
// The symbol 'React' should be marked as 'used' so we don't incorrectly elide its import. And if there
// is no 'React' symbol in scope when targeting React emit, we should issue an error.
const reactRefErr = compilerOptions.jsx === JsxEmit.React ? Diagnostics.Cannot_find_name_0 : undefined;
const reactSym = resolveName(node.tagName, "React", SymbolFlags.Value, reactRefErr, "React");
if (reactSym) {
getSymbolLinks(reactSym).referenced = true;
}
const targetAttributesType = getJsxElementAttributesType(node);

View file

@ -34,7 +34,7 @@ module M {
//// [test.jsx]
define(["require", "exports", 'react-router'], function (require, exports, ReactRouter) {
define(["require", "exports", 'react', 'react-router'], function (require, exports, React, ReactRouter) {
"use strict";
var Route = ReactRouter.Route;
var routes1 = <Route />;

View file

@ -0,0 +1,10 @@
//// [test.tsx]
var Route: any;
var routes1 = <Route />;
//// [test.jsx]
var Route;
var routes1 = <Route />;

View file

@ -0,0 +1,10 @@
=== tests/cases/conformance/jsx/test.tsx ===
var Route: any;
>Route : Symbol(Route, Decl(test.tsx, 2, 3))
var routes1 = <Route />;
>routes1 : Symbol(routes1, Decl(test.tsx, 3, 3))
>Route : Symbol(Route, Decl(test.tsx, 2, 3))

View file

@ -0,0 +1,11 @@
=== tests/cases/conformance/jsx/test.tsx ===
var Route: any;
>Route : any
var routes1 = <Route />;
>routes1 : any
><Route /> : any
>Route : any

View file

@ -0,0 +1,24 @@
//// [tests/cases/conformance/jsx/tsxPreserveEmit3.tsx] ////
//// [file.tsx]
declare module JSX {
interface Element { }
interface IntrinsicElements {
[s: string]: any;
}
}
//// [test.d.ts]
export var React;
//// [react-consumer.tsx]
// This import should be elided
import {React} from "./test";
//// [file.jsx]
//// [react-consumer.jsx]
define(["require", "exports"], function (require, exports) {
"use strict";
});

View file

@ -0,0 +1,25 @@
=== tests/cases/conformance/jsx/file.tsx ===
declare module JSX {
>JSX : Symbol(JSX, Decl(file.tsx, 0, 0))
interface Element { }
>Element : Symbol(Element, Decl(file.tsx, 1, 20))
interface IntrinsicElements {
>IntrinsicElements : Symbol(IntrinsicElements, Decl(file.tsx, 2, 22))
[s: string]: any;
>s : Symbol(s, Decl(file.tsx, 4, 3))
}
}
=== tests/cases/conformance/jsx/test.d.ts ===
export var React;
>React : Symbol(React, Decl(test.d.ts, 0, 10))
=== tests/cases/conformance/jsx/react-consumer.tsx ===
// This import should be elided
import {React} from "./test";
>React : Symbol(React, Decl(react-consumer.tsx, 1, 8))

View file

@ -0,0 +1,25 @@
=== tests/cases/conformance/jsx/file.tsx ===
declare module JSX {
>JSX : any
interface Element { }
>Element : Element
interface IntrinsicElements {
>IntrinsicElements : IntrinsicElements
[s: string]: any;
>s : string
}
}
=== tests/cases/conformance/jsx/test.d.ts ===
export var React;
>React : any
=== tests/cases/conformance/jsx/react-consumer.tsx ===
// This import should be elided
import {React} from "./test";
>React : any

View file

@ -0,0 +1,8 @@
//@module: amd
//@jsx: preserve
//@target: ES5
//@Filename: test.tsx
var Route: any;
var routes1 = <Route />;

View file

@ -0,0 +1,17 @@
//@jsx: preserve
//@module: amd
//@filename: file.tsx
declare module JSX {
interface Element { }
interface IntrinsicElements {
[s: string]: any;
}
}
//@filename: test.d.ts
export var React;
//@filename: react-consumer.tsx
// This import should be elided
import {React} from "./test";