Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Jan 11, 2023. It is now read-only.

Commitd6ab717

Browse files
ryanjduffyjasonLaster
authored andcommitted
Apply SourceMaps type to redux actions (#8077)
1 parent6643ff4 commitd6ab717

File tree

16 files changed

+101
-70
lines changed

16 files changed

+101
-70
lines changed

‎flow-typed/debugger-html.js‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,18 @@ declare module "debugger-html" {
106106
this:Object
107107
};
108108

109+
/**
110+
* Original Frame
111+
*
112+
*@memberof types
113+
*@static
114+
*/
115+
declaretypeOriginalFrame={
116+
displayName:string,
117+
location?:SourceLocation,
118+
thread?:string
119+
};
120+
109121
/**
110122
* why
111123
*@memberof types

‎packages/devtools-source-map/src/index.js‎

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,13 @@ const {
88
workerUtils:{ WorkerDispatcher}
99
}=require("devtools-utils");
1010

11-
importtype{SourceLocation,Source,SourceId}from"../../../src/types";
11+
importtype{
12+
OriginalFrame,
13+
Range,
14+
SourceLocation,
15+
Source,
16+
SourceId
17+
}from"../../../src/types";
1218
importtype{SourceMapConsumer}from"source-map";
1319
importtype{locationOptions}from"./source-map";
1420

@@ -87,18 +93,7 @@ export const getGeneratedRangesForOriginal = async (
8793
sourceId:SourceId,
8894
url:string,
8995
mergeUnmappedRegions?:boolean
90-
):Promise<
91-
Array<{
92-
start:{
93-
line:number,
94-
column:number
95-
},
96-
end:{
97-
line:number,
98-
column:number
99-
}
100-
}>
101-
>=>
96+
):Promise<Range[]>=>
10297
dispatcher.invoke(
10398
"getGeneratedRangesForOriginal",
10499
sourceId,
@@ -108,8 +103,7 @@ export const getGeneratedRangesForOriginal = async (
108103

109104
exportconstgetFileGeneratedRange=async(
110105
originalSource:Source
111-
):Promise<?{start:any,end:any}>=>
112-
dispatcher.invoke("getFileGeneratedRange",originalSource);
106+
):Promise<Range>=>dispatcher.invoke("getFileGeneratedRange",originalSource);
113107

114108
exportconstgetLocationScopes=dispatcher.task("getLocationScopes");
115109

@@ -137,10 +131,8 @@ export const hasMappedSource = async (
137131

138132
exportconstgetOriginalStackFrames=async(
139133
generatedLocation:SourceLocation
140-
):Promise<?Array<{
141-
displayName:string,
142-
location?:SourceLocation
143-
}>>=>dispatcher.invoke("getOriginalStackFrames",generatedLocation);
134+
):Promise<?Array<OriginalFrame>>=>
135+
dispatcher.invoke("getOriginalStackFrames",generatedLocation);
144136

145137
export{
146138
originalToGeneratedId,

‎packages/devtools-source-map/src/utils/getOriginalStackFrames.js‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,15 @@
44

55
//@flow
66

7-
importtype{SourceLocation}from"debugger-html";
7+
importtype{OriginalFrame,SourceLocation}from"debugger-html";
88

99
const{ getWasmXScopes}=require("./wasmXScopes");
1010

1111
// Returns expanded stack frames details based on the generated location.
1212
// The function return null if not information was found.
1313
asyncfunctiongetOriginalStackFrames(
1414
generatedLocation:SourceLocation
15-
):Promise<?Array<{
16-
displayName:string,
17-
location?:SourceLocation
18-
}>>{
15+
):Promise<?Array<OriginalFrame>>{
1916
constwasmXScopes=awaitgetWasmXScopes(generatedLocation.sourceId);
2017
if(!wasmXScopes){
2118
returnnull;

‎packages/devtools-source-map/src/utils/wasmXScopes.js‎

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
//@flow
66
/* eslint camelcase: 0*/
77

8-
importtype{SourceLocation,SourceId}from"debugger-html";
8+
importtype{OriginalFrame,SourceLocation,SourceId}from"debugger-html";
99

1010
const{ getSourceMap}=require("./sourceMapRequests");
1111
const{ generatedToOriginalId}=require("./index");
@@ -153,12 +153,7 @@ class XScope {
153153
this.xScope=xScopeData;
154154
}
155155

156-
search(
157-
generatedLocation:SourceLocation
158-
):Array<{
159-
displayName:string,
160-
location?:SourceLocation
161-
}>{
156+
search(generatedLocation:SourceLocation):Array<OriginalFrame>{
162157
const{ code_section_offset, debug_info, sources, idIndex}=this.xScope;
163158
constpc=generatedLocation.line-(code_section_offset||0);
164159
constscopes=filterScopes(debug_info,pc,null,idIndex);

‎src/actions/breakpoints/breakpointPositions.js‎

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44

55
//@flow
66

7-
import{isOriginalId,originalToGeneratedId}from"devtools-source-map";
7+
importSourceMaps,{
8+
isOriginalId,
9+
originalToGeneratedId
10+
}from"devtools-source-map";
811
import{uniqBy,zip}from"lodash";
912

1013
import{
@@ -14,16 +17,15 @@ import {
1417
getBreakpointPositionsForSource
1518
}from"../../selectors";
1619

17-
importtype{MappedLocation,SourceLocation}from"../../types";
20+
importtype{MappedLocation,Range,SourceLocation}from"../../types";
1821
importtype{ThunkArgs}from"../../actions/types";
1922
import{makeBreakpointId}from"../../utils/breakpoint";
20-
importtypeofSourceMapsfrom"../../../packages/devtools-source-map/src";
2123

2224
constrequests=newMap();
2325

2426
asyncfunctionmapLocations(
2527
generatedLocations:SourceLocation[],
26-
{ sourceMaps}:{sourceMaps:SourceMaps}
28+
{ sourceMaps}:{sourceMaps:typeofSourceMaps}
2729
){
2830
constoriginalLocations=awaitsourceMaps.getOriginalLocations(
2931
generatedLocations
@@ -65,7 +67,9 @@ async function _setBreakpointPositions(sourceId, thunkArgs) {
6567

6668
letresults={};
6769
if(isOriginalId(sourceId)){
68-
constranges=awaitsourceMaps.getGeneratedRangesForOriginal(
70+
// Explicitly typing ranges is required to work around the following issue
71+
// https://github.com/facebook/flow/issues/5294
72+
constranges:Range[]=awaitsourceMaps.getGeneratedRangesForOriginal(
6973
sourceId,
7074
generatedSource.url,
7175
true
@@ -81,8 +85,10 @@ async function _setBreakpointPositions(sourceId, thunkArgs) {
8185
// and because we know we don't care about the end-line whitespace
8286
// in this case.
8387
if(range.end.column===Infinity){
84-
range.end.line+=1;
85-
range.end.column=0;
88+
range.end={
89+
line:range.end.line+1,
90+
column:0
91+
};
8692
}
8793

8894
constbps=awaitclient.getBreakpointPositions(generatedSource,range);

‎src/actions/breakpoints/remapLocations.js‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44

55
//@flow
66

7+
importtypeofSourceMapsfrom"devtools-source-map";
8+
79
importtype{Breakpoint}from"../../types";
810

911
exportdefaultfunctionremapLocations(
1012
breakpoints:Breakpoint[],
1113
sourceId:string,
12-
sourceMaps:Object
14+
sourceMaps:SourceMaps
1315
){
1416
constsourceBreakpoints:Promise<Breakpoint>[] = breakpoints.map(
1517
async breakpoint =>{

‎src/actions/pause/mapFrames.js‎

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ import {
1414
importassertfrom"../../utils/assert";
1515
import{findClosestFunction}from"../../utils/ast";
1616

17-
importtype{Frame,ThreadId}from"../../types";
17+
importtype{Frame,OriginalFrame,ThreadId}from"../../types";
1818
importtype{State}from"../../reducers/types";
1919
importtype{ThunkArgs}from"../types";
2020

21-
import{isGeneratedId}from"devtools-source-map";
21+
importSourceMaps,{isGeneratedId}from"devtools-source-map";
2222

2323
functionisFrameBlackboxed(state,frame){
2424
constsource=getSource(state,frame.location.sourceId);
@@ -35,7 +35,10 @@ function getSelectedFrameId(state, thread, frames) {
3535
returnselectedFrame&&selectedFrame.id;
3636
}
3737

38-
exportfunctionupdateFrameLocation(frame:Frame,sourceMaps:any){
38+
exportfunctionupdateFrameLocation(
39+
frame:Frame,
40+
sourceMaps:typeofSourceMaps
41+
){
3942
if(frame.isOriginal){
4043
returnPromise.resolve(frame);
4144
}
@@ -48,7 +51,7 @@ export function updateFrameLocation(frame: Frame, sourceMaps: any) {
4851

4952
functionupdateFrameLocations(
5053
frames:Frame[],
51-
sourceMaps:any
54+
sourceMaps:typeofSourceMaps
5255
):Promise<Frame[]>{
5356
if(!frames||frames.length==0){
5457
returnPromise.resolve(frames);
@@ -104,7 +107,7 @@ function isWasmOriginalSourceFrame(frame, getState: () => State): boolean {
104107

105108
asyncfunctionexpandFrames(
106109
frames:Frame[],
107-
sourceMaps:any,
110+
sourceMaps:typeofSourceMaps,
108111
getState:()=>State
109112
):Promise<Frame[]>{
110113
const result=[];
@@ -114,9 +117,9 @@ async function expandFrames(
114117
result.push(frame);
115118
continue;
116119
}
117-
constoriginalFrames=awaitsourceMaps.getOriginalStackFrames(
118-
frame.generatedLocation
119-
);
120+
constoriginalFrames: ?Array<
121+
OriginalFrame
122+
>=awaitsourceMaps.getOriginalStackFrames(frame.generatedLocation);
120123
if(!originalFrames){
121124
result.push(frame);
122125
continue;
@@ -130,6 +133,10 @@ async function expandFrames(
130133
};
131134

132135
originalFrames.forEach((originalFrame,j)=>{
136+
if(!originalFrame.location||!originalFrame.thread){
137+
return;
138+
}
139+
133140
// Keep outer most frame with true actor ID, and generate uniquie
134141
// one for the nested frames.
135142
constid=j==0 ?frame.id :`${frame.id}-originalFrame${j}`;

‎src/actions/sources/newSources.js‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,10 @@ function loadSourceMap(sourceId: SourceId) {
9898

9999
leturls=null;
100100
try{
101-
consturlInfo={ ...source};
102-
if(!urlInfo.url){
101+
// Unable to correctly type the result of a spread on a union type.
102+
// See https://github.com/facebook/flow/pull/7298
103+
consturlInfo:Source={ ...(source:any)};
104+
if(!urlInfo.url&&typeofurlInfo.introductionUrl==="string"){
103105
// If the source was dynamically generated (via eval, dynamically
104106
// created script elements, and so forth), it won't have a URL, so that
105107
// it is not collapsed into other sources from the same place. The

‎src/actions/sources/prettyPrint.js‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
//@flow
66

7+
importtypeofSourceMapsfrom"devtools-source-map";
8+
79
importassertfrom"../../utils/assert";
810
import{recordEvent}from"../../utils/telemetry";
911
import{remapBreakpoints}from"../breakpoints";
@@ -28,7 +30,7 @@ import { selectSource } from "./select";
2830
importtype{JsSource,Source}from"../../types";
2931

3032
exportasyncfunctionprettyPrintSource(
31-
sourceMaps:any,
33+
sourceMaps:SourceMaps,
3234
prettySource:Source,
3335
generatedSource:any
3436
){

‎src/actions/types/index.js‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
//@flow
66

7+
importtypeofSourceMapsfrom"devtools-source-map";
8+
79
importtype{WorkerList,MainThread}from"../../types";
810
importtype{State}from"../../reducers/types";
911
importtype{MatchedLocations}from"../../reducers/file-search";
@@ -34,7 +36,7 @@ export type ThunkArgs = {
3436
dispatch:(action:any)=>Promise<any>,
3537
getState:()=>State,
3638
client:typeofclientCommands,
37-
sourceMaps:any,
39+
sourceMaps:SourceMaps,
3840
panel:Panel
3941
};
4042

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp