Skip to content

Commit 9b2514f

Browse files
Juanzhengjitf
Juan
authored andcommitted
[DevTools] Updated source map extension format + more precise types (facebook#22073)
## Summary Follow up from facebook#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
1 parent a557e5a commit 9b2514f

25 files changed

+100
-36
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow strict-local
8+
*/
9+
10+
import type {EncodedHookMap} from './generateHookMap';
11+
12+
export type ReactSourceMetadata = [?EncodedHookMap];
13+
export type ReactSourcesArray = $ReadOnlyArray<?ReactSourceMetadata>;
14+
15+
export type FBSourceMetadata = [?{...}, ?ReactSourceMetadata];
16+
export type FBSourcesArray = $ReadOnlyArray<?FBSourceMetadata>;
17+
18+
export type BasicSourceMap = {|
19+
+file?: string,
20+
+mappings: string,
21+
+names: Array<string>,
22+
+sourceRoot?: string,
23+
+sources: Array<string>,
24+
+sourcesContent?: Array<?string>,
25+
+version: number,
26+
+x_facebook_sources?: FBSourcesArray,
27+
+x_react_sources?: ReactSourcesArray,
28+
|};
29+
30+
export type IndexMapSection = {
31+
map: IndexMap | BasicSourceMap,
32+
offset: {
33+
line: number,
34+
column: number,
35+
...
36+
},
37+
...
38+
};
39+
40+
export type IndexMap = {|
41+
+file?: string,
42+
+mappings?: void, // avoids SourceMap being a disjoint union
43+
+sourcesContent?: void,
44+
+sections: Array<IndexMapSection>,
45+
+version: number,
46+
+x_facebook_sources?: FBSourcesArray,
47+
+x_react_sources?: ReactSourcesArray,
48+
|};
49+
50+
export type MixedSourceMap = IndexMap | BasicSourceMap;

packages/react-devtools-extensions/src/__tests__/__source__/__compiled__/external/fb-sources-extended/ComponentUsingHooksIndirectly.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/react-devtools-extensions/src/__tests__/__source__/__compiled__/external/fb-sources-extended/ComponentWithCustomHook.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/react-devtools-extensions/src/__tests__/__source__/__compiled__/external/fb-sources-extended/ComponentWithExternalCustomHooks.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/react-devtools-extensions/src/__tests__/__source__/__compiled__/external/fb-sources-extended/ComponentWithMultipleHooksPerLine.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/react-devtools-extensions/src/__tests__/__source__/__compiled__/external/fb-sources-extended/ComponentWithNestedHooks.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/react-devtools-extensions/src/__tests__/__source__/__compiled__/external/fb-sources-extended/ContainingStringSourceMappingURL.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/react-devtools-extensions/src/__tests__/__source__/__compiled__/external/fb-sources-extended/Example.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)