Merge pull request #6290 from RyanCavanaugh/fix5865
Tag 'react' import as used if it exists when targeting --jsx preserve
This commit is contained in:
commit
0debd2b6cd
10 changed files with 137 additions and 9 deletions
|
@ -8363,15 +8363,13 @@ 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");
|
||||
// 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);
|
||||
|
||||
|
|
|
@ -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 />;
|
||||
|
|
10
tests/baselines/reference/tsxPreserveEmit2.js
Normal file
10
tests/baselines/reference/tsxPreserveEmit2.js
Normal file
|
@ -0,0 +1,10 @@
|
|||
//// [test.tsx]
|
||||
|
||||
|
||||
var Route: any;
|
||||
var routes1 = <Route />;
|
||||
|
||||
|
||||
//// [test.jsx]
|
||||
var Route;
|
||||
var routes1 = <Route />;
|
10
tests/baselines/reference/tsxPreserveEmit2.symbols
Normal file
10
tests/baselines/reference/tsxPreserveEmit2.symbols
Normal 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))
|
||||
|
11
tests/baselines/reference/tsxPreserveEmit2.types
Normal file
11
tests/baselines/reference/tsxPreserveEmit2.types
Normal 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
|
||||
|
24
tests/baselines/reference/tsxPreserveEmit3.js
Normal file
24
tests/baselines/reference/tsxPreserveEmit3.js
Normal 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";
|
||||
});
|
25
tests/baselines/reference/tsxPreserveEmit3.symbols
Normal file
25
tests/baselines/reference/tsxPreserveEmit3.symbols
Normal 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))
|
||||
|
25
tests/baselines/reference/tsxPreserveEmit3.types
Normal file
25
tests/baselines/reference/tsxPreserveEmit3.types
Normal 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
|
||||
|
8
tests/cases/conformance/jsx/tsxPreserveEmit2.tsx
Normal file
8
tests/cases/conformance/jsx/tsxPreserveEmit2.tsx
Normal file
|
@ -0,0 +1,8 @@
|
|||
//@module: amd
|
||||
//@jsx: preserve
|
||||
//@target: ES5
|
||||
|
||||
//@Filename: test.tsx
|
||||
|
||||
var Route: any;
|
||||
var routes1 = <Route />;
|
17
tests/cases/conformance/jsx/tsxPreserveEmit3.tsx
Normal file
17
tests/cases/conformance/jsx/tsxPreserveEmit3.tsx
Normal 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";
|
Loading…
Reference in a new issue