Skip to content

Commit

Permalink
[compiler] patch: rewrite scope dep/decl in inlineJsxTransform (#31431)
Browse files Browse the repository at this point in the history
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
---
[//]: # (BEGIN SAPLING FOOTER)
Stack created with [Sapling](https://sapling-scm.com). Best reviewed
with [ReviewStack](https://reviewstack.dev/facebook/react/pull/31431).
* #31204
* #31202
* #31203
* #31201
* #31200
* #31346
* #31199
* __->__ #31431
* #31345
* #31197
  • Loading branch information
mofeiZ authored Nov 5, 2024
1 parent e7e269b commit 527bcaa
Showing 1 changed file with 40 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,30 @@ export function inlineJsxTransform(
mapTerminalOperands(block.terminal, place =>
handlePlace(place, blockId, inlinedJsxDeclarations),
);

if (block.terminal.kind === 'scope') {
const scope = block.terminal.scope;
for (const dep of scope.dependencies) {
dep.identifier = handleIdentifier(
dep.identifier,
inlinedJsxDeclarations,
);
}

for (const [origId, decl] of [...scope.declarations]) {
const newDecl = handleIdentifier(
decl.identifier,
inlinedJsxDeclarations,
);
if (newDecl.id !== origId) {
scope.declarations.delete(origId);
scope.declarations.set(decl.identifier.id, {
identifier: newDecl,
scope: decl.scope,
});
}
}
}
}

/**
Expand Down Expand Up @@ -697,10 +721,10 @@ function handlePlace(
inlinedJsxDeclaration == null ||
inlinedJsxDeclaration.blockIdsToIgnore.has(blockId)
) {
return {...place};
return place;
}

return {...place, identifier: {...inlinedJsxDeclaration.identifier}};
return {...place, identifier: inlinedJsxDeclaration.identifier};
}

function handlelValue(
Expand All @@ -715,8 +739,20 @@ function handlelValue(
inlinedJsxDeclaration == null ||
inlinedJsxDeclaration.blockIdsToIgnore.has(blockId)
) {
return {...lvalue};
return lvalue;
}

return {...lvalue, identifier: {...inlinedJsxDeclaration.identifier}};
return {...lvalue, identifier: inlinedJsxDeclaration.identifier};
}

function handleIdentifier(
identifier: Identifier,
inlinedJsxDeclarations: InlinedJsxDeclarationMap,
): Identifier {
const inlinedJsxDeclaration = inlinedJsxDeclarations.get(
identifier.declarationId,
);
return inlinedJsxDeclaration == null
? identifier
: inlinedJsxDeclaration.identifier;
}

0 comments on commit 527bcaa

Please sign in to comment.