Skip to content

Commit 7dcfc96

Browse files
committed
Change childrenLength parameter -> isStaticChildren
1 parent dbac3e7 commit 7dcfc96

File tree

1 file changed

+22
-11
lines changed
  • src/compiler/transformers

1 file changed

+22
-11
lines changed

src/compiler/transformers/jsx.ts

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ namespace ts {
2626
return currentFileState.filenameDeclaration.name;
2727
}
2828

29-
function getJsxFactoryCalleePrimitive(childrenLength: number): "jsx" | "jsxs" | "jsxDEV" {
30-
return compilerOptions.jsx === JsxEmit.ReactJSXDev ? "jsxDEV" : childrenLength > 1 ? "jsxs" : "jsx";
29+
function getJsxFactoryCalleePrimitive(isStaticChildren: boolean): "jsx" | "jsxs" | "jsxDEV" {
30+
return compilerOptions.jsx === JsxEmit.ReactJSXDev ? "jsxDEV" : isStaticChildren ? "jsxs" : "jsx";
3131
}
3232

33-
function getJsxFactoryCallee(childrenLength: number) {
34-
const type = getJsxFactoryCalleePrimitive(childrenLength);
33+
function getJsxFactoryCallee(isStaticChildren: boolean) {
34+
const type = getJsxFactoryCalleePrimitive(isStaticChildren);
3535
return getImplicitImportForName(type);
3636
}
3737

@@ -221,24 +221,33 @@ namespace ts {
221221
const attrs = keyAttr ? filter(node.attributes.properties, p => p !== keyAttr) : node.attributes.properties;
222222
const objectProperties = length(attrs) ? transformJsxAttributesToObjectProps(attrs, childrenProp) :
223223
factory.createObjectLiteralExpression(childrenProp ? [childrenProp] : emptyArray); // When there are no attributes, React wants {}
224-
const nonWhitespaceChildren = getSemanticJsxChildren(children || emptyArray);
225224
return visitJsxOpeningLikeElementOrFragmentJSX(
226225
tagName,
227226
objectProperties,
228227
keyAttr,
229-
(nonWhitespaceChildren[0] as JsxExpression)?.dotDotDotToken ? 2 : length(nonWhitespaceChildren),
228+
children || emptyArray,
230229
isChild,
231230
location
232231
);
233232
}
234233

235-
function visitJsxOpeningLikeElementOrFragmentJSX(tagName: Expression, objectProperties: Expression, keyAttr: JsxAttribute | undefined, childrenLength: number, isChild: boolean, location: TextRange) {
234+
function visitJsxOpeningLikeElementOrFragmentJSX(
235+
tagName: Expression,
236+
objectProperties: Expression,
237+
keyAttr: JsxAttribute | undefined,
238+
children: readonly JsxChild[],
239+
isChild: boolean,
240+
location: TextRange
241+
) {
242+
const nonWhitespaceChildren = getSemanticJsxChildren(children);
243+
const isStaticChildren =
244+
length(nonWhitespaceChildren) > 1 || (nonWhitespaceChildren[0] as JsxExpression).dotDotDotToken;
236245
const args: Expression[] = [tagName, objectProperties, !keyAttr ? factory.createVoidZero() : transformJsxAttributeInitializer(keyAttr.initializer)];
237246
if (compilerOptions.jsx === JsxEmit.ReactJSXDev) {
238247
const originalFile = getOriginalNode(currentSourceFile);
239248
if (originalFile && isSourceFile(originalFile)) {
240249
// isStaticChildren development flag
241-
args.push(childrenLength > 1 ? factory.createTrue() : factory.createFalse());
250+
args.push(isStaticChildren ? factory.createTrue() : factory.createFalse());
242251
// __source development flag
243252
const lineCol = getLineAndCharacterOfPosition(originalFile, location.pos);
244253
args.push(factory.createObjectLiteralExpression([
@@ -250,7 +259,10 @@ namespace ts {
250259
args.push(factory.createThis());
251260
}
252261
}
253-
const element = setTextRange(factory.createCallExpression(getJsxFactoryCallee(childrenLength), /*typeArguments*/ undefined, args), location);
262+
const element = setTextRange(
263+
factory.createCallExpression(getJsxFactoryCallee(isStaticChildren), /*typeArguments*/ undefined, args),
264+
location
265+
);
254266

255267
if (isChild) {
256268
startOnNewLine(element);
@@ -298,12 +310,11 @@ namespace ts {
298310
childrenProps = result;
299311
}
300312
}
301-
const nonWhitespaceChildren = getSemanticJsxChildren(children);
302313
return visitJsxOpeningLikeElementOrFragmentJSX(
303314
getImplicitJsxFragmentReference(),
304315
childrenProps || factory.createObjectLiteralExpression([]),
305316
/*keyAttr*/ undefined,
306-
(nonWhitespaceChildren[0] as JsxExpression)?.dotDotDotToken ? 2 : length(nonWhitespaceChildren),
317+
children,
307318
isChild,
308319
location
309320
);

0 commit comments

Comments
 (0)