Skip to content

Commit

Permalink
[DevTools] Updated source map extension format + more precise types (#…
Browse files Browse the repository at this point in the history
…22073)

## Summary

Follow up from #22010.

As suggested by @motiz88, update the way the react sources metadata is stored within the fb sources metadata. Specifically,  instead of `x_facebook_sources` directly containing a hook map in the second position of the metadata tuple for a given source, it contains the react sources metadata itself, which is also a tuple of react sources metadata for a given source, and which contains the hook map in the first position. This way the react sources metadata tuple can be extended to contain more react-specific metadata without taking up more positions in the top-level facebook sources metadata.

As part of this change:
- Adds more precise Flow types, mostly borrowed from Metro
- Fixes the facebook sources field name (we were using `x_fb_sources` but it should be `x_facebook_sources`

## Test Plan

- yarn flow
- yarn test
- yarn test-build-devtools
  • Loading branch information
Juan committed Aug 11, 2021
1 parent ad15053 commit 531c97e
Show file tree
Hide file tree
Showing 25 changed files with 100 additions and 36 deletions.
50 changes: 50 additions & 0 deletions packages/react-devtools-extensions/src/SourceMapTypes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow strict-local
*/

import type {EncodedHookMap} from './generateHookMap';

export type ReactSourceMetadata = [?EncodedHookMap];
export type ReactSourcesArray = $ReadOnlyArray<?ReactSourceMetadata>;

export type FBSourceMetadata = [?{...}, ?ReactSourceMetadata];
export type FBSourcesArray = $ReadOnlyArray<?FBSourceMetadata>;

export type BasicSourceMap = {|
+file?: string,
+mappings: string,
+names: Array<string>,
+sourceRoot?: string,
+sources: Array<string>,
+sourcesContent?: Array<?string>,
+version: number,
+x_facebook_sources?: FBSourcesArray,
+x_react_sources?: ReactSourcesArray,
|};

export type IndexMapSection = {
map: IndexMap | BasicSourceMap,
offset: {
line: number,
column: number,
...
},
...
};

export type IndexMap = {|
+file?: string,
+mappings?: void, // avoids SourceMap being a disjoint union
+sourcesContent?: void,
+sections: Array<IndexMapSection>,
+version: number,
+x_facebook_sources?: FBSourcesArray,
+x_react_sources?: ReactSourcesArray,
|};

export type MixedSourceMap = IndexMap | BasicSourceMap;

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 531c97e

Please sign in to comment.