mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-05 08:11:30 -06:00
Use synthetic identifier during emit instead
This commit is contained in:
parent
6b5a14a353
commit
0e4fdf8373
@ -7629,12 +7629,8 @@ namespace ts {
|
||||
// is no 'React' symbol in scope, we should issue an error.
|
||||
if (compilerOptions.jsx === JsxEmit.React) {
|
||||
let reactSym = resolveName(node.tagName, "React", SymbolFlags.Value, Diagnostics.Cannot_find_name_0, "React");
|
||||
if (reactSym && reactSym !== unknownSymbol) {
|
||||
if (reactSym) {
|
||||
getSymbolLinks(reactSym).referenced = true;
|
||||
let reactNode = <Identifier>createSynthesizedNode(SyntaxKind.Identifier, false);
|
||||
reactNode.text = 'React';
|
||||
getNodeLinks(reactNode).resolvedSymbol = reactSym;
|
||||
node.reactNode = reactNode;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1177,14 +1177,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
|
||||
}
|
||||
|
||||
function emitJsxElement(openingNode: JsxOpeningLikeElement, children?: JsxChild[]) {
|
||||
let syntheticReactRef = <Identifier>createSynthesizedNode(SyntaxKind.Identifier);
|
||||
syntheticReactRef.text = 'React';
|
||||
syntheticReactRef.parent = openingNode;
|
||||
|
||||
// Call React.createElement(tag, ...
|
||||
emitLeadingComments(openingNode);
|
||||
if (openingNode.reactNode) {
|
||||
emitExpressionIdentifier(openingNode.reactNode);
|
||||
}
|
||||
else {
|
||||
write('React');
|
||||
}
|
||||
emitExpressionIdentifier(syntheticReactRef);
|
||||
write(".createElement(");
|
||||
emitTagName(openingNode.tagName);
|
||||
write(", ");
|
||||
@ -1199,12 +1198,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
|
||||
// a call to React.__spread
|
||||
let attrs = openingNode.attributes;
|
||||
if (forEach(attrs, attr => attr.kind === SyntaxKind.JsxSpreadAttribute)) {
|
||||
if (openingNode.reactNode) {
|
||||
emitExpressionIdentifier(openingNode.reactNode);
|
||||
}
|
||||
else {
|
||||
write('React');
|
||||
}
|
||||
emitExpressionIdentifier(syntheticReactRef);
|
||||
write(".__spread(");
|
||||
|
||||
let haveOpenedObjectLiteral = false;
|
||||
|
||||
36
tests/baselines/reference/tsxReactEmit6.js
Normal file
36
tests/baselines/reference/tsxReactEmit6.js
Normal file
@ -0,0 +1,36 @@
|
||||
//// [tests/cases/conformance/jsx/tsxReactEmit6.tsx] ////
|
||||
|
||||
//// [file.tsx]
|
||||
|
||||
declare module JSX {
|
||||
interface Element { }
|
||||
interface IntrinsicElements {
|
||||
[s: string]: any;
|
||||
}
|
||||
}
|
||||
|
||||
//// [react-consumer.tsx]
|
||||
namespace M {
|
||||
export var React: any;
|
||||
}
|
||||
|
||||
namespace M {
|
||||
// Should emit M.React.createElement
|
||||
// and M.React.__spread
|
||||
var foo;
|
||||
var spread1 = <div x='' {...foo} y='' />;
|
||||
}
|
||||
|
||||
|
||||
//// [file.js]
|
||||
//// [react-consumer.js]
|
||||
var M;
|
||||
(function (M) {
|
||||
})(M || (M = {}));
|
||||
var M;
|
||||
(function (M) {
|
||||
// Should emit M.React.createElement
|
||||
// and M.React.__spread
|
||||
var foo;
|
||||
var spread1 = M.React.createElement("div", M.React.__spread({x: ''}, foo, {y: ''}));
|
||||
})(M || (M = {}));
|
||||
39
tests/baselines/reference/tsxReactEmit6.symbols
Normal file
39
tests/baselines/reference/tsxReactEmit6.symbols
Normal file
@ -0,0 +1,39 @@
|
||||
=== 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/react-consumer.tsx ===
|
||||
namespace M {
|
||||
>M : Symbol(M, Decl(react-consumer.tsx, 0, 0), Decl(react-consumer.tsx, 2, 1))
|
||||
|
||||
export var React: any;
|
||||
>React : Symbol(React, Decl(react-consumer.tsx, 1, 11))
|
||||
}
|
||||
|
||||
namespace M {
|
||||
>M : Symbol(M, Decl(react-consumer.tsx, 0, 0), Decl(react-consumer.tsx, 2, 1))
|
||||
|
||||
// Should emit M.React.createElement
|
||||
// and M.React.__spread
|
||||
var foo;
|
||||
>foo : Symbol(foo, Decl(react-consumer.tsx, 7, 4))
|
||||
|
||||
var spread1 = <div x='' {...foo} y='' />;
|
||||
>spread1 : Symbol(spread1, Decl(react-consumer.tsx, 8, 4))
|
||||
>div : Symbol(JSX.IntrinsicElements, Decl(file.tsx, 2, 22))
|
||||
>x : Symbol(unknown)
|
||||
>y : Symbol(unknown)
|
||||
}
|
||||
|
||||
41
tests/baselines/reference/tsxReactEmit6.types
Normal file
41
tests/baselines/reference/tsxReactEmit6.types
Normal file
@ -0,0 +1,41 @@
|
||||
=== 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/react-consumer.tsx ===
|
||||
namespace M {
|
||||
>M : typeof M
|
||||
|
||||
export var React: any;
|
||||
>React : any
|
||||
}
|
||||
|
||||
namespace M {
|
||||
>M : typeof M
|
||||
|
||||
// Should emit M.React.createElement
|
||||
// and M.React.__spread
|
||||
var foo;
|
||||
>foo : any
|
||||
|
||||
var spread1 = <div x='' {...foo} y='' />;
|
||||
>spread1 : JSX.Element
|
||||
><div x='' {...foo} y='' /> : JSX.Element
|
||||
>div : any
|
||||
>x : any
|
||||
>foo : any
|
||||
>y : any
|
||||
}
|
||||
|
||||
22
tests/cases/conformance/jsx/tsxReactEmit6.tsx
Normal file
22
tests/cases/conformance/jsx/tsxReactEmit6.tsx
Normal file
@ -0,0 +1,22 @@
|
||||
//@jsx: react
|
||||
//@module: commonjs
|
||||
|
||||
//@filename: file.tsx
|
||||
declare module JSX {
|
||||
interface Element { }
|
||||
interface IntrinsicElements {
|
||||
[s: string]: any;
|
||||
}
|
||||
}
|
||||
|
||||
//@filename: react-consumer.tsx
|
||||
namespace M {
|
||||
export var React: any;
|
||||
}
|
||||
|
||||
namespace M {
|
||||
// Should emit M.React.createElement
|
||||
// and M.React.__spread
|
||||
var foo;
|
||||
var spread1 = <div x='' {...foo} y='' />;
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user