Skip to content

Commit

Permalink
Add extra comments about extension fields
Browse files Browse the repository at this point in the history
  • Loading branch information
Juan Tejada committed Aug 11, 2021
1 parent 2887765 commit 83e3b89
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,15 @@ function compile(fileName) {
const encodedHookMap = generateEncodedHookMap(parsed);
const fbSourcesExtendedSourceMap = {
...sourceMap,
// When using the x_fb_sources extension field, the first item
// for a given source is reserved for the Function Map, and the
// Hook Map is added as the second item.
x_fb_sources: [[null, encodedHookMap]],
};
const reactSourcesExtendedSourceMap = {
...sourceMap,
// When using the x_react_sources extension field, the first item
// for a given source is reserved for the Hook Map.
x_react_sources: [[encodedHookMap]],
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -667,8 +667,15 @@ function extractHookMapFromSourceMap(
): HookMap | null {
let hookMap;
if (sourcemap.hasOwnProperty(REACT_SOURCES_EXTENSION_KEY)) {
// When using the x_react_sources extension field, the first item
// for a given source is reserved for the Hook Map, which is why
// we look up the index at position 0.
hookMap = sourcemap[REACT_SOURCES_EXTENSION_KEY][sourceIndex][0];
} else if (sourcemap.hasOwnProperty(FB_SOURCES_EXTENSION_KEY)) {
// When using the x_fb_sources extension field, the first item
// for a given source is reserved for the Function Map, and the
// Hook Map is added as the second item, which is why we look up
// the index at position 1.
hookMap = sourcemap[FB_SOURCES_EXTENSION_KEY][sourceIndex][1];
}
if (hookMap != null) {
Expand Down

0 comments on commit 83e3b89

Please sign in to comment.