Skip to content

Commit

Permalink
Avoid property name conflicts in event-emitter codegen (#36591)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #36591

If any of the properties used in event-emitter codegen conflict with `event` or `payload`, the generated code will fail to build, even if this generated code isn't used. Since these are quite common keys, prefix them with `$` (still valid C++) to avoid conflicts.

Changelog: [General][Fixed] Resolved property name conflicts in event-emitter codegen

Reviewed By: cipolleschi

Differential Revision: D44274619

fbshipit-source-id: 45e67850c49e082d8f9b1f85bb632d45a9fd4f1d
  • Loading branch information
javache authored and facebook-github-bot committed Mar 23, 2023
1 parent 928f4fb commit 3759a26
Show file tree
Hide file tree
Showing 6 changed files with 147 additions and 320 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ Object {
namespace facebook {
namespace react {
} // namespace react
} // namespace facebook
",
Expand All @@ -42,8 +40,6 @@ Object {
namespace facebook {
namespace react {
} // namespace react
} // namespace facebook
",
Expand All @@ -67,8 +63,6 @@ Object {
namespace facebook {
namespace react {
} // namespace react
} // namespace facebook
",
Expand All @@ -92,8 +86,6 @@ Object {
namespace facebook {
namespace react {
} // namespace react
} // namespace facebook
",
Expand All @@ -117,8 +109,6 @@ Object {
namespace facebook {
namespace react {
} // namespace react
} // namespace facebook
",
Expand All @@ -142,8 +132,6 @@ Object {
namespace facebook {
namespace react {
} // namespace react
} // namespace facebook
",
Expand All @@ -167,23 +155,21 @@ Object {
namespace facebook {
namespace react {
void EventNestedObjectPropsNativeComponentViewEventEmitter::onChange(OnChange event) const {
dispatchEvent(\\"change\\", [event=std::move(event)](jsi::Runtime &runtime) {
auto payload = jsi::Object(runtime);
void EventNestedObjectPropsNativeComponentViewEventEmitter::onChange(OnChange $event) const {
dispatchEvent(\\"change\\", [$event=std::move($event)](jsi::Runtime &runtime) {
auto $payload = jsi::Object(runtime);
{
auto location = jsi::Object(runtime);
{
auto source = jsi::Object(runtime);
source.setProperty(runtime, \\"url\\", event.location.source.url);
location.setProperty(runtime, \\"source\\", source);
}
location.setProperty(runtime, \\"x\\", event.location.x);
location.setProperty(runtime, \\"y\\", event.location.y);
payload.setProperty(runtime, \\"location\\", location);
}
return payload;
auto location = jsi::Object(runtime);
{
auto source = jsi::Object(runtime);
source.setProperty(runtime, \\"url\\", $event.location.source.url);
location.setProperty(runtime, \\"source\\", source);
}
location.setProperty(runtime, \\"x\\", $event.location.x);
location.setProperty(runtime, \\"y\\", $event.location.y);
$payload.setProperty(runtime, \\"location\\", location);
}
return $payload;
});
}
Expand All @@ -210,49 +196,59 @@ Object {
namespace facebook {
namespace react {
void EventPropsNativeComponentViewEventEmitter::onChange(OnChange event) const {
dispatchEvent(\\"change\\", [event=std::move(event)](jsi::Runtime &runtime) {
auto payload = jsi::Object(runtime);
payload.setProperty(runtime, \\"value\\", event.value);
payload.setProperty(runtime, \\"source\\", event.source);
payload.setProperty(runtime, \\"progress\\", event.progress);
payload.setProperty(runtime, \\"scale\\", event.scale);
return payload;
void EventPropsNativeComponentViewEventEmitter::onChange(OnChange $event) const {
dispatchEvent(\\"change\\", [$event=std::move($event)](jsi::Runtime &runtime) {
auto $payload = jsi::Object(runtime);
$payload.setProperty(runtime, \\"value\\", $event.value);
$payload.setProperty(runtime, \\"source\\", $event.source);
$payload.setProperty(runtime, \\"progress\\", $event.progress);
$payload.setProperty(runtime, \\"scale\\", $event.scale);
return $payload;
});
}
void EventPropsNativeComponentViewEventEmitter::onEventDirect(OnEventDirect event) const {
dispatchEvent(\\"eventDirect\\", [event=std::move(event)](jsi::Runtime &runtime) {
auto payload = jsi::Object(runtime);
payload.setProperty(runtime, \\"value\\", event.value);
return payload;
void EventPropsNativeComponentViewEventEmitter::onEventDirect(OnEventDirect $event) const {
dispatchEvent(\\"eventDirect\\", [$event=std::move($event)](jsi::Runtime &runtime) {
auto $payload = jsi::Object(runtime);
$payload.setProperty(runtime, \\"value\\", $event.value);
return $payload;
});
}
void EventPropsNativeComponentViewEventEmitter::onEventDirectWithPaperName(OnEventDirectWithPaperName event) const {
dispatchEvent(\\"eventDirectWithPaperName\\", [event=std::move(event)](jsi::Runtime &runtime) {
auto payload = jsi::Object(runtime);
payload.setProperty(runtime, \\"value\\", event.value);
return payload;
void EventPropsNativeComponentViewEventEmitter::onEventDirectWithPaperName(OnEventDirectWithPaperName $event) const {
dispatchEvent(\\"eventDirectWithPaperName\\", [$event=std::move($event)](jsi::Runtime &runtime) {
auto $payload = jsi::Object(runtime);
$payload.setProperty(runtime, \\"value\\", $event.value);
return $payload;
});
}
void EventPropsNativeComponentViewEventEmitter::onOrientationChange(OnOrientationChange event) const {
dispatchEvent(\\"orientationChange\\", [event=std::move(event)](jsi::Runtime &runtime) {
auto payload = jsi::Object(runtime);
payload.setProperty(runtime, \\"orientation\\", toString(event.orientation));
return payload;
void EventPropsNativeComponentViewEventEmitter::onOrientationChange(OnOrientationChange $event) const {
dispatchEvent(\\"orientationChange\\", [$event=std::move($event)](jsi::Runtime &runtime) {
auto $payload = jsi::Object(runtime);
$payload.setProperty(runtime, \\"orientation\\", toString($event.orientation));
return $payload;
});
}
void EventPropsNativeComponentViewEventEmitter::onEnd(OnEnd event) const {
void EventPropsNativeComponentViewEventEmitter::onEnd(OnEnd $event) const {
dispatchEvent(\\"end\\", [](jsi::Runtime &runtime) {
auto payload = jsi::Object(runtime);
auto $payload = jsi::Object(runtime);
return payload;
return $payload;
});
}
void EventPropsNativeComponentViewEventEmitter::onEventBubblingWithPaperName(OnEventBubblingWithPaperName event) const {
void EventPropsNativeComponentViewEventEmitter::onEventBubblingWithPaperName(OnEventBubblingWithPaperName $event) const {
dispatchEvent(\\"eventBubblingWithPaperName\\", [](jsi::Runtime &runtime) {
auto payload = jsi::Object(runtime);
auto $payload = jsi::Object(runtime);
return payload;
return $payload;
});
}
Expand All @@ -279,8 +275,6 @@ Object {
namespace facebook {
namespace react {
} // namespace react
} // namespace facebook
",
Expand All @@ -304,8 +298,6 @@ Object {
namespace facebook {
namespace react {
} // namespace react
} // namespace facebook
",
Expand All @@ -329,8 +321,6 @@ Object {
namespace facebook {
namespace react {
} // namespace react
} // namespace facebook
",
Expand All @@ -354,11 +344,11 @@ Object {
namespace facebook {
namespace react {
void InterfaceOnlyNativeComponentViewEventEmitter::onChange(OnChange event) const {
dispatchEvent(\\"change\\", [event=std::move(event)](jsi::Runtime &runtime) {
auto payload = jsi::Object(runtime);
payload.setProperty(runtime, \\"value\\", event.value);
return payload;
void InterfaceOnlyNativeComponentViewEventEmitter::onChange(OnChange $event) const {
dispatchEvent(\\"change\\", [$event=std::move($event)](jsi::Runtime &runtime) {
auto $payload = jsi::Object(runtime);
$payload.setProperty(runtime, \\"value\\", $event.value);
return $payload;
});
}
Expand All @@ -385,8 +375,6 @@ Object {
namespace facebook {
namespace react {
} // namespace react
} // namespace facebook
",
Expand All @@ -410,8 +398,6 @@ Object {
namespace facebook {
namespace react {
} // namespace react
} // namespace facebook
",
Expand All @@ -435,8 +421,6 @@ Object {
namespace facebook {
namespace react {
} // namespace react
} // namespace facebook
",
Expand All @@ -460,8 +444,6 @@ Object {
namespace facebook {
namespace react {
} // namespace react
} // namespace facebook
",
Expand All @@ -485,8 +467,6 @@ Object {
namespace facebook {
namespace react {
} // namespace react
} // namespace facebook
",
Expand All @@ -510,8 +490,6 @@ Object {
namespace facebook {
namespace react {
} // namespace react
} // namespace facebook
",
Expand Down
Loading

0 comments on commit 3759a26

Please sign in to comment.