feat(47439): omit optional key from jsx output (#47467)

This commit is contained in:
Oleksandr T
2022-01-18 21:38:52 +02:00
committed by GitHub
parent cecd8c50a0
commit 16e96f62d7
39 changed files with 156 additions and 63 deletions

View File

@@ -242,10 +242,19 @@ namespace ts {
const nonWhitespaceChildren = getSemanticJsxChildren(children);
const isStaticChildren =
length(nonWhitespaceChildren) > 1 || !!(nonWhitespaceChildren[0] as JsxExpression)?.dotDotDotToken;
const args: Expression[] = [tagName, objectProperties, !keyAttr ? factory.createVoidZero() : transformJsxAttributeInitializer(keyAttr.initializer)];
const args: Expression[] = [tagName, objectProperties];
// function jsx(type, config, maybeKey) {}
// "maybeKey" is optional. It is acceptable to use "_jsx" without a third argument
if (keyAttr) {
args.push(transformJsxAttributeInitializer(keyAttr.initializer));
}
if (compilerOptions.jsx === JsxEmit.ReactJSXDev) {
const originalFile = getOriginalNode(currentSourceFile);
if (originalFile && isSourceFile(originalFile)) {
// "maybeKey" has to be replaced with "void 0" to not break the jsxDEV signature
if (keyAttr === undefined) {
args.push(factory.createVoidZero());
}
// isStaticChildren development flag
args.push(isStaticChildren ? factory.createTrue() : factory.createFalse());
// __source development flag
@@ -259,6 +268,7 @@ namespace ts {
args.push(factory.createThis());
}
}
const element = setTextRange(
factory.createCallExpression(getJsxFactoryCallee(isStaticChildren), /*typeArguments*/ undefined, args),
location