Skip to content

Commit 13752bf

Browse files
committed
[compiler] patch: rewrite scope dep/decl in inlineJsxTransform
This bugfix is needed to land #31199 PropagateScopeDepsHIR infers scope declarations for the `inline-jsx-transform` test fixture (the non-hir version does not). These declarations must get the rewritten phi identifiers
1 parent e288dea commit 13752bf

File tree

1 file changed

+40
-4
lines changed

1 file changed

+40
-4
lines changed

compiler/packages/babel-plugin-react-compiler/src/Optimization/InlineJsxTransform.ts

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,30 @@ export function inlineJsxTransform(
383383
mapTerminalOperands(block.terminal, place =>
384384
handlePlace(place, blockId, inlinedJsxDeclarations),
385385
);
386+
387+
if (block.terminal.kind === 'scope') {
388+
const scope = block.terminal.scope;
389+
for (const dep of scope.dependencies) {
390+
dep.identifier = handleIdentifier(
391+
dep.identifier,
392+
inlinedJsxDeclarations,
393+
);
394+
}
395+
396+
for (const [origId, decl] of [...scope.declarations]) {
397+
const newDecl = handleIdentifier(
398+
decl.identifier,
399+
inlinedJsxDeclarations,
400+
);
401+
if (newDecl.id !== origId) {
402+
scope.declarations.delete(origId);
403+
scope.declarations.set(decl.identifier.id, {
404+
identifier: newDecl,
405+
scope: decl.scope,
406+
});
407+
}
408+
}
409+
}
386410
}
387411

388412
/**
@@ -697,10 +721,10 @@ function handlePlace(
697721
inlinedJsxDeclaration == null ||
698722
inlinedJsxDeclaration.blockIdsToIgnore.has(blockId)
699723
) {
700-
return {...place};
724+
return place;
701725
}
702726

703-
return {...place, identifier: {...inlinedJsxDeclaration.identifier}};
727+
return {...place, identifier: inlinedJsxDeclaration.identifier};
704728
}
705729

706730
function handlelValue(
@@ -715,8 +739,20 @@ function handlelValue(
715739
inlinedJsxDeclaration == null ||
716740
inlinedJsxDeclaration.blockIdsToIgnore.has(blockId)
717741
) {
718-
return {...lvalue};
742+
return lvalue;
719743
}
720744

721-
return {...lvalue, identifier: {...inlinedJsxDeclaration.identifier}};
745+
return {...lvalue, identifier: inlinedJsxDeclaration.identifier};
746+
}
747+
748+
function handleIdentifier(
749+
identifier: Identifier,
750+
inlinedJsxDeclarations: InlinedJsxDeclarationMap,
751+
): Identifier {
752+
const inlinedJsxDeclaration = inlinedJsxDeclarations.get(
753+
identifier.declarationId,
754+
);
755+
return inlinedJsxDeclaration == null
756+
? identifier
757+
: inlinedJsxDeclaration.identifier;
722758
}

0 commit comments

Comments
 (0)