Skip to content

Commit

Permalink
Pass nameHint correctly for class elements
Browse files Browse the repository at this point in the history
Summary: Set the nameHint when we can for class fields.

Reviewed By: avp

Differential Revision: D69488826

fbshipit-source-id: a7831cf94f0a5c7b77a822fb67b214fd855dc5d7
  • Loading branch information
fbmal7 authored and facebook-github-bot committed Feb 21, 2025
1 parent 739f229 commit c348c72
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lib/IRGen/ESTreeIRGen-legacy-class.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -525,16 +525,20 @@ NormalFunction *ESTreeIRGen::genStaticElementsInitFunction(
if (!prop->_static)
continue;
Value *propKey;
Identifier nameHint;
if (prop->_computed) {
// use .at, since there should always be an entry for this node.
Variable *fieldKeyVar = LC->classComputedFieldKeys.at(prop);
auto *scope = emitResolveScopeInstIfNeeded(fieldKeyVar->getParent());
propKey = Builder.createLoadFrameInst(scope, fieldKeyVar);
} else {
if (auto *id = llvh::dyn_cast<ESTree::IdentifierNode>(prop->_key)) {
nameHint = Identifier::getFromPointer(id->_name);
}
propKey =
Builder.getLiteralString(propertyKeyAsString(buffer, prop->_key));
}
Value *propValue = prop->_value ? genExpression(prop->_value)
Value *propValue = prop->_value ? genExpression(prop->_value, nameHint)
: Builder.getLiteralUndefined();
Builder.createDefineOwnPropertyInst(
propValue, classVal, propKey, IRBuilder::PropEnumerable::Yes);
Expand Down Expand Up @@ -603,15 +607,19 @@ NormalFunction *ESTreeIRGen::genLegacyInstanceElementsInit(
if (prop->_static)
continue;
Value *propKey;
Identifier nameHint;
if (prop->_computed) {
Variable *fieldKeyVar = LC->classComputedFieldKeys.at(prop);
auto *scope = emitResolveScopeInstIfNeeded(fieldKeyVar->getParent());
propKey = Builder.createLoadFrameInst(scope, fieldKeyVar);
} else {
if (auto *ID = llvh::dyn_cast<ESTree::IdentifierNode>(prop->_key)) {
nameHint = Identifier::getFromPointer(ID->_name);
}
propKey =
Builder.getLiteralString(propertyKeyAsString(buffer, prop->_key));
}
Value *propValue = prop->_value ? genExpression(prop->_value)
Value *propValue = prop->_value ? genExpression(prop->_value, nameHint)
: Builder.getLiteralUndefined();
Builder.createDefineOwnPropertyInst(
propValue, thisParam, propKey, IRBuilder::PropEnumerable::Yes);
Expand Down

0 comments on commit c348c72

Please sign in to comment.