Use synthetic identifier during emit instead

This commit is contained in:
Ryan Cavanaugh
2015-08-26 16:12:50 -07:00
parent 6b5a14a353
commit 0e4fdf8373
6 changed files with 145 additions and 17 deletions

View File

@@ -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;
}
}

View File

@@ -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;