mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-15 20:25:23 -06:00
Update emitter to use JSXAttributes node instead of JSXAttribute node array
# Conflicts: # src/compiler/visitor.ts
This commit is contained in:
parent
46716855d6
commit
41108dbaae
@ -538,6 +538,8 @@ namespace ts {
|
||||
return emitJsxClosingElement(<JsxClosingElement>node);
|
||||
case SyntaxKind.JsxAttribute:
|
||||
return emitJsxAttribute(<JsxAttribute>node);
|
||||
case SyntaxKind.JsxAttributes:
|
||||
return emitJsxAttributes(<JsxAttributes>node);
|
||||
case SyntaxKind.JsxSpreadAttribute:
|
||||
return emitJsxSpreadAttribute(<JsxSpreadAttribute>node);
|
||||
case SyntaxKind.JsxExpression:
|
||||
@ -1824,15 +1826,21 @@ namespace ts {
|
||||
write("<");
|
||||
emitJsxTagName(node.tagName);
|
||||
write(" ");
|
||||
emitList(node, node.attributes, ListFormat.JsxElementAttributes);
|
||||
// We are checking here so we won't re-enter the emiting pipeline and emit extra sourcemap
|
||||
if (node.attributes.properties && node.attributes.properties.length > 0) {
|
||||
emit(node.attributes);
|
||||
}
|
||||
write("/>");
|
||||
}
|
||||
|
||||
function emitJsxOpeningElement(node: JsxOpeningElement) {
|
||||
write("<");
|
||||
emitJsxTagName(node.tagName);
|
||||
writeIfAny(node.attributes, " ");
|
||||
emitList(node, node.attributes, ListFormat.JsxElementAttributes);
|
||||
writeIfAny(node.attributes.properties, " ");
|
||||
// We are checking here so we won't re-enter the emiting pipeline and emit extra sourcemap
|
||||
if (node.attributes.properties && node.attributes.properties.length > 0) {
|
||||
emit(node.attributes);
|
||||
}
|
||||
write(">");
|
||||
}
|
||||
|
||||
@ -1846,6 +1854,10 @@ namespace ts {
|
||||
write(">");
|
||||
}
|
||||
|
||||
function emitJsxAttributes(node: JsxAttributes) {
|
||||
emitList(node, node.properties, ListFormat.JsxElementAttributes);
|
||||
}
|
||||
|
||||
function emitJsxAttribute(node: JsxAttribute) {
|
||||
emit(node.name);
|
||||
emitWithPrefix("=", node.initializer);
|
||||
|
||||
@ -1249,28 +1249,28 @@ namespace ts {
|
||||
return node;
|
||||
}
|
||||
|
||||
export function createJsxSelfClosingElement(tagName: JsxTagNameExpression, attributes: JsxAttributeLike[], location?: TextRange) {
|
||||
export function createJsxSelfClosingElement(tagName: JsxTagNameExpression, attributes: JsxAttributes, location?: TextRange) {
|
||||
const node = <JsxSelfClosingElement>createNode(SyntaxKind.JsxSelfClosingElement, location);
|
||||
node.tagName = tagName;
|
||||
node.attributes = createNodeArray(attributes);
|
||||
node.attributes = attributes;
|
||||
return node;
|
||||
}
|
||||
|
||||
export function updateJsxSelfClosingElement(node: JsxSelfClosingElement, tagName: JsxTagNameExpression, attributes: JsxAttributeLike[]) {
|
||||
export function updateJsxSelfClosingElement(node: JsxSelfClosingElement, tagName: JsxTagNameExpression, attributes: JsxAttributes) {
|
||||
if (node.tagName !== tagName || node.attributes !== attributes) {
|
||||
return updateNode(createJsxSelfClosingElement(tagName, attributes, node), node);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
export function createJsxOpeningElement(tagName: JsxTagNameExpression, attributes: JsxAttributeLike[], location?: TextRange) {
|
||||
export function createJsxOpeningElement(tagName: JsxTagNameExpression, attributes: JsxAttributes, location?: TextRange) {
|
||||
const node = <JsxOpeningElement>createNode(SyntaxKind.JsxOpeningElement, location);
|
||||
node.tagName = tagName;
|
||||
node.attributes = createNodeArray(attributes);
|
||||
node.attributes = attributes;
|
||||
return node;
|
||||
}
|
||||
|
||||
export function updateJsxOpeningElement(node: JsxOpeningElement, tagName: JsxTagNameExpression, attributes: JsxAttributeLike[]) {
|
||||
export function updateJsxOpeningElement(node: JsxOpeningElement, tagName: JsxTagNameExpression, attributes: JsxAttributes) {
|
||||
if (node.tagName !== tagName || node.attributes !== attributes) {
|
||||
return updateNode(createJsxOpeningElement(tagName, attributes, node), node);
|
||||
}
|
||||
@ -1290,6 +1290,20 @@ namespace ts {
|
||||
return node;
|
||||
}
|
||||
|
||||
export function createJsxAttributes(properties: JsxAttributeLike[], location?: TextRange) {
|
||||
const jsxAttributes = <JsxAttributes>createNode(SyntaxKind.JsxAttributes, location);
|
||||
setEmitFlags(jsxAttributes, EmitFlags.NoSourceMap);
|
||||
jsxAttributes.properties = createNodeArray(properties);
|
||||
return jsxAttributes;
|
||||
}
|
||||
|
||||
export function updateJsxAttributes(jsxAttributes: JsxAttributes, properties: JsxAttributeLike[]) {
|
||||
if (jsxAttributes.properties !== properties) {
|
||||
return updateNode(createJsxAttributes(properties, jsxAttributes), jsxAttributes);
|
||||
}
|
||||
return jsxAttributes;
|
||||
}
|
||||
|
||||
export function createJsxAttribute(name: Identifier, initializer: StringLiteral | JsxExpression, location?: TextRange) {
|
||||
const node = <JsxAttribute>createNode(SyntaxKind.JsxAttribute, location);
|
||||
node.name = name;
|
||||
|
||||
@ -85,7 +85,7 @@ namespace ts {
|
||||
function visitJsxOpeningLikeElement(node: JsxOpeningLikeElement, children: JsxChild[], isChild: boolean, location: TextRange) {
|
||||
const tagName = getTagName(node);
|
||||
let objectProperties: Expression;
|
||||
const attrs = node.attributes;
|
||||
const attrs = node.attributes.properties;
|
||||
if (attrs.length === 0) {
|
||||
// When there are no attributes, React wants "null"
|
||||
objectProperties = createNull();
|
||||
|
||||
@ -469,13 +469,17 @@ namespace ts {
|
||||
case SyntaxKind.JsxSelfClosingElement:
|
||||
case SyntaxKind.JsxOpeningElement:
|
||||
result = reduceNode((<JsxSelfClosingElement | JsxOpeningElement>node).tagName, cbNode, result);
|
||||
result = reduceNodes((<JsxSelfClosingElement | JsxOpeningElement>node).attributes, cbNodes, result);
|
||||
result = reduceNode((<JsxSelfClosingElement | JsxOpeningElement>node).attributes, cbNode, result);
|
||||
break;
|
||||
|
||||
case SyntaxKind.JsxClosingElement:
|
||||
result = reduceNode((<JsxClosingElement>node).tagName, cbNode, result);
|
||||
break;
|
||||
|
||||
case SyntaxKind.JsxAttributes:
|
||||
result = reduceNodes((<JsxAttributes>node).properties, cbNodes, result);
|
||||
break;
|
||||
|
||||
case SyntaxKind.JsxAttribute:
|
||||
result = reduceNode((<JsxAttribute>node).name, cbNode, result);
|
||||
result = reduceNode((<JsxAttribute>node).initializer, cbNode, result);
|
||||
@ -1117,15 +1121,19 @@ namespace ts {
|
||||
visitNodes((<JsxElement>node).children, visitor, isJsxChild),
|
||||
visitNode((<JsxElement>node).closingElement, visitor, isJsxClosingElement));
|
||||
|
||||
case SyntaxKind.JsxAttributes:
|
||||
return updateJsxAttributes(<JsxAttributes>node,
|
||||
visitNodes((<JsxAttributes>node).properties, visitor, isJsxAttributeLike));
|
||||
|
||||
case SyntaxKind.JsxSelfClosingElement:
|
||||
return updateJsxSelfClosingElement(<JsxSelfClosingElement>node,
|
||||
visitNode((<JsxSelfClosingElement>node).tagName, visitor, isJsxTagNameExpression),
|
||||
visitNodes((<JsxSelfClosingElement>node).attributes, visitor, isJsxAttributeLike));
|
||||
visitNode((<JsxSelfClosingElement>node).attributes, visitor, isJsxAttributes));
|
||||
|
||||
case SyntaxKind.JsxOpeningElement:
|
||||
return updateJsxOpeningElement(<JsxOpeningElement>node,
|
||||
visitNode((<JsxOpeningElement>node).tagName, visitor, isJsxTagNameExpression),
|
||||
visitNodes((<JsxOpeningElement>node).attributes, visitor, isJsxAttributeLike));
|
||||
visitNode((<JsxOpeningElement>node).attributes, visitor, isJsxAttributes));
|
||||
|
||||
case SyntaxKind.JsxClosingElement:
|
||||
return updateJsxClosingElement(<JsxClosingElement>node,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user